blob: 08b6f45c441adfeb367039f4d3647b5d1adba671 [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 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100527 if (wp->w_skipcol > 0 && wlv->startrow == 0
528 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100529 wlv->need_showbreak = FALSE;
zeertzjq23627722023-12-27 19:08:53 +0100530
531 // Correct start of highlighted area for 'breakindent',
532 if (wlv->fromcol >= wlv->vcol
533 && wlv->fromcol < wlv->vcol + wlv->n_extra)
534 wlv->fromcol = wlv->vcol + wlv->n_extra;
535
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100536 // Correct end of highlighted area for 'breakindent',
537 // required when 'linebreak' is also set.
538 if (wlv->tocol == wlv->vcol)
539 wlv->tocol += wlv->n_extra;
540 }
541 }
542}
543#endif
544
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100545#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
546 static void
547handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
548{
549# ifdef FEAT_DIFF
550 if (wlv->filler_todo > 0)
551 {
552 // Draw "deleted" diff line(s).
553 if (char2cells(wp->w_fill_chars.diff) > 1)
554 {
555 wlv->c_extra = '-';
556 wlv->c_final = NUL;
557 }
558 else
559 {
560 wlv->c_extra = wp->w_fill_chars.diff;
561 wlv->c_final = NUL;
562 }
563# ifdef FEAT_RIGHTLEFT
564 if (wp->w_p_rl)
565 wlv->n_extra = wlv->col + 1;
566 else
567# endif
568 wlv->n_extra = wp->w_width - wlv->col;
569 wlv->char_attr = HL_ATTR(HLF_DED);
570 }
571# endif
572
573# ifdef FEAT_LINEBREAK
574 char_u *sbr = get_showbreak_value(wp);
575 if (*sbr != NUL && wlv->need_showbreak)
576 {
577 // Draw 'showbreak' at the start of each broken line.
578 wlv->p_extra = sbr;
579 wlv->c_extra = NUL;
580 wlv->c_final = NUL;
581 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100582 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100583 wlv->need_showbreak = FALSE;
584 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100585
586 // Correct start of highlighted area for 'showbreak'.
587 if (wlv->fromcol >= wlv->vcol && wlv->fromcol < wlv->vcol_sbr)
588 wlv->fromcol = wlv->vcol_sbr;
589
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100590 // Correct end of highlighted area for 'showbreak',
591 // required when 'linebreak' is also set.
592 if (wlv->tocol == wlv->vcol)
593 wlv->tocol += wlv->n_extra;
594 // combine 'showbreak' with 'wincolor'
595 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
596# ifdef FEAT_SYN_HL
597 // combine 'showbreak' with 'cursorline'
598 if (wlv->cul_attr != 0)
599 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
600# endif
601 }
602# endif
603}
604#endif
605
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100606#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100607/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100608 * Return the cell size of virtual text after truncation.
609 */
610 static int
611textprop_size_after_trunc(
612 win_T *wp,
613 int flags, // TP_FLAG_ALIGN_*
614 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100615 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100616 char_u *text,
617 int *n_used_ptr)
618{
619 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100620 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100621 int len = (int)STRLEN(text);
622 int strsize = 0;
623 int n_used;
624
Bram Moolenaar7e017462022-10-11 21:02:09 +0100625 // if the remaining size is to small and 'wrap' is set we wrap anyway and
626 // use the next line
627 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100628 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100629 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100630 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100631 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
632 {
633 int clen = ptr2cells(text + n_used);
634
635 if (strsize + clen > space)
636 break;
637 strsize += clen;
638 }
639 *n_used_ptr = n_used;
640 return strsize;
641}
642
643/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100644 * Take care of padding, right-align and truncation of virtual text after a
645 * line.
646 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
647 * padding, right-align and truncation. Otherwise only the size is computed.
648 * When "n_attr" is NULL returns the number of screen cells used.
649 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100650 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100651 int
652text_prop_position(
653 win_T *wp,
654 textprop_T *tp,
porygonisaduck38854b52022-11-27 20:55:05 +0000655 int vcol, // current text column
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100656 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100657 int *n_extra, // nr of bytes for virtual text
658 char_u **p_extra, // virtual text
659 int *n_attr, // attribute cells, NULL if not used
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000660 int *n_attr_skip, // cells to skip attr, NULL if not used
661 int do_skip) // skip_cells is not zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200662{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100663 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100664 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100665 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
Bram Moolenaar1aeb3eb2023-01-01 14:04:51 +0000666 int wrap = tp->tp_col < MAXCOL || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100667 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
porygonisaduck38854b52022-11-27 20:55:05 +0000668 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100669 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100670 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100671 int before = room; // spaces before the text
672 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100673 int n_used = *n_extra;
674 char_u *l = NULL;
675 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100676 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100677 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200678
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100679 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100680 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100681 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100682
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100683 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100684 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100685 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100686 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar2354b662023-04-23 21:42:25 +0100687 if (after < 0)
688 {
689 // text "above" has too much padding to fit
690 padding += after;
691 after = 0;
692 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100693 }
694 else
695 {
696 // Right-align: fill with before
697 if (right)
698 before -= cells;
porygonisaduck38854b52022-11-27 20:55:05 +0000699
700 // Below-align: empty line add one character
Bram Moolenaar7c02ad92022-11-29 21:37:13 +0000701 if (below && vcol == 0 && col_with_padding == col_off
702 && wp->w_width - col_off == before)
703 col_with_padding += 1;
porygonisaduck38854b52022-11-27 20:55:05 +0000704
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100705 if (before < 0
706 || !(right || below)
porygonisaduck38854b52022-11-27 20:55:05 +0000707 || (below ? (col_with_padding <= col_off || !wp->w_p_wrap)
708 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100709 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100710 if (right && (wrap
711 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100712 {
713 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100714 before = wp->w_width - col_off - strsize + room;
715 if (before < 0)
716 before = 0;
717 else
718 n_used = *n_extra;
719 }
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000720 else if (below && before > vcol && do_skip)
721 before -= vcol;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100722 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100723 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100724 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100725 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100726
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100727 // With 'nowrap' add one to show the "extends" character if needed (it
728 // doesn't show if the text just fits).
729 if (!wp->w_p_wrap
730 && n_used < *n_extra
731 && wp->w_lcs_chars.ext != NUL
732 && wp->w_p_list)
733 ++n_used;
734
735 // add 1 for NUL, 2 for when '…' is used
736 if (n_attr != NULL)
Christian Brabandtf1cc4d52023-08-12 00:14:14 +0200737 l = alloc(n_used + before + after + (padding > 0 ? padding : 0) + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100738 if (n_attr == NULL || l != NULL)
739 {
740 int off = 0;
741
742 if (n_attr != NULL)
743 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100744 vim_memset(l, ' ', before);
745 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100746 if (padding > 0)
747 {
748 vim_memset(l + off, ' ', padding);
749 off += padding;
750 }
751 vim_strncpy(l + off, *p_extra, n_used);
752 off += n_used;
753 }
754 else
755 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100756 off = before + after + padding + n_used;
757 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100758 }
759 if (n_attr != NULL)
760 {
761 if (n_used < *n_extra && wp->w_p_wrap)
762 {
763 char_u *lp = l + off - 1;
764
765 if (has_mbyte)
766 {
h-east4c42c7e2023-04-17 21:44:57 +0100767 char_u buf[MB_MAXBYTES + 1];
768 char_u *cp = buf;
769
770 // change the last character to '…', converted to the
771 // current 'encoding'
772 STRCPY(buf, "…");
773 if (!enc_utf8)
774 {
775 vimconv_T vc;
776
777 vc.vc_type = CONV_NONE;
778 convert_setup(&vc, (char_u *)"utf-8", p_enc);
779 if (vc.vc_type != CONV_NONE)
780 {
781 cp = string_convert(&vc, buf, NULL);
782 if (cp == NULL)
783 {
784 // when conversion fails use '>'
785 cp = buf;
786 STRCPY(buf, ">");
787 }
788 convert_setup(&vc, NULL, NULL);
789 }
790 }
791
792 lp -= (*mb_ptr2cells)(cp) - 1;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100793 lp -= (*mb_head_off)(l, lp);
h-east4c42c7e2023-04-17 21:44:57 +0100794 STRCPY(lp, cp);
Bram Moolenaar13845c42022-10-09 15:26:03 +0100795 n_used = lp - l + 3 - before - padding;
h-east4c42c7e2023-04-17 21:44:57 +0100796 if (cp != buf)
797 vim_free(cp);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100798 }
799 else
800 // change last character to '>'
801 *lp = '>';
802 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100803 else if (after > 0)
804 {
805 vim_memset(l + off, ' ', after);
806 l[off + after] = NUL;
807 }
808
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100809 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100810 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100811 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100812 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100813 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100814
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);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100818 }
819 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100820 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100821
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100822 if (n_attr == NULL)
823 return cells;
824 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200825}
826#endif
827
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100828/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100829 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100830 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
831 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100832 */
833 static void
834wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
835{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100836 if (wlv->row == 0 && wp->w_skipcol > 0
837#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100838 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100839 && *get_showbreak_value(wp) == NUL
840#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100841 // do not overwrite the 'listchars' "precedes" text with "<<<"
842 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100843 {
844 int off = (int)(current_ScreenLine - ScreenLines);
zeertzjqecb87dd2023-06-03 19:45:06 +0100845 int max_off = off + screen_Columns;
Bram Moolenaareb4de622022-10-15 13:42:17 +0100846 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100847
Bram Moolenaareb4de622022-10-15 13:42:17 +0100848 if (wp->w_p_nu && wp->w_p_rnu)
849 // Do not overwrite the line number, change "123 text" to
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100850 // "123<<<xt".
Bram Moolenaareb4de622022-10-15 13:42:17 +0100851 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
852 {
853 ++off;
854 ++skip;
855 }
856
857 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100858 {
zeertzjqecb87dd2023-06-03 19:45:06 +0100859 if ((*mb_off2cells)(off, max_off) > 1)
860 // When the first half of a double-width character is
861 // overwritten, change the second half to a space.
862 ScreenLines[off + 1] = ' ';
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100863 ScreenLines[off] = '<';
864 if (enc_utf8)
865 ScreenLinesUC[off] = 0;
866 ScreenAttrs[off] = HL_ATTR(HLF_AT);
867 ++off;
868 }
869 }
870
871 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
872 negative_width ? -wp->w_width : wp->w_width,
873 wlv->screen_line_flags);
874}
875
876/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100877 * Called when finished with the line: draw the screen line and handle any
878 * highlighting until the right of the window.
879 */
880 static void
881draw_screen_line(win_T *wp, winlinevars_T *wlv)
882{
883#ifdef FEAT_SYN_HL
884 long v;
885
886 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
887 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100888 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100889 else
890 v = wp->w_leftcol;
891
892 // check if line ends before left margin
893 if (wlv->vcol < v + wlv->col - win_col_off(wp))
894 wlv->vcol = v + wlv->col - win_col_off(wp);
895# ifdef FEAT_CONCEAL
896 // Get rid of the boguscols now, we want to draw until the right
897 // edge for 'cursorcolumn'.
898 wlv->col -= wlv->boguscols;
899 wlv->boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000900# define VCOL_HLC (wlv->vcol - wlv->vcol_off_co - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100901# else
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000902# define VCOL_HLC (wlv->vcol - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100903# endif
904
905 if (wlv->draw_color_col)
906 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
907
908 if (((wp->w_p_cuc
909 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
910 && (int)wp->w_virtcol <
911 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
912 && wlv->lnum != wp->w_cursor.lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000913 || wlv->draw_color_col
914# ifdef LINE_ATTR
915 || wlv->line_attr != 0
916# endif
917 || wlv->win_attr != 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100918# ifdef FEAT_RIGHTLEFT
919 && !wp->w_p_rl
920# endif
921 )
922 {
923 int rightmost_vcol = 0;
924 int i;
925
926 if (wp->w_p_cuc)
927 rightmost_vcol = wp->w_virtcol;
928 if (wlv->draw_color_col)
929 // determine rightmost colorcolumn to possibly draw
930 for (i = 0; wlv->color_cols[i] >= 0; ++i)
931 if (rightmost_vcol < wlv->color_cols[i])
932 rightmost_vcol = wlv->color_cols[i];
933
934 while (wlv->col < wp->w_width)
935 {
936 ScreenLines[wlv->off] = ' ';
937 if (enc_utf8)
938 ScreenLinesUC[wlv->off] = 0;
939 ScreenCols[wlv->off] = MAXCOL;
940 ++wlv->col;
941 if (wlv->draw_color_col)
942 wlv->draw_color_col = advance_color_col(
943 VCOL_HLC, &wlv->color_cols);
944
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000945 int attr = wlv->win_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100946 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000947 attr = HL_ATTR(HLF_CUC);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100948 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000949 attr = HL_ATTR(HLF_MC);
950# ifdef LINE_ATTR
951 else if (wlv->line_attr != 0)
952 attr = wlv->line_attr;
953# endif
954 ScreenAttrs[wlv->off++] = attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100955
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000956 if (VCOL_HLC >= rightmost_vcol
957# ifdef LINE_ATTR
958 && wlv->line_attr == 0
959# endif
960 && wlv->win_attr == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100961 break;
962
963 ++wlv->vcol;
964 }
965 }
966#endif
967
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100968 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100969 ++wlv->row;
970 ++wlv->screen_row;
971}
972#undef VCOL_HLC
973
974/*
975 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100976 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100977 */
978 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100979win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100980{
981 wlv->col = 0;
982 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
Christian Brabandtdd75fcf2023-10-11 21:51:19 +0200983#ifdef FEAT_LINEBREAK
984 wlv->need_lbr = FALSE;
985#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100986
987#ifdef FEAT_RIGHTLEFT
988 if (wp->w_p_rl)
989 {
990 // Rightleft window: process the text in the normal direction, but put
991 // it in current_ScreenLine[] from right to left. Start at the
992 // rightmost column of the window.
993 wlv->col = wp->w_width - 1;
994 wlv->off += wlv->col;
995 wlv->screen_line_flags |= SLF_RIGHTLEFT;
996 }
997#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100998 if (save_extra)
999 {
1000 // reset the drawing state for the start of a wrapped line
1001 wlv->draw_state = WL_START;
1002 wlv->saved_n_extra = wlv->n_extra;
1003 wlv->saved_p_extra = wlv->p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +01001004 vim_free(wlv->saved_p_extra_free);
1005 wlv->saved_p_extra_free = wlv->p_extra_free;
1006 wlv->p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001007 wlv->saved_extra_attr = wlv->extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001008 wlv->saved_n_attr_skip = wlv->n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001009 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001010 wlv->saved_c_extra = wlv->c_extra;
1011 wlv->saved_c_final = wlv->c_final;
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02001012#ifdef FEAT_LINEBREAK
1013 wlv->need_lbr = TRUE;
1014#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001015#ifdef FEAT_SYN_HL
1016 if (!(wlv->cul_screenline
1017# ifdef FEAT_DIFF
1018 && wlv->diff_hlf == (hlf_T)0
1019# endif
1020 ))
1021 wlv->saved_char_attr = wlv->char_attr;
1022 else
1023#endif
1024 wlv->saved_char_attr = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001025
1026 // these are not used until restored in win_line_continue()
Bram Moolenaar1306b362022-08-06 15:59:06 +01001027 wlv->n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001028 wlv->n_attr_skip = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001029 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001030}
1031
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001032/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001033 * Called when wlv->draw_state is set to WL_LINE.
1034 */
1035 static void
1036win_line_continue(winlinevars_T *wlv)
1037{
1038 if (wlv->saved_n_extra > 0)
1039 {
1040 // Continue item from end of wrapped line.
1041 wlv->n_extra = wlv->saved_n_extra;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001042 wlv->saved_n_extra = 0;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001043 wlv->c_extra = wlv->saved_c_extra;
1044 wlv->c_final = wlv->saved_c_final;
1045 wlv->p_extra = wlv->saved_p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +01001046 vim_free(wlv->p_extra_free);
1047 wlv->p_extra_free = wlv->saved_p_extra_free;
1048 wlv->saved_p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001049 wlv->extra_attr = wlv->saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001050 wlv->n_attr_skip = wlv->saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001051 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001052 wlv->char_attr = wlv->saved_char_attr;
1053 }
1054 else
1055 wlv->char_attr = wlv->win_attr;
1056}
1057
zeertzjqb7acea12022-12-12 13:20:43 +00001058#ifdef FEAT_SYN_HL
1059 static void
1060apply_cursorline_highlight(
1061 winlinevars_T *wlv,
1062 int sign_present UNUSED)
1063{
1064 wlv->cul_attr = HL_ATTR(HLF_CUL);
1065# ifdef FEAT_SIGNS
1066 // Combine the 'cursorline' and sign highlighting, depending on
1067 // the sign priority.
1068 if (sign_present && wlv->sattr.sat_linehl > 0)
1069 {
1070 if (wlv->sattr.sat_priority >= 100)
1071 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1072 else
1073 wlv->line_attr = hl_combine_attr(wlv->line_attr, wlv->cul_attr);
1074 }
1075 else
1076# endif
1077# if defined(FEAT_QUICKFIX)
1078 // let the line attribute overrule 'cursorline', otherwise
1079 // it disappears when both have background set;
1080 // 'cursorline' can use underline or bold to make it show
1081 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1082# else
1083 wlv->line_attr = wlv->cul_attr;
1084# endif
1085}
1086#endif
1087
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001088/*
Luuk van Baal30805a12023-05-27 22:22:10 +01001089 * Display line "lnum" of window "wp" on the screen.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001090 * Start at row "startrow", stop when "endrow" is reached.
Luuk van Baal30805a12023-05-27 22:22:10 +01001091 * When "number_only" is TRUE only update the number column.
1092 * "spv" is used to store information for spell checking, kept between
1093 * sequential calls for the same window.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001094 * wp->w_virtcol needs to be valid.
1095 *
1096 * Return the number of last row the line occupies.
1097 */
1098 int
1099win_line(
1100 win_T *wp,
1101 linenr_T lnum,
1102 int startrow,
1103 int endrow,
Luuk van Baal30805a12023-05-27 22:22:10 +01001104 int number_only,
1105 spellvars_T *spv UNUSED)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001106{
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001107 winlinevars_T wlv; // variables passed between functions
1108
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001109 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001110 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001111 char_u *line; // current line
1112 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001113
Bram Moolenaar1306b362022-08-06 15:59:06 +01001114#ifdef FEAT_PROP_POPUP
1115 char_u *p_extra_free2 = NULL; // another p_extra to be freed
1116#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001117#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001118 int in_linebreak = FALSE; // n_extra set for showing linebreak
1119#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001120 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +01001121 // displaying eol at end-of-line
1122 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001123 int lcs_prec_todo = wp->w_lcs_chars.prec;
1124 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001125
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001126 int n_attr = 0; // chars with special attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001127 int saved_attr2 = 0; // char_attr saved for n_attr
1128 int n_attr3 = 0; // chars with overruling special attr
1129 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001130
zeertzjqb557f482023-08-22 22:07:34 +02001131 int skip_cells = 0; // nr of cells to skip for w_leftcol or
1132 // w_skipcol or concealing
1133 int skipped_cells = 0; // nr of skipped cells for virtual text
1134 // to be added to wlv.vcol later
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001135 int fromcol_prev = -2; // start of inverting after cursor
1136 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001137 int lnum_in_visual_area = FALSE;
1138 pos_T pos;
1139 long v;
1140
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001141 int attr_pri = FALSE; // char_attr has priority
1142 int area_highlighting = FALSE; // Visual or incsearch highlighting
1143 // in this line
1144 int vi_attr = 0; // attributes for Visual and incsearch
1145 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001146 int area_attr = 0; // attributes desired by highlighting
1147 int search_attr = 0; // attributes desired by 'hlsearch'
1148#ifdef FEAT_SYN_HL
1149 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1150 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001151 int prev_syntax_col = -1; // column of prev_syntax_attr
1152 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001153 int has_syntax = FALSE; // this buffer has syntax highl.
1154 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001155#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001156#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001157 int did_line = FALSE; // set to TRUE when line text done
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001158 int text_prop_count;
zeertzjq4e26a9a2023-12-03 17:50:47 +01001159 int last_textprop_text_idx = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001160 int text_prop_next = 0; // next text property to use
1161 textprop_T *text_props = NULL;
1162 int *text_prop_idxs = NULL;
1163 int text_props_active = 0;
1164 proptype_T *text_prop_type = NULL;
1165 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001166 int text_prop_attr_comb = 0; // text_prop_attr combined with
1167 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001168 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001169 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001170 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001171 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001172 int saved_search_attr = 0; // search_attr to be used when n_extra
1173 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001174 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001175 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001176#endif
1177#ifdef FEAT_SPELL
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001178 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001179# define SPWORDLEN 150
1180 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1181 int nextlinecol = 0; // column where nextline[] starts
1182 int nextline_idx = 0; // index in nextline[] where next line
1183 // starts
1184 int spell_attr = 0; // attributes desired by spelling
1185 int word_end = 0; // last byte with same spell_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001186 int cur_checked_col = 0; // checked column for current line
1187#endif
1188 int extra_check = 0; // has extra highlighting
1189 int multi_attr = 0; // attributes desired by multibyte
1190 int mb_l = 1; // multi-byte byte length
1191 int mb_c = 0; // decoded multi-byte character
1192 int mb_utf8 = FALSE; // screen char is UTF-8 char
1193 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001194#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001195 int change_start = MAXCOL; // first col of changed area
1196 int change_end = -1; // last col of changed area
1197#endif
1198 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001199 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001200 int in_multispace = FALSE; // in multiple consecutive spaces
1201 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001202#ifdef LINE_ATTR
Bram Moolenaarbf915842022-08-06 22:38:02 +01001203 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001204#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001205 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001206 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001207#ifdef FEAT_ARABIC
1208 int prev_c = 0; // previous Arabic character
1209 int prev_c1 = 0; // first composing char for prev_c
1210#endif
1211#if defined(LINE_ATTR)
1212 int did_line_attr = 0;
1213#endif
1214#ifdef FEAT_TERMINAL
1215 int get_term_attr = FALSE;
1216#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001217
Martin Tournoijba43e762022-10-13 22:12:15 +01001218#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001219 // margin columns for the screen line, needed for when 'cursorlineopt'
1220 // contains "screenline"
1221 int left_curline_col = 0;
1222 int right_curline_col = 0;
1223#endif
1224
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001225#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1226 int feedback_col = 0;
1227 int feedback_old_attr = -1;
1228#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001229
1230#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1231 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001232#endif
1233#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001234 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001235#endif
1236#ifdef FEAT_CONCEAL
1237 int syntax_flags = 0;
1238 int syntax_seqnr = 0;
1239 int prev_syntax_id = 0;
1240 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1241 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001242 int did_wcol = FALSE;
1243 int old_boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001244# define VCOL_HLC (wlv.vcol - wlv.vcol_off_co - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001245# define FIX_FOR_BOGUSCOLS \
1246 { \
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001247 wlv.n_extra += wlv.vcol_off_co; \
1248 wlv.vcol -= wlv.vcol_off_co; \
1249 wlv.vcol_off_co = 0; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001250 wlv.col -= wlv.boguscols; \
1251 old_boguscols = wlv.boguscols; \
1252 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001253 }
1254#else
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001255# define VCOL_HLC (wlv.vcol - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001256#endif
1257
1258 if (startrow > endrow) // past the end already!
1259 return startrow;
1260
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001261 CLEAR_FIELD(wlv);
1262
1263 wlv.lnum = lnum;
1264 wlv.startrow = startrow;
1265 wlv.row = startrow;
1266 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001267 wlv.fromcol = -10;
1268 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001269#ifdef FEAT_LINEBREAK
1270 wlv.vcol_sbr = -1;
1271#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001272
1273 if (!number_only)
1274 {
1275 // To speed up the loop below, set extra_check when there is linebreak,
1276 // trailing white space and/or syntax processing to be done.
1277#ifdef FEAT_LINEBREAK
1278 extra_check = wp->w_p_lbr;
1279#endif
1280#ifdef FEAT_SYN_HL
1281 if (syntax_present(wp) && !wp->w_s->b_syn_error
1282# ifdef SYN_TIME_LIMIT
1283 && !wp->w_s->b_syn_slow
1284# endif
1285 )
1286 {
1287 // Prepare for syntax highlighting in this line. When there is an
1288 // error, stop syntax highlighting.
1289 save_did_emsg = did_emsg;
1290 did_emsg = FALSE;
1291 syntax_start(wp, lnum);
1292 if (did_emsg)
1293 wp->w_s->b_syn_error = TRUE;
1294 else
1295 {
1296 did_emsg = save_did_emsg;
1297#ifdef SYN_TIME_LIMIT
1298 if (!wp->w_s->b_syn_slow)
1299#endif
1300 {
1301 has_syntax = TRUE;
1302 extra_check = TRUE;
1303 }
1304 }
1305 }
1306
1307 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001308 wlv.color_cols = wp->w_p_cc_cols;
1309 if (wlv.color_cols != NULL)
1310 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001311#endif
1312
1313#ifdef FEAT_TERMINAL
1314 if (term_show_buffer(wp->w_buffer))
1315 {
1316 extra_check = TRUE;
1317 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001318 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001319 }
1320#endif
1321
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001322 // handle Visual active in this window
1323 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1324 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001325 pos_T *top, *bot;
1326
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001327 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1328 {
1329 // Visual is after curwin->w_cursor
1330 top = &curwin->w_cursor;
1331 bot = &VIsual;
1332 }
1333 else
1334 {
1335 // Visual is before curwin->w_cursor
1336 top = &VIsual;
1337 bot = &curwin->w_cursor;
1338 }
1339 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1340 if (VIsual_mode == Ctrl_V)
1341 {
1342 // block mode
1343 if (lnum_in_visual_area)
1344 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001345 wlv.fromcol = wp->w_old_cursor_fcol;
1346 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001347 }
1348 }
1349 else
1350 {
1351 // non-block mode
1352 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001353 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001354 else if (lnum == top->lnum)
1355 {
1356 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001357 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001358 else
1359 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001360 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001361 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001362 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001363 }
1364 }
1365 if (VIsual_mode != 'V' && lnum == bot->lnum)
1366 {
1367 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1368 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001369 wlv.fromcol = -10;
1370 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001371 }
1372 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001373 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001374 else
1375 {
1376 pos = *bot;
1377 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001378 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1379 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001380 else
1381 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001382 getvvcol(wp, &pos, NULL, NULL,
1383 (colnr_T *)&wlv.tocol);
1384 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001385 }
1386 }
1387 }
1388 }
1389
1390 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001391 if (!highlight_match && lnum == curwin->w_cursor.lnum
1392 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001393#ifdef FEAT_GUI
1394 && !gui.in_use
1395#endif
1396 )
1397 noinvcur = TRUE;
1398
1399 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001400 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001401 {
1402 area_highlighting = TRUE;
1403 vi_attr = HL_ATTR(HLF_V);
1404#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1405 if ((clip_star.available && !clip_star.owned
1406 && clip_isautosel_star())
1407 || (clip_plus.available && !clip_plus.owned
1408 && clip_isautosel_plus()))
1409 vi_attr = HL_ATTR(HLF_VNC);
1410#endif
1411 }
1412 }
1413
1414 // handle 'incsearch' and ":s///c" highlighting
1415 else if (highlight_match
1416 && wp == curwin
1417 && lnum >= curwin->w_cursor.lnum
1418 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1419 {
1420 if (lnum == curwin->w_cursor.lnum)
1421 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001422 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001423 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001424 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001425 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1426 {
1427 pos.lnum = lnum;
1428 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001429 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001430 }
1431 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001432 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001433 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001434 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1435 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001436 area_highlighting = TRUE;
1437 vi_attr = HL_ATTR(HLF_I);
1438 }
1439 }
1440
1441#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001442 wlv.filler_lines = diff_check(wp, lnum);
1443 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001444 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001445 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001446 {
1447 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001448 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001449 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001450 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001451 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001452 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001453 }
1454 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001455 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001456 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001457 area_highlighting = TRUE;
1458 }
1459 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001460 wlv.filler_lines = wp->w_topfill;
1461 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001462#endif
1463
1464#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001465 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001466 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001467 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001468#endif
1469
1470#ifdef LINE_ATTR
1471# ifdef FEAT_SIGNS
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001472 // If this line has a sign with line highlighting set wlv.line_attr.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001473 if (sign_present)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001474 wlv.line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001475# endif
1476# if defined(FEAT_QUICKFIX)
1477 // Highlight the current line in the quickfix window.
1478 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001479 wlv.line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001480# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001481 if (wlv.line_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001482 area_highlighting = TRUE;
1483#endif
1484
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001485#ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01001486 if (spv->spv_has_spell && !number_only)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001487 {
Luuk van Baal30805a12023-05-27 22:22:10 +01001488 // Prepare for spell checking.
1489 extra_check = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001490
Luuk van Baal30805a12023-05-27 22:22:10 +01001491 // When a word wrapped from the previous line the start of the
1492 // current line is valid.
1493 if (lnum == spv->spv_checked_lnum)
1494 cur_checked_col = spv->spv_checked_col;
Luuk van Baale84c7732023-05-31 18:57:36 +01001495 // Previous line was not spell checked, check for capital. This happens
1496 // for the first line in an updated region or after a closed fold.
1497 if (spv->spv_capcol_lnum == 0 && check_need_cap(wp, lnum, 0))
1498 spv->spv_cap_col = 0;
1499 else if (lnum != spv->spv_capcol_lnum)
Luuk van Baal30805a12023-05-27 22:22:10 +01001500 spv->spv_cap_col = -1;
1501 spv->spv_checked_lnum = 0;
1502
Luuk van Baal30805a12023-05-27 22:22:10 +01001503 // Get the start of the next line, so that words that wrap to the
1504 // next line are found too: "et<line-break>al.".
1505 // Trick: skip a few chars for C/shell/Vim comments
1506 nextline[SPWORDLEN] = NUL;
1507 if (lnum < wp->w_buffer->b_ml.ml_line_count)
Luuk van Baale84c7732023-05-31 18:57:36 +01001508 {
1509 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1510 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1511 }
1512 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1513
1514 // If current line is empty, check first word in next line for capital.
1515 ptr = skipwhite(line);
1516 if (*ptr == NUL)
1517 {
1518 spv->spv_cap_col = 0;
1519 spv->spv_capcol_lnum = lnum + 1;
1520 }
1521 // For checking first word with a capital skip white space.
1522 else if (spv->spv_cap_col == 0)
1523 spv->spv_cap_col = ptr - line;
1524
Luuk van Baal30805a12023-05-27 22:22:10 +01001525 // Copy the end of the current line into nextline[].
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001526 if (nextline[SPWORDLEN] == NUL)
1527 {
1528 // No next line or it is empty.
1529 nextlinecol = MAXCOL;
1530 nextline_idx = 0;
1531 }
1532 else
1533 {
1534 v = (long)STRLEN(line);
1535 if (v < SPWORDLEN)
1536 {
1537 // Short line, use it completely and append the start of the
1538 // next line.
1539 nextlinecol = 0;
1540 mch_memmove(nextline, line, (size_t)v);
1541 STRMOVE(nextline + v, nextline + SPWORDLEN);
1542 nextline_idx = v + 1;
1543 }
1544 else
1545 {
1546 // Long line, use only the last SPWORDLEN bytes.
1547 nextlinecol = v - SPWORDLEN;
1548 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1549 nextline_idx = SPWORDLEN + 1;
1550 }
1551 }
1552 }
1553#endif
1554
Luuk van Baale84c7732023-05-31 18:57:36 +01001555 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1556 ptr = line;
1557
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001558 if (wp->w_p_list)
1559 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001560 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001561 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001562 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001563 || wp->w_lcs_chars.trail
1564 || wp->w_lcs_chars.lead
1565 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001566 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001567
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001568 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001569 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001570 {
1571 trailcol = (colnr_T)STRLEN(ptr);
1572 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1573 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001574 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001575 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001576 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001577 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001578 {
1579 leadcol = 0;
1580 while (VIM_ISWHITE(ptr[leadcol]))
1581 ++leadcol;
1582 if (ptr[leadcol] == NUL)
1583 // in a line full of spaces all of them are treated as trailing
1584 leadcol = (colnr_T)0;
1585 else
1586 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001587 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001588 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001589 }
1590
Bram Moolenaard7657e92022-09-20 18:59:30 +01001591 wlv.wcr_attr = get_wcr_attr(wp);
1592 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001593 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001594 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001595 area_highlighting = TRUE;
1596 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001597
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001598 // When w_skipcol is non-zero and there is virtual text above the actual
1599 // text, then this much of the virtual text is skipped.
1600 int skipcol_in_text_prop_above = 0;
1601
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001602#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001603 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001604 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001605
1606 char_u *prop_start;
1607 text_prop_count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE);
1608 if (text_prop_count > 0)
1609 {
1610 // Make a copy of the properties, so that they are properly
1611 // aligned.
1612 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1613 if (text_props != NULL)
1614 mch_memmove(text_props, prop_start,
1615 text_prop_count * sizeof(textprop_T));
1616
1617 // Allocate an array for the indexes.
1618 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1619 if (text_prop_idxs == NULL)
1620 VIM_CLEAR(text_props);
1621
1622 if (text_props != NULL)
1623 {
1624 area_highlighting = TRUE;
1625 extra_check = TRUE;
1626
zeertzjq4e26a9a2023-12-03 17:50:47 +01001627 /* Find the last text property that inserts text. */
1628 for (int i = 0; i < text_prop_count; ++i)
1629 if (text_props[i].tp_id < 0)
1630 last_textprop_text_idx = i;
1631
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001632 // When skipping virtual text the props need to be sorted. The
1633 // order is reversed!
1634 if (lnum == wp->w_topline && wp->w_skipcol > 0)
1635 {
1636 for (int i = 0; i < text_prop_count; ++i)
1637 text_prop_idxs[i] = i;
1638 sort_text_props(wp->w_buffer, text_props,
1639 text_prop_idxs, text_prop_count);
1640 }
1641
1642 // Text props "above" move the line number down to where the text
1643 // is. Only count the ones that are visible, not those that are
1644 // skipped because of w_skipcol.
1645 int text_width = wp->w_width - win_col_off(wp);
1646 for (int i = text_prop_count - 1; i >= 0; --i)
1647 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1648 {
1649 if (lnum == wp->w_topline
1650 && wp->w_skipcol - skipcol_in_text_prop_above
1651 >= text_width)
1652 {
1653 // This virtual text above is skipped, remove it from
1654 // the array.
1655 skipcol_in_text_prop_above += text_width;
1656 for (int j = i + 1; j < text_prop_count; ++j)
1657 text_props[j - 1] = text_props[j];
1658 ++i;
1659 --text_prop_count;
1660 }
1661 else
1662 ++wlv.text_prop_above_count;
1663 }
1664 }
1665 }
Bram Moolenaara572b932023-02-19 14:34:37 +00001666
1667 if (number_only)
1668 {
1669 // skip over rows only used for virtual text above
1670 wlv.row += wlv.text_prop_above_count;
1671 if (wlv.row > endrow)
1672 return wlv.row;
1673 wlv.screen_row += wlv.text_prop_above_count;
1674 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001675#endif
1676
zeertzjqce53e3e2023-09-01 18:49:30 +02001677#if defined(FEAT_LINEBREAK) || defined(FEAT_PROP_POPUP)
1678 colnr_T vcol_first_char = 0;
1679 if (wp->w_p_lbr && !number_only)
1680 {
1681 chartabsize_T cts;
1682 init_chartabsize_arg(&cts, wp, lnum, 0, line, line);
1683 (void)win_lbr_chartabsize(&cts, NULL);
1684 vcol_first_char = cts.cts_first_char;
1685 clear_chartabsize_arg(&cts);
1686 }
1687#endif
1688
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001689 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1690 // first character to be displayed.
1691 if (wp->w_p_wrap)
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001692 v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001693 else
1694 v = wp->w_leftcol;
1695 if (v > 0 && !number_only)
1696 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001697 char_u *prev_ptr = ptr;
1698 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001699 int charsize = 0;
zeertzjqb557f482023-08-22 22:07:34 +02001700 int head = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001701
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001702 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
zeertzjqb557f482023-08-22 22:07:34 +02001703 cts.cts_max_head_vcol = v;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001704 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001705 {
zeertzjqb557f482023-08-22 22:07:34 +02001706 head = 0;
1707 charsize = win_lbr_chartabsize(&cts, &head);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001708 cts.cts_vcol += charsize;
1709 prev_ptr = cts.cts_ptr;
1710 MB_PTR_ADV(cts.cts_ptr);
zeertzjqabc80812023-09-24 23:32:18 +02001711 if (wp->w_p_list)
1712 {
1713 in_multispace = *prev_ptr == ' ' && (*cts.cts_ptr == ' '
1714 || (prev_ptr > line && prev_ptr[-1] == ' '));
1715 if (!in_multispace)
1716 multispace_pos = 0;
1717 else if (cts.cts_ptr >= line + leadcol
1718 && wp->w_lcs_chars.multispace != NULL)
1719 {
1720 ++multispace_pos;
1721 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
1722 multispace_pos = 0;
1723 }
1724 else if (cts.cts_ptr < line + leadcol
1725 && wp->w_lcs_chars.leadmultispace != NULL)
1726 {
1727 ++multispace_pos;
1728 if (wp->w_lcs_chars.leadmultispace[multispace_pos] == NUL)
1729 multispace_pos = 0;
1730 }
1731 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001732 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001733 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001734 ptr = cts.cts_ptr;
1735 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001736
1737 // When:
1738 // - 'cuc' is set, or
1739 // - 'colorcolumn' is set, or
1740 // - 'virtualedit' is set, or
1741 // - the visual mode is active,
1742 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001743 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001744#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001745 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001746#endif
1747 virtual_active() ||
1748 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001749 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001750
1751 // Handle a character that's not completely on the screen: Put ptr at
1752 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001753 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001754 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001755 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001756 ptr = prev_ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001757 }
zeertzjqb557f482023-08-22 22:07:34 +02001758 if (v > wlv.vcol)
1759 skip_cells = v - wlv.vcol - head;
Bram Moolenaarcd105412022-10-10 19:50:42 +01001760
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001761 // Adjust for when the inverted text is before the screen,
1762 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001763 if (wlv.tocol <= wlv.vcol)
1764 wlv.fromcol = 0;
1765 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1766 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001767
1768#ifdef FEAT_LINEBREAK
1769 // When w_skipcol is non-zero, first line needs 'showbreak'
1770 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001771 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001772#endif
1773#ifdef FEAT_SPELL
1774 // When spell checking a word we need to figure out the start of the
1775 // word and if it's badly spelled or not.
Luuk van Baal30805a12023-05-27 22:22:10 +01001776 if (spv->spv_has_spell)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001777 {
1778 int len;
1779 colnr_T linecol = (colnr_T)(ptr - line);
1780 hlf_T spell_hlf = HLF_COUNT;
1781
1782 pos = wp->w_cursor;
1783 wp->w_cursor.lnum = lnum;
1784 wp->w_cursor.col = linecol;
1785 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1786
1787 // spell_move_to() may call ml_get() and make "line" invalid
1788 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1789 ptr = line + linecol;
1790
1791 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1792 {
1793 // no bad word found at line start, don't check until end of a
1794 // word
1795 spell_hlf = HLF_COUNT;
1796 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1797 }
1798 else
1799 {
1800 // bad word found, use attributes until end of word
1801 word_end = wp->w_cursor.col + len + 1;
1802
1803 // Turn index into actual attributes.
1804 if (spell_hlf != HLF_COUNT)
1805 spell_attr = highlight_attr[spell_hlf];
1806 }
1807 wp->w_cursor = pos;
1808
1809# ifdef FEAT_SYN_HL
1810 // Need to restart syntax highlighting for this line.
1811 if (has_syntax)
1812 syntax_start(wp, lnum);
1813# endif
1814 }
1815#endif
1816 }
1817
1818 // Correct highlighting for cursor that can't be disabled.
1819 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001820 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001821 {
1822 if (noinvcur)
1823 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001824 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001825 {
1826 // highlighting starts at cursor, let it start just after the
1827 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001828 fromcol_prev = wlv.fromcol;
1829 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001830 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001831 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001832 // restart highlighting after the cursor
1833 fromcol_prev = wp->w_virtcol;
1834 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001835 if (wlv.fromcol >= wlv.tocol)
1836 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001837 }
1838
1839#ifdef FEAT_SEARCH_EXTRA
1840 if (!number_only)
1841 {
1842 v = (long)(ptr - line);
1843 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1844 &line, &screen_search_hl,
1845 &search_attr);
1846 ptr = line + v; // "line" may have been updated
1847 }
1848#endif
1849
1850#ifdef FEAT_SYN_HL
1851 // Cursor line highlighting for 'cursorline' in the current window.
1852 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1853 {
1854 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001855 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001856 if (!(wp == curwin && VIsual_active)
1857 && wp->w_p_culopt_flags != CULOPT_NBR)
1858 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001859 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001860 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1861
zeertzjqb7acea12022-12-12 13:20:43 +00001862 // Only apply CursorLine highlight here when "screenline" is not
1863 // present in 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001864 if (!wlv.cul_screenline)
zeertzjqb7acea12022-12-12 13:20:43 +00001865 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001866 else
1867 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001868 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001869 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1870 }
1871 area_highlighting = TRUE;
1872 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001873 }
1874#endif
1875
Bram Moolenaar1306b362022-08-06 15:59:06 +01001876 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001877
1878 // Repeat for the whole displayed line.
1879 for (;;)
1880 {
1881#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001882 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001883#endif
1884#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001885 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001886#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001887
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001888 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001889 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001890 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001891#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001892 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001893 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001894 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001895 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001896 }
1897#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001898 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001899 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001900 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001901 if (cmdwin_type != 0 && wp == curwin)
1902 {
1903 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001904 wlv.n_extra = 1;
1905 wlv.c_extra = cmdwin_type;
1906 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001907 wlv.char_attr =
1908 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001909 }
1910 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001911#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001912 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001913 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001914 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001915 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001916 }
1917#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001918#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001919 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001920 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001921 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001922 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001923 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001924 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001925 }
1926#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001927 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001928 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001929 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001930 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001931 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001932 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001933#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001934 // Check if 'breakindent' applies and show it.
1935 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1936 if (wlv.n_extra == 0)
1937 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001938#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001939#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001940 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001941 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001942 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001943 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001944 }
1945#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001946 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001947 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001948 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001949 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001950 }
1951 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001952
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001953#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001954 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001955 && wlv.vcol >= left_curline_col
1956 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001957 {
zeertzjqb7acea12022-12-12 13:20:43 +00001958 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001959 }
1960#endif
1961
1962 // When still displaying '$' of change command, stop at cursor.
1963 // When only displaying the (relative) line number and that's done,
1964 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001965 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001966 && lnum == wp->w_cursor.lnum
1967 && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001968 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001969#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001970 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001971#endif
1972 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001973 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001974 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001975 // Pretend we have finished updating the window. Except when
1976 // 'cursorcolumn' is set.
1977#ifdef FEAT_SYN_HL
1978 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001979 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001980 else
1981#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001982 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001983 break;
1984 }
1985
Bram Moolenaar1306b362022-08-06 15:59:06 +01001986 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001987 {
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001988#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001989 if (text_props != NULL)
1990 {
1991 int pi;
1992 int bcol = (int)(ptr - line);
1993
Bram Moolenaar1306b362022-08-06 15:59:06 +01001994 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001995# ifdef FEAT_LINEBREAK
1996 && !in_linebreak
1997# endif
1998 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001999 --bcol; // still working on the previous char, e.g. Tab
2000
2001 // Check if any active property ends.
2002 for (pi = 0; pi < text_props_active; ++pi)
2003 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002004 int tpi = text_prop_idxs[pi];
2005 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002006
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002007 // An inline property ends when after the start column plus
2008 // length. An "above" property ends when used and n_extra
2009 // is zero.
2010 if ((tp->tp_col != MAXCOL
2011 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002012 {
2013 if (pi + 1 < text_props_active)
2014 mch_memmove(text_prop_idxs + pi,
2015 text_prop_idxs + pi + 1,
2016 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002017 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002018 --text_props_active;
2019 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002020# ifdef FEAT_LINEBREAK
2021 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002022 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002023 syntax_attr = 0;
2024# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002025 }
2026 }
2027
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002028# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01002029 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002030 // not on the next char yet, don't start another prop
2031 --bcol;
2032# endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002033 int display_text_first = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002034
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002035 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002036 // With 'nowrap' and not in the first screen line only "below"
2037 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002038 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002039 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002040 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002041 && (wp->w_p_wrap
2042 || wlv.row == startrow
2043 || (text_props[text_prop_next].tp_flags
2044 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002045 || (bcol == 0
2046 && (text_props[text_prop_next].tp_flags
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002047 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002048 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002049 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01002050 if (text_props[text_prop_next].tp_col == MAXCOL
2051 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002052 + text_props[text_prop_next].tp_len)
2053 text_prop_idxs[text_props_active++] = text_prop_next;
2054 ++text_prop_next;
2055 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002056
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002057 if (wlv.n_extra == 0 ||
2058 (!wlv.extra_for_textprop
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002059 && !(text_prop_type != NULL &&
2060 text_prop_flags & PT_FLAG_OVERRIDE)
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002061 ))
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002062 {
2063 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002064 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002065 text_prop_flags = 0;
2066 text_prop_type = NULL;
2067 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002068 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002069 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002070 if (text_props_active > 0 && wlv.n_extra == 0
2071 && !display_text_first)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002072 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01002073 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002074 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002075 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002076
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002077 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002078 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002079
2080 // Sort the properties on priority and/or starting last.
2081 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002082 sort_text_props(wp->w_buffer, text_props,
2083 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002084
2085 for (pi = 0; pi < text_props_active; ++pi)
2086 {
2087 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002088 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002089 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002090 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002091
Bram Moolenaarcd105412022-10-10 19:50:42 +01002092 // Only use a text property that can be displayed.
2093 // Skip "after" properties when wrap is off and at the
2094 // end of the window.
2095 if (pt != NULL
2096 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2097 && tp->tp_id != -MAXCOL
2098 && !(tp->tp_id < 0
2099 && !wp->w_p_wrap
2100 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2101 | TP_FLAG_ALIGN_ABOVE
2102 | TP_FLAG_ALIGN_BELOW)) == 0
2103 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002104 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002105 if (tp->tp_col == MAXCOL
2106 && *ptr == NUL
2107 && ((wp->w_p_list && lcs_eol_one > 0
2108 && (tp->tp_flags
2109 & TP_FLAG_ALIGN_ABOVE) == 0)
2110 || (ptr == line
2111 && !did_line
2112 && (tp->tp_flags
2113 & TP_FLAG_ALIGN_BELOW))))
2114 {
2115 // skip this prop, first display the '$' after
2116 // the line or display an empty line
2117 text_prop_follows = TRUE;
2118 if (used_tpi < 0)
2119 display_text_first = TRUE;
2120 continue;
2121 }
2122
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002123 if (pt->pt_hl_id > 0)
2124 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002125 text_prop_type = pt;
2126 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002127 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002128 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2129 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002130 text_prop_flags = pt->pt_flags;
2131 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002132 used_tpi = tpi;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002133 display_text_first = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002134 }
2135 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002136 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002137 && -text_prop_id
2138 <= wp->w_buffer->b_textprop_text.ga_len)
2139 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002140 textprop_T *tp = &text_props[used_tpi];
2141 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002142 ->b_textprop_text.ga_data)[
2143 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002144 int above = (tp->tp_flags
2145 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002146 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002147
2148 // reset the ID in the copy to avoid it being used
2149 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002150 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002151
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002152 if (p != NULL)
2153 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002154 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002155 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002156 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002157 & TP_FLAG_ALIGN_BELOW);
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002158 int wrap = tp->tp_col < MAXCOL
2159 || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002160 int padding = tp->tp_col == MAXCOL
2161 && tp->tp_len > 1
2162 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002163
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002164 // Insert virtual text before the current
2165 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002166 wlv.p_extra = p;
2167 wlv.c_extra = NUL;
2168 wlv.c_final = NUL;
2169 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002170 wlv.extra_for_textprop = TRUE;
zeertzjq6e940d92023-08-17 23:21:40 +02002171 wlv.start_extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002172 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2173 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002174 n_attr = mb_charlen(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002175 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002176 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002177 if (*ptr == NUL)
2178 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002179 text_prop_flags &= ~PT_FLAG_COMBINE;
zeertzjq6b9c2022023-09-11 20:01:17 +02002180# ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002181 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002182 {
2183 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002184 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002185 wlv.need_showbreak = FALSE;
2186 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002187 }
zeertzjq6b9c2022023-09-11 20:01:17 +02002188# endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002189 if ((right || above || below || !wrap
2190 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002191 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002192 char_u *prev_p_extra = wlv.p_extra;
2193 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002194
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002195 // Take care of padding, right-align and
2196 // truncation.
2197 // Shared with win_lbr_chartabsize(), must do
2198 // exactly the same.
2199 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002200 wlv.vcol,
zeertzjq6b9c2022023-09-11 20:01:17 +02002201# ifdef FEAT_RIGHTLEFT
2202 wp->w_p_rl
2203 ? wp->w_width - wlv.col - 1
2204 :
2205# endif
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002206 wlv.col,
2207 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002208 &n_attr, &wlv.n_attr_skip,
2209 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002210 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002211 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002212 // wlv.p_extra was allocated
2213 vim_free(p_extra_free2);
2214 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002215 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002216
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002217 if (above)
2218 wlv.vcol_off_tp = wlv.n_extra;
2219
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002220 if (lcs_eol_one < 0
2221 && wp->w_p_wrap
2222 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002223 + wlv.n_extra - 2 > wp->w_width)
2224 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002225 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002226
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002227 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002228 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002229 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002230 {
2231 draw_screen_line(wp, &wlv);
2232
2233 // When line got too long for screen break
2234 // here.
2235 if (wlv.row == endrow)
2236 {
2237 ++wlv.row;
2238 break;
2239 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002240 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002241 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002242 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002243 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002244 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002245
Bram Moolenaarcd105412022-10-10 19:50:42 +01002246 // If the text didn't reach until the first window
2247 // column we need to skip cells.
2248 if (skip_cells > 0)
2249 {
2250 if (wlv.n_extra > skip_cells)
2251 {
2252 wlv.n_extra -= skip_cells;
2253 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002254 wlv.n_attr_skip -= skip_cells;
2255 if (wlv.n_attr_skip < 0)
2256 wlv.n_attr_skip = 0;
zeertzjqb557f482023-08-22 22:07:34 +02002257 skipped_cells += skip_cells;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002258 skip_cells = 0;
2259 }
2260 else
2261 {
2262 // the whole text is left of the window, drop
2263 // it and advance to the next one
2264 skip_cells -= wlv.n_extra;
zeertzjqb557f482023-08-22 22:07:34 +02002265 skipped_cells += wlv.n_extra;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002266 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002267 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002268 bail_out = TRUE;
2269 }
2270 }
2271
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002272 // If another text prop follows the condition below at
2273 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002274 // If this is an "above" text prop and 'nowrap' the we
2275 // must wrap anyway.
2276 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002277 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002278 && (wp->w_p_wrap
2279 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002280 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002281
2282 if (bail_out)
2283 // starting a new line for "below"
2284 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002285 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002286 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002287 else if (text_prop_next < text_prop_count
2288 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002289 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2290 || (!wp->w_p_wrap
2291 && wlv.col == wp->w_width - 1
2292 && (text_props[text_prop_next].tp_flags
2293 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002294 // When at last-but-one character and a text property
2295 // follows after it, we may need to flush the line after
2296 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002297 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002298 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002299 }
zeertzjq6e940d92023-08-17 23:21:40 +02002300
2301 if (wlv.start_extra_for_textprop)
2302 {
2303 wlv.start_extra_for_textprop = FALSE;
2304 // restore search_attr and area_attr when n_extra
2305 // is down to zero
2306 saved_search_attr = search_attr;
2307 saved_area_attr = area_attr;
2308 search_attr = 0;
2309 area_attr = 0;
2310 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002311#endif
2312
zeertzjq6e940d92023-08-17 23:21:40 +02002313 int *area_attr_p =
2314#ifdef FEAT_PROP_POPUP
2315 wlv.extra_for_textprop ? &saved_area_attr :
2316#endif
2317 &area_attr;
2318
2319 // handle Visual or match highlighting in this line
2320 if (wlv.vcol == wlv.fromcol
2321 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
2322 && ((wlv.n_extra == 0 && (*mb_ptr2cells)(ptr) > 1)
2323 || (wlv.n_extra > 0 && wlv.p_extra != NULL
2324 && (*mb_ptr2cells)(wlv.p_extra) > 1)))
2325 || ((int)vcol_prev == fromcol_prev
2326 && vcol_prev < wlv.vcol // not at margin
2327 && wlv.vcol < wlv.tocol))
2328 *area_attr_p = vi_attr; // start highlighting
2329 else if (*area_attr_p != 0
2330 && (wlv.vcol == wlv.tocol
2331 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
2332 *area_attr_p = 0; // stop highlighting
2333
zeertzjqe500ae82023-08-17 22:35:26 +02002334#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaare38fc862022-08-11 17:24:50 +01002335 if (wlv.n_extra == 0)
2336 {
2337 // Check for start/end of 'hlsearch' and other matches.
2338 // After end, check for start/end of next match.
2339 // When another match, have to check for start again.
2340 v = (long)(ptr - line);
2341 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2342 &screen_search_hl, &has_match_conc,
2343 &match_conc, did_line_attr, lcs_eol_one,
2344 &on_last_col);
2345 ptr = line + v; // "line" may have been changed
Bram Moolenaare38fc862022-08-11 17:24:50 +01002346
2347 // Do not allow a conceal over EOL otherwise EOL will be missed
2348 // and bad things happen.
2349 if (*ptr == NUL)
2350 has_match_conc = 0;
zeertzjqb25dbb32023-08-13 18:11:05 +02002351 }
zeertzjqe500ae82023-08-17 22:35:26 +02002352#endif
zeertzjqb25dbb32023-08-13 18:11:05 +02002353
Bram Moolenaare38fc862022-08-11 17:24:50 +01002354#ifdef FEAT_DIFF
2355 if (wlv.diff_hlf != (hlf_T)0)
2356 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002357 // When there is extra text (e.g. virtual text) it gets the
2358 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002359 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2360 && wlv.n_extra == 0)
2361 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002362 if (wlv.diff_hlf == HLF_TXD
2363 && ((ptr - line > change_end && wlv.n_extra == 0)
2364 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002365 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002366 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002367 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2368 && wp->w_p_culopt_flags != CULOPT_NBR
2369 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2370 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002371 wlv.line_attr = hl_combine_attr(
2372 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002373 }
2374#endif
2375
Bram Moolenaara74fda62019-10-19 17:38:03 +02002376#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002377 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002378 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002379 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002380# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002381 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002382 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002383# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002384 // Get syntax attribute.
2385 if (has_syntax)
2386 {
2387 // Get the syntax attribute for the character. If there
2388 // is an error, disable syntax highlighting.
2389 save_did_emsg = did_emsg;
2390 did_emsg = FALSE;
2391
2392 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002393 if (v == prev_syntax_col)
2394 // at same column again
2395 syntax_attr = prev_syntax_attr;
2396 else
2397 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002398# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002399 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002400# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002401 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002402# ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01002403 spv->spv_has_spell ? &can_spell :
Bram Moolenaar34390282019-10-16 14:38:26 +02002404# endif
Luuk van Baal30805a12023-05-27 22:22:10 +01002405 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002406 prev_syntax_col = v;
2407 prev_syntax_attr = syntax_attr;
2408 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002409
Bram Moolenaar34390282019-10-16 14:38:26 +02002410 if (did_emsg)
2411 {
2412 wp->w_s->b_syn_error = TRUE;
2413 has_syntax = FALSE;
2414 syntax_attr = 0;
2415 }
2416 else
2417 did_emsg = save_did_emsg;
2418# ifdef SYN_TIME_LIMIT
2419 if (wp->w_s->b_syn_slow)
2420 has_syntax = FALSE;
2421# endif
2422
2423 // Need to get the line again, a multi-line regexp may
2424 // have made it invalid.
2425 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2426 ptr = line + v;
2427# ifdef FEAT_CONCEAL
2428 // no concealing past the end of the line, it interferes
2429 // with line highlighting
2430 if (*ptr == NUL)
2431 syntax_flags = 0;
2432 else
2433 syntax_flags = get_syntax_info(&syntax_seqnr);
2434# endif
2435 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002436 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002437# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002438 // Combine text property highlight into syntax highlight.
2439 if (text_prop_type != NULL)
2440 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002441 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002442 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2443 else
2444 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002445 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002446 }
2447# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002448#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002449
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002450 // Decide which of the highlight attributes to use.
2451 attr_pri = TRUE;
2452#ifdef LINE_ATTR
2453 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002454 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002455 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002456 if (!highlight_match)
2457 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002458 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002459# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002460 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002461# endif
2462 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002463 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002464 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002465 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002466# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002467 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002468# endif
2469 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002470 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002471 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2472 || wlv.vcol < wlv.fromcol
2473 || vcol_prev < fromcol_prev
2474 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002475 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002476 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002477 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002478# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002479 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002480# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002481 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002482# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002483 attr_pri = FALSE;
2484 }
2485#else
2486 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002487 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002488 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002489 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002490#endif
2491 else
2492 {
2493 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002494#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002495 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002496#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002497 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002498#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002499 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002500#ifdef FEAT_PROP_POPUP
2501 // override with text property highlight when "override" is TRUE
2502 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002503 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002504#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002505 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002506
2507 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002508 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002509 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002510 if (wlv.char_attr == 0)
2511 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002512 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002513 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002514 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002515
2516 // Get the next character to put on the screen.
2517
2518 // The "p_extra" points to the extra stuff that is inserted to
2519 // represent special characters (non-printable stuff) and other
2520 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002521 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002522 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2523 // "p_extra[n_extra]".
2524 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002525 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002526 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002527 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002528 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002529 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2530 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002531 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2532 if (enc_utf8 && utf_char2len(c) > 1)
2533 {
2534 mb_utf8 = TRUE;
2535 u8cc[0] = 0;
2536 c = 0xc0;
2537 }
2538 else
2539 mb_utf8 = FALSE;
2540 }
2541 else
2542 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002543 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002544 if (has_mbyte)
2545 {
2546 mb_c = c;
2547 if (enc_utf8)
2548 {
2549 // If the UTF-8 character is more than one byte:
2550 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002551 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002552 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002553 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002554 mb_l = 1;
2555 else if (mb_l > 1)
2556 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002557 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002558 mb_utf8 = TRUE;
2559 c = 0xc0;
2560 }
2561 }
2562 else
2563 {
2564 // if this is a DBCS character, put it in "mb_c"
2565 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002566 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002567 mb_l = 1;
2568 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002569 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002570 }
2571 if (mb_l == 0) // at the NUL at end-of-line
2572 mb_l = 1;
2573
2574 // If a double-width char doesn't fit display a '>' in the
2575 // last column.
2576 if ((
2577# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002578 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002579# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002580 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002581 && (*mb_char2cells)(mb_c) == 2)
2582 {
2583 c = '>';
2584 mb_c = c;
2585 mb_l = 1;
2586 mb_utf8 = FALSE;
2587 multi_attr = HL_ATTR(HLF_AT);
2588#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002589 if (wlv.cul_attr)
2590 multi_attr = hl_combine_attr(
2591 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002592#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002593 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002594
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002595 // put the pointer back to output the double-width
2596 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002597 ++wlv.n_extra;
2598 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002599 }
2600 else
2601 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002602 wlv.n_extra -= mb_l - 1;
2603 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002604 }
2605 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002606 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002607 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002608 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002609#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002610 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002611 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002612 // Only restore search_attr and area_attr after "n_extra" in
2613 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002614 if (wlv.saved_n_extra <= 0)
2615 {
2616 if (search_attr == 0)
2617 search_attr = saved_search_attr;
2618 if (area_attr == 0 && *ptr != NUL)
2619 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002620
2621 if (wlv.extra_for_textprop)
2622 // wlv.extra_attr should be used at this position but
2623 // not any further.
2624 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002625 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002626
2627 wlv.extra_for_textprop = FALSE;
2628 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002629 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002630#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002631 }
2632 else
2633 {
2634#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002635 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002636#endif
zeertzjqe500ae82023-08-17 22:35:26 +02002637 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002638
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002639 // Get a character from the line itself.
2640 c = *ptr;
2641#ifdef FEAT_LINEBREAK
2642 c0 = *ptr;
2643#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002644 if (c == NUL)
zeertzjqb557f482023-08-22 22:07:34 +02002645 {
2646#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002647 // text is finished, may display a "below" virtual text
2648 did_line = TRUE;
2649#endif
zeertzjqb557f482023-08-22 22:07:34 +02002650 // no more cells to skip
2651 skip_cells = 0;
2652 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002653
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002654 if (has_mbyte)
2655 {
2656 mb_c = c;
2657 if (enc_utf8)
2658 {
2659 // If the UTF-8 character is more than one byte: Decode it
2660 // into "mb_c".
2661 mb_l = utfc_ptr2len(ptr);
2662 mb_utf8 = FALSE;
2663 if (mb_l > 1)
2664 {
2665 mb_c = utfc_ptr2char(ptr, u8cc);
2666 // Overlong encoded ASCII or ASCII with composing char
2667 // is displayed normally, except a NUL.
2668 if (mb_c < 0x80)
2669 {
2670 c = mb_c;
2671#ifdef FEAT_LINEBREAK
2672 c0 = mb_c;
2673#endif
2674 }
2675 mb_utf8 = TRUE;
2676
2677 // At start of the line we can have a composing char.
2678 // Draw it as a space with a composing char.
2679 if (utf_iscomposing(mb_c))
2680 {
2681 int i;
2682
2683 for (i = Screen_mco - 1; i > 0; --i)
2684 u8cc[i] = u8cc[i - 1];
2685 u8cc[0] = mb_c;
2686 mb_c = ' ';
2687 }
2688 }
2689
2690 if ((mb_l == 1 && c >= 0x80)
2691 || (mb_l >= 1 && mb_c == 0)
2692 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2693 {
2694 // Illegal UTF-8 byte: display as <xx>.
2695 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002696 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002697# ifdef FEAT_RIGHTLEFT
2698 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002699 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002700# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002701 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002702 c = *wlv.p_extra;
2703 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002704 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002705 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2706 wlv.c_extra = NUL;
2707 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002708 if (area_attr == 0 && search_attr == 0)
2709 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002710 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002711 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002712 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002713 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002714 }
2715 }
2716 else if (mb_l == 0) // at the NUL at end-of-line
2717 mb_l = 1;
2718#ifdef FEAT_ARABIC
2719 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2720 {
2721 // Do Arabic shaping.
2722 int pc, pc1, nc;
2723 int pcc[MAX_MCO];
2724
2725 // The idea of what is the previous and next
2726 // character depends on 'rightleft'.
2727 if (wp->w_p_rl)
2728 {
2729 pc = prev_c;
2730 pc1 = prev_c1;
2731 nc = utf_ptr2char(ptr + mb_l);
2732 prev_c1 = u8cc[0];
2733 }
2734 else
2735 {
2736 pc = utfc_ptr2char(ptr + mb_l, pcc);
2737 nc = prev_c;
2738 pc1 = pcc[0];
2739 }
2740 prev_c = mb_c;
2741
2742 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2743 }
2744 else
2745 prev_c = mb_c;
2746#endif
2747 }
2748 else // enc_dbcs
2749 {
2750 mb_l = MB_BYTE2LEN(c);
2751 if (mb_l == 0) // at the NUL at end-of-line
2752 mb_l = 1;
2753 else if (mb_l > 1)
2754 {
2755 // We assume a second byte below 32 is illegal.
2756 // Hopefully this is OK for all double-byte encodings!
2757 if (ptr[1] >= 32)
2758 mb_c = (c << 8) + ptr[1];
2759 else
2760 {
2761 if (ptr[1] == NUL)
2762 {
2763 // head byte at end of line
2764 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002765 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002766 }
2767 else
2768 {
2769 // illegal tail byte
2770 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002771 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002772 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002773 wlv.p_extra = wlv.extra;
2774 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002775 wlv.c_extra = NUL;
2776 wlv.c_final = NUL;
2777 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002778 if (area_attr == 0 && search_attr == 0)
2779 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002780 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002781 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002782 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002783 // save current attr
2784 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002785 }
2786 mb_c = c;
2787 }
2788 }
2789 }
2790 // If a double-width char doesn't fit display a '>' in the
2791 // last column; the character is displayed at the start of the
2792 // next line.
2793 if ((
2794# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002795 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002796# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002797 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002798 && (*mb_char2cells)(mb_c) == 2)
2799 {
2800 c = '>';
2801 mb_c = c;
2802 mb_utf8 = FALSE;
2803 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002804 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002805 // Put pointer back so that the character will be
2806 // displayed at the start of the next line.
2807 --ptr;
2808#ifdef FEAT_CONCEAL
2809 did_decrement_ptr = TRUE;
2810#endif
2811 }
2812 else if (*ptr != NUL)
2813 ptr += mb_l - 1;
2814
2815 // If a double-width char doesn't fit at the left side display
2816 // a '<' in the first column. Don't do this for unprintable
2817 // characters.
zeertzjqb557f482023-08-22 22:07:34 +02002818 if (skip_cells > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002819 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002820 wlv.n_extra = 1;
2821 wlv.c_extra = MB_FILLER_CHAR;
2822 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002823 c = ' ';
2824 if (area_attr == 0 && search_attr == 0)
2825 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002826 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002827 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002828 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002829 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002830 }
2831 mb_c = c;
2832 mb_utf8 = FALSE;
2833 mb_l = 1;
2834 }
2835
2836 }
2837 ++ptr;
2838
2839 if (extra_check)
2840 {
2841#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002842 // Check spelling (unless at the end of the line).
2843 // Only do this when there is no syntax highlighting, the
2844 // @Spell cluster is not used or the current syntax item
2845 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002846 v = (long)(ptr - line);
Luuk van Baal30805a12023-05-27 22:22:10 +01002847 if (spv->spv_has_spell && v >= word_end && v > cur_checked_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002848 {
2849 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002850 // do not calculate cap_col at the end of the line or when
2851 // only white space is following
2852 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002853# ifdef FEAT_SYN_HL
2854 !has_syntax ||
2855# endif
2856 can_spell))
2857 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002858 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002859 int len;
2860 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002861
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002862 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002863 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002864
2865 // Use nextline[] if possible, it has the start of the
2866 // next line concatenated.
2867 if ((prev_ptr - line) - nextlinecol >= 0)
2868 p = nextline + (prev_ptr - line) - nextlinecol;
2869 else
2870 p = prev_ptr;
Luuk van Baal30805a12023-05-27 22:22:10 +01002871 spv->spv_cap_col -= (int)(prev_ptr - line);
2872 len = spell_check(wp, p, &spell_hlf, &spv->spv_cap_col,
2873 spv->spv_unchanged);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002874 word_end = v + len;
2875
2876 // In Insert mode only highlight a word that
2877 // doesn't touch the cursor.
2878 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002879 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002880 && wp->w_cursor.lnum == lnum
2881 && wp->w_cursor.col >=
2882 (colnr_T)(prev_ptr - line)
2883 && wp->w_cursor.col < (colnr_T)word_end)
2884 {
2885 spell_hlf = HLF_COUNT;
2886 spell_redraw_lnum = lnum;
2887 }
2888
2889 if (spell_hlf == HLF_COUNT && p != prev_ptr
2890 && (p - nextline) + len > nextline_idx)
2891 {
2892 // Remember that the good word continues at the
2893 // start of the next line.
Luuk van Baal30805a12023-05-27 22:22:10 +01002894 spv->spv_checked_lnum = lnum + 1;
2895 spv->spv_checked_col = (p - nextline) + len
2896 - nextline_idx;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002897 }
2898
2899 // Turn index into actual attributes.
2900 if (spell_hlf != HLF_COUNT)
2901 spell_attr = highlight_attr[spell_hlf];
2902
Luuk van Baal30805a12023-05-27 22:22:10 +01002903 if (spv->spv_cap_col > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002904 {
2905 if (p != prev_ptr
Luuk van Baal30805a12023-05-27 22:22:10 +01002906 && (p - nextline) + spv->spv_cap_col
2907 >= nextline_idx)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002908 {
2909 // Remember that the word in the next line
2910 // must start with a capital.
Luuk van Baal30805a12023-05-27 22:22:10 +01002911 spv->spv_capcol_lnum = lnum + 1;
2912 spv->spv_cap_col = ((p - nextline)
2913 + spv->spv_cap_col - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002914 }
2915 else
2916 // Compute the actual column.
Luuk van Baal30805a12023-05-27 22:22:10 +01002917 spv->spv_cap_col += (prev_ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002918 }
2919 }
2920 }
2921 if (spell_attr != 0)
2922 {
2923 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002924 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2925 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002926 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002927 wlv.char_attr = hl_combine_attr(spell_attr,
2928 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002929 }
2930#endif
2931#ifdef FEAT_LINEBREAK
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02002932 // we don't want linebreak to apply for lines that start with
2933 // leading spaces, followed by long letters (since it would add
2934 // a break at the beginning of a line and this might be unexpected)
2935 //
2936 // So only allow to linebreak, once we have found chars not in
2937 // 'breakat' in the line.
2938 if ( wp->w_p_lbr && !wlv.need_lbr && c != NUL &&
2939 !VIM_ISBREAK((int)*ptr))
2940 wlv.need_lbr = TRUE;
2941#endif
2942#ifdef FEAT_LINEBREAK
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002943 // Found last space before word: check for line break.
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02002944 if (wp->w_p_lbr && c0 == c && wlv.need_lbr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002945 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2946 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002947 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2948 : 0;
2949 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002950 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002951
zeertzjqce53e3e2023-09-01 18:49:30 +02002952 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol
2953# ifdef FEAT_PROP_POPUP
2954 - vcol_first_char,
2955# endif
2956 line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002957# ifdef FEAT_PROP_POPUP
2958 // do not want virtual text counted here
2959 cts.cts_has_prop_with_text = FALSE;
2960# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002961 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002962 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002963
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002964 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002965 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002966 // line break, but for TABs the highlighting should
2967 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002968 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002969
Bram Moolenaar1306b362022-08-06 15:59:06 +01002970 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002971# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002972 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002973 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002974 wp->w_buffer->b_p_vts_array) - 1;
2975# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002976 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002977 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002978# endif
2979
Bram Moolenaar1306b362022-08-06 15:59:06 +01002980 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2981 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002982# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002983 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002984 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002985# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002986 if (VIM_ISWHITE(c))
2987 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002988# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002989 if (c == TAB)
2990 // See "Tab alignment" below.
2991 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002992# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002993 if (!wp->w_p_list)
2994 c = ' ';
2995 }
2996 }
2997#endif
zeertzjqabc80812023-09-24 23:32:18 +02002998 if (wp->w_p_list)
2999 {
3000 in_multispace = c == ' ' && (*ptr == ' '
3001 || (prev_ptr > line && prev_ptr[-1] == ' '));
3002 if (!in_multispace)
3003 multispace_pos = 0;
3004 }
zeertzjqf14b8ba2021-09-10 16:58:30 +02003005
Bram Moolenaareed9d462021-02-15 20:38:25 +01003006 // 'list': Change char 160 to 'nbsp' and space to 'space'
3007 // setting in 'listchars'. But not when the character is
3008 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003009 if (wp->w_p_list
3010 && ((((c == 160 && mb_l == 1)
3011 || (mb_utf8
3012 && ((mb_c == 160 && mb_l == 2)
3013 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01003014 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003015 || (c == ' '
3016 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02003017 && (wp->w_lcs_chars.space
3018 || (in_multispace
3019 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01003020 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003021 && ptr - line <= trailcol)))
3022 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02003023 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
3024 {
3025 c = wp->w_lcs_chars.multispace[multispace_pos++];
3026 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
3027 multispace_pos = 0;
3028 }
3029 else
3030 c = (c == ' ') ? wp->w_lcs_chars.space
3031 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003032 if (area_attr == 0 && search_attr == 0)
3033 {
3034 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003035 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003036 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003037 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003038 }
3039 mb_c = c;
3040 if (enc_utf8 && utf_char2len(c) > 1)
3041 {
3042 mb_utf8 = TRUE;
3043 u8cc[0] = 0;
3044 c = 0xc0;
3045 }
3046 else
3047 mb_utf8 = FALSE;
3048 }
3049
zeertzjq2e7cba32022-06-10 15:30:32 +01003050 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
3051 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003052 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003053 if (leadcol != 0 && in_multispace && ptr < line + leadcol
3054 && wp->w_lcs_chars.leadmultispace != NULL)
3055 {
3056 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01003057 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
3058 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003059 multispace_pos = 0;
3060 }
3061
3062 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
3063 c = wp->w_lcs_chars.trail;
3064
3065 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
3066 c = wp->w_lcs_chars.lead;
3067
zeertzjq2e7cba32022-06-10 15:30:32 +01003068 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003069 c = wp->w_lcs_chars.space;
3070
3071
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003072 if (!attr_pri)
3073 {
3074 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003075 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003076 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003077 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003078 }
3079 mb_c = c;
3080 if (enc_utf8 && utf_char2len(c) > 1)
3081 {
3082 mb_utf8 = TRUE;
3083 u8cc[0] = 0;
3084 c = 0xc0;
3085 }
3086 else
3087 mb_utf8 = FALSE;
3088 }
3089 }
3090
3091 // Handling of non-printable characters.
3092 if (!vim_isprintc(c))
3093 {
3094 // when getting a character from the file, we may have to
3095 // turn it into something else on the way to putting it
3096 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01003097 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003098 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003099 int tab_len = 0;
3100 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003101#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003102 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01003103
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003104 // only adjust the tab_len, when at the first column
3105 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01003106 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003107 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003108#endif
3109 // tab amount depends on current column
3110#ifdef FEAT_VARTABS
3111 tab_len = tabstop_padding(vcol_adjusted,
3112 wp->w_buffer->b_p_ts,
3113 wp->w_buffer->b_p_vts_array) - 1;
3114#else
3115 tab_len = (int)wp->w_buffer->b_p_ts
3116 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
3117#endif
3118
3119#ifdef FEAT_LINEBREAK
3120 if (!wp->w_p_lbr || !wp->w_p_list)
3121#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003122 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003123 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01003124 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003125 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003126#ifdef FEAT_LINEBREAK
3127 else
3128 {
3129 char_u *p;
3130 int len;
3131 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003132 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003133
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003134# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003135 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003136 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003137 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003138
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003139 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003140 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003141 && old_boguscols > 0
3142 && wlv.n_extra > tab_len)
3143 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003144# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003145 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003146 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003147 // If wlv.n_extra > 0, it gives the number of chars
3148 // to use for a tab, else we need to calculate the
3149 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003150 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3151 len = tab_len * tab2_len;
3152 if (wp->w_lcs_chars.tab3)
3153 len += mb_char2len(wp->w_lcs_chars.tab3)
3154 - tab2_len;
3155 if (wlv.n_extra > 0)
3156 len += wlv.n_extra - tab_len;
3157 c = wp->w_lcs_chars.tab1;
3158 p = alloc(len + 1);
3159 if (p == NULL)
3160 wlv.n_extra = 0;
3161 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003162 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003163 vim_memset(p, ' ', len);
3164 p[len] = NUL;
3165 vim_free(wlv.p_extra_free);
3166 wlv.p_extra_free = p;
3167 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003168 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003169 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003170
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003171 if (*p == NUL)
3172 {
3173 tab_len = i;
3174 break;
3175 }
3176
3177 // if tab3 is given, use it for the last
3178 // char
3179 if (wp->w_lcs_chars.tab3
3180 && i == tab_len - 1)
3181 lcs = wp->w_lcs_chars.tab3;
3182 p += mb_char2bytes(lcs, p);
3183 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003184 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003185 }
3186 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003187# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003188 // n_extra will be increased by
3189 // FIX_FOX_BOGUSCOLS macro below, so need to
3190 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003191 if (wlv.vcol_off_co > 0)
3192 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003193# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003194 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003195 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003196 }
3197#endif
3198#ifdef FEAT_CONCEAL
3199 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003200 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003201
3202 // Tab alignment should be identical regardless of
3203 // 'conceallevel' value. So tab compensates of all
3204 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003205 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003206 // line. Note that the tab can be longer than
3207 // 'tabstop' when there are concealed characters.
3208 FIX_FOR_BOGUSCOLS;
3209
3210 // Make sure, the highlighting for the tab char will be
3211 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003212 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003213 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003214 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003215 tab_len += vc_saved;
3216 }
3217#endif
3218 mb_utf8 = FALSE; // don't draw as UTF-8
3219 if (wp->w_p_list)
3220 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003221 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003222 ? wp->w_lcs_chars.tab3
3223 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003224#ifdef FEAT_LINEBREAK
h-east194555c2023-03-02 18:49:09 +00003225 if (wp->w_p_lbr && wlv.p_extra != NULL
3226 && *wlv.p_extra != NUL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003227 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003228 else
3229#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003230 wlv.c_extra = wp->w_lcs_chars.tab2;
3231 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003232 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003233 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003234 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003235 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003236 mb_c = c;
3237 if (enc_utf8 && utf_char2len(c) > 1)
3238 {
3239 mb_utf8 = TRUE;
3240 u8cc[0] = 0;
3241 c = 0xc0;
3242 }
3243 }
3244 else
3245 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003246 wlv.c_final = NUL;
3247 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003248 c = ' ';
3249 }
3250 }
3251 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003252 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003253 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003254 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3255 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003256 && VIsual_mode != Ctrl_V
3257 && (
3258# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003259 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003260# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003261 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003262 && !(noinvcur
3263 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003264 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003265 && lcs_eol_one > 0)
3266 {
3267 // Display a '$' after the line or highlight an extra
3268 // character if the line break is included.
3269#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3270 // For a diff line the highlighting continues after the
3271 // "$".
3272 if (
3273# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003274 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003275# ifdef LINE_ATTR
3276 &&
3277# endif
3278# endif
3279# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003280 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003281# endif
3282 )
3283#endif
3284 {
3285 // In virtualedit, visual selections may extend
3286 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003287 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003288 && wlv.tocol != MAXCOL
3289 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003290 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003291 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003292 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003293 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3294 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003295 else
3296 c = ' ';
3297 lcs_eol_one = -1;
3298 --ptr; // put it back at the NUL
3299 if (!attr_pri)
3300 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003301 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003302 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003303 n_attr = 1;
3304 }
3305 mb_c = c;
3306 if (enc_utf8 && utf_char2len(c) > 1)
3307 {
3308 mb_utf8 = TRUE;
3309 u8cc[0] = 0;
3310 c = 0xc0;
3311 }
3312 else
3313 mb_utf8 = FALSE; // don't draw as UTF-8
3314 }
3315 else if (c != NUL)
3316 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003317 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3318 if (wlv.n_extra == 0)
3319 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003320#ifdef FEAT_RIGHTLEFT
3321 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003322 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003323#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003324 wlv.c_extra = NUL;
3325 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003326#ifdef FEAT_LINEBREAK
3327 if (wp->w_p_lbr)
3328 {
3329 char_u *p;
3330
Bram Moolenaar1306b362022-08-06 15:59:06 +01003331 c = *wlv.p_extra;
3332 p = alloc(wlv.n_extra + 1);
3333 vim_memset(p, ' ', wlv.n_extra);
3334 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3335 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003336 vim_free(wlv.p_extra_free);
3337 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003338 }
3339 else
3340#endif
3341 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003342 wlv.n_extra = byte2cells(c) - 1;
3343 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003344 }
3345 if (!attr_pri)
3346 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003347 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003348 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003349 HL_ATTR(HLF_8));
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003350#ifdef FEAT_PROP_POPUP
3351 if (text_prop_type != NULL &&
3352 text_prop_flags & PT_FLAG_OVERRIDE)
3353 wlv.extra_attr = hl_combine_attr(text_prop_attr, wlv.extra_attr);
3354#endif
3355
Bram Moolenaar1306b362022-08-06 15:59:06 +01003356 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003357 }
3358 mb_utf8 = FALSE; // don't draw as UTF-8
3359 }
3360 else if (VIsual_active
3361 && (VIsual_mode == Ctrl_V
3362 || VIsual_mode == 'v')
3363 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003364 && wlv.tocol != MAXCOL
3365 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003366 && (
3367#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003368 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003369#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003370 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003371 {
3372 c = ' ';
3373 --ptr; // put it back at the NUL
3374 }
3375#if defined(LINE_ATTR)
3376 else if ((
3377# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003378 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003379# endif
3380# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003381 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003382# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003383 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003384 ) && (
3385# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003386 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003387# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003388 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003389# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003390 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003391# endif
3392 < wp->w_width)))
3393 {
3394 // Highlight until the right side of the window
3395 c = ' ';
3396 --ptr; // put it back at the NUL
3397
3398 // Remember we do the char for line highlighting.
3399 ++did_line_attr;
3400
3401 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003402 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003403 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003404 || (wp->w_p_list &&
3405 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003406 wlv.char_attr = wlv.line_attr;
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003407#ifdef FEAT_SIGNS
3408 // At end of line: if Sign is present with line highlight, reset char_attr
Christian Brabandte1eaae22023-08-19 22:36:12 +02003409 // but not when cursorline is active
3410 if (sign_present && wlv.sattr.sat_linehl > 0 && wlv.draw_state == WL_LINE
3411 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum))
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003412 wlv.char_attr = wlv.sattr.sat_linehl;
3413#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003414# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003415 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003416 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003417 wlv.diff_hlf = HLF_CHD;
3418 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003419 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003420 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003421 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3422 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003423 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003424 || (wlv.vcol >= left_curline_col
3425 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003426 wlv.char_attr = hl_combine_attr(
3427 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003428 }
3429 }
3430# endif
3431# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003432 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003433 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003434 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003435 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3436 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003437 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003438 if (!wlv.cul_screenline
3439 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003440 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003441 wlv.char_attr = hl_combine_attr(
3442 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003443 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003444 else if (wlv.line_attr)
3445 wlv.char_attr = hl_combine_attr(
3446 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003447 }
3448# endif
3449 }
3450#endif
3451 }
3452
3453#ifdef FEAT_CONCEAL
3454 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003455 && (wp != curwin || lnum != wp->w_cursor.lnum
3456 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003457 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3458 && !(lnum_in_visual_area
3459 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3460 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003461 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003462 if (((prev_syntax_id != syntax_seqnr
3463 && (syntax_flags & HL_CONCEAL) != 0)
3464 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003465 && (syn_get_sub_char() != NUL
3466 || (has_match_conc && match_conc)
3467 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003468 && wp->w_p_cole != 3)
3469 {
3470 // First time at this concealed item: display one
3471 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003472 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003473 c = match_conc;
3474 else if (syn_get_sub_char() != NUL)
3475 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003476 else if (wp->w_lcs_chars.conceal != NUL)
3477 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003478 else
3479 c = ' ';
3480
3481 prev_syntax_id = syntax_seqnr;
3482
Bram Moolenaar1306b362022-08-06 15:59:06 +01003483 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003484 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003485 wlv.vcol += wlv.n_extra;
3486 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003487 {
3488# ifdef FEAT_RIGHTLEFT
3489 if (wp->w_p_rl)
3490 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003491 wlv.col -= wlv.n_extra;
3492 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003493 }
3494 else
3495# endif
3496 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003497 wlv.boguscols += wlv.n_extra;
3498 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003499 }
3500 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003501 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003502 n_attr = 0;
3503 }
zeertzjqb557f482023-08-22 22:07:34 +02003504 else if (skip_cells == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003505 {
3506 is_concealing = TRUE;
zeertzjqb557f482023-08-22 22:07:34 +02003507 skip_cells = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003508 }
3509 mb_c = c;
3510 if (enc_utf8 && utf_char2len(c) > 1)
3511 {
3512 mb_utf8 = TRUE;
3513 u8cc[0] = 0;
3514 c = 0xc0;
3515 }
3516 else
3517 mb_utf8 = FALSE; // don't draw as UTF-8
3518 }
3519 else
3520 {
3521 prev_syntax_id = 0;
3522 is_concealing = FALSE;
3523 }
3524
zeertzjqb557f482023-08-22 22:07:34 +02003525 if (skip_cells > 0 && did_decrement_ptr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003526 // not showing the '>', put pointer back to avoid getting stuck
3527 ++ptr;
3528
3529#endif // FEAT_CONCEAL
3530 }
3531
3532#ifdef FEAT_CONCEAL
3533 // In the cursor line and we may be concealing characters: correct
3534 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003535 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003536 && wp == curwin && lnum == wp->w_cursor.lnum
3537 && conceal_cursor_line(wp)
zeertzjqb557f482023-08-22 22:07:34 +02003538 && (int)wp->w_virtcol <= wlv.vcol + skip_cells)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003539 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003540# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003541 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003542 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003543 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003544# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003545 wp->w_wcol = wlv.col - wlv.boguscols;
3546 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003547 did_wcol = TRUE;
3548 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003549# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003550 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003551# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003552 }
3553#endif
3554
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003555 // Use "wlv.extra_attr", but don't override visual selection
3556 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003557 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3558 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003559 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003560 && (!attr_pri
3561#ifdef FEAT_PROP_POPUP
3562 || (text_prop_flags & PT_FLAG_OVERRIDE)
3563#endif
3564 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003565 {
3566#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003567 if (wlv.line_attr)
3568 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003569 else
3570#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003571 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003572#ifdef FEAT_PROP_POPUP
3573 if (reset_extra_attr)
3574 {
3575 reset_extra_attr = FALSE;
3576 wlv.extra_attr = 0;
3577 }
3578#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003579 }
3580
3581#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3582 // XIM don't send preedit_start and preedit_end, but they send
3583 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3584 // im_is_preediting() here.
3585 if (p_imst == IM_ON_THE_SPOT
3586 && xic != NULL
3587 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003588 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003589 && !p_imdisable
3590 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003591 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003592 {
3593 colnr_T tcol;
3594
3595 if (preedit_end_col == MAXCOL)
3596 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3597 else
3598 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003599 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003600 {
3601 if (feedback_old_attr < 0)
3602 {
3603 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003604 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003605 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003606 wlv.char_attr = im_get_feedback_attr(feedback_col);
3607 if (wlv.char_attr < 0)
3608 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003609 feedback_col++;
3610 }
3611 else if (feedback_old_attr >= 0)
3612 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003613 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003614 feedback_old_attr = -1;
3615 feedback_col = 0;
3616 }
3617 }
3618#endif
3619 // Handle the case where we are in column 0 but not on the first
3620 // character of the line and the user wants us to show us a
3621 // special character (via 'listchars' option "precedes:<char>".
3622 if (lcs_prec_todo != NUL
3623 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003624 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3625 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003626#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003627 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003628#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003629 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003630 && c != NUL)
3631 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003632 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003633 lcs_prec_todo = NUL;
3634 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3635 {
3636 // Double-width character being overwritten by the "precedes"
3637 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003638 wlv.c_extra = MB_FILLER_CHAR;
3639 wlv.c_final = NUL;
3640 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003641 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003642 wlv.extra_attr =
3643 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003644 }
3645 mb_c = c;
3646 if (enc_utf8 && utf_char2len(c) > 1)
3647 {
3648 mb_utf8 = TRUE;
3649 u8cc[0] = 0;
3650 c = 0xc0;
3651 }
3652 else
3653 mb_utf8 = FALSE; // don't draw as UTF-8
3654 if (!attr_pri)
3655 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003656 saved_attr3 = wlv.char_attr; // save current attr
3657 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003658 n_attr3 = 1;
3659 }
3660 }
3661
3662 // At end of the text line or just after the last character.
3663 if ((c == NUL
3664#if defined(LINE_ATTR)
3665 || did_line_attr == 1
3666#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003667 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003668 {
3669#ifdef FEAT_SEARCH_EXTRA
3670 // flag to indicate whether prevcol equals startcol of search_hl or
3671 // one of the matches
3672 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3673 (long)(ptr - line) - (c == NUL));
3674#endif
3675 // Invert at least one char, used for Visual and empty line or
3676 // highlight match at end of line. If it's beyond the last
3677 // char on the screen, just overwrite that one (tricky!) Not
3678 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003679 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003680 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003681 && (VIsual_mode != Ctrl_V
3682 || lnum == VIsual.lnum
3683 || lnum == curwin->w_cursor.lnum)
3684 && c == NUL)
3685#ifdef FEAT_SEARCH_EXTRA
3686 // highlight 'hlsearch' match at end of line
3687 || (prevcol_hl_flag
3688# ifdef FEAT_SYN_HL
3689 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3690 && !(wp == curwin && VIsual_active))
3691# endif
3692# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003693 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003694# endif
3695# if defined(LINE_ATTR)
3696 && did_line_attr <= 1
3697# endif
3698 )
3699#endif
3700 ))
3701 {
3702 int n = 0;
3703
3704#ifdef FEAT_RIGHTLEFT
3705 if (wp->w_p_rl)
3706 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003707 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003708 n = 1;
3709 }
3710 else
3711#endif
3712 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003713 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003714 n = -1;
3715 }
3716 if (n != 0)
3717 {
3718 // At the window boundary, highlight the last character
3719 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003720 wlv.off += n;
3721 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003722 }
3723 else
3724 {
3725 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003726 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003727 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003728 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003729 }
3730#ifdef FEAT_SEARCH_EXTRA
3731 if (area_attr == 0)
3732 {
3733 // Use attributes from match with highest priority among
3734 // 'search_hl' and the match list.
3735 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003736 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003737 }
3738#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003739 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003740 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003741#ifdef FEAT_RIGHTLEFT
3742 if (wp->w_p_rl)
3743 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003744 --wlv.col;
3745 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003746 }
3747 else
3748#endif
3749 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003750 ++wlv.col;
3751 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003752 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003753 ++wlv.vcol;
3754 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003755 }
3756 }
3757
3758 // At end of the text line.
3759 if (c == NUL)
3760 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003761#ifdef FEAT_PROP_POPUP
3762 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003763 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003764 // Put the pointer back to the NUL.
3765 --ptr;
3766 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003767 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003768 else
3769#endif
3770 {
3771 draw_screen_line(wp, &wlv);
3772
3773 // Update w_cline_height and w_cline_folded if the cursor line
3774 // was updated (saves a call to plines() later).
3775 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3776 {
3777 curwin->w_cline_row = startrow;
3778 curwin->w_cline_height = wlv.row - startrow;
3779#ifdef FEAT_FOLDING
3780 curwin->w_cline_folded = FALSE;
3781#endif
3782 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3783 }
3784 break;
3785 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003786 }
3787
3788 // Show "extends" character from 'listchars' if beyond the line end and
3789 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003790 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003791 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003792 && wp->w_p_list
3793 && !wp->w_p_wrap
3794#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003795 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003796#endif
3797 && (
3798#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003799 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003800#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003801 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003802 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003803 || lcs_eol_one > 0
3804 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
zeertzjq6a389722023-08-27 19:04:14 +02003805 || *wlv.p_extra != NUL))
3806#ifdef FEAT_PROP_POPUP
zeertzjq4e26a9a2023-12-03 17:50:47 +01003807 || text_prop_next <= last_textprop_text_idx
zeertzjq6a389722023-08-27 19:04:14 +02003808#endif
3809 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003810 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003811 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003812 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003813 mb_c = c;
3814 if (enc_utf8 && utf_char2len(c) > 1)
3815 {
3816 mb_utf8 = TRUE;
3817 u8cc[0] = 0;
3818 c = 0xc0;
3819 }
3820 else
3821 mb_utf8 = FALSE;
3822 }
3823
3824#ifdef FEAT_SYN_HL
3825 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003826 if (wlv.draw_color_col)
3827 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003828
3829 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3830 // highlight the cursor position itself.
3831 // Also highlight the 'colorcolumn' if it is different than
3832 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003833 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3834 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003835 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003836 if (((wlv.draw_state == WL_LINE
3837 || wlv.draw_state == WL_BRI
3838 || wlv.draw_state == WL_SBR)
3839 && !lnum_in_visual_area
3840 && search_attr == 0
3841 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003842# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003843 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003844# endif
3845 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003846 {
3847 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3848 && lnum != wp->w_cursor.lnum)
3849 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003850 vcol_save_attr = wlv.char_attr;
3851 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3852 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003853 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003854 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003855 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003856 vcol_save_attr = wlv.char_attr;
3857 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003858 }
3859 }
3860#endif
3861
zeertzjq8fc6a1d2023-08-20 18:12:54 +02003862 if (wlv.draw_state == WL_LINE)
3863 vcol_prev = wlv.vcol;
3864
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003865 // Store character to be displayed.
3866 // Skip characters that are left of the screen for 'nowrap'.
zeertzjqb557f482023-08-22 22:07:34 +02003867 if (wlv.draw_state < WL_LINE || skip_cells <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003868 {
3869 // Store the character.
3870#if defined(FEAT_RIGHTLEFT)
3871 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3872 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003873 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003874 --wlv.off;
3875 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003876 }
3877#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003878 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003879 if (enc_dbcs == DBCS_JPNU)
3880 {
3881 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003882 ScreenLines[wlv.off] = 0x8e;
3883 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003884 }
3885 else if (enc_utf8)
3886 {
3887 if (mb_utf8)
3888 {
3889 int i;
3890
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003891 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003892 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003893 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003894 for (i = 0; i < Screen_mco; ++i)
3895 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003896 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003897 if (u8cc[i] == 0)
3898 break;
3899 }
3900 }
3901 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003902 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003903 }
3904 if (multi_attr)
3905 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003906 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003907 multi_attr = 0;
3908 }
3909 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003910 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003911
zeertzjqdb54e982023-09-21 16:33:09 +02003912 if (wlv.draw_state > WL_NR
3913#ifdef FEAT_DIFF
3914 && wlv.filler_todo <= 0
3915#endif
3916 )
3917 ScreenCols[wlv.off] = wlv.vcol;
3918 else
3919 ScreenCols[wlv.off] = -1;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003920
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003921 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3922 {
3923 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003924 ++wlv.off;
3925 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003926 if (enc_utf8)
3927 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003928 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003929 else
3930 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003931 ScreenLines[wlv.off] = mb_c & 0xff;
zeertzjqdb54e982023-09-21 16:33:09 +02003932
Bram Moolenaar1306b362022-08-06 15:59:06 +01003933 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003934#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003935 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003936#endif
3937 )
zeertzjqdb54e982023-09-21 16:33:09 +02003938 ScreenCols[wlv.off] = ++wlv.vcol;
3939 else
3940 ScreenCols[wlv.off] = -1;
3941
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003942 // When "wlv.tocol" is halfway a character, set it to the end
3943 // of the character, otherwise highlighting won't stop.
3944 if (wlv.tocol == wlv.vcol)
3945 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003946
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003947#ifdef FEAT_RIGHTLEFT
3948 if (wp->w_p_rl)
3949 {
3950 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003951 --wlv.off;
3952 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003953 }
3954#endif
3955 }
3956#ifdef FEAT_RIGHTLEFT
3957 if (wp->w_p_rl)
3958 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003959 --wlv.off;
3960 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003961 }
3962 else
3963#endif
3964 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003965 ++wlv.off;
3966 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003967 }
3968 }
3969#ifdef FEAT_CONCEAL
3970 else if (wp->w_p_cole > 0 && is_concealing)
3971 {
zeertzjqb557f482023-08-22 22:07:34 +02003972 --skip_cells;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003973 ++wlv.vcol_off_co;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003974 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003975 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003976 if (wp->w_p_wrap)
3977 {
3978 // Special voodoo required if 'wrap' is on.
3979 //
3980 // Advance the column indicator to force the line
3981 // drawing to wrap early. This will make the line
3982 // take up the same screen space when parts are concealed,
3983 // so that cursor line computations aren't messed up.
3984 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003985 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003986 // trailing junk to be written out of the screen line
3987 // we are building, 'boguscols' keeps track of the number
3988 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003989 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003990 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003991 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003992# ifdef FEAT_RIGHTLEFT
3993 if (wp->w_p_rl)
3994 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003995 wlv.col -= wlv.n_extra;
3996 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003997 }
3998 else
3999# endif
4000 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004001 wlv.col += wlv.n_extra;
4002 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004003 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01004004 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004005 n_attr = 0;
4006 }
4007
4008
4009 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
4010 {
4011 // Need to fill two screen columns.
4012# ifdef FEAT_RIGHTLEFT
4013 if (wp->w_p_rl)
4014 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004015 --wlv.boguscols;
4016 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004017 }
4018 else
4019# endif
4020 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004021 ++wlv.boguscols;
4022 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004023 }
4024 }
4025
4026# ifdef FEAT_RIGHTLEFT
4027 if (wp->w_p_rl)
4028 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004029 --wlv.boguscols;
4030 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004031 }
4032 else
4033# endif
4034 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004035 ++wlv.boguscols;
4036 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004037 }
4038 }
4039 else
4040 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004041 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004042 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004043 wlv.vcol += wlv.n_extra;
4044 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004045 n_attr = 0;
4046 }
4047 }
4048
4049 }
4050#endif // FEAT_CONCEAL
4051 else
zeertzjqb557f482023-08-22 22:07:34 +02004052 --skip_cells;
4053
4054 if (wlv.draw_state > WL_NR && skipped_cells > 0)
4055 {
4056 wlv.vcol += skipped_cells;
4057 skipped_cells = 0;
4058 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004059
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004060 // Only advance the "wlv.vcol" when after the 'number' or
4061 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004062 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004063#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004064 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004065#endif
4066 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004067 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004068
4069#ifdef FEAT_SYN_HL
4070 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004071 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004072#endif
4073
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004074 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01004075 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
4076 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004077
4078 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01004079 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004080 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004081 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004082 if (wlv.n_attr_skip > 0)
4083 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004084
4085 // At end of screen line and there is more to come: Display the line
4086 // so far. If there is no more to display it is caught above.
4087 if ((
4088#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004089 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004090#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004091 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01004092 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02004093 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004094#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004095 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004096#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004097#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004098 || text_prop_above || text_prop_follows
zeertzjq4e26a9a2023-12-03 17:50:47 +01004099 || text_prop_next <= last_textprop_text_idx
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004100#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01004101 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01004102 && wlv.p_extra != at_end_str)
4103 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
4104 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004105 )
4106 {
4107#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01004108 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01004109 wlv_screen_line(wp, &wlv, FALSE);
4110 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004111 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004112 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004113#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01004114 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004115#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004116 ++wlv.row;
4117 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004118
4119 // When not wrapping and finished diff lines, or when displayed
4120 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01004121 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004122#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004123 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004124#endif
4125#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01004126 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004127#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01004128 ) || lcs_eol_one == -1)
4129#ifdef FEAT_PROP_POPUP
4130 && !text_prop_follows
4131#endif
4132 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004133 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004134#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004135 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004136 {
4137 // do not output more of the line, only the "below" prop
4138 ptr += STRLEN(ptr);
4139# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004140 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004141# endif
4142 }
4143#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004144
4145 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004146 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004147#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004148 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004149#endif
4150 )
4151 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004152 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
4153 draw_vsep_win(wp, wlv.row);
4154 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004155 }
4156
4157 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004158 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004159 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004160 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004161 break;
4162 }
4163
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004164 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004165#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004166 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004167#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004168#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004169 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004170#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004171 && wp->w_width == Columns)
4172 {
4173 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004174 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004175
4176 // Special trick to make copy/paste of wrapped lines work with
4177 // xterm/screen: write an extra character beyond the end of
4178 // the line. This will work with all terminal types
4179 // (regardless of the xn,am settings).
4180 // Only do this on a fast tty.
4181 // Only do this if the cursor is on the current line
4182 // (something has been written in it).
4183 // Don't do this for the GUI.
4184 // Don't do this for double-width characters.
4185 // Don't do this for a window not at the right screen border.
4186 if (p_tf
4187#ifdef FEAT_GUI
4188 && !gui.in_use
4189#endif
4190 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004191 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4192 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004193 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004194 || (*mb_off2cells)(
4195 LineOffset[wlv.screen_row - 1]
4196 + (int)Columns - 2,
4197 LineOffset[wlv.screen_row]
4198 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004199 {
4200 // First make sure we are at the end of the screen line,
4201 // then output the same character again to let the
4202 // terminal know about the wrap. If the terminal doesn't
4203 // auto-wrap, we overwrite the character.
4204 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004205 screen_char(LineOffset[wlv.screen_row - 1]
4206 + (unsigned)Columns - 1,
4207 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004208
4209 // When there is a multi-byte character, just output a
4210 // space to keep it simple.
4211 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004212 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004213 out_char(' ');
4214 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004215 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004216 + (Columns - 1)]);
4217 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004218 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004219 screen_start(); // don't know where cursor is now
4220 }
4221 }
4222
Bram Moolenaar1306b362022-08-06 15:59:06 +01004223 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004224
Bram Moolenaareed9d462021-02-15 20:38:25 +01004225 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004226#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004227 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004228# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004229 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004230# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004231 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004232 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004233#endif
4234#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004235 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004236 // When the filler lines are actually below the last line of the
4237 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004238 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004239 break;
4240#endif
4241 }
4242
4243 } // for every character in the line
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004244#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004245 vim_free(text_props);
4246 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004247 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004248#endif
4249
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004250 vim_free(wlv.p_extra_free);
zeertzjq58e1e012023-06-04 18:46:28 +01004251 vim_free(wlv.saved_p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004252 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004253}