blob: cc1bed6b194af7ddcc621cd8b661ca7959e4d822 [file] [log] [blame]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * drawline.c: Functions for drawing window lines on the screen.
Bram Moolenaare89aeed2022-08-22 13:00:16 +010012 * This is the middle level, drawscreen.c is the higher level and screen.c the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020013 * lower level.
14 */
15
16#include "vim.h"
17
18#ifdef FEAT_SYN_HL
19/*
20 * Advance **color_cols and return TRUE when there are columns to draw.
21 */
22 static int
23advance_color_col(int vcol, int **color_cols)
24{
25 while (**color_cols >= 0 && vcol > **color_cols)
26 ++*color_cols;
27 return (**color_cols >= 0);
28}
29#endif
30
31#ifdef FEAT_SYN_HL
32/*
33 * Used when 'cursorlineopt' contains "screenline": compute the margins between
34 * which the highlighting is used.
35 */
36 static void
37margin_columns_win(win_T *wp, int *left_col, int *right_col)
38{
39 // cache previous calculations depending on w_virtcol
40 static int saved_w_virtcol;
41 static win_T *prev_wp;
42 static int prev_left_col;
43 static int prev_right_col;
44 static int prev_col_off;
45
46 int cur_col_off = win_col_off(wp);
47 int width1;
48 int width2;
49
50 if (saved_w_virtcol == wp->w_virtcol
51 && prev_wp == wp && prev_col_off == cur_col_off)
52 {
53 *right_col = prev_right_col;
54 *left_col = prev_left_col;
55 return;
56 }
57
58 width1 = wp->w_width - cur_col_off;
59 width2 = width1 + win_col_off2(wp);
60
61 *left_col = 0;
62 *right_col = width1;
63
64 if (wp->w_virtcol >= (colnr_T)width1)
65 *right_col = width1 + ((wp->w_virtcol - width1) / width2 + 1) * width2;
66 if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0)
67 *left_col = (wp->w_virtcol - width1) / width2 * width2 + width1;
68
69 // cache values
70 prev_left_col = *left_col;
71 prev_right_col = *right_col;
72 prev_wp = wp;
73 saved_w_virtcol = wp->w_virtcol;
74 prev_col_off = cur_col_off;
75}
76#endif
77
Bram Moolenaar45e4eea2022-12-01 18:38:02 +000078#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
79 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
80// using an attribute for the whole line
81# define LINE_ATTR
82#endif
83
Bram Moolenaar1306b362022-08-06 15:59:06 +010084// structure with variables passed between win_line() and other functions
85typedef struct {
86 int draw_state; // what to draw next
87
88 linenr_T lnum; // line number to be drawn
89
90 int startrow; // first row in the window to be drawn
91 int row; // row in the window, excl w_winrow
92 int screen_row; // row on the screen, incl w_winrow
93
94 long vcol; // virtual column, before wrapping
95 int col; // visual column on screen, after wrapping
96#ifdef FEAT_CONCEAL
97 int boguscols; // nonexistent columns added to "col" to force
98 // wrapping
Bram Moolenaarf53e0652023-02-19 14:16:02 +000099 int vcol_off_co; // offset for concealed characters
Bram Moolenaar1306b362022-08-06 15:59:06 +0100100#endif
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000101 int vcol_off_tp; // offset for virtual text
Bram Moolenaar1306b362022-08-06 15:59:06 +0100102#ifdef FEAT_SYN_HL
103 int draw_color_col; // highlight colorcolumn
104 int *color_cols; // pointer to according columns array
105#endif
106 int eol_hl_off; // 1 if highlighted char after EOL
107
108 unsigned off; // offset in ScreenLines/ScreenAttrs
109
110 int win_attr; // background for the whole window, except
111 // margins and "~" lines.
Bram Moolenaard7657e92022-09-20 18:59:30 +0100112 int wcr_attr; // attributes from 'wincolor'
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100113#ifdef FEAT_SYN_HL
114 int cul_attr; // set when 'cursorline' active
115#endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000116#ifdef LINE_ATTR
117 int line_attr; // for the whole line, includes 'cursorline'
118#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100119
120 int screen_line_flags; // flags for screen_line()
121
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100122 int fromcol; // start of inverting
123 int tocol; // end of inverting
124
125#ifdef FEAT_LINEBREAK
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100126 long vcol_sbr; // virtual column after showbreak
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100127 int need_showbreak; // overlong line, skipping first x chars
128 int dont_use_showbreak; // do not use 'showbreak'
129#endif
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100130#ifdef FEAT_PROP_POPUP
131 int text_prop_above_count;
132#endif
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100133
Bram Moolenaar1306b362022-08-06 15:59:06 +0100134 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
135 int cul_screenline;
136
137 int char_attr; // attributes for the next character
138
139 int n_extra; // number of extra bytes
140 char_u *p_extra; // string of extra chars, plus NUL, only used
141 // when c_extra and c_final are NUL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100142 char_u *p_extra_free; // p_extra buffer that needs to be freed
Bram Moolenaaree28c702022-11-17 14:56:00 +0000143 int extra_attr; // attributes for p_extra, should be combined
144 // with win_attr if needed
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000145 int n_attr_skip; // chars to skip before using extra_attr
Bram Moolenaar1306b362022-08-06 15:59:06 +0100146 int c_extra; // extra chars, all the same
147 int c_final; // final char, mandatory if set
zeertzjq6e940d92023-08-17 23:21:40 +0200148 int extra_for_textprop; // n_extra set for textprop
149 int start_extra_for_textprop; // extra_for_textprop was just set
Bram Moolenaar1306b362022-08-06 15:59:06 +0100150
151 // saved "extra" items for when draw_state becomes WL_LINE (again)
152 int saved_n_extra;
153 char_u *saved_p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +0100154 char_u *saved_p_extra_free;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000155 int saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000156 int saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000157 int saved_extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100158 int saved_c_extra;
159 int saved_c_final;
160 int saved_char_attr;
161
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100162 char_u extra[NUMBUFLEN + MB_MAXBYTES];
163 // "%ld " and 'fdc' must fit in here, as well
164 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100165
Bram Moolenaar1306b362022-08-06 15:59:06 +0100166#ifdef FEAT_DIFF
167 hlf_T diff_hlf; // type of diff highlighting
168#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100169 int filler_lines; // nr of filler lines to be drawn
170 int filler_todo; // nr of filler lines still to do + 1
171#ifdef FEAT_SIGNS
172 sign_attrs_T sattr;
173#endif
Christian Brabandtdd75fcf2023-10-11 21:51:19 +0200174#ifdef FEAT_LINEBREAK
175 // do consider wrapping in linebreak mode only after encountering
176 // a non whitespace char
177 int need_lbr;
178#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100179} winlinevars_T;
180
181// draw_state values for items that are drawn in sequence:
182#define WL_START 0 // nothing done yet, must be zero
Martin Tournoij7904fa42022-10-04 16:28:45 +0100183#define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar1306b362022-08-06 15:59:06 +0100184#ifdef FEAT_FOLDING
185# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
186#else
187# define WL_FOLD WL_CMDLINE
188#endif
189#ifdef FEAT_SIGNS
190# define WL_SIGN (WL_FOLD + 1) // column for signs
191#else
192# define WL_SIGN WL_FOLD // column for signs
193#endif
194#define WL_NR (WL_SIGN + 1) // line number
195#ifdef FEAT_LINEBREAK
196# define WL_BRI (WL_NR + 1) // 'breakindent'
197#else
198# define WL_BRI WL_NR
199#endif
200#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
201# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
202#else
203# define WL_SBR WL_BRI
204#endif
205#define WL_LINE (WL_SBR + 1) // text in the line
206
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100207#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200208/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000209 * Return TRUE if CursorLineSign highlight is to be used.
210 */
211 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100212use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000213{
214 return wp->w_p_cul
215 && lnum == wp->w_cursor.lnum
216 && (wp->w_p_culopt_flags & CULOPT_NBR);
217}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100218#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000219
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100220
221#ifdef FEAT_FOLDING
222/*
223 * Setup for drawing the 'foldcolumn', if there is one.
224 */
225 static void
226handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
227{
228 int fdc = compute_foldcolumn(wp, 0);
229
230 if (fdc <= 0)
231 return;
232
233 // Allocate a buffer, "wlv->extra[]" may already be in use.
234 vim_free(wlv->p_extra_free);
235 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
Yegappan Lakshmanan465de3a2022-12-26 12:50:04 +0000236 if (wlv->p_extra_free == NULL)
237 return;
238
239 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
zeertzjq58e1e012023-06-04 18:46:28 +0100240 wp, FALSE, wlv->lnum);
Yegappan Lakshmanan465de3a2022-12-26 12:50:04 +0000241 wlv->p_extra_free[wlv->n_extra] = NUL;
242 wlv->p_extra = wlv->p_extra_free;
243 wlv->c_extra = NUL;
244 wlv->c_final = NUL;
245 if (use_cursor_line_highlight(wp, wlv->lnum))
246 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
247 else
248 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100249}
250#endif
251
252#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000253/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100254 * Get information needed to display the sign in line "wlv->lnum" in window
255 * "wp".
256 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200257 * Otherwise the sign is going to be displayed in the sign column.
258 */
259 static void
260get_sign_display_info(
261 int nrcol,
262 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100263 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200264{
265 int text_sign;
266# ifdef FEAT_SIGN_ICONS
267 int icon_sign;
268# endif
269
270 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100271 wlv->c_extra = ' ';
272 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200273 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100274 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200275 else
276 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100277 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100278 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000279 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100280 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100281 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200282 }
283
Bram Moolenaar1306b362022-08-06 15:59:06 +0100284 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200285#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100286 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200287#endif
288 )
289 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100290 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200291# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100292 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200293 if (gui.in_use && icon_sign != 0)
294 {
295 // Use the image in this position.
296 if (nrcol)
297 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100298 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100299 sprintf((char *)wlv->extra, "%-*c ",
300 number_width(wp), SIGN_BYTE);
301 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100302 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200303 }
304 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100305 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200306# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100307 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
308 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200309 {
310 if (nrcol)
311 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100312 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100313 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200314 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100315 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100316 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200317 }
318 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100319 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200320 }
321# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100322 wlv->c_final = NUL;
323 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200324 }
325 else
326# endif
327 if (text_sign != 0)
328 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100329 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100330 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200331 {
332 if (nrcol)
333 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100334 int width = number_width(wp) - 2;
335 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200336
337 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100338 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100339 vim_snprintf((char *)wlv->extra + n,
340 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100341 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200342 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100343 wlv->c_extra = NUL;
344 wlv->c_final = NUL;
345 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200346 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000347
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100348 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100349 && wlv->sattr.sat_culhl > 0)
350 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000351 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100352 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200353 }
354 }
355}
356#endif
357
Bram Moolenaard7657e92022-09-20 18:59:30 +0100358/*
359 * Display the absolute or relative line number. After the first row fill with
360 * blanks when the 'n' flag isn't in 'cpo'.
361 */
362 static void
363handle_lnum_col(
364 win_T *wp,
365 winlinevars_T *wlv,
366 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100367 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100368{
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100369 int has_cpo_n = vim_strchr(p_cpo, CPO_NUMCOL) != NULL;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100370 int lnum_row = wlv->startrow + wlv->filler_lines
371#ifdef FEAT_PROP_POPUP
372 + wlv->text_prop_above_count
373#endif
374 ;
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100375
Bram Moolenaard7657e92022-09-20 18:59:30 +0100376 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100377 && (wlv->row <= lnum_row || !has_cpo_n)
Bram Moolenaar37251162022-10-06 20:48:00 +0100378 // there is no line number in a wrapped line when "n" is in
379 // 'cpoptions', but 'breakindent' assumes it anyway.
380 && !((has_cpo_n
381#ifdef FEAT_LINEBREAK
382 && !wp->w_p_bri
383#endif
384 ) && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100385 {
386#ifdef FEAT_SIGNS
387 // If 'signcolumn' is set to 'number' and a sign is present
388 // in 'lnum', then display the sign instead of the line
389 // number.
390 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
391 get_sign_display_info(TRUE, wp, wlv);
392 else
393#endif
394 {
395 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100396 // When there are text properties above the line put the line number
397 // below them.
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100398 if (wlv->row == lnum_row
zeertzjq88bb3e02023-05-02 20:52:59 +0100399 && (wp->w_skipcol == 0 || wlv->row > 0
Bram Moolenaareb4de622022-10-15 13:42:17 +0100400 || (wp->w_p_nu && wp->w_p_rnu)))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100401 {
402 long num;
403 char *fmt = "%*ld ";
404
405 if (wp->w_p_nu && !wp->w_p_rnu)
406 // 'number' + 'norelativenumber'
407 num = (long)wlv->lnum;
408 else
409 {
410 // 'relativenumber', don't use negative numbers
411 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
412 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
413 {
414 // 'number' + 'relativenumber'
415 num = wlv->lnum;
416 fmt = "%-*ld ";
417 }
418 }
419
420 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100421 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100422 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
423 ++wlv->p_extra)
424 *wlv->p_extra = '-';
425#ifdef FEAT_RIGHTLEFT
426 if (wp->w_p_rl) // reverse line numbers
427 {
428 char_u *p1, *p2;
429 int t;
430
431 // like rl_mirror(), but keep the space at the end
432 p2 = skipwhite(wlv->extra);
433 p2 = skiptowhite(p2) - 1;
434 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
435 {
436 t = *p1;
437 *p1 = *p2;
438 *p2 = t;
439 }
440 }
441#endif
442 wlv->p_extra = wlv->extra;
443 wlv->c_extra = NUL;
444 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100445 }
446 else
447 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100448 wlv->c_extra = ' ';
449 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100450 }
451 wlv->n_extra = number_width(wp) + 1;
452 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
453#ifdef FEAT_SYN_HL
454 // When 'cursorline' is set highlight the line number of
455 // the current line differently.
456 // When 'cursorlineopt' does not have "line" only
457 // highlight the line number itself.
458 // TODO: Can we use CursorLine instead of CursorLineNr
459 // when CursorLineNr isn't set?
460 if (wp->w_p_cul
461 && wlv->lnum == wp->w_cursor.lnum
462 && (wp->w_p_culopt_flags & CULOPT_NBR)
463 && (wlv->row == wlv->startrow + wlv->filler_lines
464 || (wlv->row > wlv->startrow + wlv->filler_lines
465 && (wp->w_p_culopt_flags & CULOPT_LINE))))
466 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
467#endif
468 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
469 && HL_ATTR(HLF_LNA) != 0)
470 // Use LineNrAbove
471 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
472 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
473 && HL_ATTR(HLF_LNB) != 0)
474 // Use LineNrBelow
475 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
476 }
477#ifdef FEAT_SIGNS
478 if (num_attr)
479 wlv->char_attr = num_attr;
480#endif
481 }
482}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100483
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100484#ifdef FEAT_LINEBREAK
485 static void
486handle_breakindent(win_T *wp, winlinevars_T *wlv)
487{
488 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100489 && *get_showbreak_value(wp) != NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100490 // draw indent after showbreak value
491 wlv->draw_state = WL_BRI;
492 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
493 // After the showbreak, draw the breakindent
494 wlv->draw_state = WL_BRI - 1;
495
496 // draw 'breakindent': indent wrapped text accordingly
497 if (wlv->draw_state == WL_BRI - 1)
498 {
499 wlv->draw_state = WL_BRI;
500 // if wlv->need_showbreak is set, breakindent also applies
zeertzjq588f20d2023-12-05 15:47:09 +0100501 if (wp->w_p_bri && (wlv->row > wlv->startrow
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100502# ifdef FEAT_DIFF
zeertzjq588f20d2023-12-05 15:47:09 +0100503 + wlv->filler_lines
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100504# endif
zeertzjq588f20d2023-12-05 15:47:09 +0100505 || wlv->need_showbreak)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100506# ifdef FEAT_PROP_POPUP
507 && !wlv->dont_use_showbreak
508# endif
509 )
510 {
511 wlv->char_attr = 0;
512# ifdef FEAT_DIFF
513 if (wlv->diff_hlf != (hlf_T)0)
514 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
515# endif
516 wlv->p_extra = NULL;
517 wlv->c_extra = ' ';
518 wlv->c_final = NUL;
519 wlv->n_extra = get_breakindent_win(wp,
520 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
521 if (wlv->row == wlv->startrow)
522 {
523 wlv->n_extra -= win_col_off2(wp);
524 if (wlv->n_extra < 0)
525 wlv->n_extra = 0;
526 }
zeertzjq23627722023-12-27 19:08:53 +0100527
528 // Correct start of highlighted area for 'breakindent',
529 if (wlv->fromcol >= wlv->vcol
530 && wlv->fromcol < wlv->vcol + wlv->n_extra)
531 wlv->fromcol = wlv->vcol + wlv->n_extra;
532
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100533 // Correct end of highlighted area for 'breakindent',
534 // required when 'linebreak' is also set.
535 if (wlv->tocol == wlv->vcol)
536 wlv->tocol += wlv->n_extra;
537 }
zeertzjq7e4f62a2023-12-28 23:19:52 +0100538
539 if (wp->w_skipcol > 0 && wlv->startrow == 0 && wp->w_p_wrap
540 && wp->w_briopt_sbr)
541 wlv->need_showbreak = FALSE;
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100542 }
543}
544#endif
545
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100546#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
547 static void
548handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
549{
550# ifdef FEAT_DIFF
551 if (wlv->filler_todo > 0)
552 {
553 // Draw "deleted" diff line(s).
554 if (char2cells(wp->w_fill_chars.diff) > 1)
555 {
556 wlv->c_extra = '-';
557 wlv->c_final = NUL;
558 }
559 else
560 {
561 wlv->c_extra = wp->w_fill_chars.diff;
562 wlv->c_final = NUL;
563 }
564# ifdef FEAT_RIGHTLEFT
565 if (wp->w_p_rl)
566 wlv->n_extra = wlv->col + 1;
567 else
568# endif
569 wlv->n_extra = wp->w_width - wlv->col;
570 wlv->char_attr = HL_ATTR(HLF_DED);
571 }
572# endif
573
574# ifdef FEAT_LINEBREAK
575 char_u *sbr = get_showbreak_value(wp);
576 if (*sbr != NUL && wlv->need_showbreak)
577 {
578 // Draw 'showbreak' at the start of each broken line.
579 wlv->p_extra = sbr;
580 wlv->c_extra = NUL;
581 wlv->c_final = NUL;
582 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100583 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100584
585 // Correct start of highlighted area for 'showbreak'.
586 if (wlv->fromcol >= wlv->vcol && wlv->fromcol < wlv->vcol_sbr)
587 wlv->fromcol = wlv->vcol_sbr;
588
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100589 // Correct end of highlighted area for 'showbreak',
590 // required when 'linebreak' is also set.
591 if (wlv->tocol == wlv->vcol)
zeertzjqdf23d7f2024-02-09 18:14:12 +0100592 wlv->tocol = wlv->vcol_sbr;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100593 // combine 'showbreak' with 'wincolor'
594 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
595# ifdef FEAT_SYN_HL
596 // combine 'showbreak' with 'cursorline'
597 if (wlv->cul_attr != 0)
598 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
599# endif
600 }
zeertzjq7e4f62a2023-12-28 23:19:52 +0100601
602 if (wp->w_skipcol == 0 || wlv->startrow > 0 || !wp->w_p_wrap
603 || !wp->w_briopt_sbr)
604 wlv->need_showbreak = FALSE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100605# endif
606}
607#endif
608
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100609#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100610/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100611 * Return the cell size of virtual text after truncation.
612 */
613 static int
614textprop_size_after_trunc(
615 win_T *wp,
616 int flags, // TP_FLAG_ALIGN_*
617 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100618 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100619 char_u *text,
620 int *n_used_ptr)
621{
622 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100623 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100624 int len = (int)STRLEN(text);
625 int strsize = 0;
626 int n_used;
627
Bram Moolenaar7e017462022-10-11 21:02:09 +0100628 // if the remaining size is to small and 'wrap' is set we wrap anyway and
629 // use the next line
630 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100631 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100632 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100633 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100634 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
635 {
636 int clen = ptr2cells(text + n_used);
637
638 if (strsize + clen > space)
639 break;
640 strsize += clen;
641 }
642 *n_used_ptr = n_used;
643 return strsize;
644}
645
646/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100647 * Take care of padding, right-align and truncation of virtual text after a
648 * line.
649 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
650 * padding, right-align and truncation. Otherwise only the size is computed.
651 * When "n_attr" is NULL returns the number of screen cells used.
652 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100653 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100654 int
655text_prop_position(
656 win_T *wp,
657 textprop_T *tp,
porygonisaduck38854b52022-11-27 20:55:05 +0000658 int vcol, // current text column
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100659 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100660 int *n_extra, // nr of bytes for virtual text
661 char_u **p_extra, // virtual text
662 int *n_attr, // attribute cells, NULL if not used
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000663 int *n_attr_skip, // cells to skip attr, NULL if not used
664 int do_skip) // skip_cells is not zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200665{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100666 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100667 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100668 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
Bram Moolenaar1aeb3eb2023-01-01 14:04:51 +0000669 int wrap = tp->tp_col < MAXCOL || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100670 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
porygonisaduck38854b52022-11-27 20:55:05 +0000671 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100672 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100673 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100674 int before = room; // spaces before the text
675 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100676 int n_used = *n_extra;
677 char_u *l = NULL;
678 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100679 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100680 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200681
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100682 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100683 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100684 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100685
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100686 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100687 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100688 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100689 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar2354b662023-04-23 21:42:25 +0100690 if (after < 0)
691 {
692 // text "above" has too much padding to fit
693 padding += after;
694 after = 0;
695 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100696 }
697 else
698 {
699 // Right-align: fill with before
700 if (right)
701 before -= cells;
porygonisaduck38854b52022-11-27 20:55:05 +0000702
703 // Below-align: empty line add one character
Bram Moolenaar7c02ad92022-11-29 21:37:13 +0000704 if (below && vcol == 0 && col_with_padding == col_off
705 && wp->w_width - col_off == before)
706 col_with_padding += 1;
porygonisaduck38854b52022-11-27 20:55:05 +0000707
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100708 if (before < 0
709 || !(right || below)
porygonisaduck38854b52022-11-27 20:55:05 +0000710 || (below ? (col_with_padding <= col_off || !wp->w_p_wrap)
711 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100712 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100713 if (right && (wrap
714 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100715 {
716 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100717 before = wp->w_width - col_off - strsize + room;
718 if (before < 0)
719 before = 0;
720 else
721 n_used = *n_extra;
722 }
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000723 else if (below && before > vcol && do_skip)
724 before -= vcol;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100725 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100726 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100727 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100728 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100729
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100730 // With 'nowrap' add one to show the "extends" character if needed (it
731 // doesn't show if the text just fits).
732 if (!wp->w_p_wrap
733 && n_used < *n_extra
734 && wp->w_lcs_chars.ext != NUL
735 && wp->w_p_list)
736 ++n_used;
737
738 // add 1 for NUL, 2 for when '…' is used
739 if (n_attr != NULL)
Christian Brabandtf1cc4d52023-08-12 00:14:14 +0200740 l = alloc(n_used + before + after + (padding > 0 ? padding : 0) + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100741 if (n_attr == NULL || l != NULL)
742 {
743 int off = 0;
744
745 if (n_attr != NULL)
746 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100747 vim_memset(l, ' ', before);
748 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100749 if (padding > 0)
750 {
751 vim_memset(l + off, ' ', padding);
752 off += padding;
753 }
754 vim_strncpy(l + off, *p_extra, n_used);
755 off += n_used;
756 }
757 else
758 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100759 off = before + after + padding + n_used;
760 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100761 }
762 if (n_attr != NULL)
763 {
764 if (n_used < *n_extra && wp->w_p_wrap)
765 {
766 char_u *lp = l + off - 1;
767
768 if (has_mbyte)
769 {
h-east4c42c7e2023-04-17 21:44:57 +0100770 char_u buf[MB_MAXBYTES + 1];
771 char_u *cp = buf;
772
773 // change the last character to '…', converted to the
774 // current 'encoding'
775 STRCPY(buf, "…");
776 if (!enc_utf8)
777 {
778 vimconv_T vc;
779
780 vc.vc_type = CONV_NONE;
781 convert_setup(&vc, (char_u *)"utf-8", p_enc);
782 if (vc.vc_type != CONV_NONE)
783 {
784 cp = string_convert(&vc, buf, NULL);
785 if (cp == NULL)
786 {
787 // when conversion fails use '>'
788 cp = buf;
789 STRCPY(buf, ">");
790 }
791 convert_setup(&vc, NULL, NULL);
792 }
793 }
794
795 lp -= (*mb_ptr2cells)(cp) - 1;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100796 lp -= (*mb_head_off)(l, lp);
h-east4c42c7e2023-04-17 21:44:57 +0100797 STRCPY(lp, cp);
Bram Moolenaar13845c42022-10-09 15:26:03 +0100798 n_used = lp - l + 3 - before - padding;
h-east4c42c7e2023-04-17 21:44:57 +0100799 if (cp != buf)
800 vim_free(cp);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100801 }
802 else
803 // change last character to '>'
804 *lp = '>';
805 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100806 else if (after > 0)
807 {
808 vim_memset(l + off, ' ', after);
809 l[off + after] = NUL;
810 }
811
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100812 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100813 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100814 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000815 // n_attr_skip will not be decremented before draw_state is
816 // WL_LINE
Christian Brabandtf1cc4d52023-08-12 00:14:14 +0200817 *n_attr_skip = before + (padding > 0 ? padding : 0);
zeertzjq9352c282024-03-14 18:16:56 +0100818 *n_attr -= *n_attr_skip;
819 if (above)
820 *n_attr -= after;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100821 }
822 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100823 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100824
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100825 if (n_attr == NULL)
826 return cells;
827 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200828}
829#endif
830
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100831/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100832 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100833 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
834 * when 'showbreak' is not set.
zeertzjqd0c1b772024-03-16 15:03:33 +0100835 * When "clear_end" is TRUE clear until the end of the screen line.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100836 */
837 static void
zeertzjqd0c1b772024-03-16 15:03:33 +0100838wlv_screen_line(win_T *wp, winlinevars_T *wlv, int clear_end)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100839{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100840 if (wlv->row == 0 && wp->w_skipcol > 0
841#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100842 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100843 && *get_showbreak_value(wp) == NUL
844#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100845 // do not overwrite the 'listchars' "precedes" text with "<<<"
846 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100847 {
848 int off = (int)(current_ScreenLine - ScreenLines);
zeertzjqecb87dd2023-06-03 19:45:06 +0100849 int max_off = off + screen_Columns;
Bram Moolenaareb4de622022-10-15 13:42:17 +0100850 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100851
Bram Moolenaareb4de622022-10-15 13:42:17 +0100852 if (wp->w_p_nu && wp->w_p_rnu)
853 // Do not overwrite the line number, change "123 text" to
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100854 // "123<<<xt".
Bram Moolenaareb4de622022-10-15 13:42:17 +0100855 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
856 {
857 ++off;
858 ++skip;
859 }
860
861 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100862 {
zeertzjqecb87dd2023-06-03 19:45:06 +0100863 if ((*mb_off2cells)(off, max_off) > 1)
864 // When the first half of a double-width character is
865 // overwritten, change the second half to a space.
866 ScreenLines[off + 1] = ' ';
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100867 ScreenLines[off] = '<';
868 if (enc_utf8)
869 ScreenLinesUC[off] = 0;
870 ScreenAttrs[off] = HL_ATTR(HLF_AT);
871 ++off;
872 }
873 }
874
875 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
zeertzjqd0c1b772024-03-16 15:03:33 +0100876 clear_end ? wp->w_width : -wp->w_width,
877 wlv->vcol - 1, wlv->screen_line_flags);
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100878}
879
880/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100881 * Called when finished with the line: draw the screen line and handle any
882 * highlighting until the right of the window.
883 */
884 static void
885draw_screen_line(win_T *wp, winlinevars_T *wlv)
886{
887#ifdef FEAT_SYN_HL
888 long v;
zeertzjqf6272552024-03-17 10:01:47 +0100889 int wcol;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100890
891 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
892 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100893 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100894 else
895 v = wp->w_leftcol;
896
zeertzjqf6272552024-03-17 10:01:47 +0100897 wcol =
898# ifdef FEAT_RIGHTLEFT
899 wp->w_p_rl ? wp->w_width - wlv->col - 1 :
900# endif
901 wlv->col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100902 // check if line ends before left margin
zeertzjqf6272552024-03-17 10:01:47 +0100903 if (wlv->vcol < v + wcol - win_col_off(wp))
904 wlv->vcol = v + wcol - win_col_off(wp);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100905# ifdef FEAT_CONCEAL
906 // Get rid of the boguscols now, we want to draw until the right
907 // edge for 'cursorcolumn'.
908 wlv->col -= wlv->boguscols;
909 wlv->boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000910# define VCOL_HLC (wlv->vcol - wlv->vcol_off_co - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100911# else
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000912# define VCOL_HLC (wlv->vcol - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100913# endif
914
915 if (wlv->draw_color_col)
916 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
917
918 if (((wp->w_p_cuc
919 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
920 && (int)wp->w_virtcol <
921 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
922 && wlv->lnum != wp->w_cursor.lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000923 || wlv->draw_color_col
924# ifdef LINE_ATTR
925 || wlv->line_attr != 0
926# endif
zeertzjqf6272552024-03-17 10:01:47 +0100927 || wlv->win_attr != 0))
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100928 {
929 int rightmost_vcol = 0;
930 int i;
931
932 if (wp->w_p_cuc)
933 rightmost_vcol = wp->w_virtcol;
934 if (wlv->draw_color_col)
935 // determine rightmost colorcolumn to possibly draw
936 for (i = 0; wlv->color_cols[i] >= 0; ++i)
937 if (rightmost_vcol < wlv->color_cols[i])
938 rightmost_vcol = wlv->color_cols[i];
939
zeertzjqf6272552024-03-17 10:01:47 +0100940 while (
941# ifdef FEAT_RIGHTLEFT
942 wp->w_p_rl ? (wlv->col >= 0) :
943# endif
944 (wlv->col < wp->w_width))
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100945 {
946 ScreenLines[wlv->off] = ' ';
947 if (enc_utf8)
948 ScreenLinesUC[wlv->off] = 0;
zeertzjqf6272552024-03-17 10:01:47 +0100949
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100950 if (wlv->draw_color_col)
951 wlv->draw_color_col = advance_color_col(
952 VCOL_HLC, &wlv->color_cols);
953
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000954 int attr = wlv->win_attr;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000955# ifdef LINE_ATTR
zeertzjq9352c282024-03-14 18:16:56 +0100956 if (wlv->line_attr != 0)
957 attr = hl_combine_attr(attr, wlv->line_attr);
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000958# endif
zeertzjq9352c282024-03-14 18:16:56 +0100959 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
960 && wlv->lnum != wp->w_cursor.lnum)
961 attr = hl_combine_attr(attr, HL_ATTR(HLF_CUC));
962 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
963 attr = hl_combine_attr(attr, HL_ATTR(HLF_MC));
zeertzjqf6272552024-03-17 10:01:47 +0100964 ScreenAttrs[wlv->off] = attr;
965 ScreenCols[wlv->off] = wlv->vcol;
966# ifdef FEAT_RIGHTLEFT
967 if (wp->w_p_rl)
968 {
969 --wlv->off;
970 --wlv->col;
971 }
972 else
973# endif
974 {
975 ++wlv->off;
976 ++wlv->col;
977 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100978
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000979 if (VCOL_HLC >= rightmost_vcol
980# ifdef LINE_ATTR
981 && wlv->line_attr == 0
982# endif
983 && wlv->win_attr == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100984 break;
985
986 ++wlv->vcol;
987 }
988 }
989#endif
990
zeertzjqd0c1b772024-03-16 15:03:33 +0100991 // Set increasing virtual columns in ScreenCols[] to set correct curswant
992 // (or "coladd" for 'virtualedit') when clicking after end of line.
993 wlv->screen_line_flags |= SLF_INC_VCOL;
994 wlv_screen_line(wp, wlv, TRUE);
995 wlv->screen_line_flags &= ~SLF_INC_VCOL;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100996 ++wlv->row;
997 ++wlv->screen_row;
998}
999#undef VCOL_HLC
1000
1001/*
1002 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001003 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001004 */
1005 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +01001006win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001007{
1008 wlv->col = 0;
1009 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02001010#ifdef FEAT_LINEBREAK
1011 wlv->need_lbr = FALSE;
1012#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001013
1014#ifdef FEAT_RIGHTLEFT
1015 if (wp->w_p_rl)
1016 {
1017 // Rightleft window: process the text in the normal direction, but put
1018 // it in current_ScreenLine[] from right to left. Start at the
1019 // rightmost column of the window.
1020 wlv->col = wp->w_width - 1;
1021 wlv->off += wlv->col;
1022 wlv->screen_line_flags |= SLF_RIGHTLEFT;
1023 }
1024#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001025 if (save_extra)
1026 {
1027 // reset the drawing state for the start of a wrapped line
1028 wlv->draw_state = WL_START;
1029 wlv->saved_n_extra = wlv->n_extra;
1030 wlv->saved_p_extra = wlv->p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +01001031 vim_free(wlv->saved_p_extra_free);
1032 wlv->saved_p_extra_free = wlv->p_extra_free;
1033 wlv->p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001034 wlv->saved_extra_attr = wlv->extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001035 wlv->saved_n_attr_skip = wlv->n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001036 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001037 wlv->saved_c_extra = wlv->c_extra;
1038 wlv->saved_c_final = wlv->c_final;
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02001039#ifdef FEAT_LINEBREAK
1040 wlv->need_lbr = TRUE;
1041#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001042#ifdef FEAT_SYN_HL
1043 if (!(wlv->cul_screenline
1044# ifdef FEAT_DIFF
1045 && wlv->diff_hlf == (hlf_T)0
1046# endif
1047 ))
1048 wlv->saved_char_attr = wlv->char_attr;
1049 else
1050#endif
1051 wlv->saved_char_attr = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001052
1053 // these are not used until restored in win_line_continue()
Bram Moolenaar1306b362022-08-06 15:59:06 +01001054 wlv->n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001055 wlv->n_attr_skip = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001056 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001057}
1058
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001059/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001060 * Called when wlv->draw_state is set to WL_LINE.
1061 */
1062 static void
1063win_line_continue(winlinevars_T *wlv)
1064{
1065 if (wlv->saved_n_extra > 0)
1066 {
1067 // Continue item from end of wrapped line.
1068 wlv->n_extra = wlv->saved_n_extra;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001069 wlv->saved_n_extra = 0;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001070 wlv->c_extra = wlv->saved_c_extra;
1071 wlv->c_final = wlv->saved_c_final;
1072 wlv->p_extra = wlv->saved_p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +01001073 vim_free(wlv->p_extra_free);
1074 wlv->p_extra_free = wlv->saved_p_extra_free;
1075 wlv->saved_p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001076 wlv->extra_attr = wlv->saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001077 wlv->n_attr_skip = wlv->saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001078 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001079 wlv->char_attr = wlv->saved_char_attr;
1080 }
1081 else
1082 wlv->char_attr = wlv->win_attr;
1083}
1084
zeertzjqb7acea12022-12-12 13:20:43 +00001085#ifdef FEAT_SYN_HL
1086 static void
1087apply_cursorline_highlight(
1088 winlinevars_T *wlv,
1089 int sign_present UNUSED)
1090{
1091 wlv->cul_attr = HL_ATTR(HLF_CUL);
1092# ifdef FEAT_SIGNS
1093 // Combine the 'cursorline' and sign highlighting, depending on
1094 // the sign priority.
1095 if (sign_present && wlv->sattr.sat_linehl > 0)
1096 {
1097 if (wlv->sattr.sat_priority >= 100)
1098 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1099 else
1100 wlv->line_attr = hl_combine_attr(wlv->line_attr, wlv->cul_attr);
1101 }
1102 else
1103# endif
1104# if defined(FEAT_QUICKFIX)
1105 // let the line attribute overrule 'cursorline', otherwise
1106 // it disappears when both have background set;
1107 // 'cursorline' can use underline or bold to make it show
1108 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1109# else
1110 wlv->line_attr = wlv->cul_attr;
1111# endif
1112}
1113#endif
1114
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001115/*
Luuk van Baal30805a12023-05-27 22:22:10 +01001116 * Display line "lnum" of window "wp" on the screen.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001117 * Start at row "startrow", stop when "endrow" is reached.
zeertzjqebfd8562024-02-06 10:59:03 +01001118 * When only updating the number column, "number_only" is set to the height of
1119 * the line, otherwise it is set to 0.
Luuk van Baal30805a12023-05-27 22:22:10 +01001120 * "spv" is used to store information for spell checking, kept between
1121 * sequential calls for the same window.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001122 * wp->w_virtcol needs to be valid.
1123 *
1124 * Return the number of last row the line occupies.
1125 */
1126 int
1127win_line(
1128 win_T *wp,
1129 linenr_T lnum,
1130 int startrow,
1131 int endrow,
Luuk van Baal30805a12023-05-27 22:22:10 +01001132 int number_only,
1133 spellvars_T *spv UNUSED)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001134{
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001135 winlinevars_T wlv; // variables passed between functions
1136
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001137 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001138 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001139 char_u *line; // current line
1140 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001141
Bram Moolenaar1306b362022-08-06 15:59:06 +01001142#ifdef FEAT_PROP_POPUP
1143 char_u *p_extra_free2 = NULL; // another p_extra to be freed
1144#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001145#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001146 int in_linebreak = FALSE; // n_extra set for showing linebreak
1147#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01001148 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001149 int lcs_prec_todo = wp->w_lcs_chars.prec;
1150 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001151
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001152 int n_attr = 0; // chars with special attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001153 int saved_attr2 = 0; // char_attr saved for n_attr
1154 int n_attr3 = 0; // chars with overruling special attr
1155 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001156
zeertzjqb557f482023-08-22 22:07:34 +02001157 int skip_cells = 0; // nr of cells to skip for w_leftcol or
1158 // w_skipcol or concealing
1159 int skipped_cells = 0; // nr of skipped cells for virtual text
1160 // to be added to wlv.vcol later
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001161 int fromcol_prev = -2; // start of inverting after cursor
1162 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001163 int lnum_in_visual_area = FALSE;
1164 pos_T pos;
1165 long v;
1166
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001167 int attr_pri = FALSE; // char_attr has priority
1168 int area_highlighting = FALSE; // Visual or incsearch highlighting
1169 // in this line
1170 int vi_attr = 0; // attributes for Visual and incsearch
1171 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001172 int area_attr = 0; // attributes desired by highlighting
1173 int search_attr = 0; // attributes desired by 'hlsearch'
1174#ifdef FEAT_SYN_HL
1175 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1176 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001177 int prev_syntax_col = -1; // column of prev_syntax_attr
1178 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001179 int has_syntax = FALSE; // this buffer has syntax highl.
1180 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001181#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001182#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001183 int did_line = FALSE; // set to TRUE when line text done
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001184 int text_prop_count;
zeertzjq4e26a9a2023-12-03 17:50:47 +01001185 int last_textprop_text_idx = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001186 int text_prop_next = 0; // next text property to use
1187 textprop_T *text_props = NULL;
1188 int *text_prop_idxs = NULL;
1189 int text_props_active = 0;
1190 proptype_T *text_prop_type = NULL;
1191 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001192 int text_prop_attr_comb = 0; // text_prop_attr combined with
1193 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001194 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001195 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001196 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001197 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001198 int saved_search_attr = 0; // search_attr to be used when n_extra
1199 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001200 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001201 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001202#endif
1203#ifdef FEAT_SPELL
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001204 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001205# define SPWORDLEN 150
1206 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1207 int nextlinecol = 0; // column where nextline[] starts
1208 int nextline_idx = 0; // index in nextline[] where next line
1209 // starts
1210 int spell_attr = 0; // attributes desired by spelling
1211 int word_end = 0; // last byte with same spell_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001212 int cur_checked_col = 0; // checked column for current line
1213#endif
1214 int extra_check = 0; // has extra highlighting
1215 int multi_attr = 0; // attributes desired by multibyte
1216 int mb_l = 1; // multi-byte byte length
1217 int mb_c = 0; // decoded multi-byte character
1218 int mb_utf8 = FALSE; // screen char is UTF-8 char
1219 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001220#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001221 int change_start = MAXCOL; // first col of changed area
1222 int change_end = -1; // last col of changed area
1223#endif
1224 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001225 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001226 int in_multispace = FALSE; // in multiple consecutive spaces
1227 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001228#ifdef LINE_ATTR
Bram Moolenaarbf915842022-08-06 22:38:02 +01001229 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001230#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001231 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001232 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001233#ifdef FEAT_ARABIC
1234 int prev_c = 0; // previous Arabic character
1235 int prev_c1 = 0; // first composing char for prev_c
1236#endif
1237#if defined(LINE_ATTR)
1238 int did_line_attr = 0;
1239#endif
1240#ifdef FEAT_TERMINAL
1241 int get_term_attr = FALSE;
1242#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001243
Martin Tournoijba43e762022-10-13 22:12:15 +01001244#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001245 // margin columns for the screen line, needed for when 'cursorlineopt'
1246 // contains "screenline"
1247 int left_curline_col = 0;
1248 int right_curline_col = 0;
1249#endif
1250
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001251#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1252 int feedback_col = 0;
1253 int feedback_old_attr = -1;
1254#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001255
1256#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1257 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001258#endif
1259#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001260 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001261#endif
1262#ifdef FEAT_CONCEAL
1263 int syntax_flags = 0;
1264 int syntax_seqnr = 0;
1265 int prev_syntax_id = 0;
1266 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1267 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001268 int did_wcol = FALSE;
1269 int old_boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001270# define VCOL_HLC (wlv.vcol - wlv.vcol_off_co - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001271# define FIX_FOR_BOGUSCOLS \
1272 { \
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001273 wlv.n_extra += wlv.vcol_off_co; \
1274 wlv.vcol -= wlv.vcol_off_co; \
1275 wlv.vcol_off_co = 0; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001276 wlv.col -= wlv.boguscols; \
1277 old_boguscols = wlv.boguscols; \
1278 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001279 }
1280#else
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001281# define VCOL_HLC (wlv.vcol - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001282#endif
1283
1284 if (startrow > endrow) // past the end already!
1285 return startrow;
1286
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001287 CLEAR_FIELD(wlv);
1288
1289 wlv.lnum = lnum;
1290 wlv.startrow = startrow;
1291 wlv.row = startrow;
1292 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001293 wlv.fromcol = -10;
1294 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001295#ifdef FEAT_LINEBREAK
1296 wlv.vcol_sbr = -1;
1297#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001298
zeertzjqebfd8562024-02-06 10:59:03 +01001299 if (number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001300 {
1301 // To speed up the loop below, set extra_check when there is linebreak,
1302 // trailing white space and/or syntax processing to be done.
1303#ifdef FEAT_LINEBREAK
1304 extra_check = wp->w_p_lbr;
1305#endif
1306#ifdef FEAT_SYN_HL
1307 if (syntax_present(wp) && !wp->w_s->b_syn_error
1308# ifdef SYN_TIME_LIMIT
1309 && !wp->w_s->b_syn_slow
1310# endif
1311 )
1312 {
1313 // Prepare for syntax highlighting in this line. When there is an
1314 // error, stop syntax highlighting.
1315 save_did_emsg = did_emsg;
1316 did_emsg = FALSE;
1317 syntax_start(wp, lnum);
1318 if (did_emsg)
1319 wp->w_s->b_syn_error = TRUE;
1320 else
1321 {
1322 did_emsg = save_did_emsg;
1323#ifdef SYN_TIME_LIMIT
1324 if (!wp->w_s->b_syn_slow)
1325#endif
1326 {
1327 has_syntax = TRUE;
1328 extra_check = TRUE;
1329 }
1330 }
1331 }
1332
1333 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001334 wlv.color_cols = wp->w_p_cc_cols;
1335 if (wlv.color_cols != NULL)
1336 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001337#endif
1338
1339#ifdef FEAT_TERMINAL
1340 if (term_show_buffer(wp->w_buffer))
1341 {
1342 extra_check = TRUE;
1343 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001344 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001345 }
1346#endif
1347
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001348 // handle Visual active in this window
1349 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1350 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001351 pos_T *top, *bot;
1352
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001353 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1354 {
1355 // Visual is after curwin->w_cursor
1356 top = &curwin->w_cursor;
1357 bot = &VIsual;
1358 }
1359 else
1360 {
1361 // Visual is before curwin->w_cursor
1362 top = &VIsual;
1363 bot = &curwin->w_cursor;
1364 }
1365 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1366 if (VIsual_mode == Ctrl_V)
1367 {
1368 // block mode
1369 if (lnum_in_visual_area)
1370 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001371 wlv.fromcol = wp->w_old_cursor_fcol;
1372 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001373 }
1374 }
1375 else
1376 {
1377 // non-block mode
1378 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001379 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001380 else if (lnum == top->lnum)
1381 {
1382 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001383 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001384 else
1385 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001386 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001387 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001388 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001389 }
1390 }
1391 if (VIsual_mode != 'V' && lnum == bot->lnum)
1392 {
1393 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1394 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001395 wlv.fromcol = -10;
1396 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001397 }
1398 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001399 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001400 else
1401 {
1402 pos = *bot;
1403 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001404 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1405 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001406 else
1407 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001408 getvvcol(wp, &pos, NULL, NULL,
1409 (colnr_T *)&wlv.tocol);
1410 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001411 }
1412 }
1413 }
1414 }
1415
1416 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001417 if (!highlight_match && lnum == curwin->w_cursor.lnum
1418 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001419#ifdef FEAT_GUI
1420 && !gui.in_use
1421#endif
1422 )
1423 noinvcur = TRUE;
1424
1425 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001426 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001427 {
1428 area_highlighting = TRUE;
1429 vi_attr = HL_ATTR(HLF_V);
1430#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1431 if ((clip_star.available && !clip_star.owned
1432 && clip_isautosel_star())
1433 || (clip_plus.available && !clip_plus.owned
1434 && clip_isautosel_plus()))
1435 vi_attr = HL_ATTR(HLF_VNC);
1436#endif
1437 }
1438 }
1439
1440 // handle 'incsearch' and ":s///c" highlighting
1441 else if (highlight_match
1442 && wp == curwin
1443 && lnum >= curwin->w_cursor.lnum
1444 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1445 {
1446 if (lnum == curwin->w_cursor.lnum)
1447 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001448 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001449 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001450 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001451 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1452 {
1453 pos.lnum = lnum;
1454 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001455 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001456 }
1457 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001458 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001459 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001460 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1461 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001462 area_highlighting = TRUE;
1463 vi_attr = HL_ATTR(HLF_I);
1464 }
1465 }
1466
1467#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001468 wlv.filler_lines = diff_check(wp, lnum);
1469 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001470 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001471 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001472 {
1473 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001474 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001475 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001476 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001477 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001478 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001479 }
1480 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001481 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001482 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001483 area_highlighting = TRUE;
1484 }
1485 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001486 wlv.filler_lines = wp->w_topfill;
1487 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001488#endif
1489
1490#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001491 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001492 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001493 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001494#endif
1495
1496#ifdef LINE_ATTR
1497# ifdef FEAT_SIGNS
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001498 // If this line has a sign with line highlighting set wlv.line_attr.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001499 if (sign_present)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001500 wlv.line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001501# endif
1502# if defined(FEAT_QUICKFIX)
1503 // Highlight the current line in the quickfix window.
1504 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001505 wlv.line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001506# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001507 if (wlv.line_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001508 area_highlighting = TRUE;
1509#endif
1510
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001511#ifdef FEAT_SPELL
zeertzjqebfd8562024-02-06 10:59:03 +01001512 if (spv->spv_has_spell && number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001513 {
Luuk van Baal30805a12023-05-27 22:22:10 +01001514 // Prepare for spell checking.
1515 extra_check = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001516
Luuk van Baal30805a12023-05-27 22:22:10 +01001517 // When a word wrapped from the previous line the start of the
1518 // current line is valid.
1519 if (lnum == spv->spv_checked_lnum)
1520 cur_checked_col = spv->spv_checked_col;
Luuk van Baale84c7732023-05-31 18:57:36 +01001521 // Previous line was not spell checked, check for capital. This happens
1522 // for the first line in an updated region or after a closed fold.
1523 if (spv->spv_capcol_lnum == 0 && check_need_cap(wp, lnum, 0))
1524 spv->spv_cap_col = 0;
1525 else if (lnum != spv->spv_capcol_lnum)
Luuk van Baal30805a12023-05-27 22:22:10 +01001526 spv->spv_cap_col = -1;
1527 spv->spv_checked_lnum = 0;
1528
Luuk van Baal30805a12023-05-27 22:22:10 +01001529 // Get the start of the next line, so that words that wrap to the
1530 // next line are found too: "et<line-break>al.".
1531 // Trick: skip a few chars for C/shell/Vim comments
1532 nextline[SPWORDLEN] = NUL;
1533 if (lnum < wp->w_buffer->b_ml.ml_line_count)
Luuk van Baale84c7732023-05-31 18:57:36 +01001534 {
1535 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1536 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1537 }
1538 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1539
1540 // If current line is empty, check first word in next line for capital.
1541 ptr = skipwhite(line);
1542 if (*ptr == NUL)
1543 {
1544 spv->spv_cap_col = 0;
1545 spv->spv_capcol_lnum = lnum + 1;
1546 }
1547 // For checking first word with a capital skip white space.
1548 else if (spv->spv_cap_col == 0)
1549 spv->spv_cap_col = ptr - line;
1550
Luuk van Baal30805a12023-05-27 22:22:10 +01001551 // Copy the end of the current line into nextline[].
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001552 if (nextline[SPWORDLEN] == NUL)
1553 {
1554 // No next line or it is empty.
1555 nextlinecol = MAXCOL;
1556 nextline_idx = 0;
1557 }
1558 else
1559 {
zeertzjq94b7c322024-03-12 21:50:32 +01001560 v = ml_get_buf_len(wp->w_buffer, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001561 if (v < SPWORDLEN)
1562 {
1563 // Short line, use it completely and append the start of the
1564 // next line.
1565 nextlinecol = 0;
1566 mch_memmove(nextline, line, (size_t)v);
1567 STRMOVE(nextline + v, nextline + SPWORDLEN);
1568 nextline_idx = v + 1;
1569 }
1570 else
1571 {
1572 // Long line, use only the last SPWORDLEN bytes.
1573 nextlinecol = v - SPWORDLEN;
1574 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1575 nextline_idx = SPWORDLEN + 1;
1576 }
1577 }
1578 }
1579#endif
1580
Luuk van Baale84c7732023-05-31 18:57:36 +01001581 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1582 ptr = line;
1583
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001584 if (wp->w_p_list)
1585 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001586 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001587 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001588 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001589 || wp->w_lcs_chars.trail
1590 || wp->w_lcs_chars.lead
1591 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001592 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001593
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001594 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001595 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001596 {
zeertzjq94b7c322024-03-12 21:50:32 +01001597 trailcol = ml_get_buf_len(wp->w_buffer, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001598 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1599 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001600 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001601 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001602 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001603 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001604 {
1605 leadcol = 0;
1606 while (VIM_ISWHITE(ptr[leadcol]))
1607 ++leadcol;
1608 if (ptr[leadcol] == NUL)
1609 // in a line full of spaces all of them are treated as trailing
1610 leadcol = (colnr_T)0;
1611 else
1612 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001613 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001614 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001615 }
1616
Bram Moolenaard7657e92022-09-20 18:59:30 +01001617 wlv.wcr_attr = get_wcr_attr(wp);
1618 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001619 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001620 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001621 area_highlighting = TRUE;
1622 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001623
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001624 // When w_skipcol is non-zero and there is virtual text above the actual
1625 // text, then this much of the virtual text is skipped.
1626 int skipcol_in_text_prop_above = 0;
1627
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001628#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001629 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001630 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001631
1632 char_u *prop_start;
1633 text_prop_count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE);
1634 if (text_prop_count > 0)
1635 {
1636 // Make a copy of the properties, so that they are properly
1637 // aligned.
1638 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1639 if (text_props != NULL)
1640 mch_memmove(text_props, prop_start,
1641 text_prop_count * sizeof(textprop_T));
1642
1643 // Allocate an array for the indexes.
1644 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1645 if (text_prop_idxs == NULL)
1646 VIM_CLEAR(text_props);
1647
1648 if (text_props != NULL)
1649 {
1650 area_highlighting = TRUE;
1651 extra_check = TRUE;
1652
zeertzjq4e26a9a2023-12-03 17:50:47 +01001653 /* Find the last text property that inserts text. */
1654 for (int i = 0; i < text_prop_count; ++i)
1655 if (text_props[i].tp_id < 0)
1656 last_textprop_text_idx = i;
1657
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001658 // Text props "above" move the line number down to where the text
1659 // is. Only count the ones that are visible, not those that are
1660 // skipped because of w_skipcol.
1661 int text_width = wp->w_width - win_col_off(wp);
1662 for (int i = text_prop_count - 1; i >= 0; --i)
1663 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1664 {
1665 if (lnum == wp->w_topline
1666 && wp->w_skipcol - skipcol_in_text_prop_above
1667 >= text_width)
1668 {
1669 // This virtual text above is skipped, remove it from
1670 // the array.
1671 skipcol_in_text_prop_above += text_width;
1672 for (int j = i + 1; j < text_prop_count; ++j)
1673 text_props[j - 1] = text_props[j];
1674 ++i;
1675 --text_prop_count;
1676 }
1677 else
1678 ++wlv.text_prop_above_count;
1679 }
1680 }
1681 }
Bram Moolenaara572b932023-02-19 14:34:37 +00001682
zeertzjqebfd8562024-02-06 10:59:03 +01001683 if (number_only > 0)
Bram Moolenaara572b932023-02-19 14:34:37 +00001684 {
1685 // skip over rows only used for virtual text above
1686 wlv.row += wlv.text_prop_above_count;
1687 if (wlv.row > endrow)
1688 return wlv.row;
1689 wlv.screen_row += wlv.text_prop_above_count;
1690 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001691#endif
1692
zeertzjqce53e3e2023-09-01 18:49:30 +02001693#if defined(FEAT_LINEBREAK) || defined(FEAT_PROP_POPUP)
1694 colnr_T vcol_first_char = 0;
zeertzjqebfd8562024-02-06 10:59:03 +01001695 if (wp->w_p_lbr && number_only == 0)
zeertzjqce53e3e2023-09-01 18:49:30 +02001696 {
1697 chartabsize_T cts;
1698 init_chartabsize_arg(&cts, wp, lnum, 0, line, line);
1699 (void)win_lbr_chartabsize(&cts, NULL);
1700 vcol_first_char = cts.cts_first_char;
1701 clear_chartabsize_arg(&cts);
1702 }
1703#endif
1704
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001705 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1706 // first character to be displayed.
1707 if (wp->w_p_wrap)
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001708 v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001709 else
1710 v = wp->w_leftcol;
zeertzjqebfd8562024-02-06 10:59:03 +01001711 if (v > 0 && number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001712 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001713 char_u *prev_ptr = ptr;
1714 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001715 int charsize = 0;
zeertzjqb557f482023-08-22 22:07:34 +02001716 int head = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001717
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001718 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
zeertzjqb557f482023-08-22 22:07:34 +02001719 cts.cts_max_head_vcol = v;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001720 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001721 {
zeertzjqb557f482023-08-22 22:07:34 +02001722 head = 0;
1723 charsize = win_lbr_chartabsize(&cts, &head);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001724 cts.cts_vcol += charsize;
1725 prev_ptr = cts.cts_ptr;
1726 MB_PTR_ADV(cts.cts_ptr);
zeertzjqabc80812023-09-24 23:32:18 +02001727 if (wp->w_p_list)
1728 {
1729 in_multispace = *prev_ptr == ' ' && (*cts.cts_ptr == ' '
1730 || (prev_ptr > line && prev_ptr[-1] == ' '));
1731 if (!in_multispace)
1732 multispace_pos = 0;
1733 else if (cts.cts_ptr >= line + leadcol
1734 && wp->w_lcs_chars.multispace != NULL)
1735 {
1736 ++multispace_pos;
1737 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
1738 multispace_pos = 0;
1739 }
1740 else if (cts.cts_ptr < line + leadcol
1741 && wp->w_lcs_chars.leadmultispace != NULL)
1742 {
1743 ++multispace_pos;
1744 if (wp->w_lcs_chars.leadmultispace[multispace_pos] == NUL)
1745 multispace_pos = 0;
1746 }
1747 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001748 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001749 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001750 ptr = cts.cts_ptr;
1751 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001752
1753 // When:
1754 // - 'cuc' is set, or
1755 // - 'colorcolumn' is set, or
1756 // - 'virtualedit' is set, or
1757 // - the visual mode is active,
1758 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001759 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001760#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001761 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001762#endif
1763 virtual_active() ||
1764 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001765 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001766
1767 // Handle a character that's not completely on the screen: Put ptr at
1768 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001769 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001770 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001771 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001772 ptr = prev_ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001773 }
zeertzjqb557f482023-08-22 22:07:34 +02001774 if (v > wlv.vcol)
1775 skip_cells = v - wlv.vcol - head;
Bram Moolenaarcd105412022-10-10 19:50:42 +01001776
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001777 // Adjust for when the inverted text is before the screen,
1778 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001779 if (wlv.tocol <= wlv.vcol)
1780 wlv.fromcol = 0;
1781 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1782 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001783
1784#ifdef FEAT_LINEBREAK
1785 // When w_skipcol is non-zero, first line needs 'showbreak'
1786 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001787 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001788#endif
1789#ifdef FEAT_SPELL
1790 // When spell checking a word we need to figure out the start of the
1791 // word and if it's badly spelled or not.
Luuk van Baal30805a12023-05-27 22:22:10 +01001792 if (spv->spv_has_spell)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001793 {
1794 int len;
1795 colnr_T linecol = (colnr_T)(ptr - line);
1796 hlf_T spell_hlf = HLF_COUNT;
1797
1798 pos = wp->w_cursor;
1799 wp->w_cursor.lnum = lnum;
1800 wp->w_cursor.col = linecol;
1801 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1802
1803 // spell_move_to() may call ml_get() and make "line" invalid
1804 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1805 ptr = line + linecol;
1806
1807 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1808 {
1809 // no bad word found at line start, don't check until end of a
1810 // word
1811 spell_hlf = HLF_COUNT;
1812 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1813 }
1814 else
1815 {
1816 // bad word found, use attributes until end of word
1817 word_end = wp->w_cursor.col + len + 1;
1818
1819 // Turn index into actual attributes.
1820 if (spell_hlf != HLF_COUNT)
1821 spell_attr = highlight_attr[spell_hlf];
1822 }
1823 wp->w_cursor = pos;
1824
1825# ifdef FEAT_SYN_HL
1826 // Need to restart syntax highlighting for this line.
1827 if (has_syntax)
1828 syntax_start(wp, lnum);
1829# endif
1830 }
1831#endif
1832 }
1833
1834 // Correct highlighting for cursor that can't be disabled.
1835 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001836 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001837 {
1838 if (noinvcur)
1839 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001840 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001841 {
1842 // highlighting starts at cursor, let it start just after the
1843 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001844 fromcol_prev = wlv.fromcol;
1845 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001846 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001847 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001848 // restart highlighting after the cursor
1849 fromcol_prev = wp->w_virtcol;
1850 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001851 if (wlv.fromcol >= wlv.tocol)
1852 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001853 }
1854
1855#ifdef FEAT_SEARCH_EXTRA
zeertzjqebfd8562024-02-06 10:59:03 +01001856 if (number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001857 {
1858 v = (long)(ptr - line);
1859 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1860 &line, &screen_search_hl,
1861 &search_attr);
1862 ptr = line + v; // "line" may have been updated
1863 }
1864#endif
1865
1866#ifdef FEAT_SYN_HL
1867 // Cursor line highlighting for 'cursorline' in the current window.
1868 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1869 {
1870 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001871 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001872 if (!(wp == curwin && VIsual_active)
1873 && wp->w_p_culopt_flags != CULOPT_NBR)
1874 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001875 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001876 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1877
zeertzjqb7acea12022-12-12 13:20:43 +00001878 // Only apply CursorLine highlight here when "screenline" is not
1879 // present in 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001880 if (!wlv.cul_screenline)
zeertzjqb7acea12022-12-12 13:20:43 +00001881 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001882 else
1883 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001884 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001885 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1886 }
1887 area_highlighting = TRUE;
1888 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001889 }
1890#endif
1891
Bram Moolenaar1306b362022-08-06 15:59:06 +01001892 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001893
1894 // Repeat for the whole displayed line.
1895 for (;;)
1896 {
1897#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001898 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001899#endif
1900#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001901 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001902#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001903
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001904 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001905 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001906 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001907#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001908 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001909 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001910 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001911 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001912 }
1913#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001914 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001915 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001916 wlv.draw_state = WL_CMDLINE;
Sean Dewar988f7432023-08-16 14:17:36 +01001917 if (wp == cmdwin_win)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001918 {
1919 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001920 wlv.n_extra = 1;
1921 wlv.c_extra = cmdwin_type;
1922 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001923 wlv.char_attr =
1924 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001925 }
1926 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001927#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001928 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001929 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001930 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001931 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001932 }
1933#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001934#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001935 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001936 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001937 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001938 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001939 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001940 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001941 }
1942#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001943 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001944 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001945 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001946 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001947 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001948 }
zeertzjqebfd8562024-02-06 10:59:03 +01001949
1950 // When only displaying the (relative) line number and that's done,
1951 // stop here.
1952 if (number_only > 0 && wlv.draw_state == WL_NR && wlv.n_extra == 0)
1953 {
zeertzjqd0c1b772024-03-16 15:03:33 +01001954 wlv_screen_line(wp, &wlv, FALSE);
zeertzjqebfd8562024-02-06 10:59:03 +01001955 // Need to update more screen lines if:
1956 // - LineNrAbove or LineNrBelow is used, or
1957 // - still drawing filler lines.
1958 if ((wlv.row + 1 - wlv.startrow < number_only
1959 && (HL_ATTR(HLF_LNA) != 0 || HL_ATTR(HLF_LNB) != 0))
1960#ifdef FEAT_DIFF
1961 || wlv.filler_todo > 0
1962#endif
1963 )
1964 {
1965 ++wlv.row;
1966 ++wlv.screen_row;
1967 if (wlv.row == endrow)
1968 break;
1969#ifdef FEAT_DIFF
1970 --wlv.filler_todo;
1971 if (wlv.filler_todo == 0 && wp->w_botfill)
1972 break;
1973#endif
1974 win_line_start(wp, &wlv, TRUE);
1975 continue;
1976 }
1977 else
1978 break;
1979 }
1980
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001981#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001982 // Check if 'breakindent' applies and show it.
1983 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1984 if (wlv.n_extra == 0)
1985 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001986#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001987#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001988 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001989 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001990 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001991 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001992 }
1993#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001994 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001995 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001996 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001997 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001998 }
1999 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002000
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002001#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002002 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002003 && wlv.vcol >= left_curline_col
2004 && wlv.vcol < right_curline_col)
zeertzjqb7acea12022-12-12 13:20:43 +00002005 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002006#endif
2007
2008 // When still displaying '$' of change command, stop at cursor.
zeertzjqebfd8562024-02-06 10:59:03 +01002009 if (dollar_vcol >= 0 && wp == curwin
2010 && lnum == wp->w_cursor.lnum
2011 && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002012 {
zeertzjqd0c1b772024-03-16 15:03:33 +01002013 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002014 // Pretend we have finished updating the window. Except when
2015 // 'cursorcolumn' is set.
2016#ifdef FEAT_SYN_HL
2017 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002018 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002019 else
2020#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002021 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002022 break;
2023 }
2024
Bram Moolenaar1306b362022-08-06 15:59:06 +01002025 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002026 {
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002027#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002028 if (text_props != NULL)
2029 {
2030 int pi;
2031 int bcol = (int)(ptr - line);
2032
Bram Moolenaar1306b362022-08-06 15:59:06 +01002033 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002034# ifdef FEAT_LINEBREAK
2035 && !in_linebreak
2036# endif
2037 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002038 --bcol; // still working on the previous char, e.g. Tab
2039
2040 // Check if any active property ends.
2041 for (pi = 0; pi < text_props_active; ++pi)
2042 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002043 int tpi = text_prop_idxs[pi];
2044 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002045
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002046 // An inline property ends when after the start column plus
2047 // length. An "above" property ends when used and n_extra
2048 // is zero.
2049 if ((tp->tp_col != MAXCOL
2050 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002051 {
2052 if (pi + 1 < text_props_active)
2053 mch_memmove(text_prop_idxs + pi,
2054 text_prop_idxs + pi + 1,
2055 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002056 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002057 --text_props_active;
2058 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002059# ifdef FEAT_LINEBREAK
2060 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002061 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002062 syntax_attr = 0;
2063# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002064 }
2065 }
2066
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002067# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01002068 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002069 // not on the next char yet, don't start another prop
2070 --bcol;
2071# endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002072 int display_text_first = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002073
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002074 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002075 // With 'nowrap' and not in the first screen line only "below"
2076 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002077 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002078 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002079 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002080 && (wp->w_p_wrap
2081 || wlv.row == startrow
2082 || (text_props[text_prop_next].tp_flags
2083 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002084 || (bcol == 0
2085 && (text_props[text_prop_next].tp_flags
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002086 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002087 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002088 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01002089 if (text_props[text_prop_next].tp_col == MAXCOL
2090 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002091 + text_props[text_prop_next].tp_len)
2092 text_prop_idxs[text_props_active++] = text_prop_next;
2093 ++text_prop_next;
2094 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002095
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002096 if (wlv.n_extra == 0 ||
2097 (!wlv.extra_for_textprop
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002098 && !(text_prop_type != NULL &&
2099 text_prop_flags & PT_FLAG_OVERRIDE)
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002100 ))
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002101 {
2102 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002103 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002104 text_prop_flags = 0;
2105 text_prop_type = NULL;
2106 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002107 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002108 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002109 if (text_props_active > 0 && wlv.n_extra == 0
2110 && !display_text_first)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002111 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01002112 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002113 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002114 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002115
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002116 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002117 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002118
2119 // Sort the properties on priority and/or starting last.
2120 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002121 sort_text_props(wp->w_buffer, text_props,
2122 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002123
2124 for (pi = 0; pi < text_props_active; ++pi)
2125 {
2126 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002127 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002128 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002129 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002130
Bram Moolenaarcd105412022-10-10 19:50:42 +01002131 // Only use a text property that can be displayed.
2132 // Skip "after" properties when wrap is off and at the
2133 // end of the window.
2134 if (pt != NULL
2135 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2136 && tp->tp_id != -MAXCOL
2137 && !(tp->tp_id < 0
2138 && !wp->w_p_wrap
2139 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2140 | TP_FLAG_ALIGN_ABOVE
2141 | TP_FLAG_ALIGN_BELOW)) == 0
2142 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002143 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002144 if (tp->tp_col == MAXCOL
2145 && *ptr == NUL
2146 && ((wp->w_p_list && lcs_eol_one > 0
2147 && (tp->tp_flags
2148 & TP_FLAG_ALIGN_ABOVE) == 0)
2149 || (ptr == line
2150 && !did_line
2151 && (tp->tp_flags
2152 & TP_FLAG_ALIGN_BELOW))))
2153 {
2154 // skip this prop, first display the '$' after
2155 // the line or display an empty line
2156 text_prop_follows = TRUE;
2157 if (used_tpi < 0)
2158 display_text_first = TRUE;
2159 continue;
2160 }
2161
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002162 if (pt->pt_hl_id > 0)
2163 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002164 text_prop_type = pt;
2165 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002166 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002167 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2168 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002169 text_prop_flags = pt->pt_flags;
2170 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002171 used_tpi = tpi;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002172 display_text_first = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002173 }
2174 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002175 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002176 && -text_prop_id
2177 <= wp->w_buffer->b_textprop_text.ga_len)
2178 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002179 textprop_T *tp = &text_props[used_tpi];
2180 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002181 ->b_textprop_text.ga_data)[
2182 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002183 int above = (tp->tp_flags
2184 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002185 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002186
2187 // reset the ID in the copy to avoid it being used
2188 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002189 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002190
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002191 if (p != NULL)
2192 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002193 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002194 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002195 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002196 & TP_FLAG_ALIGN_BELOW);
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002197 int wrap = tp->tp_col < MAXCOL
2198 || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002199 int padding = tp->tp_col == MAXCOL
2200 && tp->tp_len > 1
2201 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002202
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002203 // Insert virtual text before the current
2204 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002205 wlv.p_extra = p;
2206 wlv.c_extra = NUL;
2207 wlv.c_final = NUL;
2208 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002209 wlv.extra_for_textprop = TRUE;
zeertzjq6e940d92023-08-17 23:21:40 +02002210 wlv.start_extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002211 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2212 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002213 n_attr = mb_charlen(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002214 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002215 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002216 if (*ptr == NUL)
2217 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002218 text_prop_flags &= ~PT_FLAG_COMBINE;
zeertzjq6b9c2022023-09-11 20:01:17 +02002219# ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002220 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002221 {
2222 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002223 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002224 wlv.need_showbreak = FALSE;
2225 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002226 }
zeertzjq6b9c2022023-09-11 20:01:17 +02002227# endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002228 if ((right || above || below || !wrap
2229 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002230 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002231 char_u *prev_p_extra = wlv.p_extra;
2232 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002233
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002234 // Take care of padding, right-align and
2235 // truncation.
2236 // Shared with win_lbr_chartabsize(), must do
2237 // exactly the same.
2238 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002239 wlv.vcol,
zeertzjq6b9c2022023-09-11 20:01:17 +02002240# ifdef FEAT_RIGHTLEFT
2241 wp->w_p_rl
2242 ? wp->w_width - wlv.col - 1
2243 :
2244# endif
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002245 wlv.col,
2246 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002247 &n_attr, &wlv.n_attr_skip,
2248 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002249 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002250 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002251 // wlv.p_extra was allocated
2252 vim_free(p_extra_free2);
2253 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002254 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002255
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002256 if (above)
2257 wlv.vcol_off_tp = wlv.n_extra;
2258
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002259 if (lcs_eol_one < 0
2260 && wp->w_p_wrap
2261 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002262 + wlv.n_extra - 2 > wp->w_width)
2263 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002264 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002265
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002266 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002267 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002268 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002269 {
2270 draw_screen_line(wp, &wlv);
2271
2272 // When line got too long for screen break
2273 // here.
2274 if (wlv.row == endrow)
2275 {
2276 ++wlv.row;
2277 break;
2278 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002279 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002280 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002281 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002282 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002283 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002284
Bram Moolenaarcd105412022-10-10 19:50:42 +01002285 // If the text didn't reach until the first window
2286 // column we need to skip cells.
2287 if (skip_cells > 0)
2288 {
2289 if (wlv.n_extra > skip_cells)
2290 {
2291 wlv.n_extra -= skip_cells;
2292 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002293 wlv.n_attr_skip -= skip_cells;
2294 if (wlv.n_attr_skip < 0)
2295 wlv.n_attr_skip = 0;
zeertzjqb557f482023-08-22 22:07:34 +02002296 skipped_cells += skip_cells;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002297 skip_cells = 0;
2298 }
2299 else
2300 {
2301 // the whole text is left of the window, drop
2302 // it and advance to the next one
2303 skip_cells -= wlv.n_extra;
zeertzjqb557f482023-08-22 22:07:34 +02002304 skipped_cells += wlv.n_extra;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002305 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002306 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002307 bail_out = TRUE;
2308 }
2309 }
2310
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002311 // If another text prop follows the condition below at
2312 // the last window column must know.
Dylan Thacker-Smith83925be2024-02-21 21:03:10 +01002313 // If this is an "above" text prop and 'nowrap' then we
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002314 // must wrap anyway.
2315 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002316 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002317 && (wp->w_p_wrap
2318 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002319 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002320
2321 if (bail_out)
2322 // starting a new line for "below"
2323 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002324 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002325 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002326 else if (text_prop_next < text_prop_count
2327 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002328 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2329 || (!wp->w_p_wrap
2330 && wlv.col == wp->w_width - 1
2331 && (text_props[text_prop_next].tp_flags
2332 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002333 // When at last-but-one character and a text property
2334 // follows after it, we may need to flush the line after
2335 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002336 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002337 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002338 }
zeertzjq6e940d92023-08-17 23:21:40 +02002339
2340 if (wlv.start_extra_for_textprop)
2341 {
2342 wlv.start_extra_for_textprop = FALSE;
2343 // restore search_attr and area_attr when n_extra
2344 // is down to zero
2345 saved_search_attr = search_attr;
2346 saved_area_attr = area_attr;
2347 search_attr = 0;
2348 area_attr = 0;
2349 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002350#endif
2351
zeertzjq6e940d92023-08-17 23:21:40 +02002352 int *area_attr_p =
2353#ifdef FEAT_PROP_POPUP
2354 wlv.extra_for_textprop ? &saved_area_attr :
2355#endif
2356 &area_attr;
2357
2358 // handle Visual or match highlighting in this line
2359 if (wlv.vcol == wlv.fromcol
2360 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
2361 && ((wlv.n_extra == 0 && (*mb_ptr2cells)(ptr) > 1)
2362 || (wlv.n_extra > 0 && wlv.p_extra != NULL
2363 && (*mb_ptr2cells)(wlv.p_extra) > 1)))
2364 || ((int)vcol_prev == fromcol_prev
2365 && vcol_prev < wlv.vcol // not at margin
2366 && wlv.vcol < wlv.tocol))
2367 *area_attr_p = vi_attr; // start highlighting
2368 else if (*area_attr_p != 0
2369 && (wlv.vcol == wlv.tocol
2370 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
2371 *area_attr_p = 0; // stop highlighting
2372
zeertzjqe500ae82023-08-17 22:35:26 +02002373#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaare38fc862022-08-11 17:24:50 +01002374 if (wlv.n_extra == 0)
2375 {
2376 // Check for start/end of 'hlsearch' and other matches.
2377 // After end, check for start/end of next match.
2378 // When another match, have to check for start again.
2379 v = (long)(ptr - line);
2380 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2381 &screen_search_hl, &has_match_conc,
2382 &match_conc, did_line_attr, lcs_eol_one,
2383 &on_last_col);
2384 ptr = line + v; // "line" may have been changed
Bram Moolenaare38fc862022-08-11 17:24:50 +01002385
2386 // Do not allow a conceal over EOL otherwise EOL will be missed
2387 // and bad things happen.
2388 if (*ptr == NUL)
2389 has_match_conc = 0;
zeertzjqb25dbb32023-08-13 18:11:05 +02002390 }
zeertzjqe500ae82023-08-17 22:35:26 +02002391#endif
zeertzjqb25dbb32023-08-13 18:11:05 +02002392
Bram Moolenaare38fc862022-08-11 17:24:50 +01002393#ifdef FEAT_DIFF
2394 if (wlv.diff_hlf != (hlf_T)0)
2395 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002396 // When there is extra text (e.g. virtual text) it gets the
2397 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002398 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2399 && wlv.n_extra == 0)
2400 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002401 if (wlv.diff_hlf == HLF_TXD
2402 && ((ptr - line > change_end && wlv.n_extra == 0)
2403 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002404 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002405 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002406 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2407 && wp->w_p_culopt_flags != CULOPT_NBR
2408 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2409 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002410 wlv.line_attr = hl_combine_attr(
2411 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002412 }
2413#endif
2414
Bram Moolenaara74fda62019-10-19 17:38:03 +02002415#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002416 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002417 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002418 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002419# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002420 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002421 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002422# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002423 // Get syntax attribute.
2424 if (has_syntax)
2425 {
2426 // Get the syntax attribute for the character. If there
2427 // is an error, disable syntax highlighting.
2428 save_did_emsg = did_emsg;
2429 did_emsg = FALSE;
2430
2431 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002432 if (v == prev_syntax_col)
2433 // at same column again
2434 syntax_attr = prev_syntax_attr;
2435 else
2436 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002437# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002438 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002439# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002440 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002441# ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01002442 spv->spv_has_spell ? &can_spell :
Bram Moolenaar34390282019-10-16 14:38:26 +02002443# endif
Luuk van Baal30805a12023-05-27 22:22:10 +01002444 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002445 prev_syntax_col = v;
2446 prev_syntax_attr = syntax_attr;
2447 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002448
Bram Moolenaar34390282019-10-16 14:38:26 +02002449 if (did_emsg)
2450 {
2451 wp->w_s->b_syn_error = TRUE;
2452 has_syntax = FALSE;
2453 syntax_attr = 0;
2454 }
2455 else
2456 did_emsg = save_did_emsg;
2457# ifdef SYN_TIME_LIMIT
2458 if (wp->w_s->b_syn_slow)
2459 has_syntax = FALSE;
2460# endif
2461
2462 // Need to get the line again, a multi-line regexp may
2463 // have made it invalid.
2464 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2465 ptr = line + v;
2466# ifdef FEAT_CONCEAL
2467 // no concealing past the end of the line, it interferes
2468 // with line highlighting
2469 if (*ptr == NUL)
2470 syntax_flags = 0;
2471 else
2472 syntax_flags = get_syntax_info(&syntax_seqnr);
2473# endif
2474 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002475 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002476# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002477 // Combine text property highlight into syntax highlight.
2478 if (text_prop_type != NULL)
2479 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002480 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002481 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2482 else
2483 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002484 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002485 }
2486# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002487#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002488
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002489 // Decide which of the highlight attributes to use.
2490 attr_pri = TRUE;
2491#ifdef LINE_ATTR
2492 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002493 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002494 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002495 if (!highlight_match)
2496 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002497 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002498# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002499 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002500# endif
2501 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002502 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002503 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002504 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002505# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002506 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002507# endif
2508 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002509 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002510 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2511 || wlv.vcol < wlv.fromcol
2512 || vcol_prev < fromcol_prev
2513 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002514 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002515 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002516 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002517# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002518 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002519# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002520 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002521# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002522 attr_pri = FALSE;
2523 }
2524#else
2525 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002526 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002527 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002528 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002529#endif
2530 else
2531 {
2532 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002533#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002534 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002535#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002536 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002537#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002538 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002539#ifdef FEAT_PROP_POPUP
2540 // override with text property highlight when "override" is TRUE
2541 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002542 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002543#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002544 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002545
2546 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002547 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002548 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002549 if (wlv.char_attr == 0)
2550 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002551 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002552 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002553 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002554
2555 // Get the next character to put on the screen.
2556
2557 // The "p_extra" points to the extra stuff that is inserted to
2558 // represent special characters (non-printable stuff) and other
2559 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002560 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002561 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2562 // "p_extra[n_extra]".
2563 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002564 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002565 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002566 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002567 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002568 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2569 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002570 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2571 if (enc_utf8 && utf_char2len(c) > 1)
2572 {
2573 mb_utf8 = TRUE;
2574 u8cc[0] = 0;
2575 c = 0xc0;
2576 }
2577 else
2578 mb_utf8 = FALSE;
2579 }
2580 else
2581 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002582 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002583 if (has_mbyte)
2584 {
2585 mb_c = c;
2586 if (enc_utf8)
2587 {
2588 // If the UTF-8 character is more than one byte:
2589 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002590 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002591 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002592 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002593 mb_l = 1;
2594 else if (mb_l > 1)
2595 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002596 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002597 mb_utf8 = TRUE;
2598 c = 0xc0;
2599 }
2600 }
2601 else
2602 {
2603 // if this is a DBCS character, put it in "mb_c"
2604 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002605 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002606 mb_l = 1;
2607 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002608 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002609 }
2610 if (mb_l == 0) // at the NUL at end-of-line
2611 mb_l = 1;
2612
2613 // If a double-width char doesn't fit display a '>' in the
2614 // last column.
2615 if ((
2616# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002617 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002618# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002619 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002620 && (*mb_char2cells)(mb_c) == 2)
2621 {
2622 c = '>';
2623 mb_c = c;
2624 mb_l = 1;
2625 mb_utf8 = FALSE;
2626 multi_attr = HL_ATTR(HLF_AT);
2627#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002628 if (wlv.cul_attr)
2629 multi_attr = hl_combine_attr(
2630 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002631#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002632 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002633
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002634 // put the pointer back to output the double-width
2635 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002636 ++wlv.n_extra;
2637 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002638 }
2639 else
2640 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002641 wlv.n_extra -= mb_l - 1;
2642 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002643 }
2644 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002645 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002646 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002647 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002648#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002649 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002650 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002651 // Only restore search_attr and area_attr after "n_extra" in
2652 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002653 if (wlv.saved_n_extra <= 0)
2654 {
2655 if (search_attr == 0)
2656 search_attr = saved_search_attr;
2657 if (area_attr == 0 && *ptr != NUL)
2658 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002659
2660 if (wlv.extra_for_textprop)
2661 // wlv.extra_attr should be used at this position but
2662 // not any further.
2663 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002664 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002665
2666 wlv.extra_for_textprop = FALSE;
2667 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002668 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002669#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002670 }
2671 else
2672 {
2673#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002674 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002675#endif
zeertzjqe500ae82023-08-17 22:35:26 +02002676 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002677
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002678 // Get a character from the line itself.
2679 c = *ptr;
2680#ifdef FEAT_LINEBREAK
2681 c0 = *ptr;
2682#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002683 if (c == NUL)
zeertzjqb557f482023-08-22 22:07:34 +02002684 {
2685#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002686 // text is finished, may display a "below" virtual text
2687 did_line = TRUE;
2688#endif
zeertzjqb557f482023-08-22 22:07:34 +02002689 // no more cells to skip
2690 skip_cells = 0;
2691 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002692
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002693 if (has_mbyte)
2694 {
2695 mb_c = c;
2696 if (enc_utf8)
2697 {
2698 // If the UTF-8 character is more than one byte: Decode it
2699 // into "mb_c".
2700 mb_l = utfc_ptr2len(ptr);
2701 mb_utf8 = FALSE;
2702 if (mb_l > 1)
2703 {
2704 mb_c = utfc_ptr2char(ptr, u8cc);
2705 // Overlong encoded ASCII or ASCII with composing char
2706 // is displayed normally, except a NUL.
2707 if (mb_c < 0x80)
2708 {
2709 c = mb_c;
2710#ifdef FEAT_LINEBREAK
2711 c0 = mb_c;
2712#endif
2713 }
2714 mb_utf8 = TRUE;
2715
2716 // At start of the line we can have a composing char.
2717 // Draw it as a space with a composing char.
2718 if (utf_iscomposing(mb_c))
2719 {
2720 int i;
2721
2722 for (i = Screen_mco - 1; i > 0; --i)
2723 u8cc[i] = u8cc[i - 1];
2724 u8cc[0] = mb_c;
2725 mb_c = ' ';
2726 }
2727 }
2728
2729 if ((mb_l == 1 && c >= 0x80)
2730 || (mb_l >= 1 && mb_c == 0)
2731 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2732 {
2733 // Illegal UTF-8 byte: display as <xx>.
2734 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002735 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002736# ifdef FEAT_RIGHTLEFT
2737 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002738 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002739# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002740 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002741 c = *wlv.p_extra;
2742 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002743 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002744 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2745 wlv.c_extra = NUL;
2746 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002747 if (area_attr == 0 && search_attr == 0)
2748 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002749 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002750 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002751 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002752 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002753 }
2754 }
2755 else if (mb_l == 0) // at the NUL at end-of-line
2756 mb_l = 1;
2757#ifdef FEAT_ARABIC
2758 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2759 {
2760 // Do Arabic shaping.
2761 int pc, pc1, nc;
2762 int pcc[MAX_MCO];
2763
2764 // The idea of what is the previous and next
2765 // character depends on 'rightleft'.
2766 if (wp->w_p_rl)
2767 {
2768 pc = prev_c;
2769 pc1 = prev_c1;
2770 nc = utf_ptr2char(ptr + mb_l);
2771 prev_c1 = u8cc[0];
2772 }
2773 else
2774 {
2775 pc = utfc_ptr2char(ptr + mb_l, pcc);
2776 nc = prev_c;
2777 pc1 = pcc[0];
2778 }
2779 prev_c = mb_c;
2780
2781 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2782 }
2783 else
2784 prev_c = mb_c;
2785#endif
2786 }
2787 else // enc_dbcs
2788 {
2789 mb_l = MB_BYTE2LEN(c);
2790 if (mb_l == 0) // at the NUL at end-of-line
2791 mb_l = 1;
2792 else if (mb_l > 1)
2793 {
2794 // We assume a second byte below 32 is illegal.
2795 // Hopefully this is OK for all double-byte encodings!
2796 if (ptr[1] >= 32)
2797 mb_c = (c << 8) + ptr[1];
2798 else
2799 {
2800 if (ptr[1] == NUL)
2801 {
2802 // head byte at end of line
2803 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002804 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002805 }
2806 else
2807 {
2808 // illegal tail byte
2809 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002810 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002811 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002812 wlv.p_extra = wlv.extra;
2813 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002814 wlv.c_extra = NUL;
2815 wlv.c_final = NUL;
2816 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002817 if (area_attr == 0 && search_attr == 0)
2818 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002819 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002820 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002821 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002822 // save current attr
2823 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002824 }
2825 mb_c = c;
2826 }
2827 }
2828 }
2829 // If a double-width char doesn't fit display a '>' in the
2830 // last column; the character is displayed at the start of the
2831 // next line.
2832 if ((
2833# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002834 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002835# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002836 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002837 && (*mb_char2cells)(mb_c) == 2)
2838 {
2839 c = '>';
2840 mb_c = c;
2841 mb_utf8 = FALSE;
2842 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002843 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002844 // Put pointer back so that the character will be
2845 // displayed at the start of the next line.
2846 --ptr;
2847#ifdef FEAT_CONCEAL
2848 did_decrement_ptr = TRUE;
2849#endif
2850 }
2851 else if (*ptr != NUL)
2852 ptr += mb_l - 1;
2853
2854 // If a double-width char doesn't fit at the left side display
2855 // a '<' in the first column. Don't do this for unprintable
2856 // characters.
zeertzjqb557f482023-08-22 22:07:34 +02002857 if (skip_cells > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002858 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002859 wlv.n_extra = 1;
2860 wlv.c_extra = MB_FILLER_CHAR;
2861 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002862 c = ' ';
2863 if (area_attr == 0 && search_attr == 0)
2864 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002865 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002866 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002867 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002868 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002869 }
2870 mb_c = c;
2871 mb_utf8 = FALSE;
2872 mb_l = 1;
2873 }
2874
2875 }
2876 ++ptr;
2877
2878 if (extra_check)
2879 {
2880#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002881 // Check spelling (unless at the end of the line).
2882 // Only do this when there is no syntax highlighting, the
2883 // @Spell cluster is not used or the current syntax item
2884 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002885 v = (long)(ptr - line);
Luuk van Baal30805a12023-05-27 22:22:10 +01002886 if (spv->spv_has_spell && v >= word_end && v > cur_checked_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002887 {
2888 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002889 // do not calculate cap_col at the end of the line or when
2890 // only white space is following
2891 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002892# ifdef FEAT_SYN_HL
2893 !has_syntax ||
2894# endif
2895 can_spell))
2896 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002897 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002898 int len;
2899 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002900
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002901 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002902 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002903
2904 // Use nextline[] if possible, it has the start of the
2905 // next line concatenated.
2906 if ((prev_ptr - line) - nextlinecol >= 0)
2907 p = nextline + (prev_ptr - line) - nextlinecol;
2908 else
2909 p = prev_ptr;
Luuk van Baal30805a12023-05-27 22:22:10 +01002910 spv->spv_cap_col -= (int)(prev_ptr - line);
2911 len = spell_check(wp, p, &spell_hlf, &spv->spv_cap_col,
2912 spv->spv_unchanged);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002913 word_end = v + len;
2914
2915 // In Insert mode only highlight a word that
2916 // doesn't touch the cursor.
2917 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002918 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002919 && wp->w_cursor.lnum == lnum
2920 && wp->w_cursor.col >=
2921 (colnr_T)(prev_ptr - line)
2922 && wp->w_cursor.col < (colnr_T)word_end)
2923 {
2924 spell_hlf = HLF_COUNT;
2925 spell_redraw_lnum = lnum;
2926 }
2927
2928 if (spell_hlf == HLF_COUNT && p != prev_ptr
2929 && (p - nextline) + len > nextline_idx)
2930 {
2931 // Remember that the good word continues at the
2932 // start of the next line.
Luuk van Baal30805a12023-05-27 22:22:10 +01002933 spv->spv_checked_lnum = lnum + 1;
2934 spv->spv_checked_col = (p - nextline) + len
2935 - nextline_idx;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002936 }
2937
2938 // Turn index into actual attributes.
2939 if (spell_hlf != HLF_COUNT)
2940 spell_attr = highlight_attr[spell_hlf];
2941
Luuk van Baal30805a12023-05-27 22:22:10 +01002942 if (spv->spv_cap_col > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002943 {
2944 if (p != prev_ptr
Luuk van Baal30805a12023-05-27 22:22:10 +01002945 && (p - nextline) + spv->spv_cap_col
2946 >= nextline_idx)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002947 {
2948 // Remember that the word in the next line
2949 // must start with a capital.
Luuk van Baal30805a12023-05-27 22:22:10 +01002950 spv->spv_capcol_lnum = lnum + 1;
2951 spv->spv_cap_col = ((p - nextline)
2952 + spv->spv_cap_col - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002953 }
2954 else
2955 // Compute the actual column.
Luuk van Baal30805a12023-05-27 22:22:10 +01002956 spv->spv_cap_col += (prev_ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002957 }
2958 }
2959 }
2960 if (spell_attr != 0)
2961 {
2962 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002963 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2964 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002965 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002966 wlv.char_attr = hl_combine_attr(spell_attr,
2967 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002968 }
2969#endif
2970#ifdef FEAT_LINEBREAK
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02002971 // we don't want linebreak to apply for lines that start with
2972 // leading spaces, followed by long letters (since it would add
2973 // a break at the beginning of a line and this might be unexpected)
2974 //
2975 // So only allow to linebreak, once we have found chars not in
2976 // 'breakat' in the line.
2977 if ( wp->w_p_lbr && !wlv.need_lbr && c != NUL &&
2978 !VIM_ISBREAK((int)*ptr))
2979 wlv.need_lbr = TRUE;
2980#endif
2981#ifdef FEAT_LINEBREAK
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002982 // Found last space before word: check for line break.
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02002983 if (wp->w_p_lbr && c0 == c && wlv.need_lbr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002984 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2985 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002986 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2987 : 0;
2988 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002989 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002990
zeertzjqce53e3e2023-09-01 18:49:30 +02002991 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol
2992# ifdef FEAT_PROP_POPUP
2993 - vcol_first_char,
2994# endif
2995 line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002996# ifdef FEAT_PROP_POPUP
2997 // do not want virtual text counted here
2998 cts.cts_has_prop_with_text = FALSE;
2999# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003000 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01003001 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02003002
Bram Moolenaar0bbca542022-01-11 13:14:54 +00003003 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00003004 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00003005 // line break, but for TABs the highlighting should
3006 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00003007 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02003008
Bram Moolenaar1306b362022-08-06 15:59:06 +01003009 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003010# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01003011 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003012 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003013 wp->w_buffer->b_p_vts_array) - 1;
3014# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003015 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003016 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003017# endif
3018
Bram Moolenaar1306b362022-08-06 15:59:06 +01003019 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
3020 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01003021# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01003022 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00003023 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00003024# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003025 if (VIM_ISWHITE(c))
3026 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01003027# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003028 if (c == TAB)
3029 // See "Tab alignment" below.
3030 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01003031# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003032 if (!wp->w_p_list)
3033 c = ' ';
3034 }
3035 }
3036#endif
zeertzjqabc80812023-09-24 23:32:18 +02003037 if (wp->w_p_list)
3038 {
3039 in_multispace = c == ' ' && (*ptr == ' '
3040 || (prev_ptr > line && prev_ptr[-1] == ' '));
3041 if (!in_multispace)
3042 multispace_pos = 0;
3043 }
zeertzjqf14b8ba2021-09-10 16:58:30 +02003044
Bram Moolenaareed9d462021-02-15 20:38:25 +01003045 // 'list': Change char 160 to 'nbsp' and space to 'space'
3046 // setting in 'listchars'. But not when the character is
3047 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003048 if (wp->w_p_list
3049 && ((((c == 160 && mb_l == 1)
3050 || (mb_utf8
3051 && ((mb_c == 160 && mb_l == 2)
3052 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01003053 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003054 || (c == ' '
3055 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02003056 && (wp->w_lcs_chars.space
3057 || (in_multispace
3058 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01003059 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003060 && ptr - line <= trailcol)))
3061 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02003062 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
3063 {
3064 c = wp->w_lcs_chars.multispace[multispace_pos++];
3065 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
3066 multispace_pos = 0;
3067 }
3068 else
3069 c = (c == ' ') ? wp->w_lcs_chars.space
3070 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003071 if (area_attr == 0 && search_attr == 0)
3072 {
3073 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003074 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003075 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003076 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003077 }
3078 mb_c = c;
3079 if (enc_utf8 && utf_char2len(c) > 1)
3080 {
3081 mb_utf8 = TRUE;
3082 u8cc[0] = 0;
3083 c = 0xc0;
3084 }
3085 else
3086 mb_utf8 = FALSE;
3087 }
3088
zeertzjq2e7cba32022-06-10 15:30:32 +01003089 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
3090 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003091 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003092 if (leadcol != 0 && in_multispace && ptr < line + leadcol
3093 && wp->w_lcs_chars.leadmultispace != NULL)
3094 {
3095 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01003096 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
3097 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003098 multispace_pos = 0;
3099 }
3100
3101 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
3102 c = wp->w_lcs_chars.trail;
3103
3104 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
3105 c = wp->w_lcs_chars.lead;
3106
zeertzjq2e7cba32022-06-10 15:30:32 +01003107 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003108 c = wp->w_lcs_chars.space;
3109
3110
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003111 if (!attr_pri)
3112 {
3113 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003114 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003115 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003116 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003117 }
3118 mb_c = c;
3119 if (enc_utf8 && utf_char2len(c) > 1)
3120 {
3121 mb_utf8 = TRUE;
3122 u8cc[0] = 0;
3123 c = 0xc0;
3124 }
3125 else
3126 mb_utf8 = FALSE;
3127 }
3128 }
3129
3130 // Handling of non-printable characters.
3131 if (!vim_isprintc(c))
3132 {
3133 // when getting a character from the file, we may have to
3134 // turn it into something else on the way to putting it
3135 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01003136 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003137 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003138 int tab_len = 0;
3139 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003140#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003141 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01003142
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003143 // only adjust the tab_len, when at the first column
3144 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01003145 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003146 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003147#endif
3148 // tab amount depends on current column
3149#ifdef FEAT_VARTABS
3150 tab_len = tabstop_padding(vcol_adjusted,
3151 wp->w_buffer->b_p_ts,
3152 wp->w_buffer->b_p_vts_array) - 1;
3153#else
3154 tab_len = (int)wp->w_buffer->b_p_ts
3155 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
3156#endif
3157
3158#ifdef FEAT_LINEBREAK
3159 if (!wp->w_p_lbr || !wp->w_p_list)
3160#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003161 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003162 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01003163 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003164 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003165#ifdef FEAT_LINEBREAK
3166 else
3167 {
3168 char_u *p;
3169 int len;
3170 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003171 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003172
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003173# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003174 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003175 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003176 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003177
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003178 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003179 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003180 && old_boguscols > 0
3181 && wlv.n_extra > tab_len)
3182 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003183# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003184 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003185 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003186 // If wlv.n_extra > 0, it gives the number of chars
3187 // to use for a tab, else we need to calculate the
3188 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003189 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3190 len = tab_len * tab2_len;
3191 if (wp->w_lcs_chars.tab3)
3192 len += mb_char2len(wp->w_lcs_chars.tab3)
3193 - tab2_len;
3194 if (wlv.n_extra > 0)
3195 len += wlv.n_extra - tab_len;
3196 c = wp->w_lcs_chars.tab1;
3197 p = alloc(len + 1);
3198 if (p == NULL)
3199 wlv.n_extra = 0;
3200 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003201 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003202 vim_memset(p, ' ', len);
3203 p[len] = NUL;
3204 vim_free(wlv.p_extra_free);
3205 wlv.p_extra_free = p;
3206 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003207 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003208 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003209
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003210 if (*p == NUL)
3211 {
3212 tab_len = i;
3213 break;
3214 }
3215
3216 // if tab3 is given, use it for the last
3217 // char
3218 if (wp->w_lcs_chars.tab3
3219 && i == tab_len - 1)
3220 lcs = wp->w_lcs_chars.tab3;
3221 p += mb_char2bytes(lcs, p);
3222 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003223 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003224 }
3225 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003226# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003227 // n_extra will be increased by
3228 // FIX_FOX_BOGUSCOLS macro below, so need to
3229 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003230 if (wlv.vcol_off_co > 0)
3231 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003232# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003233 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003234 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003235 }
3236#endif
3237#ifdef FEAT_CONCEAL
3238 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003239 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003240
3241 // Tab alignment should be identical regardless of
3242 // 'conceallevel' value. So tab compensates of all
3243 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003244 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003245 // line. Note that the tab can be longer than
3246 // 'tabstop' when there are concealed characters.
3247 FIX_FOR_BOGUSCOLS;
3248
3249 // Make sure, the highlighting for the tab char will be
3250 // correctly set further below (effectively reverts the
zeertzjq010e1532024-03-14 18:22:17 +01003251 // FIX_FOR_BOGUSCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003252 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003253 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003254 tab_len += vc_saved;
3255 }
3256#endif
3257 mb_utf8 = FALSE; // don't draw as UTF-8
3258 if (wp->w_p_list)
3259 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003260 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003261 ? wp->w_lcs_chars.tab3
3262 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003263#ifdef FEAT_LINEBREAK
h-east194555c2023-03-02 18:49:09 +00003264 if (wp->w_p_lbr && wlv.p_extra != NULL
3265 && *wlv.p_extra != NUL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003266 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003267 else
3268#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003269 wlv.c_extra = wp->w_lcs_chars.tab2;
3270 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003271 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003272 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003273 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003274 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003275 mb_c = c;
3276 if (enc_utf8 && utf_char2len(c) > 1)
3277 {
3278 mb_utf8 = TRUE;
3279 u8cc[0] = 0;
3280 c = 0xc0;
3281 }
3282 }
3283 else
3284 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003285 wlv.c_final = NUL;
3286 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003287 c = ' ';
3288 }
3289 }
3290 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003291 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003292 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003293 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3294 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003295 && VIsual_mode != Ctrl_V
3296 && (
3297# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003298 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003299# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003300 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003301 && !(noinvcur
3302 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003303 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003304 && lcs_eol_one > 0)
3305 {
3306 // Display a '$' after the line or highlight an extra
3307 // character if the line break is included.
3308#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3309 // For a diff line the highlighting continues after the
3310 // "$".
3311 if (
3312# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003313 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003314# ifdef LINE_ATTR
3315 &&
3316# endif
3317# endif
3318# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003319 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003320# endif
3321 )
3322#endif
3323 {
3324 // In virtualedit, visual selections may extend
3325 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003326 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003327 && wlv.tocol != MAXCOL
3328 && wlv.vcol < wlv.tocol))
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01003329 wlv.p_extra = (char_u *)"";
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003330 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003331 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003332 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3333 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003334 else
3335 c = ' ';
3336 lcs_eol_one = -1;
3337 --ptr; // put it back at the NUL
3338 if (!attr_pri)
3339 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003340 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003341 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003342 n_attr = 1;
3343 }
3344 mb_c = c;
3345 if (enc_utf8 && utf_char2len(c) > 1)
3346 {
3347 mb_utf8 = TRUE;
3348 u8cc[0] = 0;
3349 c = 0xc0;
3350 }
3351 else
3352 mb_utf8 = FALSE; // don't draw as UTF-8
3353 }
3354 else if (c != NUL)
3355 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003356 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3357 if (wlv.n_extra == 0)
3358 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003359#ifdef FEAT_RIGHTLEFT
3360 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003361 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003362#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003363 wlv.c_extra = NUL;
3364 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003365#ifdef FEAT_LINEBREAK
3366 if (wp->w_p_lbr)
3367 {
3368 char_u *p;
3369
Bram Moolenaar1306b362022-08-06 15:59:06 +01003370 c = *wlv.p_extra;
3371 p = alloc(wlv.n_extra + 1);
3372 vim_memset(p, ' ', wlv.n_extra);
3373 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3374 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003375 vim_free(wlv.p_extra_free);
3376 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003377 }
3378 else
3379#endif
3380 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003381 wlv.n_extra = byte2cells(c) - 1;
3382 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003383 }
3384 if (!attr_pri)
3385 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003386 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003387 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003388 HL_ATTR(HLF_8));
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003389#ifdef FEAT_PROP_POPUP
3390 if (text_prop_type != NULL &&
3391 text_prop_flags & PT_FLAG_OVERRIDE)
3392 wlv.extra_attr = hl_combine_attr(text_prop_attr, wlv.extra_attr);
3393#endif
3394
Bram Moolenaar1306b362022-08-06 15:59:06 +01003395 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003396 }
3397 mb_utf8 = FALSE; // don't draw as UTF-8
3398 }
3399 else if (VIsual_active
3400 && (VIsual_mode == Ctrl_V
3401 || VIsual_mode == 'v')
3402 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003403 && wlv.tocol != MAXCOL
3404 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003405 && (
3406#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003407 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003408#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003409 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003410 {
3411 c = ' ';
3412 --ptr; // put it back at the NUL
3413 }
3414#if defined(LINE_ATTR)
3415 else if ((
3416# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003417 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003418# endif
3419# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003420 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003421# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003422 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003423 ) && (
3424# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003425 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003426# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003427 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003428# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003429 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003430# endif
3431 < wp->w_width)))
3432 {
3433 // Highlight until the right side of the window
3434 c = ' ';
3435 --ptr; // put it back at the NUL
3436
3437 // Remember we do the char for line highlighting.
3438 ++did_line_attr;
3439
3440 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003441 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003442 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003443 || (wp->w_p_list &&
3444 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003445 wlv.char_attr = wlv.line_attr;
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003446#ifdef FEAT_SIGNS
3447 // At end of line: if Sign is present with line highlight, reset char_attr
Christian Brabandte1eaae22023-08-19 22:36:12 +02003448 // but not when cursorline is active
3449 if (sign_present && wlv.sattr.sat_linehl > 0 && wlv.draw_state == WL_LINE
3450 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum))
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003451 wlv.char_attr = wlv.sattr.sat_linehl;
3452#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003453# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003454 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003455 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003456 wlv.diff_hlf = HLF_CHD;
3457 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003458 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003459 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003460 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3461 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003462 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003463 || (wlv.vcol >= left_curline_col
3464 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003465 wlv.char_attr = hl_combine_attr(
3466 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003467 }
3468 }
3469# endif
3470# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003471 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003472 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003473 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003474 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3475 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003476 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003477 if (!wlv.cul_screenline
3478 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003479 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003480 wlv.char_attr = hl_combine_attr(
3481 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003482 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003483 else if (wlv.line_attr)
3484 wlv.char_attr = hl_combine_attr(
3485 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003486 }
3487# endif
3488 }
3489#endif
3490 }
3491
3492#ifdef FEAT_CONCEAL
3493 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003494 && (wp != curwin || lnum != wp->w_cursor.lnum
3495 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003496 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3497 && !(lnum_in_visual_area
3498 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3499 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003500 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003501 if (((prev_syntax_id != syntax_seqnr
3502 && (syntax_flags & HL_CONCEAL) != 0)
3503 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003504 && (syn_get_sub_char() != NUL
3505 || (has_match_conc && match_conc)
3506 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003507 && wp->w_p_cole != 3)
3508 {
3509 // First time at this concealed item: display one
3510 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003511 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003512 c = match_conc;
3513 else if (syn_get_sub_char() != NUL)
3514 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003515 else if (wp->w_lcs_chars.conceal != NUL)
3516 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003517 else
3518 c = ' ';
3519
zeertzjq010e1532024-03-14 18:22:17 +01003520 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3521 // When the first char to be concealed is double-width,
3522 // need to advance one more virtual column.
3523 wlv.n_extra++;
3524
3525 mb_c = c;
3526 if (enc_utf8 && utf_char2len(c) > 1)
3527 {
3528 mb_utf8 = TRUE;
3529 u8cc[0] = 0;
3530 c = 0xc0;
3531 }
3532 else
3533 mb_utf8 = FALSE; // don't draw as UTF-8
3534
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003535 prev_syntax_id = syntax_seqnr;
3536
Bram Moolenaar1306b362022-08-06 15:59:06 +01003537 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003538 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003539 wlv.vcol += wlv.n_extra;
3540 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003541 {
3542# ifdef FEAT_RIGHTLEFT
3543 if (wp->w_p_rl)
3544 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003545 wlv.col -= wlv.n_extra;
3546 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003547 }
3548 else
3549# endif
3550 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003551 wlv.boguscols += wlv.n_extra;
3552 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003553 }
3554 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003555 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003556 n_attr = 0;
3557 }
zeertzjqb557f482023-08-22 22:07:34 +02003558 else if (skip_cells == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003559 {
3560 is_concealing = TRUE;
zeertzjqb557f482023-08-22 22:07:34 +02003561 skip_cells = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003562 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003563 }
3564 else
3565 {
3566 prev_syntax_id = 0;
3567 is_concealing = FALSE;
3568 }
3569
zeertzjqb557f482023-08-22 22:07:34 +02003570 if (skip_cells > 0 && did_decrement_ptr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003571 // not showing the '>', put pointer back to avoid getting stuck
3572 ++ptr;
3573
3574#endif // FEAT_CONCEAL
3575 }
3576
3577#ifdef FEAT_CONCEAL
3578 // In the cursor line and we may be concealing characters: correct
3579 // the cursor column when we reach its position.
zeertzjq253ff4d2024-03-13 20:38:26 +01003580 // With 'virtualedit' we may never reach cursor position, but we still
3581 // need to correct the cursor column, so do that at end of line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003582 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003583 && wp == curwin && lnum == wp->w_cursor.lnum
3584 && conceal_cursor_line(wp)
zeertzjq253ff4d2024-03-13 20:38:26 +01003585 && (wlv.vcol + skip_cells >= wp->w_virtcol || c == NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003586 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003587# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003588 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003589 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003590 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003591# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003592 wp->w_wcol = wlv.col - wlv.boguscols;
zeertzjq253ff4d2024-03-13 20:38:26 +01003593 if (wlv.vcol + skip_cells < wp->w_virtcol)
3594 // Cursor beyond end of the line with 'virtualedit'.
3595 wp->w_wcol += wp->w_virtcol - wlv.vcol - skip_cells;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003596 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003597 did_wcol = TRUE;
3598 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003599# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003600 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003601# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003602 }
3603#endif
3604
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003605 // Use "wlv.extra_attr", but don't override visual selection
3606 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003607 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3608 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003609 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003610 && (!attr_pri
3611#ifdef FEAT_PROP_POPUP
3612 || (text_prop_flags & PT_FLAG_OVERRIDE)
3613#endif
3614 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003615 {
3616#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003617 if (wlv.line_attr)
3618 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003619 else
3620#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003621 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003622#ifdef FEAT_PROP_POPUP
3623 if (reset_extra_attr)
3624 {
3625 reset_extra_attr = FALSE;
3626 wlv.extra_attr = 0;
3627 }
3628#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003629 }
3630
3631#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3632 // XIM don't send preedit_start and preedit_end, but they send
3633 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3634 // im_is_preediting() here.
3635 if (p_imst == IM_ON_THE_SPOT
3636 && xic != NULL
3637 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003638 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003639 && !p_imdisable
3640 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003641 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003642 {
3643 colnr_T tcol;
3644
3645 if (preedit_end_col == MAXCOL)
3646 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3647 else
3648 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003649 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003650 {
3651 if (feedback_old_attr < 0)
3652 {
3653 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003654 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003655 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003656 wlv.char_attr = im_get_feedback_attr(feedback_col);
3657 if (wlv.char_attr < 0)
3658 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003659 feedback_col++;
3660 }
3661 else if (feedback_old_attr >= 0)
3662 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003663 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003664 feedback_old_attr = -1;
3665 feedback_col = 0;
3666 }
3667 }
3668#endif
3669 // Handle the case where we are in column 0 but not on the first
3670 // character of the line and the user wants us to show us a
3671 // special character (via 'listchars' option "precedes:<char>".
3672 if (lcs_prec_todo != NUL
3673 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003674 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3675 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003676#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003677 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003678#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003679 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003680 && c != NUL)
3681 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003682 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003683 lcs_prec_todo = NUL;
3684 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3685 {
3686 // Double-width character being overwritten by the "precedes"
3687 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003688 wlv.c_extra = MB_FILLER_CHAR;
3689 wlv.c_final = NUL;
3690 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003691 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003692 wlv.extra_attr =
3693 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003694 }
3695 mb_c = c;
3696 if (enc_utf8 && utf_char2len(c) > 1)
3697 {
3698 mb_utf8 = TRUE;
3699 u8cc[0] = 0;
3700 c = 0xc0;
3701 }
3702 else
3703 mb_utf8 = FALSE; // don't draw as UTF-8
3704 if (!attr_pri)
3705 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003706 saved_attr3 = wlv.char_attr; // save current attr
3707 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003708 n_attr3 = 1;
3709 }
3710 }
3711
3712 // At end of the text line or just after the last character.
3713 if ((c == NUL
3714#if defined(LINE_ATTR)
3715 || did_line_attr == 1
3716#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003717 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003718 {
3719#ifdef FEAT_SEARCH_EXTRA
3720 // flag to indicate whether prevcol equals startcol of search_hl or
3721 // one of the matches
3722 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3723 (long)(ptr - line) - (c == NUL));
3724#endif
3725 // Invert at least one char, used for Visual and empty line or
3726 // highlight match at end of line. If it's beyond the last
3727 // char on the screen, just overwrite that one (tricky!) Not
3728 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003729 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003730 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003731 && (VIsual_mode != Ctrl_V
3732 || lnum == VIsual.lnum
3733 || lnum == curwin->w_cursor.lnum)
3734 && c == NUL)
3735#ifdef FEAT_SEARCH_EXTRA
3736 // highlight 'hlsearch' match at end of line
3737 || (prevcol_hl_flag
3738# ifdef FEAT_SYN_HL
3739 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3740 && !(wp == curwin && VIsual_active))
3741# endif
3742# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003743 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003744# endif
3745# if defined(LINE_ATTR)
3746 && did_line_attr <= 1
3747# endif
3748 )
3749#endif
3750 ))
3751 {
3752 int n = 0;
3753
3754#ifdef FEAT_RIGHTLEFT
3755 if (wp->w_p_rl)
3756 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003757 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003758 n = 1;
3759 }
3760 else
3761#endif
3762 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003763 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003764 n = -1;
3765 }
3766 if (n != 0)
3767 {
3768 // At the window boundary, highlight the last character
3769 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003770 wlv.off += n;
3771 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003772 }
3773 else
3774 {
3775 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003776 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003777 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003778 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003779 }
3780#ifdef FEAT_SEARCH_EXTRA
3781 if (area_attr == 0)
3782 {
3783 // Use attributes from match with highest priority among
3784 // 'search_hl' and the match list.
3785 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003786 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003787 }
3788#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003789 ScreenAttrs[wlv.off] = wlv.char_attr;
zeertzjqd0c1b772024-03-16 15:03:33 +01003790 ScreenCols[wlv.off] = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003791#ifdef FEAT_RIGHTLEFT
3792 if (wp->w_p_rl)
3793 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003794 --wlv.col;
3795 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003796 }
3797 else
3798#endif
3799 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003800 ++wlv.col;
3801 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003802 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003803 ++wlv.vcol;
3804 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003805 }
3806 }
3807
3808 // At end of the text line.
3809 if (c == NUL)
3810 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003811#ifdef FEAT_PROP_POPUP
3812 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003813 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003814 // Put the pointer back to the NUL.
3815 --ptr;
3816 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003817 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003818 else
3819#endif
3820 {
3821 draw_screen_line(wp, &wlv);
3822
3823 // Update w_cline_height and w_cline_folded if the cursor line
3824 // was updated (saves a call to plines() later).
3825 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3826 {
3827 curwin->w_cline_row = startrow;
3828 curwin->w_cline_height = wlv.row - startrow;
3829#ifdef FEAT_FOLDING
3830 curwin->w_cline_folded = FALSE;
3831#endif
3832 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3833 }
3834 break;
3835 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003836 }
3837
3838 // Show "extends" character from 'listchars' if beyond the line end and
3839 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003840 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003841 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003842 && wp->w_p_list
3843 && !wp->w_p_wrap
3844#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003845 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003846#endif
3847 && (
3848#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003849 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003850#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003851 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003852 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003853 || lcs_eol_one > 0
3854 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
zeertzjq6a389722023-08-27 19:04:14 +02003855 || *wlv.p_extra != NUL))
3856#ifdef FEAT_PROP_POPUP
zeertzjq4e26a9a2023-12-03 17:50:47 +01003857 || text_prop_next <= last_textprop_text_idx
zeertzjq6a389722023-08-27 19:04:14 +02003858#endif
3859 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003860 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003861 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003862 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003863 mb_c = c;
3864 if (enc_utf8 && utf_char2len(c) > 1)
3865 {
3866 mb_utf8 = TRUE;
3867 u8cc[0] = 0;
3868 c = 0xc0;
3869 }
3870 else
3871 mb_utf8 = FALSE;
3872 }
3873
3874#ifdef FEAT_SYN_HL
3875 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003876 if (wlv.draw_color_col)
3877 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003878
3879 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3880 // highlight the cursor position itself.
3881 // Also highlight the 'colorcolumn' if it is different than
3882 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003883 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3884 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003885 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003886 if (((wlv.draw_state == WL_LINE
3887 || wlv.draw_state == WL_BRI
3888 || wlv.draw_state == WL_SBR)
3889 && !lnum_in_visual_area
3890 && search_attr == 0
3891 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003892# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003893 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003894# endif
3895 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003896 {
3897 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3898 && lnum != wp->w_cursor.lnum)
3899 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003900 vcol_save_attr = wlv.char_attr;
3901 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3902 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003903 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003904 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003905 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003906 vcol_save_attr = wlv.char_attr;
3907 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003908 }
3909 }
3910#endif
3911
zeertzjq8fc6a1d2023-08-20 18:12:54 +02003912 if (wlv.draw_state == WL_LINE)
3913 vcol_prev = wlv.vcol;
3914
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003915 // Store character to be displayed.
3916 // Skip characters that are left of the screen for 'nowrap'.
zeertzjqb557f482023-08-22 22:07:34 +02003917 if (wlv.draw_state < WL_LINE || skip_cells <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003918 {
3919 // Store the character.
3920#if defined(FEAT_RIGHTLEFT)
3921 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3922 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003923 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003924 --wlv.off;
3925 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003926 }
3927#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003928 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003929 if (enc_dbcs == DBCS_JPNU)
3930 {
3931 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003932 ScreenLines[wlv.off] = 0x8e;
3933 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003934 }
3935 else if (enc_utf8)
3936 {
3937 if (mb_utf8)
3938 {
3939 int i;
3940
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003941 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003942 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003943 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003944 for (i = 0; i < Screen_mco; ++i)
3945 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003946 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003947 if (u8cc[i] == 0)
3948 break;
3949 }
3950 }
3951 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003952 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003953 }
3954 if (multi_attr)
3955 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003956 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003957 multi_attr = 0;
3958 }
3959 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003960 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003961
zeertzjqdb54e982023-09-21 16:33:09 +02003962 if (wlv.draw_state > WL_NR
3963#ifdef FEAT_DIFF
3964 && wlv.filler_todo <= 0
3965#endif
3966 )
3967 ScreenCols[wlv.off] = wlv.vcol;
3968 else
3969 ScreenCols[wlv.off] = -1;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003970
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003971 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3972 {
3973 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003974 ++wlv.off;
3975 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003976 if (enc_utf8)
3977 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003978 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003979 else
3980 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003981 ScreenLines[wlv.off] = mb_c & 0xff;
zeertzjqdb54e982023-09-21 16:33:09 +02003982
Bram Moolenaar1306b362022-08-06 15:59:06 +01003983 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003984#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003985 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003986#endif
3987 )
zeertzjqdb54e982023-09-21 16:33:09 +02003988 ScreenCols[wlv.off] = ++wlv.vcol;
3989 else
3990 ScreenCols[wlv.off] = -1;
3991
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003992 // When "wlv.tocol" is halfway a character, set it to the end
3993 // of the character, otherwise highlighting won't stop.
3994 if (wlv.tocol == wlv.vcol)
3995 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003996
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003997#ifdef FEAT_RIGHTLEFT
3998 if (wp->w_p_rl)
3999 {
4000 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004001 --wlv.off;
4002 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004003 }
4004#endif
4005 }
4006#ifdef FEAT_RIGHTLEFT
4007 if (wp->w_p_rl)
4008 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004009 --wlv.off;
4010 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004011 }
4012 else
4013#endif
4014 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004015 ++wlv.off;
4016 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004017 }
4018 }
4019#ifdef FEAT_CONCEAL
4020 else if (wp->w_p_cole > 0 && is_concealing)
4021 {
zeertzjq010e1532024-03-14 18:22:17 +01004022 int concealed_wide = has_mbyte && (*mb_char2cells)(mb_c) > 1;
4023
zeertzjqb557f482023-08-22 22:07:34 +02004024 --skip_cells;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004025 ++wlv.vcol_off_co;
zeertzjq010e1532024-03-14 18:22:17 +01004026 if (concealed_wide)
4027 {
4028 // When a double-width char is concealed,
4029 // need to advance one more virtual column.
4030 ++wlv.vcol;
4031 ++wlv.vcol_off_co;
4032 }
4033
Bram Moolenaar1306b362022-08-06 15:59:06 +01004034 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004035 wlv.vcol_off_co += wlv.n_extra;
zeertzjq010e1532024-03-14 18:22:17 +01004036
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004037 if (wp->w_p_wrap)
4038 {
4039 // Special voodoo required if 'wrap' is on.
4040 //
4041 // Advance the column indicator to force the line
4042 // drawing to wrap early. This will make the line
4043 // take up the same screen space when parts are concealed,
4044 // so that cursor line computations aren't messed up.
4045 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004046 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004047 // trailing junk to be written out of the screen line
4048 // we are building, 'boguscols' keeps track of the number
4049 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004050 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004051 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004052 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004053# ifdef FEAT_RIGHTLEFT
4054 if (wp->w_p_rl)
4055 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004056 wlv.col -= wlv.n_extra;
4057 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004058 }
4059 else
4060# endif
4061 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004062 wlv.col += wlv.n_extra;
4063 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004064 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01004065 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004066 n_attr = 0;
4067 }
4068
zeertzjq010e1532024-03-14 18:22:17 +01004069 if (concealed_wide)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004070 {
4071 // Need to fill two screen columns.
4072# ifdef FEAT_RIGHTLEFT
4073 if (wp->w_p_rl)
4074 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004075 --wlv.boguscols;
4076 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004077 }
4078 else
4079# endif
4080 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004081 ++wlv.boguscols;
4082 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004083 }
4084 }
4085
4086# ifdef FEAT_RIGHTLEFT
4087 if (wp->w_p_rl)
4088 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004089 --wlv.boguscols;
4090 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004091 }
4092 else
4093# endif
4094 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004095 ++wlv.boguscols;
4096 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004097 }
4098 }
4099 else
4100 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004101 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004102 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004103 wlv.vcol += wlv.n_extra;
4104 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004105 n_attr = 0;
4106 }
4107 }
4108
4109 }
4110#endif // FEAT_CONCEAL
4111 else
zeertzjqb557f482023-08-22 22:07:34 +02004112 --skip_cells;
4113
4114 if (wlv.draw_state > WL_NR && skipped_cells > 0)
4115 {
4116 wlv.vcol += skipped_cells;
4117 skipped_cells = 0;
4118 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004119
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004120 // Only advance the "wlv.vcol" when after the 'number' or
4121 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004122 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004123#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004124 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004125#endif
4126 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004127 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004128
4129#ifdef FEAT_SYN_HL
4130 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004131 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004132#endif
4133
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004134 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01004135 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
4136 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004137
4138 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01004139 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004140 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004141 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004142 if (wlv.n_attr_skip > 0)
4143 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004144
4145 // At end of screen line and there is more to come: Display the line
4146 // so far. If there is no more to display it is caught above.
4147 if ((
4148#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004149 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004150#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004151 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01004152 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02004153 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004154#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004155 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004156#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004157#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004158 || text_prop_above || text_prop_follows
zeertzjq4e26a9a2023-12-03 17:50:47 +01004159 || text_prop_next <= last_textprop_text_idx
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004160#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01004161 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01004162 && lcs_eol_one != -1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004163 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
4164 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004165 )
4166 {
4167#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01004168 wlv.col -= wlv.boguscols;
zeertzjq21b0a3d2024-03-13 20:06:34 +01004169 // Apply 'cursorline' and 'wincolor' highlight.
4170 if (wlv.boguscols != 0 && (
4171# ifdef LINE_ATTR
4172 wlv.line_attr != 0 ||
4173# endif
4174 wlv.win_attr != 0
4175 )
4176 )
4177 {
4178 int attr = wlv.win_attr;
4179# ifdef LINE_ATTR
4180 if (wlv.line_attr != 0)
4181 attr = hl_combine_attr(attr, wlv.line_attr);
4182# endif
4183 while ((
4184# ifdef FEAT_RIGHTLEFT
4185 wp->w_p_rl ? wlv.col >= 0 :
4186# endif
4187 wlv.col < wp->w_width))
4188 {
4189 ScreenLines[wlv.off] = ' ';
4190 if (enc_utf8)
4191 ScreenLinesUC[wlv.off] = 0;
4192 ScreenAttrs[wlv.off] = attr;
zeertzjqd0c1b772024-03-16 15:03:33 +01004193 ScreenCols[wlv.off] = wlv.vcol - 1;
zeertzjq21b0a3d2024-03-13 20:06:34 +01004194# ifdef FEAT_RIGHTLEFT
4195 if (wp->w_p_rl)
4196 {
4197 wlv.off--;
4198 wlv.col--;
4199 wlv.boguscols++;
4200 }
4201 else
4202# endif
4203 {
4204 wlv.off++;
4205 wlv.col++;
4206 wlv.boguscols--;
4207 }
4208 }
4209 }
zeertzjqd0c1b772024-03-16 15:03:33 +01004210 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar75008662022-10-04 22:40:56 +01004211 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004212 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004213 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004214#else
zeertzjqd0c1b772024-03-16 15:03:33 +01004215 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004216#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004217 ++wlv.row;
4218 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004219
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01004220 // When not wrapping and finished diff lines, break here.
4221 if (!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004222#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004223 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004224#endif
4225#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01004226 && !text_prop_above
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01004227 && !text_prop_follows
Bram Moolenaar877151b2022-10-11 15:29:50 +01004228#endif
4229 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004230 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004231#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004232 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004233 {
4234 // do not output more of the line, only the "below" prop
4235 ptr += STRLEN(ptr);
4236# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004237 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004238# endif
4239 }
4240#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004241
4242 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004243 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004244#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004245 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004246#endif
4247 )
4248 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004249 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
4250 draw_vsep_win(wp, wlv.row);
4251 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004252 }
4253
4254 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004255 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004256 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004257 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004258 break;
4259 }
4260
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004261 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004262#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004263 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004264#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004265#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004266 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004267#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004268 && wp->w_width == Columns)
4269 {
4270 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004271 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004272
4273 // Special trick to make copy/paste of wrapped lines work with
4274 // xterm/screen: write an extra character beyond the end of
4275 // the line. This will work with all terminal types
4276 // (regardless of the xn,am settings).
4277 // Only do this on a fast tty.
4278 // Only do this if the cursor is on the current line
4279 // (something has been written in it).
4280 // Don't do this for the GUI.
4281 // Don't do this for double-width characters.
4282 // Don't do this for a window not at the right screen border.
4283 if (p_tf
4284#ifdef FEAT_GUI
4285 && !gui.in_use
4286#endif
4287 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004288 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4289 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004290 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004291 || (*mb_off2cells)(
4292 LineOffset[wlv.screen_row - 1]
4293 + (int)Columns - 2,
4294 LineOffset[wlv.screen_row]
4295 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004296 {
4297 // First make sure we are at the end of the screen line,
4298 // then output the same character again to let the
4299 // terminal know about the wrap. If the terminal doesn't
4300 // auto-wrap, we overwrite the character.
4301 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004302 screen_char(LineOffset[wlv.screen_row - 1]
4303 + (unsigned)Columns - 1,
4304 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004305
4306 // When there is a multi-byte character, just output a
4307 // space to keep it simple.
4308 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004309 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004310 out_char(' ');
4311 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004312 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004313 + (Columns - 1)]);
4314 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004315 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004316 screen_start(); // don't know where cursor is now
4317 }
4318 }
4319
Bram Moolenaar1306b362022-08-06 15:59:06 +01004320 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004321
Bram Moolenaareed9d462021-02-15 20:38:25 +01004322 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004323#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004324 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004325# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004326 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004327# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004328 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004329 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004330#endif
4331#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004332 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004333 // When the filler lines are actually below the last line of the
4334 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004335 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004336 break;
4337#endif
4338 }
4339
4340 } // for every character in the line
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004341#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004342 vim_free(text_props);
4343 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004344 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004345#endif
4346
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004347 vim_free(wlv.p_extra_free);
zeertzjq58e1e012023-06-04 18:46:28 +01004348 vim_free(wlv.saved_p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004349 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004350}