blob: 9347fda21b7532c59dcd315fb4088f5e8f0829b2 [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 Moolenaaree28c702022-11-17 14:56:00 +0000133 int extra_attr; // attributes for p_extra, should be combined
134 // with win_attr if needed
Bram Moolenaar1306b362022-08-06 15:59:06 +0100135 int c_extra; // extra chars, all the same
136 int c_final; // final char, mandatory if set
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000137 int extra_for_textprop; // wlv.n_extra set for textprop
Bram Moolenaar1306b362022-08-06 15:59:06 +0100138
139 // saved "extra" items for when draw_state becomes WL_LINE (again)
140 int saved_n_extra;
141 char_u *saved_p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000142 int saved_extra_attr;
143 int saved_extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100144 int saved_c_extra;
145 int saved_c_final;
146 int saved_char_attr;
147
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100148 char_u extra[NUMBUFLEN + MB_MAXBYTES];
149 // "%ld " and 'fdc' must fit in here, as well
150 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100151
Bram Moolenaar1306b362022-08-06 15:59:06 +0100152#ifdef FEAT_DIFF
153 hlf_T diff_hlf; // type of diff highlighting
154#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100155 int filler_lines; // nr of filler lines to be drawn
156 int filler_todo; // nr of filler lines still to do + 1
157#ifdef FEAT_SIGNS
158 sign_attrs_T sattr;
159#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100160} winlinevars_T;
161
162// draw_state values for items that are drawn in sequence:
163#define WL_START 0 // nothing done yet, must be zero
Martin Tournoij7904fa42022-10-04 16:28:45 +0100164#define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar1306b362022-08-06 15:59:06 +0100165#ifdef FEAT_FOLDING
166# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
167#else
168# define WL_FOLD WL_CMDLINE
169#endif
170#ifdef FEAT_SIGNS
171# define WL_SIGN (WL_FOLD + 1) // column for signs
172#else
173# define WL_SIGN WL_FOLD // column for signs
174#endif
175#define WL_NR (WL_SIGN + 1) // line number
176#ifdef FEAT_LINEBREAK
177# define WL_BRI (WL_NR + 1) // 'breakindent'
178#else
179# define WL_BRI WL_NR
180#endif
181#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
182# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
183#else
184# define WL_SBR WL_BRI
185#endif
186#define WL_LINE (WL_SBR + 1) // text in the line
187
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100188#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200189/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000190 * Return TRUE if CursorLineSign highlight is to be used.
191 */
192 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100193use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000194{
195 return wp->w_p_cul
196 && lnum == wp->w_cursor.lnum
197 && (wp->w_p_culopt_flags & CULOPT_NBR);
198}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100199#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000200
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100201
202#ifdef FEAT_FOLDING
203/*
204 * Setup for drawing the 'foldcolumn', if there is one.
205 */
206 static void
207handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
208{
209 int fdc = compute_foldcolumn(wp, 0);
210
211 if (fdc <= 0)
212 return;
213
214 // Allocate a buffer, "wlv->extra[]" may already be in use.
215 vim_free(wlv->p_extra_free);
216 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
217 if (wlv->p_extra_free != NULL)
218 {
219 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
220 wp, FALSE, wlv->lnum);
221 wlv->p_extra_free[wlv->n_extra] = NUL;
222 wlv->p_extra = wlv->p_extra_free;
223 wlv->c_extra = NUL;
224 wlv->c_final = NUL;
225 if (use_cursor_line_highlight(wp, wlv->lnum))
226 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
227 else
228 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
229 }
230}
231#endif
232
233#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000234/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100235 * Get information needed to display the sign in line "wlv->lnum" in window
236 * "wp".
237 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200238 * Otherwise the sign is going to be displayed in the sign column.
239 */
240 static void
241get_sign_display_info(
242 int nrcol,
243 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100244 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200245{
246 int text_sign;
247# ifdef FEAT_SIGN_ICONS
248 int icon_sign;
249# endif
250
251 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100252 wlv->c_extra = ' ';
253 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200254 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100255 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200256 else
257 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100258 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100259 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000260 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100261 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100262 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200263 }
264
Bram Moolenaar1306b362022-08-06 15:59:06 +0100265 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200266#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100267 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200268#endif
269 )
270 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100271 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200272# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100273 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200274 if (gui.in_use && icon_sign != 0)
275 {
276 // Use the image in this position.
277 if (nrcol)
278 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100279 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100280 sprintf((char *)wlv->extra, "%-*c ",
281 number_width(wp), SIGN_BYTE);
282 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100283 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200284 }
285 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100286 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200287# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100288 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
289 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200290 {
291 if (nrcol)
292 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100293 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100294 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200295 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100296 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100297 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200298 }
299 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100300 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200301 }
302# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100303 wlv->c_final = NUL;
304 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200305 }
306 else
307# endif
308 if (text_sign != 0)
309 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100310 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100311 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200312 {
313 if (nrcol)
314 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100315 int width = number_width(wp) - 2;
316 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200317
318 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100319 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100320 vim_snprintf((char *)wlv->extra + n,
321 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100322 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200323 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100324 wlv->c_extra = NUL;
325 wlv->c_final = NUL;
326 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200327 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000328
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100329 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100330 && wlv->sattr.sat_culhl > 0)
331 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000332 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100333 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200334 }
335 }
336}
337#endif
338
Bram Moolenaard7657e92022-09-20 18:59:30 +0100339/*
340 * Display the absolute or relative line number. After the first row fill with
341 * blanks when the 'n' flag isn't in 'cpo'.
342 */
343 static void
344handle_lnum_col(
345 win_T *wp,
346 winlinevars_T *wlv,
347 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100348 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100349{
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100350 int has_cpo_n = vim_strchr(p_cpo, CPO_NUMCOL) != NULL;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100351 int lnum_row = wlv->startrow + wlv->filler_lines
352#ifdef FEAT_PROP_POPUP
353 + wlv->text_prop_above_count
354#endif
355 ;
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100356
Bram Moolenaard7657e92022-09-20 18:59:30 +0100357 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100358 && (wlv->row <= lnum_row || !has_cpo_n)
Bram Moolenaar37251162022-10-06 20:48:00 +0100359 // there is no line number in a wrapped line when "n" is in
360 // 'cpoptions', but 'breakindent' assumes it anyway.
361 && !((has_cpo_n
362#ifdef FEAT_LINEBREAK
363 && !wp->w_p_bri
364#endif
365 ) && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100366 {
367#ifdef FEAT_SIGNS
368 // If 'signcolumn' is set to 'number' and a sign is present
369 // in 'lnum', then display the sign instead of the line
370 // number.
371 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
372 get_sign_display_info(TRUE, wp, wlv);
373 else
374#endif
375 {
376 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100377 // When there are text properties above the line put the line number
378 // below them.
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100379 if (wlv->row == lnum_row
Bram Moolenaareb4de622022-10-15 13:42:17 +0100380 && (wp->w_skipcol == 0 || wlv->row > wp->w_winrow
381 || (wp->w_p_nu && wp->w_p_rnu)))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100382 {
383 long num;
384 char *fmt = "%*ld ";
385
386 if (wp->w_p_nu && !wp->w_p_rnu)
387 // 'number' + 'norelativenumber'
388 num = (long)wlv->lnum;
389 else
390 {
391 // 'relativenumber', don't use negative numbers
392 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
393 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
394 {
395 // 'number' + 'relativenumber'
396 num = wlv->lnum;
397 fmt = "%-*ld ";
398 }
399 }
400
401 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100402 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100403 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
404 ++wlv->p_extra)
405 *wlv->p_extra = '-';
406#ifdef FEAT_RIGHTLEFT
407 if (wp->w_p_rl) // reverse line numbers
408 {
409 char_u *p1, *p2;
410 int t;
411
412 // like rl_mirror(), but keep the space at the end
413 p2 = skipwhite(wlv->extra);
414 p2 = skiptowhite(p2) - 1;
415 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
416 {
417 t = *p1;
418 *p1 = *p2;
419 *p2 = t;
420 }
421 }
422#endif
423 wlv->p_extra = wlv->extra;
424 wlv->c_extra = NUL;
425 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100426 }
427 else
428 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100429 wlv->c_extra = ' ';
430 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100431 }
432 wlv->n_extra = number_width(wp) + 1;
433 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
434#ifdef FEAT_SYN_HL
435 // When 'cursorline' is set highlight the line number of
436 // the current line differently.
437 // When 'cursorlineopt' does not have "line" only
438 // highlight the line number itself.
439 // TODO: Can we use CursorLine instead of CursorLineNr
440 // when CursorLineNr isn't set?
441 if (wp->w_p_cul
442 && wlv->lnum == wp->w_cursor.lnum
443 && (wp->w_p_culopt_flags & CULOPT_NBR)
444 && (wlv->row == wlv->startrow + wlv->filler_lines
445 || (wlv->row > wlv->startrow + wlv->filler_lines
446 && (wp->w_p_culopt_flags & CULOPT_LINE))))
447 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
448#endif
449 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
450 && HL_ATTR(HLF_LNA) != 0)
451 // Use LineNrAbove
452 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
453 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
454 && HL_ATTR(HLF_LNB) != 0)
455 // Use LineNrBelow
456 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
457 }
458#ifdef FEAT_SIGNS
459 if (num_attr)
460 wlv->char_attr = num_attr;
461#endif
462 }
463}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100464
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100465#ifdef FEAT_LINEBREAK
466 static void
467handle_breakindent(win_T *wp, winlinevars_T *wlv)
468{
469 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100470 && *get_showbreak_value(wp) != NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100471 // draw indent after showbreak value
472 wlv->draw_state = WL_BRI;
473 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
474 // After the showbreak, draw the breakindent
475 wlv->draw_state = WL_BRI - 1;
476
477 // draw 'breakindent': indent wrapped text accordingly
478 if (wlv->draw_state == WL_BRI - 1)
479 {
480 wlv->draw_state = WL_BRI;
481 // if wlv->need_showbreak is set, breakindent also applies
482 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
483# ifdef FEAT_DIFF
484 && wlv->filler_lines == 0
485# endif
486# ifdef FEAT_PROP_POPUP
487 && !wlv->dont_use_showbreak
488# endif
489 )
490 {
491 wlv->char_attr = 0;
492# ifdef FEAT_DIFF
493 if (wlv->diff_hlf != (hlf_T)0)
494 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
495# endif
496 wlv->p_extra = NULL;
497 wlv->c_extra = ' ';
498 wlv->c_final = NUL;
499 wlv->n_extra = get_breakindent_win(wp,
500 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
501 if (wlv->row == wlv->startrow)
502 {
503 wlv->n_extra -= win_col_off2(wp);
504 if (wlv->n_extra < 0)
505 wlv->n_extra = 0;
506 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100507 if (wp->w_skipcol > 0 && wlv->startrow == 0
508 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100509 wlv->need_showbreak = FALSE;
510 // Correct end of highlighted area for 'breakindent',
511 // required when 'linebreak' is also set.
512 if (wlv->tocol == wlv->vcol)
513 wlv->tocol += wlv->n_extra;
514 }
515 }
516}
517#endif
518
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100519#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
520 static void
521handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
522{
523# ifdef FEAT_DIFF
524 if (wlv->filler_todo > 0)
525 {
526 // Draw "deleted" diff line(s).
527 if (char2cells(wp->w_fill_chars.diff) > 1)
528 {
529 wlv->c_extra = '-';
530 wlv->c_final = NUL;
531 }
532 else
533 {
534 wlv->c_extra = wp->w_fill_chars.diff;
535 wlv->c_final = NUL;
536 }
537# ifdef FEAT_RIGHTLEFT
538 if (wp->w_p_rl)
539 wlv->n_extra = wlv->col + 1;
540 else
541# endif
542 wlv->n_extra = wp->w_width - wlv->col;
543 wlv->char_attr = HL_ATTR(HLF_DED);
544 }
545# endif
546
547# ifdef FEAT_LINEBREAK
548 char_u *sbr = get_showbreak_value(wp);
549 if (*sbr != NUL && wlv->need_showbreak)
550 {
551 // Draw 'showbreak' at the start of each broken line.
552 wlv->p_extra = sbr;
553 wlv->c_extra = NUL;
554 wlv->c_final = NUL;
555 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100556 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100557 wlv->need_showbreak = FALSE;
558 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
559 // Correct end of highlighted area for 'showbreak',
560 // required when 'linebreak' is also set.
561 if (wlv->tocol == wlv->vcol)
562 wlv->tocol += wlv->n_extra;
563 // combine 'showbreak' with 'wincolor'
564 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
565# ifdef FEAT_SYN_HL
566 // combine 'showbreak' with 'cursorline'
567 if (wlv->cul_attr != 0)
568 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
569# endif
570 }
571# endif
572}
573#endif
574
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100575#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100576/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100577 * Return the cell size of virtual text after truncation.
578 */
579 static int
580textprop_size_after_trunc(
581 win_T *wp,
582 int flags, // TP_FLAG_ALIGN_*
583 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100584 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100585 char_u *text,
586 int *n_used_ptr)
587{
588 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100589 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100590 int len = (int)STRLEN(text);
591 int strsize = 0;
592 int n_used;
593
Bram Moolenaar7e017462022-10-11 21:02:09 +0100594 // if the remaining size is to small and 'wrap' is set we wrap anyway and
595 // use the next line
596 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100597 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100598 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100599 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100600 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
601 {
602 int clen = ptr2cells(text + n_used);
603
604 if (strsize + clen > space)
605 break;
606 strsize += clen;
607 }
608 *n_used_ptr = n_used;
609 return strsize;
610}
611
612/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100613 * Take care of padding, right-align and truncation of virtual text after a
614 * line.
615 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
616 * padding, right-align and truncation. Otherwise only the size is computed.
617 * When "n_attr" is NULL returns the number of screen cells used.
618 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100619 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100620 int
621text_prop_position(
622 win_T *wp,
623 textprop_T *tp,
porygonisaduck38854b52022-11-27 20:55:05 +0000624 int vcol, // current text column
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100625 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100626 int *n_extra, // nr of bytes for virtual text
627 char_u **p_extra, // virtual text
628 int *n_attr, // attribute cells, NULL if not used
629 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200630{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100631 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100632 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100633 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
634 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
635 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
porygonisaduck38854b52022-11-27 20:55:05 +0000636 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100637 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100638 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100639 int before = room; // spaces before the text
640 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100641 int n_used = *n_extra;
642 char_u *l = NULL;
643 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100644 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100645 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar1206c162022-10-10 15:40:04 +0100646 int cont_on_next_line = below && col_with_padding > win_col_off(wp)
647 && !wp->w_p_wrap;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200648
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100649 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100650 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100651 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100652 int skip_add = 0;
653
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100654 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100655 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100656 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100657 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100658 }
659 else
660 {
661 // Right-align: fill with before
662 if (right)
663 before -= cells;
porygonisaduck38854b52022-11-27 20:55:05 +0000664
665 // Below-align: empty line add one character
Bram Moolenaar7c02ad92022-11-29 21:37:13 +0000666 if (below && vcol == 0 && col_with_padding == col_off
667 && wp->w_width - col_off == before)
668 col_with_padding += 1;
porygonisaduck38854b52022-11-27 20:55:05 +0000669
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100670 if (before < 0
671 || !(right || below)
porygonisaduck38854b52022-11-27 20:55:05 +0000672 || (below ? (col_with_padding <= col_off || !wp->w_p_wrap)
673 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100674 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100675 if (right && (wrap
676 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100677 {
678 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100679 before = wp->w_width - col_off - strsize + room;
680 if (before < 0)
681 before = 0;
682 else
683 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100684 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100685 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100686 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100687 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100688 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100689 else if (below && before > 0)
690 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100691 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100692 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100693
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100694 // With 'nowrap' add one to show the "extends" character if needed (it
695 // doesn't show if the text just fits).
696 if (!wp->w_p_wrap
697 && n_used < *n_extra
698 && wp->w_lcs_chars.ext != NUL
699 && wp->w_p_list)
700 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100701 if (!wp->w_p_wrap && below && padding > 0)
702 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100703
704 // add 1 for NUL, 2 for when '…' is used
705 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100706 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100707 if (n_attr == NULL || l != NULL)
708 {
709 int off = 0;
710
711 if (n_attr != NULL)
712 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100713 vim_memset(l, ' ', before);
714 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100715 if (padding > 0)
716 {
717 vim_memset(l + off, ' ', padding);
718 off += padding;
719 }
720 vim_strncpy(l + off, *p_extra, n_used);
721 off += n_used;
722 }
723 else
724 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100725 off = before + after + padding + n_used;
726 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100727 }
728 if (n_attr != NULL)
729 {
730 if (n_used < *n_extra && wp->w_p_wrap)
731 {
732 char_u *lp = l + off - 1;
733
734 if (has_mbyte)
735 {
736 // change last character to '…'
737 lp -= (*mb_head_off)(l, lp);
738 STRCPY(lp, "…");
Bram Moolenaar13845c42022-10-09 15:26:03 +0100739 n_used = lp - l + 3 - before - padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100740 }
741 else
742 // change last character to '>'
743 *lp = '>';
744 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100745 else if (after > 0)
746 {
747 vim_memset(l + off, ' ', after);
748 l[off + after] = NUL;
749 }
750
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100751 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100752 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100753 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100754 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100755 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100756
757 // Add "skip_add" when starting a new line or wrapping,
758 // n_attr_skip will then be decremented in the number column.
759 *n_attr_skip = before + padding
760 + (cont_on_next_line || before > 0 ? skip_add : 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100761 }
762 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100763 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100764
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100765 if (n_attr == NULL)
766 return cells;
767 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200768}
769#endif
770
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100771/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100772 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100773 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
774 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100775 */
776 static void
777wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
778{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100779 if (wlv->row == 0 && wp->w_skipcol > 0
780#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100781 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100782 && *get_showbreak_value(wp) == NUL
783#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100784 // do not overwrite the 'listchars' "precedes" text with "<<<"
785 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100786 {
787 int off = (int)(current_ScreenLine - ScreenLines);
Bram Moolenaareb4de622022-10-15 13:42:17 +0100788 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100789
Bram Moolenaareb4de622022-10-15 13:42:17 +0100790 if (wp->w_p_nu && wp->w_p_rnu)
791 // Do not overwrite the line number, change "123 text" to
792 // "123>>>xt".
793 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
794 {
795 ++off;
796 ++skip;
797 }
798
799 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100800 {
801 ScreenLines[off] = '<';
802 if (enc_utf8)
803 ScreenLinesUC[off] = 0;
804 ScreenAttrs[off] = HL_ATTR(HLF_AT);
805 ++off;
806 }
807 }
808
809 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
810 negative_width ? -wp->w_width : wp->w_width,
811 wlv->screen_line_flags);
812}
813
814/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100815 * Called when finished with the line: draw the screen line and handle any
816 * highlighting until the right of the window.
817 */
818 static void
819draw_screen_line(win_T *wp, winlinevars_T *wlv)
820{
821#ifdef FEAT_SYN_HL
822 long v;
823
824 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
825 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100826 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100827 else
828 v = wp->w_leftcol;
829
830 // check if line ends before left margin
831 if (wlv->vcol < v + wlv->col - win_col_off(wp))
832 wlv->vcol = v + wlv->col - win_col_off(wp);
833# ifdef FEAT_CONCEAL
834 // Get rid of the boguscols now, we want to draw until the right
835 // edge for 'cursorcolumn'.
836 wlv->col -= wlv->boguscols;
837 wlv->boguscols = 0;
838# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
839# else
840# define VCOL_HLC (wlv->vcol)
841# endif
842
843 if (wlv->draw_color_col)
844 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
845
846 if (((wp->w_p_cuc
847 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
848 && (int)wp->w_virtcol <
849 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
850 && wlv->lnum != wp->w_cursor.lnum)
851 || wlv->draw_color_col
852 || wlv->win_attr != 0)
853# ifdef FEAT_RIGHTLEFT
854 && !wp->w_p_rl
855# endif
856 )
857 {
858 int rightmost_vcol = 0;
859 int i;
860
861 if (wp->w_p_cuc)
862 rightmost_vcol = wp->w_virtcol;
863 if (wlv->draw_color_col)
864 // determine rightmost colorcolumn to possibly draw
865 for (i = 0; wlv->color_cols[i] >= 0; ++i)
866 if (rightmost_vcol < wlv->color_cols[i])
867 rightmost_vcol = wlv->color_cols[i];
868
869 while (wlv->col < wp->w_width)
870 {
871 ScreenLines[wlv->off] = ' ';
872 if (enc_utf8)
873 ScreenLinesUC[wlv->off] = 0;
874 ScreenCols[wlv->off] = MAXCOL;
875 ++wlv->col;
876 if (wlv->draw_color_col)
877 wlv->draw_color_col = advance_color_col(
878 VCOL_HLC, &wlv->color_cols);
879
880 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
881 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
882 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
883 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
884 else
885 ScreenAttrs[wlv->off++] = wlv->win_attr;
886
887 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
888 break;
889
890 ++wlv->vcol;
891 }
892 }
893#endif
894
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100895 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100896 ++wlv->row;
897 ++wlv->screen_row;
898}
899#undef VCOL_HLC
900
901/*
902 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100903 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100904 */
905 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100906win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100907{
908 wlv->col = 0;
909 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
910
911#ifdef FEAT_RIGHTLEFT
912 if (wp->w_p_rl)
913 {
914 // Rightleft window: process the text in the normal direction, but put
915 // it in current_ScreenLine[] from right to left. Start at the
916 // rightmost column of the window.
917 wlv->col = wp->w_width - 1;
918 wlv->off += wlv->col;
919 wlv->screen_line_flags |= SLF_RIGHTLEFT;
920 }
921#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100922 if (save_extra)
923 {
924 // reset the drawing state for the start of a wrapped line
925 wlv->draw_state = WL_START;
926 wlv->saved_n_extra = wlv->n_extra;
927 wlv->saved_p_extra = wlv->p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000928 wlv->saved_extra_attr = wlv->extra_attr;
929 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100930 wlv->saved_c_extra = wlv->c_extra;
931 wlv->saved_c_final = wlv->c_final;
932#ifdef FEAT_SYN_HL
933 if (!(wlv->cul_screenline
934# ifdef FEAT_DIFF
935 && wlv->diff_hlf == (hlf_T)0
936# endif
937 ))
938 wlv->saved_char_attr = wlv->char_attr;
939 else
940#endif
941 wlv->saved_char_attr = 0;
942 wlv->n_extra = 0;
943 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100944}
945
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200946/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100947 * Called when wlv->draw_state is set to WL_LINE.
948 */
949 static void
950win_line_continue(winlinevars_T *wlv)
951{
952 if (wlv->saved_n_extra > 0)
953 {
954 // Continue item from end of wrapped line.
955 wlv->n_extra = wlv->saved_n_extra;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +0000956 wlv->saved_n_extra = 0;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100957 wlv->c_extra = wlv->saved_c_extra;
958 wlv->c_final = wlv->saved_c_final;
959 wlv->p_extra = wlv->saved_p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000960 wlv->extra_attr = wlv->saved_extra_attr;
961 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100962 wlv->char_attr = wlv->saved_char_attr;
963 }
964 else
965 wlv->char_attr = wlv->win_attr;
966}
967
968/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200969 * Display line "lnum" of window 'wp' on the screen.
970 * Start at row "startrow", stop when "endrow" is reached.
971 * wp->w_virtcol needs to be valid.
972 *
973 * Return the number of last row the line occupies.
974 */
975 int
976win_line(
977 win_T *wp,
978 linenr_T lnum,
979 int startrow,
980 int endrow,
981 int nochange UNUSED, // not updating for changed text
982 int number_only) // only update the number column
983{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100984 winlinevars_T wlv; // variables passed between functions
985
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200986 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100987 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200988 char_u *line; // current line
989 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200990
Bram Moolenaar1306b362022-08-06 15:59:06 +0100991#ifdef FEAT_PROP_POPUP
992 char_u *p_extra_free2 = NULL; // another p_extra to be freed
993#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000994#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000995 int in_linebreak = FALSE; // n_extra set for showing linebreak
996#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200997 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100998 // displaying eol at end-of-line
999 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001000 int lcs_prec_todo = wp->w_lcs_chars.prec;
1001 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001002
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001003 int n_attr = 0; // chars with special attr
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001004 int n_attr_skip = 0; // chars to skip bef. using wlv.extra_attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001005 int saved_attr2 = 0; // char_attr saved for n_attr
1006 int n_attr3 = 0; // chars with overruling special attr
1007 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001008
Bram Moolenaarcd105412022-10-10 19:50:42 +01001009 int n_skip = 0; // nr of cells to skip for 'nowrap' or
1010 // concealing
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001011#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001012 int skip_cells = 0; // nr of cells to skip for virtual text
1013 // after the line, when w_skipcol is
1014 // larger than the text length
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001015#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001016
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001017 int fromcol_prev = -2; // start of inverting after cursor
1018 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001019 int lnum_in_visual_area = FALSE;
1020 pos_T pos;
1021 long v;
1022
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001023 int attr_pri = FALSE; // char_attr has priority
1024 int area_highlighting = FALSE; // Visual or incsearch highlighting
1025 // in this line
1026 int vi_attr = 0; // attributes for Visual and incsearch
1027 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001028 int area_attr = 0; // attributes desired by highlighting
1029 int search_attr = 0; // attributes desired by 'hlsearch'
1030#ifdef FEAT_SYN_HL
1031 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1032 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001033 int prev_syntax_col = -1; // column of prev_syntax_attr
1034 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001035 int has_syntax = FALSE; // this buffer has syntax highl.
1036 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001037#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001038#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001039 int text_prop_count;
1040 int text_prop_next = 0; // next text property to use
1041 textprop_T *text_props = NULL;
1042 int *text_prop_idxs = NULL;
1043 int text_props_active = 0;
1044 proptype_T *text_prop_type = NULL;
1045 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001046 int text_prop_attr_comb = 0; // text_prop_attr combined with
1047 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001048 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001049 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001050 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001051 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001052 int saved_search_attr = 0; // search_attr to be used when n_extra
1053 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001054 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001055 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001056#endif
1057#ifdef FEAT_SPELL
1058 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001059 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001060# define SPWORDLEN 150
1061 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1062 int nextlinecol = 0; // column where nextline[] starts
1063 int nextline_idx = 0; // index in nextline[] where next line
1064 // starts
1065 int spell_attr = 0; // attributes desired by spelling
1066 int word_end = 0; // last byte with same spell_attr
1067 static linenr_T checked_lnum = 0; // line number for "checked_col"
1068 static int checked_col = 0; // column in "checked_lnum" up to which
1069 // there are no spell errors
1070 static int cap_col = -1; // column to check for Cap word
1071 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1072 int cur_checked_col = 0; // checked column for current line
1073#endif
1074 int extra_check = 0; // has extra highlighting
1075 int multi_attr = 0; // attributes desired by multibyte
1076 int mb_l = 1; // multi-byte byte length
1077 int mb_c = 0; // decoded multi-byte character
1078 int mb_utf8 = FALSE; // screen char is UTF-8 char
1079 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001080#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001081 int change_start = MAXCOL; // first col of changed area
1082 int change_end = -1; // last col of changed area
1083#endif
1084 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001085 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001086 int in_multispace = FALSE; // in multiple consecutive spaces
1087 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001088#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
1089 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
1090# define LINE_ATTR
1091 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +01001092 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001093#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001094 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001095 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001096#ifdef FEAT_ARABIC
1097 int prev_c = 0; // previous Arabic character
1098 int prev_c1 = 0; // first composing char for prev_c
1099#endif
1100#if defined(LINE_ATTR)
1101 int did_line_attr = 0;
1102#endif
1103#ifdef FEAT_TERMINAL
1104 int get_term_attr = FALSE;
1105#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001106
Martin Tournoijba43e762022-10-13 22:12:15 +01001107#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001108 // margin columns for the screen line, needed for when 'cursorlineopt'
1109 // contains "screenline"
1110 int left_curline_col = 0;
1111 int right_curline_col = 0;
1112#endif
1113
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001114#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1115 int feedback_col = 0;
1116 int feedback_old_attr = -1;
1117#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001118
1119#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1120 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001121#endif
1122#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001123 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001124#endif
1125#ifdef FEAT_CONCEAL
1126 int syntax_flags = 0;
1127 int syntax_seqnr = 0;
1128 int prev_syntax_id = 0;
1129 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1130 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001131 int did_wcol = FALSE;
1132 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001133# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001134# define FIX_FOR_BOGUSCOLS \
1135 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001136 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001137 wlv.vcol -= wlv.vcol_off; \
1138 wlv.vcol_off = 0; \
1139 wlv.col -= wlv.boguscols; \
1140 old_boguscols = wlv.boguscols; \
1141 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001142 }
1143#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001144# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001145#endif
1146
1147 if (startrow > endrow) // past the end already!
1148 return startrow;
1149
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001150 CLEAR_FIELD(wlv);
1151
1152 wlv.lnum = lnum;
1153 wlv.startrow = startrow;
1154 wlv.row = startrow;
1155 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001156 wlv.fromcol = -10;
1157 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001158#ifdef FEAT_LINEBREAK
1159 wlv.vcol_sbr = -1;
1160#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001161
1162 if (!number_only)
1163 {
1164 // To speed up the loop below, set extra_check when there is linebreak,
1165 // trailing white space and/or syntax processing to be done.
1166#ifdef FEAT_LINEBREAK
1167 extra_check = wp->w_p_lbr;
1168#endif
1169#ifdef FEAT_SYN_HL
1170 if (syntax_present(wp) && !wp->w_s->b_syn_error
1171# ifdef SYN_TIME_LIMIT
1172 && !wp->w_s->b_syn_slow
1173# endif
1174 )
1175 {
1176 // Prepare for syntax highlighting in this line. When there is an
1177 // error, stop syntax highlighting.
1178 save_did_emsg = did_emsg;
1179 did_emsg = FALSE;
1180 syntax_start(wp, lnum);
1181 if (did_emsg)
1182 wp->w_s->b_syn_error = TRUE;
1183 else
1184 {
1185 did_emsg = save_did_emsg;
1186#ifdef SYN_TIME_LIMIT
1187 if (!wp->w_s->b_syn_slow)
1188#endif
1189 {
1190 has_syntax = TRUE;
1191 extra_check = TRUE;
1192 }
1193 }
1194 }
1195
1196 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001197 wlv.color_cols = wp->w_p_cc_cols;
1198 if (wlv.color_cols != NULL)
1199 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001200#endif
1201
1202#ifdef FEAT_TERMINAL
1203 if (term_show_buffer(wp->w_buffer))
1204 {
1205 extra_check = TRUE;
1206 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001207 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001208 }
1209#endif
1210
1211#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001212 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001213 {
1214 // Prepare for spell checking.
1215 has_spell = TRUE;
1216 extra_check = TRUE;
1217
1218 // Get the start of the next line, so that words that wrap to the
1219 // next line are found too: "et<line-break>al.".
1220 // Trick: skip a few chars for C/shell/Vim comments
1221 nextline[SPWORDLEN] = NUL;
1222 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1223 {
1224 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1225 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1226 }
1227
1228 // When a word wrapped from the previous line the start of the
1229 // current line is valid.
1230 if (lnum == checked_lnum)
1231 cur_checked_col = checked_col;
1232 checked_lnum = 0;
1233
1234 // When there was a sentence end in the previous line may require a
1235 // word starting with capital in this line. In line 1 always check
1236 // the first word.
1237 if (lnum != capcol_lnum)
1238 cap_col = -1;
1239 if (lnum == 1)
1240 cap_col = 0;
1241 capcol_lnum = 0;
1242 }
1243#endif
1244
1245 // handle Visual active in this window
1246 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1247 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001248 pos_T *top, *bot;
1249
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001250 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1251 {
1252 // Visual is after curwin->w_cursor
1253 top = &curwin->w_cursor;
1254 bot = &VIsual;
1255 }
1256 else
1257 {
1258 // Visual is before curwin->w_cursor
1259 top = &VIsual;
1260 bot = &curwin->w_cursor;
1261 }
1262 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1263 if (VIsual_mode == Ctrl_V)
1264 {
1265 // block mode
1266 if (lnum_in_visual_area)
1267 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001268 wlv.fromcol = wp->w_old_cursor_fcol;
1269 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001270 }
1271 }
1272 else
1273 {
1274 // non-block mode
1275 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001276 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001277 else if (lnum == top->lnum)
1278 {
1279 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001280 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001281 else
1282 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001283 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001284 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001285 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001286 }
1287 }
1288 if (VIsual_mode != 'V' && lnum == bot->lnum)
1289 {
1290 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1291 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001292 wlv.fromcol = -10;
1293 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001294 }
1295 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001296 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001297 else
1298 {
1299 pos = *bot;
1300 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001301 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1302 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001303 else
1304 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001305 getvvcol(wp, &pos, NULL, NULL,
1306 (colnr_T *)&wlv.tocol);
1307 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001308 }
1309 }
1310 }
1311 }
1312
1313 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001314 if (!highlight_match && lnum == curwin->w_cursor.lnum
1315 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001316#ifdef FEAT_GUI
1317 && !gui.in_use
1318#endif
1319 )
1320 noinvcur = TRUE;
1321
1322 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001323 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001324 {
1325 area_highlighting = TRUE;
1326 vi_attr = HL_ATTR(HLF_V);
1327#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1328 if ((clip_star.available && !clip_star.owned
1329 && clip_isautosel_star())
1330 || (clip_plus.available && !clip_plus.owned
1331 && clip_isautosel_plus()))
1332 vi_attr = HL_ATTR(HLF_VNC);
1333#endif
1334 }
1335 }
1336
1337 // handle 'incsearch' and ":s///c" highlighting
1338 else if (highlight_match
1339 && wp == curwin
1340 && lnum >= curwin->w_cursor.lnum
1341 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1342 {
1343 if (lnum == curwin->w_cursor.lnum)
1344 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001345 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001346 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001347 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001348 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1349 {
1350 pos.lnum = lnum;
1351 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001352 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001353 }
1354 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001355 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001356 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001357 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1358 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001359 area_highlighting = TRUE;
1360 vi_attr = HL_ATTR(HLF_I);
1361 }
1362 }
1363
1364#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001365 wlv.filler_lines = diff_check(wp, lnum);
1366 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001367 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001368 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001369 {
1370 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001371 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001372 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001373 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001374 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001375 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001376 }
1377 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001378 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001379 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001380 area_highlighting = TRUE;
1381 }
1382 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001383 wlv.filler_lines = wp->w_topfill;
1384 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001385#endif
1386
1387#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001388 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001389 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001390 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001391#endif
1392
1393#ifdef LINE_ATTR
1394# ifdef FEAT_SIGNS
1395 // If this line has a sign with line highlighting set line_attr.
1396 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001397 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001398# endif
1399# if defined(FEAT_QUICKFIX)
1400 // Highlight the current line in the quickfix window.
1401 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1402 line_attr = HL_ATTR(HLF_QFL);
1403# endif
1404 if (line_attr != 0)
1405 area_highlighting = TRUE;
1406#endif
1407
1408 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1409 ptr = line;
1410
1411#ifdef FEAT_SPELL
1412 if (has_spell && !number_only)
1413 {
1414 // For checking first word with a capital skip white space.
1415 if (cap_col == 0)
1416 cap_col = getwhitecols(line);
1417
1418 // To be able to spell-check over line boundaries copy the end of the
1419 // current line into nextline[]. Above the start of the next line was
1420 // copied to nextline[SPWORDLEN].
1421 if (nextline[SPWORDLEN] == NUL)
1422 {
1423 // No next line or it is empty.
1424 nextlinecol = MAXCOL;
1425 nextline_idx = 0;
1426 }
1427 else
1428 {
1429 v = (long)STRLEN(line);
1430 if (v < SPWORDLEN)
1431 {
1432 // Short line, use it completely and append the start of the
1433 // next line.
1434 nextlinecol = 0;
1435 mch_memmove(nextline, line, (size_t)v);
1436 STRMOVE(nextline + v, nextline + SPWORDLEN);
1437 nextline_idx = v + 1;
1438 }
1439 else
1440 {
1441 // Long line, use only the last SPWORDLEN bytes.
1442 nextlinecol = v - SPWORDLEN;
1443 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1444 nextline_idx = SPWORDLEN + 1;
1445 }
1446 }
1447 }
1448#endif
1449
1450 if (wp->w_p_list)
1451 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001452 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001453 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001454 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001455 || wp->w_lcs_chars.trail
1456 || wp->w_lcs_chars.lead
1457 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001458 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001459
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001460 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001461 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001462 {
1463 trailcol = (colnr_T)STRLEN(ptr);
1464 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1465 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001466 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001467 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001468 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001469 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001470 {
1471 leadcol = 0;
1472 while (VIM_ISWHITE(ptr[leadcol]))
1473 ++leadcol;
1474 if (ptr[leadcol] == NUL)
1475 // in a line full of spaces all of them are treated as trailing
1476 leadcol = (colnr_T)0;
1477 else
1478 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001479 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001480 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001481 }
1482
Bram Moolenaard7657e92022-09-20 18:59:30 +01001483 wlv.wcr_attr = get_wcr_attr(wp);
1484 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001485 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001486 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001487 area_highlighting = TRUE;
1488 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001489
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001490#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001491 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001492 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001493#endif
1494
1495 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1496 // first character to be displayed.
1497 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001498 v = startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001499 else
1500 v = wp->w_leftcol;
1501 if (v > 0 && !number_only)
1502 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001503 char_u *prev_ptr = ptr;
1504 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001505 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001506
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001507 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001508 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001509 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001510 charsize = win_lbr_chartabsize(&cts, NULL);
1511 cts.cts_vcol += charsize;
1512 prev_ptr = cts.cts_ptr;
1513 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001514 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001515 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001516 ptr = cts.cts_ptr;
1517 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001518
1519 // When:
1520 // - 'cuc' is set, or
1521 // - 'colorcolumn' is set, or
1522 // - 'virtualedit' is set, or
1523 // - the visual mode is active,
1524 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001525 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001526#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001527 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001528#endif
1529 virtual_active() ||
1530 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001531 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001532
1533 // Handle a character that's not completely on the screen: Put ptr at
1534 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001535 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001536 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001537 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001538 ptr = prev_ptr;
1539 // If the character fits on the screen, don't need to skip it.
1540 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001541 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1542 && wlv.col == 0)
1543 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001544 }
1545
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001546#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001547 // If there the text doesn't reach to the desired column, need to skip
1548 // "skip_cells" cells when virtual text follows.
1549 if (!wp->w_p_wrap && v > wlv.vcol)
1550 skip_cells = v - wlv.vcol;
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001551#endif
Bram Moolenaarcd105412022-10-10 19:50:42 +01001552
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001553 // Adjust for when the inverted text is before the screen,
1554 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001555 if (wlv.tocol <= wlv.vcol)
1556 wlv.fromcol = 0;
1557 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1558 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001559
1560#ifdef FEAT_LINEBREAK
1561 // When w_skipcol is non-zero, first line needs 'showbreak'
1562 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001563 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001564#endif
1565#ifdef FEAT_SPELL
1566 // When spell checking a word we need to figure out the start of the
1567 // word and if it's badly spelled or not.
1568 if (has_spell)
1569 {
1570 int len;
1571 colnr_T linecol = (colnr_T)(ptr - line);
1572 hlf_T spell_hlf = HLF_COUNT;
1573
1574 pos = wp->w_cursor;
1575 wp->w_cursor.lnum = lnum;
1576 wp->w_cursor.col = linecol;
1577 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1578
1579 // spell_move_to() may call ml_get() and make "line" invalid
1580 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1581 ptr = line + linecol;
1582
1583 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1584 {
1585 // no bad word found at line start, don't check until end of a
1586 // word
1587 spell_hlf = HLF_COUNT;
1588 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1589 }
1590 else
1591 {
1592 // bad word found, use attributes until end of word
1593 word_end = wp->w_cursor.col + len + 1;
1594
1595 // Turn index into actual attributes.
1596 if (spell_hlf != HLF_COUNT)
1597 spell_attr = highlight_attr[spell_hlf];
1598 }
1599 wp->w_cursor = pos;
1600
1601# ifdef FEAT_SYN_HL
1602 // Need to restart syntax highlighting for this line.
1603 if (has_syntax)
1604 syntax_start(wp, lnum);
1605# endif
1606 }
1607#endif
1608 }
1609
1610 // Correct highlighting for cursor that can't be disabled.
1611 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001612 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001613 {
1614 if (noinvcur)
1615 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001616 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001617 {
1618 // highlighting starts at cursor, let it start just after the
1619 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001620 fromcol_prev = wlv.fromcol;
1621 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001622 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001623 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001624 // restart highlighting after the cursor
1625 fromcol_prev = wp->w_virtcol;
1626 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001627 if (wlv.fromcol >= wlv.tocol)
1628 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001629 }
1630
1631#ifdef FEAT_SEARCH_EXTRA
1632 if (!number_only)
1633 {
1634 v = (long)(ptr - line);
1635 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1636 &line, &screen_search_hl,
1637 &search_attr);
1638 ptr = line + v; // "line" may have been updated
1639 }
1640#endif
1641
1642#ifdef FEAT_SYN_HL
1643 // Cursor line highlighting for 'cursorline' in the current window.
1644 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1645 {
1646 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001647 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001648 if (!(wp == curwin && VIsual_active)
1649 && wp->w_p_culopt_flags != CULOPT_NBR)
1650 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001651 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001652 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1653
1654 // Only set line_attr here when "screenline" is not present in
1655 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001656 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001657 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001658 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001659# ifdef FEAT_SIGNS
1660 // Combine the 'cursorline' and sign highlighting, depending on
1661 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001662 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001663 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001664 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001665 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001666 else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001667 line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001668 }
1669 else
1670# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001671# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001672 // let the line attribute overrule 'cursorline', otherwise
1673 // it disappears when both have background set;
1674 // 'cursorline' can use underline or bold to make it show
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001675 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001676# else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001677 line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001678# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001679 }
1680 else
1681 {
1682 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001683 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1684 }
1685 area_highlighting = TRUE;
1686 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001687 }
1688#endif
1689
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001690#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001691 {
1692 char_u *prop_start;
1693
1694 text_prop_count = get_text_props(wp->w_buffer, lnum,
1695 &prop_start, FALSE);
1696 if (text_prop_count > 0)
1697 {
1698 // Make a copy of the properties, so that they are properly
1699 // aligned.
1700 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1701 if (text_props != NULL)
1702 mch_memmove(text_props, prop_start,
1703 text_prop_count * sizeof(textprop_T));
1704
1705 // Allocate an array for the indexes.
1706 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001707 if (text_prop_idxs == NULL)
1708 VIM_CLEAR(text_props);
1709
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001710 if (text_props != NULL)
1711 {
1712 area_highlighting = TRUE;
1713 extra_check = TRUE;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +01001714 // text props "above" move the line number down to where the
1715 // text is.
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001716 for (int i = 0; i < text_prop_count; ++i)
1717 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1718 ++wlv.text_prop_above_count;
1719 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001720 }
1721 }
1722#endif
1723
Bram Moolenaar1306b362022-08-06 15:59:06 +01001724 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001725
1726 // Repeat for the whole displayed line.
1727 for (;;)
1728 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001729 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001730#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001731 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001732#endif
1733#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001734 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001735#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001736
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001737 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001738 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001739 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001740#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001741 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001742 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001743 wlv.cul_attr = 0;
zeertzjq4f33bc22021-08-05 17:57:02 +02001744 line_attr = line_attr_save;
1745 }
1746#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001747 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001748 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001749 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001750 if (cmdwin_type != 0 && wp == curwin)
1751 {
1752 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001753 wlv.n_extra = 1;
1754 wlv.c_extra = cmdwin_type;
1755 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001756 wlv.char_attr =
1757 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001758 }
1759 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001760#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001761 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001762 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001763 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001764 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001765 }
1766#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001767#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001768 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001769 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001770 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001771 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001772 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001773 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001774 }
1775#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001776 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001777 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001778 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001779 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001780 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001781 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001782#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001783 // Check if 'breakindent' applies and show it.
1784 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1785 if (wlv.n_extra == 0)
1786 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001787#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001788#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001789 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001790 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001791 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001792 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001793 }
1794#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001795 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001796 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001797 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001798 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001799 }
1800 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001801
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001802#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001803 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001804 && wlv.vcol >= left_curline_col
1805 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001806 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001807 wlv.cul_attr = HL_ATTR(HLF_CUL);
1808 line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001809 }
1810#endif
1811
1812 // When still displaying '$' of change command, stop at cursor.
1813 // When only displaying the (relative) line number and that's done,
1814 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001815 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001816 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001817 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001818#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001819 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001820#endif
1821 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001822 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001823 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001824 // Pretend we have finished updating the window. Except when
1825 // 'cursorcolumn' is set.
1826#ifdef FEAT_SYN_HL
1827 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001828 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001829 else
1830#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001831 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001832 break;
1833 }
1834
Bram Moolenaar1306b362022-08-06 15:59:06 +01001835 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001836 {
1837 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001838 if (wlv.vcol == wlv.fromcol
1839 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1840 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001841 && (*mb_ptr2cells)(ptr) > 1)
1842 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001843 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001844 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001845 area_attr = vi_attr; // start highlighting
1846 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001847 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001848 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001849 area_attr = 0; // stop highlighting
1850
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001851#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001852 if (text_props != NULL)
1853 {
1854 int pi;
1855 int bcol = (int)(ptr - line);
1856
Bram Moolenaar1306b362022-08-06 15:59:06 +01001857 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001858# ifdef FEAT_LINEBREAK
1859 && !in_linebreak
1860# endif
1861 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001862 --bcol; // still working on the previous char, e.g. Tab
1863
1864 // Check if any active property ends.
1865 for (pi = 0; pi < text_props_active; ++pi)
1866 {
1867 int tpi = text_prop_idxs[pi];
1868
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001869 if (text_props[tpi].tp_col != MAXCOL
1870 && bcol >= text_props[tpi].tp_col - 1
1871 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001872 {
1873 if (pi + 1 < text_props_active)
1874 mch_memmove(text_prop_idxs + pi,
1875 text_prop_idxs + pi + 1,
1876 sizeof(int)
1877 * (text_props_active - (pi + 1)));
1878 --text_props_active;
1879 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001880# ifdef FEAT_LINEBREAK
1881 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001882 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001883 syntax_attr = 0;
1884# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001885 }
1886 }
1887
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001888# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001889 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001890 // not on the next char yet, don't start another prop
1891 --bcol;
1892# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001893 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001894 // With 'nowrap' and not in the first screen line only "below"
1895 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001896 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001897 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001898 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001899 && (wp->w_p_wrap
1900 || wlv.row == startrow
1901 || (text_props[text_prop_next].tp_flags
1902 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001903 || (bcol == 0 &&
1904 (text_props[text_prop_next].tp_flags
1905 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001906 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001907 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001908 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001909 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1910 {
1911 // first display the '$' after the line
1912 text_prop_follows = TRUE;
1913 break;
1914 }
1915 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001916 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001917 + text_props[text_prop_next].tp_len)
1918 text_prop_idxs[text_props_active++] = text_prop_next;
1919 ++text_prop_next;
1920 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001921
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001922 if (wlv.n_extra == 0 || !wlv.extra_for_textprop)
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001923 {
1924 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001925 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001926 text_prop_flags = 0;
1927 text_prop_type = NULL;
1928 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001929 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001930 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001931 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001932 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001933 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001934 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001935 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001936
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001937 // Sort the properties on priority and/or starting last.
1938 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001939 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001940 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001941 sort_text_props(wp->w_buffer, text_props,
1942 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001943
1944 for (pi = 0; pi < text_props_active; ++pi)
1945 {
1946 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001947 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001948 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01001949 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001950
Bram Moolenaarcd105412022-10-10 19:50:42 +01001951 // Only use a text property that can be displayed.
1952 // Skip "after" properties when wrap is off and at the
1953 // end of the window.
1954 if (pt != NULL
1955 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
1956 && tp->tp_id != -MAXCOL
1957 && !(tp->tp_id < 0
1958 && !wp->w_p_wrap
1959 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
1960 | TP_FLAG_ALIGN_ABOVE
1961 | TP_FLAG_ALIGN_BELOW)) == 0
1962 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001963 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001964 if (pt->pt_hl_id > 0)
1965 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001966 text_prop_type = pt;
1967 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001968 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001969 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001970 text_prop_flags = pt->pt_flags;
1971 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001972 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001973 }
1974 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001975 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001976 && -text_prop_id
1977 <= wp->w_buffer->b_textprop_text.ga_len)
1978 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001979 textprop_T *tp = &text_props[used_tpi];
1980 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001981 ->b_textprop_text.ga_data)[
1982 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001983 int above = (tp->tp_flags
1984 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01001985 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001986
1987 // reset the ID in the copy to avoid it being used
1988 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001989 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001990
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001991 if (p != NULL)
1992 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001993 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001994 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001995 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001996 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001997 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1998 int padding = tp->tp_col == MAXCOL
1999 && tp->tp_len > 1
2000 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002001
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002002 // Insert virtual text before the current
2003 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002004 wlv.p_extra = p;
2005 wlv.c_extra = NUL;
2006 wlv.c_final = NUL;
2007 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002008 wlv.extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002009 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2010 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002011 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002012 // restore search_attr and area_attr when n_extra
2013 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01002014 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002015 saved_area_attr = area_attr;
2016 search_attr = 0;
2017 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002018 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002019 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002020 if (*ptr == NUL)
2021 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002022 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002023#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002024 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002025 {
2026 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002027 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002028 wlv.need_showbreak = FALSE;
2029 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002030 }
2031#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002032 if ((right || above || below || !wrap
2033 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002034 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002035 char_u *prev_p_extra = wlv.p_extra;
2036 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002037
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002038 // Take care of padding, right-align and
2039 // truncation.
2040 // Shared with win_lbr_chartabsize(), must do
2041 // exactly the same.
2042 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002043 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002044 wlv.col,
2045 &wlv.n_extra, &wlv.p_extra,
2046 &n_attr, &n_attr_skip);
2047 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002048 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002049 // wlv.p_extra was allocated
2050 vim_free(p_extra_free2);
2051 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002052 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002053
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002054 if (lcs_eol_one < 0
2055 && wp->w_p_wrap
2056 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002057 + wlv.n_extra - 2 > wp->w_width)
2058 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002059 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002060
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002061 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002062 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002063 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002064 {
2065 draw_screen_line(wp, &wlv);
2066
2067 // When line got too long for screen break
2068 // here.
2069 if (wlv.row == endrow)
2070 {
2071 ++wlv.row;
2072 break;
2073 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002074 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002075 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002076 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002077 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002078 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002079
Bram Moolenaarcd105412022-10-10 19:50:42 +01002080 // If the text didn't reach until the first window
2081 // column we need to skip cells.
2082 if (skip_cells > 0)
2083 {
2084 if (wlv.n_extra > skip_cells)
2085 {
2086 wlv.n_extra -= skip_cells;
2087 wlv.p_extra += skip_cells;
2088 n_attr_skip -= skip_cells;
2089 if (n_attr_skip < 0)
2090 n_attr_skip = 0;
2091 skip_cells = 0;
2092 }
2093 else
2094 {
2095 // the whole text is left of the window, drop
2096 // it and advance to the next one
2097 skip_cells -= wlv.n_extra;
2098 wlv.n_extra = 0;
2099 n_attr_skip = 0;
2100 bail_out = TRUE;
2101 }
2102 }
2103
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002104 // If another text prop follows the condition below at
2105 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002106 // If this is an "above" text prop and 'nowrap' the we
2107 // must wrap anyway.
2108 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002109 text_prop_follows |= other_tpi != -1
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002110 && (wp->w_p_wrap
2111 || (text_props[other_tpi].tp_flags
2112 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002113
2114 if (bail_out)
2115 // starting a new line for "below"
2116 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002117 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002118 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002119 else if (text_prop_next < text_prop_count
2120 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002121 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2122 || (!wp->w_p_wrap
2123 && wlv.col == wp->w_width - 1
2124 && (text_props[text_prop_next].tp_flags
2125 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002126 // When at last-but-one character and a text property
2127 // follows after it, we may need to flush the line after
2128 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002129 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002130 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002131 }
2132#endif
2133
Bram Moolenaare38fc862022-08-11 17:24:50 +01002134#ifdef FEAT_SEARCH_EXTRA
2135 if (wlv.n_extra == 0)
2136 {
2137 // Check for start/end of 'hlsearch' and other matches.
2138 // After end, check for start/end of next match.
2139 // When another match, have to check for start again.
2140 v = (long)(ptr - line);
2141 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2142 &screen_search_hl, &has_match_conc,
2143 &match_conc, did_line_attr, lcs_eol_one,
2144 &on_last_col);
2145 ptr = line + v; // "line" may have been changed
2146 prev_ptr = ptr;
2147
2148 // Do not allow a conceal over EOL otherwise EOL will be missed
2149 // and bad things happen.
2150 if (*ptr == NUL)
2151 has_match_conc = 0;
2152 }
2153#endif
2154
2155#ifdef FEAT_DIFF
2156 if (wlv.diff_hlf != (hlf_T)0)
2157 {
2158 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2159 && wlv.n_extra == 0)
2160 wlv.diff_hlf = HLF_TXD; // changed text
2161 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2162 && wlv.n_extra == 0)
2163 wlv.diff_hlf = HLF_CHD; // changed line
2164 line_attr = HL_ATTR(wlv.diff_hlf);
2165 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2166 && wp->w_p_culopt_flags != CULOPT_NBR
2167 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2168 && wlv.vcol <= right_curline_col)))
2169 line_attr = hl_combine_attr(
2170 line_attr, HL_ATTR(HLF_CUL));
2171 }
2172#endif
2173
Bram Moolenaara74fda62019-10-19 17:38:03 +02002174#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002175 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002176 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002177 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002178# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002179 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002180 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002181# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002182 // Get syntax attribute.
2183 if (has_syntax)
2184 {
2185 // Get the syntax attribute for the character. If there
2186 // is an error, disable syntax highlighting.
2187 save_did_emsg = did_emsg;
2188 did_emsg = FALSE;
2189
2190 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002191 if (v == prev_syntax_col)
2192 // at same column again
2193 syntax_attr = prev_syntax_attr;
2194 else
2195 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002196# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002197 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002198# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002199 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002200# ifdef FEAT_SPELL
2201 has_spell ? &can_spell :
2202# endif
2203 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002204 prev_syntax_col = v;
2205 prev_syntax_attr = syntax_attr;
2206 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002207
Bram Moolenaar34390282019-10-16 14:38:26 +02002208 if (did_emsg)
2209 {
2210 wp->w_s->b_syn_error = TRUE;
2211 has_syntax = FALSE;
2212 syntax_attr = 0;
2213 }
2214 else
2215 did_emsg = save_did_emsg;
2216# ifdef SYN_TIME_LIMIT
2217 if (wp->w_s->b_syn_slow)
2218 has_syntax = FALSE;
2219# endif
2220
2221 // Need to get the line again, a multi-line regexp may
2222 // have made it invalid.
2223 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2224 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002225 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002226# ifdef FEAT_CONCEAL
2227 // no concealing past the end of the line, it interferes
2228 // with line highlighting
2229 if (*ptr == NUL)
2230 syntax_flags = 0;
2231 else
2232 syntax_flags = get_syntax_info(&syntax_seqnr);
2233# endif
2234 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002235 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002236# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002237 // Combine text property highlight into syntax highlight.
2238 if (text_prop_type != NULL)
2239 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002240 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002241 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2242 else
2243 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002244 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002245 }
2246# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002247#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002248
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002249 // Decide which of the highlight attributes to use.
2250 attr_pri = TRUE;
2251#ifdef LINE_ATTR
2252 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002253 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002254 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002255 if (!highlight_match)
2256 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002257 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002258# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002259 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002260# endif
2261 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002262 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002263 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002264 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002265# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002266 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002267# endif
2268 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002269 else if (line_attr != 0
2270 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2271 || wlv.vcol < wlv.fromcol
2272 || vcol_prev < fromcol_prev
2273 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002274 {
2275 // Use line_attr when not in the Visual or 'incsearch' area
2276 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002277# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002278 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002279# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002280 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002281# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002282 attr_pri = FALSE;
2283 }
2284#else
2285 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002286 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002287 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002288 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002289#endif
2290 else
2291 {
2292 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002293#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002294 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002295#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002296 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002297#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002298 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002299#ifdef FEAT_PROP_POPUP
2300 // override with text property highlight when "override" is TRUE
2301 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002302 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002303#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002304 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002305
2306 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002307 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002308 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002309 if (wlv.char_attr == 0)
2310 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002311 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002312 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002313 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002314
2315 // Get the next character to put on the screen.
2316
2317 // The "p_extra" points to the extra stuff that is inserted to
2318 // represent special characters (non-printable stuff) and other
2319 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002320 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002321 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2322 // "p_extra[n_extra]".
2323 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002324 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002325 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002326 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002327 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002328 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2329 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002330 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2331 if (enc_utf8 && utf_char2len(c) > 1)
2332 {
2333 mb_utf8 = TRUE;
2334 u8cc[0] = 0;
2335 c = 0xc0;
2336 }
2337 else
2338 mb_utf8 = FALSE;
2339 }
2340 else
2341 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002342 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002343 if (has_mbyte)
2344 {
2345 mb_c = c;
2346 if (enc_utf8)
2347 {
2348 // If the UTF-8 character is more than one byte:
2349 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002350 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002351 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002352 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002353 mb_l = 1;
2354 else if (mb_l > 1)
2355 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002356 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002357 mb_utf8 = TRUE;
2358 c = 0xc0;
2359 }
2360 }
2361 else
2362 {
2363 // if this is a DBCS character, put it in "mb_c"
2364 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002365 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002366 mb_l = 1;
2367 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002368 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002369 }
2370 if (mb_l == 0) // at the NUL at end-of-line
2371 mb_l = 1;
2372
2373 // If a double-width char doesn't fit display a '>' in the
2374 // last column.
2375 if ((
2376# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002377 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002378# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002379 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002380 && (*mb_char2cells)(mb_c) == 2)
2381 {
2382 c = '>';
2383 mb_c = c;
2384 mb_l = 1;
2385 mb_utf8 = FALSE;
2386 multi_attr = HL_ATTR(HLF_AT);
2387#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002388 if (wlv.cul_attr)
2389 multi_attr = hl_combine_attr(
2390 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002391#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002392 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002393
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002394 // put the pointer back to output the double-width
2395 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002396 ++wlv.n_extra;
2397 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002398 }
2399 else
2400 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002401 wlv.n_extra -= mb_l - 1;
2402 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002403 }
2404 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002405 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002406 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002407 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002408#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002409 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002410 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002411 // Only restore search_attr and area_attr after "n_extra" in
2412 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002413 if (wlv.saved_n_extra <= 0)
2414 {
2415 if (search_attr == 0)
2416 search_attr = saved_search_attr;
2417 if (area_attr == 0 && *ptr != NUL)
2418 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002419
2420 if (wlv.extra_for_textprop)
2421 // wlv.extra_attr should be used at this position but
2422 // not any further.
2423 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002424 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002425
2426 wlv.extra_for_textprop = FALSE;
2427 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002428 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002429#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002430 }
2431 else
2432 {
2433#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002434 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002435#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002436 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002437
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002438 // Get a character from the line itself.
2439 c = *ptr;
2440#ifdef FEAT_LINEBREAK
2441 c0 = *ptr;
2442#endif
2443 if (has_mbyte)
2444 {
2445 mb_c = c;
2446 if (enc_utf8)
2447 {
2448 // If the UTF-8 character is more than one byte: Decode it
2449 // into "mb_c".
2450 mb_l = utfc_ptr2len(ptr);
2451 mb_utf8 = FALSE;
2452 if (mb_l > 1)
2453 {
2454 mb_c = utfc_ptr2char(ptr, u8cc);
2455 // Overlong encoded ASCII or ASCII with composing char
2456 // is displayed normally, except a NUL.
2457 if (mb_c < 0x80)
2458 {
2459 c = mb_c;
2460#ifdef FEAT_LINEBREAK
2461 c0 = mb_c;
2462#endif
2463 }
2464 mb_utf8 = TRUE;
2465
2466 // At start of the line we can have a composing char.
2467 // Draw it as a space with a composing char.
2468 if (utf_iscomposing(mb_c))
2469 {
2470 int i;
2471
2472 for (i = Screen_mco - 1; i > 0; --i)
2473 u8cc[i] = u8cc[i - 1];
2474 u8cc[0] = mb_c;
2475 mb_c = ' ';
2476 }
2477 }
2478
2479 if ((mb_l == 1 && c >= 0x80)
2480 || (mb_l >= 1 && mb_c == 0)
2481 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2482 {
2483 // Illegal UTF-8 byte: display as <xx>.
2484 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002485 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002486# ifdef FEAT_RIGHTLEFT
2487 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002488 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002489# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002490 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002491 c = *wlv.p_extra;
2492 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002493 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002494 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2495 wlv.c_extra = NUL;
2496 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002497 if (area_attr == 0 && search_attr == 0)
2498 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002499 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002500 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002501 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002502 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002503 }
2504 }
2505 else if (mb_l == 0) // at the NUL at end-of-line
2506 mb_l = 1;
2507#ifdef FEAT_ARABIC
2508 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2509 {
2510 // Do Arabic shaping.
2511 int pc, pc1, nc;
2512 int pcc[MAX_MCO];
2513
2514 // The idea of what is the previous and next
2515 // character depends on 'rightleft'.
2516 if (wp->w_p_rl)
2517 {
2518 pc = prev_c;
2519 pc1 = prev_c1;
2520 nc = utf_ptr2char(ptr + mb_l);
2521 prev_c1 = u8cc[0];
2522 }
2523 else
2524 {
2525 pc = utfc_ptr2char(ptr + mb_l, pcc);
2526 nc = prev_c;
2527 pc1 = pcc[0];
2528 }
2529 prev_c = mb_c;
2530
2531 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2532 }
2533 else
2534 prev_c = mb_c;
2535#endif
2536 }
2537 else // enc_dbcs
2538 {
2539 mb_l = MB_BYTE2LEN(c);
2540 if (mb_l == 0) // at the NUL at end-of-line
2541 mb_l = 1;
2542 else if (mb_l > 1)
2543 {
2544 // We assume a second byte below 32 is illegal.
2545 // Hopefully this is OK for all double-byte encodings!
2546 if (ptr[1] >= 32)
2547 mb_c = (c << 8) + ptr[1];
2548 else
2549 {
2550 if (ptr[1] == NUL)
2551 {
2552 // head byte at end of line
2553 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002554 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002555 }
2556 else
2557 {
2558 // illegal tail byte
2559 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002560 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002561 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002562 wlv.p_extra = wlv.extra;
2563 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002564 wlv.c_extra = NUL;
2565 wlv.c_final = NUL;
2566 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002567 if (area_attr == 0 && search_attr == 0)
2568 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002569 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002570 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002571 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002572 // save current attr
2573 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002574 }
2575 mb_c = c;
2576 }
2577 }
2578 }
2579 // If a double-width char doesn't fit display a '>' in the
2580 // last column; the character is displayed at the start of the
2581 // next line.
2582 if ((
2583# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002584 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002585# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002586 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002587 && (*mb_char2cells)(mb_c) == 2)
2588 {
2589 c = '>';
2590 mb_c = c;
2591 mb_utf8 = FALSE;
2592 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002593 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002594 // Put pointer back so that the character will be
2595 // displayed at the start of the next line.
2596 --ptr;
2597#ifdef FEAT_CONCEAL
2598 did_decrement_ptr = TRUE;
2599#endif
2600 }
2601 else if (*ptr != NUL)
2602 ptr += mb_l - 1;
2603
2604 // If a double-width char doesn't fit at the left side display
2605 // a '<' in the first column. Don't do this for unprintable
2606 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002607 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002608 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002609 wlv.n_extra = 1;
2610 wlv.c_extra = MB_FILLER_CHAR;
2611 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002612 c = ' ';
2613 if (area_attr == 0 && search_attr == 0)
2614 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002615 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002616 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002617 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002618 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002619 }
2620 mb_c = c;
2621 mb_utf8 = FALSE;
2622 mb_l = 1;
2623 }
2624
2625 }
2626 ++ptr;
2627
2628 if (extra_check)
2629 {
2630#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002631 // Check spelling (unless at the end of the line).
2632 // Only do this when there is no syntax highlighting, the
2633 // @Spell cluster is not used or the current syntax item
2634 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002635 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002636 if (has_spell && v >= word_end && v > cur_checked_col)
2637 {
2638 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002639 // do not calculate cap_col at the end of the line or when
2640 // only white space is following
2641 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002642# ifdef FEAT_SYN_HL
2643 !has_syntax ||
2644# endif
2645 can_spell))
2646 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002647 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002648 int len;
2649 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002650
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002651 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002652 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002653
2654 // Use nextline[] if possible, it has the start of the
2655 // next line concatenated.
2656 if ((prev_ptr - line) - nextlinecol >= 0)
2657 p = nextline + (prev_ptr - line) - nextlinecol;
2658 else
2659 p = prev_ptr;
2660 cap_col -= (int)(prev_ptr - line);
2661 len = spell_check(wp, p, &spell_hlf, &cap_col,
2662 nochange);
2663 word_end = v + len;
2664
2665 // In Insert mode only highlight a word that
2666 // doesn't touch the cursor.
2667 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002668 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002669 && wp->w_cursor.lnum == lnum
2670 && wp->w_cursor.col >=
2671 (colnr_T)(prev_ptr - line)
2672 && wp->w_cursor.col < (colnr_T)word_end)
2673 {
2674 spell_hlf = HLF_COUNT;
2675 spell_redraw_lnum = lnum;
2676 }
2677
2678 if (spell_hlf == HLF_COUNT && p != prev_ptr
2679 && (p - nextline) + len > nextline_idx)
2680 {
2681 // Remember that the good word continues at the
2682 // start of the next line.
2683 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002684 checked_col = (int)((p - nextline)
2685 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002686 }
2687
2688 // Turn index into actual attributes.
2689 if (spell_hlf != HLF_COUNT)
2690 spell_attr = highlight_attr[spell_hlf];
2691
2692 if (cap_col > 0)
2693 {
2694 if (p != prev_ptr
2695 && (p - nextline) + cap_col >= nextline_idx)
2696 {
2697 // Remember that the word in the next line
2698 // must start with a capital.
2699 capcol_lnum = lnum + 1;
2700 cap_col = (int)((p - nextline) + cap_col
2701 - nextline_idx);
2702 }
2703 else
2704 // Compute the actual column.
2705 cap_col += (int)(prev_ptr - line);
2706 }
2707 }
2708 }
2709 if (spell_attr != 0)
2710 {
2711 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002712 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2713 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002714 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002715 wlv.char_attr = hl_combine_attr(spell_attr,
2716 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002717 }
2718#endif
2719#ifdef FEAT_LINEBREAK
2720 // Found last space before word: check for line break.
2721 if (wp->w_p_lbr && c0 == c
2722 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2723 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002724 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2725 : 0;
2726 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002727 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002728
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002729 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002730# ifdef FEAT_PROP_POPUP
2731 // do not want virtual text counted here
2732 cts.cts_has_prop_with_text = FALSE;
2733# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002734 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002735 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002736
2737 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002738 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002739 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002740 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002741 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2742 if (wlv.n_extra < 0)
2743 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002744 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002745 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002746 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002747 // line break, but for TABs the highlighting should
2748 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002749 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002750
Bram Moolenaar1306b362022-08-06 15:59:06 +01002751 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002752# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002753 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002754 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002755 wp->w_buffer->b_p_vts_array) - 1;
2756# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002757 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002758 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002759# endif
2760
Bram Moolenaar1306b362022-08-06 15:59:06 +01002761 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2762 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002763# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002764 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002765 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002766# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002767 if (VIM_ISWHITE(c))
2768 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002769# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002770 if (c == TAB)
2771 // See "Tab alignment" below.
2772 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002773# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002774 if (!wp->w_p_list)
2775 c = ' ';
2776 }
2777 }
2778#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002779 in_multispace = c == ' '
2780 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2781 if (!in_multispace)
2782 multispace_pos = 0;
2783
Bram Moolenaareed9d462021-02-15 20:38:25 +01002784 // 'list': Change char 160 to 'nbsp' and space to 'space'
2785 // setting in 'listchars'. But not when the character is
2786 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002787 if (wp->w_p_list
2788 && ((((c == 160 && mb_l == 1)
2789 || (mb_utf8
2790 && ((mb_c == 160 && mb_l == 2)
2791 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002792 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002793 || (c == ' '
2794 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002795 && (wp->w_lcs_chars.space
2796 || (in_multispace
2797 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002798 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002799 && ptr - line <= trailcol)))
2800 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002801 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2802 {
2803 c = wp->w_lcs_chars.multispace[multispace_pos++];
2804 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2805 multispace_pos = 0;
2806 }
2807 else
2808 c = (c == ' ') ? wp->w_lcs_chars.space
2809 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002810 if (area_attr == 0 && search_attr == 0)
2811 {
2812 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002813 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002814 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002815 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002816 }
2817 mb_c = c;
2818 if (enc_utf8 && utf_char2len(c) > 1)
2819 {
2820 mb_utf8 = TRUE;
2821 u8cc[0] = 0;
2822 c = 0xc0;
2823 }
2824 else
2825 mb_utf8 = FALSE;
2826 }
2827
zeertzjq2e7cba32022-06-10 15:30:32 +01002828 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2829 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002830 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002831 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2832 && wp->w_lcs_chars.leadmultispace != NULL)
2833 {
2834 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002835 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2836 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002837 multispace_pos = 0;
2838 }
2839
2840 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2841 c = wp->w_lcs_chars.trail;
2842
2843 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2844 c = wp->w_lcs_chars.lead;
2845
zeertzjq2e7cba32022-06-10 15:30:32 +01002846 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002847 c = wp->w_lcs_chars.space;
2848
2849
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002850 if (!attr_pri)
2851 {
2852 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002853 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002854 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002855 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002856 }
2857 mb_c = c;
2858 if (enc_utf8 && utf_char2len(c) > 1)
2859 {
2860 mb_utf8 = TRUE;
2861 u8cc[0] = 0;
2862 c = 0xc0;
2863 }
2864 else
2865 mb_utf8 = FALSE;
2866 }
2867 }
2868
2869 // Handling of non-printable characters.
2870 if (!vim_isprintc(c))
2871 {
2872 // when getting a character from the file, we may have to
2873 // turn it into something else on the way to putting it
2874 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002875 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002876 {
2877 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002878 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002879#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002880 char_u *sbr = get_showbreak_value(wp);
2881
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002882 // only adjust the tab_len, when at the first column
2883 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002884 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002885 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002886#endif
2887 // tab amount depends on current column
2888#ifdef FEAT_VARTABS
2889 tab_len = tabstop_padding(vcol_adjusted,
2890 wp->w_buffer->b_p_ts,
2891 wp->w_buffer->b_p_vts_array) - 1;
2892#else
2893 tab_len = (int)wp->w_buffer->b_p_ts
2894 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2895#endif
2896
2897#ifdef FEAT_LINEBREAK
2898 if (!wp->w_p_lbr || !wp->w_p_list)
2899#endif
2900 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002901 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002902#ifdef FEAT_LINEBREAK
2903 else
2904 {
2905 char_u *p;
2906 int len;
2907 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002908 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002909
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002910# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002911 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002912 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002913 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002914
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002915 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002916 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002917 && old_boguscols > 0
2918 && wlv.n_extra > tab_len)
2919 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002920# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002921 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002922 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002923 // If wlv.n_extra > 0, it gives the number of
2924 // chars, to use for a tab, else we need to
2925 // calculate the width for a tab.
2926 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
2927 len = tab_len * tab2_len;
2928 if (wp->w_lcs_chars.tab3)
2929 len += mb_char2len(wp->w_lcs_chars.tab3)
2930 - tab2_len;
2931 if (wlv.n_extra > 0)
2932 len += wlv.n_extra - tab_len;
2933 c = wp->w_lcs_chars.tab1;
2934 p = alloc(len + 1);
2935 if (p == NULL)
2936 wlv.n_extra = 0;
2937 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002938 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002939 vim_memset(p, ' ', len);
2940 p[len] = NUL;
2941 vim_free(wlv.p_extra_free);
2942 wlv.p_extra_free = p;
2943 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002944 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002945 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002946
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002947 if (*p == NUL)
2948 {
2949 tab_len = i;
2950 break;
2951 }
2952
2953 // if tab3 is given, use it for the last
2954 // char
2955 if (wp->w_lcs_chars.tab3
2956 && i == tab_len - 1)
2957 lcs = wp->w_lcs_chars.tab3;
2958 p += mb_char2bytes(lcs, p);
2959 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002960 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002961 }
2962 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002963# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002964 // n_extra will be increased by
2965 // FIX_FOX_BOGUSCOLS macro below, so need to
2966 // adjust for that here
2967 if (wlv.vcol_off > 0)
2968 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002969# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002970 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002971 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002972 }
2973#endif
2974#ifdef FEAT_CONCEAL
2975 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002976 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002977
2978 // Tab alignment should be identical regardless of
2979 // 'conceallevel' value. So tab compensates of all
2980 // previous concealed characters, and thus resets
2981 // vcol_off and boguscols accumulated so far in the
2982 // line. Note that the tab can be longer than
2983 // 'tabstop' when there are concealed characters.
2984 FIX_FOR_BOGUSCOLS;
2985
2986 // Make sure, the highlighting for the tab char will be
2987 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002988 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002989 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002990 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002991 tab_len += vc_saved;
2992 }
2993#endif
2994 mb_utf8 = FALSE; // don't draw as UTF-8
2995 if (wp->w_p_list)
2996 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002997 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002998 ? wp->w_lcs_chars.tab3
2999 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003000#ifdef FEAT_LINEBREAK
3001 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003002 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003003 else
3004#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003005 wlv.c_extra = wp->w_lcs_chars.tab2;
3006 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003007 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003008 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003009 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003010 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003011 mb_c = c;
3012 if (enc_utf8 && utf_char2len(c) > 1)
3013 {
3014 mb_utf8 = TRUE;
3015 u8cc[0] = 0;
3016 c = 0xc0;
3017 }
3018 }
3019 else
3020 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003021 wlv.c_final = NUL;
3022 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003023 c = ' ';
3024 }
3025 }
3026 else if (c == NUL
3027 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003028 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3029 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003030 && VIsual_mode != Ctrl_V
3031 && (
3032# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003033 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003034# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003035 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003036 && !(noinvcur
3037 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003038 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003039 && lcs_eol_one > 0)
3040 {
3041 // Display a '$' after the line or highlight an extra
3042 // character if the line break is included.
3043#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3044 // For a diff line the highlighting continues after the
3045 // "$".
3046 if (
3047# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003048 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003049# ifdef LINE_ATTR
3050 &&
3051# endif
3052# endif
3053# ifdef LINE_ATTR
3054 line_attr == 0
3055# endif
3056 )
3057#endif
3058 {
3059 // In virtualedit, visual selections may extend
3060 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003061 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003062 && wlv.tocol != MAXCOL
3063 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003064 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003065 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003066 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003067 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3068 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003069 else
3070 c = ' ';
3071 lcs_eol_one = -1;
3072 --ptr; // put it back at the NUL
3073 if (!attr_pri)
3074 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003075 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003076 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003077 n_attr = 1;
3078 }
3079 mb_c = c;
3080 if (enc_utf8 && utf_char2len(c) > 1)
3081 {
3082 mb_utf8 = TRUE;
3083 u8cc[0] = 0;
3084 c = 0xc0;
3085 }
3086 else
3087 mb_utf8 = FALSE; // don't draw as UTF-8
3088 }
3089 else if (c != NUL)
3090 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003091 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3092 if (wlv.n_extra == 0)
3093 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003094#ifdef FEAT_RIGHTLEFT
3095 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003096 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003097#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003098 wlv.c_extra = NUL;
3099 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003100#ifdef FEAT_LINEBREAK
3101 if (wp->w_p_lbr)
3102 {
3103 char_u *p;
3104
Bram Moolenaar1306b362022-08-06 15:59:06 +01003105 c = *wlv.p_extra;
3106 p = alloc(wlv.n_extra + 1);
3107 vim_memset(p, ' ', wlv.n_extra);
3108 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3109 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003110 vim_free(wlv.p_extra_free);
3111 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003112 }
3113 else
3114#endif
3115 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003116 wlv.n_extra = byte2cells(c) - 1;
3117 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003118 }
3119 if (!attr_pri)
3120 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003121 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003122 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003123 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003124 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003125 }
3126 mb_utf8 = FALSE; // don't draw as UTF-8
3127 }
3128 else if (VIsual_active
3129 && (VIsual_mode == Ctrl_V
3130 || VIsual_mode == 'v')
3131 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003132 && wlv.tocol != MAXCOL
3133 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003134 && (
3135#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003136 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003137#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003138 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003139 {
3140 c = ' ';
3141 --ptr; // put it back at the NUL
3142 }
3143#if defined(LINE_ATTR)
3144 else if ((
3145# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003146 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003147# endif
3148# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003149 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003150# endif
3151 line_attr != 0
3152 ) && (
3153# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003154 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003155# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003156 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003157# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003158 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003159# endif
3160 < wp->w_width)))
3161 {
3162 // Highlight until the right side of the window
3163 c = ' ';
3164 --ptr; // put it back at the NUL
3165
3166 // Remember we do the char for line highlighting.
3167 ++did_line_attr;
3168
3169 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01003170 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003171 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003172 || (wp->w_p_list &&
3173 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003174 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003175# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003176 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003177 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003178 wlv.diff_hlf = HLF_CHD;
3179 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003180 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003181 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003182 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3183 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003184 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003185 || (wlv.vcol >= left_curline_col
3186 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003187 wlv.char_attr = hl_combine_attr(
3188 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003189 }
3190 }
3191# endif
3192# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003193 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003194 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003195 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003196 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3197 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003198 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003199 if (!wlv.cul_screenline
3200 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003201 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003202 wlv.char_attr = hl_combine_attr(
3203 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003204 }
3205 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003206 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3207 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003208 }
3209# endif
3210 }
3211#endif
3212 }
3213
3214#ifdef FEAT_CONCEAL
3215 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003216 && (wp != curwin || lnum != wp->w_cursor.lnum
3217 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003218 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3219 && !(lnum_in_visual_area
3220 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3221 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003222 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003223 if (((prev_syntax_id != syntax_seqnr
3224 && (syntax_flags & HL_CONCEAL) != 0)
3225 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003226 && (syn_get_sub_char() != NUL
3227 || (has_match_conc && match_conc)
3228 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003229 && wp->w_p_cole != 3)
3230 {
3231 // First time at this concealed item: display one
3232 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003233 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003234 c = match_conc;
3235 else if (syn_get_sub_char() != NUL)
3236 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003237 else if (wp->w_lcs_chars.conceal != NUL)
3238 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003239 else
3240 c = ' ';
3241
3242 prev_syntax_id = syntax_seqnr;
3243
Bram Moolenaar1306b362022-08-06 15:59:06 +01003244 if (wlv.n_extra > 0)
3245 wlv.vcol_off += wlv.n_extra;
3246 wlv.vcol += wlv.n_extra;
3247 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003248 {
3249# ifdef FEAT_RIGHTLEFT
3250 if (wp->w_p_rl)
3251 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003252 wlv.col -= wlv.n_extra;
3253 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003254 }
3255 else
3256# endif
3257 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003258 wlv.boguscols += wlv.n_extra;
3259 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003260 }
3261 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003262 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003263 n_attr = 0;
3264 }
3265 else if (n_skip == 0)
3266 {
3267 is_concealing = TRUE;
3268 n_skip = 1;
3269 }
3270 mb_c = c;
3271 if (enc_utf8 && utf_char2len(c) > 1)
3272 {
3273 mb_utf8 = TRUE;
3274 u8cc[0] = 0;
3275 c = 0xc0;
3276 }
3277 else
3278 mb_utf8 = FALSE; // don't draw as UTF-8
3279 }
3280 else
3281 {
3282 prev_syntax_id = 0;
3283 is_concealing = FALSE;
3284 }
3285
3286 if (n_skip > 0 && did_decrement_ptr)
3287 // not showing the '>', put pointer back to avoid getting stuck
3288 ++ptr;
3289
3290#endif // FEAT_CONCEAL
3291 }
3292
3293#ifdef FEAT_CONCEAL
3294 // In the cursor line and we may be concealing characters: correct
3295 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003296 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003297 && wp == curwin && lnum == wp->w_cursor.lnum
3298 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003299 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003300 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003301# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003302 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003303 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003304 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003305# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003306 wp->w_wcol = wlv.col - wlv.boguscols;
3307 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003308 did_wcol = TRUE;
3309 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003310# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003311 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003312# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003313 }
3314#endif
3315
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003316 // Use "wlv.extra_attr", but don't override visual selection
3317 // highlighting, unless text property overrides.
3318 // Don't use "wlv.extra_attr" until n_attr_skip is zero.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003319 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003320 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003321 && (!attr_pri
3322#ifdef FEAT_PROP_POPUP
3323 || (text_prop_flags & PT_FLAG_OVERRIDE)
3324#endif
3325 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003326 {
3327#ifdef LINE_ATTR
3328 if (line_attr)
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003329 wlv.char_attr = hl_combine_attr(line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003330 else
3331#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003332 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003333#ifdef FEAT_PROP_POPUP
3334 if (reset_extra_attr)
3335 {
3336 reset_extra_attr = FALSE;
3337 wlv.extra_attr = 0;
3338 }
3339#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003340 }
3341
3342#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3343 // XIM don't send preedit_start and preedit_end, but they send
3344 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3345 // im_is_preediting() here.
3346 if (p_imst == IM_ON_THE_SPOT
3347 && xic != NULL
3348 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003349 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003350 && !p_imdisable
3351 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003352 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003353 {
3354 colnr_T tcol;
3355
3356 if (preedit_end_col == MAXCOL)
3357 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3358 else
3359 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003360 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003361 {
3362 if (feedback_old_attr < 0)
3363 {
3364 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003365 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003366 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003367 wlv.char_attr = im_get_feedback_attr(feedback_col);
3368 if (wlv.char_attr < 0)
3369 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003370 feedback_col++;
3371 }
3372 else if (feedback_old_attr >= 0)
3373 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003374 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003375 feedback_old_attr = -1;
3376 feedback_col = 0;
3377 }
3378 }
3379#endif
3380 // Handle the case where we are in column 0 but not on the first
3381 // character of the line and the user wants us to show us a
3382 // special character (via 'listchars' option "precedes:<char>".
3383 if (lcs_prec_todo != NUL
3384 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003385 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3386 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003387#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003388 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003389#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003390 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003391 && c != NUL)
3392 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003393 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003394 lcs_prec_todo = NUL;
3395 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3396 {
3397 // Double-width character being overwritten by the "precedes"
3398 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003399 wlv.c_extra = MB_FILLER_CHAR;
3400 wlv.c_final = NUL;
3401 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003402 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003403 wlv.extra_attr =
3404 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003405 }
3406 mb_c = c;
3407 if (enc_utf8 && utf_char2len(c) > 1)
3408 {
3409 mb_utf8 = TRUE;
3410 u8cc[0] = 0;
3411 c = 0xc0;
3412 }
3413 else
3414 mb_utf8 = FALSE; // don't draw as UTF-8
3415 if (!attr_pri)
3416 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003417 saved_attr3 = wlv.char_attr; // save current attr
3418 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003419 n_attr3 = 1;
3420 }
3421 }
3422
3423 // At end of the text line or just after the last character.
3424 if ((c == NUL
3425#if defined(LINE_ATTR)
3426 || did_line_attr == 1
3427#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003428 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003429 {
3430#ifdef FEAT_SEARCH_EXTRA
3431 // flag to indicate whether prevcol equals startcol of search_hl or
3432 // one of the matches
3433 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3434 (long)(ptr - line) - (c == NUL));
3435#endif
3436 // Invert at least one char, used for Visual and empty line or
3437 // highlight match at end of line. If it's beyond the last
3438 // char on the screen, just overwrite that one (tricky!) Not
3439 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003440 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003441 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003442 && (VIsual_mode != Ctrl_V
3443 || lnum == VIsual.lnum
3444 || lnum == curwin->w_cursor.lnum)
3445 && c == NUL)
3446#ifdef FEAT_SEARCH_EXTRA
3447 // highlight 'hlsearch' match at end of line
3448 || (prevcol_hl_flag
3449# ifdef FEAT_SYN_HL
3450 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3451 && !(wp == curwin && VIsual_active))
3452# endif
3453# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003454 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003455# endif
3456# if defined(LINE_ATTR)
3457 && did_line_attr <= 1
3458# endif
3459 )
3460#endif
3461 ))
3462 {
3463 int n = 0;
3464
3465#ifdef FEAT_RIGHTLEFT
3466 if (wp->w_p_rl)
3467 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003468 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003469 n = 1;
3470 }
3471 else
3472#endif
3473 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003474 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003475 n = -1;
3476 }
3477 if (n != 0)
3478 {
3479 // At the window boundary, highlight the last character
3480 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003481 wlv.off += n;
3482 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003483 }
3484 else
3485 {
3486 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003487 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003488 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003489 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003490 }
3491#ifdef FEAT_SEARCH_EXTRA
3492 if (area_attr == 0)
3493 {
3494 // Use attributes from match with highest priority among
3495 // 'search_hl' and the match list.
3496 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003497 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003498 }
3499#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003500 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003501 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003502#ifdef FEAT_RIGHTLEFT
3503 if (wp->w_p_rl)
3504 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003505 --wlv.col;
3506 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003507 }
3508 else
3509#endif
3510 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003511 ++wlv.col;
3512 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003513 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003514 ++wlv.vcol;
3515 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003516 }
3517 }
3518
3519 // At end of the text line.
3520 if (c == NUL)
3521 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003522 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003523
3524 // Update w_cline_height and w_cline_folded if the cursor line was
3525 // updated (saves a call to plines() later).
3526 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3527 {
3528 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003529 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003530#ifdef FEAT_FOLDING
3531 curwin->w_cline_folded = FALSE;
3532#endif
3533 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3534 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003535 break;
3536 }
3537
3538 // Show "extends" character from 'listchars' if beyond the line end and
3539 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003540 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003541 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003542 && wp->w_p_list
3543 && !wp->w_p_wrap
3544#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003545 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003546#endif
3547 && (
3548#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003549 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003550#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003551 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003552 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003553 || lcs_eol_one > 0
3554 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003555 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003556 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003557 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003558 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003559 mb_c = c;
3560 if (enc_utf8 && utf_char2len(c) > 1)
3561 {
3562 mb_utf8 = TRUE;
3563 u8cc[0] = 0;
3564 c = 0xc0;
3565 }
3566 else
3567 mb_utf8 = FALSE;
3568 }
3569
3570#ifdef FEAT_SYN_HL
3571 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003572 if (wlv.draw_color_col)
3573 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003574
3575 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3576 // highlight the cursor position itself.
3577 // Also highlight the 'colorcolumn' if it is different than
3578 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003579 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3580 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003581 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003582 if (((wlv.draw_state == WL_LINE
3583 || wlv.draw_state == WL_BRI
3584 || wlv.draw_state == WL_SBR)
3585 && !lnum_in_visual_area
3586 && search_attr == 0
3587 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003588# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003589 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003590# endif
3591 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003592 {
3593 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3594 && lnum != wp->w_cursor.lnum)
3595 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003596 vcol_save_attr = wlv.char_attr;
3597 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3598 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003599 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003600 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003601 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003602 vcol_save_attr = wlv.char_attr;
3603 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003604 }
3605 }
3606#endif
3607
3608 // Store character to be displayed.
3609 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003610 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003611 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003612 {
3613 // Store the character.
3614#if defined(FEAT_RIGHTLEFT)
3615 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3616 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003617 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003618 --wlv.off;
3619 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003620 }
3621#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003622 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003623 if (enc_dbcs == DBCS_JPNU)
3624 {
3625 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003626 ScreenLines[wlv.off] = 0x8e;
3627 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003628 }
3629 else if (enc_utf8)
3630 {
3631 if (mb_utf8)
3632 {
3633 int i;
3634
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003635 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003636 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003637 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003638 for (i = 0; i < Screen_mco; ++i)
3639 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003640 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003641 if (u8cc[i] == 0)
3642 break;
3643 }
3644 }
3645 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003646 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003647 }
3648 if (multi_attr)
3649 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003650 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003651 multi_attr = 0;
3652 }
3653 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003654 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003655
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003656 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003657
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003658 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3659 {
3660 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003661 ++wlv.off;
3662 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003663 if (enc_utf8)
3664 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003665 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003666 else
3667 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003668 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003669 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003670#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003671 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003672#endif
3673 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003674 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003675 // When "wlv.tocol" is halfway a character, set it to the end
3676 // of the character, otherwise highlighting won't stop.
3677 if (wlv.tocol == wlv.vcol)
3678 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003679
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003680 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003681
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003682#ifdef FEAT_RIGHTLEFT
3683 if (wp->w_p_rl)
3684 {
3685 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003686 --wlv.off;
3687 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003688 }
3689#endif
3690 }
3691#ifdef FEAT_RIGHTLEFT
3692 if (wp->w_p_rl)
3693 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003694 --wlv.off;
3695 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003696 }
3697 else
3698#endif
3699 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003700 ++wlv.off;
3701 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003702 }
3703 }
3704#ifdef FEAT_CONCEAL
3705 else if (wp->w_p_cole > 0 && is_concealing)
3706 {
3707 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003708 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003709 if (wlv.n_extra > 0)
3710 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003711 if (wp->w_p_wrap)
3712 {
3713 // Special voodoo required if 'wrap' is on.
3714 //
3715 // Advance the column indicator to force the line
3716 // drawing to wrap early. This will make the line
3717 // take up the same screen space when parts are concealed,
3718 // so that cursor line computations aren't messed up.
3719 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003720 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003721 // trailing junk to be written out of the screen line
3722 // we are building, 'boguscols' keeps track of the number
3723 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003724 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003725 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003726 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003727# ifdef FEAT_RIGHTLEFT
3728 if (wp->w_p_rl)
3729 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003730 wlv.col -= wlv.n_extra;
3731 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003732 }
3733 else
3734# endif
3735 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003736 wlv.col += wlv.n_extra;
3737 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003738 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003739 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003740 n_attr = 0;
3741 }
3742
3743
3744 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3745 {
3746 // Need to fill two screen columns.
3747# ifdef FEAT_RIGHTLEFT
3748 if (wp->w_p_rl)
3749 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003750 --wlv.boguscols;
3751 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003752 }
3753 else
3754# endif
3755 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003756 ++wlv.boguscols;
3757 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003758 }
3759 }
3760
3761# ifdef FEAT_RIGHTLEFT
3762 if (wp->w_p_rl)
3763 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003764 --wlv.boguscols;
3765 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003766 }
3767 else
3768# endif
3769 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003770 ++wlv.boguscols;
3771 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003772 }
3773 }
3774 else
3775 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003776 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003777 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003778 wlv.vcol += wlv.n_extra;
3779 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003780 n_attr = 0;
3781 }
3782 }
3783
3784 }
3785#endif // FEAT_CONCEAL
3786 else
3787 --n_skip;
3788
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003789 // Only advance the "wlv.vcol" when after the 'number' or
3790 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003791 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003792#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003793 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003794#endif
3795 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003796 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003797
3798#ifdef FEAT_SYN_HL
3799 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003800 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003801#endif
3802
3803 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003804 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3805 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003806
3807 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003808 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003809 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003810 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003811 if (n_attr_skip > 0)
3812 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003813
3814 // At end of screen line and there is more to come: Display the line
3815 // so far. If there is no more to display it is caught above.
3816 if ((
3817#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003818 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003819#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003820 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003821 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003822 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003823#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003824 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003825#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003826#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003827 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003828#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003829 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003830 && wlv.p_extra != at_end_str)
3831 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3832 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003833 )
3834 {
3835#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003836 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003837 wlv_screen_line(wp, &wlv, FALSE);
3838 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003839 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003840#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003841 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003842#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003843 ++wlv.row;
3844 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003845
3846 // When not wrapping and finished diff lines, or when displayed
3847 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01003848 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003849#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003850 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003851#endif
3852#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01003853 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003854#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01003855 ) || lcs_eol_one == -1)
3856#ifdef FEAT_PROP_POPUP
3857 && !text_prop_follows
3858#endif
3859 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003860 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003861#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003862 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003863 {
3864 // do not output more of the line, only the "below" prop
3865 ptr += STRLEN(ptr);
3866# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003867 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003868# endif
3869 }
3870#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003871
3872 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003873 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003874#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003875 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003876#endif
3877 )
3878 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003879 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3880 draw_vsep_win(wp, wlv.row);
3881 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003882 }
3883
3884 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003885 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003886 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003887 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003888 break;
3889 }
3890
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003891 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003892#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003893 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003894#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003895#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003896 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003897#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003898 && wp->w_width == Columns)
3899 {
3900 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003901 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003902
3903 // Special trick to make copy/paste of wrapped lines work with
3904 // xterm/screen: write an extra character beyond the end of
3905 // the line. This will work with all terminal types
3906 // (regardless of the xn,am settings).
3907 // Only do this on a fast tty.
3908 // Only do this if the cursor is on the current line
3909 // (something has been written in it).
3910 // Don't do this for the GUI.
3911 // Don't do this for double-width characters.
3912 // Don't do this for a window not at the right screen border.
3913 if (p_tf
3914#ifdef FEAT_GUI
3915 && !gui.in_use
3916#endif
3917 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003918 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3919 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003920 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003921 || (*mb_off2cells)(
3922 LineOffset[wlv.screen_row - 1]
3923 + (int)Columns - 2,
3924 LineOffset[wlv.screen_row]
3925 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003926 {
3927 // First make sure we are at the end of the screen line,
3928 // then output the same character again to let the
3929 // terminal know about the wrap. If the terminal doesn't
3930 // auto-wrap, we overwrite the character.
3931 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003932 screen_char(LineOffset[wlv.screen_row - 1]
3933 + (unsigned)Columns - 1,
3934 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003935
3936 // When there is a multi-byte character, just output a
3937 // space to keep it simple.
3938 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003939 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003940 out_char(' ');
3941 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003942 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003943 + (Columns - 1)]);
3944 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003945 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003946 screen_start(); // don't know where cursor is now
3947 }
3948 }
3949
Bram Moolenaar1306b362022-08-06 15:59:06 +01003950 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003951
Bram Moolenaareed9d462021-02-15 20:38:25 +01003952 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003953#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003954 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003955# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003956 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003957# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003958 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003959 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003960#endif
3961#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003962 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003963 // When the filler lines are actually below the last line of the
3964 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003965 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003966 break;
3967#endif
3968 }
3969
3970 } // for every character in the line
3971
3972#ifdef FEAT_SPELL
3973 // After an empty line check first word for capital.
3974 if (*skipwhite(line) == NUL)
3975 {
3976 capcol_lnum = lnum + 1;
3977 cap_col = 0;
3978 }
3979#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003980#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003981 vim_free(text_props);
3982 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003983 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003984#endif
3985
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003986 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003987 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003988}