blob: f02e4f3a2fc027d2e11653a79a5aaeb2df652bec [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
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100120#ifdef FEAT_PROP_POPUP
121 int text_prop_above_count;
122#endif
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100123
Bram Moolenaar1306b362022-08-06 15:59:06 +0100124 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
125 int cul_screenline;
126
127 int char_attr; // attributes for the next character
128
129 int n_extra; // number of extra bytes
130 char_u *p_extra; // string of extra chars, plus NUL, only used
131 // when c_extra and c_final are NUL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100132 char_u *p_extra_free; // p_extra buffer that needs to be freed
Bram Moolenaar1306b362022-08-06 15:59:06 +0100133 int c_extra; // extra chars, all the same
134 int c_final; // final char, mandatory if set
135
136 // saved "extra" items for when draw_state becomes WL_LINE (again)
137 int saved_n_extra;
138 char_u *saved_p_extra;
139 int saved_c_extra;
140 int saved_c_final;
141 int saved_char_attr;
142
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100143 char_u extra[NUMBUFLEN + MB_MAXBYTES];
144 // "%ld " and 'fdc' must fit in here, as well
145 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100146
Bram Moolenaar1306b362022-08-06 15:59:06 +0100147#ifdef FEAT_DIFF
148 hlf_T diff_hlf; // type of diff highlighting
149#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100150 int filler_lines; // nr of filler lines to be drawn
151 int filler_todo; // nr of filler lines still to do + 1
152#ifdef FEAT_SIGNS
153 sign_attrs_T sattr;
154#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100155} winlinevars_T;
156
157// draw_state values for items that are drawn in sequence:
158#define WL_START 0 // nothing done yet, must be zero
Martin Tournoij7904fa42022-10-04 16:28:45 +0100159#define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar1306b362022-08-06 15:59:06 +0100160#ifdef FEAT_FOLDING
161# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
162#else
163# define WL_FOLD WL_CMDLINE
164#endif
165#ifdef FEAT_SIGNS
166# define WL_SIGN (WL_FOLD + 1) // column for signs
167#else
168# define WL_SIGN WL_FOLD // column for signs
169#endif
170#define WL_NR (WL_SIGN + 1) // line number
171#ifdef FEAT_LINEBREAK
172# define WL_BRI (WL_NR + 1) // 'breakindent'
173#else
174# define WL_BRI WL_NR
175#endif
176#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
177# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
178#else
179# define WL_SBR WL_BRI
180#endif
181#define WL_LINE (WL_SBR + 1) // text in the line
182
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100183#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200184/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000185 * Return TRUE if CursorLineSign highlight is to be used.
186 */
187 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100188use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000189{
190 return wp->w_p_cul
191 && lnum == wp->w_cursor.lnum
192 && (wp->w_p_culopt_flags & CULOPT_NBR);
193}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100194#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000195
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100196
197#ifdef FEAT_FOLDING
198/*
199 * Setup for drawing the 'foldcolumn', if there is one.
200 */
201 static void
202handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
203{
204 int fdc = compute_foldcolumn(wp, 0);
205
206 if (fdc <= 0)
207 return;
208
209 // Allocate a buffer, "wlv->extra[]" may already be in use.
210 vim_free(wlv->p_extra_free);
211 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
212 if (wlv->p_extra_free != NULL)
213 {
214 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
215 wp, FALSE, wlv->lnum);
216 wlv->p_extra_free[wlv->n_extra] = NUL;
217 wlv->p_extra = wlv->p_extra_free;
218 wlv->c_extra = NUL;
219 wlv->c_final = NUL;
220 if (use_cursor_line_highlight(wp, wlv->lnum))
221 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
222 else
223 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
224 }
225}
226#endif
227
228#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000229/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100230 * Get information needed to display the sign in line "wlv->lnum" in window
231 * "wp".
232 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200233 * Otherwise the sign is going to be displayed in the sign column.
234 */
235 static void
236get_sign_display_info(
237 int nrcol,
238 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100239 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200240{
241 int text_sign;
242# ifdef FEAT_SIGN_ICONS
243 int icon_sign;
244# endif
245
246 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100247 wlv->c_extra = ' ';
248 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200249 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100250 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200251 else
252 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100253 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100254 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000255 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100256 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100257 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200258 }
259
Bram Moolenaar1306b362022-08-06 15:59:06 +0100260 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200261#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100262 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200263#endif
264 )
265 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100266 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200267# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100268 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200269 if (gui.in_use && icon_sign != 0)
270 {
271 // Use the image in this position.
272 if (nrcol)
273 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100274 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100275 sprintf((char *)wlv->extra, "%-*c ",
276 number_width(wp), SIGN_BYTE);
277 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100278 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200279 }
280 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100281 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200282# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100283 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
284 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200285 {
286 if (nrcol)
287 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100288 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100289 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200290 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100291 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100292 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200293 }
294 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100295 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200296 }
297# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100298 wlv->c_final = NUL;
299 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200300 }
301 else
302# endif
303 if (text_sign != 0)
304 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100305 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100306 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200307 {
308 if (nrcol)
309 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100310 int width = number_width(wp) - 2;
311 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200312
313 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100314 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100315 vim_snprintf((char *)wlv->extra + n,
316 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100317 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200318 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100319 wlv->c_extra = NUL;
320 wlv->c_final = NUL;
321 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200322 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000323
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100324 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100325 && wlv->sattr.sat_culhl > 0)
326 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000327 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100328 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200329 }
330 }
331}
332#endif
333
Bram Moolenaard7657e92022-09-20 18:59:30 +0100334/*
335 * Display the absolute or relative line number. After the first row fill with
336 * blanks when the 'n' flag isn't in 'cpo'.
337 */
338 static void
339handle_lnum_col(
340 win_T *wp,
341 winlinevars_T *wlv,
342 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100343 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100344{
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100345 int has_cpo_n = vim_strchr(p_cpo, CPO_NUMCOL) != NULL;
346
Bram Moolenaard7657e92022-09-20 18:59:30 +0100347 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100348 && (wlv->row == wlv->startrow + wlv->filler_lines || !has_cpo_n)
Bram Moolenaar37251162022-10-06 20:48:00 +0100349 // there is no line number in a wrapped line when "n" is in
350 // 'cpoptions', but 'breakindent' assumes it anyway.
351 && !((has_cpo_n
352#ifdef FEAT_LINEBREAK
353 && !wp->w_p_bri
354#endif
355 ) && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100356 {
357#ifdef FEAT_SIGNS
358 // If 'signcolumn' is set to 'number' and a sign is present
359 // in 'lnum', then display the sign instead of the line
360 // number.
361 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
362 get_sign_display_info(TRUE, wp, wlv);
363 else
364#endif
365 {
366 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100367 // When there are text properties above the line put the line number
368 // below them.
369 if (wlv->row == wlv->startrow + wlv->filler_lines
370#ifdef FEAT_PROP_POPUP
371 + wlv->text_prop_above_count
Bram Moolenaard7657e92022-09-20 18:59:30 +0100372#endif
Bram Moolenaar06618f92022-10-06 19:21:20 +0100373 && (wp->w_skipcol == 0 || wlv->row > wp->w_winrow))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100374 {
375 long num;
376 char *fmt = "%*ld ";
377
378 if (wp->w_p_nu && !wp->w_p_rnu)
379 // 'number' + 'norelativenumber'
380 num = (long)wlv->lnum;
381 else
382 {
383 // 'relativenumber', don't use negative numbers
384 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
385 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
386 {
387 // 'number' + 'relativenumber'
388 num = wlv->lnum;
389 fmt = "%-*ld ";
390 }
391 }
392
393 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100394 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100395 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
396 ++wlv->p_extra)
397 *wlv->p_extra = '-';
398#ifdef FEAT_RIGHTLEFT
399 if (wp->w_p_rl) // reverse line numbers
400 {
401 char_u *p1, *p2;
402 int t;
403
404 // like rl_mirror(), but keep the space at the end
405 p2 = skipwhite(wlv->extra);
406 p2 = skiptowhite(p2) - 1;
407 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
408 {
409 t = *p1;
410 *p1 = *p2;
411 *p2 = t;
412 }
413 }
414#endif
415 wlv->p_extra = wlv->extra;
416 wlv->c_extra = NUL;
417 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100418 }
419 else
420 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100421 wlv->c_extra = ' ';
422 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100423 }
424 wlv->n_extra = number_width(wp) + 1;
425 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
426#ifdef FEAT_SYN_HL
427 // When 'cursorline' is set highlight the line number of
428 // the current line differently.
429 // When 'cursorlineopt' does not have "line" only
430 // highlight the line number itself.
431 // TODO: Can we use CursorLine instead of CursorLineNr
432 // when CursorLineNr isn't set?
433 if (wp->w_p_cul
434 && wlv->lnum == wp->w_cursor.lnum
435 && (wp->w_p_culopt_flags & CULOPT_NBR)
436 && (wlv->row == wlv->startrow + wlv->filler_lines
437 || (wlv->row > wlv->startrow + wlv->filler_lines
438 && (wp->w_p_culopt_flags & CULOPT_LINE))))
439 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
440#endif
441 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
442 && HL_ATTR(HLF_LNA) != 0)
443 // Use LineNrAbove
444 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
445 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
446 && HL_ATTR(HLF_LNB) != 0)
447 // Use LineNrBelow
448 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
449 }
450#ifdef FEAT_SIGNS
451 if (num_attr)
452 wlv->char_attr = num_attr;
453#endif
454 }
455}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100456
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100457#ifdef FEAT_LINEBREAK
458 static void
459handle_breakindent(win_T *wp, winlinevars_T *wlv)
460{
461 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
462 && *get_showbreak_value(wp) != NUL)
463 // draw indent after showbreak value
464 wlv->draw_state = WL_BRI;
465 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
466 // After the showbreak, draw the breakindent
467 wlv->draw_state = WL_BRI - 1;
468
469 // draw 'breakindent': indent wrapped text accordingly
470 if (wlv->draw_state == WL_BRI - 1)
471 {
472 wlv->draw_state = WL_BRI;
473 // if wlv->need_showbreak is set, breakindent also applies
474 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
475# ifdef FEAT_DIFF
476 && wlv->filler_lines == 0
477# endif
478# ifdef FEAT_PROP_POPUP
479 && !wlv->dont_use_showbreak
480# endif
481 )
482 {
483 wlv->char_attr = 0;
484# ifdef FEAT_DIFF
485 if (wlv->diff_hlf != (hlf_T)0)
486 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
487# endif
488 wlv->p_extra = NULL;
489 wlv->c_extra = ' ';
490 wlv->c_final = NUL;
491 wlv->n_extra = get_breakindent_win(wp,
492 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
493 if (wlv->row == wlv->startrow)
494 {
495 wlv->n_extra -= win_col_off2(wp);
496 if (wlv->n_extra < 0)
497 wlv->n_extra = 0;
498 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100499 if (wp->w_skipcol > 0 && wlv->startrow == 0
500 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100501 wlv->need_showbreak = FALSE;
502 // Correct end of highlighted area for 'breakindent',
503 // required when 'linebreak' is also set.
504 if (wlv->tocol == wlv->vcol)
505 wlv->tocol += wlv->n_extra;
506 }
507 }
508}
509#endif
510
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100511#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
512 static void
513handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
514{
515# ifdef FEAT_DIFF
516 if (wlv->filler_todo > 0)
517 {
518 // Draw "deleted" diff line(s).
519 if (char2cells(wp->w_fill_chars.diff) > 1)
520 {
521 wlv->c_extra = '-';
522 wlv->c_final = NUL;
523 }
524 else
525 {
526 wlv->c_extra = wp->w_fill_chars.diff;
527 wlv->c_final = NUL;
528 }
529# ifdef FEAT_RIGHTLEFT
530 if (wp->w_p_rl)
531 wlv->n_extra = wlv->col + 1;
532 else
533# endif
534 wlv->n_extra = wp->w_width - wlv->col;
535 wlv->char_attr = HL_ATTR(HLF_DED);
536 }
537# endif
538
539# ifdef FEAT_LINEBREAK
540 char_u *sbr = get_showbreak_value(wp);
541 if (*sbr != NUL && wlv->need_showbreak)
542 {
543 // Draw 'showbreak' at the start of each broken line.
544 wlv->p_extra = sbr;
545 wlv->c_extra = NUL;
546 wlv->c_final = NUL;
547 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100548 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100549 wlv->need_showbreak = FALSE;
550 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
551 // Correct end of highlighted area for 'showbreak',
552 // required when 'linebreak' is also set.
553 if (wlv->tocol == wlv->vcol)
554 wlv->tocol += wlv->n_extra;
555 // combine 'showbreak' with 'wincolor'
556 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
557# ifdef FEAT_SYN_HL
558 // combine 'showbreak' with 'cursorline'
559 if (wlv->cul_attr != 0)
560 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
561# endif
562 }
563# endif
564}
565#endif
566
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100567#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100568/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100569 * Return the cell size of virtual text after truncation.
570 */
571 static int
572textprop_size_after_trunc(
573 win_T *wp,
574 int flags, // TP_FLAG_ALIGN_*
575 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100576 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100577 char_u *text,
578 int *n_used_ptr)
579{
580 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100581 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100582 int len = (int)STRLEN(text);
583 int strsize = 0;
584 int n_used;
585
586 // if the remaining size is to small wrap anyway and use the next line
587 if (space < PROP_TEXT_MIN_CELLS)
588 space += wp->w_width;
Bram Moolenaar13845c42022-10-09 15:26:03 +0100589 if (flags & TP_FLAG_ALIGN_BELOW)
590 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100591 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
592 {
593 int clen = ptr2cells(text + n_used);
594
595 if (strsize + clen > space)
596 break;
597 strsize += clen;
598 }
599 *n_used_ptr = n_used;
600 return strsize;
601}
602
603/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100604 * Take care of padding, right-align and truncation of virtual text after a
605 * line.
606 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
607 * padding, right-align and truncation. Otherwise only the size is computed.
608 * When "n_attr" is NULL returns the number of screen cells used.
609 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100610 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100611 int
612text_prop_position(
613 win_T *wp,
614 textprop_T *tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100615 int vcol UNUSED, // current text column
616 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100617 int *n_extra, // nr of bytes for virtual text
618 char_u **p_extra, // virtual text
619 int *n_attr, // attribute cells, NULL if not used
620 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200621{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100622 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100623 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100624 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
625 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
626 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
627 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100628 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100629 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100630 int before = room; // spaces before the text
631 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100632 int n_used = *n_extra;
633 char_u *l = NULL;
634 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100635 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100636 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar1206c162022-10-10 15:40:04 +0100637 int cont_on_next_line = below && col_with_padding > win_col_off(wp)
638 && !wp->w_p_wrap;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200639
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100640 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100641 {
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100642 int col_off = win_col_off(wp) + win_col_off2(wp);
643 int skip_add = 0;
644
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100645 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100646 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100647 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100648 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100649 }
650 else
651 {
652 // Right-align: fill with before
653 if (right)
654 before -= cells;
655 if (before < 0
656 || !(right || below)
657 || (below
658 ? (col_with_padding == 0 || !wp->w_p_wrap)
659 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100660 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100661 if (right && (wrap || room < PROP_TEXT_MIN_CELLS))
662 {
663 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100664 before = wp->w_width - col_off - strsize + room;
665 if (before < 0)
666 before = 0;
667 else
668 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100669 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100670 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100671 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100672 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100673 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100674 else if (below && before > 0)
675 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100676 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100677 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100678
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100679 // With 'nowrap' add one to show the "extends" character if needed (it
680 // doesn't show if the text just fits).
681 if (!wp->w_p_wrap
682 && n_used < *n_extra
683 && wp->w_lcs_chars.ext != NUL
684 && wp->w_p_list)
685 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100686 if (!wp->w_p_wrap && below && padding > 0)
687 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100688
689 // add 1 for NUL, 2 for when '…' is used
690 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100691 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100692 if (n_attr == NULL || l != NULL)
693 {
694 int off = 0;
695
696 if (n_attr != NULL)
697 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100698 vim_memset(l, ' ', before);
699 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100700 if (padding > 0)
701 {
702 vim_memset(l + off, ' ', padding);
703 off += padding;
704 }
705 vim_strncpy(l + off, *p_extra, n_used);
706 off += n_used;
707 }
708 else
709 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100710 off = before + after + padding + n_used;
711 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100712 }
713 if (n_attr != NULL)
714 {
715 if (n_used < *n_extra && wp->w_p_wrap)
716 {
717 char_u *lp = l + off - 1;
718
719 if (has_mbyte)
720 {
721 // change last character to '…'
722 lp -= (*mb_head_off)(l, lp);
723 STRCPY(lp, "…");
Bram Moolenaar13845c42022-10-09 15:26:03 +0100724 n_used = lp - l + 3 - before - padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100725 }
726 else
727 // change last character to '>'
728 *lp = '>';
729 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100730 else if (after > 0)
731 {
732 vim_memset(l + off, ' ', after);
733 l[off + after] = NUL;
734 }
735
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100736 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100737 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100738 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100739 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100740 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100741
742 // Add "skip_add" when starting a new line or wrapping,
743 // n_attr_skip will then be decremented in the number column.
744 *n_attr_skip = before + padding
745 + (cont_on_next_line || before > 0 ? skip_add : 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100746 }
747 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100748 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100749
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100750 if (n_attr == NULL)
751 return cells;
752 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200753}
754#endif
755
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100756/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100757 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100758 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
759 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100760 */
761 static void
762wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
763{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100764 if (wlv->row == 0 && wp->w_skipcol > 0
765#if defined(FEAT_LINEBREAK)
766 && *get_showbreak_value(wp) == NUL
767#endif
768 )
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100769 {
770 int off = (int)(current_ScreenLine - ScreenLines);
771
772 for (int i = 0; i < 3; ++i)
773 {
774 ScreenLines[off] = '<';
775 if (enc_utf8)
776 ScreenLinesUC[off] = 0;
777 ScreenAttrs[off] = HL_ATTR(HLF_AT);
778 ++off;
779 }
780 }
781
782 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
783 negative_width ? -wp->w_width : wp->w_width,
784 wlv->screen_line_flags);
785}
786
787/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100788 * Called when finished with the line: draw the screen line and handle any
789 * highlighting until the right of the window.
790 */
791 static void
792draw_screen_line(win_T *wp, winlinevars_T *wlv)
793{
794#ifdef FEAT_SYN_HL
795 long v;
796
797 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
798 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100799 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100800 else
801 v = wp->w_leftcol;
802
803 // check if line ends before left margin
804 if (wlv->vcol < v + wlv->col - win_col_off(wp))
805 wlv->vcol = v + wlv->col - win_col_off(wp);
806# ifdef FEAT_CONCEAL
807 // Get rid of the boguscols now, we want to draw until the right
808 // edge for 'cursorcolumn'.
809 wlv->col -= wlv->boguscols;
810 wlv->boguscols = 0;
811# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
812# else
813# define VCOL_HLC (wlv->vcol)
814# endif
815
816 if (wlv->draw_color_col)
817 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
818
819 if (((wp->w_p_cuc
820 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
821 && (int)wp->w_virtcol <
822 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
823 && wlv->lnum != wp->w_cursor.lnum)
824 || wlv->draw_color_col
825 || wlv->win_attr != 0)
826# ifdef FEAT_RIGHTLEFT
827 && !wp->w_p_rl
828# endif
829 )
830 {
831 int rightmost_vcol = 0;
832 int i;
833
834 if (wp->w_p_cuc)
835 rightmost_vcol = wp->w_virtcol;
836 if (wlv->draw_color_col)
837 // determine rightmost colorcolumn to possibly draw
838 for (i = 0; wlv->color_cols[i] >= 0; ++i)
839 if (rightmost_vcol < wlv->color_cols[i])
840 rightmost_vcol = wlv->color_cols[i];
841
842 while (wlv->col < wp->w_width)
843 {
844 ScreenLines[wlv->off] = ' ';
845 if (enc_utf8)
846 ScreenLinesUC[wlv->off] = 0;
847 ScreenCols[wlv->off] = MAXCOL;
848 ++wlv->col;
849 if (wlv->draw_color_col)
850 wlv->draw_color_col = advance_color_col(
851 VCOL_HLC, &wlv->color_cols);
852
853 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
854 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
855 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
856 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
857 else
858 ScreenAttrs[wlv->off++] = wlv->win_attr;
859
860 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
861 break;
862
863 ++wlv->vcol;
864 }
865 }
866#endif
867
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100868 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100869 ++wlv->row;
870 ++wlv->screen_row;
871}
872#undef VCOL_HLC
873
874/*
875 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100876 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100877 */
878 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100879win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100880{
881 wlv->col = 0;
882 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
883
884#ifdef FEAT_RIGHTLEFT
885 if (wp->w_p_rl)
886 {
887 // Rightleft window: process the text in the normal direction, but put
888 // it in current_ScreenLine[] from right to left. Start at the
889 // rightmost column of the window.
890 wlv->col = wp->w_width - 1;
891 wlv->off += wlv->col;
892 wlv->screen_line_flags |= SLF_RIGHTLEFT;
893 }
894#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100895 if (save_extra)
896 {
897 // reset the drawing state for the start of a wrapped line
898 wlv->draw_state = WL_START;
899 wlv->saved_n_extra = wlv->n_extra;
900 wlv->saved_p_extra = wlv->p_extra;
901 wlv->saved_c_extra = wlv->c_extra;
902 wlv->saved_c_final = wlv->c_final;
903#ifdef FEAT_SYN_HL
904 if (!(wlv->cul_screenline
905# ifdef FEAT_DIFF
906 && wlv->diff_hlf == (hlf_T)0
907# endif
908 ))
909 wlv->saved_char_attr = wlv->char_attr;
910 else
911#endif
912 wlv->saved_char_attr = 0;
913 wlv->n_extra = 0;
914 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100915}
916
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200917/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100918 * Called when wlv->draw_state is set to WL_LINE.
919 */
920 static void
921win_line_continue(winlinevars_T *wlv)
922{
923 if (wlv->saved_n_extra > 0)
924 {
925 // Continue item from end of wrapped line.
926 wlv->n_extra = wlv->saved_n_extra;
927 wlv->c_extra = wlv->saved_c_extra;
928 wlv->c_final = wlv->saved_c_final;
929 wlv->p_extra = wlv->saved_p_extra;
930 wlv->char_attr = wlv->saved_char_attr;
931 }
932 else
933 wlv->char_attr = wlv->win_attr;
934}
935
936/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200937 * Display line "lnum" of window 'wp' on the screen.
938 * Start at row "startrow", stop when "endrow" is reached.
939 * wp->w_virtcol needs to be valid.
940 *
941 * Return the number of last row the line occupies.
942 */
943 int
944win_line(
945 win_T *wp,
946 linenr_T lnum,
947 int startrow,
948 int endrow,
949 int nochange UNUSED, // not updating for changed text
950 int number_only) // only update the number column
951{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100952 winlinevars_T wlv; // variables passed between functions
953
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200954 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100955 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200956 char_u *line; // current line
957 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200958
Bram Moolenaar1306b362022-08-06 15:59:06 +0100959#ifdef FEAT_PROP_POPUP
960 char_u *p_extra_free2 = NULL; // another p_extra to be freed
961#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200962 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000963#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000964 int in_linebreak = FALSE; // n_extra set for showing linebreak
965#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200966 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100967 // displaying eol at end-of-line
968 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000969 int lcs_prec_todo = wp->w_lcs_chars.prec;
970 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200971
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100972 int n_attr = 0; // chars with special attr
973 int n_attr_skip = 0; // chars to skip before using extra_attr
974 int saved_attr2 = 0; // char_attr saved for n_attr
975 int n_attr3 = 0; // chars with overruling special attr
976 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200977
Bram Moolenaarcd105412022-10-10 19:50:42 +0100978 int n_skip = 0; // nr of cells to skip for 'nowrap' or
979 // concealing
980 int skip_cells = 0; // nr of cells to skip for virtual text
981 // after the line, when w_skipcol is
982 // larger than the text length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200983
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200984 int fromcol_prev = -2; // start of inverting after cursor
985 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200986 int lnum_in_visual_area = FALSE;
987 pos_T pos;
988 long v;
989
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200990 int attr_pri = FALSE; // char_attr has priority
991 int area_highlighting = FALSE; // Visual or incsearch highlighting
992 // in this line
993 int vi_attr = 0; // attributes for Visual and incsearch
994 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200995 int area_attr = 0; // attributes desired by highlighting
996 int search_attr = 0; // attributes desired by 'hlsearch'
997#ifdef FEAT_SYN_HL
998 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
999 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001000 int prev_syntax_col = -1; // column of prev_syntax_attr
1001 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001002 int has_syntax = FALSE; // this buffer has syntax highl.
1003 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001004#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001005#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001006 int text_prop_count;
1007 int text_prop_next = 0; // next text property to use
1008 textprop_T *text_props = NULL;
1009 int *text_prop_idxs = NULL;
1010 int text_props_active = 0;
1011 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001012 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001013 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001014 int text_prop_attr_comb = 0; // text_prop_attr combined with
1015 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001016 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001017 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001018 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001019 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001020 int saved_search_attr = 0; // search_attr to be used when n_extra
1021 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001022 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001023#endif
1024#ifdef FEAT_SPELL
1025 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001026 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001027# define SPWORDLEN 150
1028 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1029 int nextlinecol = 0; // column where nextline[] starts
1030 int nextline_idx = 0; // index in nextline[] where next line
1031 // starts
1032 int spell_attr = 0; // attributes desired by spelling
1033 int word_end = 0; // last byte with same spell_attr
1034 static linenr_T checked_lnum = 0; // line number for "checked_col"
1035 static int checked_col = 0; // column in "checked_lnum" up to which
1036 // there are no spell errors
1037 static int cap_col = -1; // column to check for Cap word
1038 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1039 int cur_checked_col = 0; // checked column for current line
1040#endif
1041 int extra_check = 0; // has extra highlighting
1042 int multi_attr = 0; // attributes desired by multibyte
1043 int mb_l = 1; // multi-byte byte length
1044 int mb_c = 0; // decoded multi-byte character
1045 int mb_utf8 = FALSE; // screen char is UTF-8 char
1046 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001047#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001048 int change_start = MAXCOL; // first col of changed area
1049 int change_end = -1; // last col of changed area
1050#endif
1051 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001052 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001053 int in_multispace = FALSE; // in multiple consecutive spaces
1054 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001055#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
1056 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
1057# define LINE_ATTR
1058 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +01001059 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001060#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001061 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001062 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001063#ifdef FEAT_ARABIC
1064 int prev_c = 0; // previous Arabic character
1065 int prev_c1 = 0; // first composing char for prev_c
1066#endif
1067#if defined(LINE_ATTR)
1068 int did_line_attr = 0;
1069#endif
1070#ifdef FEAT_TERMINAL
1071 int get_term_attr = FALSE;
1072#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001073
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001074#ifdef FEAT_SYN_HL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001075 // margin columns for the screen line, needed for when 'cursorlineopt'
1076 // contains "screenline"
1077 int left_curline_col = 0;
1078 int right_curline_col = 0;
1079#endif
1080
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001081#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1082 int feedback_col = 0;
1083 int feedback_old_attr = -1;
1084#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001085
1086#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1087 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001088 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001089#endif
1090#ifdef FEAT_CONCEAL
1091 int syntax_flags = 0;
1092 int syntax_seqnr = 0;
1093 int prev_syntax_id = 0;
1094 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1095 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001096 int did_wcol = FALSE;
1097 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001098# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001099# define FIX_FOR_BOGUSCOLS \
1100 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001101 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001102 wlv.vcol -= wlv.vcol_off; \
1103 wlv.vcol_off = 0; \
1104 wlv.col -= wlv.boguscols; \
1105 old_boguscols = wlv.boguscols; \
1106 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001107 }
1108#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001109# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001110#endif
1111
1112 if (startrow > endrow) // past the end already!
1113 return startrow;
1114
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001115 CLEAR_FIELD(wlv);
1116
1117 wlv.lnum = lnum;
1118 wlv.startrow = startrow;
1119 wlv.row = startrow;
1120 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001121 wlv.fromcol = -10;
1122 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001123#ifdef FEAT_LINEBREAK
1124 wlv.vcol_sbr = -1;
1125#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001126
1127 if (!number_only)
1128 {
1129 // To speed up the loop below, set extra_check when there is linebreak,
1130 // trailing white space and/or syntax processing to be done.
1131#ifdef FEAT_LINEBREAK
1132 extra_check = wp->w_p_lbr;
1133#endif
1134#ifdef FEAT_SYN_HL
1135 if (syntax_present(wp) && !wp->w_s->b_syn_error
1136# ifdef SYN_TIME_LIMIT
1137 && !wp->w_s->b_syn_slow
1138# endif
1139 )
1140 {
1141 // Prepare for syntax highlighting in this line. When there is an
1142 // error, stop syntax highlighting.
1143 save_did_emsg = did_emsg;
1144 did_emsg = FALSE;
1145 syntax_start(wp, lnum);
1146 if (did_emsg)
1147 wp->w_s->b_syn_error = TRUE;
1148 else
1149 {
1150 did_emsg = save_did_emsg;
1151#ifdef SYN_TIME_LIMIT
1152 if (!wp->w_s->b_syn_slow)
1153#endif
1154 {
1155 has_syntax = TRUE;
1156 extra_check = TRUE;
1157 }
1158 }
1159 }
1160
1161 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001162 wlv.color_cols = wp->w_p_cc_cols;
1163 if (wlv.color_cols != NULL)
1164 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001165#endif
1166
1167#ifdef FEAT_TERMINAL
1168 if (term_show_buffer(wp->w_buffer))
1169 {
1170 extra_check = TRUE;
1171 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001172 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001173 }
1174#endif
1175
1176#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001177 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001178 {
1179 // Prepare for spell checking.
1180 has_spell = TRUE;
1181 extra_check = TRUE;
1182
1183 // Get the start of the next line, so that words that wrap to the
1184 // next line are found too: "et<line-break>al.".
1185 // Trick: skip a few chars for C/shell/Vim comments
1186 nextline[SPWORDLEN] = NUL;
1187 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1188 {
1189 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1190 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1191 }
1192
1193 // When a word wrapped from the previous line the start of the
1194 // current line is valid.
1195 if (lnum == checked_lnum)
1196 cur_checked_col = checked_col;
1197 checked_lnum = 0;
1198
1199 // When there was a sentence end in the previous line may require a
1200 // word starting with capital in this line. In line 1 always check
1201 // the first word.
1202 if (lnum != capcol_lnum)
1203 cap_col = -1;
1204 if (lnum == 1)
1205 cap_col = 0;
1206 capcol_lnum = 0;
1207 }
1208#endif
1209
1210 // handle Visual active in this window
1211 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1212 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001213 pos_T *top, *bot;
1214
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001215 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1216 {
1217 // Visual is after curwin->w_cursor
1218 top = &curwin->w_cursor;
1219 bot = &VIsual;
1220 }
1221 else
1222 {
1223 // Visual is before curwin->w_cursor
1224 top = &VIsual;
1225 bot = &curwin->w_cursor;
1226 }
1227 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1228 if (VIsual_mode == Ctrl_V)
1229 {
1230 // block mode
1231 if (lnum_in_visual_area)
1232 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001233 wlv.fromcol = wp->w_old_cursor_fcol;
1234 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001235 }
1236 }
1237 else
1238 {
1239 // non-block mode
1240 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001241 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001242 else if (lnum == top->lnum)
1243 {
1244 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001245 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001246 else
1247 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001248 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001249 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001250 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001251 }
1252 }
1253 if (VIsual_mode != 'V' && lnum == bot->lnum)
1254 {
1255 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1256 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001257 wlv.fromcol = -10;
1258 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001259 }
1260 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001261 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001262 else
1263 {
1264 pos = *bot;
1265 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001266 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1267 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001268 else
1269 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001270 getvvcol(wp, &pos, NULL, NULL,
1271 (colnr_T *)&wlv.tocol);
1272 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001273 }
1274 }
1275 }
1276 }
1277
1278 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001279 if (!highlight_match && lnum == curwin->w_cursor.lnum
1280 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001281#ifdef FEAT_GUI
1282 && !gui.in_use
1283#endif
1284 )
1285 noinvcur = TRUE;
1286
1287 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001288 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001289 {
1290 area_highlighting = TRUE;
1291 vi_attr = HL_ATTR(HLF_V);
1292#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1293 if ((clip_star.available && !clip_star.owned
1294 && clip_isautosel_star())
1295 || (clip_plus.available && !clip_plus.owned
1296 && clip_isautosel_plus()))
1297 vi_attr = HL_ATTR(HLF_VNC);
1298#endif
1299 }
1300 }
1301
1302 // handle 'incsearch' and ":s///c" highlighting
1303 else if (highlight_match
1304 && wp == curwin
1305 && lnum >= curwin->w_cursor.lnum
1306 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1307 {
1308 if (lnum == curwin->w_cursor.lnum)
1309 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001310 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001311 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001312 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001313 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1314 {
1315 pos.lnum = lnum;
1316 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001317 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001318 }
1319 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001320 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001321 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001322 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1323 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001324 area_highlighting = TRUE;
1325 vi_attr = HL_ATTR(HLF_I);
1326 }
1327 }
1328
1329#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001330 wlv.filler_lines = diff_check(wp, lnum);
1331 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001332 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001333 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001334 {
1335 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001336 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001337 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001338 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001339 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001340 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001341 }
1342 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001343 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001344 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001345 area_highlighting = TRUE;
1346 }
1347 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001348 wlv.filler_lines = wp->w_topfill;
1349 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001350#endif
1351
1352#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001353 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001354 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001355 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001356#endif
1357
1358#ifdef LINE_ATTR
1359# ifdef FEAT_SIGNS
1360 // If this line has a sign with line highlighting set line_attr.
1361 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001362 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001363# endif
1364# if defined(FEAT_QUICKFIX)
1365 // Highlight the current line in the quickfix window.
1366 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1367 line_attr = HL_ATTR(HLF_QFL);
1368# endif
1369 if (line_attr != 0)
1370 area_highlighting = TRUE;
1371#endif
1372
1373 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1374 ptr = line;
1375
1376#ifdef FEAT_SPELL
1377 if (has_spell && !number_only)
1378 {
1379 // For checking first word with a capital skip white space.
1380 if (cap_col == 0)
1381 cap_col = getwhitecols(line);
1382
1383 // To be able to spell-check over line boundaries copy the end of the
1384 // current line into nextline[]. Above the start of the next line was
1385 // copied to nextline[SPWORDLEN].
1386 if (nextline[SPWORDLEN] == NUL)
1387 {
1388 // No next line or it is empty.
1389 nextlinecol = MAXCOL;
1390 nextline_idx = 0;
1391 }
1392 else
1393 {
1394 v = (long)STRLEN(line);
1395 if (v < SPWORDLEN)
1396 {
1397 // Short line, use it completely and append the start of the
1398 // next line.
1399 nextlinecol = 0;
1400 mch_memmove(nextline, line, (size_t)v);
1401 STRMOVE(nextline + v, nextline + SPWORDLEN);
1402 nextline_idx = v + 1;
1403 }
1404 else
1405 {
1406 // Long line, use only the last SPWORDLEN bytes.
1407 nextlinecol = v - SPWORDLEN;
1408 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1409 nextline_idx = SPWORDLEN + 1;
1410 }
1411 }
1412 }
1413#endif
1414
1415 if (wp->w_p_list)
1416 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001417 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001418 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001419 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001420 || wp->w_lcs_chars.trail
1421 || wp->w_lcs_chars.lead
1422 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001423 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001424
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001425 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001426 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001427 {
1428 trailcol = (colnr_T)STRLEN(ptr);
1429 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1430 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001431 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001432 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001433 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001434 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001435 {
1436 leadcol = 0;
1437 while (VIM_ISWHITE(ptr[leadcol]))
1438 ++leadcol;
1439 if (ptr[leadcol] == NUL)
1440 // in a line full of spaces all of them are treated as trailing
1441 leadcol = (colnr_T)0;
1442 else
1443 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001444 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001445 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001446 }
1447
Bram Moolenaard7657e92022-09-20 18:59:30 +01001448 wlv.wcr_attr = get_wcr_attr(wp);
1449 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001450 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001451 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001452 area_highlighting = TRUE;
1453 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001454
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001455#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001456 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001457 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001458#endif
1459
1460 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1461 // first character to be displayed.
1462 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001463 v = startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001464 else
1465 v = wp->w_leftcol;
1466 if (v > 0 && !number_only)
1467 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001468 char_u *prev_ptr = ptr;
1469 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001470 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001471
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001472 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001473 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001474 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001475 charsize = win_lbr_chartabsize(&cts, NULL);
1476 cts.cts_vcol += charsize;
1477 prev_ptr = cts.cts_ptr;
1478 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001479 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001480 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001481 ptr = cts.cts_ptr;
1482 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001483
1484 // When:
1485 // - 'cuc' is set, or
1486 // - 'colorcolumn' is set, or
1487 // - 'virtualedit' is set, or
1488 // - the visual mode is active,
1489 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001490 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001491#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001492 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001493#endif
1494 virtual_active() ||
1495 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001496 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001497
1498 // Handle a character that's not completely on the screen: Put ptr at
1499 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001500 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001501 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001502 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001503 ptr = prev_ptr;
1504 // If the character fits on the screen, don't need to skip it.
1505 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001506 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1507 && wlv.col == 0)
1508 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001509 }
1510
Bram Moolenaarcd105412022-10-10 19:50:42 +01001511 // If there the text doesn't reach to the desired column, need to skip
1512 // "skip_cells" cells when virtual text follows.
1513 if (!wp->w_p_wrap && v > wlv.vcol)
1514 skip_cells = v - wlv.vcol;
1515
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001516 // Adjust for when the inverted text is before the screen,
1517 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001518 if (wlv.tocol <= wlv.vcol)
1519 wlv.fromcol = 0;
1520 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1521 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001522
1523#ifdef FEAT_LINEBREAK
1524 // When w_skipcol is non-zero, first line needs 'showbreak'
1525 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001526 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001527#endif
1528#ifdef FEAT_SPELL
1529 // When spell checking a word we need to figure out the start of the
1530 // word and if it's badly spelled or not.
1531 if (has_spell)
1532 {
1533 int len;
1534 colnr_T linecol = (colnr_T)(ptr - line);
1535 hlf_T spell_hlf = HLF_COUNT;
1536
1537 pos = wp->w_cursor;
1538 wp->w_cursor.lnum = lnum;
1539 wp->w_cursor.col = linecol;
1540 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1541
1542 // spell_move_to() may call ml_get() and make "line" invalid
1543 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1544 ptr = line + linecol;
1545
1546 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1547 {
1548 // no bad word found at line start, don't check until end of a
1549 // word
1550 spell_hlf = HLF_COUNT;
1551 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1552 }
1553 else
1554 {
1555 // bad word found, use attributes until end of word
1556 word_end = wp->w_cursor.col + len + 1;
1557
1558 // Turn index into actual attributes.
1559 if (spell_hlf != HLF_COUNT)
1560 spell_attr = highlight_attr[spell_hlf];
1561 }
1562 wp->w_cursor = pos;
1563
1564# ifdef FEAT_SYN_HL
1565 // Need to restart syntax highlighting for this line.
1566 if (has_syntax)
1567 syntax_start(wp, lnum);
1568# endif
1569 }
1570#endif
1571 }
1572
1573 // Correct highlighting for cursor that can't be disabled.
1574 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001575 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001576 {
1577 if (noinvcur)
1578 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001579 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001580 {
1581 // highlighting starts at cursor, let it start just after the
1582 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001583 fromcol_prev = wlv.fromcol;
1584 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001585 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001586 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001587 // restart highlighting after the cursor
1588 fromcol_prev = wp->w_virtcol;
1589 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001590 if (wlv.fromcol >= wlv.tocol)
1591 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001592 }
1593
1594#ifdef FEAT_SEARCH_EXTRA
1595 if (!number_only)
1596 {
1597 v = (long)(ptr - line);
1598 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1599 &line, &screen_search_hl,
1600 &search_attr);
1601 ptr = line + v; // "line" may have been updated
1602 }
1603#endif
1604
1605#ifdef FEAT_SYN_HL
1606 // Cursor line highlighting for 'cursorline' in the current window.
1607 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1608 {
1609 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001610 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001611 if (!(wp == curwin && VIsual_active)
1612 && wp->w_p_culopt_flags != CULOPT_NBR)
1613 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001614 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001615 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1616
1617 // Only set line_attr here when "screenline" is not present in
1618 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001619 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001620 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001621 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001622# ifdef FEAT_SIGNS
1623 // Combine the 'cursorline' and sign highlighting, depending on
1624 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001625 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001626 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001627 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001628 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001629 else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001630 line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001631 }
1632 else
1633# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001634# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001635 // let the line attribute overrule 'cursorline', otherwise
1636 // it disappears when both have background set;
1637 // 'cursorline' can use underline or bold to make it show
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001638 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001639# else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001640 line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001641# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001642 }
1643 else
1644 {
1645 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001646 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1647 }
1648 area_highlighting = TRUE;
1649 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001650 }
1651#endif
1652
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001653#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001654 {
1655 char_u *prop_start;
1656
1657 text_prop_count = get_text_props(wp->w_buffer, lnum,
1658 &prop_start, FALSE);
1659 if (text_prop_count > 0)
1660 {
1661 // Make a copy of the properties, so that they are properly
1662 // aligned.
1663 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1664 if (text_props != NULL)
1665 mch_memmove(text_props, prop_start,
1666 text_prop_count * sizeof(textprop_T));
1667
1668 // Allocate an array for the indexes.
1669 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001670 if (text_prop_idxs == NULL)
1671 VIM_CLEAR(text_props);
1672
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001673 if (text_props != NULL)
1674 {
1675 area_highlighting = TRUE;
1676 extra_check = TRUE;
1677 for (int i = 0; i < text_prop_count; ++i)
1678 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1679 ++wlv.text_prop_above_count;
1680 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001681 }
1682 }
1683#endif
1684
Bram Moolenaar1306b362022-08-06 15:59:06 +01001685 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001686
1687 // Repeat for the whole displayed line.
1688 for (;;)
1689 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001690 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001691#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001692 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001693#endif
1694#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001695 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001696#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001697
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001698 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001699 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001700 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001701#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001702 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001703 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001704 wlv.cul_attr = 0;
zeertzjq4f33bc22021-08-05 17:57:02 +02001705 line_attr = line_attr_save;
1706 }
1707#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001708 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001709 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001710 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001711 if (cmdwin_type != 0 && wp == curwin)
1712 {
1713 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001714 wlv.n_extra = 1;
1715 wlv.c_extra = cmdwin_type;
1716 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001717 wlv.char_attr =
1718 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001719 }
1720 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001721#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001722 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001723 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001724 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001725 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001726 }
1727#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001728#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001729 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001730 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001731 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001732 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001733 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001734 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001735 }
1736#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001737 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001738 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001739 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001740 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001741 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001742 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001743#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001744 // Check if 'breakindent' applies and show it.
1745 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1746 if (wlv.n_extra == 0)
1747 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001748#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001749#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001750 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001751 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001752 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001753 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001754 }
1755#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001756 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001757 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001758 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001759 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001760 }
1761 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001762
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001763#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001764 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001765 && wlv.vcol >= left_curline_col
1766 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001767 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001768 wlv.cul_attr = HL_ATTR(HLF_CUL);
1769 line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001770 }
1771#endif
1772
1773 // When still displaying '$' of change command, stop at cursor.
1774 // When only displaying the (relative) line number and that's done,
1775 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001776 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001777 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001778 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001779#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001780 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001781#endif
1782 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001783 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001784 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001785 // Pretend we have finished updating the window. Except when
1786 // 'cursorcolumn' is set.
1787#ifdef FEAT_SYN_HL
1788 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001789 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001790 else
1791#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001792 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001793 break;
1794 }
1795
Bram Moolenaar1306b362022-08-06 15:59:06 +01001796 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001797 {
1798 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001799 if (wlv.vcol == wlv.fromcol
1800 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1801 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001802 && (*mb_ptr2cells)(ptr) > 1)
1803 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001804 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001805 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001806 area_attr = vi_attr; // start highlighting
1807 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001808 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001809 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001810 area_attr = 0; // stop highlighting
1811
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001812#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001813 if (text_props != NULL)
1814 {
1815 int pi;
1816 int bcol = (int)(ptr - line);
1817
Bram Moolenaar1306b362022-08-06 15:59:06 +01001818 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001819# ifdef FEAT_LINEBREAK
1820 && !in_linebreak
1821# endif
1822 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001823 --bcol; // still working on the previous char, e.g. Tab
1824
1825 // Check if any active property ends.
1826 for (pi = 0; pi < text_props_active; ++pi)
1827 {
1828 int tpi = text_prop_idxs[pi];
1829
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001830 if (text_props[tpi].tp_col != MAXCOL
1831 && bcol >= text_props[tpi].tp_col - 1
1832 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001833 {
1834 if (pi + 1 < text_props_active)
1835 mch_memmove(text_prop_idxs + pi,
1836 text_prop_idxs + pi + 1,
1837 sizeof(int)
1838 * (text_props_active - (pi + 1)));
1839 --text_props_active;
1840 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001841# ifdef FEAT_LINEBREAK
1842 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001843 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001844 syntax_attr = 0;
1845# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001846 }
1847 }
1848
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001849# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001850 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001851 // not on the next char yet, don't start another prop
1852 --bcol;
1853# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001854 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001855 // With 'nowrap' and not in the first screen line only "below"
1856 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001857 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001858 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001859 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001860 && (wp->w_p_wrap
1861 || wlv.row == startrow
1862 || (text_props[text_prop_next].tp_flags
1863 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001864 || (bcol == 0 &&
1865 (text_props[text_prop_next].tp_flags
1866 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001867 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001868 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001869 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001870 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1871 {
1872 // first display the '$' after the line
1873 text_prop_follows = TRUE;
1874 break;
1875 }
1876 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001877 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001878 + text_props[text_prop_next].tp_len)
1879 text_prop_idxs[text_props_active++] = text_prop_next;
1880 ++text_prop_next;
1881 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001882
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001883 if (wlv.n_extra == 0 || !extra_for_textprop)
1884 {
1885 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001886 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001887 text_prop_flags = 0;
1888 text_prop_type = NULL;
1889 text_prop_id = 0;
1890 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001891 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001892 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001893 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001894 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001895 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001896
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001897 // Sort the properties on priority and/or starting last.
1898 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001899 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001900 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001901 sort_text_props(wp->w_buffer, text_props,
1902 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001903
1904 for (pi = 0; pi < text_props_active; ++pi)
1905 {
1906 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001907 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001908 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01001909 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001910
Bram Moolenaarcd105412022-10-10 19:50:42 +01001911 // Only use a text property that can be displayed.
1912 // Skip "after" properties when wrap is off and at the
1913 // end of the window.
1914 if (pt != NULL
1915 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
1916 && tp->tp_id != -MAXCOL
1917 && !(tp->tp_id < 0
1918 && !wp->w_p_wrap
1919 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
1920 | TP_FLAG_ALIGN_ABOVE
1921 | TP_FLAG_ALIGN_BELOW)) == 0
1922 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001923 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001924 if (pt->pt_hl_id > 0)
1925 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001926 text_prop_type = pt;
1927 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001928 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001929 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001930 text_prop_flags = pt->pt_flags;
1931 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001932 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001933 }
1934 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001935 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001936 && -text_prop_id
1937 <= wp->w_buffer->b_textprop_text.ga_len)
1938 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001939 textprop_T *tp = &text_props[used_tpi];
1940 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001941 ->b_textprop_text.ga_data)[
1942 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001943 int above = (tp->tp_flags
1944 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01001945 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001946
1947 // reset the ID in the copy to avoid it being used
1948 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001949 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001950
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001951 if (p != NULL)
1952 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001953 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001954 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001955 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001956 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001957 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1958 int padding = tp->tp_col == MAXCOL
1959 && tp->tp_len > 1
1960 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001961
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001962 // Insert virtual text before the current
1963 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001964 wlv.p_extra = p;
1965 wlv.c_extra = NUL;
1966 wlv.c_final = NUL;
1967 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001968 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001969 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001970 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001971 // restore search_attr and area_attr when n_extra
1972 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001973 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001974 saved_area_attr = area_attr;
1975 search_attr = 0;
1976 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001977 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001978 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001979 if (*ptr == NUL)
1980 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001981 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001982#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001983 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001984 {
1985 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001986 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001987 wlv.need_showbreak = FALSE;
1988 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001989 }
1990#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001991 if ((right || above || below || !wrap
1992 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001993 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001994 char_u *prev_p_extra = wlv.p_extra;
1995 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001996
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001997 // Take care of padding, right-align and
1998 // truncation.
1999 // Shared with win_lbr_chartabsize(), must do
2000 // exactly the same.
2001 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002002 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002003 wlv.col,
2004 &wlv.n_extra, &wlv.p_extra,
2005 &n_attr, &n_attr_skip);
2006 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002007 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002008 // wlv.p_extra was allocated
2009 vim_free(p_extra_free2);
2010 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002011 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002012
Bram Moolenaara4abe512022-09-15 19:44:09 +01002013 if (lcs_eol_one < 0 && wlv.col
2014 + wlv.n_extra - 2 > wp->w_width)
2015 // don't bail out at end of line
2016 lcs_eol_one = 0;
2017
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002018 // When 'wrap' is off then for "below" we need
2019 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002020 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002021 {
2022 draw_screen_line(wp, &wlv);
2023
2024 // When line got too long for screen break
2025 // here.
2026 if (wlv.row == endrow)
2027 {
2028 ++wlv.row;
2029 break;
2030 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002031 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002032 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002033 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002034 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002035 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002036
Bram Moolenaarcd105412022-10-10 19:50:42 +01002037 // If the text didn't reach until the first window
2038 // column we need to skip cells.
2039 if (skip_cells > 0)
2040 {
2041 if (wlv.n_extra > skip_cells)
2042 {
2043 wlv.n_extra -= skip_cells;
2044 wlv.p_extra += skip_cells;
2045 n_attr_skip -= skip_cells;
2046 if (n_attr_skip < 0)
2047 n_attr_skip = 0;
2048 skip_cells = 0;
2049 }
2050 else
2051 {
2052 // the whole text is left of the window, drop
2053 // it and advance to the next one
2054 skip_cells -= wlv.n_extra;
2055 wlv.n_extra = 0;
2056 n_attr_skip = 0;
2057 bail_out = TRUE;
2058 }
2059 }
2060
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002061 // If another text prop follows the condition below at
2062 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002063 // If this is an "above" text prop and 'nowrap' the we
2064 // must wrap anyway.
2065 text_prop_above = above;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002066 text_prop_follows = other_tpi != -1
2067 && (wp->w_p_wrap
2068 || (text_props[other_tpi].tp_flags
2069 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002070
2071 if (bail_out)
2072 // starting a new line for "below"
2073 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002074 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002075 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002076 else if (text_prop_next < text_prop_count
2077 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002078 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2079 || (!wp->w_p_wrap
2080 && wlv.col == wp->w_width - 1
2081 && (text_props[text_prop_next].tp_flags
2082 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002083 // When at last-but-one character and a text property
2084 // follows after it, we may need to flush the line after
2085 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002086 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002087 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002088 }
2089#endif
2090
Bram Moolenaare38fc862022-08-11 17:24:50 +01002091#ifdef FEAT_SEARCH_EXTRA
2092 if (wlv.n_extra == 0)
2093 {
2094 // Check for start/end of 'hlsearch' and other matches.
2095 // After end, check for start/end of next match.
2096 // When another match, have to check for start again.
2097 v = (long)(ptr - line);
2098 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2099 &screen_search_hl, &has_match_conc,
2100 &match_conc, did_line_attr, lcs_eol_one,
2101 &on_last_col);
2102 ptr = line + v; // "line" may have been changed
2103 prev_ptr = ptr;
2104
2105 // Do not allow a conceal over EOL otherwise EOL will be missed
2106 // and bad things happen.
2107 if (*ptr == NUL)
2108 has_match_conc = 0;
2109 }
2110#endif
2111
2112#ifdef FEAT_DIFF
2113 if (wlv.diff_hlf != (hlf_T)0)
2114 {
2115 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2116 && wlv.n_extra == 0)
2117 wlv.diff_hlf = HLF_TXD; // changed text
2118 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2119 && wlv.n_extra == 0)
2120 wlv.diff_hlf = HLF_CHD; // changed line
2121 line_attr = HL_ATTR(wlv.diff_hlf);
2122 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2123 && wp->w_p_culopt_flags != CULOPT_NBR
2124 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2125 && wlv.vcol <= right_curline_col)))
2126 line_attr = hl_combine_attr(
2127 line_attr, HL_ATTR(HLF_CUL));
2128 }
2129#endif
2130
Bram Moolenaara74fda62019-10-19 17:38:03 +02002131#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002132 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002133 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002134 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002135# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002136 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002137 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002138# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002139 // Get syntax attribute.
2140 if (has_syntax)
2141 {
2142 // Get the syntax attribute for the character. If there
2143 // is an error, disable syntax highlighting.
2144 save_did_emsg = did_emsg;
2145 did_emsg = FALSE;
2146
2147 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002148 if (v == prev_syntax_col)
2149 // at same column again
2150 syntax_attr = prev_syntax_attr;
2151 else
2152 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002153# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002154 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002155# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002156 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002157# ifdef FEAT_SPELL
2158 has_spell ? &can_spell :
2159# endif
2160 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002161 prev_syntax_col = v;
2162 prev_syntax_attr = syntax_attr;
2163 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002164
Bram Moolenaar34390282019-10-16 14:38:26 +02002165 if (did_emsg)
2166 {
2167 wp->w_s->b_syn_error = TRUE;
2168 has_syntax = FALSE;
2169 syntax_attr = 0;
2170 }
2171 else
2172 did_emsg = save_did_emsg;
2173# ifdef SYN_TIME_LIMIT
2174 if (wp->w_s->b_syn_slow)
2175 has_syntax = FALSE;
2176# endif
2177
2178 // Need to get the line again, a multi-line regexp may
2179 // have made it invalid.
2180 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2181 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002182 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002183# ifdef FEAT_CONCEAL
2184 // no concealing past the end of the line, it interferes
2185 // with line highlighting
2186 if (*ptr == NUL)
2187 syntax_flags = 0;
2188 else
2189 syntax_flags = get_syntax_info(&syntax_seqnr);
2190# endif
2191 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002192 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002193# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002194 // Combine text property highlight into syntax highlight.
2195 if (text_prop_type != NULL)
2196 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002197 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002198 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2199 else
2200 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002201 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002202 }
2203# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002204#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002205
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002206 // Decide which of the highlight attributes to use.
2207 attr_pri = TRUE;
2208#ifdef LINE_ATTR
2209 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002210 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002211 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002212 if (!highlight_match)
2213 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002214 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002215# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002216 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002217# endif
2218 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002219 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002220 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002221 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002222# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002223 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002224# endif
2225 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002226 else if (line_attr != 0
2227 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2228 || wlv.vcol < wlv.fromcol
2229 || vcol_prev < fromcol_prev
2230 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002231 {
2232 // Use line_attr when not in the Visual or 'incsearch' area
2233 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002234# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002235 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002236# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002237 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002238# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002239 attr_pri = FALSE;
2240 }
2241#else
2242 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002243 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002244 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002245 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002246#endif
2247 else
2248 {
2249 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002250#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002251 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002252#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002253 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002254#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002255 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002256#ifdef FEAT_PROP_POPUP
2257 // override with text property highlight when "override" is TRUE
2258 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002259 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002260#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002261 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002262
2263 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002264 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002265 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002266 if (wlv.char_attr == 0)
2267 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002268 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002269 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002270 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002271
2272 // Get the next character to put on the screen.
2273
2274 // The "p_extra" points to the extra stuff that is inserted to
2275 // represent special characters (non-printable stuff) and other
2276 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002277 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002278 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2279 // "p_extra[n_extra]".
2280 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002281 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002282 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002283 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002284 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002285 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2286 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002287 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2288 if (enc_utf8 && utf_char2len(c) > 1)
2289 {
2290 mb_utf8 = TRUE;
2291 u8cc[0] = 0;
2292 c = 0xc0;
2293 }
2294 else
2295 mb_utf8 = FALSE;
2296 }
2297 else
2298 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002299 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002300 if (has_mbyte)
2301 {
2302 mb_c = c;
2303 if (enc_utf8)
2304 {
2305 // If the UTF-8 character is more than one byte:
2306 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002307 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002308 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002309 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002310 mb_l = 1;
2311 else if (mb_l > 1)
2312 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002313 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002314 mb_utf8 = TRUE;
2315 c = 0xc0;
2316 }
2317 }
2318 else
2319 {
2320 // if this is a DBCS character, put it in "mb_c"
2321 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002322 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002323 mb_l = 1;
2324 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002325 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002326 }
2327 if (mb_l == 0) // at the NUL at end-of-line
2328 mb_l = 1;
2329
2330 // If a double-width char doesn't fit display a '>' in the
2331 // last column.
2332 if ((
2333# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002334 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002335# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002336 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002337 && (*mb_char2cells)(mb_c) == 2)
2338 {
2339 c = '>';
2340 mb_c = c;
2341 mb_l = 1;
2342 mb_utf8 = FALSE;
2343 multi_attr = HL_ATTR(HLF_AT);
2344#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002345 if (wlv.cul_attr)
2346 multi_attr = hl_combine_attr(
2347 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002348#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002349 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002350
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002351 // put the pointer back to output the double-width
2352 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002353 ++wlv.n_extra;
2354 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002355 }
2356 else
2357 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002358 wlv.n_extra -= mb_l - 1;
2359 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002360 }
2361 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002362 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002363 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002364 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002365#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002366 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002367 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002368 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002369 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002370 if (search_attr == 0)
2371 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002372 if (area_attr == 0 && *ptr != NUL)
2373 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002374 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002375#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002376 }
2377 else
2378 {
2379#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002380 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002381#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002382 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002383
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002384 // Get a character from the line itself.
2385 c = *ptr;
2386#ifdef FEAT_LINEBREAK
2387 c0 = *ptr;
2388#endif
2389 if (has_mbyte)
2390 {
2391 mb_c = c;
2392 if (enc_utf8)
2393 {
2394 // If the UTF-8 character is more than one byte: Decode it
2395 // into "mb_c".
2396 mb_l = utfc_ptr2len(ptr);
2397 mb_utf8 = FALSE;
2398 if (mb_l > 1)
2399 {
2400 mb_c = utfc_ptr2char(ptr, u8cc);
2401 // Overlong encoded ASCII or ASCII with composing char
2402 // is displayed normally, except a NUL.
2403 if (mb_c < 0x80)
2404 {
2405 c = mb_c;
2406#ifdef FEAT_LINEBREAK
2407 c0 = mb_c;
2408#endif
2409 }
2410 mb_utf8 = TRUE;
2411
2412 // At start of the line we can have a composing char.
2413 // Draw it as a space with a composing char.
2414 if (utf_iscomposing(mb_c))
2415 {
2416 int i;
2417
2418 for (i = Screen_mco - 1; i > 0; --i)
2419 u8cc[i] = u8cc[i - 1];
2420 u8cc[0] = mb_c;
2421 mb_c = ' ';
2422 }
2423 }
2424
2425 if ((mb_l == 1 && c >= 0x80)
2426 || (mb_l >= 1 && mb_c == 0)
2427 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2428 {
2429 // Illegal UTF-8 byte: display as <xx>.
2430 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002431 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002432# ifdef FEAT_RIGHTLEFT
2433 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002434 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002435# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002436 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002437 c = *wlv.p_extra;
2438 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002439 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002440 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2441 wlv.c_extra = NUL;
2442 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002443 if (area_attr == 0 && search_attr == 0)
2444 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002445 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002446 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002447 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002448 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002449 }
2450 }
2451 else if (mb_l == 0) // at the NUL at end-of-line
2452 mb_l = 1;
2453#ifdef FEAT_ARABIC
2454 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2455 {
2456 // Do Arabic shaping.
2457 int pc, pc1, nc;
2458 int pcc[MAX_MCO];
2459
2460 // The idea of what is the previous and next
2461 // character depends on 'rightleft'.
2462 if (wp->w_p_rl)
2463 {
2464 pc = prev_c;
2465 pc1 = prev_c1;
2466 nc = utf_ptr2char(ptr + mb_l);
2467 prev_c1 = u8cc[0];
2468 }
2469 else
2470 {
2471 pc = utfc_ptr2char(ptr + mb_l, pcc);
2472 nc = prev_c;
2473 pc1 = pcc[0];
2474 }
2475 prev_c = mb_c;
2476
2477 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2478 }
2479 else
2480 prev_c = mb_c;
2481#endif
2482 }
2483 else // enc_dbcs
2484 {
2485 mb_l = MB_BYTE2LEN(c);
2486 if (mb_l == 0) // at the NUL at end-of-line
2487 mb_l = 1;
2488 else if (mb_l > 1)
2489 {
2490 // We assume a second byte below 32 is illegal.
2491 // Hopefully this is OK for all double-byte encodings!
2492 if (ptr[1] >= 32)
2493 mb_c = (c << 8) + ptr[1];
2494 else
2495 {
2496 if (ptr[1] == NUL)
2497 {
2498 // head byte at end of line
2499 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002500 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002501 }
2502 else
2503 {
2504 // illegal tail byte
2505 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002506 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002507 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002508 wlv.p_extra = wlv.extra;
2509 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002510 wlv.c_extra = NUL;
2511 wlv.c_final = NUL;
2512 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002513 if (area_attr == 0 && search_attr == 0)
2514 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002515 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002516 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002517 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002518 // save current attr
2519 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002520 }
2521 mb_c = c;
2522 }
2523 }
2524 }
2525 // If a double-width char doesn't fit display a '>' in the
2526 // last column; the character is displayed at the start of the
2527 // next line.
2528 if ((
2529# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002530 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002531# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002532 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002533 && (*mb_char2cells)(mb_c) == 2)
2534 {
2535 c = '>';
2536 mb_c = c;
2537 mb_utf8 = FALSE;
2538 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002539 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002540 // Put pointer back so that the character will be
2541 // displayed at the start of the next line.
2542 --ptr;
2543#ifdef FEAT_CONCEAL
2544 did_decrement_ptr = TRUE;
2545#endif
2546 }
2547 else if (*ptr != NUL)
2548 ptr += mb_l - 1;
2549
2550 // If a double-width char doesn't fit at the left side display
2551 // a '<' in the first column. Don't do this for unprintable
2552 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002553 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002554 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002555 wlv.n_extra = 1;
2556 wlv.c_extra = MB_FILLER_CHAR;
2557 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002558 c = ' ';
2559 if (area_attr == 0 && search_attr == 0)
2560 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002561 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002562 extra_attr = hl_combine_attr(
2563 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002564 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002565 }
2566 mb_c = c;
2567 mb_utf8 = FALSE;
2568 mb_l = 1;
2569 }
2570
2571 }
2572 ++ptr;
2573
2574 if (extra_check)
2575 {
2576#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002577 // Check spelling (unless at the end of the line).
2578 // Only do this when there is no syntax highlighting, the
2579 // @Spell cluster is not used or the current syntax item
2580 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002581 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002582 if (has_spell && v >= word_end && v > cur_checked_col)
2583 {
2584 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002585 // do not calculate cap_col at the end of the line or when
2586 // only white space is following
2587 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002588# ifdef FEAT_SYN_HL
2589 !has_syntax ||
2590# endif
2591 can_spell))
2592 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002593 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002594 int len;
2595 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002596
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002597 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002598 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002599
2600 // Use nextline[] if possible, it has the start of the
2601 // next line concatenated.
2602 if ((prev_ptr - line) - nextlinecol >= 0)
2603 p = nextline + (prev_ptr - line) - nextlinecol;
2604 else
2605 p = prev_ptr;
2606 cap_col -= (int)(prev_ptr - line);
2607 len = spell_check(wp, p, &spell_hlf, &cap_col,
2608 nochange);
2609 word_end = v + len;
2610
2611 // In Insert mode only highlight a word that
2612 // doesn't touch the cursor.
2613 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002614 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002615 && wp->w_cursor.lnum == lnum
2616 && wp->w_cursor.col >=
2617 (colnr_T)(prev_ptr - line)
2618 && wp->w_cursor.col < (colnr_T)word_end)
2619 {
2620 spell_hlf = HLF_COUNT;
2621 spell_redraw_lnum = lnum;
2622 }
2623
2624 if (spell_hlf == HLF_COUNT && p != prev_ptr
2625 && (p - nextline) + len > nextline_idx)
2626 {
2627 // Remember that the good word continues at the
2628 // start of the next line.
2629 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002630 checked_col = (int)((p - nextline)
2631 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002632 }
2633
2634 // Turn index into actual attributes.
2635 if (spell_hlf != HLF_COUNT)
2636 spell_attr = highlight_attr[spell_hlf];
2637
2638 if (cap_col > 0)
2639 {
2640 if (p != prev_ptr
2641 && (p - nextline) + cap_col >= nextline_idx)
2642 {
2643 // Remember that the word in the next line
2644 // must start with a capital.
2645 capcol_lnum = lnum + 1;
2646 cap_col = (int)((p - nextline) + cap_col
2647 - nextline_idx);
2648 }
2649 else
2650 // Compute the actual column.
2651 cap_col += (int)(prev_ptr - line);
2652 }
2653 }
2654 }
2655 if (spell_attr != 0)
2656 {
2657 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002658 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2659 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002660 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002661 wlv.char_attr = hl_combine_attr(spell_attr,
2662 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002663 }
2664#endif
2665#ifdef FEAT_LINEBREAK
2666 // Found last space before word: check for line break.
2667 if (wp->w_p_lbr && c0 == c
2668 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2669 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002670 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2671 : 0;
2672 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002673 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002674
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002675 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002676# ifdef FEAT_PROP_POPUP
2677 // do not want virtual text counted here
2678 cts.cts_has_prop_with_text = FALSE;
2679# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002680 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002681 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002682
2683 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002684 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002685 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002686 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002687 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2688 if (wlv.n_extra < 0)
2689 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002690 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002691 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002692 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002693 // line break, but for TABs the highlighting should
2694 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002695 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002696
Bram Moolenaar1306b362022-08-06 15:59:06 +01002697 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002698# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002699 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002700 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002701 wp->w_buffer->b_p_vts_array) - 1;
2702# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002703 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002704 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002705# endif
2706
Bram Moolenaar1306b362022-08-06 15:59:06 +01002707 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2708 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002709# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002710 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002711 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002712# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002713 if (VIM_ISWHITE(c))
2714 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002715# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002716 if (c == TAB)
2717 // See "Tab alignment" below.
2718 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002719# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002720 if (!wp->w_p_list)
2721 c = ' ';
2722 }
2723 }
2724#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002725 in_multispace = c == ' '
2726 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2727 if (!in_multispace)
2728 multispace_pos = 0;
2729
Bram Moolenaareed9d462021-02-15 20:38:25 +01002730 // 'list': Change char 160 to 'nbsp' and space to 'space'
2731 // setting in 'listchars'. But not when the character is
2732 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002733 if (wp->w_p_list
2734 && ((((c == 160 && mb_l == 1)
2735 || (mb_utf8
2736 && ((mb_c == 160 && mb_l == 2)
2737 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002738 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002739 || (c == ' '
2740 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002741 && (wp->w_lcs_chars.space
2742 || (in_multispace
2743 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002744 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002745 && ptr - line <= trailcol)))
2746 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002747 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2748 {
2749 c = wp->w_lcs_chars.multispace[multispace_pos++];
2750 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2751 multispace_pos = 0;
2752 }
2753 else
2754 c = (c == ' ') ? wp->w_lcs_chars.space
2755 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002756 if (area_attr == 0 && search_attr == 0)
2757 {
2758 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002759 extra_attr = hl_combine_attr(wlv.win_attr,
2760 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002761 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002762 }
2763 mb_c = c;
2764 if (enc_utf8 && utf_char2len(c) > 1)
2765 {
2766 mb_utf8 = TRUE;
2767 u8cc[0] = 0;
2768 c = 0xc0;
2769 }
2770 else
2771 mb_utf8 = FALSE;
2772 }
2773
zeertzjq2e7cba32022-06-10 15:30:32 +01002774 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2775 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002776 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002777 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2778 && wp->w_lcs_chars.leadmultispace != NULL)
2779 {
2780 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002781 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2782 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002783 multispace_pos = 0;
2784 }
2785
2786 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2787 c = wp->w_lcs_chars.trail;
2788
2789 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2790 c = wp->w_lcs_chars.lead;
2791
zeertzjq2e7cba32022-06-10 15:30:32 +01002792 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002793 c = wp->w_lcs_chars.space;
2794
2795
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002796 if (!attr_pri)
2797 {
2798 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002799 extra_attr = hl_combine_attr(wlv.win_attr,
2800 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002801 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002802 }
2803 mb_c = c;
2804 if (enc_utf8 && utf_char2len(c) > 1)
2805 {
2806 mb_utf8 = TRUE;
2807 u8cc[0] = 0;
2808 c = 0xc0;
2809 }
2810 else
2811 mb_utf8 = FALSE;
2812 }
2813 }
2814
2815 // Handling of non-printable characters.
2816 if (!vim_isprintc(c))
2817 {
2818 // when getting a character from the file, we may have to
2819 // turn it into something else on the way to putting it
2820 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002821 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002822 {
2823 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002824 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002825#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002826 char_u *sbr = get_showbreak_value(wp);
2827
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002828 // only adjust the tab_len, when at the first column
2829 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002830 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002831 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002832#endif
2833 // tab amount depends on current column
2834#ifdef FEAT_VARTABS
2835 tab_len = tabstop_padding(vcol_adjusted,
2836 wp->w_buffer->b_p_ts,
2837 wp->w_buffer->b_p_vts_array) - 1;
2838#else
2839 tab_len = (int)wp->w_buffer->b_p_ts
2840 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2841#endif
2842
2843#ifdef FEAT_LINEBREAK
2844 if (!wp->w_p_lbr || !wp->w_p_list)
2845#endif
2846 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002847 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002848#ifdef FEAT_LINEBREAK
2849 else
2850 {
2851 char_u *p;
2852 int len;
2853 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002854 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002855
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002856# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002857 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002858 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002859 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002860
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002861 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002862 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002863 && old_boguscols > 0
2864 && wlv.n_extra > tab_len)
2865 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002866# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002867 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002868 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002869 // If wlv.n_extra > 0, it gives the number of
2870 // chars, to use for a tab, else we need to
2871 // calculate the width for a tab.
2872 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
2873 len = tab_len * tab2_len;
2874 if (wp->w_lcs_chars.tab3)
2875 len += mb_char2len(wp->w_lcs_chars.tab3)
2876 - tab2_len;
2877 if (wlv.n_extra > 0)
2878 len += wlv.n_extra - tab_len;
2879 c = wp->w_lcs_chars.tab1;
2880 p = alloc(len + 1);
2881 if (p == NULL)
2882 wlv.n_extra = 0;
2883 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002884 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002885 vim_memset(p, ' ', len);
2886 p[len] = NUL;
2887 vim_free(wlv.p_extra_free);
2888 wlv.p_extra_free = p;
2889 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002890 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002891 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002892
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002893 if (*p == NUL)
2894 {
2895 tab_len = i;
2896 break;
2897 }
2898
2899 // if tab3 is given, use it for the last
2900 // char
2901 if (wp->w_lcs_chars.tab3
2902 && i == tab_len - 1)
2903 lcs = wp->w_lcs_chars.tab3;
2904 p += mb_char2bytes(lcs, p);
2905 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002906 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002907 }
2908 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002909# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002910 // n_extra will be increased by
2911 // FIX_FOX_BOGUSCOLS macro below, so need to
2912 // adjust for that here
2913 if (wlv.vcol_off > 0)
2914 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002915# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002916 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002917 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002918 }
2919#endif
2920#ifdef FEAT_CONCEAL
2921 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002922 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002923
2924 // Tab alignment should be identical regardless of
2925 // 'conceallevel' value. So tab compensates of all
2926 // previous concealed characters, and thus resets
2927 // vcol_off and boguscols accumulated so far in the
2928 // line. Note that the tab can be longer than
2929 // 'tabstop' when there are concealed characters.
2930 FIX_FOR_BOGUSCOLS;
2931
2932 // Make sure, the highlighting for the tab char will be
2933 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002934 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002935 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002936 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002937 tab_len += vc_saved;
2938 }
2939#endif
2940 mb_utf8 = FALSE; // don't draw as UTF-8
2941 if (wp->w_p_list)
2942 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002943 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002944 ? wp->w_lcs_chars.tab3
2945 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002946#ifdef FEAT_LINEBREAK
2947 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002948 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002949 else
2950#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002951 wlv.c_extra = wp->w_lcs_chars.tab2;
2952 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002953 n_attr = tab_len + 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 mb_c = c;
2958 if (enc_utf8 && utf_char2len(c) > 1)
2959 {
2960 mb_utf8 = TRUE;
2961 u8cc[0] = 0;
2962 c = 0xc0;
2963 }
2964 }
2965 else
2966 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002967 wlv.c_final = NUL;
2968 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002969 c = ' ';
2970 }
2971 }
2972 else if (c == NUL
2973 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002974 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
2975 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002976 && VIsual_mode != Ctrl_V
2977 && (
2978# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002979 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002980# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002981 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002982 && !(noinvcur
2983 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002984 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002985 && lcs_eol_one > 0)
2986 {
2987 // Display a '$' after the line or highlight an extra
2988 // character if the line break is included.
2989#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2990 // For a diff line the highlighting continues after the
2991 // "$".
2992 if (
2993# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002994 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002995# ifdef LINE_ATTR
2996 &&
2997# endif
2998# endif
2999# ifdef LINE_ATTR
3000 line_attr == 0
3001# endif
3002 )
3003#endif
3004 {
3005 // In virtualedit, visual selections may extend
3006 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003007 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003008 && wlv.tocol != MAXCOL
3009 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003010 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003011 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003012 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003013 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3014 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003015 else
3016 c = ' ';
3017 lcs_eol_one = -1;
3018 --ptr; // put it back at the NUL
3019 if (!attr_pri)
3020 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003021 extra_attr = hl_combine_attr(wlv.win_attr,
3022 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003023 n_attr = 1;
3024 }
3025 mb_c = c;
3026 if (enc_utf8 && utf_char2len(c) > 1)
3027 {
3028 mb_utf8 = TRUE;
3029 u8cc[0] = 0;
3030 c = 0xc0;
3031 }
3032 else
3033 mb_utf8 = FALSE; // don't draw as UTF-8
3034 }
3035 else if (c != NUL)
3036 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003037 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3038 if (wlv.n_extra == 0)
3039 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003040#ifdef FEAT_RIGHTLEFT
3041 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003042 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003043#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003044 wlv.c_extra = NUL;
3045 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003046#ifdef FEAT_LINEBREAK
3047 if (wp->w_p_lbr)
3048 {
3049 char_u *p;
3050
Bram Moolenaar1306b362022-08-06 15:59:06 +01003051 c = *wlv.p_extra;
3052 p = alloc(wlv.n_extra + 1);
3053 vim_memset(p, ' ', wlv.n_extra);
3054 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3055 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003056 vim_free(wlv.p_extra_free);
3057 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003058 }
3059 else
3060#endif
3061 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003062 wlv.n_extra = byte2cells(c) - 1;
3063 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003064 }
3065 if (!attr_pri)
3066 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003067 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003068 extra_attr = hl_combine_attr(wlv.win_attr,
3069 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003070 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003071 }
3072 mb_utf8 = FALSE; // don't draw as UTF-8
3073 }
3074 else if (VIsual_active
3075 && (VIsual_mode == Ctrl_V
3076 || VIsual_mode == 'v')
3077 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003078 && wlv.tocol != MAXCOL
3079 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003080 && (
3081#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003082 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003083#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003084 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003085 {
3086 c = ' ';
3087 --ptr; // put it back at the NUL
3088 }
3089#if defined(LINE_ATTR)
3090 else if ((
3091# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003092 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003093# endif
3094# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003095 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003096# endif
3097 line_attr != 0
3098 ) && (
3099# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003100 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003101# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003102 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003103# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003104 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003105# endif
3106 < wp->w_width)))
3107 {
3108 // Highlight until the right side of the window
3109 c = ' ';
3110 --ptr; // put it back at the NUL
3111
3112 // Remember we do the char for line highlighting.
3113 ++did_line_attr;
3114
3115 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01003116 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003117 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003118 || (wp->w_p_list &&
3119 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003120 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003121# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003122 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003123 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003124 wlv.diff_hlf = HLF_CHD;
3125 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003126 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003127 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003128 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3129 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003130 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003131 || (wlv.vcol >= left_curline_col
3132 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003133 wlv.char_attr = hl_combine_attr(
3134 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003135 }
3136 }
3137# endif
3138# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003139 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003140 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003141 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003142 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3143 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003144 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003145 if (!wlv.cul_screenline
3146 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003147 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003148 wlv.char_attr = hl_combine_attr(
3149 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003150 }
3151 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003152 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3153 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003154 }
3155# endif
3156 }
3157#endif
3158 }
3159
3160#ifdef FEAT_CONCEAL
3161 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003162 && (wp != curwin || lnum != wp->w_cursor.lnum
3163 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003164 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3165 && !(lnum_in_visual_area
3166 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3167 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003168 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003169 if (((prev_syntax_id != syntax_seqnr
3170 && (syntax_flags & HL_CONCEAL) != 0)
3171 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003172 && (syn_get_sub_char() != NUL
3173 || (has_match_conc && match_conc)
3174 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003175 && wp->w_p_cole != 3)
3176 {
3177 // First time at this concealed item: display one
3178 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003179 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003180 c = match_conc;
3181 else if (syn_get_sub_char() != NUL)
3182 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003183 else if (wp->w_lcs_chars.conceal != NUL)
3184 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003185 else
3186 c = ' ';
3187
3188 prev_syntax_id = syntax_seqnr;
3189
Bram Moolenaar1306b362022-08-06 15:59:06 +01003190 if (wlv.n_extra > 0)
3191 wlv.vcol_off += wlv.n_extra;
3192 wlv.vcol += wlv.n_extra;
3193 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003194 {
3195# ifdef FEAT_RIGHTLEFT
3196 if (wp->w_p_rl)
3197 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003198 wlv.col -= wlv.n_extra;
3199 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003200 }
3201 else
3202# endif
3203 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003204 wlv.boguscols += wlv.n_extra;
3205 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003206 }
3207 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003208 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003209 n_attr = 0;
3210 }
3211 else if (n_skip == 0)
3212 {
3213 is_concealing = TRUE;
3214 n_skip = 1;
3215 }
3216 mb_c = c;
3217 if (enc_utf8 && utf_char2len(c) > 1)
3218 {
3219 mb_utf8 = TRUE;
3220 u8cc[0] = 0;
3221 c = 0xc0;
3222 }
3223 else
3224 mb_utf8 = FALSE; // don't draw as UTF-8
3225 }
3226 else
3227 {
3228 prev_syntax_id = 0;
3229 is_concealing = FALSE;
3230 }
3231
3232 if (n_skip > 0 && did_decrement_ptr)
3233 // not showing the '>', put pointer back to avoid getting stuck
3234 ++ptr;
3235
3236#endif // FEAT_CONCEAL
3237 }
3238
3239#ifdef FEAT_CONCEAL
3240 // In the cursor line and we may be concealing characters: correct
3241 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003242 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003243 && wp == curwin && lnum == wp->w_cursor.lnum
3244 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003245 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003246 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003247# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003248 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003249 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003250 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003251# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003252 wp->w_wcol = wlv.col - wlv.boguscols;
3253 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003254 did_wcol = TRUE;
3255 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003256# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003257 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003258# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003259 }
3260#endif
3261
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003262 // Use "extra_attr", but don't override visual selection highlighting,
3263 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003264 // Don't use "extra_attr" until n_attr_skip is zero.
3265 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003266 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003267 && (!attr_pri
3268#ifdef FEAT_PROP_POPUP
3269 || (text_prop_flags & PT_FLAG_OVERRIDE)
3270#endif
3271 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003272 {
3273#ifdef LINE_ATTR
3274 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003275 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003276 else
3277#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003278 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003279 }
3280
3281#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3282 // XIM don't send preedit_start and preedit_end, but they send
3283 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3284 // im_is_preediting() here.
3285 if (p_imst == IM_ON_THE_SPOT
3286 && xic != NULL
3287 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003288 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003289 && !p_imdisable
3290 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003291 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003292 {
3293 colnr_T tcol;
3294
3295 if (preedit_end_col == MAXCOL)
3296 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3297 else
3298 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003299 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003300 {
3301 if (feedback_old_attr < 0)
3302 {
3303 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003304 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003305 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003306 wlv.char_attr = im_get_feedback_attr(feedback_col);
3307 if (wlv.char_attr < 0)
3308 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003309 feedback_col++;
3310 }
3311 else if (feedback_old_attr >= 0)
3312 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003313 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003314 feedback_old_attr = -1;
3315 feedback_col = 0;
3316 }
3317 }
3318#endif
3319 // Handle the case where we are in column 0 but not on the first
3320 // character of the line and the user wants us to show us a
3321 // special character (via 'listchars' option "precedes:<char>".
3322 if (lcs_prec_todo != NUL
3323 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003324 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3325 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003326#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003327 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003328#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003329 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003330 && c != NUL)
3331 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003332 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003333 lcs_prec_todo = NUL;
3334 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3335 {
3336 // Double-width character being overwritten by the "precedes"
3337 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003338 wlv.c_extra = MB_FILLER_CHAR;
3339 wlv.c_final = NUL;
3340 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003341 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003342 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003343 }
3344 mb_c = c;
3345 if (enc_utf8 && utf_char2len(c) > 1)
3346 {
3347 mb_utf8 = TRUE;
3348 u8cc[0] = 0;
3349 c = 0xc0;
3350 }
3351 else
3352 mb_utf8 = FALSE; // don't draw as UTF-8
3353 if (!attr_pri)
3354 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003355 saved_attr3 = wlv.char_attr; // save current attr
3356 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003357 n_attr3 = 1;
3358 }
3359 }
3360
3361 // At end of the text line or just after the last character.
3362 if ((c == NUL
3363#if defined(LINE_ATTR)
3364 || did_line_attr == 1
3365#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003366 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003367 {
3368#ifdef FEAT_SEARCH_EXTRA
3369 // flag to indicate whether prevcol equals startcol of search_hl or
3370 // one of the matches
3371 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3372 (long)(ptr - line) - (c == NUL));
3373#endif
3374 // Invert at least one char, used for Visual and empty line or
3375 // highlight match at end of line. If it's beyond the last
3376 // char on the screen, just overwrite that one (tricky!) Not
3377 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003378 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003379 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003380 && (VIsual_mode != Ctrl_V
3381 || lnum == VIsual.lnum
3382 || lnum == curwin->w_cursor.lnum)
3383 && c == NUL)
3384#ifdef FEAT_SEARCH_EXTRA
3385 // highlight 'hlsearch' match at end of line
3386 || (prevcol_hl_flag
3387# ifdef FEAT_SYN_HL
3388 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3389 && !(wp == curwin && VIsual_active))
3390# endif
3391# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003392 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003393# endif
3394# if defined(LINE_ATTR)
3395 && did_line_attr <= 1
3396# endif
3397 )
3398#endif
3399 ))
3400 {
3401 int n = 0;
3402
3403#ifdef FEAT_RIGHTLEFT
3404 if (wp->w_p_rl)
3405 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003406 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003407 n = 1;
3408 }
3409 else
3410#endif
3411 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003412 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003413 n = -1;
3414 }
3415 if (n != 0)
3416 {
3417 // At the window boundary, highlight the last character
3418 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003419 wlv.off += n;
3420 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003421 }
3422 else
3423 {
3424 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003425 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003426 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003427 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003428 }
3429#ifdef FEAT_SEARCH_EXTRA
3430 if (area_attr == 0)
3431 {
3432 // Use attributes from match with highest priority among
3433 // 'search_hl' and the match list.
3434 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003435 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003436 }
3437#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003438 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003439 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003440#ifdef FEAT_RIGHTLEFT
3441 if (wp->w_p_rl)
3442 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003443 --wlv.col;
3444 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003445 }
3446 else
3447#endif
3448 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003449 ++wlv.col;
3450 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003451 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003452 ++wlv.vcol;
3453 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003454 }
3455 }
3456
3457 // At end of the text line.
3458 if (c == NUL)
3459 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003460 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003461
3462 // Update w_cline_height and w_cline_folded if the cursor line was
3463 // updated (saves a call to plines() later).
3464 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3465 {
3466 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003467 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003468#ifdef FEAT_FOLDING
3469 curwin->w_cline_folded = FALSE;
3470#endif
3471 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3472 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003473 break;
3474 }
3475
3476 // Show "extends" character from 'listchars' if beyond the line end and
3477 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003478 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003479 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003480 && wp->w_p_list
3481 && !wp->w_p_wrap
3482#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003483 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003484#endif
3485 && (
3486#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003487 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003488#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003489 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003490 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003491 || lcs_eol_one > 0
3492 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003493 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003494 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003495 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003496 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003497 mb_c = c;
3498 if (enc_utf8 && utf_char2len(c) > 1)
3499 {
3500 mb_utf8 = TRUE;
3501 u8cc[0] = 0;
3502 c = 0xc0;
3503 }
3504 else
3505 mb_utf8 = FALSE;
3506 }
3507
3508#ifdef FEAT_SYN_HL
3509 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003510 if (wlv.draw_color_col)
3511 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003512
3513 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3514 // highlight the cursor position itself.
3515 // Also highlight the 'colorcolumn' if it is different than
3516 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003517 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3518 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003519 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003520 if (((wlv.draw_state == WL_LINE
3521 || wlv.draw_state == WL_BRI
3522 || wlv.draw_state == WL_SBR)
3523 && !lnum_in_visual_area
3524 && search_attr == 0
3525 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003526# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003527 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003528# endif
3529 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003530 {
3531 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3532 && lnum != wp->w_cursor.lnum)
3533 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003534 vcol_save_attr = wlv.char_attr;
3535 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3536 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003537 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003538 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003539 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003540 vcol_save_attr = wlv.char_attr;
3541 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003542 }
3543 }
3544#endif
3545
3546 // Store character to be displayed.
3547 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003548 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003549 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003550 {
3551 // Store the character.
3552#if defined(FEAT_RIGHTLEFT)
3553 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3554 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003555 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003556 --wlv.off;
3557 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003558 }
3559#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003560 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003561 if (enc_dbcs == DBCS_JPNU)
3562 {
3563 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003564 ScreenLines[wlv.off] = 0x8e;
3565 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003566 }
3567 else if (enc_utf8)
3568 {
3569 if (mb_utf8)
3570 {
3571 int i;
3572
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003573 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003574 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003575 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003576 for (i = 0; i < Screen_mco; ++i)
3577 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003578 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003579 if (u8cc[i] == 0)
3580 break;
3581 }
3582 }
3583 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003584 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003585 }
3586 if (multi_attr)
3587 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003588 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003589 multi_attr = 0;
3590 }
3591 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003592 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003593
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003594 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003595
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003596 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3597 {
3598 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003599 ++wlv.off;
3600 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003601 if (enc_utf8)
3602 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003603 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003604 else
3605 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003606 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003607 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003608#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003609 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003610#endif
3611 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003612 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003613 // When "wlv.tocol" is halfway a character, set it to the end
3614 // of the character, otherwise highlighting won't stop.
3615 if (wlv.tocol == wlv.vcol)
3616 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003617
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003618 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003619
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003620#ifdef FEAT_RIGHTLEFT
3621 if (wp->w_p_rl)
3622 {
3623 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003624 --wlv.off;
3625 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003626 }
3627#endif
3628 }
3629#ifdef FEAT_RIGHTLEFT
3630 if (wp->w_p_rl)
3631 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003632 --wlv.off;
3633 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003634 }
3635 else
3636#endif
3637 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003638 ++wlv.off;
3639 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003640 }
3641 }
3642#ifdef FEAT_CONCEAL
3643 else if (wp->w_p_cole > 0 && is_concealing)
3644 {
3645 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003646 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003647 if (wlv.n_extra > 0)
3648 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003649 if (wp->w_p_wrap)
3650 {
3651 // Special voodoo required if 'wrap' is on.
3652 //
3653 // Advance the column indicator to force the line
3654 // drawing to wrap early. This will make the line
3655 // take up the same screen space when parts are concealed,
3656 // so that cursor line computations aren't messed up.
3657 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003658 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003659 // trailing junk to be written out of the screen line
3660 // we are building, 'boguscols' keeps track of the number
3661 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003662 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003663 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003664 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003665# ifdef FEAT_RIGHTLEFT
3666 if (wp->w_p_rl)
3667 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003668 wlv.col -= wlv.n_extra;
3669 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003670 }
3671 else
3672# endif
3673 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003674 wlv.col += wlv.n_extra;
3675 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003676 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003677 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003678 n_attr = 0;
3679 }
3680
3681
3682 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3683 {
3684 // Need to fill two screen columns.
3685# ifdef FEAT_RIGHTLEFT
3686 if (wp->w_p_rl)
3687 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003688 --wlv.boguscols;
3689 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003690 }
3691 else
3692# endif
3693 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003694 ++wlv.boguscols;
3695 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003696 }
3697 }
3698
3699# ifdef FEAT_RIGHTLEFT
3700 if (wp->w_p_rl)
3701 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003702 --wlv.boguscols;
3703 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003704 }
3705 else
3706# endif
3707 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003708 ++wlv.boguscols;
3709 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003710 }
3711 }
3712 else
3713 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003714 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003715 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003716 wlv.vcol += wlv.n_extra;
3717 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003718 n_attr = 0;
3719 }
3720 }
3721
3722 }
3723#endif // FEAT_CONCEAL
3724 else
3725 --n_skip;
3726
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003727 // Only advance the "wlv.vcol" when after the 'number' or
3728 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003729 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003730#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003731 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003732#endif
3733 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003734 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003735
3736#ifdef FEAT_SYN_HL
3737 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003738 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003739#endif
3740
3741 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003742 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3743 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003744
3745 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003746 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003747 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003748 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003749 if (n_attr_skip > 0)
3750 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003751
3752 // At end of screen line and there is more to come: Display the line
3753 // so far. If there is no more to display it is caught above.
3754 if ((
3755#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003756 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003757#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003758 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003759 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003760 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003761#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003762 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003763#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003764#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003765 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003766#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003767 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003768 && wlv.p_extra != at_end_str)
3769 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3770 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003771 )
3772 {
3773#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003774 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003775 wlv_screen_line(wp, &wlv, FALSE);
3776 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003777 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003778#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003779 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003780#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003781 ++wlv.row;
3782 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003783
3784 // When not wrapping and finished diff lines, or when displayed
3785 // '$' and highlighting until last column, break here.
3786 if ((!wp->w_p_wrap
3787#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003788 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003789#endif
3790#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003791 && !text_prop_above && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003792#endif
3793 ) || lcs_eol_one == -1)
3794 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003795#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003796 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003797 {
3798 // do not output more of the line, only the "below" prop
3799 ptr += STRLEN(ptr);
3800# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003801 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003802# endif
3803 }
3804#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003805
3806 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003807 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003808#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003809 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003810#endif
3811 )
3812 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003813 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3814 draw_vsep_win(wp, wlv.row);
3815 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003816 }
3817
3818 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003819 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003820 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003821 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003822 break;
3823 }
3824
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003825 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003826#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003827 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003828#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003829#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003830 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003831#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003832 && wp->w_width == Columns)
3833 {
3834 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003835 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003836
3837 // Special trick to make copy/paste of wrapped lines work with
3838 // xterm/screen: write an extra character beyond the end of
3839 // the line. This will work with all terminal types
3840 // (regardless of the xn,am settings).
3841 // Only do this on a fast tty.
3842 // Only do this if the cursor is on the current line
3843 // (something has been written in it).
3844 // Don't do this for the GUI.
3845 // Don't do this for double-width characters.
3846 // Don't do this for a window not at the right screen border.
3847 if (p_tf
3848#ifdef FEAT_GUI
3849 && !gui.in_use
3850#endif
3851 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003852 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3853 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003854 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003855 || (*mb_off2cells)(
3856 LineOffset[wlv.screen_row - 1]
3857 + (int)Columns - 2,
3858 LineOffset[wlv.screen_row]
3859 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003860 {
3861 // First make sure we are at the end of the screen line,
3862 // then output the same character again to let the
3863 // terminal know about the wrap. If the terminal doesn't
3864 // auto-wrap, we overwrite the character.
3865 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003866 screen_char(LineOffset[wlv.screen_row - 1]
3867 + (unsigned)Columns - 1,
3868 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003869
3870 // When there is a multi-byte character, just output a
3871 // space to keep it simple.
3872 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003873 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003874 out_char(' ');
3875 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003876 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003877 + (Columns - 1)]);
3878 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003879 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003880 screen_start(); // don't know where cursor is now
3881 }
3882 }
3883
Bram Moolenaar1306b362022-08-06 15:59:06 +01003884 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003885
Bram Moolenaareed9d462021-02-15 20:38:25 +01003886 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003887#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003888 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003889# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003890 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003891# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003892 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003893 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003894#endif
3895#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003896 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003897 // When the filler lines are actually below the last line of the
3898 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003899 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003900 break;
3901#endif
3902 }
3903
3904 } // for every character in the line
3905
3906#ifdef FEAT_SPELL
3907 // After an empty line check first word for capital.
3908 if (*skipwhite(line) == NUL)
3909 {
3910 capcol_lnum = lnum + 1;
3911 cap_col = 0;
3912 }
3913#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003914#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003915 vim_free(text_props);
3916 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003917 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003918#endif
3919
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003920 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003921 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003922}