blob: b71bedefabfbd72f73bea7b4b1d090b7a0fb0a1b [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
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100462 && *get_showbreak_value(wp) != NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100463 // 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 Moolenaar9466fb82022-10-11 14:54:42 +0100589 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100590 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 Moolenaarccf28372022-10-10 21:10:03 +0100642 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100643 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
Bram Moolenaarccf28372022-10-10 21:10:03 +0100658 ? (col_with_padding <= col_off || !wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100659 : (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
Bram Moolenaard3283fb2022-10-10 20:33:25 +0100980#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +0100981 int skip_cells = 0; // nr of cells to skip for virtual text
982 // after the line, when w_skipcol is
983 // larger than the text length
Bram Moolenaard3283fb2022-10-10 20:33:25 +0100984#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200985
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200986 int fromcol_prev = -2; // start of inverting after cursor
987 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200988 int lnum_in_visual_area = FALSE;
989 pos_T pos;
990 long v;
991
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200992 int attr_pri = FALSE; // char_attr has priority
993 int area_highlighting = FALSE; // Visual or incsearch highlighting
994 // in this line
995 int vi_attr = 0; // attributes for Visual and incsearch
996 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200997 int area_attr = 0; // attributes desired by highlighting
998 int search_attr = 0; // attributes desired by 'hlsearch'
999#ifdef FEAT_SYN_HL
1000 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1001 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001002 int prev_syntax_col = -1; // column of prev_syntax_attr
1003 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001004 int has_syntax = FALSE; // this buffer has syntax highl.
1005 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001006#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001007#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001008 int text_prop_count;
1009 int text_prop_next = 0; // next text property to use
1010 textprop_T *text_props = NULL;
1011 int *text_prop_idxs = NULL;
1012 int text_props_active = 0;
1013 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001014 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001015 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001016 int text_prop_attr_comb = 0; // text_prop_attr combined with
1017 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001018 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001019 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001020 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001021 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001022 int saved_search_attr = 0; // search_attr to be used when n_extra
1023 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001024 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001025#endif
1026#ifdef FEAT_SPELL
1027 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001028 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001029# define SPWORDLEN 150
1030 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1031 int nextlinecol = 0; // column where nextline[] starts
1032 int nextline_idx = 0; // index in nextline[] where next line
1033 // starts
1034 int spell_attr = 0; // attributes desired by spelling
1035 int word_end = 0; // last byte with same spell_attr
1036 static linenr_T checked_lnum = 0; // line number for "checked_col"
1037 static int checked_col = 0; // column in "checked_lnum" up to which
1038 // there are no spell errors
1039 static int cap_col = -1; // column to check for Cap word
1040 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1041 int cur_checked_col = 0; // checked column for current line
1042#endif
1043 int extra_check = 0; // has extra highlighting
1044 int multi_attr = 0; // attributes desired by multibyte
1045 int mb_l = 1; // multi-byte byte length
1046 int mb_c = 0; // decoded multi-byte character
1047 int mb_utf8 = FALSE; // screen char is UTF-8 char
1048 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001049#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001050 int change_start = MAXCOL; // first col of changed area
1051 int change_end = -1; // last col of changed area
1052#endif
1053 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001054 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001055 int in_multispace = FALSE; // in multiple consecutive spaces
1056 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001057#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
1058 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
1059# define LINE_ATTR
1060 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +01001061 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001062#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001063 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001064 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001065#ifdef FEAT_ARABIC
1066 int prev_c = 0; // previous Arabic character
1067 int prev_c1 = 0; // first composing char for prev_c
1068#endif
1069#if defined(LINE_ATTR)
1070 int did_line_attr = 0;
1071#endif
1072#ifdef FEAT_TERMINAL
1073 int get_term_attr = FALSE;
1074#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001075
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001076#ifdef FEAT_SYN_HL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001077 // margin columns for the screen line, needed for when 'cursorlineopt'
1078 // contains "screenline"
1079 int left_curline_col = 0;
1080 int right_curline_col = 0;
1081#endif
1082
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001083#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1084 int feedback_col = 0;
1085 int feedback_old_attr = -1;
1086#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001087
1088#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1089 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001090 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001091#endif
1092#ifdef FEAT_CONCEAL
1093 int syntax_flags = 0;
1094 int syntax_seqnr = 0;
1095 int prev_syntax_id = 0;
1096 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1097 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001098 int did_wcol = FALSE;
1099 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001100# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001101# define FIX_FOR_BOGUSCOLS \
1102 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001103 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001104 wlv.vcol -= wlv.vcol_off; \
1105 wlv.vcol_off = 0; \
1106 wlv.col -= wlv.boguscols; \
1107 old_boguscols = wlv.boguscols; \
1108 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001109 }
1110#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001111# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001112#endif
1113
1114 if (startrow > endrow) // past the end already!
1115 return startrow;
1116
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001117 CLEAR_FIELD(wlv);
1118
1119 wlv.lnum = lnum;
1120 wlv.startrow = startrow;
1121 wlv.row = startrow;
1122 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001123 wlv.fromcol = -10;
1124 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001125#ifdef FEAT_LINEBREAK
1126 wlv.vcol_sbr = -1;
1127#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001128
1129 if (!number_only)
1130 {
1131 // To speed up the loop below, set extra_check when there is linebreak,
1132 // trailing white space and/or syntax processing to be done.
1133#ifdef FEAT_LINEBREAK
1134 extra_check = wp->w_p_lbr;
1135#endif
1136#ifdef FEAT_SYN_HL
1137 if (syntax_present(wp) && !wp->w_s->b_syn_error
1138# ifdef SYN_TIME_LIMIT
1139 && !wp->w_s->b_syn_slow
1140# endif
1141 )
1142 {
1143 // Prepare for syntax highlighting in this line. When there is an
1144 // error, stop syntax highlighting.
1145 save_did_emsg = did_emsg;
1146 did_emsg = FALSE;
1147 syntax_start(wp, lnum);
1148 if (did_emsg)
1149 wp->w_s->b_syn_error = TRUE;
1150 else
1151 {
1152 did_emsg = save_did_emsg;
1153#ifdef SYN_TIME_LIMIT
1154 if (!wp->w_s->b_syn_slow)
1155#endif
1156 {
1157 has_syntax = TRUE;
1158 extra_check = TRUE;
1159 }
1160 }
1161 }
1162
1163 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001164 wlv.color_cols = wp->w_p_cc_cols;
1165 if (wlv.color_cols != NULL)
1166 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001167#endif
1168
1169#ifdef FEAT_TERMINAL
1170 if (term_show_buffer(wp->w_buffer))
1171 {
1172 extra_check = TRUE;
1173 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001174 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001175 }
1176#endif
1177
1178#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001179 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001180 {
1181 // Prepare for spell checking.
1182 has_spell = TRUE;
1183 extra_check = TRUE;
1184
1185 // Get the start of the next line, so that words that wrap to the
1186 // next line are found too: "et<line-break>al.".
1187 // Trick: skip a few chars for C/shell/Vim comments
1188 nextline[SPWORDLEN] = NUL;
1189 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1190 {
1191 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1192 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1193 }
1194
1195 // When a word wrapped from the previous line the start of the
1196 // current line is valid.
1197 if (lnum == checked_lnum)
1198 cur_checked_col = checked_col;
1199 checked_lnum = 0;
1200
1201 // When there was a sentence end in the previous line may require a
1202 // word starting with capital in this line. In line 1 always check
1203 // the first word.
1204 if (lnum != capcol_lnum)
1205 cap_col = -1;
1206 if (lnum == 1)
1207 cap_col = 0;
1208 capcol_lnum = 0;
1209 }
1210#endif
1211
1212 // handle Visual active in this window
1213 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1214 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001215 pos_T *top, *bot;
1216
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001217 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1218 {
1219 // Visual is after curwin->w_cursor
1220 top = &curwin->w_cursor;
1221 bot = &VIsual;
1222 }
1223 else
1224 {
1225 // Visual is before curwin->w_cursor
1226 top = &VIsual;
1227 bot = &curwin->w_cursor;
1228 }
1229 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1230 if (VIsual_mode == Ctrl_V)
1231 {
1232 // block mode
1233 if (lnum_in_visual_area)
1234 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001235 wlv.fromcol = wp->w_old_cursor_fcol;
1236 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001237 }
1238 }
1239 else
1240 {
1241 // non-block mode
1242 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001243 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001244 else if (lnum == top->lnum)
1245 {
1246 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001247 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001248 else
1249 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001250 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001251 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001252 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001253 }
1254 }
1255 if (VIsual_mode != 'V' && lnum == bot->lnum)
1256 {
1257 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1258 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001259 wlv.fromcol = -10;
1260 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001261 }
1262 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001263 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001264 else
1265 {
1266 pos = *bot;
1267 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001268 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1269 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001270 else
1271 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001272 getvvcol(wp, &pos, NULL, NULL,
1273 (colnr_T *)&wlv.tocol);
1274 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001275 }
1276 }
1277 }
1278 }
1279
1280 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001281 if (!highlight_match && lnum == curwin->w_cursor.lnum
1282 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001283#ifdef FEAT_GUI
1284 && !gui.in_use
1285#endif
1286 )
1287 noinvcur = TRUE;
1288
1289 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001290 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001291 {
1292 area_highlighting = TRUE;
1293 vi_attr = HL_ATTR(HLF_V);
1294#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1295 if ((clip_star.available && !clip_star.owned
1296 && clip_isautosel_star())
1297 || (clip_plus.available && !clip_plus.owned
1298 && clip_isautosel_plus()))
1299 vi_attr = HL_ATTR(HLF_VNC);
1300#endif
1301 }
1302 }
1303
1304 // handle 'incsearch' and ":s///c" highlighting
1305 else if (highlight_match
1306 && wp == curwin
1307 && lnum >= curwin->w_cursor.lnum
1308 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1309 {
1310 if (lnum == curwin->w_cursor.lnum)
1311 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001312 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001313 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001314 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001315 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1316 {
1317 pos.lnum = lnum;
1318 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001319 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001320 }
1321 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001322 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001323 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001324 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1325 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001326 area_highlighting = TRUE;
1327 vi_attr = HL_ATTR(HLF_I);
1328 }
1329 }
1330
1331#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001332 wlv.filler_lines = diff_check(wp, lnum);
1333 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001334 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001335 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001336 {
1337 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001338 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001339 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001340 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001341 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001342 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001343 }
1344 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001345 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001346 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001347 area_highlighting = TRUE;
1348 }
1349 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001350 wlv.filler_lines = wp->w_topfill;
1351 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001352#endif
1353
1354#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001355 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001356 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001357 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001358#endif
1359
1360#ifdef LINE_ATTR
1361# ifdef FEAT_SIGNS
1362 // If this line has a sign with line highlighting set line_attr.
1363 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001364 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001365# endif
1366# if defined(FEAT_QUICKFIX)
1367 // Highlight the current line in the quickfix window.
1368 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1369 line_attr = HL_ATTR(HLF_QFL);
1370# endif
1371 if (line_attr != 0)
1372 area_highlighting = TRUE;
1373#endif
1374
1375 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1376 ptr = line;
1377
1378#ifdef FEAT_SPELL
1379 if (has_spell && !number_only)
1380 {
1381 // For checking first word with a capital skip white space.
1382 if (cap_col == 0)
1383 cap_col = getwhitecols(line);
1384
1385 // To be able to spell-check over line boundaries copy the end of the
1386 // current line into nextline[]. Above the start of the next line was
1387 // copied to nextline[SPWORDLEN].
1388 if (nextline[SPWORDLEN] == NUL)
1389 {
1390 // No next line or it is empty.
1391 nextlinecol = MAXCOL;
1392 nextline_idx = 0;
1393 }
1394 else
1395 {
1396 v = (long)STRLEN(line);
1397 if (v < SPWORDLEN)
1398 {
1399 // Short line, use it completely and append the start of the
1400 // next line.
1401 nextlinecol = 0;
1402 mch_memmove(nextline, line, (size_t)v);
1403 STRMOVE(nextline + v, nextline + SPWORDLEN);
1404 nextline_idx = v + 1;
1405 }
1406 else
1407 {
1408 // Long line, use only the last SPWORDLEN bytes.
1409 nextlinecol = v - SPWORDLEN;
1410 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1411 nextline_idx = SPWORDLEN + 1;
1412 }
1413 }
1414 }
1415#endif
1416
1417 if (wp->w_p_list)
1418 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001419 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001420 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001421 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001422 || wp->w_lcs_chars.trail
1423 || wp->w_lcs_chars.lead
1424 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001425 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001426
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001427 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001428 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001429 {
1430 trailcol = (colnr_T)STRLEN(ptr);
1431 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1432 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001433 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001434 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001435 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001436 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001437 {
1438 leadcol = 0;
1439 while (VIM_ISWHITE(ptr[leadcol]))
1440 ++leadcol;
1441 if (ptr[leadcol] == NUL)
1442 // in a line full of spaces all of them are treated as trailing
1443 leadcol = (colnr_T)0;
1444 else
1445 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001446 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001447 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001448 }
1449
Bram Moolenaard7657e92022-09-20 18:59:30 +01001450 wlv.wcr_attr = get_wcr_attr(wp);
1451 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001452 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001453 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001454 area_highlighting = TRUE;
1455 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001456
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001457#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001458 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001459 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001460#endif
1461
1462 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1463 // first character to be displayed.
1464 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001465 v = startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001466 else
1467 v = wp->w_leftcol;
1468 if (v > 0 && !number_only)
1469 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001470 char_u *prev_ptr = ptr;
1471 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001472 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001473
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001474 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001475 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001476 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001477 charsize = win_lbr_chartabsize(&cts, NULL);
1478 cts.cts_vcol += charsize;
1479 prev_ptr = cts.cts_ptr;
1480 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001481 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001482 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001483 ptr = cts.cts_ptr;
1484 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001485
1486 // When:
1487 // - 'cuc' is set, or
1488 // - 'colorcolumn' is set, or
1489 // - 'virtualedit' is set, or
1490 // - the visual mode is active,
1491 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001492 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001493#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001494 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001495#endif
1496 virtual_active() ||
1497 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001498 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001499
1500 // Handle a character that's not completely on the screen: Put ptr at
1501 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001502 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001503 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001504 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001505 ptr = prev_ptr;
1506 // If the character fits on the screen, don't need to skip it.
1507 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001508 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1509 && wlv.col == 0)
1510 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001511 }
1512
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001513#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001514 // If there the text doesn't reach to the desired column, need to skip
1515 // "skip_cells" cells when virtual text follows.
1516 if (!wp->w_p_wrap && v > wlv.vcol)
1517 skip_cells = v - wlv.vcol;
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001518#endif
Bram Moolenaarcd105412022-10-10 19:50:42 +01001519
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001520 // Adjust for when the inverted text is before the screen,
1521 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001522 if (wlv.tocol <= wlv.vcol)
1523 wlv.fromcol = 0;
1524 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1525 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001526
1527#ifdef FEAT_LINEBREAK
1528 // When w_skipcol is non-zero, first line needs 'showbreak'
1529 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001530 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001531#endif
1532#ifdef FEAT_SPELL
1533 // When spell checking a word we need to figure out the start of the
1534 // word and if it's badly spelled or not.
1535 if (has_spell)
1536 {
1537 int len;
1538 colnr_T linecol = (colnr_T)(ptr - line);
1539 hlf_T spell_hlf = HLF_COUNT;
1540
1541 pos = wp->w_cursor;
1542 wp->w_cursor.lnum = lnum;
1543 wp->w_cursor.col = linecol;
1544 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1545
1546 // spell_move_to() may call ml_get() and make "line" invalid
1547 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1548 ptr = line + linecol;
1549
1550 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1551 {
1552 // no bad word found at line start, don't check until end of a
1553 // word
1554 spell_hlf = HLF_COUNT;
1555 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1556 }
1557 else
1558 {
1559 // bad word found, use attributes until end of word
1560 word_end = wp->w_cursor.col + len + 1;
1561
1562 // Turn index into actual attributes.
1563 if (spell_hlf != HLF_COUNT)
1564 spell_attr = highlight_attr[spell_hlf];
1565 }
1566 wp->w_cursor = pos;
1567
1568# ifdef FEAT_SYN_HL
1569 // Need to restart syntax highlighting for this line.
1570 if (has_syntax)
1571 syntax_start(wp, lnum);
1572# endif
1573 }
1574#endif
1575 }
1576
1577 // Correct highlighting for cursor that can't be disabled.
1578 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001579 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001580 {
1581 if (noinvcur)
1582 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001583 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001584 {
1585 // highlighting starts at cursor, let it start just after the
1586 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001587 fromcol_prev = wlv.fromcol;
1588 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001589 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001590 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001591 // restart highlighting after the cursor
1592 fromcol_prev = wp->w_virtcol;
1593 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001594 if (wlv.fromcol >= wlv.tocol)
1595 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001596 }
1597
1598#ifdef FEAT_SEARCH_EXTRA
1599 if (!number_only)
1600 {
1601 v = (long)(ptr - line);
1602 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1603 &line, &screen_search_hl,
1604 &search_attr);
1605 ptr = line + v; // "line" may have been updated
1606 }
1607#endif
1608
1609#ifdef FEAT_SYN_HL
1610 // Cursor line highlighting for 'cursorline' in the current window.
1611 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1612 {
1613 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001614 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001615 if (!(wp == curwin && VIsual_active)
1616 && wp->w_p_culopt_flags != CULOPT_NBR)
1617 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001618 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001619 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1620
1621 // Only set line_attr here when "screenline" is not present in
1622 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001623 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001624 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001625 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001626# ifdef FEAT_SIGNS
1627 // Combine the 'cursorline' and sign highlighting, depending on
1628 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001629 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001630 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001631 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001632 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001633 else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001634 line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001635 }
1636 else
1637# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001638# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001639 // let the line attribute overrule 'cursorline', otherwise
1640 // it disappears when both have background set;
1641 // 'cursorline' can use underline or bold to make it show
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001642 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001643# else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001644 line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001645# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001646 }
1647 else
1648 {
1649 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001650 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1651 }
1652 area_highlighting = TRUE;
1653 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001654 }
1655#endif
1656
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001657#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001658 {
1659 char_u *prop_start;
1660
1661 text_prop_count = get_text_props(wp->w_buffer, lnum,
1662 &prop_start, FALSE);
1663 if (text_prop_count > 0)
1664 {
1665 // Make a copy of the properties, so that they are properly
1666 // aligned.
1667 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1668 if (text_props != NULL)
1669 mch_memmove(text_props, prop_start,
1670 text_prop_count * sizeof(textprop_T));
1671
1672 // Allocate an array for the indexes.
1673 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001674 if (text_prop_idxs == NULL)
1675 VIM_CLEAR(text_props);
1676
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001677 if (text_props != NULL)
1678 {
1679 area_highlighting = TRUE;
1680 extra_check = TRUE;
1681 for (int i = 0; i < text_prop_count; ++i)
1682 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1683 ++wlv.text_prop_above_count;
1684 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001685 }
1686 }
1687#endif
1688
Bram Moolenaar1306b362022-08-06 15:59:06 +01001689 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001690
1691 // Repeat for the whole displayed line.
1692 for (;;)
1693 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001694 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001695#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001696 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001697#endif
1698#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001699 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001700#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001701
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001702 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001703 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001704 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001705#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001706 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001707 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001708 wlv.cul_attr = 0;
zeertzjq4f33bc22021-08-05 17:57:02 +02001709 line_attr = line_attr_save;
1710 }
1711#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001712 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001713 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001714 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001715 if (cmdwin_type != 0 && wp == curwin)
1716 {
1717 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001718 wlv.n_extra = 1;
1719 wlv.c_extra = cmdwin_type;
1720 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001721 wlv.char_attr =
1722 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001723 }
1724 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001725#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001726 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001727 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001728 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001729 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001730 }
1731#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001732#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001733 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001734 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001735 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001736 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001737 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001738 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001739 }
1740#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001741 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001742 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001743 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001744 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001745 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001746 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001747#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001748 // Check if 'breakindent' applies and show it.
1749 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1750 if (wlv.n_extra == 0)
1751 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001752#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001753#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001754 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001755 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001756 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001757 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001758 }
1759#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001760 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001761 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001762 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001763 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001764 }
1765 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001766
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001767#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001768 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001769 && wlv.vcol >= left_curline_col
1770 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001771 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001772 wlv.cul_attr = HL_ATTR(HLF_CUL);
1773 line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001774 }
1775#endif
1776
1777 // When still displaying '$' of change command, stop at cursor.
1778 // When only displaying the (relative) line number and that's done,
1779 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001780 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001781 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001782 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001783#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001784 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001785#endif
1786 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001787 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001788 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001789 // Pretend we have finished updating the window. Except when
1790 // 'cursorcolumn' is set.
1791#ifdef FEAT_SYN_HL
1792 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001793 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001794 else
1795#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001796 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001797 break;
1798 }
1799
Bram Moolenaar1306b362022-08-06 15:59:06 +01001800 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001801 {
1802 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001803 if (wlv.vcol == wlv.fromcol
1804 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1805 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001806 && (*mb_ptr2cells)(ptr) > 1)
1807 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001808 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001809 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001810 area_attr = vi_attr; // start highlighting
1811 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001812 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001813 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001814 area_attr = 0; // stop highlighting
1815
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001816#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001817 if (text_props != NULL)
1818 {
1819 int pi;
1820 int bcol = (int)(ptr - line);
1821
Bram Moolenaar1306b362022-08-06 15:59:06 +01001822 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001823# ifdef FEAT_LINEBREAK
1824 && !in_linebreak
1825# endif
1826 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001827 --bcol; // still working on the previous char, e.g. Tab
1828
1829 // Check if any active property ends.
1830 for (pi = 0; pi < text_props_active; ++pi)
1831 {
1832 int tpi = text_prop_idxs[pi];
1833
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001834 if (text_props[tpi].tp_col != MAXCOL
1835 && bcol >= text_props[tpi].tp_col - 1
1836 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001837 {
1838 if (pi + 1 < text_props_active)
1839 mch_memmove(text_prop_idxs + pi,
1840 text_prop_idxs + pi + 1,
1841 sizeof(int)
1842 * (text_props_active - (pi + 1)));
1843 --text_props_active;
1844 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001845# ifdef FEAT_LINEBREAK
1846 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001847 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001848 syntax_attr = 0;
1849# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001850 }
1851 }
1852
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001853# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001854 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001855 // not on the next char yet, don't start another prop
1856 --bcol;
1857# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001858 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001859 // With 'nowrap' and not in the first screen line only "below"
1860 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001861 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001862 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001863 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001864 && (wp->w_p_wrap
1865 || wlv.row == startrow
1866 || (text_props[text_prop_next].tp_flags
1867 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001868 || (bcol == 0 &&
1869 (text_props[text_prop_next].tp_flags
1870 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001871 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001872 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001873 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001874 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1875 {
1876 // first display the '$' after the line
1877 text_prop_follows = TRUE;
1878 break;
1879 }
1880 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001881 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001882 + text_props[text_prop_next].tp_len)
1883 text_prop_idxs[text_props_active++] = text_prop_next;
1884 ++text_prop_next;
1885 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001886
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001887 if (wlv.n_extra == 0 || !extra_for_textprop)
1888 {
1889 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001890 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001891 text_prop_flags = 0;
1892 text_prop_type = NULL;
1893 text_prop_id = 0;
1894 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001895 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001896 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001897 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001898 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001899 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001900
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001901 // Sort the properties on priority and/or starting last.
1902 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001903 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001904 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001905 sort_text_props(wp->w_buffer, text_props,
1906 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001907
1908 for (pi = 0; pi < text_props_active; ++pi)
1909 {
1910 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001911 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001912 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01001913 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001914
Bram Moolenaarcd105412022-10-10 19:50:42 +01001915 // Only use a text property that can be displayed.
1916 // Skip "after" properties when wrap is off and at the
1917 // end of the window.
1918 if (pt != NULL
1919 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
1920 && tp->tp_id != -MAXCOL
1921 && !(tp->tp_id < 0
1922 && !wp->w_p_wrap
1923 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
1924 | TP_FLAG_ALIGN_ABOVE
1925 | TP_FLAG_ALIGN_BELOW)) == 0
1926 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001927 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001928 if (pt->pt_hl_id > 0)
1929 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001930 text_prop_type = pt;
1931 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001932 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001933 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001934 text_prop_flags = pt->pt_flags;
1935 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001936 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001937 }
1938 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001939 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001940 && -text_prop_id
1941 <= wp->w_buffer->b_textprop_text.ga_len)
1942 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001943 textprop_T *tp = &text_props[used_tpi];
1944 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001945 ->b_textprop_text.ga_data)[
1946 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001947 int above = (tp->tp_flags
1948 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01001949 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001950
1951 // reset the ID in the copy to avoid it being used
1952 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001953 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001954
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001955 if (p != NULL)
1956 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001957 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001958 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001959 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001960 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001961 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1962 int padding = tp->tp_col == MAXCOL
1963 && tp->tp_len > 1
1964 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001965
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001966 // Insert virtual text before the current
1967 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001968 wlv.p_extra = p;
1969 wlv.c_extra = NUL;
1970 wlv.c_final = NUL;
1971 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001972 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001973 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001974 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001975 // restore search_attr and area_attr when n_extra
1976 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001977 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001978 saved_area_attr = area_attr;
1979 search_attr = 0;
1980 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001981 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001982 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001983 if (*ptr == NUL)
1984 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001985 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001986#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001987 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001988 {
1989 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001990 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001991 wlv.need_showbreak = FALSE;
1992 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001993 }
1994#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001995 if ((right || above || below || !wrap
1996 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001997 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001998 char_u *prev_p_extra = wlv.p_extra;
1999 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002000
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002001 // Take care of padding, right-align and
2002 // truncation.
2003 // Shared with win_lbr_chartabsize(), must do
2004 // exactly the same.
2005 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002006 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002007 wlv.col,
2008 &wlv.n_extra, &wlv.p_extra,
2009 &n_attr, &n_attr_skip);
2010 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002011 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002012 // wlv.p_extra was allocated
2013 vim_free(p_extra_free2);
2014 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002015 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002016
Bram Moolenaara4abe512022-09-15 19:44:09 +01002017 if (lcs_eol_one < 0 && wlv.col
2018 + wlv.n_extra - 2 > wp->w_width)
2019 // don't bail out at end of line
2020 lcs_eol_one = 0;
2021
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002022 // When 'wrap' is off then for "below" we need
2023 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002024 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002025 {
2026 draw_screen_line(wp, &wlv);
2027
2028 // When line got too long for screen break
2029 // here.
2030 if (wlv.row == endrow)
2031 {
2032 ++wlv.row;
2033 break;
2034 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002035 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002036 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002037 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002038 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002039 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002040
Bram Moolenaarcd105412022-10-10 19:50:42 +01002041 // If the text didn't reach until the first window
2042 // column we need to skip cells.
2043 if (skip_cells > 0)
2044 {
2045 if (wlv.n_extra > skip_cells)
2046 {
2047 wlv.n_extra -= skip_cells;
2048 wlv.p_extra += skip_cells;
2049 n_attr_skip -= skip_cells;
2050 if (n_attr_skip < 0)
2051 n_attr_skip = 0;
2052 skip_cells = 0;
2053 }
2054 else
2055 {
2056 // the whole text is left of the window, drop
2057 // it and advance to the next one
2058 skip_cells -= wlv.n_extra;
2059 wlv.n_extra = 0;
2060 n_attr_skip = 0;
2061 bail_out = TRUE;
2062 }
2063 }
2064
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002065 // If another text prop follows the condition below at
2066 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002067 // If this is an "above" text prop and 'nowrap' the we
2068 // must wrap anyway.
2069 text_prop_above = above;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002070 text_prop_follows = other_tpi != -1
2071 && (wp->w_p_wrap
2072 || (text_props[other_tpi].tp_flags
2073 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002074
2075 if (bail_out)
2076 // starting a new line for "below"
2077 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002078 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002079 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002080 else if (text_prop_next < text_prop_count
2081 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002082 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2083 || (!wp->w_p_wrap
2084 && wlv.col == wp->w_width - 1
2085 && (text_props[text_prop_next].tp_flags
2086 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002087 // When at last-but-one character and a text property
2088 // follows after it, we may need to flush the line after
2089 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002090 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002091 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002092 }
2093#endif
2094
Bram Moolenaare38fc862022-08-11 17:24:50 +01002095#ifdef FEAT_SEARCH_EXTRA
2096 if (wlv.n_extra == 0)
2097 {
2098 // Check for start/end of 'hlsearch' and other matches.
2099 // After end, check for start/end of next match.
2100 // When another match, have to check for start again.
2101 v = (long)(ptr - line);
2102 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2103 &screen_search_hl, &has_match_conc,
2104 &match_conc, did_line_attr, lcs_eol_one,
2105 &on_last_col);
2106 ptr = line + v; // "line" may have been changed
2107 prev_ptr = ptr;
2108
2109 // Do not allow a conceal over EOL otherwise EOL will be missed
2110 // and bad things happen.
2111 if (*ptr == NUL)
2112 has_match_conc = 0;
2113 }
2114#endif
2115
2116#ifdef FEAT_DIFF
2117 if (wlv.diff_hlf != (hlf_T)0)
2118 {
2119 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2120 && wlv.n_extra == 0)
2121 wlv.diff_hlf = HLF_TXD; // changed text
2122 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2123 && wlv.n_extra == 0)
2124 wlv.diff_hlf = HLF_CHD; // changed line
2125 line_attr = HL_ATTR(wlv.diff_hlf);
2126 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2127 && wp->w_p_culopt_flags != CULOPT_NBR
2128 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2129 && wlv.vcol <= right_curline_col)))
2130 line_attr = hl_combine_attr(
2131 line_attr, HL_ATTR(HLF_CUL));
2132 }
2133#endif
2134
Bram Moolenaara74fda62019-10-19 17:38:03 +02002135#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002136 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002137 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002138 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002139# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002140 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002141 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002142# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002143 // Get syntax attribute.
2144 if (has_syntax)
2145 {
2146 // Get the syntax attribute for the character. If there
2147 // is an error, disable syntax highlighting.
2148 save_did_emsg = did_emsg;
2149 did_emsg = FALSE;
2150
2151 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002152 if (v == prev_syntax_col)
2153 // at same column again
2154 syntax_attr = prev_syntax_attr;
2155 else
2156 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002157# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002158 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002159# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002160 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002161# ifdef FEAT_SPELL
2162 has_spell ? &can_spell :
2163# endif
2164 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002165 prev_syntax_col = v;
2166 prev_syntax_attr = syntax_attr;
2167 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002168
Bram Moolenaar34390282019-10-16 14:38:26 +02002169 if (did_emsg)
2170 {
2171 wp->w_s->b_syn_error = TRUE;
2172 has_syntax = FALSE;
2173 syntax_attr = 0;
2174 }
2175 else
2176 did_emsg = save_did_emsg;
2177# ifdef SYN_TIME_LIMIT
2178 if (wp->w_s->b_syn_slow)
2179 has_syntax = FALSE;
2180# endif
2181
2182 // Need to get the line again, a multi-line regexp may
2183 // have made it invalid.
2184 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2185 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002186 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002187# ifdef FEAT_CONCEAL
2188 // no concealing past the end of the line, it interferes
2189 // with line highlighting
2190 if (*ptr == NUL)
2191 syntax_flags = 0;
2192 else
2193 syntax_flags = get_syntax_info(&syntax_seqnr);
2194# endif
2195 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002196 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002197# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002198 // Combine text property highlight into syntax highlight.
2199 if (text_prop_type != NULL)
2200 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002201 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002202 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2203 else
2204 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002205 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002206 }
2207# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002208#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002209
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002210 // Decide which of the highlight attributes to use.
2211 attr_pri = TRUE;
2212#ifdef LINE_ATTR
2213 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002214 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002215 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002216 if (!highlight_match)
2217 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002218 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002219# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002220 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002221# endif
2222 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002223 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002224 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002225 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002226# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002227 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002228# endif
2229 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002230 else if (line_attr != 0
2231 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2232 || wlv.vcol < wlv.fromcol
2233 || vcol_prev < fromcol_prev
2234 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002235 {
2236 // Use line_attr when not in the Visual or 'incsearch' area
2237 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002238# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002239 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002240# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002241 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002242# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002243 attr_pri = FALSE;
2244 }
2245#else
2246 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002247 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002248 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002249 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002250#endif
2251 else
2252 {
2253 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002254#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002255 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002256#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002257 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002258#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002259 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002260#ifdef FEAT_PROP_POPUP
2261 // override with text property highlight when "override" is TRUE
2262 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002263 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002264#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002265 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002266
2267 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002268 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002269 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002270 if (wlv.char_attr == 0)
2271 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002272 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002273 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002274 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002275
2276 // Get the next character to put on the screen.
2277
2278 // The "p_extra" points to the extra stuff that is inserted to
2279 // represent special characters (non-printable stuff) and other
2280 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002281 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002282 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2283 // "p_extra[n_extra]".
2284 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002285 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002286 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002287 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002288 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002289 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2290 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002291 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2292 if (enc_utf8 && utf_char2len(c) > 1)
2293 {
2294 mb_utf8 = TRUE;
2295 u8cc[0] = 0;
2296 c = 0xc0;
2297 }
2298 else
2299 mb_utf8 = FALSE;
2300 }
2301 else
2302 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002303 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002304 if (has_mbyte)
2305 {
2306 mb_c = c;
2307 if (enc_utf8)
2308 {
2309 // If the UTF-8 character is more than one byte:
2310 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002311 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002312 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002313 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002314 mb_l = 1;
2315 else if (mb_l > 1)
2316 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002317 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002318 mb_utf8 = TRUE;
2319 c = 0xc0;
2320 }
2321 }
2322 else
2323 {
2324 // if this is a DBCS character, put it in "mb_c"
2325 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002326 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002327 mb_l = 1;
2328 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002329 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002330 }
2331 if (mb_l == 0) // at the NUL at end-of-line
2332 mb_l = 1;
2333
2334 // If a double-width char doesn't fit display a '>' in the
2335 // last column.
2336 if ((
2337# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002338 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002339# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002340 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002341 && (*mb_char2cells)(mb_c) == 2)
2342 {
2343 c = '>';
2344 mb_c = c;
2345 mb_l = 1;
2346 mb_utf8 = FALSE;
2347 multi_attr = HL_ATTR(HLF_AT);
2348#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002349 if (wlv.cul_attr)
2350 multi_attr = hl_combine_attr(
2351 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002352#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002353 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002354
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002355 // put the pointer back to output the double-width
2356 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002357 ++wlv.n_extra;
2358 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002359 }
2360 else
2361 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002362 wlv.n_extra -= mb_l - 1;
2363 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002364 }
2365 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002366 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002367 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002368 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002369#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002370 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002371 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002372 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002373 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002374 if (search_attr == 0)
2375 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002376 if (area_attr == 0 && *ptr != NUL)
2377 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002378 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002379#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002380 }
2381 else
2382 {
2383#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002384 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002385#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002386 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002387
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002388 // Get a character from the line itself.
2389 c = *ptr;
2390#ifdef FEAT_LINEBREAK
2391 c0 = *ptr;
2392#endif
2393 if (has_mbyte)
2394 {
2395 mb_c = c;
2396 if (enc_utf8)
2397 {
2398 // If the UTF-8 character is more than one byte: Decode it
2399 // into "mb_c".
2400 mb_l = utfc_ptr2len(ptr);
2401 mb_utf8 = FALSE;
2402 if (mb_l > 1)
2403 {
2404 mb_c = utfc_ptr2char(ptr, u8cc);
2405 // Overlong encoded ASCII or ASCII with composing char
2406 // is displayed normally, except a NUL.
2407 if (mb_c < 0x80)
2408 {
2409 c = mb_c;
2410#ifdef FEAT_LINEBREAK
2411 c0 = mb_c;
2412#endif
2413 }
2414 mb_utf8 = TRUE;
2415
2416 // At start of the line we can have a composing char.
2417 // Draw it as a space with a composing char.
2418 if (utf_iscomposing(mb_c))
2419 {
2420 int i;
2421
2422 for (i = Screen_mco - 1; i > 0; --i)
2423 u8cc[i] = u8cc[i - 1];
2424 u8cc[0] = mb_c;
2425 mb_c = ' ';
2426 }
2427 }
2428
2429 if ((mb_l == 1 && c >= 0x80)
2430 || (mb_l >= 1 && mb_c == 0)
2431 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2432 {
2433 // Illegal UTF-8 byte: display as <xx>.
2434 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002435 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002436# ifdef FEAT_RIGHTLEFT
2437 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002438 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002439# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002440 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002441 c = *wlv.p_extra;
2442 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002443 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002444 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2445 wlv.c_extra = NUL;
2446 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002447 if (area_attr == 0 && search_attr == 0)
2448 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002449 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002450 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002451 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002452 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002453 }
2454 }
2455 else if (mb_l == 0) // at the NUL at end-of-line
2456 mb_l = 1;
2457#ifdef FEAT_ARABIC
2458 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2459 {
2460 // Do Arabic shaping.
2461 int pc, pc1, nc;
2462 int pcc[MAX_MCO];
2463
2464 // The idea of what is the previous and next
2465 // character depends on 'rightleft'.
2466 if (wp->w_p_rl)
2467 {
2468 pc = prev_c;
2469 pc1 = prev_c1;
2470 nc = utf_ptr2char(ptr + mb_l);
2471 prev_c1 = u8cc[0];
2472 }
2473 else
2474 {
2475 pc = utfc_ptr2char(ptr + mb_l, pcc);
2476 nc = prev_c;
2477 pc1 = pcc[0];
2478 }
2479 prev_c = mb_c;
2480
2481 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2482 }
2483 else
2484 prev_c = mb_c;
2485#endif
2486 }
2487 else // enc_dbcs
2488 {
2489 mb_l = MB_BYTE2LEN(c);
2490 if (mb_l == 0) // at the NUL at end-of-line
2491 mb_l = 1;
2492 else if (mb_l > 1)
2493 {
2494 // We assume a second byte below 32 is illegal.
2495 // Hopefully this is OK for all double-byte encodings!
2496 if (ptr[1] >= 32)
2497 mb_c = (c << 8) + ptr[1];
2498 else
2499 {
2500 if (ptr[1] == NUL)
2501 {
2502 // head byte at end of line
2503 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002504 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002505 }
2506 else
2507 {
2508 // illegal tail byte
2509 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002510 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002511 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002512 wlv.p_extra = wlv.extra;
2513 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002514 wlv.c_extra = NUL;
2515 wlv.c_final = NUL;
2516 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002517 if (area_attr == 0 && search_attr == 0)
2518 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002519 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002520 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002521 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002522 // save current attr
2523 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002524 }
2525 mb_c = c;
2526 }
2527 }
2528 }
2529 // If a double-width char doesn't fit display a '>' in the
2530 // last column; the character is displayed at the start of the
2531 // next line.
2532 if ((
2533# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002534 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002535# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002536 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002537 && (*mb_char2cells)(mb_c) == 2)
2538 {
2539 c = '>';
2540 mb_c = c;
2541 mb_utf8 = FALSE;
2542 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002543 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002544 // Put pointer back so that the character will be
2545 // displayed at the start of the next line.
2546 --ptr;
2547#ifdef FEAT_CONCEAL
2548 did_decrement_ptr = TRUE;
2549#endif
2550 }
2551 else if (*ptr != NUL)
2552 ptr += mb_l - 1;
2553
2554 // If a double-width char doesn't fit at the left side display
2555 // a '<' in the first column. Don't do this for unprintable
2556 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002557 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002558 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002559 wlv.n_extra = 1;
2560 wlv.c_extra = MB_FILLER_CHAR;
2561 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002562 c = ' ';
2563 if (area_attr == 0 && search_attr == 0)
2564 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002565 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002566 extra_attr = hl_combine_attr(
2567 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002568 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002569 }
2570 mb_c = c;
2571 mb_utf8 = FALSE;
2572 mb_l = 1;
2573 }
2574
2575 }
2576 ++ptr;
2577
2578 if (extra_check)
2579 {
2580#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002581 // Check spelling (unless at the end of the line).
2582 // Only do this when there is no syntax highlighting, the
2583 // @Spell cluster is not used or the current syntax item
2584 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002585 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002586 if (has_spell && v >= word_end && v > cur_checked_col)
2587 {
2588 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002589 // do not calculate cap_col at the end of the line or when
2590 // only white space is following
2591 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002592# ifdef FEAT_SYN_HL
2593 !has_syntax ||
2594# endif
2595 can_spell))
2596 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002597 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002598 int len;
2599 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002600
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002601 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002602 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002603
2604 // Use nextline[] if possible, it has the start of the
2605 // next line concatenated.
2606 if ((prev_ptr - line) - nextlinecol >= 0)
2607 p = nextline + (prev_ptr - line) - nextlinecol;
2608 else
2609 p = prev_ptr;
2610 cap_col -= (int)(prev_ptr - line);
2611 len = spell_check(wp, p, &spell_hlf, &cap_col,
2612 nochange);
2613 word_end = v + len;
2614
2615 // In Insert mode only highlight a word that
2616 // doesn't touch the cursor.
2617 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002618 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002619 && wp->w_cursor.lnum == lnum
2620 && wp->w_cursor.col >=
2621 (colnr_T)(prev_ptr - line)
2622 && wp->w_cursor.col < (colnr_T)word_end)
2623 {
2624 spell_hlf = HLF_COUNT;
2625 spell_redraw_lnum = lnum;
2626 }
2627
2628 if (spell_hlf == HLF_COUNT && p != prev_ptr
2629 && (p - nextline) + len > nextline_idx)
2630 {
2631 // Remember that the good word continues at the
2632 // start of the next line.
2633 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002634 checked_col = (int)((p - nextline)
2635 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002636 }
2637
2638 // Turn index into actual attributes.
2639 if (spell_hlf != HLF_COUNT)
2640 spell_attr = highlight_attr[spell_hlf];
2641
2642 if (cap_col > 0)
2643 {
2644 if (p != prev_ptr
2645 && (p - nextline) + cap_col >= nextline_idx)
2646 {
2647 // Remember that the word in the next line
2648 // must start with a capital.
2649 capcol_lnum = lnum + 1;
2650 cap_col = (int)((p - nextline) + cap_col
2651 - nextline_idx);
2652 }
2653 else
2654 // Compute the actual column.
2655 cap_col += (int)(prev_ptr - line);
2656 }
2657 }
2658 }
2659 if (spell_attr != 0)
2660 {
2661 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002662 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2663 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002664 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002665 wlv.char_attr = hl_combine_attr(spell_attr,
2666 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002667 }
2668#endif
2669#ifdef FEAT_LINEBREAK
2670 // Found last space before word: check for line break.
2671 if (wp->w_p_lbr && c0 == c
2672 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2673 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002674 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2675 : 0;
2676 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002677 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002678
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002679 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002680# ifdef FEAT_PROP_POPUP
2681 // do not want virtual text counted here
2682 cts.cts_has_prop_with_text = FALSE;
2683# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002684 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002685 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002686
2687 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002688 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002689 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002690 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002691 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2692 if (wlv.n_extra < 0)
2693 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002694 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002695 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002696 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002697 // line break, but for TABs the highlighting should
2698 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002699 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002700
Bram Moolenaar1306b362022-08-06 15:59:06 +01002701 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002702# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002703 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002704 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002705 wp->w_buffer->b_p_vts_array) - 1;
2706# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002707 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002708 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002709# endif
2710
Bram Moolenaar1306b362022-08-06 15:59:06 +01002711 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2712 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002713# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002714 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002715 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002716# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002717 if (VIM_ISWHITE(c))
2718 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002719# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002720 if (c == TAB)
2721 // See "Tab alignment" below.
2722 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002723# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002724 if (!wp->w_p_list)
2725 c = ' ';
2726 }
2727 }
2728#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002729 in_multispace = c == ' '
2730 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2731 if (!in_multispace)
2732 multispace_pos = 0;
2733
Bram Moolenaareed9d462021-02-15 20:38:25 +01002734 // 'list': Change char 160 to 'nbsp' and space to 'space'
2735 // setting in 'listchars'. But not when the character is
2736 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002737 if (wp->w_p_list
2738 && ((((c == 160 && mb_l == 1)
2739 || (mb_utf8
2740 && ((mb_c == 160 && mb_l == 2)
2741 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002742 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002743 || (c == ' '
2744 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002745 && (wp->w_lcs_chars.space
2746 || (in_multispace
2747 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002748 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002749 && ptr - line <= trailcol)))
2750 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002751 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2752 {
2753 c = wp->w_lcs_chars.multispace[multispace_pos++];
2754 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2755 multispace_pos = 0;
2756 }
2757 else
2758 c = (c == ' ') ? wp->w_lcs_chars.space
2759 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002760 if (area_attr == 0 && search_attr == 0)
2761 {
2762 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002763 extra_attr = hl_combine_attr(wlv.win_attr,
2764 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002765 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002766 }
2767 mb_c = c;
2768 if (enc_utf8 && utf_char2len(c) > 1)
2769 {
2770 mb_utf8 = TRUE;
2771 u8cc[0] = 0;
2772 c = 0xc0;
2773 }
2774 else
2775 mb_utf8 = FALSE;
2776 }
2777
zeertzjq2e7cba32022-06-10 15:30:32 +01002778 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2779 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002780 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002781 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2782 && wp->w_lcs_chars.leadmultispace != NULL)
2783 {
2784 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002785 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2786 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002787 multispace_pos = 0;
2788 }
2789
2790 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2791 c = wp->w_lcs_chars.trail;
2792
2793 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2794 c = wp->w_lcs_chars.lead;
2795
zeertzjq2e7cba32022-06-10 15:30:32 +01002796 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002797 c = wp->w_lcs_chars.space;
2798
2799
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002800 if (!attr_pri)
2801 {
2802 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002803 extra_attr = hl_combine_attr(wlv.win_attr,
2804 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002805 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002806 }
2807 mb_c = c;
2808 if (enc_utf8 && utf_char2len(c) > 1)
2809 {
2810 mb_utf8 = TRUE;
2811 u8cc[0] = 0;
2812 c = 0xc0;
2813 }
2814 else
2815 mb_utf8 = FALSE;
2816 }
2817 }
2818
2819 // Handling of non-printable characters.
2820 if (!vim_isprintc(c))
2821 {
2822 // when getting a character from the file, we may have to
2823 // turn it into something else on the way to putting it
2824 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002825 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002826 {
2827 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002828 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002829#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002830 char_u *sbr = get_showbreak_value(wp);
2831
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002832 // only adjust the tab_len, when at the first column
2833 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002834 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002835 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002836#endif
2837 // tab amount depends on current column
2838#ifdef FEAT_VARTABS
2839 tab_len = tabstop_padding(vcol_adjusted,
2840 wp->w_buffer->b_p_ts,
2841 wp->w_buffer->b_p_vts_array) - 1;
2842#else
2843 tab_len = (int)wp->w_buffer->b_p_ts
2844 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2845#endif
2846
2847#ifdef FEAT_LINEBREAK
2848 if (!wp->w_p_lbr || !wp->w_p_list)
2849#endif
2850 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002851 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002852#ifdef FEAT_LINEBREAK
2853 else
2854 {
2855 char_u *p;
2856 int len;
2857 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002858 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002859
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002860# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002861 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002862 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002863 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002864
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002865 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002866 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002867 && old_boguscols > 0
2868 && wlv.n_extra > tab_len)
2869 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002870# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002871 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002872 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002873 // If wlv.n_extra > 0, it gives the number of
2874 // chars, to use for a tab, else we need to
2875 // calculate the width for a tab.
2876 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
2877 len = tab_len * tab2_len;
2878 if (wp->w_lcs_chars.tab3)
2879 len += mb_char2len(wp->w_lcs_chars.tab3)
2880 - tab2_len;
2881 if (wlv.n_extra > 0)
2882 len += wlv.n_extra - tab_len;
2883 c = wp->w_lcs_chars.tab1;
2884 p = alloc(len + 1);
2885 if (p == NULL)
2886 wlv.n_extra = 0;
2887 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002888 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002889 vim_memset(p, ' ', len);
2890 p[len] = NUL;
2891 vim_free(wlv.p_extra_free);
2892 wlv.p_extra_free = p;
2893 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002894 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002895 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002896
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002897 if (*p == NUL)
2898 {
2899 tab_len = i;
2900 break;
2901 }
2902
2903 // if tab3 is given, use it for the last
2904 // char
2905 if (wp->w_lcs_chars.tab3
2906 && i == tab_len - 1)
2907 lcs = wp->w_lcs_chars.tab3;
2908 p += mb_char2bytes(lcs, p);
2909 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002910 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002911 }
2912 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002913# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002914 // n_extra will be increased by
2915 // FIX_FOX_BOGUSCOLS macro below, so need to
2916 // adjust for that here
2917 if (wlv.vcol_off > 0)
2918 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002919# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002920 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002921 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002922 }
2923#endif
2924#ifdef FEAT_CONCEAL
2925 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002926 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002927
2928 // Tab alignment should be identical regardless of
2929 // 'conceallevel' value. So tab compensates of all
2930 // previous concealed characters, and thus resets
2931 // vcol_off and boguscols accumulated so far in the
2932 // line. Note that the tab can be longer than
2933 // 'tabstop' when there are concealed characters.
2934 FIX_FOR_BOGUSCOLS;
2935
2936 // Make sure, the highlighting for the tab char will be
2937 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002938 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002939 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002940 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002941 tab_len += vc_saved;
2942 }
2943#endif
2944 mb_utf8 = FALSE; // don't draw as UTF-8
2945 if (wp->w_p_list)
2946 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002947 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002948 ? wp->w_lcs_chars.tab3
2949 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002950#ifdef FEAT_LINEBREAK
2951 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002952 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002953 else
2954#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002955 wlv.c_extra = wp->w_lcs_chars.tab2;
2956 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002957 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002958 extra_attr = hl_combine_attr(wlv.win_attr,
2959 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002960 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002961 mb_c = c;
2962 if (enc_utf8 && utf_char2len(c) > 1)
2963 {
2964 mb_utf8 = TRUE;
2965 u8cc[0] = 0;
2966 c = 0xc0;
2967 }
2968 }
2969 else
2970 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002971 wlv.c_final = NUL;
2972 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002973 c = ' ';
2974 }
2975 }
2976 else if (c == NUL
2977 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002978 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
2979 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002980 && VIsual_mode != Ctrl_V
2981 && (
2982# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002983 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002984# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002985 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002986 && !(noinvcur
2987 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002988 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002989 && lcs_eol_one > 0)
2990 {
2991 // Display a '$' after the line or highlight an extra
2992 // character if the line break is included.
2993#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2994 // For a diff line the highlighting continues after the
2995 // "$".
2996 if (
2997# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002998 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002999# ifdef LINE_ATTR
3000 &&
3001# endif
3002# endif
3003# ifdef LINE_ATTR
3004 line_attr == 0
3005# endif
3006 )
3007#endif
3008 {
3009 // In virtualedit, visual selections may extend
3010 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003011 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003012 && wlv.tocol != MAXCOL
3013 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003014 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003015 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003016 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003017 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3018 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003019 else
3020 c = ' ';
3021 lcs_eol_one = -1;
3022 --ptr; // put it back at the NUL
3023 if (!attr_pri)
3024 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003025 extra_attr = hl_combine_attr(wlv.win_attr,
3026 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003027 n_attr = 1;
3028 }
3029 mb_c = c;
3030 if (enc_utf8 && utf_char2len(c) > 1)
3031 {
3032 mb_utf8 = TRUE;
3033 u8cc[0] = 0;
3034 c = 0xc0;
3035 }
3036 else
3037 mb_utf8 = FALSE; // don't draw as UTF-8
3038 }
3039 else if (c != NUL)
3040 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003041 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3042 if (wlv.n_extra == 0)
3043 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003044#ifdef FEAT_RIGHTLEFT
3045 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003046 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003047#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003048 wlv.c_extra = NUL;
3049 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003050#ifdef FEAT_LINEBREAK
3051 if (wp->w_p_lbr)
3052 {
3053 char_u *p;
3054
Bram Moolenaar1306b362022-08-06 15:59:06 +01003055 c = *wlv.p_extra;
3056 p = alloc(wlv.n_extra + 1);
3057 vim_memset(p, ' ', wlv.n_extra);
3058 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3059 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003060 vim_free(wlv.p_extra_free);
3061 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003062 }
3063 else
3064#endif
3065 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003066 wlv.n_extra = byte2cells(c) - 1;
3067 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003068 }
3069 if (!attr_pri)
3070 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003071 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003072 extra_attr = hl_combine_attr(wlv.win_attr,
3073 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003074 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003075 }
3076 mb_utf8 = FALSE; // don't draw as UTF-8
3077 }
3078 else if (VIsual_active
3079 && (VIsual_mode == Ctrl_V
3080 || VIsual_mode == 'v')
3081 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003082 && wlv.tocol != MAXCOL
3083 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003084 && (
3085#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003086 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003087#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003088 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003089 {
3090 c = ' ';
3091 --ptr; // put it back at the NUL
3092 }
3093#if defined(LINE_ATTR)
3094 else if ((
3095# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003096 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003097# endif
3098# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003099 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003100# endif
3101 line_attr != 0
3102 ) && (
3103# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003104 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003105# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003106 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003107# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003108 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003109# endif
3110 < wp->w_width)))
3111 {
3112 // Highlight until the right side of the window
3113 c = ' ';
3114 --ptr; // put it back at the NUL
3115
3116 // Remember we do the char for line highlighting.
3117 ++did_line_attr;
3118
3119 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01003120 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003121 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003122 || (wp->w_p_list &&
3123 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003124 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003125# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003126 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003127 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003128 wlv.diff_hlf = HLF_CHD;
3129 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003130 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003131 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003132 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3133 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003134 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003135 || (wlv.vcol >= left_curline_col
3136 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003137 wlv.char_attr = hl_combine_attr(
3138 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003139 }
3140 }
3141# endif
3142# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003143 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003144 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003145 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003146 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3147 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003148 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003149 if (!wlv.cul_screenline
3150 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003151 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003152 wlv.char_attr = hl_combine_attr(
3153 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003154 }
3155 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003156 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3157 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003158 }
3159# endif
3160 }
3161#endif
3162 }
3163
3164#ifdef FEAT_CONCEAL
3165 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003166 && (wp != curwin || lnum != wp->w_cursor.lnum
3167 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003168 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3169 && !(lnum_in_visual_area
3170 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3171 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003172 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003173 if (((prev_syntax_id != syntax_seqnr
3174 && (syntax_flags & HL_CONCEAL) != 0)
3175 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003176 && (syn_get_sub_char() != NUL
3177 || (has_match_conc && match_conc)
3178 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003179 && wp->w_p_cole != 3)
3180 {
3181 // First time at this concealed item: display one
3182 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003183 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003184 c = match_conc;
3185 else if (syn_get_sub_char() != NUL)
3186 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003187 else if (wp->w_lcs_chars.conceal != NUL)
3188 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003189 else
3190 c = ' ';
3191
3192 prev_syntax_id = syntax_seqnr;
3193
Bram Moolenaar1306b362022-08-06 15:59:06 +01003194 if (wlv.n_extra > 0)
3195 wlv.vcol_off += wlv.n_extra;
3196 wlv.vcol += wlv.n_extra;
3197 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003198 {
3199# ifdef FEAT_RIGHTLEFT
3200 if (wp->w_p_rl)
3201 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003202 wlv.col -= wlv.n_extra;
3203 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003204 }
3205 else
3206# endif
3207 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003208 wlv.boguscols += wlv.n_extra;
3209 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003210 }
3211 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003212 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003213 n_attr = 0;
3214 }
3215 else if (n_skip == 0)
3216 {
3217 is_concealing = TRUE;
3218 n_skip = 1;
3219 }
3220 mb_c = c;
3221 if (enc_utf8 && utf_char2len(c) > 1)
3222 {
3223 mb_utf8 = TRUE;
3224 u8cc[0] = 0;
3225 c = 0xc0;
3226 }
3227 else
3228 mb_utf8 = FALSE; // don't draw as UTF-8
3229 }
3230 else
3231 {
3232 prev_syntax_id = 0;
3233 is_concealing = FALSE;
3234 }
3235
3236 if (n_skip > 0 && did_decrement_ptr)
3237 // not showing the '>', put pointer back to avoid getting stuck
3238 ++ptr;
3239
3240#endif // FEAT_CONCEAL
3241 }
3242
3243#ifdef FEAT_CONCEAL
3244 // In the cursor line and we may be concealing characters: correct
3245 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003246 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003247 && wp == curwin && lnum == wp->w_cursor.lnum
3248 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003249 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003250 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003251# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003252 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003253 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003254 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003255# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003256 wp->w_wcol = wlv.col - wlv.boguscols;
3257 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003258 did_wcol = TRUE;
3259 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003260# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003261 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003262# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003263 }
3264#endif
3265
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003266 // Use "extra_attr", but don't override visual selection highlighting,
3267 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003268 // Don't use "extra_attr" until n_attr_skip is zero.
3269 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003270 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003271 && (!attr_pri
3272#ifdef FEAT_PROP_POPUP
3273 || (text_prop_flags & PT_FLAG_OVERRIDE)
3274#endif
3275 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003276 {
3277#ifdef LINE_ATTR
3278 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003279 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003280 else
3281#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003282 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003283 }
3284
3285#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3286 // XIM don't send preedit_start and preedit_end, but they send
3287 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3288 // im_is_preediting() here.
3289 if (p_imst == IM_ON_THE_SPOT
3290 && xic != NULL
3291 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003292 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003293 && !p_imdisable
3294 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003295 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003296 {
3297 colnr_T tcol;
3298
3299 if (preedit_end_col == MAXCOL)
3300 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3301 else
3302 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003303 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003304 {
3305 if (feedback_old_attr < 0)
3306 {
3307 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003308 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003309 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003310 wlv.char_attr = im_get_feedback_attr(feedback_col);
3311 if (wlv.char_attr < 0)
3312 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003313 feedback_col++;
3314 }
3315 else if (feedback_old_attr >= 0)
3316 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003317 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003318 feedback_old_attr = -1;
3319 feedback_col = 0;
3320 }
3321 }
3322#endif
3323 // Handle the case where we are in column 0 but not on the first
3324 // character of the line and the user wants us to show us a
3325 // special character (via 'listchars' option "precedes:<char>".
3326 if (lcs_prec_todo != NUL
3327 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003328 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3329 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003330#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003331 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003332#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003333 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003334 && c != NUL)
3335 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003336 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003337 lcs_prec_todo = NUL;
3338 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3339 {
3340 // Double-width character being overwritten by the "precedes"
3341 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003342 wlv.c_extra = MB_FILLER_CHAR;
3343 wlv.c_final = NUL;
3344 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003345 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003346 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003347 }
3348 mb_c = c;
3349 if (enc_utf8 && utf_char2len(c) > 1)
3350 {
3351 mb_utf8 = TRUE;
3352 u8cc[0] = 0;
3353 c = 0xc0;
3354 }
3355 else
3356 mb_utf8 = FALSE; // don't draw as UTF-8
3357 if (!attr_pri)
3358 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003359 saved_attr3 = wlv.char_attr; // save current attr
3360 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003361 n_attr3 = 1;
3362 }
3363 }
3364
3365 // At end of the text line or just after the last character.
3366 if ((c == NUL
3367#if defined(LINE_ATTR)
3368 || did_line_attr == 1
3369#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003370 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003371 {
3372#ifdef FEAT_SEARCH_EXTRA
3373 // flag to indicate whether prevcol equals startcol of search_hl or
3374 // one of the matches
3375 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3376 (long)(ptr - line) - (c == NUL));
3377#endif
3378 // Invert at least one char, used for Visual and empty line or
3379 // highlight match at end of line. If it's beyond the last
3380 // char on the screen, just overwrite that one (tricky!) Not
3381 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003382 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003383 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003384 && (VIsual_mode != Ctrl_V
3385 || lnum == VIsual.lnum
3386 || lnum == curwin->w_cursor.lnum)
3387 && c == NUL)
3388#ifdef FEAT_SEARCH_EXTRA
3389 // highlight 'hlsearch' match at end of line
3390 || (prevcol_hl_flag
3391# ifdef FEAT_SYN_HL
3392 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3393 && !(wp == curwin && VIsual_active))
3394# endif
3395# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003396 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003397# endif
3398# if defined(LINE_ATTR)
3399 && did_line_attr <= 1
3400# endif
3401 )
3402#endif
3403 ))
3404 {
3405 int n = 0;
3406
3407#ifdef FEAT_RIGHTLEFT
3408 if (wp->w_p_rl)
3409 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003410 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003411 n = 1;
3412 }
3413 else
3414#endif
3415 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003416 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003417 n = -1;
3418 }
3419 if (n != 0)
3420 {
3421 // At the window boundary, highlight the last character
3422 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003423 wlv.off += n;
3424 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003425 }
3426 else
3427 {
3428 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003429 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003430 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003431 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003432 }
3433#ifdef FEAT_SEARCH_EXTRA
3434 if (area_attr == 0)
3435 {
3436 // Use attributes from match with highest priority among
3437 // 'search_hl' and the match list.
3438 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003439 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003440 }
3441#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003442 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003443 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003444#ifdef FEAT_RIGHTLEFT
3445 if (wp->w_p_rl)
3446 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003447 --wlv.col;
3448 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003449 }
3450 else
3451#endif
3452 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003453 ++wlv.col;
3454 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003455 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003456 ++wlv.vcol;
3457 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003458 }
3459 }
3460
3461 // At end of the text line.
3462 if (c == NUL)
3463 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003464 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003465
3466 // Update w_cline_height and w_cline_folded if the cursor line was
3467 // updated (saves a call to plines() later).
3468 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3469 {
3470 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003471 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003472#ifdef FEAT_FOLDING
3473 curwin->w_cline_folded = FALSE;
3474#endif
3475 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3476 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003477 break;
3478 }
3479
3480 // Show "extends" character from 'listchars' if beyond the line end and
3481 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003482 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003483 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003484 && wp->w_p_list
3485 && !wp->w_p_wrap
3486#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003487 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003488#endif
3489 && (
3490#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003491 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003492#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003493 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003494 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003495 || lcs_eol_one > 0
3496 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003497 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003498 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003499 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003500 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003501 mb_c = c;
3502 if (enc_utf8 && utf_char2len(c) > 1)
3503 {
3504 mb_utf8 = TRUE;
3505 u8cc[0] = 0;
3506 c = 0xc0;
3507 }
3508 else
3509 mb_utf8 = FALSE;
3510 }
3511
3512#ifdef FEAT_SYN_HL
3513 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003514 if (wlv.draw_color_col)
3515 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003516
3517 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3518 // highlight the cursor position itself.
3519 // Also highlight the 'colorcolumn' if it is different than
3520 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003521 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3522 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003523 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003524 if (((wlv.draw_state == WL_LINE
3525 || wlv.draw_state == WL_BRI
3526 || wlv.draw_state == WL_SBR)
3527 && !lnum_in_visual_area
3528 && search_attr == 0
3529 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003530# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003531 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003532# endif
3533 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003534 {
3535 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3536 && lnum != wp->w_cursor.lnum)
3537 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003538 vcol_save_attr = wlv.char_attr;
3539 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3540 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003541 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003542 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003543 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003544 vcol_save_attr = wlv.char_attr;
3545 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003546 }
3547 }
3548#endif
3549
3550 // Store character to be displayed.
3551 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003552 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003553 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003554 {
3555 // Store the character.
3556#if defined(FEAT_RIGHTLEFT)
3557 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3558 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003559 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003560 --wlv.off;
3561 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003562 }
3563#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003564 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003565 if (enc_dbcs == DBCS_JPNU)
3566 {
3567 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003568 ScreenLines[wlv.off] = 0x8e;
3569 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003570 }
3571 else if (enc_utf8)
3572 {
3573 if (mb_utf8)
3574 {
3575 int i;
3576
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003577 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003578 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003579 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003580 for (i = 0; i < Screen_mco; ++i)
3581 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003582 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003583 if (u8cc[i] == 0)
3584 break;
3585 }
3586 }
3587 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003588 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003589 }
3590 if (multi_attr)
3591 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003592 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003593 multi_attr = 0;
3594 }
3595 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003596 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003597
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003598 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003599
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003600 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3601 {
3602 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003603 ++wlv.off;
3604 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003605 if (enc_utf8)
3606 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003607 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003608 else
3609 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003610 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003611 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003612#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003613 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003614#endif
3615 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003616 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003617 // When "wlv.tocol" is halfway a character, set it to the end
3618 // of the character, otherwise highlighting won't stop.
3619 if (wlv.tocol == wlv.vcol)
3620 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003621
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003622 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003623
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003624#ifdef FEAT_RIGHTLEFT
3625 if (wp->w_p_rl)
3626 {
3627 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003628 --wlv.off;
3629 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003630 }
3631#endif
3632 }
3633#ifdef FEAT_RIGHTLEFT
3634 if (wp->w_p_rl)
3635 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003636 --wlv.off;
3637 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003638 }
3639 else
3640#endif
3641 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003642 ++wlv.off;
3643 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003644 }
3645 }
3646#ifdef FEAT_CONCEAL
3647 else if (wp->w_p_cole > 0 && is_concealing)
3648 {
3649 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003650 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003651 if (wlv.n_extra > 0)
3652 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003653 if (wp->w_p_wrap)
3654 {
3655 // Special voodoo required if 'wrap' is on.
3656 //
3657 // Advance the column indicator to force the line
3658 // drawing to wrap early. This will make the line
3659 // take up the same screen space when parts are concealed,
3660 // so that cursor line computations aren't messed up.
3661 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003662 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003663 // trailing junk to be written out of the screen line
3664 // we are building, 'boguscols' keeps track of the number
3665 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003666 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003667 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003668 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003669# ifdef FEAT_RIGHTLEFT
3670 if (wp->w_p_rl)
3671 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003672 wlv.col -= wlv.n_extra;
3673 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003674 }
3675 else
3676# endif
3677 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003678 wlv.col += wlv.n_extra;
3679 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003680 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003681 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003682 n_attr = 0;
3683 }
3684
3685
3686 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3687 {
3688 // Need to fill two screen columns.
3689# ifdef FEAT_RIGHTLEFT
3690 if (wp->w_p_rl)
3691 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003692 --wlv.boguscols;
3693 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003694 }
3695 else
3696# endif
3697 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003698 ++wlv.boguscols;
3699 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003700 }
3701 }
3702
3703# ifdef FEAT_RIGHTLEFT
3704 if (wp->w_p_rl)
3705 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003706 --wlv.boguscols;
3707 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003708 }
3709 else
3710# endif
3711 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003712 ++wlv.boguscols;
3713 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003714 }
3715 }
3716 else
3717 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003718 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003719 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003720 wlv.vcol += wlv.n_extra;
3721 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003722 n_attr = 0;
3723 }
3724 }
3725
3726 }
3727#endif // FEAT_CONCEAL
3728 else
3729 --n_skip;
3730
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003731 // Only advance the "wlv.vcol" when after the 'number' or
3732 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003733 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003734#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003735 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003736#endif
3737 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003738 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003739
3740#ifdef FEAT_SYN_HL
3741 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003742 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003743#endif
3744
3745 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003746 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3747 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003748
3749 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003750 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003751 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003752 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003753 if (n_attr_skip > 0)
3754 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003755
3756 // At end of screen line and there is more to come: Display the line
3757 // so far. If there is no more to display it is caught above.
3758 if ((
3759#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003760 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003761#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003762 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003763 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003764 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003765#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003766 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003767#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003768#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003769 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003770#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003771 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003772 && wlv.p_extra != at_end_str)
3773 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3774 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003775 )
3776 {
3777#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003778 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003779 wlv_screen_line(wp, &wlv, FALSE);
3780 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003781 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003782#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003783 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003784#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003785 ++wlv.row;
3786 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003787
3788 // When not wrapping and finished diff lines, or when displayed
3789 // '$' and highlighting until last column, break here.
3790 if ((!wp->w_p_wrap
3791#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003792 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003793#endif
3794#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003795 && !text_prop_above && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003796#endif
3797 ) || lcs_eol_one == -1)
3798 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003799#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003800 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003801 {
3802 // do not output more of the line, only the "below" prop
3803 ptr += STRLEN(ptr);
3804# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003805 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003806# endif
3807 }
3808#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003809
3810 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003811 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003812#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003813 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003814#endif
3815 )
3816 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003817 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3818 draw_vsep_win(wp, wlv.row);
3819 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003820 }
3821
3822 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003823 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003824 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003825 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003826 break;
3827 }
3828
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003829 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003830#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003831 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003832#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003833#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003834 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003835#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003836 && wp->w_width == Columns)
3837 {
3838 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003839 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003840
3841 // Special trick to make copy/paste of wrapped lines work with
3842 // xterm/screen: write an extra character beyond the end of
3843 // the line. This will work with all terminal types
3844 // (regardless of the xn,am settings).
3845 // Only do this on a fast tty.
3846 // Only do this if the cursor is on the current line
3847 // (something has been written in it).
3848 // Don't do this for the GUI.
3849 // Don't do this for double-width characters.
3850 // Don't do this for a window not at the right screen border.
3851 if (p_tf
3852#ifdef FEAT_GUI
3853 && !gui.in_use
3854#endif
3855 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003856 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3857 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003858 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003859 || (*mb_off2cells)(
3860 LineOffset[wlv.screen_row - 1]
3861 + (int)Columns - 2,
3862 LineOffset[wlv.screen_row]
3863 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003864 {
3865 // First make sure we are at the end of the screen line,
3866 // then output the same character again to let the
3867 // terminal know about the wrap. If the terminal doesn't
3868 // auto-wrap, we overwrite the character.
3869 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003870 screen_char(LineOffset[wlv.screen_row - 1]
3871 + (unsigned)Columns - 1,
3872 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003873
3874 // When there is a multi-byte character, just output a
3875 // space to keep it simple.
3876 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003877 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003878 out_char(' ');
3879 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003880 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003881 + (Columns - 1)]);
3882 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003883 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003884 screen_start(); // don't know where cursor is now
3885 }
3886 }
3887
Bram Moolenaar1306b362022-08-06 15:59:06 +01003888 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003889
Bram Moolenaareed9d462021-02-15 20:38:25 +01003890 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003891#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003892 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003893# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003894 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003895# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003896 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003897 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003898#endif
3899#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003900 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003901 // When the filler lines are actually below the last line of the
3902 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003903 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003904 break;
3905#endif
3906 }
3907
3908 } // for every character in the line
3909
3910#ifdef FEAT_SPELL
3911 // After an empty line check first word for capital.
3912 if (*skipwhite(line) == NUL)
3913 {
3914 capcol_lnum = lnum + 1;
3915 cap_col = 0;
3916 }
3917#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003918#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003919 vim_free(text_props);
3920 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003921 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003922#endif
3923
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003924 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003925 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003926}