blob: 9f385f033a68f7b5ed5e704c0fd0dd149c5c5f57 [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;
530 // Correct end of highlighted area for 'breakindent',
531 // required when 'linebreak' is also set.
532 if (wlv->tocol == wlv->vcol)
533 wlv->tocol += wlv->n_extra;
534 }
535 }
536}
537#endif
538
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100539#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
540 static void
541handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
542{
543# ifdef FEAT_DIFF
544 if (wlv->filler_todo > 0)
545 {
546 // Draw "deleted" diff line(s).
547 if (char2cells(wp->w_fill_chars.diff) > 1)
548 {
549 wlv->c_extra = '-';
550 wlv->c_final = NUL;
551 }
552 else
553 {
554 wlv->c_extra = wp->w_fill_chars.diff;
555 wlv->c_final = NUL;
556 }
557# ifdef FEAT_RIGHTLEFT
558 if (wp->w_p_rl)
559 wlv->n_extra = wlv->col + 1;
560 else
561# endif
562 wlv->n_extra = wp->w_width - wlv->col;
563 wlv->char_attr = HL_ATTR(HLF_DED);
564 }
565# endif
566
567# ifdef FEAT_LINEBREAK
568 char_u *sbr = get_showbreak_value(wp);
569 if (*sbr != NUL && wlv->need_showbreak)
570 {
571 // Draw 'showbreak' at the start of each broken line.
572 wlv->p_extra = sbr;
573 wlv->c_extra = NUL;
574 wlv->c_final = NUL;
575 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100576 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100577 wlv->need_showbreak = FALSE;
578 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100579
580 // Correct start of highlighted area for 'showbreak'.
581 if (wlv->fromcol >= wlv->vcol && wlv->fromcol < wlv->vcol_sbr)
582 wlv->fromcol = wlv->vcol_sbr;
583
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100584 // Correct end of highlighted area for 'showbreak',
585 // required when 'linebreak' is also set.
586 if (wlv->tocol == wlv->vcol)
587 wlv->tocol += wlv->n_extra;
588 // combine 'showbreak' with 'wincolor'
589 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
590# ifdef FEAT_SYN_HL
591 // combine 'showbreak' with 'cursorline'
592 if (wlv->cul_attr != 0)
593 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
594# endif
595 }
596# endif
597}
598#endif
599
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100600#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100601/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100602 * Return the cell size of virtual text after truncation.
603 */
604 static int
605textprop_size_after_trunc(
606 win_T *wp,
607 int flags, // TP_FLAG_ALIGN_*
608 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100609 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100610 char_u *text,
611 int *n_used_ptr)
612{
613 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100614 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100615 int len = (int)STRLEN(text);
616 int strsize = 0;
617 int n_used;
618
Bram Moolenaar7e017462022-10-11 21:02:09 +0100619 // if the remaining size is to small and 'wrap' is set we wrap anyway and
620 // use the next line
621 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100622 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100623 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100624 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100625 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
626 {
627 int clen = ptr2cells(text + n_used);
628
629 if (strsize + clen > space)
630 break;
631 strsize += clen;
632 }
633 *n_used_ptr = n_used;
634 return strsize;
635}
636
637/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100638 * Take care of padding, right-align and truncation of virtual text after a
639 * line.
640 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
641 * padding, right-align and truncation. Otherwise only the size is computed.
642 * When "n_attr" is NULL returns the number of screen cells used.
643 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100644 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100645 int
646text_prop_position(
647 win_T *wp,
648 textprop_T *tp,
porygonisaduck38854b52022-11-27 20:55:05 +0000649 int vcol, // current text column
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100650 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100651 int *n_extra, // nr of bytes for virtual text
652 char_u **p_extra, // virtual text
653 int *n_attr, // attribute cells, NULL if not used
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000654 int *n_attr_skip, // cells to skip attr, NULL if not used
655 int do_skip) // skip_cells is not zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200656{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100657 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100658 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100659 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
Bram Moolenaar1aeb3eb2023-01-01 14:04:51 +0000660 int wrap = tp->tp_col < MAXCOL || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100661 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
porygonisaduck38854b52022-11-27 20:55:05 +0000662 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100663 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100664 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100665 int before = room; // spaces before the text
666 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100667 int n_used = *n_extra;
668 char_u *l = NULL;
669 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100670 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100671 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200672
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100673 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100674 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100675 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100676
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100677 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100678 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100679 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100680 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar2354b662023-04-23 21:42:25 +0100681 if (after < 0)
682 {
683 // text "above" has too much padding to fit
684 padding += after;
685 after = 0;
686 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100687 }
688 else
689 {
690 // Right-align: fill with before
691 if (right)
692 before -= cells;
porygonisaduck38854b52022-11-27 20:55:05 +0000693
694 // Below-align: empty line add one character
Bram Moolenaar7c02ad92022-11-29 21:37:13 +0000695 if (below && vcol == 0 && col_with_padding == col_off
696 && wp->w_width - col_off == before)
697 col_with_padding += 1;
porygonisaduck38854b52022-11-27 20:55:05 +0000698
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100699 if (before < 0
700 || !(right || below)
porygonisaduck38854b52022-11-27 20:55:05 +0000701 || (below ? (col_with_padding <= col_off || !wp->w_p_wrap)
702 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100703 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100704 if (right && (wrap
705 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100706 {
707 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100708 before = wp->w_width - col_off - strsize + room;
709 if (before < 0)
710 before = 0;
711 else
712 n_used = *n_extra;
713 }
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000714 else if (below && before > vcol && do_skip)
715 before -= vcol;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100716 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100717 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100718 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100719 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100720
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100721 // With 'nowrap' add one to show the "extends" character if needed (it
722 // doesn't show if the text just fits).
723 if (!wp->w_p_wrap
724 && n_used < *n_extra
725 && wp->w_lcs_chars.ext != NUL
726 && wp->w_p_list)
727 ++n_used;
728
729 // add 1 for NUL, 2 for when '…' is used
730 if (n_attr != NULL)
Christian Brabandtf1cc4d52023-08-12 00:14:14 +0200731 l = alloc(n_used + before + after + (padding > 0 ? padding : 0) + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100732 if (n_attr == NULL || l != NULL)
733 {
734 int off = 0;
735
736 if (n_attr != NULL)
737 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100738 vim_memset(l, ' ', before);
739 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100740 if (padding > 0)
741 {
742 vim_memset(l + off, ' ', padding);
743 off += padding;
744 }
745 vim_strncpy(l + off, *p_extra, n_used);
746 off += n_used;
747 }
748 else
749 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100750 off = before + after + padding + n_used;
751 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100752 }
753 if (n_attr != NULL)
754 {
755 if (n_used < *n_extra && wp->w_p_wrap)
756 {
757 char_u *lp = l + off - 1;
758
759 if (has_mbyte)
760 {
h-east4c42c7e2023-04-17 21:44:57 +0100761 char_u buf[MB_MAXBYTES + 1];
762 char_u *cp = buf;
763
764 // change the last character to '…', converted to the
765 // current 'encoding'
766 STRCPY(buf, "…");
767 if (!enc_utf8)
768 {
769 vimconv_T vc;
770
771 vc.vc_type = CONV_NONE;
772 convert_setup(&vc, (char_u *)"utf-8", p_enc);
773 if (vc.vc_type != CONV_NONE)
774 {
775 cp = string_convert(&vc, buf, NULL);
776 if (cp == NULL)
777 {
778 // when conversion fails use '>'
779 cp = buf;
780 STRCPY(buf, ">");
781 }
782 convert_setup(&vc, NULL, NULL);
783 }
784 }
785
786 lp -= (*mb_ptr2cells)(cp) - 1;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100787 lp -= (*mb_head_off)(l, lp);
h-east4c42c7e2023-04-17 21:44:57 +0100788 STRCPY(lp, cp);
Bram Moolenaar13845c42022-10-09 15:26:03 +0100789 n_used = lp - l + 3 - before - padding;
h-east4c42c7e2023-04-17 21:44:57 +0100790 if (cp != buf)
791 vim_free(cp);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100792 }
793 else
794 // change last character to '>'
795 *lp = '>';
796 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100797 else if (after > 0)
798 {
799 vim_memset(l + off, ' ', after);
800 l[off + after] = NUL;
801 }
802
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100803 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100804 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100805 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100806 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100807 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100808
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000809 // n_attr_skip will not be decremented before draw_state is
810 // WL_LINE
Christian Brabandtf1cc4d52023-08-12 00:14:14 +0200811 *n_attr_skip = before + (padding > 0 ? padding : 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100812 }
813 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100814 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100815
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100816 if (n_attr == NULL)
817 return cells;
818 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200819}
820#endif
821
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100822/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100823 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100824 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
825 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100826 */
827 static void
828wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
829{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100830 if (wlv->row == 0 && wp->w_skipcol > 0
831#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100832 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100833 && *get_showbreak_value(wp) == NUL
834#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100835 // do not overwrite the 'listchars' "precedes" text with "<<<"
836 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100837 {
838 int off = (int)(current_ScreenLine - ScreenLines);
zeertzjqecb87dd2023-06-03 19:45:06 +0100839 int max_off = off + screen_Columns;
Bram Moolenaareb4de622022-10-15 13:42:17 +0100840 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100841
Bram Moolenaareb4de622022-10-15 13:42:17 +0100842 if (wp->w_p_nu && wp->w_p_rnu)
843 // Do not overwrite the line number, change "123 text" to
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100844 // "123<<<xt".
Bram Moolenaareb4de622022-10-15 13:42:17 +0100845 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
846 {
847 ++off;
848 ++skip;
849 }
850
851 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100852 {
zeertzjqecb87dd2023-06-03 19:45:06 +0100853 if ((*mb_off2cells)(off, max_off) > 1)
854 // When the first half of a double-width character is
855 // overwritten, change the second half to a space.
856 ScreenLines[off + 1] = ' ';
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100857 ScreenLines[off] = '<';
858 if (enc_utf8)
859 ScreenLinesUC[off] = 0;
860 ScreenAttrs[off] = HL_ATTR(HLF_AT);
861 ++off;
862 }
863 }
864
865 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
866 negative_width ? -wp->w_width : wp->w_width,
867 wlv->screen_line_flags);
868}
869
870/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100871 * Called when finished with the line: draw the screen line and handle any
872 * highlighting until the right of the window.
873 */
874 static void
875draw_screen_line(win_T *wp, winlinevars_T *wlv)
876{
877#ifdef FEAT_SYN_HL
878 long v;
879
880 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
881 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100882 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100883 else
884 v = wp->w_leftcol;
885
886 // check if line ends before left margin
887 if (wlv->vcol < v + wlv->col - win_col_off(wp))
888 wlv->vcol = v + wlv->col - win_col_off(wp);
889# ifdef FEAT_CONCEAL
890 // Get rid of the boguscols now, we want to draw until the right
891 // edge for 'cursorcolumn'.
892 wlv->col -= wlv->boguscols;
893 wlv->boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000894# define VCOL_HLC (wlv->vcol - wlv->vcol_off_co - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100895# else
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000896# define VCOL_HLC (wlv->vcol - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100897# endif
898
899 if (wlv->draw_color_col)
900 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
901
902 if (((wp->w_p_cuc
903 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
904 && (int)wp->w_virtcol <
905 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
906 && wlv->lnum != wp->w_cursor.lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000907 || wlv->draw_color_col
908# ifdef LINE_ATTR
909 || wlv->line_attr != 0
910# endif
911 || wlv->win_attr != 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100912# ifdef FEAT_RIGHTLEFT
913 && !wp->w_p_rl
914# endif
915 )
916 {
917 int rightmost_vcol = 0;
918 int i;
919
920 if (wp->w_p_cuc)
921 rightmost_vcol = wp->w_virtcol;
922 if (wlv->draw_color_col)
923 // determine rightmost colorcolumn to possibly draw
924 for (i = 0; wlv->color_cols[i] >= 0; ++i)
925 if (rightmost_vcol < wlv->color_cols[i])
926 rightmost_vcol = wlv->color_cols[i];
927
928 while (wlv->col < wp->w_width)
929 {
930 ScreenLines[wlv->off] = ' ';
931 if (enc_utf8)
932 ScreenLinesUC[wlv->off] = 0;
933 ScreenCols[wlv->off] = MAXCOL;
934 ++wlv->col;
935 if (wlv->draw_color_col)
936 wlv->draw_color_col = advance_color_col(
937 VCOL_HLC, &wlv->color_cols);
938
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000939 int attr = wlv->win_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100940 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000941 attr = HL_ATTR(HLF_CUC);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100942 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000943 attr = HL_ATTR(HLF_MC);
944# ifdef LINE_ATTR
945 else if (wlv->line_attr != 0)
946 attr = wlv->line_attr;
947# endif
948 ScreenAttrs[wlv->off++] = attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100949
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000950 if (VCOL_HLC >= rightmost_vcol
951# ifdef LINE_ATTR
952 && wlv->line_attr == 0
953# endif
954 && wlv->win_attr == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100955 break;
956
957 ++wlv->vcol;
958 }
959 }
960#endif
961
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100962 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100963 ++wlv->row;
964 ++wlv->screen_row;
965}
966#undef VCOL_HLC
967
968/*
969 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100970 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100971 */
972 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100973win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100974{
975 wlv->col = 0;
976 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
Christian Brabandtdd75fcf2023-10-11 21:51:19 +0200977#ifdef FEAT_LINEBREAK
978 wlv->need_lbr = FALSE;
979#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100980
981#ifdef FEAT_RIGHTLEFT
982 if (wp->w_p_rl)
983 {
984 // Rightleft window: process the text in the normal direction, but put
985 // it in current_ScreenLine[] from right to left. Start at the
986 // rightmost column of the window.
987 wlv->col = wp->w_width - 1;
988 wlv->off += wlv->col;
989 wlv->screen_line_flags |= SLF_RIGHTLEFT;
990 }
991#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100992 if (save_extra)
993 {
994 // reset the drawing state for the start of a wrapped line
995 wlv->draw_state = WL_START;
996 wlv->saved_n_extra = wlv->n_extra;
997 wlv->saved_p_extra = wlv->p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +0100998 vim_free(wlv->saved_p_extra_free);
999 wlv->saved_p_extra_free = wlv->p_extra_free;
1000 wlv->p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001001 wlv->saved_extra_attr = wlv->extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001002 wlv->saved_n_attr_skip = wlv->n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001003 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001004 wlv->saved_c_extra = wlv->c_extra;
1005 wlv->saved_c_final = wlv->c_final;
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02001006#ifdef FEAT_LINEBREAK
1007 wlv->need_lbr = TRUE;
1008#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001009#ifdef FEAT_SYN_HL
1010 if (!(wlv->cul_screenline
1011# ifdef FEAT_DIFF
1012 && wlv->diff_hlf == (hlf_T)0
1013# endif
1014 ))
1015 wlv->saved_char_attr = wlv->char_attr;
1016 else
1017#endif
1018 wlv->saved_char_attr = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001019
1020 // these are not used until restored in win_line_continue()
Bram Moolenaar1306b362022-08-06 15:59:06 +01001021 wlv->n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001022 wlv->n_attr_skip = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001023 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001024}
1025
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001026/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001027 * Called when wlv->draw_state is set to WL_LINE.
1028 */
1029 static void
1030win_line_continue(winlinevars_T *wlv)
1031{
1032 if (wlv->saved_n_extra > 0)
1033 {
1034 // Continue item from end of wrapped line.
1035 wlv->n_extra = wlv->saved_n_extra;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001036 wlv->saved_n_extra = 0;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001037 wlv->c_extra = wlv->saved_c_extra;
1038 wlv->c_final = wlv->saved_c_final;
1039 wlv->p_extra = wlv->saved_p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +01001040 vim_free(wlv->p_extra_free);
1041 wlv->p_extra_free = wlv->saved_p_extra_free;
1042 wlv->saved_p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001043 wlv->extra_attr = wlv->saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001044 wlv->n_attr_skip = wlv->saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001045 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001046 wlv->char_attr = wlv->saved_char_attr;
1047 }
1048 else
1049 wlv->char_attr = wlv->win_attr;
1050}
1051
zeertzjqb7acea12022-12-12 13:20:43 +00001052#ifdef FEAT_SYN_HL
1053 static void
1054apply_cursorline_highlight(
1055 winlinevars_T *wlv,
1056 int sign_present UNUSED)
1057{
1058 wlv->cul_attr = HL_ATTR(HLF_CUL);
1059# ifdef FEAT_SIGNS
1060 // Combine the 'cursorline' and sign highlighting, depending on
1061 // the sign priority.
1062 if (sign_present && wlv->sattr.sat_linehl > 0)
1063 {
1064 if (wlv->sattr.sat_priority >= 100)
1065 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1066 else
1067 wlv->line_attr = hl_combine_attr(wlv->line_attr, wlv->cul_attr);
1068 }
1069 else
1070# endif
1071# if defined(FEAT_QUICKFIX)
1072 // let the line attribute overrule 'cursorline', otherwise
1073 // it disappears when both have background set;
1074 // 'cursorline' can use underline or bold to make it show
1075 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1076# else
1077 wlv->line_attr = wlv->cul_attr;
1078# endif
1079}
1080#endif
1081
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001082/*
Luuk van Baal30805a12023-05-27 22:22:10 +01001083 * Display line "lnum" of window "wp" on the screen.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001084 * Start at row "startrow", stop when "endrow" is reached.
Luuk van Baal30805a12023-05-27 22:22:10 +01001085 * When "number_only" is TRUE only update the number column.
1086 * "spv" is used to store information for spell checking, kept between
1087 * sequential calls for the same window.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001088 * wp->w_virtcol needs to be valid.
1089 *
1090 * Return the number of last row the line occupies.
1091 */
1092 int
1093win_line(
1094 win_T *wp,
1095 linenr_T lnum,
1096 int startrow,
1097 int endrow,
Luuk van Baal30805a12023-05-27 22:22:10 +01001098 int number_only,
1099 spellvars_T *spv UNUSED)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001100{
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001101 winlinevars_T wlv; // variables passed between functions
1102
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001103 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001104 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001105 char_u *line; // current line
1106 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001107
Bram Moolenaar1306b362022-08-06 15:59:06 +01001108#ifdef FEAT_PROP_POPUP
1109 char_u *p_extra_free2 = NULL; // another p_extra to be freed
1110#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001111#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001112 int in_linebreak = FALSE; // n_extra set for showing linebreak
1113#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001114 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +01001115 // displaying eol at end-of-line
1116 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001117 int lcs_prec_todo = wp->w_lcs_chars.prec;
1118 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001119
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001120 int n_attr = 0; // chars with special attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001121 int saved_attr2 = 0; // char_attr saved for n_attr
1122 int n_attr3 = 0; // chars with overruling special attr
1123 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001124
zeertzjqb557f482023-08-22 22:07:34 +02001125 int skip_cells = 0; // nr of cells to skip for w_leftcol or
1126 // w_skipcol or concealing
1127 int skipped_cells = 0; // nr of skipped cells for virtual text
1128 // to be added to wlv.vcol later
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001129 int fromcol_prev = -2; // start of inverting after cursor
1130 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001131 int lnum_in_visual_area = FALSE;
1132 pos_T pos;
1133 long v;
1134
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001135 int attr_pri = FALSE; // char_attr has priority
1136 int area_highlighting = FALSE; // Visual or incsearch highlighting
1137 // in this line
1138 int vi_attr = 0; // attributes for Visual and incsearch
1139 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001140 int area_attr = 0; // attributes desired by highlighting
1141 int search_attr = 0; // attributes desired by 'hlsearch'
1142#ifdef FEAT_SYN_HL
1143 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1144 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001145 int prev_syntax_col = -1; // column of prev_syntax_attr
1146 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001147 int has_syntax = FALSE; // this buffer has syntax highl.
1148 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001149#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001150#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001151 int did_line = FALSE; // set to TRUE when line text done
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001152 int text_prop_count;
zeertzjq4e26a9a2023-12-03 17:50:47 +01001153 int last_textprop_text_idx = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001154 int text_prop_next = 0; // next text property to use
1155 textprop_T *text_props = NULL;
1156 int *text_prop_idxs = NULL;
1157 int text_props_active = 0;
1158 proptype_T *text_prop_type = NULL;
1159 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001160 int text_prop_attr_comb = 0; // text_prop_attr combined with
1161 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001162 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001163 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001164 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001165 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001166 int saved_search_attr = 0; // search_attr to be used when n_extra
1167 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001168 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001169 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001170#endif
1171#ifdef FEAT_SPELL
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001172 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001173# define SPWORDLEN 150
1174 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1175 int nextlinecol = 0; // column where nextline[] starts
1176 int nextline_idx = 0; // index in nextline[] where next line
1177 // starts
1178 int spell_attr = 0; // attributes desired by spelling
1179 int word_end = 0; // last byte with same spell_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001180 int cur_checked_col = 0; // checked column for current line
1181#endif
1182 int extra_check = 0; // has extra highlighting
1183 int multi_attr = 0; // attributes desired by multibyte
1184 int mb_l = 1; // multi-byte byte length
1185 int mb_c = 0; // decoded multi-byte character
1186 int mb_utf8 = FALSE; // screen char is UTF-8 char
1187 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001188#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001189 int change_start = MAXCOL; // first col of changed area
1190 int change_end = -1; // last col of changed area
1191#endif
1192 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001193 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001194 int in_multispace = FALSE; // in multiple consecutive spaces
1195 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001196#ifdef LINE_ATTR
Bram Moolenaarbf915842022-08-06 22:38:02 +01001197 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001198#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001199 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001200 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001201#ifdef FEAT_ARABIC
1202 int prev_c = 0; // previous Arabic character
1203 int prev_c1 = 0; // first composing char for prev_c
1204#endif
1205#if defined(LINE_ATTR)
1206 int did_line_attr = 0;
1207#endif
1208#ifdef FEAT_TERMINAL
1209 int get_term_attr = FALSE;
1210#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001211
Martin Tournoijba43e762022-10-13 22:12:15 +01001212#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001213 // margin columns for the screen line, needed for when 'cursorlineopt'
1214 // contains "screenline"
1215 int left_curline_col = 0;
1216 int right_curline_col = 0;
1217#endif
1218
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001219#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1220 int feedback_col = 0;
1221 int feedback_old_attr = -1;
1222#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001223
1224#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1225 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001226#endif
1227#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001228 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001229#endif
1230#ifdef FEAT_CONCEAL
1231 int syntax_flags = 0;
1232 int syntax_seqnr = 0;
1233 int prev_syntax_id = 0;
1234 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1235 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001236 int did_wcol = FALSE;
1237 int old_boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001238# define VCOL_HLC (wlv.vcol - wlv.vcol_off_co - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001239# define FIX_FOR_BOGUSCOLS \
1240 { \
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001241 wlv.n_extra += wlv.vcol_off_co; \
1242 wlv.vcol -= wlv.vcol_off_co; \
1243 wlv.vcol_off_co = 0; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001244 wlv.col -= wlv.boguscols; \
1245 old_boguscols = wlv.boguscols; \
1246 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001247 }
1248#else
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001249# define VCOL_HLC (wlv.vcol - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001250#endif
1251
1252 if (startrow > endrow) // past the end already!
1253 return startrow;
1254
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001255 CLEAR_FIELD(wlv);
1256
1257 wlv.lnum = lnum;
1258 wlv.startrow = startrow;
1259 wlv.row = startrow;
1260 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001261 wlv.fromcol = -10;
1262 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001263#ifdef FEAT_LINEBREAK
1264 wlv.vcol_sbr = -1;
1265#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001266
1267 if (!number_only)
1268 {
1269 // To speed up the loop below, set extra_check when there is linebreak,
1270 // trailing white space and/or syntax processing to be done.
1271#ifdef FEAT_LINEBREAK
1272 extra_check = wp->w_p_lbr;
1273#endif
1274#ifdef FEAT_SYN_HL
1275 if (syntax_present(wp) && !wp->w_s->b_syn_error
1276# ifdef SYN_TIME_LIMIT
1277 && !wp->w_s->b_syn_slow
1278# endif
1279 )
1280 {
1281 // Prepare for syntax highlighting in this line. When there is an
1282 // error, stop syntax highlighting.
1283 save_did_emsg = did_emsg;
1284 did_emsg = FALSE;
1285 syntax_start(wp, lnum);
1286 if (did_emsg)
1287 wp->w_s->b_syn_error = TRUE;
1288 else
1289 {
1290 did_emsg = save_did_emsg;
1291#ifdef SYN_TIME_LIMIT
1292 if (!wp->w_s->b_syn_slow)
1293#endif
1294 {
1295 has_syntax = TRUE;
1296 extra_check = TRUE;
1297 }
1298 }
1299 }
1300
1301 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001302 wlv.color_cols = wp->w_p_cc_cols;
1303 if (wlv.color_cols != NULL)
1304 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001305#endif
1306
1307#ifdef FEAT_TERMINAL
1308 if (term_show_buffer(wp->w_buffer))
1309 {
1310 extra_check = TRUE;
1311 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001312 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001313 }
1314#endif
1315
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001316 // handle Visual active in this window
1317 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1318 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001319 pos_T *top, *bot;
1320
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001321 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1322 {
1323 // Visual is after curwin->w_cursor
1324 top = &curwin->w_cursor;
1325 bot = &VIsual;
1326 }
1327 else
1328 {
1329 // Visual is before curwin->w_cursor
1330 top = &VIsual;
1331 bot = &curwin->w_cursor;
1332 }
1333 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1334 if (VIsual_mode == Ctrl_V)
1335 {
1336 // block mode
1337 if (lnum_in_visual_area)
1338 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001339 wlv.fromcol = wp->w_old_cursor_fcol;
1340 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001341 }
1342 }
1343 else
1344 {
1345 // non-block mode
1346 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001347 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001348 else if (lnum == top->lnum)
1349 {
1350 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001351 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001352 else
1353 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001354 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001355 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001356 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001357 }
1358 }
1359 if (VIsual_mode != 'V' && lnum == bot->lnum)
1360 {
1361 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1362 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001363 wlv.fromcol = -10;
1364 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001365 }
1366 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001367 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001368 else
1369 {
1370 pos = *bot;
1371 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001372 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1373 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001374 else
1375 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001376 getvvcol(wp, &pos, NULL, NULL,
1377 (colnr_T *)&wlv.tocol);
1378 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001379 }
1380 }
1381 }
1382 }
1383
1384 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001385 if (!highlight_match && lnum == curwin->w_cursor.lnum
1386 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001387#ifdef FEAT_GUI
1388 && !gui.in_use
1389#endif
1390 )
1391 noinvcur = TRUE;
1392
1393 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001394 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001395 {
1396 area_highlighting = TRUE;
1397 vi_attr = HL_ATTR(HLF_V);
1398#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1399 if ((clip_star.available && !clip_star.owned
1400 && clip_isautosel_star())
1401 || (clip_plus.available && !clip_plus.owned
1402 && clip_isautosel_plus()))
1403 vi_attr = HL_ATTR(HLF_VNC);
1404#endif
1405 }
1406 }
1407
1408 // handle 'incsearch' and ":s///c" highlighting
1409 else if (highlight_match
1410 && wp == curwin
1411 && lnum >= curwin->w_cursor.lnum
1412 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1413 {
1414 if (lnum == curwin->w_cursor.lnum)
1415 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001416 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001417 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001418 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001419 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1420 {
1421 pos.lnum = lnum;
1422 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001423 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001424 }
1425 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001426 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001427 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001428 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1429 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001430 area_highlighting = TRUE;
1431 vi_attr = HL_ATTR(HLF_I);
1432 }
1433 }
1434
1435#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001436 wlv.filler_lines = diff_check(wp, lnum);
1437 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001438 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001439 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001440 {
1441 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001442 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001443 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001444 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001445 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001446 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001447 }
1448 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001449 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001450 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001451 area_highlighting = TRUE;
1452 }
1453 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001454 wlv.filler_lines = wp->w_topfill;
1455 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001456#endif
1457
1458#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001459 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001460 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001461 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001462#endif
1463
1464#ifdef LINE_ATTR
1465# ifdef FEAT_SIGNS
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001466 // If this line has a sign with line highlighting set wlv.line_attr.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001467 if (sign_present)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001468 wlv.line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001469# endif
1470# if defined(FEAT_QUICKFIX)
1471 // Highlight the current line in the quickfix window.
1472 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001473 wlv.line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001474# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001475 if (wlv.line_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001476 area_highlighting = TRUE;
1477#endif
1478
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001479#ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01001480 if (spv->spv_has_spell && !number_only)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001481 {
Luuk van Baal30805a12023-05-27 22:22:10 +01001482 // Prepare for spell checking.
1483 extra_check = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001484
Luuk van Baal30805a12023-05-27 22:22:10 +01001485 // When a word wrapped from the previous line the start of the
1486 // current line is valid.
1487 if (lnum == spv->spv_checked_lnum)
1488 cur_checked_col = spv->spv_checked_col;
Luuk van Baale84c7732023-05-31 18:57:36 +01001489 // Previous line was not spell checked, check for capital. This happens
1490 // for the first line in an updated region or after a closed fold.
1491 if (spv->spv_capcol_lnum == 0 && check_need_cap(wp, lnum, 0))
1492 spv->spv_cap_col = 0;
1493 else if (lnum != spv->spv_capcol_lnum)
Luuk van Baal30805a12023-05-27 22:22:10 +01001494 spv->spv_cap_col = -1;
1495 spv->spv_checked_lnum = 0;
1496
Luuk van Baal30805a12023-05-27 22:22:10 +01001497 // Get the start of the next line, so that words that wrap to the
1498 // next line are found too: "et<line-break>al.".
1499 // Trick: skip a few chars for C/shell/Vim comments
1500 nextline[SPWORDLEN] = NUL;
1501 if (lnum < wp->w_buffer->b_ml.ml_line_count)
Luuk van Baale84c7732023-05-31 18:57:36 +01001502 {
1503 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1504 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1505 }
1506 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1507
1508 // If current line is empty, check first word in next line for capital.
1509 ptr = skipwhite(line);
1510 if (*ptr == NUL)
1511 {
1512 spv->spv_cap_col = 0;
1513 spv->spv_capcol_lnum = lnum + 1;
1514 }
1515 // For checking first word with a capital skip white space.
1516 else if (spv->spv_cap_col == 0)
1517 spv->spv_cap_col = ptr - line;
1518
Luuk van Baal30805a12023-05-27 22:22:10 +01001519 // Copy the end of the current line into nextline[].
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001520 if (nextline[SPWORDLEN] == NUL)
1521 {
1522 // No next line or it is empty.
1523 nextlinecol = MAXCOL;
1524 nextline_idx = 0;
1525 }
1526 else
1527 {
1528 v = (long)STRLEN(line);
1529 if (v < SPWORDLEN)
1530 {
1531 // Short line, use it completely and append the start of the
1532 // next line.
1533 nextlinecol = 0;
1534 mch_memmove(nextline, line, (size_t)v);
1535 STRMOVE(nextline + v, nextline + SPWORDLEN);
1536 nextline_idx = v + 1;
1537 }
1538 else
1539 {
1540 // Long line, use only the last SPWORDLEN bytes.
1541 nextlinecol = v - SPWORDLEN;
1542 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1543 nextline_idx = SPWORDLEN + 1;
1544 }
1545 }
1546 }
1547#endif
1548
Luuk van Baale84c7732023-05-31 18:57:36 +01001549 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1550 ptr = line;
1551
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001552 if (wp->w_p_list)
1553 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001554 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001555 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001556 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001557 || wp->w_lcs_chars.trail
1558 || wp->w_lcs_chars.lead
1559 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001560 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001561
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001562 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001563 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001564 {
1565 trailcol = (colnr_T)STRLEN(ptr);
1566 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1567 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001568 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001569 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001570 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001571 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001572 {
1573 leadcol = 0;
1574 while (VIM_ISWHITE(ptr[leadcol]))
1575 ++leadcol;
1576 if (ptr[leadcol] == NUL)
1577 // in a line full of spaces all of them are treated as trailing
1578 leadcol = (colnr_T)0;
1579 else
1580 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001581 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001582 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001583 }
1584
Bram Moolenaard7657e92022-09-20 18:59:30 +01001585 wlv.wcr_attr = get_wcr_attr(wp);
1586 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001587 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001588 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001589 area_highlighting = TRUE;
1590 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001591
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001592 // When w_skipcol is non-zero and there is virtual text above the actual
1593 // text, then this much of the virtual text is skipped.
1594 int skipcol_in_text_prop_above = 0;
1595
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001596#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001597 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001598 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001599
1600 char_u *prop_start;
1601 text_prop_count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE);
1602 if (text_prop_count > 0)
1603 {
1604 // Make a copy of the properties, so that they are properly
1605 // aligned.
1606 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1607 if (text_props != NULL)
1608 mch_memmove(text_props, prop_start,
1609 text_prop_count * sizeof(textprop_T));
1610
1611 // Allocate an array for the indexes.
1612 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1613 if (text_prop_idxs == NULL)
1614 VIM_CLEAR(text_props);
1615
1616 if (text_props != NULL)
1617 {
1618 area_highlighting = TRUE;
1619 extra_check = TRUE;
1620
zeertzjq4e26a9a2023-12-03 17:50:47 +01001621 /* Find the last text property that inserts text. */
1622 for (int i = 0; i < text_prop_count; ++i)
1623 if (text_props[i].tp_id < 0)
1624 last_textprop_text_idx = i;
1625
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001626 // When skipping virtual text the props need to be sorted. The
1627 // order is reversed!
1628 if (lnum == wp->w_topline && wp->w_skipcol > 0)
1629 {
1630 for (int i = 0; i < text_prop_count; ++i)
1631 text_prop_idxs[i] = i;
1632 sort_text_props(wp->w_buffer, text_props,
1633 text_prop_idxs, text_prop_count);
1634 }
1635
1636 // Text props "above" move the line number down to where the text
1637 // is. Only count the ones that are visible, not those that are
1638 // skipped because of w_skipcol.
1639 int text_width = wp->w_width - win_col_off(wp);
1640 for (int i = text_prop_count - 1; i >= 0; --i)
1641 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1642 {
1643 if (lnum == wp->w_topline
1644 && wp->w_skipcol - skipcol_in_text_prop_above
1645 >= text_width)
1646 {
1647 // This virtual text above is skipped, remove it from
1648 // the array.
1649 skipcol_in_text_prop_above += text_width;
1650 for (int j = i + 1; j < text_prop_count; ++j)
1651 text_props[j - 1] = text_props[j];
1652 ++i;
1653 --text_prop_count;
1654 }
1655 else
1656 ++wlv.text_prop_above_count;
1657 }
1658 }
1659 }
Bram Moolenaara572b932023-02-19 14:34:37 +00001660
1661 if (number_only)
1662 {
1663 // skip over rows only used for virtual text above
1664 wlv.row += wlv.text_prop_above_count;
1665 if (wlv.row > endrow)
1666 return wlv.row;
1667 wlv.screen_row += wlv.text_prop_above_count;
1668 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001669#endif
1670
zeertzjqce53e3e2023-09-01 18:49:30 +02001671#if defined(FEAT_LINEBREAK) || defined(FEAT_PROP_POPUP)
1672 colnr_T vcol_first_char = 0;
1673 if (wp->w_p_lbr && !number_only)
1674 {
1675 chartabsize_T cts;
1676 init_chartabsize_arg(&cts, wp, lnum, 0, line, line);
1677 (void)win_lbr_chartabsize(&cts, NULL);
1678 vcol_first_char = cts.cts_first_char;
1679 clear_chartabsize_arg(&cts);
1680 }
1681#endif
1682
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001683 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1684 // first character to be displayed.
1685 if (wp->w_p_wrap)
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001686 v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001687 else
1688 v = wp->w_leftcol;
1689 if (v > 0 && !number_only)
1690 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001691 char_u *prev_ptr = ptr;
1692 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001693 int charsize = 0;
zeertzjqb557f482023-08-22 22:07:34 +02001694 int head = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001695
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001696 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
zeertzjqb557f482023-08-22 22:07:34 +02001697 cts.cts_max_head_vcol = v;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001698 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001699 {
zeertzjqb557f482023-08-22 22:07:34 +02001700 head = 0;
1701 charsize = win_lbr_chartabsize(&cts, &head);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001702 cts.cts_vcol += charsize;
1703 prev_ptr = cts.cts_ptr;
1704 MB_PTR_ADV(cts.cts_ptr);
zeertzjqabc80812023-09-24 23:32:18 +02001705 if (wp->w_p_list)
1706 {
1707 in_multispace = *prev_ptr == ' ' && (*cts.cts_ptr == ' '
1708 || (prev_ptr > line && prev_ptr[-1] == ' '));
1709 if (!in_multispace)
1710 multispace_pos = 0;
1711 else if (cts.cts_ptr >= line + leadcol
1712 && wp->w_lcs_chars.multispace != NULL)
1713 {
1714 ++multispace_pos;
1715 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
1716 multispace_pos = 0;
1717 }
1718 else if (cts.cts_ptr < line + leadcol
1719 && wp->w_lcs_chars.leadmultispace != NULL)
1720 {
1721 ++multispace_pos;
1722 if (wp->w_lcs_chars.leadmultispace[multispace_pos] == NUL)
1723 multispace_pos = 0;
1724 }
1725 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001726 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001727 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001728 ptr = cts.cts_ptr;
1729 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001730
1731 // When:
1732 // - 'cuc' is set, or
1733 // - 'colorcolumn' is set, or
1734 // - 'virtualedit' is set, or
1735 // - the visual mode is active,
1736 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001737 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001738#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001739 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001740#endif
1741 virtual_active() ||
1742 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001743 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001744
1745 // Handle a character that's not completely on the screen: Put ptr at
1746 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001747 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001748 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001749 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001750 ptr = prev_ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001751 }
zeertzjqb557f482023-08-22 22:07:34 +02001752 if (v > wlv.vcol)
1753 skip_cells = v - wlv.vcol - head;
Bram Moolenaarcd105412022-10-10 19:50:42 +01001754
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001755 // Adjust for when the inverted text is before the screen,
1756 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001757 if (wlv.tocol <= wlv.vcol)
1758 wlv.fromcol = 0;
1759 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1760 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001761
1762#ifdef FEAT_LINEBREAK
1763 // When w_skipcol is non-zero, first line needs 'showbreak'
1764 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001765 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001766#endif
1767#ifdef FEAT_SPELL
1768 // When spell checking a word we need to figure out the start of the
1769 // word and if it's badly spelled or not.
Luuk van Baal30805a12023-05-27 22:22:10 +01001770 if (spv->spv_has_spell)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001771 {
1772 int len;
1773 colnr_T linecol = (colnr_T)(ptr - line);
1774 hlf_T spell_hlf = HLF_COUNT;
1775
1776 pos = wp->w_cursor;
1777 wp->w_cursor.lnum = lnum;
1778 wp->w_cursor.col = linecol;
1779 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1780
1781 // spell_move_to() may call ml_get() and make "line" invalid
1782 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1783 ptr = line + linecol;
1784
1785 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1786 {
1787 // no bad word found at line start, don't check until end of a
1788 // word
1789 spell_hlf = HLF_COUNT;
1790 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1791 }
1792 else
1793 {
1794 // bad word found, use attributes until end of word
1795 word_end = wp->w_cursor.col + len + 1;
1796
1797 // Turn index into actual attributes.
1798 if (spell_hlf != HLF_COUNT)
1799 spell_attr = highlight_attr[spell_hlf];
1800 }
1801 wp->w_cursor = pos;
1802
1803# ifdef FEAT_SYN_HL
1804 // Need to restart syntax highlighting for this line.
1805 if (has_syntax)
1806 syntax_start(wp, lnum);
1807# endif
1808 }
1809#endif
1810 }
1811
1812 // Correct highlighting for cursor that can't be disabled.
1813 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001814 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001815 {
1816 if (noinvcur)
1817 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001818 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001819 {
1820 // highlighting starts at cursor, let it start just after the
1821 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001822 fromcol_prev = wlv.fromcol;
1823 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001824 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001825 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001826 // restart highlighting after the cursor
1827 fromcol_prev = wp->w_virtcol;
1828 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001829 if (wlv.fromcol >= wlv.tocol)
1830 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001831 }
1832
1833#ifdef FEAT_SEARCH_EXTRA
1834 if (!number_only)
1835 {
1836 v = (long)(ptr - line);
1837 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1838 &line, &screen_search_hl,
1839 &search_attr);
1840 ptr = line + v; // "line" may have been updated
1841 }
1842#endif
1843
1844#ifdef FEAT_SYN_HL
1845 // Cursor line highlighting for 'cursorline' in the current window.
1846 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1847 {
1848 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001849 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001850 if (!(wp == curwin && VIsual_active)
1851 && wp->w_p_culopt_flags != CULOPT_NBR)
1852 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001853 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001854 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1855
zeertzjqb7acea12022-12-12 13:20:43 +00001856 // Only apply CursorLine highlight here when "screenline" is not
1857 // present in 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001858 if (!wlv.cul_screenline)
zeertzjqb7acea12022-12-12 13:20:43 +00001859 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001860 else
1861 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001862 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001863 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1864 }
1865 area_highlighting = TRUE;
1866 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001867 }
1868#endif
1869
Bram Moolenaar1306b362022-08-06 15:59:06 +01001870 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001871
1872 // Repeat for the whole displayed line.
1873 for (;;)
1874 {
1875#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001876 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001877#endif
1878#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001879 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001880#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001881
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001882 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001883 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001884 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001885#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001886 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001887 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001888 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001889 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001890 }
1891#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001892 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001893 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001894 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001895 if (cmdwin_type != 0 && wp == curwin)
1896 {
1897 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001898 wlv.n_extra = 1;
1899 wlv.c_extra = cmdwin_type;
1900 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001901 wlv.char_attr =
1902 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001903 }
1904 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001905#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001906 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001907 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001908 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001909 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001910 }
1911#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001912#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001913 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001914 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001915 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001916 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001917 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001918 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001919 }
1920#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001921 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001922 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001923 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001924 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001925 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001926 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001927#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001928 // Check if 'breakindent' applies and show it.
1929 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1930 if (wlv.n_extra == 0)
1931 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001932#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001933#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001934 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001935 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001936 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001937 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001938 }
1939#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001940 if (wlv.draw_state == WL_LINE - 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_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001943 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001944 }
1945 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001946
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001947#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001948 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001949 && wlv.vcol >= left_curline_col
1950 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001951 {
zeertzjqb7acea12022-12-12 13:20:43 +00001952 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001953 }
1954#endif
1955
1956 // When still displaying '$' of change command, stop at cursor.
1957 // When only displaying the (relative) line number and that's done,
1958 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001959 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001960 && lnum == wp->w_cursor.lnum
1961 && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001962 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001963#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001964 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001965#endif
1966 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001967 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001968 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001969 // Pretend we have finished updating the window. Except when
1970 // 'cursorcolumn' is set.
1971#ifdef FEAT_SYN_HL
1972 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001973 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001974 else
1975#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001976 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001977 break;
1978 }
1979
Bram Moolenaar1306b362022-08-06 15:59:06 +01001980 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001981 {
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001982#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001983 if (text_props != NULL)
1984 {
1985 int pi;
1986 int bcol = (int)(ptr - line);
1987
Bram Moolenaar1306b362022-08-06 15:59:06 +01001988 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001989# ifdef FEAT_LINEBREAK
1990 && !in_linebreak
1991# endif
1992 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001993 --bcol; // still working on the previous char, e.g. Tab
1994
1995 // Check if any active property ends.
1996 for (pi = 0; pi < text_props_active; ++pi)
1997 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001998 int tpi = text_prop_idxs[pi];
1999 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002000
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002001 // An inline property ends when after the start column plus
2002 // length. An "above" property ends when used and n_extra
2003 // is zero.
2004 if ((tp->tp_col != MAXCOL
2005 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002006 {
2007 if (pi + 1 < text_props_active)
2008 mch_memmove(text_prop_idxs + pi,
2009 text_prop_idxs + pi + 1,
2010 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002011 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002012 --text_props_active;
2013 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002014# ifdef FEAT_LINEBREAK
2015 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002016 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002017 syntax_attr = 0;
2018# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002019 }
2020 }
2021
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002022# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01002023 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002024 // not on the next char yet, don't start another prop
2025 --bcol;
2026# endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002027 int display_text_first = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002028
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002029 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002030 // With 'nowrap' and not in the first screen line only "below"
2031 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002032 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002033 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002034 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002035 && (wp->w_p_wrap
2036 || wlv.row == startrow
2037 || (text_props[text_prop_next].tp_flags
2038 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002039 || (bcol == 0
2040 && (text_props[text_prop_next].tp_flags
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002041 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002042 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002043 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01002044 if (text_props[text_prop_next].tp_col == MAXCOL
2045 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002046 + text_props[text_prop_next].tp_len)
2047 text_prop_idxs[text_props_active++] = text_prop_next;
2048 ++text_prop_next;
2049 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002050
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002051 if (wlv.n_extra == 0 ||
2052 (!wlv.extra_for_textprop
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002053 && !(text_prop_type != NULL &&
2054 text_prop_flags & PT_FLAG_OVERRIDE)
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002055 ))
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002056 {
2057 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002058 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002059 text_prop_flags = 0;
2060 text_prop_type = NULL;
2061 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002062 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002063 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002064 if (text_props_active > 0 && wlv.n_extra == 0
2065 && !display_text_first)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002066 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01002067 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002068 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002069 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002070
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002071 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002072 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002073
2074 // Sort the properties on priority and/or starting last.
2075 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002076 sort_text_props(wp->w_buffer, text_props,
2077 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002078
2079 for (pi = 0; pi < text_props_active; ++pi)
2080 {
2081 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002082 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002083 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002084 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002085
Bram Moolenaarcd105412022-10-10 19:50:42 +01002086 // Only use a text property that can be displayed.
2087 // Skip "after" properties when wrap is off and at the
2088 // end of the window.
2089 if (pt != NULL
2090 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2091 && tp->tp_id != -MAXCOL
2092 && !(tp->tp_id < 0
2093 && !wp->w_p_wrap
2094 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2095 | TP_FLAG_ALIGN_ABOVE
2096 | TP_FLAG_ALIGN_BELOW)) == 0
2097 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002098 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002099 if (tp->tp_col == MAXCOL
2100 && *ptr == NUL
2101 && ((wp->w_p_list && lcs_eol_one > 0
2102 && (tp->tp_flags
2103 & TP_FLAG_ALIGN_ABOVE) == 0)
2104 || (ptr == line
2105 && !did_line
2106 && (tp->tp_flags
2107 & TP_FLAG_ALIGN_BELOW))))
2108 {
2109 // skip this prop, first display the '$' after
2110 // the line or display an empty line
2111 text_prop_follows = TRUE;
2112 if (used_tpi < 0)
2113 display_text_first = TRUE;
2114 continue;
2115 }
2116
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002117 if (pt->pt_hl_id > 0)
2118 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002119 text_prop_type = pt;
2120 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002121 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002122 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2123 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002124 text_prop_flags = pt->pt_flags;
2125 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002126 used_tpi = tpi;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002127 display_text_first = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002128 }
2129 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002130 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002131 && -text_prop_id
2132 <= wp->w_buffer->b_textprop_text.ga_len)
2133 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002134 textprop_T *tp = &text_props[used_tpi];
2135 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002136 ->b_textprop_text.ga_data)[
2137 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002138 int above = (tp->tp_flags
2139 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002140 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002141
2142 // reset the ID in the copy to avoid it being used
2143 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002144 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002145
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002146 if (p != NULL)
2147 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002148 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002149 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002150 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002151 & TP_FLAG_ALIGN_BELOW);
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002152 int wrap = tp->tp_col < MAXCOL
2153 || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002154 int padding = tp->tp_col == MAXCOL
2155 && tp->tp_len > 1
2156 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002157
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002158 // Insert virtual text before the current
2159 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002160 wlv.p_extra = p;
2161 wlv.c_extra = NUL;
2162 wlv.c_final = NUL;
2163 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002164 wlv.extra_for_textprop = TRUE;
zeertzjq6e940d92023-08-17 23:21:40 +02002165 wlv.start_extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002166 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2167 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002168 n_attr = mb_charlen(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002169 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002170 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002171 if (*ptr == NUL)
2172 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002173 text_prop_flags &= ~PT_FLAG_COMBINE;
zeertzjq6b9c2022023-09-11 20:01:17 +02002174# ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002175 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002176 {
2177 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002178 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002179 wlv.need_showbreak = FALSE;
2180 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002181 }
zeertzjq6b9c2022023-09-11 20:01:17 +02002182# endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002183 if ((right || above || below || !wrap
2184 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002185 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002186 char_u *prev_p_extra = wlv.p_extra;
2187 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002188
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002189 // Take care of padding, right-align and
2190 // truncation.
2191 // Shared with win_lbr_chartabsize(), must do
2192 // exactly the same.
2193 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002194 wlv.vcol,
zeertzjq6b9c2022023-09-11 20:01:17 +02002195# ifdef FEAT_RIGHTLEFT
2196 wp->w_p_rl
2197 ? wp->w_width - wlv.col - 1
2198 :
2199# endif
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002200 wlv.col,
2201 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002202 &n_attr, &wlv.n_attr_skip,
2203 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002204 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002205 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002206 // wlv.p_extra was allocated
2207 vim_free(p_extra_free2);
2208 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002209 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002210
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002211 if (above)
2212 wlv.vcol_off_tp = wlv.n_extra;
2213
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002214 if (lcs_eol_one < 0
2215 && wp->w_p_wrap
2216 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002217 + wlv.n_extra - 2 > wp->w_width)
2218 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002219 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002220
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002221 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002222 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002223 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002224 {
2225 draw_screen_line(wp, &wlv);
2226
2227 // When line got too long for screen break
2228 // here.
2229 if (wlv.row == endrow)
2230 {
2231 ++wlv.row;
2232 break;
2233 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002234 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002235 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002236 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002237 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002238 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002239
Bram Moolenaarcd105412022-10-10 19:50:42 +01002240 // If the text didn't reach until the first window
2241 // column we need to skip cells.
2242 if (skip_cells > 0)
2243 {
2244 if (wlv.n_extra > skip_cells)
2245 {
2246 wlv.n_extra -= skip_cells;
2247 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002248 wlv.n_attr_skip -= skip_cells;
2249 if (wlv.n_attr_skip < 0)
2250 wlv.n_attr_skip = 0;
zeertzjqb557f482023-08-22 22:07:34 +02002251 skipped_cells += skip_cells;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002252 skip_cells = 0;
2253 }
2254 else
2255 {
2256 // the whole text is left of the window, drop
2257 // it and advance to the next one
2258 skip_cells -= wlv.n_extra;
zeertzjqb557f482023-08-22 22:07:34 +02002259 skipped_cells += wlv.n_extra;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002260 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002261 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002262 bail_out = TRUE;
2263 }
2264 }
2265
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002266 // If another text prop follows the condition below at
2267 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002268 // If this is an "above" text prop and 'nowrap' the we
2269 // must wrap anyway.
2270 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002271 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002272 && (wp->w_p_wrap
2273 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002274 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002275
2276 if (bail_out)
2277 // starting a new line for "below"
2278 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002279 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002280 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002281 else if (text_prop_next < text_prop_count
2282 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002283 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2284 || (!wp->w_p_wrap
2285 && wlv.col == wp->w_width - 1
2286 && (text_props[text_prop_next].tp_flags
2287 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002288 // When at last-but-one character and a text property
2289 // follows after it, we may need to flush the line after
2290 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002291 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002292 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002293 }
zeertzjq6e940d92023-08-17 23:21:40 +02002294
2295 if (wlv.start_extra_for_textprop)
2296 {
2297 wlv.start_extra_for_textprop = FALSE;
2298 // restore search_attr and area_attr when n_extra
2299 // is down to zero
2300 saved_search_attr = search_attr;
2301 saved_area_attr = area_attr;
2302 search_attr = 0;
2303 area_attr = 0;
2304 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002305#endif
2306
zeertzjq6e940d92023-08-17 23:21:40 +02002307 int *area_attr_p =
2308#ifdef FEAT_PROP_POPUP
2309 wlv.extra_for_textprop ? &saved_area_attr :
2310#endif
2311 &area_attr;
2312
2313 // handle Visual or match highlighting in this line
2314 if (wlv.vcol == wlv.fromcol
2315 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
2316 && ((wlv.n_extra == 0 && (*mb_ptr2cells)(ptr) > 1)
2317 || (wlv.n_extra > 0 && wlv.p_extra != NULL
2318 && (*mb_ptr2cells)(wlv.p_extra) > 1)))
2319 || ((int)vcol_prev == fromcol_prev
2320 && vcol_prev < wlv.vcol // not at margin
2321 && wlv.vcol < wlv.tocol))
2322 *area_attr_p = vi_attr; // start highlighting
2323 else if (*area_attr_p != 0
2324 && (wlv.vcol == wlv.tocol
2325 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
2326 *area_attr_p = 0; // stop highlighting
2327
zeertzjqe500ae82023-08-17 22:35:26 +02002328#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaare38fc862022-08-11 17:24:50 +01002329 if (wlv.n_extra == 0)
2330 {
2331 // Check for start/end of 'hlsearch' and other matches.
2332 // After end, check for start/end of next match.
2333 // When another match, have to check for start again.
2334 v = (long)(ptr - line);
2335 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2336 &screen_search_hl, &has_match_conc,
2337 &match_conc, did_line_attr, lcs_eol_one,
2338 &on_last_col);
2339 ptr = line + v; // "line" may have been changed
Bram Moolenaare38fc862022-08-11 17:24:50 +01002340
2341 // Do not allow a conceal over EOL otherwise EOL will be missed
2342 // and bad things happen.
2343 if (*ptr == NUL)
2344 has_match_conc = 0;
zeertzjqb25dbb32023-08-13 18:11:05 +02002345 }
zeertzjqe500ae82023-08-17 22:35:26 +02002346#endif
zeertzjqb25dbb32023-08-13 18:11:05 +02002347
Bram Moolenaare38fc862022-08-11 17:24:50 +01002348#ifdef FEAT_DIFF
2349 if (wlv.diff_hlf != (hlf_T)0)
2350 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002351 // When there is extra text (e.g. virtual text) it gets the
2352 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002353 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2354 && wlv.n_extra == 0)
2355 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002356 if (wlv.diff_hlf == HLF_TXD
2357 && ((ptr - line > change_end && wlv.n_extra == 0)
2358 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002359 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002360 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002361 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2362 && wp->w_p_culopt_flags != CULOPT_NBR
2363 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2364 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002365 wlv.line_attr = hl_combine_attr(
2366 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002367 }
2368#endif
2369
Bram Moolenaara74fda62019-10-19 17:38:03 +02002370#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002371 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002372 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002373 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002374# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002375 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002376 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002377# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002378 // Get syntax attribute.
2379 if (has_syntax)
2380 {
2381 // Get the syntax attribute for the character. If there
2382 // is an error, disable syntax highlighting.
2383 save_did_emsg = did_emsg;
2384 did_emsg = FALSE;
2385
2386 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002387 if (v == prev_syntax_col)
2388 // at same column again
2389 syntax_attr = prev_syntax_attr;
2390 else
2391 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002392# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002393 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002394# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002395 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002396# ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01002397 spv->spv_has_spell ? &can_spell :
Bram Moolenaar34390282019-10-16 14:38:26 +02002398# endif
Luuk van Baal30805a12023-05-27 22:22:10 +01002399 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002400 prev_syntax_col = v;
2401 prev_syntax_attr = syntax_attr;
2402 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002403
Bram Moolenaar34390282019-10-16 14:38:26 +02002404 if (did_emsg)
2405 {
2406 wp->w_s->b_syn_error = TRUE;
2407 has_syntax = FALSE;
2408 syntax_attr = 0;
2409 }
2410 else
2411 did_emsg = save_did_emsg;
2412# ifdef SYN_TIME_LIMIT
2413 if (wp->w_s->b_syn_slow)
2414 has_syntax = FALSE;
2415# endif
2416
2417 // Need to get the line again, a multi-line regexp may
2418 // have made it invalid.
2419 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2420 ptr = line + v;
2421# ifdef FEAT_CONCEAL
2422 // no concealing past the end of the line, it interferes
2423 // with line highlighting
2424 if (*ptr == NUL)
2425 syntax_flags = 0;
2426 else
2427 syntax_flags = get_syntax_info(&syntax_seqnr);
2428# endif
2429 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002430 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002431# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002432 // Combine text property highlight into syntax highlight.
2433 if (text_prop_type != NULL)
2434 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002435 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002436 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2437 else
2438 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002439 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002440 }
2441# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002442#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002443
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002444 // Decide which of the highlight attributes to use.
2445 attr_pri = TRUE;
2446#ifdef LINE_ATTR
2447 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002448 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002449 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002450 if (!highlight_match)
2451 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002452 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002453# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002454 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002455# endif
2456 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002457 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002458 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002459 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002460# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002461 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002462# endif
2463 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002464 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002465 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2466 || wlv.vcol < wlv.fromcol
2467 || vcol_prev < fromcol_prev
2468 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002469 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002470 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002471 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002472# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002473 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002474# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002475 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002476# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002477 attr_pri = FALSE;
2478 }
2479#else
2480 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002481 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002482 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002483 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002484#endif
2485 else
2486 {
2487 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002488#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002489 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002490#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002491 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002492#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002493 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002494#ifdef FEAT_PROP_POPUP
2495 // override with text property highlight when "override" is TRUE
2496 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002497 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002498#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002499 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002500
2501 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002502 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002503 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002504 if (wlv.char_attr == 0)
2505 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002506 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002507 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002508 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002509
2510 // Get the next character to put on the screen.
2511
2512 // The "p_extra" points to the extra stuff that is inserted to
2513 // represent special characters (non-printable stuff) and other
2514 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002515 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002516 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2517 // "p_extra[n_extra]".
2518 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002519 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002520 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002521 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002522 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002523 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2524 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002525 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2526 if (enc_utf8 && utf_char2len(c) > 1)
2527 {
2528 mb_utf8 = TRUE;
2529 u8cc[0] = 0;
2530 c = 0xc0;
2531 }
2532 else
2533 mb_utf8 = FALSE;
2534 }
2535 else
2536 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002537 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002538 if (has_mbyte)
2539 {
2540 mb_c = c;
2541 if (enc_utf8)
2542 {
2543 // If the UTF-8 character is more than one byte:
2544 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002545 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002546 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002547 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002548 mb_l = 1;
2549 else if (mb_l > 1)
2550 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002551 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002552 mb_utf8 = TRUE;
2553 c = 0xc0;
2554 }
2555 }
2556 else
2557 {
2558 // if this is a DBCS character, put it in "mb_c"
2559 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002560 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002561 mb_l = 1;
2562 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002563 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002564 }
2565 if (mb_l == 0) // at the NUL at end-of-line
2566 mb_l = 1;
2567
2568 // If a double-width char doesn't fit display a '>' in the
2569 // last column.
2570 if ((
2571# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002572 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002573# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002574 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002575 && (*mb_char2cells)(mb_c) == 2)
2576 {
2577 c = '>';
2578 mb_c = c;
2579 mb_l = 1;
2580 mb_utf8 = FALSE;
2581 multi_attr = HL_ATTR(HLF_AT);
2582#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002583 if (wlv.cul_attr)
2584 multi_attr = hl_combine_attr(
2585 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002586#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002587 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002588
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002589 // put the pointer back to output the double-width
2590 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002591 ++wlv.n_extra;
2592 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002593 }
2594 else
2595 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002596 wlv.n_extra -= mb_l - 1;
2597 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002598 }
2599 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002600 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002601 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002602 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002603#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002604 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002605 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002606 // Only restore search_attr and area_attr after "n_extra" in
2607 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002608 if (wlv.saved_n_extra <= 0)
2609 {
2610 if (search_attr == 0)
2611 search_attr = saved_search_attr;
2612 if (area_attr == 0 && *ptr != NUL)
2613 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002614
2615 if (wlv.extra_for_textprop)
2616 // wlv.extra_attr should be used at this position but
2617 // not any further.
2618 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002619 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002620
2621 wlv.extra_for_textprop = FALSE;
2622 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002623 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002624#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002625 }
2626 else
2627 {
2628#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002629 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002630#endif
zeertzjqe500ae82023-08-17 22:35:26 +02002631 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002632
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002633 // Get a character from the line itself.
2634 c = *ptr;
2635#ifdef FEAT_LINEBREAK
2636 c0 = *ptr;
2637#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002638 if (c == NUL)
zeertzjqb557f482023-08-22 22:07:34 +02002639 {
2640#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002641 // text is finished, may display a "below" virtual text
2642 did_line = TRUE;
2643#endif
zeertzjqb557f482023-08-22 22:07:34 +02002644 // no more cells to skip
2645 skip_cells = 0;
2646 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002647
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002648 if (has_mbyte)
2649 {
2650 mb_c = c;
2651 if (enc_utf8)
2652 {
2653 // If the UTF-8 character is more than one byte: Decode it
2654 // into "mb_c".
2655 mb_l = utfc_ptr2len(ptr);
2656 mb_utf8 = FALSE;
2657 if (mb_l > 1)
2658 {
2659 mb_c = utfc_ptr2char(ptr, u8cc);
2660 // Overlong encoded ASCII or ASCII with composing char
2661 // is displayed normally, except a NUL.
2662 if (mb_c < 0x80)
2663 {
2664 c = mb_c;
2665#ifdef FEAT_LINEBREAK
2666 c0 = mb_c;
2667#endif
2668 }
2669 mb_utf8 = TRUE;
2670
2671 // At start of the line we can have a composing char.
2672 // Draw it as a space with a composing char.
2673 if (utf_iscomposing(mb_c))
2674 {
2675 int i;
2676
2677 for (i = Screen_mco - 1; i > 0; --i)
2678 u8cc[i] = u8cc[i - 1];
2679 u8cc[0] = mb_c;
2680 mb_c = ' ';
2681 }
2682 }
2683
2684 if ((mb_l == 1 && c >= 0x80)
2685 || (mb_l >= 1 && mb_c == 0)
2686 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2687 {
2688 // Illegal UTF-8 byte: display as <xx>.
2689 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002690 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002691# ifdef FEAT_RIGHTLEFT
2692 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002693 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002694# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002695 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002696 c = *wlv.p_extra;
2697 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002698 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002699 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2700 wlv.c_extra = NUL;
2701 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002702 if (area_attr == 0 && search_attr == 0)
2703 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002704 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002705 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002706 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002707 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002708 }
2709 }
2710 else if (mb_l == 0) // at the NUL at end-of-line
2711 mb_l = 1;
2712#ifdef FEAT_ARABIC
2713 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2714 {
2715 // Do Arabic shaping.
2716 int pc, pc1, nc;
2717 int pcc[MAX_MCO];
2718
2719 // The idea of what is the previous and next
2720 // character depends on 'rightleft'.
2721 if (wp->w_p_rl)
2722 {
2723 pc = prev_c;
2724 pc1 = prev_c1;
2725 nc = utf_ptr2char(ptr + mb_l);
2726 prev_c1 = u8cc[0];
2727 }
2728 else
2729 {
2730 pc = utfc_ptr2char(ptr + mb_l, pcc);
2731 nc = prev_c;
2732 pc1 = pcc[0];
2733 }
2734 prev_c = mb_c;
2735
2736 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2737 }
2738 else
2739 prev_c = mb_c;
2740#endif
2741 }
2742 else // enc_dbcs
2743 {
2744 mb_l = MB_BYTE2LEN(c);
2745 if (mb_l == 0) // at the NUL at end-of-line
2746 mb_l = 1;
2747 else if (mb_l > 1)
2748 {
2749 // We assume a second byte below 32 is illegal.
2750 // Hopefully this is OK for all double-byte encodings!
2751 if (ptr[1] >= 32)
2752 mb_c = (c << 8) + ptr[1];
2753 else
2754 {
2755 if (ptr[1] == NUL)
2756 {
2757 // head byte at end of line
2758 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002759 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002760 }
2761 else
2762 {
2763 // illegal tail byte
2764 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002765 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002766 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002767 wlv.p_extra = wlv.extra;
2768 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002769 wlv.c_extra = NUL;
2770 wlv.c_final = NUL;
2771 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002772 if (area_attr == 0 && search_attr == 0)
2773 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002774 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002775 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002776 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002777 // save current attr
2778 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002779 }
2780 mb_c = c;
2781 }
2782 }
2783 }
2784 // If a double-width char doesn't fit display a '>' in the
2785 // last column; the character is displayed at the start of the
2786 // next line.
2787 if ((
2788# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002789 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002790# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002791 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002792 && (*mb_char2cells)(mb_c) == 2)
2793 {
2794 c = '>';
2795 mb_c = c;
2796 mb_utf8 = FALSE;
2797 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002798 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002799 // Put pointer back so that the character will be
2800 // displayed at the start of the next line.
2801 --ptr;
2802#ifdef FEAT_CONCEAL
2803 did_decrement_ptr = TRUE;
2804#endif
2805 }
2806 else if (*ptr != NUL)
2807 ptr += mb_l - 1;
2808
2809 // If a double-width char doesn't fit at the left side display
2810 // a '<' in the first column. Don't do this for unprintable
2811 // characters.
zeertzjqb557f482023-08-22 22:07:34 +02002812 if (skip_cells > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002813 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002814 wlv.n_extra = 1;
2815 wlv.c_extra = MB_FILLER_CHAR;
2816 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002817 c = ' ';
2818 if (area_attr == 0 && search_attr == 0)
2819 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002820 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002821 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002822 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002823 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002824 }
2825 mb_c = c;
2826 mb_utf8 = FALSE;
2827 mb_l = 1;
2828 }
2829
2830 }
2831 ++ptr;
2832
2833 if (extra_check)
2834 {
2835#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002836 // Check spelling (unless at the end of the line).
2837 // Only do this when there is no syntax highlighting, the
2838 // @Spell cluster is not used or the current syntax item
2839 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002840 v = (long)(ptr - line);
Luuk van Baal30805a12023-05-27 22:22:10 +01002841 if (spv->spv_has_spell && v >= word_end && v > cur_checked_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002842 {
2843 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002844 // do not calculate cap_col at the end of the line or when
2845 // only white space is following
2846 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002847# ifdef FEAT_SYN_HL
2848 !has_syntax ||
2849# endif
2850 can_spell))
2851 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002852 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002853 int len;
2854 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002855
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002856 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002857 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002858
2859 // Use nextline[] if possible, it has the start of the
2860 // next line concatenated.
2861 if ((prev_ptr - line) - nextlinecol >= 0)
2862 p = nextline + (prev_ptr - line) - nextlinecol;
2863 else
2864 p = prev_ptr;
Luuk van Baal30805a12023-05-27 22:22:10 +01002865 spv->spv_cap_col -= (int)(prev_ptr - line);
2866 len = spell_check(wp, p, &spell_hlf, &spv->spv_cap_col,
2867 spv->spv_unchanged);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002868 word_end = v + len;
2869
2870 // In Insert mode only highlight a word that
2871 // doesn't touch the cursor.
2872 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002873 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002874 && wp->w_cursor.lnum == lnum
2875 && wp->w_cursor.col >=
2876 (colnr_T)(prev_ptr - line)
2877 && wp->w_cursor.col < (colnr_T)word_end)
2878 {
2879 spell_hlf = HLF_COUNT;
2880 spell_redraw_lnum = lnum;
2881 }
2882
2883 if (spell_hlf == HLF_COUNT && p != prev_ptr
2884 && (p - nextline) + len > nextline_idx)
2885 {
2886 // Remember that the good word continues at the
2887 // start of the next line.
Luuk van Baal30805a12023-05-27 22:22:10 +01002888 spv->spv_checked_lnum = lnum + 1;
2889 spv->spv_checked_col = (p - nextline) + len
2890 - nextline_idx;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002891 }
2892
2893 // Turn index into actual attributes.
2894 if (spell_hlf != HLF_COUNT)
2895 spell_attr = highlight_attr[spell_hlf];
2896
Luuk van Baal30805a12023-05-27 22:22:10 +01002897 if (spv->spv_cap_col > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002898 {
2899 if (p != prev_ptr
Luuk van Baal30805a12023-05-27 22:22:10 +01002900 && (p - nextline) + spv->spv_cap_col
2901 >= nextline_idx)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002902 {
2903 // Remember that the word in the next line
2904 // must start with a capital.
Luuk van Baal30805a12023-05-27 22:22:10 +01002905 spv->spv_capcol_lnum = lnum + 1;
2906 spv->spv_cap_col = ((p - nextline)
2907 + spv->spv_cap_col - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002908 }
2909 else
2910 // Compute the actual column.
Luuk van Baal30805a12023-05-27 22:22:10 +01002911 spv->spv_cap_col += (prev_ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002912 }
2913 }
2914 }
2915 if (spell_attr != 0)
2916 {
2917 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002918 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2919 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002920 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002921 wlv.char_attr = hl_combine_attr(spell_attr,
2922 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002923 }
2924#endif
2925#ifdef FEAT_LINEBREAK
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02002926 // we don't want linebreak to apply for lines that start with
2927 // leading spaces, followed by long letters (since it would add
2928 // a break at the beginning of a line and this might be unexpected)
2929 //
2930 // So only allow to linebreak, once we have found chars not in
2931 // 'breakat' in the line.
2932 if ( wp->w_p_lbr && !wlv.need_lbr && c != NUL &&
2933 !VIM_ISBREAK((int)*ptr))
2934 wlv.need_lbr = TRUE;
2935#endif
2936#ifdef FEAT_LINEBREAK
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002937 // Found last space before word: check for line break.
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02002938 if (wp->w_p_lbr && c0 == c && wlv.need_lbr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002939 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2940 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002941 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2942 : 0;
2943 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002944 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002945
zeertzjqce53e3e2023-09-01 18:49:30 +02002946 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol
2947# ifdef FEAT_PROP_POPUP
2948 - vcol_first_char,
2949# endif
2950 line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002951# ifdef FEAT_PROP_POPUP
2952 // do not want virtual text counted here
2953 cts.cts_has_prop_with_text = FALSE;
2954# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002955 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002956 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002957
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002958 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002959 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002960 // line break, but for TABs the highlighting should
2961 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002962 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002963
Bram Moolenaar1306b362022-08-06 15:59:06 +01002964 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002965# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002966 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002967 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002968 wp->w_buffer->b_p_vts_array) - 1;
2969# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002970 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002971 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002972# endif
2973
Bram Moolenaar1306b362022-08-06 15:59:06 +01002974 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2975 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002976# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002977 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002978 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002979# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002980 if (VIM_ISWHITE(c))
2981 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002982# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002983 if (c == TAB)
2984 // See "Tab alignment" below.
2985 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002986# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002987 if (!wp->w_p_list)
2988 c = ' ';
2989 }
2990 }
2991#endif
zeertzjqabc80812023-09-24 23:32:18 +02002992 if (wp->w_p_list)
2993 {
2994 in_multispace = c == ' ' && (*ptr == ' '
2995 || (prev_ptr > line && prev_ptr[-1] == ' '));
2996 if (!in_multispace)
2997 multispace_pos = 0;
2998 }
zeertzjqf14b8ba2021-09-10 16:58:30 +02002999
Bram Moolenaareed9d462021-02-15 20:38:25 +01003000 // 'list': Change char 160 to 'nbsp' and space to 'space'
3001 // setting in 'listchars'. But not when the character is
3002 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003003 if (wp->w_p_list
3004 && ((((c == 160 && mb_l == 1)
3005 || (mb_utf8
3006 && ((mb_c == 160 && mb_l == 2)
3007 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01003008 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003009 || (c == ' '
3010 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02003011 && (wp->w_lcs_chars.space
3012 || (in_multispace
3013 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01003014 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003015 && ptr - line <= trailcol)))
3016 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02003017 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
3018 {
3019 c = wp->w_lcs_chars.multispace[multispace_pos++];
3020 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
3021 multispace_pos = 0;
3022 }
3023 else
3024 c = (c == ' ') ? wp->w_lcs_chars.space
3025 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003026 if (area_attr == 0 && search_attr == 0)
3027 {
3028 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003029 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003030 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003031 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003032 }
3033 mb_c = c;
3034 if (enc_utf8 && utf_char2len(c) > 1)
3035 {
3036 mb_utf8 = TRUE;
3037 u8cc[0] = 0;
3038 c = 0xc0;
3039 }
3040 else
3041 mb_utf8 = FALSE;
3042 }
3043
zeertzjq2e7cba32022-06-10 15:30:32 +01003044 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
3045 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003046 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003047 if (leadcol != 0 && in_multispace && ptr < line + leadcol
3048 && wp->w_lcs_chars.leadmultispace != NULL)
3049 {
3050 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01003051 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
3052 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003053 multispace_pos = 0;
3054 }
3055
3056 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
3057 c = wp->w_lcs_chars.trail;
3058
3059 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
3060 c = wp->w_lcs_chars.lead;
3061
zeertzjq2e7cba32022-06-10 15:30:32 +01003062 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003063 c = wp->w_lcs_chars.space;
3064
3065
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003066 if (!attr_pri)
3067 {
3068 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003069 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003070 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003071 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003072 }
3073 mb_c = c;
3074 if (enc_utf8 && utf_char2len(c) > 1)
3075 {
3076 mb_utf8 = TRUE;
3077 u8cc[0] = 0;
3078 c = 0xc0;
3079 }
3080 else
3081 mb_utf8 = FALSE;
3082 }
3083 }
3084
3085 // Handling of non-printable characters.
3086 if (!vim_isprintc(c))
3087 {
3088 // when getting a character from the file, we may have to
3089 // turn it into something else on the way to putting it
3090 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01003091 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003092 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003093 int tab_len = 0;
3094 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003095#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003096 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01003097
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003098 // only adjust the tab_len, when at the first column
3099 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01003100 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003101 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003102#endif
3103 // tab amount depends on current column
3104#ifdef FEAT_VARTABS
3105 tab_len = tabstop_padding(vcol_adjusted,
3106 wp->w_buffer->b_p_ts,
3107 wp->w_buffer->b_p_vts_array) - 1;
3108#else
3109 tab_len = (int)wp->w_buffer->b_p_ts
3110 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
3111#endif
3112
3113#ifdef FEAT_LINEBREAK
3114 if (!wp->w_p_lbr || !wp->w_p_list)
3115#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003116 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003117 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01003118 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003119 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003120#ifdef FEAT_LINEBREAK
3121 else
3122 {
3123 char_u *p;
3124 int len;
3125 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003126 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003127
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003128# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003129 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003130 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003131 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003132
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003133 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003134 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003135 && old_boguscols > 0
3136 && wlv.n_extra > tab_len)
3137 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003138# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003139 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003140 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003141 // If wlv.n_extra > 0, it gives the number of chars
3142 // to use for a tab, else we need to calculate the
3143 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003144 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3145 len = tab_len * tab2_len;
3146 if (wp->w_lcs_chars.tab3)
3147 len += mb_char2len(wp->w_lcs_chars.tab3)
3148 - tab2_len;
3149 if (wlv.n_extra > 0)
3150 len += wlv.n_extra - tab_len;
3151 c = wp->w_lcs_chars.tab1;
3152 p = alloc(len + 1);
3153 if (p == NULL)
3154 wlv.n_extra = 0;
3155 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003156 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003157 vim_memset(p, ' ', len);
3158 p[len] = NUL;
3159 vim_free(wlv.p_extra_free);
3160 wlv.p_extra_free = p;
3161 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003162 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003163 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003164
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003165 if (*p == NUL)
3166 {
3167 tab_len = i;
3168 break;
3169 }
3170
3171 // if tab3 is given, use it for the last
3172 // char
3173 if (wp->w_lcs_chars.tab3
3174 && i == tab_len - 1)
3175 lcs = wp->w_lcs_chars.tab3;
3176 p += mb_char2bytes(lcs, p);
3177 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003178 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003179 }
3180 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003181# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003182 // n_extra will be increased by
3183 // FIX_FOX_BOGUSCOLS macro below, so need to
3184 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003185 if (wlv.vcol_off_co > 0)
3186 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003187# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003188 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003189 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003190 }
3191#endif
3192#ifdef FEAT_CONCEAL
3193 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003194 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003195
3196 // Tab alignment should be identical regardless of
3197 // 'conceallevel' value. So tab compensates of all
3198 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003199 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003200 // line. Note that the tab can be longer than
3201 // 'tabstop' when there are concealed characters.
3202 FIX_FOR_BOGUSCOLS;
3203
3204 // Make sure, the highlighting for the tab char will be
3205 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003206 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003207 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003208 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003209 tab_len += vc_saved;
3210 }
3211#endif
3212 mb_utf8 = FALSE; // don't draw as UTF-8
3213 if (wp->w_p_list)
3214 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003215 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003216 ? wp->w_lcs_chars.tab3
3217 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003218#ifdef FEAT_LINEBREAK
h-east194555c2023-03-02 18:49:09 +00003219 if (wp->w_p_lbr && wlv.p_extra != NULL
3220 && *wlv.p_extra != NUL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003221 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003222 else
3223#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003224 wlv.c_extra = wp->w_lcs_chars.tab2;
3225 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003226 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003227 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003228 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003229 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003230 mb_c = c;
3231 if (enc_utf8 && utf_char2len(c) > 1)
3232 {
3233 mb_utf8 = TRUE;
3234 u8cc[0] = 0;
3235 c = 0xc0;
3236 }
3237 }
3238 else
3239 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003240 wlv.c_final = NUL;
3241 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003242 c = ' ';
3243 }
3244 }
3245 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003246 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003247 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003248 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3249 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003250 && VIsual_mode != Ctrl_V
3251 && (
3252# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003253 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003254# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003255 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003256 && !(noinvcur
3257 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003258 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003259 && lcs_eol_one > 0)
3260 {
3261 // Display a '$' after the line or highlight an extra
3262 // character if the line break is included.
3263#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3264 // For a diff line the highlighting continues after the
3265 // "$".
3266 if (
3267# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003268 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003269# ifdef LINE_ATTR
3270 &&
3271# endif
3272# endif
3273# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003274 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003275# endif
3276 )
3277#endif
3278 {
3279 // In virtualedit, visual selections may extend
3280 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003281 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003282 && wlv.tocol != MAXCOL
3283 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003284 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003285 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003286 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003287 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3288 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003289 else
3290 c = ' ';
3291 lcs_eol_one = -1;
3292 --ptr; // put it back at the NUL
3293 if (!attr_pri)
3294 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003295 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003296 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003297 n_attr = 1;
3298 }
3299 mb_c = c;
3300 if (enc_utf8 && utf_char2len(c) > 1)
3301 {
3302 mb_utf8 = TRUE;
3303 u8cc[0] = 0;
3304 c = 0xc0;
3305 }
3306 else
3307 mb_utf8 = FALSE; // don't draw as UTF-8
3308 }
3309 else if (c != NUL)
3310 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003311 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3312 if (wlv.n_extra == 0)
3313 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003314#ifdef FEAT_RIGHTLEFT
3315 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003316 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003317#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003318 wlv.c_extra = NUL;
3319 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003320#ifdef FEAT_LINEBREAK
3321 if (wp->w_p_lbr)
3322 {
3323 char_u *p;
3324
Bram Moolenaar1306b362022-08-06 15:59:06 +01003325 c = *wlv.p_extra;
3326 p = alloc(wlv.n_extra + 1);
3327 vim_memset(p, ' ', wlv.n_extra);
3328 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3329 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003330 vim_free(wlv.p_extra_free);
3331 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003332 }
3333 else
3334#endif
3335 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003336 wlv.n_extra = byte2cells(c) - 1;
3337 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003338 }
3339 if (!attr_pri)
3340 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003341 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003342 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003343 HL_ATTR(HLF_8));
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003344#ifdef FEAT_PROP_POPUP
3345 if (text_prop_type != NULL &&
3346 text_prop_flags & PT_FLAG_OVERRIDE)
3347 wlv.extra_attr = hl_combine_attr(text_prop_attr, wlv.extra_attr);
3348#endif
3349
Bram Moolenaar1306b362022-08-06 15:59:06 +01003350 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003351 }
3352 mb_utf8 = FALSE; // don't draw as UTF-8
3353 }
3354 else if (VIsual_active
3355 && (VIsual_mode == Ctrl_V
3356 || VIsual_mode == 'v')
3357 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003358 && wlv.tocol != MAXCOL
3359 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003360 && (
3361#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003362 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003363#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003364 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003365 {
3366 c = ' ';
3367 --ptr; // put it back at the NUL
3368 }
3369#if defined(LINE_ATTR)
3370 else if ((
3371# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003372 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003373# endif
3374# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003375 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003376# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003377 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003378 ) && (
3379# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003380 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003381# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003382 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003383# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003384 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003385# endif
3386 < wp->w_width)))
3387 {
3388 // Highlight until the right side of the window
3389 c = ' ';
3390 --ptr; // put it back at the NUL
3391
3392 // Remember we do the char for line highlighting.
3393 ++did_line_attr;
3394
3395 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003396 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003397 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003398 || (wp->w_p_list &&
3399 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003400 wlv.char_attr = wlv.line_attr;
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003401#ifdef FEAT_SIGNS
3402 // At end of line: if Sign is present with line highlight, reset char_attr
Christian Brabandte1eaae22023-08-19 22:36:12 +02003403 // but not when cursorline is active
3404 if (sign_present && wlv.sattr.sat_linehl > 0 && wlv.draw_state == WL_LINE
3405 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum))
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003406 wlv.char_attr = wlv.sattr.sat_linehl;
3407#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003408# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003409 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003410 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003411 wlv.diff_hlf = HLF_CHD;
3412 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003413 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003414 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003415 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3416 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003417 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003418 || (wlv.vcol >= left_curline_col
3419 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003420 wlv.char_attr = hl_combine_attr(
3421 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003422 }
3423 }
3424# endif
3425# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003426 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003427 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003428 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003429 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3430 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003431 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003432 if (!wlv.cul_screenline
3433 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003434 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003435 wlv.char_attr = hl_combine_attr(
3436 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003437 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003438 else if (wlv.line_attr)
3439 wlv.char_attr = hl_combine_attr(
3440 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003441 }
3442# endif
3443 }
3444#endif
3445 }
3446
3447#ifdef FEAT_CONCEAL
3448 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003449 && (wp != curwin || lnum != wp->w_cursor.lnum
3450 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003451 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3452 && !(lnum_in_visual_area
3453 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3454 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003455 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003456 if (((prev_syntax_id != syntax_seqnr
3457 && (syntax_flags & HL_CONCEAL) != 0)
3458 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003459 && (syn_get_sub_char() != NUL
3460 || (has_match_conc && match_conc)
3461 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003462 && wp->w_p_cole != 3)
3463 {
3464 // First time at this concealed item: display one
3465 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003466 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003467 c = match_conc;
3468 else if (syn_get_sub_char() != NUL)
3469 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003470 else if (wp->w_lcs_chars.conceal != NUL)
3471 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003472 else
3473 c = ' ';
3474
3475 prev_syntax_id = syntax_seqnr;
3476
Bram Moolenaar1306b362022-08-06 15:59:06 +01003477 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003478 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003479 wlv.vcol += wlv.n_extra;
3480 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003481 {
3482# ifdef FEAT_RIGHTLEFT
3483 if (wp->w_p_rl)
3484 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003485 wlv.col -= wlv.n_extra;
3486 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003487 }
3488 else
3489# endif
3490 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003491 wlv.boguscols += wlv.n_extra;
3492 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003493 }
3494 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003495 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003496 n_attr = 0;
3497 }
zeertzjqb557f482023-08-22 22:07:34 +02003498 else if (skip_cells == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003499 {
3500 is_concealing = TRUE;
zeertzjqb557f482023-08-22 22:07:34 +02003501 skip_cells = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003502 }
3503 mb_c = c;
3504 if (enc_utf8 && utf_char2len(c) > 1)
3505 {
3506 mb_utf8 = TRUE;
3507 u8cc[0] = 0;
3508 c = 0xc0;
3509 }
3510 else
3511 mb_utf8 = FALSE; // don't draw as UTF-8
3512 }
3513 else
3514 {
3515 prev_syntax_id = 0;
3516 is_concealing = FALSE;
3517 }
3518
zeertzjqb557f482023-08-22 22:07:34 +02003519 if (skip_cells > 0 && did_decrement_ptr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003520 // not showing the '>', put pointer back to avoid getting stuck
3521 ++ptr;
3522
3523#endif // FEAT_CONCEAL
3524 }
3525
3526#ifdef FEAT_CONCEAL
3527 // In the cursor line and we may be concealing characters: correct
3528 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003529 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003530 && wp == curwin && lnum == wp->w_cursor.lnum
3531 && conceal_cursor_line(wp)
zeertzjqb557f482023-08-22 22:07:34 +02003532 && (int)wp->w_virtcol <= wlv.vcol + skip_cells)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003533 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003534# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003535 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003536 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003537 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003538# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003539 wp->w_wcol = wlv.col - wlv.boguscols;
3540 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003541 did_wcol = TRUE;
3542 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003543# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003544 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003545# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003546 }
3547#endif
3548
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003549 // Use "wlv.extra_attr", but don't override visual selection
3550 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003551 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3552 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003553 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003554 && (!attr_pri
3555#ifdef FEAT_PROP_POPUP
3556 || (text_prop_flags & PT_FLAG_OVERRIDE)
3557#endif
3558 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003559 {
3560#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003561 if (wlv.line_attr)
3562 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003563 else
3564#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003565 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003566#ifdef FEAT_PROP_POPUP
3567 if (reset_extra_attr)
3568 {
3569 reset_extra_attr = FALSE;
3570 wlv.extra_attr = 0;
3571 }
3572#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003573 }
3574
3575#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3576 // XIM don't send preedit_start and preedit_end, but they send
3577 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3578 // im_is_preediting() here.
3579 if (p_imst == IM_ON_THE_SPOT
3580 && xic != NULL
3581 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003582 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003583 && !p_imdisable
3584 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003585 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003586 {
3587 colnr_T tcol;
3588
3589 if (preedit_end_col == MAXCOL)
3590 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3591 else
3592 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003593 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003594 {
3595 if (feedback_old_attr < 0)
3596 {
3597 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003598 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003599 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003600 wlv.char_attr = im_get_feedback_attr(feedback_col);
3601 if (wlv.char_attr < 0)
3602 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003603 feedback_col++;
3604 }
3605 else if (feedback_old_attr >= 0)
3606 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003607 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003608 feedback_old_attr = -1;
3609 feedback_col = 0;
3610 }
3611 }
3612#endif
3613 // Handle the case where we are in column 0 but not on the first
3614 // character of the line and the user wants us to show us a
3615 // special character (via 'listchars' option "precedes:<char>".
3616 if (lcs_prec_todo != NUL
3617 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003618 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3619 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003620#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003621 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003622#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003623 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003624 && c != NUL)
3625 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003626 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003627 lcs_prec_todo = NUL;
3628 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3629 {
3630 // Double-width character being overwritten by the "precedes"
3631 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003632 wlv.c_extra = MB_FILLER_CHAR;
3633 wlv.c_final = NUL;
3634 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003635 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003636 wlv.extra_attr =
3637 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003638 }
3639 mb_c = c;
3640 if (enc_utf8 && utf_char2len(c) > 1)
3641 {
3642 mb_utf8 = TRUE;
3643 u8cc[0] = 0;
3644 c = 0xc0;
3645 }
3646 else
3647 mb_utf8 = FALSE; // don't draw as UTF-8
3648 if (!attr_pri)
3649 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003650 saved_attr3 = wlv.char_attr; // save current attr
3651 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003652 n_attr3 = 1;
3653 }
3654 }
3655
3656 // At end of the text line or just after the last character.
3657 if ((c == NUL
3658#if defined(LINE_ATTR)
3659 || did_line_attr == 1
3660#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003661 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003662 {
3663#ifdef FEAT_SEARCH_EXTRA
3664 // flag to indicate whether prevcol equals startcol of search_hl or
3665 // one of the matches
3666 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3667 (long)(ptr - line) - (c == NUL));
3668#endif
3669 // Invert at least one char, used for Visual and empty line or
3670 // highlight match at end of line. If it's beyond the last
3671 // char on the screen, just overwrite that one (tricky!) Not
3672 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003673 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003674 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003675 && (VIsual_mode != Ctrl_V
3676 || lnum == VIsual.lnum
3677 || lnum == curwin->w_cursor.lnum)
3678 && c == NUL)
3679#ifdef FEAT_SEARCH_EXTRA
3680 // highlight 'hlsearch' match at end of line
3681 || (prevcol_hl_flag
3682# ifdef FEAT_SYN_HL
3683 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3684 && !(wp == curwin && VIsual_active))
3685# endif
3686# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003687 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003688# endif
3689# if defined(LINE_ATTR)
3690 && did_line_attr <= 1
3691# endif
3692 )
3693#endif
3694 ))
3695 {
3696 int n = 0;
3697
3698#ifdef FEAT_RIGHTLEFT
3699 if (wp->w_p_rl)
3700 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003701 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003702 n = 1;
3703 }
3704 else
3705#endif
3706 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003707 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003708 n = -1;
3709 }
3710 if (n != 0)
3711 {
3712 // At the window boundary, highlight the last character
3713 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003714 wlv.off += n;
3715 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003716 }
3717 else
3718 {
3719 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003720 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003721 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003722 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003723 }
3724#ifdef FEAT_SEARCH_EXTRA
3725 if (area_attr == 0)
3726 {
3727 // Use attributes from match with highest priority among
3728 // 'search_hl' and the match list.
3729 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003730 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003731 }
3732#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003733 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003734 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003735#ifdef FEAT_RIGHTLEFT
3736 if (wp->w_p_rl)
3737 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003738 --wlv.col;
3739 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003740 }
3741 else
3742#endif
3743 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003744 ++wlv.col;
3745 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003746 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003747 ++wlv.vcol;
3748 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003749 }
3750 }
3751
3752 // At end of the text line.
3753 if (c == NUL)
3754 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003755#ifdef FEAT_PROP_POPUP
3756 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003757 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003758 // Put the pointer back to the NUL.
3759 --ptr;
3760 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003761 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003762 else
3763#endif
3764 {
3765 draw_screen_line(wp, &wlv);
3766
3767 // Update w_cline_height and w_cline_folded if the cursor line
3768 // was updated (saves a call to plines() later).
3769 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3770 {
3771 curwin->w_cline_row = startrow;
3772 curwin->w_cline_height = wlv.row - startrow;
3773#ifdef FEAT_FOLDING
3774 curwin->w_cline_folded = FALSE;
3775#endif
3776 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3777 }
3778 break;
3779 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003780 }
3781
3782 // Show "extends" character from 'listchars' if beyond the line end and
3783 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003784 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003785 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003786 && wp->w_p_list
3787 && !wp->w_p_wrap
3788#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003789 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003790#endif
3791 && (
3792#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003793 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003794#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003795 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003796 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003797 || lcs_eol_one > 0
3798 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
zeertzjq6a389722023-08-27 19:04:14 +02003799 || *wlv.p_extra != NUL))
3800#ifdef FEAT_PROP_POPUP
zeertzjq4e26a9a2023-12-03 17:50:47 +01003801 || text_prop_next <= last_textprop_text_idx
zeertzjq6a389722023-08-27 19:04:14 +02003802#endif
3803 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003804 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003805 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003806 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003807 mb_c = c;
3808 if (enc_utf8 && utf_char2len(c) > 1)
3809 {
3810 mb_utf8 = TRUE;
3811 u8cc[0] = 0;
3812 c = 0xc0;
3813 }
3814 else
3815 mb_utf8 = FALSE;
3816 }
3817
3818#ifdef FEAT_SYN_HL
3819 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003820 if (wlv.draw_color_col)
3821 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003822
3823 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3824 // highlight the cursor position itself.
3825 // Also highlight the 'colorcolumn' if it is different than
3826 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003827 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3828 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003829 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003830 if (((wlv.draw_state == WL_LINE
3831 || wlv.draw_state == WL_BRI
3832 || wlv.draw_state == WL_SBR)
3833 && !lnum_in_visual_area
3834 && search_attr == 0
3835 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003836# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003837 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003838# endif
3839 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003840 {
3841 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3842 && lnum != wp->w_cursor.lnum)
3843 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003844 vcol_save_attr = wlv.char_attr;
3845 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3846 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003847 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003848 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003849 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003850 vcol_save_attr = wlv.char_attr;
3851 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003852 }
3853 }
3854#endif
3855
zeertzjq8fc6a1d2023-08-20 18:12:54 +02003856 if (wlv.draw_state == WL_LINE)
3857 vcol_prev = wlv.vcol;
3858
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003859 // Store character to be displayed.
3860 // Skip characters that are left of the screen for 'nowrap'.
zeertzjqb557f482023-08-22 22:07:34 +02003861 if (wlv.draw_state < WL_LINE || skip_cells <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003862 {
3863 // Store the character.
3864#if defined(FEAT_RIGHTLEFT)
3865 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3866 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003867 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003868 --wlv.off;
3869 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003870 }
3871#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003872 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003873 if (enc_dbcs == DBCS_JPNU)
3874 {
3875 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003876 ScreenLines[wlv.off] = 0x8e;
3877 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003878 }
3879 else if (enc_utf8)
3880 {
3881 if (mb_utf8)
3882 {
3883 int i;
3884
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003885 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003886 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003887 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003888 for (i = 0; i < Screen_mco; ++i)
3889 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003890 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003891 if (u8cc[i] == 0)
3892 break;
3893 }
3894 }
3895 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003896 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003897 }
3898 if (multi_attr)
3899 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003900 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003901 multi_attr = 0;
3902 }
3903 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003904 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003905
zeertzjqdb54e982023-09-21 16:33:09 +02003906 if (wlv.draw_state > WL_NR
3907#ifdef FEAT_DIFF
3908 && wlv.filler_todo <= 0
3909#endif
3910 )
3911 ScreenCols[wlv.off] = wlv.vcol;
3912 else
3913 ScreenCols[wlv.off] = -1;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003914
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003915 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3916 {
3917 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003918 ++wlv.off;
3919 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003920 if (enc_utf8)
3921 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003922 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003923 else
3924 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003925 ScreenLines[wlv.off] = mb_c & 0xff;
zeertzjqdb54e982023-09-21 16:33:09 +02003926
Bram Moolenaar1306b362022-08-06 15:59:06 +01003927 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003928#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003929 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003930#endif
3931 )
zeertzjqdb54e982023-09-21 16:33:09 +02003932 ScreenCols[wlv.off] = ++wlv.vcol;
3933 else
3934 ScreenCols[wlv.off] = -1;
3935
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003936 // When "wlv.tocol" is halfway a character, set it to the end
3937 // of the character, otherwise highlighting won't stop.
3938 if (wlv.tocol == wlv.vcol)
3939 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003940
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003941#ifdef FEAT_RIGHTLEFT
3942 if (wp->w_p_rl)
3943 {
3944 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003945 --wlv.off;
3946 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003947 }
3948#endif
3949 }
3950#ifdef FEAT_RIGHTLEFT
3951 if (wp->w_p_rl)
3952 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003953 --wlv.off;
3954 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003955 }
3956 else
3957#endif
3958 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003959 ++wlv.off;
3960 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003961 }
3962 }
3963#ifdef FEAT_CONCEAL
3964 else if (wp->w_p_cole > 0 && is_concealing)
3965 {
zeertzjqb557f482023-08-22 22:07:34 +02003966 --skip_cells;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003967 ++wlv.vcol_off_co;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003968 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003969 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003970 if (wp->w_p_wrap)
3971 {
3972 // Special voodoo required if 'wrap' is on.
3973 //
3974 // Advance the column indicator to force the line
3975 // drawing to wrap early. This will make the line
3976 // take up the same screen space when parts are concealed,
3977 // so that cursor line computations aren't messed up.
3978 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003979 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003980 // trailing junk to be written out of the screen line
3981 // we are building, 'boguscols' keeps track of the number
3982 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003983 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003984 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003985 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003986# ifdef FEAT_RIGHTLEFT
3987 if (wp->w_p_rl)
3988 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003989 wlv.col -= wlv.n_extra;
3990 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003991 }
3992 else
3993# endif
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 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003998 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003999 n_attr = 0;
4000 }
4001
4002
4003 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
4004 {
4005 // Need to fill two screen columns.
4006# ifdef FEAT_RIGHTLEFT
4007 if (wp->w_p_rl)
4008 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004009 --wlv.boguscols;
4010 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004011 }
4012 else
4013# endif
4014 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004015 ++wlv.boguscols;
4016 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004017 }
4018 }
4019
4020# ifdef FEAT_RIGHTLEFT
4021 if (wp->w_p_rl)
4022 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004023 --wlv.boguscols;
4024 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004025 }
4026 else
4027# endif
4028 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004029 ++wlv.boguscols;
4030 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004031 }
4032 }
4033 else
4034 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004035 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004036 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004037 wlv.vcol += wlv.n_extra;
4038 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004039 n_attr = 0;
4040 }
4041 }
4042
4043 }
4044#endif // FEAT_CONCEAL
4045 else
zeertzjqb557f482023-08-22 22:07:34 +02004046 --skip_cells;
4047
4048 if (wlv.draw_state > WL_NR && skipped_cells > 0)
4049 {
4050 wlv.vcol += skipped_cells;
4051 skipped_cells = 0;
4052 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004053
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004054 // Only advance the "wlv.vcol" when after the 'number' or
4055 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004056 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004057#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004058 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004059#endif
4060 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004061 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004062
4063#ifdef FEAT_SYN_HL
4064 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004065 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004066#endif
4067
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004068 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01004069 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
4070 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004071
4072 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01004073 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004074 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004075 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004076 if (wlv.n_attr_skip > 0)
4077 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004078
4079 // At end of screen line and there is more to come: Display the line
4080 // so far. If there is no more to display it is caught above.
4081 if ((
4082#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004083 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004084#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004085 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01004086 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02004087 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004088#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004089 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004090#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004091#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004092 || text_prop_above || text_prop_follows
zeertzjq4e26a9a2023-12-03 17:50:47 +01004093 || text_prop_next <= last_textprop_text_idx
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004094#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01004095 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01004096 && wlv.p_extra != at_end_str)
4097 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
4098 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004099 )
4100 {
4101#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01004102 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01004103 wlv_screen_line(wp, &wlv, FALSE);
4104 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004105 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004106 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004107#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01004108 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004109#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004110 ++wlv.row;
4111 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004112
4113 // When not wrapping and finished diff lines, or when displayed
4114 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01004115 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004116#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004117 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004118#endif
4119#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01004120 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004121#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01004122 ) || lcs_eol_one == -1)
4123#ifdef FEAT_PROP_POPUP
4124 && !text_prop_follows
4125#endif
4126 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004127 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004128#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004129 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004130 {
4131 // do not output more of the line, only the "below" prop
4132 ptr += STRLEN(ptr);
4133# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004134 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004135# endif
4136 }
4137#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004138
4139 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004140 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004141#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004142 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004143#endif
4144 )
4145 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004146 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
4147 draw_vsep_win(wp, wlv.row);
4148 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004149 }
4150
4151 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004152 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004153 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004154 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004155 break;
4156 }
4157
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004158 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004159#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004160 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004161#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004162#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004163 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004164#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004165 && wp->w_width == Columns)
4166 {
4167 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004168 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004169
4170 // Special trick to make copy/paste of wrapped lines work with
4171 // xterm/screen: write an extra character beyond the end of
4172 // the line. This will work with all terminal types
4173 // (regardless of the xn,am settings).
4174 // Only do this on a fast tty.
4175 // Only do this if the cursor is on the current line
4176 // (something has been written in it).
4177 // Don't do this for the GUI.
4178 // Don't do this for double-width characters.
4179 // Don't do this for a window not at the right screen border.
4180 if (p_tf
4181#ifdef FEAT_GUI
4182 && !gui.in_use
4183#endif
4184 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004185 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4186 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004187 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004188 || (*mb_off2cells)(
4189 LineOffset[wlv.screen_row - 1]
4190 + (int)Columns - 2,
4191 LineOffset[wlv.screen_row]
4192 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004193 {
4194 // First make sure we are at the end of the screen line,
4195 // then output the same character again to let the
4196 // terminal know about the wrap. If the terminal doesn't
4197 // auto-wrap, we overwrite the character.
4198 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004199 screen_char(LineOffset[wlv.screen_row - 1]
4200 + (unsigned)Columns - 1,
4201 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004202
4203 // When there is a multi-byte character, just output a
4204 // space to keep it simple.
4205 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004206 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004207 out_char(' ');
4208 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004209 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004210 + (Columns - 1)]);
4211 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004212 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004213 screen_start(); // don't know where cursor is now
4214 }
4215 }
4216
Bram Moolenaar1306b362022-08-06 15:59:06 +01004217 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004218
Bram Moolenaareed9d462021-02-15 20:38:25 +01004219 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004220#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004221 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004222# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004223 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004224# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004225 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004226 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004227#endif
4228#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004229 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004230 // When the filler lines are actually below the last line of the
4231 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004232 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004233 break;
4234#endif
4235 }
4236
4237 } // for every character in the line
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004238#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004239 vim_free(text_props);
4240 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004241 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004242#endif
4243
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004244 vim_free(wlv.p_extra_free);
zeertzjq58e1e012023-06-04 18:46:28 +01004245 vim_free(wlv.saved_p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004246 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004247}