blob: e73d5b1b63fd6fe3fff01b64e8a1c99652530d30 [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;
889
890 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
891 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100892 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100893 else
894 v = wp->w_leftcol;
895
896 // check if line ends before left margin
897 if (wlv->vcol < v + wlv->col - win_col_off(wp))
898 wlv->vcol = v + wlv->col - win_col_off(wp);
899# ifdef FEAT_CONCEAL
900 // Get rid of the boguscols now, we want to draw until the right
901 // edge for 'cursorcolumn'.
902 wlv->col -= wlv->boguscols;
903 wlv->boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000904# define VCOL_HLC (wlv->vcol - wlv->vcol_off_co - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100905# else
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000906# define VCOL_HLC (wlv->vcol - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100907# endif
908
909 if (wlv->draw_color_col)
910 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
911
912 if (((wp->w_p_cuc
913 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
914 && (int)wp->w_virtcol <
915 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
916 && wlv->lnum != wp->w_cursor.lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000917 || wlv->draw_color_col
918# ifdef LINE_ATTR
919 || wlv->line_attr != 0
920# endif
921 || wlv->win_attr != 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100922# ifdef FEAT_RIGHTLEFT
923 && !wp->w_p_rl
924# endif
925 )
926 {
927 int rightmost_vcol = 0;
928 int i;
929
930 if (wp->w_p_cuc)
931 rightmost_vcol = wp->w_virtcol;
932 if (wlv->draw_color_col)
933 // determine rightmost colorcolumn to possibly draw
934 for (i = 0; wlv->color_cols[i] >= 0; ++i)
935 if (rightmost_vcol < wlv->color_cols[i])
936 rightmost_vcol = wlv->color_cols[i];
937
938 while (wlv->col < wp->w_width)
939 {
940 ScreenLines[wlv->off] = ' ';
941 if (enc_utf8)
942 ScreenLinesUC[wlv->off] = 0;
zeertzjqd0c1b772024-03-16 15:03:33 +0100943 ScreenCols[wlv->off] = wlv->vcol;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100944 ++wlv->col;
945 if (wlv->draw_color_col)
946 wlv->draw_color_col = advance_color_col(
947 VCOL_HLC, &wlv->color_cols);
948
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000949 int attr = wlv->win_attr;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000950# ifdef LINE_ATTR
zeertzjq9352c282024-03-14 18:16:56 +0100951 if (wlv->line_attr != 0)
952 attr = hl_combine_attr(attr, wlv->line_attr);
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000953# endif
zeertzjq9352c282024-03-14 18:16:56 +0100954 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
955 && wlv->lnum != wp->w_cursor.lnum)
956 attr = hl_combine_attr(attr, HL_ATTR(HLF_CUC));
957 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
958 attr = hl_combine_attr(attr, HL_ATTR(HLF_MC));
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000959 ScreenAttrs[wlv->off++] = attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100960
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000961 if (VCOL_HLC >= rightmost_vcol
962# ifdef LINE_ATTR
963 && wlv->line_attr == 0
964# endif
965 && wlv->win_attr == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100966 break;
967
968 ++wlv->vcol;
969 }
970 }
971#endif
972
zeertzjqd0c1b772024-03-16 15:03:33 +0100973 // Set increasing virtual columns in ScreenCols[] to set correct curswant
974 // (or "coladd" for 'virtualedit') when clicking after end of line.
975 wlv->screen_line_flags |= SLF_INC_VCOL;
976 wlv_screen_line(wp, wlv, TRUE);
977 wlv->screen_line_flags &= ~SLF_INC_VCOL;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100978 ++wlv->row;
979 ++wlv->screen_row;
980}
981#undef VCOL_HLC
982
983/*
984 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100985 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100986 */
987 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100988win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100989{
990 wlv->col = 0;
991 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
Christian Brabandtdd75fcf2023-10-11 21:51:19 +0200992#ifdef FEAT_LINEBREAK
993 wlv->need_lbr = FALSE;
994#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100995
996#ifdef FEAT_RIGHTLEFT
997 if (wp->w_p_rl)
998 {
999 // Rightleft window: process the text in the normal direction, but put
1000 // it in current_ScreenLine[] from right to left. Start at the
1001 // rightmost column of the window.
1002 wlv->col = wp->w_width - 1;
1003 wlv->off += wlv->col;
1004 wlv->screen_line_flags |= SLF_RIGHTLEFT;
1005 }
1006#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001007 if (save_extra)
1008 {
1009 // reset the drawing state for the start of a wrapped line
1010 wlv->draw_state = WL_START;
1011 wlv->saved_n_extra = wlv->n_extra;
1012 wlv->saved_p_extra = wlv->p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +01001013 vim_free(wlv->saved_p_extra_free);
1014 wlv->saved_p_extra_free = wlv->p_extra_free;
1015 wlv->p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001016 wlv->saved_extra_attr = wlv->extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001017 wlv->saved_n_attr_skip = wlv->n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001018 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001019 wlv->saved_c_extra = wlv->c_extra;
1020 wlv->saved_c_final = wlv->c_final;
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02001021#ifdef FEAT_LINEBREAK
1022 wlv->need_lbr = TRUE;
1023#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001024#ifdef FEAT_SYN_HL
1025 if (!(wlv->cul_screenline
1026# ifdef FEAT_DIFF
1027 && wlv->diff_hlf == (hlf_T)0
1028# endif
1029 ))
1030 wlv->saved_char_attr = wlv->char_attr;
1031 else
1032#endif
1033 wlv->saved_char_attr = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001034
1035 // these are not used until restored in win_line_continue()
Bram Moolenaar1306b362022-08-06 15:59:06 +01001036 wlv->n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001037 wlv->n_attr_skip = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001038 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001039}
1040
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001041/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001042 * Called when wlv->draw_state is set to WL_LINE.
1043 */
1044 static void
1045win_line_continue(winlinevars_T *wlv)
1046{
1047 if (wlv->saved_n_extra > 0)
1048 {
1049 // Continue item from end of wrapped line.
1050 wlv->n_extra = wlv->saved_n_extra;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001051 wlv->saved_n_extra = 0;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001052 wlv->c_extra = wlv->saved_c_extra;
1053 wlv->c_final = wlv->saved_c_final;
1054 wlv->p_extra = wlv->saved_p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +01001055 vim_free(wlv->p_extra_free);
1056 wlv->p_extra_free = wlv->saved_p_extra_free;
1057 wlv->saved_p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001058 wlv->extra_attr = wlv->saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001059 wlv->n_attr_skip = wlv->saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001060 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001061 wlv->char_attr = wlv->saved_char_attr;
1062 }
1063 else
1064 wlv->char_attr = wlv->win_attr;
1065}
1066
zeertzjqb7acea12022-12-12 13:20:43 +00001067#ifdef FEAT_SYN_HL
1068 static void
1069apply_cursorline_highlight(
1070 winlinevars_T *wlv,
1071 int sign_present UNUSED)
1072{
1073 wlv->cul_attr = HL_ATTR(HLF_CUL);
1074# ifdef FEAT_SIGNS
1075 // Combine the 'cursorline' and sign highlighting, depending on
1076 // the sign priority.
1077 if (sign_present && wlv->sattr.sat_linehl > 0)
1078 {
1079 if (wlv->sattr.sat_priority >= 100)
1080 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1081 else
1082 wlv->line_attr = hl_combine_attr(wlv->line_attr, wlv->cul_attr);
1083 }
1084 else
1085# endif
1086# if defined(FEAT_QUICKFIX)
1087 // let the line attribute overrule 'cursorline', otherwise
1088 // it disappears when both have background set;
1089 // 'cursorline' can use underline or bold to make it show
1090 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1091# else
1092 wlv->line_attr = wlv->cul_attr;
1093# endif
1094}
1095#endif
1096
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001097/*
Luuk van Baal30805a12023-05-27 22:22:10 +01001098 * Display line "lnum" of window "wp" on the screen.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001099 * Start at row "startrow", stop when "endrow" is reached.
zeertzjqebfd8562024-02-06 10:59:03 +01001100 * When only updating the number column, "number_only" is set to the height of
1101 * the line, otherwise it is set to 0.
Luuk van Baal30805a12023-05-27 22:22:10 +01001102 * "spv" is used to store information for spell checking, kept between
1103 * sequential calls for the same window.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001104 * wp->w_virtcol needs to be valid.
1105 *
1106 * Return the number of last row the line occupies.
1107 */
1108 int
1109win_line(
1110 win_T *wp,
1111 linenr_T lnum,
1112 int startrow,
1113 int endrow,
Luuk van Baal30805a12023-05-27 22:22:10 +01001114 int number_only,
1115 spellvars_T *spv UNUSED)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001116{
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001117 winlinevars_T wlv; // variables passed between functions
1118
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001119 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001120 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001121 char_u *line; // current line
1122 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001123
Bram Moolenaar1306b362022-08-06 15:59:06 +01001124#ifdef FEAT_PROP_POPUP
1125 char_u *p_extra_free2 = NULL; // another p_extra to be freed
1126#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001127#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001128 int in_linebreak = FALSE; // n_extra set for showing linebreak
1129#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01001130 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001131 int lcs_prec_todo = wp->w_lcs_chars.prec;
1132 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001133
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001134 int n_attr = 0; // chars with special attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001135 int saved_attr2 = 0; // char_attr saved for n_attr
1136 int n_attr3 = 0; // chars with overruling special attr
1137 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001138
zeertzjqb557f482023-08-22 22:07:34 +02001139 int skip_cells = 0; // nr of cells to skip for w_leftcol or
1140 // w_skipcol or concealing
1141 int skipped_cells = 0; // nr of skipped cells for virtual text
1142 // to be added to wlv.vcol later
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001143 int fromcol_prev = -2; // start of inverting after cursor
1144 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001145 int lnum_in_visual_area = FALSE;
1146 pos_T pos;
1147 long v;
1148
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001149 int attr_pri = FALSE; // char_attr has priority
1150 int area_highlighting = FALSE; // Visual or incsearch highlighting
1151 // in this line
1152 int vi_attr = 0; // attributes for Visual and incsearch
1153 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001154 int area_attr = 0; // attributes desired by highlighting
1155 int search_attr = 0; // attributes desired by 'hlsearch'
1156#ifdef FEAT_SYN_HL
1157 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1158 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001159 int prev_syntax_col = -1; // column of prev_syntax_attr
1160 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001161 int has_syntax = FALSE; // this buffer has syntax highl.
1162 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001163#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001164#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001165 int did_line = FALSE; // set to TRUE when line text done
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001166 int text_prop_count;
zeertzjq4e26a9a2023-12-03 17:50:47 +01001167 int last_textprop_text_idx = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001168 int text_prop_next = 0; // next text property to use
1169 textprop_T *text_props = NULL;
1170 int *text_prop_idxs = NULL;
1171 int text_props_active = 0;
1172 proptype_T *text_prop_type = NULL;
1173 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001174 int text_prop_attr_comb = 0; // text_prop_attr combined with
1175 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001176 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001177 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001178 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001179 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001180 int saved_search_attr = 0; // search_attr to be used when n_extra
1181 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001182 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001183 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001184#endif
1185#ifdef FEAT_SPELL
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001186 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001187# define SPWORDLEN 150
1188 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1189 int nextlinecol = 0; // column where nextline[] starts
1190 int nextline_idx = 0; // index in nextline[] where next line
1191 // starts
1192 int spell_attr = 0; // attributes desired by spelling
1193 int word_end = 0; // last byte with same spell_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001194 int cur_checked_col = 0; // checked column for current line
1195#endif
1196 int extra_check = 0; // has extra highlighting
1197 int multi_attr = 0; // attributes desired by multibyte
1198 int mb_l = 1; // multi-byte byte length
1199 int mb_c = 0; // decoded multi-byte character
1200 int mb_utf8 = FALSE; // screen char is UTF-8 char
1201 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001202#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001203 int change_start = MAXCOL; // first col of changed area
1204 int change_end = -1; // last col of changed area
1205#endif
1206 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001207 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001208 int in_multispace = FALSE; // in multiple consecutive spaces
1209 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001210#ifdef LINE_ATTR
Bram Moolenaarbf915842022-08-06 22:38:02 +01001211 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001212#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001213 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001214 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001215#ifdef FEAT_ARABIC
1216 int prev_c = 0; // previous Arabic character
1217 int prev_c1 = 0; // first composing char for prev_c
1218#endif
1219#if defined(LINE_ATTR)
1220 int did_line_attr = 0;
1221#endif
1222#ifdef FEAT_TERMINAL
1223 int get_term_attr = FALSE;
1224#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001225
Martin Tournoijba43e762022-10-13 22:12:15 +01001226#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001227 // margin columns for the screen line, needed for when 'cursorlineopt'
1228 // contains "screenline"
1229 int left_curline_col = 0;
1230 int right_curline_col = 0;
1231#endif
1232
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001233#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1234 int feedback_col = 0;
1235 int feedback_old_attr = -1;
1236#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001237
1238#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1239 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001240#endif
1241#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001242 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001243#endif
1244#ifdef FEAT_CONCEAL
1245 int syntax_flags = 0;
1246 int syntax_seqnr = 0;
1247 int prev_syntax_id = 0;
1248 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1249 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001250 int did_wcol = FALSE;
1251 int old_boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001252# define VCOL_HLC (wlv.vcol - wlv.vcol_off_co - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001253# define FIX_FOR_BOGUSCOLS \
1254 { \
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001255 wlv.n_extra += wlv.vcol_off_co; \
1256 wlv.vcol -= wlv.vcol_off_co; \
1257 wlv.vcol_off_co = 0; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001258 wlv.col -= wlv.boguscols; \
1259 old_boguscols = wlv.boguscols; \
1260 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001261 }
1262#else
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001263# define VCOL_HLC (wlv.vcol - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001264#endif
1265
1266 if (startrow > endrow) // past the end already!
1267 return startrow;
1268
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001269 CLEAR_FIELD(wlv);
1270
1271 wlv.lnum = lnum;
1272 wlv.startrow = startrow;
1273 wlv.row = startrow;
1274 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001275 wlv.fromcol = -10;
1276 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001277#ifdef FEAT_LINEBREAK
1278 wlv.vcol_sbr = -1;
1279#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001280
zeertzjqebfd8562024-02-06 10:59:03 +01001281 if (number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001282 {
1283 // To speed up the loop below, set extra_check when there is linebreak,
1284 // trailing white space and/or syntax processing to be done.
1285#ifdef FEAT_LINEBREAK
1286 extra_check = wp->w_p_lbr;
1287#endif
1288#ifdef FEAT_SYN_HL
1289 if (syntax_present(wp) && !wp->w_s->b_syn_error
1290# ifdef SYN_TIME_LIMIT
1291 && !wp->w_s->b_syn_slow
1292# endif
1293 )
1294 {
1295 // Prepare for syntax highlighting in this line. When there is an
1296 // error, stop syntax highlighting.
1297 save_did_emsg = did_emsg;
1298 did_emsg = FALSE;
1299 syntax_start(wp, lnum);
1300 if (did_emsg)
1301 wp->w_s->b_syn_error = TRUE;
1302 else
1303 {
1304 did_emsg = save_did_emsg;
1305#ifdef SYN_TIME_LIMIT
1306 if (!wp->w_s->b_syn_slow)
1307#endif
1308 {
1309 has_syntax = TRUE;
1310 extra_check = TRUE;
1311 }
1312 }
1313 }
1314
1315 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001316 wlv.color_cols = wp->w_p_cc_cols;
1317 if (wlv.color_cols != NULL)
1318 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001319#endif
1320
1321#ifdef FEAT_TERMINAL
1322 if (term_show_buffer(wp->w_buffer))
1323 {
1324 extra_check = TRUE;
1325 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001326 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001327 }
1328#endif
1329
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001330 // handle Visual active in this window
1331 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1332 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001333 pos_T *top, *bot;
1334
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001335 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1336 {
1337 // Visual is after curwin->w_cursor
1338 top = &curwin->w_cursor;
1339 bot = &VIsual;
1340 }
1341 else
1342 {
1343 // Visual is before curwin->w_cursor
1344 top = &VIsual;
1345 bot = &curwin->w_cursor;
1346 }
1347 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1348 if (VIsual_mode == Ctrl_V)
1349 {
1350 // block mode
1351 if (lnum_in_visual_area)
1352 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001353 wlv.fromcol = wp->w_old_cursor_fcol;
1354 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001355 }
1356 }
1357 else
1358 {
1359 // non-block mode
1360 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001361 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001362 else if (lnum == top->lnum)
1363 {
1364 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001365 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001366 else
1367 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001368 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001369 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001370 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001371 }
1372 }
1373 if (VIsual_mode != 'V' && lnum == bot->lnum)
1374 {
1375 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1376 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001377 wlv.fromcol = -10;
1378 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001379 }
1380 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001381 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001382 else
1383 {
1384 pos = *bot;
1385 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001386 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1387 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001388 else
1389 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001390 getvvcol(wp, &pos, NULL, NULL,
1391 (colnr_T *)&wlv.tocol);
1392 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001393 }
1394 }
1395 }
1396 }
1397
1398 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001399 if (!highlight_match && lnum == curwin->w_cursor.lnum
1400 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001401#ifdef FEAT_GUI
1402 && !gui.in_use
1403#endif
1404 )
1405 noinvcur = TRUE;
1406
1407 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001408 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001409 {
1410 area_highlighting = TRUE;
1411 vi_attr = HL_ATTR(HLF_V);
1412#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1413 if ((clip_star.available && !clip_star.owned
1414 && clip_isautosel_star())
1415 || (clip_plus.available && !clip_plus.owned
1416 && clip_isautosel_plus()))
1417 vi_attr = HL_ATTR(HLF_VNC);
1418#endif
1419 }
1420 }
1421
1422 // handle 'incsearch' and ":s///c" highlighting
1423 else if (highlight_match
1424 && wp == curwin
1425 && lnum >= curwin->w_cursor.lnum
1426 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1427 {
1428 if (lnum == curwin->w_cursor.lnum)
1429 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001430 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001431 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001432 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001433 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1434 {
1435 pos.lnum = lnum;
1436 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001437 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001438 }
1439 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001440 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001441 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001442 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1443 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001444 area_highlighting = TRUE;
1445 vi_attr = HL_ATTR(HLF_I);
1446 }
1447 }
1448
1449#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001450 wlv.filler_lines = diff_check(wp, lnum);
1451 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001452 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001453 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001454 {
1455 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001456 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001457 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001458 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001459 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001460 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001461 }
1462 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001463 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001464 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001465 area_highlighting = TRUE;
1466 }
1467 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001468 wlv.filler_lines = wp->w_topfill;
1469 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001470#endif
1471
1472#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001473 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001474 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001475 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001476#endif
1477
1478#ifdef LINE_ATTR
1479# ifdef FEAT_SIGNS
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001480 // If this line has a sign with line highlighting set wlv.line_attr.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001481 if (sign_present)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001482 wlv.line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001483# endif
1484# if defined(FEAT_QUICKFIX)
1485 // Highlight the current line in the quickfix window.
1486 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001487 wlv.line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001488# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001489 if (wlv.line_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001490 area_highlighting = TRUE;
1491#endif
1492
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001493#ifdef FEAT_SPELL
zeertzjqebfd8562024-02-06 10:59:03 +01001494 if (spv->spv_has_spell && number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001495 {
Luuk van Baal30805a12023-05-27 22:22:10 +01001496 // Prepare for spell checking.
1497 extra_check = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001498
Luuk van Baal30805a12023-05-27 22:22:10 +01001499 // When a word wrapped from the previous line the start of the
1500 // current line is valid.
1501 if (lnum == spv->spv_checked_lnum)
1502 cur_checked_col = spv->spv_checked_col;
Luuk van Baale84c7732023-05-31 18:57:36 +01001503 // Previous line was not spell checked, check for capital. This happens
1504 // for the first line in an updated region or after a closed fold.
1505 if (spv->spv_capcol_lnum == 0 && check_need_cap(wp, lnum, 0))
1506 spv->spv_cap_col = 0;
1507 else if (lnum != spv->spv_capcol_lnum)
Luuk van Baal30805a12023-05-27 22:22:10 +01001508 spv->spv_cap_col = -1;
1509 spv->spv_checked_lnum = 0;
1510
Luuk van Baal30805a12023-05-27 22:22:10 +01001511 // Get the start of the next line, so that words that wrap to the
1512 // next line are found too: "et<line-break>al.".
1513 // Trick: skip a few chars for C/shell/Vim comments
1514 nextline[SPWORDLEN] = NUL;
1515 if (lnum < wp->w_buffer->b_ml.ml_line_count)
Luuk van Baale84c7732023-05-31 18:57:36 +01001516 {
1517 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1518 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1519 }
1520 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1521
1522 // If current line is empty, check first word in next line for capital.
1523 ptr = skipwhite(line);
1524 if (*ptr == NUL)
1525 {
1526 spv->spv_cap_col = 0;
1527 spv->spv_capcol_lnum = lnum + 1;
1528 }
1529 // For checking first word with a capital skip white space.
1530 else if (spv->spv_cap_col == 0)
1531 spv->spv_cap_col = ptr - line;
1532
Luuk van Baal30805a12023-05-27 22:22:10 +01001533 // Copy the end of the current line into nextline[].
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001534 if (nextline[SPWORDLEN] == NUL)
1535 {
1536 // No next line or it is empty.
1537 nextlinecol = MAXCOL;
1538 nextline_idx = 0;
1539 }
1540 else
1541 {
zeertzjq94b7c322024-03-12 21:50:32 +01001542 v = ml_get_buf_len(wp->w_buffer, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001543 if (v < SPWORDLEN)
1544 {
1545 // Short line, use it completely and append the start of the
1546 // next line.
1547 nextlinecol = 0;
1548 mch_memmove(nextline, line, (size_t)v);
1549 STRMOVE(nextline + v, nextline + SPWORDLEN);
1550 nextline_idx = v + 1;
1551 }
1552 else
1553 {
1554 // Long line, use only the last SPWORDLEN bytes.
1555 nextlinecol = v - SPWORDLEN;
1556 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1557 nextline_idx = SPWORDLEN + 1;
1558 }
1559 }
1560 }
1561#endif
1562
Luuk van Baale84c7732023-05-31 18:57:36 +01001563 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1564 ptr = line;
1565
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001566 if (wp->w_p_list)
1567 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001568 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001569 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001570 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001571 || wp->w_lcs_chars.trail
1572 || wp->w_lcs_chars.lead
1573 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001574 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001575
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001576 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001577 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001578 {
zeertzjq94b7c322024-03-12 21:50:32 +01001579 trailcol = ml_get_buf_len(wp->w_buffer, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001580 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1581 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001582 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001583 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001584 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001585 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001586 {
1587 leadcol = 0;
1588 while (VIM_ISWHITE(ptr[leadcol]))
1589 ++leadcol;
1590 if (ptr[leadcol] == NUL)
1591 // in a line full of spaces all of them are treated as trailing
1592 leadcol = (colnr_T)0;
1593 else
1594 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001595 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001596 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001597 }
1598
Bram Moolenaard7657e92022-09-20 18:59:30 +01001599 wlv.wcr_attr = get_wcr_attr(wp);
1600 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001601 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001602 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001603 area_highlighting = TRUE;
1604 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001605
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001606 // When w_skipcol is non-zero and there is virtual text above the actual
1607 // text, then this much of the virtual text is skipped.
1608 int skipcol_in_text_prop_above = 0;
1609
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001610#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001611 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001612 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001613
1614 char_u *prop_start;
1615 text_prop_count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE);
1616 if (text_prop_count > 0)
1617 {
1618 // Make a copy of the properties, so that they are properly
1619 // aligned.
1620 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1621 if (text_props != NULL)
1622 mch_memmove(text_props, prop_start,
1623 text_prop_count * sizeof(textprop_T));
1624
1625 // Allocate an array for the indexes.
1626 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1627 if (text_prop_idxs == NULL)
1628 VIM_CLEAR(text_props);
1629
1630 if (text_props != NULL)
1631 {
1632 area_highlighting = TRUE;
1633 extra_check = TRUE;
1634
zeertzjq4e26a9a2023-12-03 17:50:47 +01001635 /* Find the last text property that inserts text. */
1636 for (int i = 0; i < text_prop_count; ++i)
1637 if (text_props[i].tp_id < 0)
1638 last_textprop_text_idx = i;
1639
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001640 // Text props "above" move the line number down to where the text
1641 // is. Only count the ones that are visible, not those that are
1642 // skipped because of w_skipcol.
1643 int text_width = wp->w_width - win_col_off(wp);
1644 for (int i = text_prop_count - 1; i >= 0; --i)
1645 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1646 {
1647 if (lnum == wp->w_topline
1648 && wp->w_skipcol - skipcol_in_text_prop_above
1649 >= text_width)
1650 {
1651 // This virtual text above is skipped, remove it from
1652 // the array.
1653 skipcol_in_text_prop_above += text_width;
1654 for (int j = i + 1; j < text_prop_count; ++j)
1655 text_props[j - 1] = text_props[j];
1656 ++i;
1657 --text_prop_count;
1658 }
1659 else
1660 ++wlv.text_prop_above_count;
1661 }
1662 }
1663 }
Bram Moolenaara572b932023-02-19 14:34:37 +00001664
zeertzjqebfd8562024-02-06 10:59:03 +01001665 if (number_only > 0)
Bram Moolenaara572b932023-02-19 14:34:37 +00001666 {
1667 // skip over rows only used for virtual text above
1668 wlv.row += wlv.text_prop_above_count;
1669 if (wlv.row > endrow)
1670 return wlv.row;
1671 wlv.screen_row += wlv.text_prop_above_count;
1672 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001673#endif
1674
zeertzjqce53e3e2023-09-01 18:49:30 +02001675#if defined(FEAT_LINEBREAK) || defined(FEAT_PROP_POPUP)
1676 colnr_T vcol_first_char = 0;
zeertzjqebfd8562024-02-06 10:59:03 +01001677 if (wp->w_p_lbr && number_only == 0)
zeertzjqce53e3e2023-09-01 18:49:30 +02001678 {
1679 chartabsize_T cts;
1680 init_chartabsize_arg(&cts, wp, lnum, 0, line, line);
1681 (void)win_lbr_chartabsize(&cts, NULL);
1682 vcol_first_char = cts.cts_first_char;
1683 clear_chartabsize_arg(&cts);
1684 }
1685#endif
1686
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001687 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1688 // first character to be displayed.
1689 if (wp->w_p_wrap)
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001690 v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001691 else
1692 v = wp->w_leftcol;
zeertzjqebfd8562024-02-06 10:59:03 +01001693 if (v > 0 && number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001694 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001695 char_u *prev_ptr = ptr;
1696 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001697 int charsize = 0;
zeertzjqb557f482023-08-22 22:07:34 +02001698 int head = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001699
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001700 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
zeertzjqb557f482023-08-22 22:07:34 +02001701 cts.cts_max_head_vcol = v;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001702 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001703 {
zeertzjqb557f482023-08-22 22:07:34 +02001704 head = 0;
1705 charsize = win_lbr_chartabsize(&cts, &head);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001706 cts.cts_vcol += charsize;
1707 prev_ptr = cts.cts_ptr;
1708 MB_PTR_ADV(cts.cts_ptr);
zeertzjqabc80812023-09-24 23:32:18 +02001709 if (wp->w_p_list)
1710 {
1711 in_multispace = *prev_ptr == ' ' && (*cts.cts_ptr == ' '
1712 || (prev_ptr > line && prev_ptr[-1] == ' '));
1713 if (!in_multispace)
1714 multispace_pos = 0;
1715 else if (cts.cts_ptr >= line + leadcol
1716 && wp->w_lcs_chars.multispace != NULL)
1717 {
1718 ++multispace_pos;
1719 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
1720 multispace_pos = 0;
1721 }
1722 else if (cts.cts_ptr < line + leadcol
1723 && wp->w_lcs_chars.leadmultispace != NULL)
1724 {
1725 ++multispace_pos;
1726 if (wp->w_lcs_chars.leadmultispace[multispace_pos] == NUL)
1727 multispace_pos = 0;
1728 }
1729 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001730 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001731 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001732 ptr = cts.cts_ptr;
1733 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001734
1735 // When:
1736 // - 'cuc' is set, or
1737 // - 'colorcolumn' is set, or
1738 // - 'virtualedit' is set, or
1739 // - the visual mode is active,
1740 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001741 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001742#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001743 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001744#endif
1745 virtual_active() ||
1746 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001747 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001748
1749 // Handle a character that's not completely on the screen: Put ptr at
1750 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001751 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001752 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001753 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001754 ptr = prev_ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001755 }
zeertzjqb557f482023-08-22 22:07:34 +02001756 if (v > wlv.vcol)
1757 skip_cells = v - wlv.vcol - head;
Bram Moolenaarcd105412022-10-10 19:50:42 +01001758
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001759 // Adjust for when the inverted text is before the screen,
1760 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001761 if (wlv.tocol <= wlv.vcol)
1762 wlv.fromcol = 0;
1763 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1764 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001765
1766#ifdef FEAT_LINEBREAK
1767 // When w_skipcol is non-zero, first line needs 'showbreak'
1768 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001769 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001770#endif
1771#ifdef FEAT_SPELL
1772 // When spell checking a word we need to figure out the start of the
1773 // word and if it's badly spelled or not.
Luuk van Baal30805a12023-05-27 22:22:10 +01001774 if (spv->spv_has_spell)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001775 {
1776 int len;
1777 colnr_T linecol = (colnr_T)(ptr - line);
1778 hlf_T spell_hlf = HLF_COUNT;
1779
1780 pos = wp->w_cursor;
1781 wp->w_cursor.lnum = lnum;
1782 wp->w_cursor.col = linecol;
1783 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1784
1785 // spell_move_to() may call ml_get() and make "line" invalid
1786 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1787 ptr = line + linecol;
1788
1789 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1790 {
1791 // no bad word found at line start, don't check until end of a
1792 // word
1793 spell_hlf = HLF_COUNT;
1794 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1795 }
1796 else
1797 {
1798 // bad word found, use attributes until end of word
1799 word_end = wp->w_cursor.col + len + 1;
1800
1801 // Turn index into actual attributes.
1802 if (spell_hlf != HLF_COUNT)
1803 spell_attr = highlight_attr[spell_hlf];
1804 }
1805 wp->w_cursor = pos;
1806
1807# ifdef FEAT_SYN_HL
1808 // Need to restart syntax highlighting for this line.
1809 if (has_syntax)
1810 syntax_start(wp, lnum);
1811# endif
1812 }
1813#endif
1814 }
1815
1816 // Correct highlighting for cursor that can't be disabled.
1817 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001818 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001819 {
1820 if (noinvcur)
1821 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001822 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001823 {
1824 // highlighting starts at cursor, let it start just after the
1825 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001826 fromcol_prev = wlv.fromcol;
1827 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001828 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001829 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001830 // restart highlighting after the cursor
1831 fromcol_prev = wp->w_virtcol;
1832 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001833 if (wlv.fromcol >= wlv.tocol)
1834 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001835 }
1836
1837#ifdef FEAT_SEARCH_EXTRA
zeertzjqebfd8562024-02-06 10:59:03 +01001838 if (number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001839 {
1840 v = (long)(ptr - line);
1841 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1842 &line, &screen_search_hl,
1843 &search_attr);
1844 ptr = line + v; // "line" may have been updated
1845 }
1846#endif
1847
1848#ifdef FEAT_SYN_HL
1849 // Cursor line highlighting for 'cursorline' in the current window.
1850 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1851 {
1852 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001853 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001854 if (!(wp == curwin && VIsual_active)
1855 && wp->w_p_culopt_flags != CULOPT_NBR)
1856 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001857 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001858 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1859
zeertzjqb7acea12022-12-12 13:20:43 +00001860 // Only apply CursorLine highlight here when "screenline" is not
1861 // present in 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001862 if (!wlv.cul_screenline)
zeertzjqb7acea12022-12-12 13:20:43 +00001863 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001864 else
1865 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001866 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001867 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1868 }
1869 area_highlighting = TRUE;
1870 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001871 }
1872#endif
1873
Bram Moolenaar1306b362022-08-06 15:59:06 +01001874 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001875
1876 // Repeat for the whole displayed line.
1877 for (;;)
1878 {
1879#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001880 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001881#endif
1882#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001883 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001884#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001885
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001886 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001887 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001888 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001889#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001890 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001891 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001892 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001893 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001894 }
1895#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001896 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001897 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001898 wlv.draw_state = WL_CMDLINE;
Sean Dewar988f7432023-08-16 14:17:36 +01001899 if (wp == cmdwin_win)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001900 {
1901 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001902 wlv.n_extra = 1;
1903 wlv.c_extra = cmdwin_type;
1904 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001905 wlv.char_attr =
1906 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001907 }
1908 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001909#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001910 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001911 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001912 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001913 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001914 }
1915#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001916#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001917 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001918 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001919 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001920 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001921 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001922 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001923 }
1924#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001925 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001926 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001927 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001928 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001929 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001930 }
zeertzjqebfd8562024-02-06 10:59:03 +01001931
1932 // When only displaying the (relative) line number and that's done,
1933 // stop here.
1934 if (number_only > 0 && wlv.draw_state == WL_NR && wlv.n_extra == 0)
1935 {
zeertzjqd0c1b772024-03-16 15:03:33 +01001936 wlv_screen_line(wp, &wlv, FALSE);
zeertzjqebfd8562024-02-06 10:59:03 +01001937 // Need to update more screen lines if:
1938 // - LineNrAbove or LineNrBelow is used, or
1939 // - still drawing filler lines.
1940 if ((wlv.row + 1 - wlv.startrow < number_only
1941 && (HL_ATTR(HLF_LNA) != 0 || HL_ATTR(HLF_LNB) != 0))
1942#ifdef FEAT_DIFF
1943 || wlv.filler_todo > 0
1944#endif
1945 )
1946 {
1947 ++wlv.row;
1948 ++wlv.screen_row;
1949 if (wlv.row == endrow)
1950 break;
1951#ifdef FEAT_DIFF
1952 --wlv.filler_todo;
1953 if (wlv.filler_todo == 0 && wp->w_botfill)
1954 break;
1955#endif
1956 win_line_start(wp, &wlv, TRUE);
1957 continue;
1958 }
1959 else
1960 break;
1961 }
1962
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001963#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001964 // Check if 'breakindent' applies and show it.
1965 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1966 if (wlv.n_extra == 0)
1967 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001968#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001969#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001970 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001971 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001972 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001973 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001974 }
1975#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001976 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001977 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001978 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001979 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001980 }
1981 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001982
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001983#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001984 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001985 && wlv.vcol >= left_curline_col
1986 && wlv.vcol < right_curline_col)
zeertzjqb7acea12022-12-12 13:20:43 +00001987 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001988#endif
1989
1990 // When still displaying '$' of change command, stop at cursor.
zeertzjqebfd8562024-02-06 10:59:03 +01001991 if (dollar_vcol >= 0 && wp == curwin
1992 && lnum == wp->w_cursor.lnum
1993 && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001994 {
zeertzjqd0c1b772024-03-16 15:03:33 +01001995 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001996 // Pretend we have finished updating the window. Except when
1997 // 'cursorcolumn' is set.
1998#ifdef FEAT_SYN_HL
1999 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002000 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002001 else
2002#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002003 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002004 break;
2005 }
2006
Bram Moolenaar1306b362022-08-06 15:59:06 +01002007 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002008 {
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002009#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002010 if (text_props != NULL)
2011 {
2012 int pi;
2013 int bcol = (int)(ptr - line);
2014
Bram Moolenaar1306b362022-08-06 15:59:06 +01002015 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002016# ifdef FEAT_LINEBREAK
2017 && !in_linebreak
2018# endif
2019 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002020 --bcol; // still working on the previous char, e.g. Tab
2021
2022 // Check if any active property ends.
2023 for (pi = 0; pi < text_props_active; ++pi)
2024 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002025 int tpi = text_prop_idxs[pi];
2026 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002027
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002028 // An inline property ends when after the start column plus
2029 // length. An "above" property ends when used and n_extra
2030 // is zero.
2031 if ((tp->tp_col != MAXCOL
2032 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002033 {
2034 if (pi + 1 < text_props_active)
2035 mch_memmove(text_prop_idxs + pi,
2036 text_prop_idxs + pi + 1,
2037 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002038 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002039 --text_props_active;
2040 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002041# ifdef FEAT_LINEBREAK
2042 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002043 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002044 syntax_attr = 0;
2045# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002046 }
2047 }
2048
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002049# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01002050 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002051 // not on the next char yet, don't start another prop
2052 --bcol;
2053# endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002054 int display_text_first = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002055
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002056 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002057 // With 'nowrap' and not in the first screen line only "below"
2058 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002059 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002060 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002061 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002062 && (wp->w_p_wrap
2063 || wlv.row == startrow
2064 || (text_props[text_prop_next].tp_flags
2065 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002066 || (bcol == 0
2067 && (text_props[text_prop_next].tp_flags
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002068 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002069 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002070 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01002071 if (text_props[text_prop_next].tp_col == MAXCOL
2072 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002073 + text_props[text_prop_next].tp_len)
2074 text_prop_idxs[text_props_active++] = text_prop_next;
2075 ++text_prop_next;
2076 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002077
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002078 if (wlv.n_extra == 0 ||
2079 (!wlv.extra_for_textprop
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002080 && !(text_prop_type != NULL &&
2081 text_prop_flags & PT_FLAG_OVERRIDE)
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002082 ))
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002083 {
2084 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002085 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002086 text_prop_flags = 0;
2087 text_prop_type = NULL;
2088 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002089 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002090 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002091 if (text_props_active > 0 && wlv.n_extra == 0
2092 && !display_text_first)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002093 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01002094 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002095 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002096 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002097
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002098 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002099 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002100
2101 // Sort the properties on priority and/or starting last.
2102 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002103 sort_text_props(wp->w_buffer, text_props,
2104 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002105
2106 for (pi = 0; pi < text_props_active; ++pi)
2107 {
2108 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002109 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002110 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002111 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002112
Bram Moolenaarcd105412022-10-10 19:50:42 +01002113 // Only use a text property that can be displayed.
2114 // Skip "after" properties when wrap is off and at the
2115 // end of the window.
2116 if (pt != NULL
2117 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2118 && tp->tp_id != -MAXCOL
2119 && !(tp->tp_id < 0
2120 && !wp->w_p_wrap
2121 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2122 | TP_FLAG_ALIGN_ABOVE
2123 | TP_FLAG_ALIGN_BELOW)) == 0
2124 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002125 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002126 if (tp->tp_col == MAXCOL
2127 && *ptr == NUL
2128 && ((wp->w_p_list && lcs_eol_one > 0
2129 && (tp->tp_flags
2130 & TP_FLAG_ALIGN_ABOVE) == 0)
2131 || (ptr == line
2132 && !did_line
2133 && (tp->tp_flags
2134 & TP_FLAG_ALIGN_BELOW))))
2135 {
2136 // skip this prop, first display the '$' after
2137 // the line or display an empty line
2138 text_prop_follows = TRUE;
2139 if (used_tpi < 0)
2140 display_text_first = TRUE;
2141 continue;
2142 }
2143
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002144 if (pt->pt_hl_id > 0)
2145 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002146 text_prop_type = pt;
2147 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002148 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002149 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2150 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002151 text_prop_flags = pt->pt_flags;
2152 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002153 used_tpi = tpi;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002154 display_text_first = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002155 }
2156 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002157 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002158 && -text_prop_id
2159 <= wp->w_buffer->b_textprop_text.ga_len)
2160 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002161 textprop_T *tp = &text_props[used_tpi];
2162 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002163 ->b_textprop_text.ga_data)[
2164 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002165 int above = (tp->tp_flags
2166 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002167 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002168
2169 // reset the ID in the copy to avoid it being used
2170 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002171 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002172
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002173 if (p != NULL)
2174 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002175 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002176 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002177 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002178 & TP_FLAG_ALIGN_BELOW);
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002179 int wrap = tp->tp_col < MAXCOL
2180 || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002181 int padding = tp->tp_col == MAXCOL
2182 && tp->tp_len > 1
2183 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002184
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002185 // Insert virtual text before the current
2186 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002187 wlv.p_extra = p;
2188 wlv.c_extra = NUL;
2189 wlv.c_final = NUL;
2190 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002191 wlv.extra_for_textprop = TRUE;
zeertzjq6e940d92023-08-17 23:21:40 +02002192 wlv.start_extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002193 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2194 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002195 n_attr = mb_charlen(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002196 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002197 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002198 if (*ptr == NUL)
2199 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002200 text_prop_flags &= ~PT_FLAG_COMBINE;
zeertzjq6b9c2022023-09-11 20:01:17 +02002201# ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002202 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002203 {
2204 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002205 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002206 wlv.need_showbreak = FALSE;
2207 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002208 }
zeertzjq6b9c2022023-09-11 20:01:17 +02002209# endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002210 if ((right || above || below || !wrap
2211 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002212 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002213 char_u *prev_p_extra = wlv.p_extra;
2214 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002215
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002216 // Take care of padding, right-align and
2217 // truncation.
2218 // Shared with win_lbr_chartabsize(), must do
2219 // exactly the same.
2220 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002221 wlv.vcol,
zeertzjq6b9c2022023-09-11 20:01:17 +02002222# ifdef FEAT_RIGHTLEFT
2223 wp->w_p_rl
2224 ? wp->w_width - wlv.col - 1
2225 :
2226# endif
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002227 wlv.col,
2228 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002229 &n_attr, &wlv.n_attr_skip,
2230 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002231 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002232 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002233 // wlv.p_extra was allocated
2234 vim_free(p_extra_free2);
2235 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002236 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002237
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002238 if (above)
2239 wlv.vcol_off_tp = wlv.n_extra;
2240
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002241 if (lcs_eol_one < 0
2242 && wp->w_p_wrap
2243 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002244 + wlv.n_extra - 2 > wp->w_width)
2245 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002246 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002247
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002248 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002249 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002250 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002251 {
2252 draw_screen_line(wp, &wlv);
2253
2254 // When line got too long for screen break
2255 // here.
2256 if (wlv.row == endrow)
2257 {
2258 ++wlv.row;
2259 break;
2260 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002261 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002262 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002263 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002264 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002265 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002266
Bram Moolenaarcd105412022-10-10 19:50:42 +01002267 // If the text didn't reach until the first window
2268 // column we need to skip cells.
2269 if (skip_cells > 0)
2270 {
2271 if (wlv.n_extra > skip_cells)
2272 {
2273 wlv.n_extra -= skip_cells;
2274 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002275 wlv.n_attr_skip -= skip_cells;
2276 if (wlv.n_attr_skip < 0)
2277 wlv.n_attr_skip = 0;
zeertzjqb557f482023-08-22 22:07:34 +02002278 skipped_cells += skip_cells;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002279 skip_cells = 0;
2280 }
2281 else
2282 {
2283 // the whole text is left of the window, drop
2284 // it and advance to the next one
2285 skip_cells -= wlv.n_extra;
zeertzjqb557f482023-08-22 22:07:34 +02002286 skipped_cells += wlv.n_extra;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002287 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002288 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002289 bail_out = TRUE;
2290 }
2291 }
2292
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002293 // If another text prop follows the condition below at
2294 // the last window column must know.
Dylan Thacker-Smith83925be2024-02-21 21:03:10 +01002295 // If this is an "above" text prop and 'nowrap' then we
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002296 // must wrap anyway.
2297 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002298 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002299 && (wp->w_p_wrap
2300 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002301 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002302
2303 if (bail_out)
2304 // starting a new line for "below"
2305 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002306 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002307 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002308 else if (text_prop_next < text_prop_count
2309 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002310 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2311 || (!wp->w_p_wrap
2312 && wlv.col == wp->w_width - 1
2313 && (text_props[text_prop_next].tp_flags
2314 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002315 // When at last-but-one character and a text property
2316 // follows after it, we may need to flush the line after
2317 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002318 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002319 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002320 }
zeertzjq6e940d92023-08-17 23:21:40 +02002321
2322 if (wlv.start_extra_for_textprop)
2323 {
2324 wlv.start_extra_for_textprop = FALSE;
2325 // restore search_attr and area_attr when n_extra
2326 // is down to zero
2327 saved_search_attr = search_attr;
2328 saved_area_attr = area_attr;
2329 search_attr = 0;
2330 area_attr = 0;
2331 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002332#endif
2333
zeertzjq6e940d92023-08-17 23:21:40 +02002334 int *area_attr_p =
2335#ifdef FEAT_PROP_POPUP
2336 wlv.extra_for_textprop ? &saved_area_attr :
2337#endif
2338 &area_attr;
2339
2340 // handle Visual or match highlighting in this line
2341 if (wlv.vcol == wlv.fromcol
2342 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
2343 && ((wlv.n_extra == 0 && (*mb_ptr2cells)(ptr) > 1)
2344 || (wlv.n_extra > 0 && wlv.p_extra != NULL
2345 && (*mb_ptr2cells)(wlv.p_extra) > 1)))
2346 || ((int)vcol_prev == fromcol_prev
2347 && vcol_prev < wlv.vcol // not at margin
2348 && wlv.vcol < wlv.tocol))
2349 *area_attr_p = vi_attr; // start highlighting
2350 else if (*area_attr_p != 0
2351 && (wlv.vcol == wlv.tocol
2352 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
2353 *area_attr_p = 0; // stop highlighting
2354
zeertzjqe500ae82023-08-17 22:35:26 +02002355#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaare38fc862022-08-11 17:24:50 +01002356 if (wlv.n_extra == 0)
2357 {
2358 // Check for start/end of 'hlsearch' and other matches.
2359 // After end, check for start/end of next match.
2360 // When another match, have to check for start again.
2361 v = (long)(ptr - line);
2362 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2363 &screen_search_hl, &has_match_conc,
2364 &match_conc, did_line_attr, lcs_eol_one,
2365 &on_last_col);
2366 ptr = line + v; // "line" may have been changed
Bram Moolenaare38fc862022-08-11 17:24:50 +01002367
2368 // Do not allow a conceal over EOL otherwise EOL will be missed
2369 // and bad things happen.
2370 if (*ptr == NUL)
2371 has_match_conc = 0;
zeertzjqb25dbb32023-08-13 18:11:05 +02002372 }
zeertzjqe500ae82023-08-17 22:35:26 +02002373#endif
zeertzjqb25dbb32023-08-13 18:11:05 +02002374
Bram Moolenaare38fc862022-08-11 17:24:50 +01002375#ifdef FEAT_DIFF
2376 if (wlv.diff_hlf != (hlf_T)0)
2377 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002378 // When there is extra text (e.g. virtual text) it gets the
2379 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002380 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2381 && wlv.n_extra == 0)
2382 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002383 if (wlv.diff_hlf == HLF_TXD
2384 && ((ptr - line > change_end && wlv.n_extra == 0)
2385 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002386 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002387 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002388 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2389 && wp->w_p_culopt_flags != CULOPT_NBR
2390 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2391 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002392 wlv.line_attr = hl_combine_attr(
2393 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002394 }
2395#endif
2396
Bram Moolenaara74fda62019-10-19 17:38:03 +02002397#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002398 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002399 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002400 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002401# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002402 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002403 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002404# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002405 // Get syntax attribute.
2406 if (has_syntax)
2407 {
2408 // Get the syntax attribute for the character. If there
2409 // is an error, disable syntax highlighting.
2410 save_did_emsg = did_emsg;
2411 did_emsg = FALSE;
2412
2413 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002414 if (v == prev_syntax_col)
2415 // at same column again
2416 syntax_attr = prev_syntax_attr;
2417 else
2418 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002419# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002420 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002421# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002422 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002423# ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01002424 spv->spv_has_spell ? &can_spell :
Bram Moolenaar34390282019-10-16 14:38:26 +02002425# endif
Luuk van Baal30805a12023-05-27 22:22:10 +01002426 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002427 prev_syntax_col = v;
2428 prev_syntax_attr = syntax_attr;
2429 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002430
Bram Moolenaar34390282019-10-16 14:38:26 +02002431 if (did_emsg)
2432 {
2433 wp->w_s->b_syn_error = TRUE;
2434 has_syntax = FALSE;
2435 syntax_attr = 0;
2436 }
2437 else
2438 did_emsg = save_did_emsg;
2439# ifdef SYN_TIME_LIMIT
2440 if (wp->w_s->b_syn_slow)
2441 has_syntax = FALSE;
2442# endif
2443
2444 // Need to get the line again, a multi-line regexp may
2445 // have made it invalid.
2446 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2447 ptr = line + v;
2448# ifdef FEAT_CONCEAL
2449 // no concealing past the end of the line, it interferes
2450 // with line highlighting
2451 if (*ptr == NUL)
2452 syntax_flags = 0;
2453 else
2454 syntax_flags = get_syntax_info(&syntax_seqnr);
2455# endif
2456 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002457 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002458# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002459 // Combine text property highlight into syntax highlight.
2460 if (text_prop_type != NULL)
2461 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002462 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002463 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2464 else
2465 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002466 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002467 }
2468# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002469#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002470
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002471 // Decide which of the highlight attributes to use.
2472 attr_pri = TRUE;
2473#ifdef LINE_ATTR
2474 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002475 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002476 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002477 if (!highlight_match)
2478 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002479 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002480# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002481 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002482# endif
2483 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002484 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002485 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002486 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002487# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002488 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002489# endif
2490 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002491 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002492 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2493 || wlv.vcol < wlv.fromcol
2494 || vcol_prev < fromcol_prev
2495 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002496 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002497 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002498 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002499# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002500 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002501# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002502 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002503# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002504 attr_pri = FALSE;
2505 }
2506#else
2507 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002508 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002509 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002510 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002511#endif
2512 else
2513 {
2514 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002515#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002516 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002517#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002518 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002519#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002520 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002521#ifdef FEAT_PROP_POPUP
2522 // override with text property highlight when "override" is TRUE
2523 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002524 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002525#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002526 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002527
2528 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002529 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002530 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002531 if (wlv.char_attr == 0)
2532 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002533 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002534 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002535 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002536
2537 // Get the next character to put on the screen.
2538
2539 // The "p_extra" points to the extra stuff that is inserted to
2540 // represent special characters (non-printable stuff) and other
2541 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002542 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002543 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2544 // "p_extra[n_extra]".
2545 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002546 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002547 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002548 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002549 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002550 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2551 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002552 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2553 if (enc_utf8 && utf_char2len(c) > 1)
2554 {
2555 mb_utf8 = TRUE;
2556 u8cc[0] = 0;
2557 c = 0xc0;
2558 }
2559 else
2560 mb_utf8 = FALSE;
2561 }
2562 else
2563 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002564 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002565 if (has_mbyte)
2566 {
2567 mb_c = c;
2568 if (enc_utf8)
2569 {
2570 // If the UTF-8 character is more than one byte:
2571 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002572 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002573 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002574 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002575 mb_l = 1;
2576 else if (mb_l > 1)
2577 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002578 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002579 mb_utf8 = TRUE;
2580 c = 0xc0;
2581 }
2582 }
2583 else
2584 {
2585 // if this is a DBCS character, put it in "mb_c"
2586 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002587 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002588 mb_l = 1;
2589 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002590 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002591 }
2592 if (mb_l == 0) // at the NUL at end-of-line
2593 mb_l = 1;
2594
2595 // If a double-width char doesn't fit display a '>' in the
2596 // last column.
2597 if ((
2598# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002599 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002600# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002601 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002602 && (*mb_char2cells)(mb_c) == 2)
2603 {
2604 c = '>';
2605 mb_c = c;
2606 mb_l = 1;
2607 mb_utf8 = FALSE;
2608 multi_attr = HL_ATTR(HLF_AT);
2609#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002610 if (wlv.cul_attr)
2611 multi_attr = hl_combine_attr(
2612 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002613#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002614 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002615
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002616 // put the pointer back to output the double-width
2617 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002618 ++wlv.n_extra;
2619 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002620 }
2621 else
2622 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002623 wlv.n_extra -= mb_l - 1;
2624 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002625 }
2626 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002627 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002628 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002629 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002630#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002631 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002632 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002633 // Only restore search_attr and area_attr after "n_extra" in
2634 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002635 if (wlv.saved_n_extra <= 0)
2636 {
2637 if (search_attr == 0)
2638 search_attr = saved_search_attr;
2639 if (area_attr == 0 && *ptr != NUL)
2640 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002641
2642 if (wlv.extra_for_textprop)
2643 // wlv.extra_attr should be used at this position but
2644 // not any further.
2645 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002646 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002647
2648 wlv.extra_for_textprop = FALSE;
2649 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002650 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002651#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002652 }
2653 else
2654 {
2655#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002656 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002657#endif
zeertzjqe500ae82023-08-17 22:35:26 +02002658 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002659
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002660 // Get a character from the line itself.
2661 c = *ptr;
2662#ifdef FEAT_LINEBREAK
2663 c0 = *ptr;
2664#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002665 if (c == NUL)
zeertzjqb557f482023-08-22 22:07:34 +02002666 {
2667#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002668 // text is finished, may display a "below" virtual text
2669 did_line = TRUE;
2670#endif
zeertzjqb557f482023-08-22 22:07:34 +02002671 // no more cells to skip
2672 skip_cells = 0;
2673 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002674
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002675 if (has_mbyte)
2676 {
2677 mb_c = c;
2678 if (enc_utf8)
2679 {
2680 // If the UTF-8 character is more than one byte: Decode it
2681 // into "mb_c".
2682 mb_l = utfc_ptr2len(ptr);
2683 mb_utf8 = FALSE;
2684 if (mb_l > 1)
2685 {
2686 mb_c = utfc_ptr2char(ptr, u8cc);
2687 // Overlong encoded ASCII or ASCII with composing char
2688 // is displayed normally, except a NUL.
2689 if (mb_c < 0x80)
2690 {
2691 c = mb_c;
2692#ifdef FEAT_LINEBREAK
2693 c0 = mb_c;
2694#endif
2695 }
2696 mb_utf8 = TRUE;
2697
2698 // At start of the line we can have a composing char.
2699 // Draw it as a space with a composing char.
2700 if (utf_iscomposing(mb_c))
2701 {
2702 int i;
2703
2704 for (i = Screen_mco - 1; i > 0; --i)
2705 u8cc[i] = u8cc[i - 1];
2706 u8cc[0] = mb_c;
2707 mb_c = ' ';
2708 }
2709 }
2710
2711 if ((mb_l == 1 && c >= 0x80)
2712 || (mb_l >= 1 && mb_c == 0)
2713 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2714 {
2715 // Illegal UTF-8 byte: display as <xx>.
2716 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002717 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002718# ifdef FEAT_RIGHTLEFT
2719 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002720 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002721# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002722 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002723 c = *wlv.p_extra;
2724 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002725 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002726 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2727 wlv.c_extra = NUL;
2728 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002729 if (area_attr == 0 && search_attr == 0)
2730 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002731 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002732 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002733 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002734 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002735 }
2736 }
2737 else if (mb_l == 0) // at the NUL at end-of-line
2738 mb_l = 1;
2739#ifdef FEAT_ARABIC
2740 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2741 {
2742 // Do Arabic shaping.
2743 int pc, pc1, nc;
2744 int pcc[MAX_MCO];
2745
2746 // The idea of what is the previous and next
2747 // character depends on 'rightleft'.
2748 if (wp->w_p_rl)
2749 {
2750 pc = prev_c;
2751 pc1 = prev_c1;
2752 nc = utf_ptr2char(ptr + mb_l);
2753 prev_c1 = u8cc[0];
2754 }
2755 else
2756 {
2757 pc = utfc_ptr2char(ptr + mb_l, pcc);
2758 nc = prev_c;
2759 pc1 = pcc[0];
2760 }
2761 prev_c = mb_c;
2762
2763 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2764 }
2765 else
2766 prev_c = mb_c;
2767#endif
2768 }
2769 else // enc_dbcs
2770 {
2771 mb_l = MB_BYTE2LEN(c);
2772 if (mb_l == 0) // at the NUL at end-of-line
2773 mb_l = 1;
2774 else if (mb_l > 1)
2775 {
2776 // We assume a second byte below 32 is illegal.
2777 // Hopefully this is OK for all double-byte encodings!
2778 if (ptr[1] >= 32)
2779 mb_c = (c << 8) + ptr[1];
2780 else
2781 {
2782 if (ptr[1] == NUL)
2783 {
2784 // head byte at end of line
2785 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002786 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002787 }
2788 else
2789 {
2790 // illegal tail byte
2791 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002792 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002793 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002794 wlv.p_extra = wlv.extra;
2795 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002796 wlv.c_extra = NUL;
2797 wlv.c_final = NUL;
2798 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002799 if (area_attr == 0 && search_attr == 0)
2800 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002801 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002802 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002803 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002804 // save current attr
2805 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002806 }
2807 mb_c = c;
2808 }
2809 }
2810 }
2811 // If a double-width char doesn't fit display a '>' in the
2812 // last column; the character is displayed at the start of the
2813 // next line.
2814 if ((
2815# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002816 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002817# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002818 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002819 && (*mb_char2cells)(mb_c) == 2)
2820 {
2821 c = '>';
2822 mb_c = c;
2823 mb_utf8 = FALSE;
2824 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002825 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002826 // Put pointer back so that the character will be
2827 // displayed at the start of the next line.
2828 --ptr;
2829#ifdef FEAT_CONCEAL
2830 did_decrement_ptr = TRUE;
2831#endif
2832 }
2833 else if (*ptr != NUL)
2834 ptr += mb_l - 1;
2835
2836 // If a double-width char doesn't fit at the left side display
2837 // a '<' in the first column. Don't do this for unprintable
2838 // characters.
zeertzjqb557f482023-08-22 22:07:34 +02002839 if (skip_cells > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002840 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002841 wlv.n_extra = 1;
2842 wlv.c_extra = MB_FILLER_CHAR;
2843 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002844 c = ' ';
2845 if (area_attr == 0 && search_attr == 0)
2846 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002847 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002848 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002849 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002850 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002851 }
2852 mb_c = c;
2853 mb_utf8 = FALSE;
2854 mb_l = 1;
2855 }
2856
2857 }
2858 ++ptr;
2859
2860 if (extra_check)
2861 {
2862#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002863 // Check spelling (unless at the end of the line).
2864 // Only do this when there is no syntax highlighting, the
2865 // @Spell cluster is not used or the current syntax item
2866 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002867 v = (long)(ptr - line);
Luuk van Baal30805a12023-05-27 22:22:10 +01002868 if (spv->spv_has_spell && v >= word_end && v > cur_checked_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002869 {
2870 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002871 // do not calculate cap_col at the end of the line or when
2872 // only white space is following
2873 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002874# ifdef FEAT_SYN_HL
2875 !has_syntax ||
2876# endif
2877 can_spell))
2878 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002879 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002880 int len;
2881 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002882
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002883 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002884 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002885
2886 // Use nextline[] if possible, it has the start of the
2887 // next line concatenated.
2888 if ((prev_ptr - line) - nextlinecol >= 0)
2889 p = nextline + (prev_ptr - line) - nextlinecol;
2890 else
2891 p = prev_ptr;
Luuk van Baal30805a12023-05-27 22:22:10 +01002892 spv->spv_cap_col -= (int)(prev_ptr - line);
2893 len = spell_check(wp, p, &spell_hlf, &spv->spv_cap_col,
2894 spv->spv_unchanged);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002895 word_end = v + len;
2896
2897 // In Insert mode only highlight a word that
2898 // doesn't touch the cursor.
2899 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002900 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002901 && wp->w_cursor.lnum == lnum
2902 && wp->w_cursor.col >=
2903 (colnr_T)(prev_ptr - line)
2904 && wp->w_cursor.col < (colnr_T)word_end)
2905 {
2906 spell_hlf = HLF_COUNT;
2907 spell_redraw_lnum = lnum;
2908 }
2909
2910 if (spell_hlf == HLF_COUNT && p != prev_ptr
2911 && (p - nextline) + len > nextline_idx)
2912 {
2913 // Remember that the good word continues at the
2914 // start of the next line.
Luuk van Baal30805a12023-05-27 22:22:10 +01002915 spv->spv_checked_lnum = lnum + 1;
2916 spv->spv_checked_col = (p - nextline) + len
2917 - nextline_idx;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002918 }
2919
2920 // Turn index into actual attributes.
2921 if (spell_hlf != HLF_COUNT)
2922 spell_attr = highlight_attr[spell_hlf];
2923
Luuk van Baal30805a12023-05-27 22:22:10 +01002924 if (spv->spv_cap_col > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002925 {
2926 if (p != prev_ptr
Luuk van Baal30805a12023-05-27 22:22:10 +01002927 && (p - nextline) + spv->spv_cap_col
2928 >= nextline_idx)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002929 {
2930 // Remember that the word in the next line
2931 // must start with a capital.
Luuk van Baal30805a12023-05-27 22:22:10 +01002932 spv->spv_capcol_lnum = lnum + 1;
2933 spv->spv_cap_col = ((p - nextline)
2934 + spv->spv_cap_col - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002935 }
2936 else
2937 // Compute the actual column.
Luuk van Baal30805a12023-05-27 22:22:10 +01002938 spv->spv_cap_col += (prev_ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002939 }
2940 }
2941 }
2942 if (spell_attr != 0)
2943 {
2944 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002945 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2946 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002947 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002948 wlv.char_attr = hl_combine_attr(spell_attr,
2949 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002950 }
2951#endif
2952#ifdef FEAT_LINEBREAK
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02002953 // we don't want linebreak to apply for lines that start with
2954 // leading spaces, followed by long letters (since it would add
2955 // a break at the beginning of a line and this might be unexpected)
2956 //
2957 // So only allow to linebreak, once we have found chars not in
2958 // 'breakat' in the line.
2959 if ( wp->w_p_lbr && !wlv.need_lbr && c != NUL &&
2960 !VIM_ISBREAK((int)*ptr))
2961 wlv.need_lbr = TRUE;
2962#endif
2963#ifdef FEAT_LINEBREAK
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002964 // Found last space before word: check for line break.
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02002965 if (wp->w_p_lbr && c0 == c && wlv.need_lbr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002966 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2967 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002968 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2969 : 0;
2970 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002971 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002972
zeertzjqce53e3e2023-09-01 18:49:30 +02002973 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol
2974# ifdef FEAT_PROP_POPUP
2975 - vcol_first_char,
2976# endif
2977 line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002978# ifdef FEAT_PROP_POPUP
2979 // do not want virtual text counted here
2980 cts.cts_has_prop_with_text = FALSE;
2981# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002982 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002983 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002984
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002985 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002986 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002987 // line break, but for TABs the highlighting should
2988 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002989 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002990
Bram Moolenaar1306b362022-08-06 15:59:06 +01002991 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002992# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002993 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002994 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002995 wp->w_buffer->b_p_vts_array) - 1;
2996# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002997 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002998 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002999# endif
3000
Bram Moolenaar1306b362022-08-06 15:59:06 +01003001 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
3002 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01003003# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01003004 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00003005 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00003006# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003007 if (VIM_ISWHITE(c))
3008 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01003009# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003010 if (c == TAB)
3011 // See "Tab alignment" below.
3012 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01003013# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003014 if (!wp->w_p_list)
3015 c = ' ';
3016 }
3017 }
3018#endif
zeertzjqabc80812023-09-24 23:32:18 +02003019 if (wp->w_p_list)
3020 {
3021 in_multispace = c == ' ' && (*ptr == ' '
3022 || (prev_ptr > line && prev_ptr[-1] == ' '));
3023 if (!in_multispace)
3024 multispace_pos = 0;
3025 }
zeertzjqf14b8ba2021-09-10 16:58:30 +02003026
Bram Moolenaareed9d462021-02-15 20:38:25 +01003027 // 'list': Change char 160 to 'nbsp' and space to 'space'
3028 // setting in 'listchars'. But not when the character is
3029 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003030 if (wp->w_p_list
3031 && ((((c == 160 && mb_l == 1)
3032 || (mb_utf8
3033 && ((mb_c == 160 && mb_l == 2)
3034 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01003035 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003036 || (c == ' '
3037 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02003038 && (wp->w_lcs_chars.space
3039 || (in_multispace
3040 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01003041 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003042 && ptr - line <= trailcol)))
3043 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02003044 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
3045 {
3046 c = wp->w_lcs_chars.multispace[multispace_pos++];
3047 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
3048 multispace_pos = 0;
3049 }
3050 else
3051 c = (c == ' ') ? wp->w_lcs_chars.space
3052 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003053 if (area_attr == 0 && search_attr == 0)
3054 {
3055 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003056 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003057 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003058 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003059 }
3060 mb_c = c;
3061 if (enc_utf8 && utf_char2len(c) > 1)
3062 {
3063 mb_utf8 = TRUE;
3064 u8cc[0] = 0;
3065 c = 0xc0;
3066 }
3067 else
3068 mb_utf8 = FALSE;
3069 }
3070
zeertzjq2e7cba32022-06-10 15:30:32 +01003071 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
3072 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003073 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003074 if (leadcol != 0 && in_multispace && ptr < line + leadcol
3075 && wp->w_lcs_chars.leadmultispace != NULL)
3076 {
3077 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01003078 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
3079 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003080 multispace_pos = 0;
3081 }
3082
3083 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
3084 c = wp->w_lcs_chars.trail;
3085
3086 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
3087 c = wp->w_lcs_chars.lead;
3088
zeertzjq2e7cba32022-06-10 15:30:32 +01003089 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003090 c = wp->w_lcs_chars.space;
3091
3092
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003093 if (!attr_pri)
3094 {
3095 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003096 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003097 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003098 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003099 }
3100 mb_c = c;
3101 if (enc_utf8 && utf_char2len(c) > 1)
3102 {
3103 mb_utf8 = TRUE;
3104 u8cc[0] = 0;
3105 c = 0xc0;
3106 }
3107 else
3108 mb_utf8 = FALSE;
3109 }
3110 }
3111
3112 // Handling of non-printable characters.
3113 if (!vim_isprintc(c))
3114 {
3115 // when getting a character from the file, we may have to
3116 // turn it into something else on the way to putting it
3117 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01003118 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003119 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003120 int tab_len = 0;
3121 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003122#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003123 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01003124
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003125 // only adjust the tab_len, when at the first column
3126 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01003127 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003128 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003129#endif
3130 // tab amount depends on current column
3131#ifdef FEAT_VARTABS
3132 tab_len = tabstop_padding(vcol_adjusted,
3133 wp->w_buffer->b_p_ts,
3134 wp->w_buffer->b_p_vts_array) - 1;
3135#else
3136 tab_len = (int)wp->w_buffer->b_p_ts
3137 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
3138#endif
3139
3140#ifdef FEAT_LINEBREAK
3141 if (!wp->w_p_lbr || !wp->w_p_list)
3142#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003143 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003144 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01003145 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003146 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003147#ifdef FEAT_LINEBREAK
3148 else
3149 {
3150 char_u *p;
3151 int len;
3152 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003153 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003154
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003155# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003156 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003157 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003158 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003159
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003160 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003161 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003162 && old_boguscols > 0
3163 && wlv.n_extra > tab_len)
3164 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003165# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003166 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003167 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003168 // If wlv.n_extra > 0, it gives the number of chars
3169 // to use for a tab, else we need to calculate the
3170 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003171 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3172 len = tab_len * tab2_len;
3173 if (wp->w_lcs_chars.tab3)
3174 len += mb_char2len(wp->w_lcs_chars.tab3)
3175 - tab2_len;
3176 if (wlv.n_extra > 0)
3177 len += wlv.n_extra - tab_len;
3178 c = wp->w_lcs_chars.tab1;
3179 p = alloc(len + 1);
3180 if (p == NULL)
3181 wlv.n_extra = 0;
3182 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003183 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003184 vim_memset(p, ' ', len);
3185 p[len] = NUL;
3186 vim_free(wlv.p_extra_free);
3187 wlv.p_extra_free = p;
3188 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003189 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003190 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003191
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003192 if (*p == NUL)
3193 {
3194 tab_len = i;
3195 break;
3196 }
3197
3198 // if tab3 is given, use it for the last
3199 // char
3200 if (wp->w_lcs_chars.tab3
3201 && i == tab_len - 1)
3202 lcs = wp->w_lcs_chars.tab3;
3203 p += mb_char2bytes(lcs, p);
3204 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003205 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003206 }
3207 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003208# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003209 // n_extra will be increased by
3210 // FIX_FOX_BOGUSCOLS macro below, so need to
3211 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003212 if (wlv.vcol_off_co > 0)
3213 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003214# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003215 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003216 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003217 }
3218#endif
3219#ifdef FEAT_CONCEAL
3220 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003221 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003222
3223 // Tab alignment should be identical regardless of
3224 // 'conceallevel' value. So tab compensates of all
3225 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003226 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003227 // line. Note that the tab can be longer than
3228 // 'tabstop' when there are concealed characters.
3229 FIX_FOR_BOGUSCOLS;
3230
3231 // Make sure, the highlighting for the tab char will be
3232 // correctly set further below (effectively reverts the
zeertzjq010e1532024-03-14 18:22:17 +01003233 // FIX_FOR_BOGUSCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003234 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003235 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003236 tab_len += vc_saved;
3237 }
3238#endif
3239 mb_utf8 = FALSE; // don't draw as UTF-8
3240 if (wp->w_p_list)
3241 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003242 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003243 ? wp->w_lcs_chars.tab3
3244 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003245#ifdef FEAT_LINEBREAK
h-east194555c2023-03-02 18:49:09 +00003246 if (wp->w_p_lbr && wlv.p_extra != NULL
3247 && *wlv.p_extra != NUL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003248 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003249 else
3250#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003251 wlv.c_extra = wp->w_lcs_chars.tab2;
3252 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003253 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003254 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003255 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003256 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003257 mb_c = c;
3258 if (enc_utf8 && utf_char2len(c) > 1)
3259 {
3260 mb_utf8 = TRUE;
3261 u8cc[0] = 0;
3262 c = 0xc0;
3263 }
3264 }
3265 else
3266 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003267 wlv.c_final = NUL;
3268 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003269 c = ' ';
3270 }
3271 }
3272 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003273 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003274 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003275 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3276 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003277 && VIsual_mode != Ctrl_V
3278 && (
3279# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003280 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003281# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003282 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003283 && !(noinvcur
3284 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003285 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003286 && lcs_eol_one > 0)
3287 {
3288 // Display a '$' after the line or highlight an extra
3289 // character if the line break is included.
3290#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3291 // For a diff line the highlighting continues after the
3292 // "$".
3293 if (
3294# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003295 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003296# ifdef LINE_ATTR
3297 &&
3298# endif
3299# endif
3300# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003301 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003302# endif
3303 )
3304#endif
3305 {
3306 // In virtualedit, visual selections may extend
3307 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003308 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003309 && wlv.tocol != MAXCOL
3310 && wlv.vcol < wlv.tocol))
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01003311 wlv.p_extra = (char_u *)"";
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003312 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003313 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003314 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3315 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003316 else
3317 c = ' ';
3318 lcs_eol_one = -1;
3319 --ptr; // put it back at the NUL
3320 if (!attr_pri)
3321 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003322 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003323 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003324 n_attr = 1;
3325 }
3326 mb_c = c;
3327 if (enc_utf8 && utf_char2len(c) > 1)
3328 {
3329 mb_utf8 = TRUE;
3330 u8cc[0] = 0;
3331 c = 0xc0;
3332 }
3333 else
3334 mb_utf8 = FALSE; // don't draw as UTF-8
3335 }
3336 else if (c != NUL)
3337 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003338 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3339 if (wlv.n_extra == 0)
3340 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003341#ifdef FEAT_RIGHTLEFT
3342 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003343 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003344#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003345 wlv.c_extra = NUL;
3346 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003347#ifdef FEAT_LINEBREAK
3348 if (wp->w_p_lbr)
3349 {
3350 char_u *p;
3351
Bram Moolenaar1306b362022-08-06 15:59:06 +01003352 c = *wlv.p_extra;
3353 p = alloc(wlv.n_extra + 1);
3354 vim_memset(p, ' ', wlv.n_extra);
3355 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3356 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003357 vim_free(wlv.p_extra_free);
3358 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003359 }
3360 else
3361#endif
3362 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003363 wlv.n_extra = byte2cells(c) - 1;
3364 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003365 }
3366 if (!attr_pri)
3367 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003368 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003369 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003370 HL_ATTR(HLF_8));
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003371#ifdef FEAT_PROP_POPUP
3372 if (text_prop_type != NULL &&
3373 text_prop_flags & PT_FLAG_OVERRIDE)
3374 wlv.extra_attr = hl_combine_attr(text_prop_attr, wlv.extra_attr);
3375#endif
3376
Bram Moolenaar1306b362022-08-06 15:59:06 +01003377 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003378 }
3379 mb_utf8 = FALSE; // don't draw as UTF-8
3380 }
3381 else if (VIsual_active
3382 && (VIsual_mode == Ctrl_V
3383 || VIsual_mode == 'v')
3384 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003385 && wlv.tocol != MAXCOL
3386 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003387 && (
3388#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003389 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003390#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003391 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003392 {
3393 c = ' ';
3394 --ptr; // put it back at the NUL
3395 }
3396#if defined(LINE_ATTR)
3397 else if ((
3398# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003399 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003400# endif
3401# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003402 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003403# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003404 wlv.line_attr != 0
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
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003410# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003411 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003412# endif
3413 < wp->w_width)))
3414 {
3415 // Highlight until the right side of the window
3416 c = ' ';
3417 --ptr; // put it back at the NUL
3418
3419 // Remember we do the char for line highlighting.
3420 ++did_line_attr;
3421
3422 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003423 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003424 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003425 || (wp->w_p_list &&
3426 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003427 wlv.char_attr = wlv.line_attr;
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003428#ifdef FEAT_SIGNS
3429 // At end of line: if Sign is present with line highlight, reset char_attr
Christian Brabandte1eaae22023-08-19 22:36:12 +02003430 // but not when cursorline is active
3431 if (sign_present && wlv.sattr.sat_linehl > 0 && wlv.draw_state == WL_LINE
3432 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum))
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003433 wlv.char_attr = wlv.sattr.sat_linehl;
3434#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003435# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003436 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003437 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003438 wlv.diff_hlf = HLF_CHD;
3439 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003440 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003441 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003442 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3443 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003444 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003445 || (wlv.vcol >= left_curline_col
3446 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003447 wlv.char_attr = hl_combine_attr(
3448 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003449 }
3450 }
3451# endif
3452# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003453 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003454 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003455 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003456 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3457 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003458 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003459 if (!wlv.cul_screenline
3460 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003461 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003462 wlv.char_attr = hl_combine_attr(
3463 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003464 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003465 else if (wlv.line_attr)
3466 wlv.char_attr = hl_combine_attr(
3467 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003468 }
3469# endif
3470 }
3471#endif
3472 }
3473
3474#ifdef FEAT_CONCEAL
3475 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003476 && (wp != curwin || lnum != wp->w_cursor.lnum
3477 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003478 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3479 && !(lnum_in_visual_area
3480 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3481 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003482 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003483 if (((prev_syntax_id != syntax_seqnr
3484 && (syntax_flags & HL_CONCEAL) != 0)
3485 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003486 && (syn_get_sub_char() != NUL
3487 || (has_match_conc && match_conc)
3488 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003489 && wp->w_p_cole != 3)
3490 {
3491 // First time at this concealed item: display one
3492 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003493 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003494 c = match_conc;
3495 else if (syn_get_sub_char() != NUL)
3496 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003497 else if (wp->w_lcs_chars.conceal != NUL)
3498 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003499 else
3500 c = ' ';
3501
zeertzjq010e1532024-03-14 18:22:17 +01003502 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3503 // When the first char to be concealed is double-width,
3504 // need to advance one more virtual column.
3505 wlv.n_extra++;
3506
3507 mb_c = c;
3508 if (enc_utf8 && utf_char2len(c) > 1)
3509 {
3510 mb_utf8 = TRUE;
3511 u8cc[0] = 0;
3512 c = 0xc0;
3513 }
3514 else
3515 mb_utf8 = FALSE; // don't draw as UTF-8
3516
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003517 prev_syntax_id = syntax_seqnr;
3518
Bram Moolenaar1306b362022-08-06 15:59:06 +01003519 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003520 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003521 wlv.vcol += wlv.n_extra;
3522 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003523 {
3524# ifdef FEAT_RIGHTLEFT
3525 if (wp->w_p_rl)
3526 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003527 wlv.col -= wlv.n_extra;
3528 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003529 }
3530 else
3531# endif
3532 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003533 wlv.boguscols += wlv.n_extra;
3534 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003535 }
3536 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003537 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003538 n_attr = 0;
3539 }
zeertzjqb557f482023-08-22 22:07:34 +02003540 else if (skip_cells == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003541 {
3542 is_concealing = TRUE;
zeertzjqb557f482023-08-22 22:07:34 +02003543 skip_cells = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003544 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003545 }
3546 else
3547 {
3548 prev_syntax_id = 0;
3549 is_concealing = FALSE;
3550 }
3551
zeertzjqb557f482023-08-22 22:07:34 +02003552 if (skip_cells > 0 && did_decrement_ptr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003553 // not showing the '>', put pointer back to avoid getting stuck
3554 ++ptr;
3555
3556#endif // FEAT_CONCEAL
3557 }
3558
3559#ifdef FEAT_CONCEAL
3560 // In the cursor line and we may be concealing characters: correct
3561 // the cursor column when we reach its position.
zeertzjq253ff4d2024-03-13 20:38:26 +01003562 // With 'virtualedit' we may never reach cursor position, but we still
3563 // need to correct the cursor column, so do that at end of line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003564 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003565 && wp == curwin && lnum == wp->w_cursor.lnum
3566 && conceal_cursor_line(wp)
zeertzjq253ff4d2024-03-13 20:38:26 +01003567 && (wlv.vcol + skip_cells >= wp->w_virtcol || c == NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003568 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003569# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003570 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003571 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003572 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003573# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003574 wp->w_wcol = wlv.col - wlv.boguscols;
zeertzjq253ff4d2024-03-13 20:38:26 +01003575 if (wlv.vcol + skip_cells < wp->w_virtcol)
3576 // Cursor beyond end of the line with 'virtualedit'.
3577 wp->w_wcol += wp->w_virtcol - wlv.vcol - skip_cells;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003578 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003579 did_wcol = TRUE;
3580 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003581# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003582 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003583# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003584 }
3585#endif
3586
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003587 // Use "wlv.extra_attr", but don't override visual selection
3588 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003589 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3590 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003591 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003592 && (!attr_pri
3593#ifdef FEAT_PROP_POPUP
3594 || (text_prop_flags & PT_FLAG_OVERRIDE)
3595#endif
3596 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003597 {
3598#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003599 if (wlv.line_attr)
3600 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003601 else
3602#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003603 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003604#ifdef FEAT_PROP_POPUP
3605 if (reset_extra_attr)
3606 {
3607 reset_extra_attr = FALSE;
3608 wlv.extra_attr = 0;
3609 }
3610#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003611 }
3612
3613#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3614 // XIM don't send preedit_start and preedit_end, but they send
3615 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3616 // im_is_preediting() here.
3617 if (p_imst == IM_ON_THE_SPOT
3618 && xic != NULL
3619 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003620 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003621 && !p_imdisable
3622 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003623 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003624 {
3625 colnr_T tcol;
3626
3627 if (preedit_end_col == MAXCOL)
3628 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3629 else
3630 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003631 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003632 {
3633 if (feedback_old_attr < 0)
3634 {
3635 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003636 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003637 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003638 wlv.char_attr = im_get_feedback_attr(feedback_col);
3639 if (wlv.char_attr < 0)
3640 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003641 feedback_col++;
3642 }
3643 else if (feedback_old_attr >= 0)
3644 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003645 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003646 feedback_old_attr = -1;
3647 feedback_col = 0;
3648 }
3649 }
3650#endif
3651 // Handle the case where we are in column 0 but not on the first
3652 // character of the line and the user wants us to show us a
3653 // special character (via 'listchars' option "precedes:<char>".
3654 if (lcs_prec_todo != NUL
3655 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003656 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3657 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003658#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003659 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003660#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003661 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003662 && c != NUL)
3663 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003664 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003665 lcs_prec_todo = NUL;
3666 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3667 {
3668 // Double-width character being overwritten by the "precedes"
3669 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003670 wlv.c_extra = MB_FILLER_CHAR;
3671 wlv.c_final = NUL;
3672 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003673 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003674 wlv.extra_attr =
3675 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003676 }
3677 mb_c = c;
3678 if (enc_utf8 && utf_char2len(c) > 1)
3679 {
3680 mb_utf8 = TRUE;
3681 u8cc[0] = 0;
3682 c = 0xc0;
3683 }
3684 else
3685 mb_utf8 = FALSE; // don't draw as UTF-8
3686 if (!attr_pri)
3687 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003688 saved_attr3 = wlv.char_attr; // save current attr
3689 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003690 n_attr3 = 1;
3691 }
3692 }
3693
3694 // At end of the text line or just after the last character.
3695 if ((c == NUL
3696#if defined(LINE_ATTR)
3697 || did_line_attr == 1
3698#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003699 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003700 {
3701#ifdef FEAT_SEARCH_EXTRA
3702 // flag to indicate whether prevcol equals startcol of search_hl or
3703 // one of the matches
3704 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3705 (long)(ptr - line) - (c == NUL));
3706#endif
3707 // Invert at least one char, used for Visual and empty line or
3708 // highlight match at end of line. If it's beyond the last
3709 // char on the screen, just overwrite that one (tricky!) Not
3710 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003711 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003712 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003713 && (VIsual_mode != Ctrl_V
3714 || lnum == VIsual.lnum
3715 || lnum == curwin->w_cursor.lnum)
3716 && c == NUL)
3717#ifdef FEAT_SEARCH_EXTRA
3718 // highlight 'hlsearch' match at end of line
3719 || (prevcol_hl_flag
3720# ifdef FEAT_SYN_HL
3721 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3722 && !(wp == curwin && VIsual_active))
3723# endif
3724# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003725 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003726# endif
3727# if defined(LINE_ATTR)
3728 && did_line_attr <= 1
3729# endif
3730 )
3731#endif
3732 ))
3733 {
3734 int n = 0;
3735
3736#ifdef FEAT_RIGHTLEFT
3737 if (wp->w_p_rl)
3738 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003739 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003740 n = 1;
3741 }
3742 else
3743#endif
3744 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003745 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003746 n = -1;
3747 }
3748 if (n != 0)
3749 {
3750 // At the window boundary, highlight the last character
3751 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003752 wlv.off += n;
3753 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003754 }
3755 else
3756 {
3757 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003758 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003759 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003760 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003761 }
3762#ifdef FEAT_SEARCH_EXTRA
3763 if (area_attr == 0)
3764 {
3765 // Use attributes from match with highest priority among
3766 // 'search_hl' and the match list.
3767 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003768 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003769 }
3770#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003771 ScreenAttrs[wlv.off] = wlv.char_attr;
zeertzjqd0c1b772024-03-16 15:03:33 +01003772 ScreenCols[wlv.off] = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003773#ifdef FEAT_RIGHTLEFT
3774 if (wp->w_p_rl)
3775 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003776 --wlv.col;
3777 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003778 }
3779 else
3780#endif
3781 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003782 ++wlv.col;
3783 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003784 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003785 ++wlv.vcol;
3786 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003787 }
3788 }
3789
3790 // At end of the text line.
3791 if (c == NUL)
3792 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003793#ifdef FEAT_PROP_POPUP
3794 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003795 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003796 // Put the pointer back to the NUL.
3797 --ptr;
3798 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003799 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003800 else
3801#endif
3802 {
3803 draw_screen_line(wp, &wlv);
3804
3805 // Update w_cline_height and w_cline_folded if the cursor line
3806 // was updated (saves a call to plines() later).
3807 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3808 {
3809 curwin->w_cline_row = startrow;
3810 curwin->w_cline_height = wlv.row - startrow;
3811#ifdef FEAT_FOLDING
3812 curwin->w_cline_folded = FALSE;
3813#endif
3814 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3815 }
3816 break;
3817 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003818 }
3819
3820 // Show "extends" character from 'listchars' if beyond the line end and
3821 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003822 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003823 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003824 && wp->w_p_list
3825 && !wp->w_p_wrap
3826#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003827 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003828#endif
3829 && (
3830#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003831 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003832#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003833 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003834 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003835 || lcs_eol_one > 0
3836 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
zeertzjq6a389722023-08-27 19:04:14 +02003837 || *wlv.p_extra != NUL))
3838#ifdef FEAT_PROP_POPUP
zeertzjq4e26a9a2023-12-03 17:50:47 +01003839 || text_prop_next <= last_textprop_text_idx
zeertzjq6a389722023-08-27 19:04:14 +02003840#endif
3841 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003842 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003843 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003844 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003845 mb_c = c;
3846 if (enc_utf8 && utf_char2len(c) > 1)
3847 {
3848 mb_utf8 = TRUE;
3849 u8cc[0] = 0;
3850 c = 0xc0;
3851 }
3852 else
3853 mb_utf8 = FALSE;
3854 }
3855
3856#ifdef FEAT_SYN_HL
3857 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003858 if (wlv.draw_color_col)
3859 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003860
3861 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3862 // highlight the cursor position itself.
3863 // Also highlight the 'colorcolumn' if it is different than
3864 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003865 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3866 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003867 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003868 if (((wlv.draw_state == WL_LINE
3869 || wlv.draw_state == WL_BRI
3870 || wlv.draw_state == WL_SBR)
3871 && !lnum_in_visual_area
3872 && search_attr == 0
3873 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003874# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003875 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003876# endif
3877 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003878 {
3879 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3880 && lnum != wp->w_cursor.lnum)
3881 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003882 vcol_save_attr = wlv.char_attr;
3883 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3884 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003885 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003886 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003887 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003888 vcol_save_attr = wlv.char_attr;
3889 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003890 }
3891 }
3892#endif
3893
zeertzjq8fc6a1d2023-08-20 18:12:54 +02003894 if (wlv.draw_state == WL_LINE)
3895 vcol_prev = wlv.vcol;
3896
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003897 // Store character to be displayed.
3898 // Skip characters that are left of the screen for 'nowrap'.
zeertzjqb557f482023-08-22 22:07:34 +02003899 if (wlv.draw_state < WL_LINE || skip_cells <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003900 {
3901 // Store the character.
3902#if defined(FEAT_RIGHTLEFT)
3903 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3904 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003905 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003906 --wlv.off;
3907 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003908 }
3909#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003910 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003911 if (enc_dbcs == DBCS_JPNU)
3912 {
3913 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003914 ScreenLines[wlv.off] = 0x8e;
3915 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003916 }
3917 else if (enc_utf8)
3918 {
3919 if (mb_utf8)
3920 {
3921 int i;
3922
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003923 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003924 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003925 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003926 for (i = 0; i < Screen_mco; ++i)
3927 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003928 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003929 if (u8cc[i] == 0)
3930 break;
3931 }
3932 }
3933 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003934 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003935 }
3936 if (multi_attr)
3937 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003938 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003939 multi_attr = 0;
3940 }
3941 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003942 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003943
zeertzjqdb54e982023-09-21 16:33:09 +02003944 if (wlv.draw_state > WL_NR
3945#ifdef FEAT_DIFF
3946 && wlv.filler_todo <= 0
3947#endif
3948 )
3949 ScreenCols[wlv.off] = wlv.vcol;
3950 else
3951 ScreenCols[wlv.off] = -1;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003952
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003953 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3954 {
3955 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003956 ++wlv.off;
3957 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003958 if (enc_utf8)
3959 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003960 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003961 else
3962 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003963 ScreenLines[wlv.off] = mb_c & 0xff;
zeertzjqdb54e982023-09-21 16:33:09 +02003964
Bram Moolenaar1306b362022-08-06 15:59:06 +01003965 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003966#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003967 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003968#endif
3969 )
zeertzjqdb54e982023-09-21 16:33:09 +02003970 ScreenCols[wlv.off] = ++wlv.vcol;
3971 else
3972 ScreenCols[wlv.off] = -1;
3973
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003974 // When "wlv.tocol" is halfway a character, set it to the end
3975 // of the character, otherwise highlighting won't stop.
3976 if (wlv.tocol == wlv.vcol)
3977 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003978
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003979#ifdef FEAT_RIGHTLEFT
3980 if (wp->w_p_rl)
3981 {
3982 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003983 --wlv.off;
3984 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003985 }
3986#endif
3987 }
3988#ifdef FEAT_RIGHTLEFT
3989 if (wp->w_p_rl)
3990 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003991 --wlv.off;
3992 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003993 }
3994 else
3995#endif
3996 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003997 ++wlv.off;
3998 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003999 }
4000 }
4001#ifdef FEAT_CONCEAL
4002 else if (wp->w_p_cole > 0 && is_concealing)
4003 {
zeertzjq010e1532024-03-14 18:22:17 +01004004 int concealed_wide = has_mbyte && (*mb_char2cells)(mb_c) > 1;
4005
zeertzjqb557f482023-08-22 22:07:34 +02004006 --skip_cells;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004007 ++wlv.vcol_off_co;
zeertzjq010e1532024-03-14 18:22:17 +01004008 if (concealed_wide)
4009 {
4010 // When a double-width char is concealed,
4011 // need to advance one more virtual column.
4012 ++wlv.vcol;
4013 ++wlv.vcol_off_co;
4014 }
4015
Bram Moolenaar1306b362022-08-06 15:59:06 +01004016 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004017 wlv.vcol_off_co += wlv.n_extra;
zeertzjq010e1532024-03-14 18:22:17 +01004018
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004019 if (wp->w_p_wrap)
4020 {
4021 // Special voodoo required if 'wrap' is on.
4022 //
4023 // Advance the column indicator to force the line
4024 // drawing to wrap early. This will make the line
4025 // take up the same screen space when parts are concealed,
4026 // so that cursor line computations aren't messed up.
4027 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004028 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004029 // trailing junk to be written out of the screen line
4030 // we are building, 'boguscols' keeps track of the number
4031 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004032 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004033 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004034 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004035# ifdef FEAT_RIGHTLEFT
4036 if (wp->w_p_rl)
4037 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004038 wlv.col -= wlv.n_extra;
4039 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004040 }
4041 else
4042# endif
4043 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004044 wlv.col += wlv.n_extra;
4045 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004046 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01004047 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004048 n_attr = 0;
4049 }
4050
zeertzjq010e1532024-03-14 18:22:17 +01004051 if (concealed_wide)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004052 {
4053 // Need to fill two screen columns.
4054# ifdef FEAT_RIGHTLEFT
4055 if (wp->w_p_rl)
4056 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004057 --wlv.boguscols;
4058 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004059 }
4060 else
4061# endif
4062 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004063 ++wlv.boguscols;
4064 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004065 }
4066 }
4067
4068# ifdef FEAT_RIGHTLEFT
4069 if (wp->w_p_rl)
4070 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004071 --wlv.boguscols;
4072 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004073 }
4074 else
4075# endif
4076 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004077 ++wlv.boguscols;
4078 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004079 }
4080 }
4081 else
4082 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004083 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004084 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004085 wlv.vcol += wlv.n_extra;
4086 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004087 n_attr = 0;
4088 }
4089 }
4090
4091 }
4092#endif // FEAT_CONCEAL
4093 else
zeertzjqb557f482023-08-22 22:07:34 +02004094 --skip_cells;
4095
4096 if (wlv.draw_state > WL_NR && skipped_cells > 0)
4097 {
4098 wlv.vcol += skipped_cells;
4099 skipped_cells = 0;
4100 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004101
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004102 // Only advance the "wlv.vcol" when after the 'number' or
4103 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004104 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004105#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004106 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004107#endif
4108 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004109 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004110
4111#ifdef FEAT_SYN_HL
4112 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004113 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004114#endif
4115
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004116 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01004117 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
4118 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004119
4120 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01004121 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004122 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004123 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004124 if (wlv.n_attr_skip > 0)
4125 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004126
4127 // At end of screen line and there is more to come: Display the line
4128 // so far. If there is no more to display it is caught above.
4129 if ((
4130#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004131 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004132#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004133 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01004134 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02004135 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004136#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004137 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004138#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004139#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004140 || text_prop_above || text_prop_follows
zeertzjq4e26a9a2023-12-03 17:50:47 +01004141 || text_prop_next <= last_textprop_text_idx
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004142#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01004143 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01004144 && lcs_eol_one != -1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004145 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
4146 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004147 )
4148 {
4149#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01004150 wlv.col -= wlv.boguscols;
zeertzjq21b0a3d2024-03-13 20:06:34 +01004151 // Apply 'cursorline' and 'wincolor' highlight.
4152 if (wlv.boguscols != 0 && (
4153# ifdef LINE_ATTR
4154 wlv.line_attr != 0 ||
4155# endif
4156 wlv.win_attr != 0
4157 )
4158 )
4159 {
4160 int attr = wlv.win_attr;
4161# ifdef LINE_ATTR
4162 if (wlv.line_attr != 0)
4163 attr = hl_combine_attr(attr, wlv.line_attr);
4164# endif
4165 while ((
4166# ifdef FEAT_RIGHTLEFT
4167 wp->w_p_rl ? wlv.col >= 0 :
4168# endif
4169 wlv.col < wp->w_width))
4170 {
4171 ScreenLines[wlv.off] = ' ';
4172 if (enc_utf8)
4173 ScreenLinesUC[wlv.off] = 0;
4174 ScreenAttrs[wlv.off] = attr;
zeertzjqd0c1b772024-03-16 15:03:33 +01004175 ScreenCols[wlv.off] = wlv.vcol - 1;
zeertzjq21b0a3d2024-03-13 20:06:34 +01004176# ifdef FEAT_RIGHTLEFT
4177 if (wp->w_p_rl)
4178 {
4179 wlv.off--;
4180 wlv.col--;
4181 wlv.boguscols++;
4182 }
4183 else
4184# endif
4185 {
4186 wlv.off++;
4187 wlv.col++;
4188 wlv.boguscols--;
4189 }
4190 }
4191 }
zeertzjqd0c1b772024-03-16 15:03:33 +01004192 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar75008662022-10-04 22:40:56 +01004193 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004194 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004195 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004196#else
zeertzjqd0c1b772024-03-16 15:03:33 +01004197 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004198#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004199 ++wlv.row;
4200 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004201
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01004202 // When not wrapping and finished diff lines, break here.
4203 if (!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004204#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004205 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004206#endif
4207#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01004208 && !text_prop_above
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01004209 && !text_prop_follows
Bram Moolenaar877151b2022-10-11 15:29:50 +01004210#endif
4211 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004212 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004213#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004214 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004215 {
4216 // do not output more of the line, only the "below" prop
4217 ptr += STRLEN(ptr);
4218# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004219 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004220# endif
4221 }
4222#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004223
4224 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004225 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004226#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004227 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004228#endif
4229 )
4230 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004231 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
4232 draw_vsep_win(wp, wlv.row);
4233 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004234 }
4235
4236 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004237 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004238 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004239 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004240 break;
4241 }
4242
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004243 if (screen_cur_row == wlv.screen_row - 1
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
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004247#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004248 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004249#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004250 && wp->w_width == Columns)
4251 {
4252 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004253 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004254
4255 // Special trick to make copy/paste of wrapped lines work with
4256 // xterm/screen: write an extra character beyond the end of
4257 // the line. This will work with all terminal types
4258 // (regardless of the xn,am settings).
4259 // Only do this on a fast tty.
4260 // Only do this if the cursor is on the current line
4261 // (something has been written in it).
4262 // Don't do this for the GUI.
4263 // Don't do this for double-width characters.
4264 // Don't do this for a window not at the right screen border.
4265 if (p_tf
4266#ifdef FEAT_GUI
4267 && !gui.in_use
4268#endif
4269 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004270 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4271 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004272 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004273 || (*mb_off2cells)(
4274 LineOffset[wlv.screen_row - 1]
4275 + (int)Columns - 2,
4276 LineOffset[wlv.screen_row]
4277 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004278 {
4279 // First make sure we are at the end of the screen line,
4280 // then output the same character again to let the
4281 // terminal know about the wrap. If the terminal doesn't
4282 // auto-wrap, we overwrite the character.
4283 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004284 screen_char(LineOffset[wlv.screen_row - 1]
4285 + (unsigned)Columns - 1,
4286 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004287
4288 // When there is a multi-byte character, just output a
4289 // space to keep it simple.
4290 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004291 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004292 out_char(' ');
4293 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004294 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004295 + (Columns - 1)]);
4296 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004297 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004298 screen_start(); // don't know where cursor is now
4299 }
4300 }
4301
Bram Moolenaar1306b362022-08-06 15:59:06 +01004302 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004303
Bram Moolenaareed9d462021-02-15 20:38:25 +01004304 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004305#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004306 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004307# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004308 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004309# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004310 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004311 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004312#endif
4313#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004314 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004315 // When the filler lines are actually below the last line of the
4316 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004317 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004318 break;
4319#endif
4320 }
4321
4322 } // for every character in the line
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004323#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004324 vim_free(text_props);
4325 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004326 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004327#endif
4328
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004329 vim_free(wlv.p_extra_free);
zeertzjq58e1e012023-06-04 18:46:28 +01004330 vim_free(wlv.saved_p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004331 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004332}