blob: 7bbe86de0f4931adc8aa2ba5f353be8eaa44e5e4 [file] [log] [blame]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * drawline.c: Functions for drawing window lines on the screen.
Bram Moolenaare89aeed2022-08-22 13:00:16 +010012 * This is the middle level, drawscreen.c is the higher level and screen.c the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020013 * lower level.
14 */
15
16#include "vim.h"
17
18#ifdef FEAT_SYN_HL
19/*
20 * Advance **color_cols and return TRUE when there are columns to draw.
21 */
22 static int
23advance_color_col(int vcol, int **color_cols)
24{
25 while (**color_cols >= 0 && vcol > **color_cols)
26 ++*color_cols;
27 return (**color_cols >= 0);
28}
29#endif
30
31#ifdef FEAT_SYN_HL
32/*
33 * Used when 'cursorlineopt' contains "screenline": compute the margins between
34 * which the highlighting is used.
35 */
36 static void
37margin_columns_win(win_T *wp, int *left_col, int *right_col)
38{
39 // cache previous calculations depending on w_virtcol
40 static int saved_w_virtcol;
41 static win_T *prev_wp;
42 static int prev_left_col;
43 static int prev_right_col;
44 static int prev_col_off;
45
46 int cur_col_off = win_col_off(wp);
47 int width1;
48 int width2;
49
50 if (saved_w_virtcol == wp->w_virtcol
51 && prev_wp == wp && prev_col_off == cur_col_off)
52 {
53 *right_col = prev_right_col;
54 *left_col = prev_left_col;
55 return;
56 }
57
58 width1 = wp->w_width - cur_col_off;
59 width2 = width1 + win_col_off2(wp);
60
61 *left_col = 0;
62 *right_col = width1;
63
64 if (wp->w_virtcol >= (colnr_T)width1)
65 *right_col = width1 + ((wp->w_virtcol - width1) / width2 + 1) * width2;
66 if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0)
67 *left_col = (wp->w_virtcol - width1) / width2 * width2 + width1;
68
69 // cache values
70 prev_left_col = *left_col;
71 prev_right_col = *right_col;
72 prev_wp = wp;
73 saved_w_virtcol = wp->w_virtcol;
74 prev_col_off = cur_col_off;
75}
76#endif
77
Bram Moolenaar45e4eea2022-12-01 18:38:02 +000078#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
79 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
80// using an attribute for the whole line
81# define LINE_ATTR
82#endif
83
Bram Moolenaar1306b362022-08-06 15:59:06 +010084// structure with variables passed between win_line() and other functions
85typedef struct {
86 int draw_state; // what to draw next
87
88 linenr_T lnum; // line number to be drawn
89
90 int startrow; // first row in the window to be drawn
91 int row; // row in the window, excl w_winrow
92 int screen_row; // row on the screen, incl w_winrow
93
94 long vcol; // virtual column, before wrapping
95 int col; // visual column on screen, after wrapping
96#ifdef FEAT_CONCEAL
97 int boguscols; // nonexistent columns added to "col" to force
98 // wrapping
Bram Moolenaarf53e0652023-02-19 14:16:02 +000099 int vcol_off_co; // offset for concealed characters
Bram Moolenaar1306b362022-08-06 15:59:06 +0100100#endif
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000101 int vcol_off_tp; // offset for virtual text
Bram Moolenaar1306b362022-08-06 15:59:06 +0100102#ifdef FEAT_SYN_HL
103 int draw_color_col; // highlight colorcolumn
104 int *color_cols; // pointer to according columns array
105#endif
106 int eol_hl_off; // 1 if highlighted char after EOL
107
108 unsigned off; // offset in ScreenLines/ScreenAttrs
109
110 int win_attr; // background for the whole window, except
111 // margins and "~" lines.
Bram Moolenaard7657e92022-09-20 18:59:30 +0100112 int wcr_attr; // attributes from 'wincolor'
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100113#ifdef FEAT_SYN_HL
114 int cul_attr; // set when 'cursorline' active
115#endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000116#ifdef LINE_ATTR
117 int line_attr; // for the whole line, includes 'cursorline'
118#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100119
120 int screen_line_flags; // flags for screen_line()
121
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100122 int fromcol; // start of inverting
123 int tocol; // end of inverting
124
125#ifdef FEAT_LINEBREAK
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100126 long vcol_sbr; // virtual column after showbreak
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100127 int need_showbreak; // overlong line, skipping first x chars
128 int dont_use_showbreak; // do not use 'showbreak'
129#endif
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100130#ifdef FEAT_PROP_POPUP
131 int text_prop_above_count;
132#endif
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100133
Bram Moolenaar1306b362022-08-06 15:59:06 +0100134 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
135 int cul_screenline;
136
137 int char_attr; // attributes for the next character
138
139 int n_extra; // number of extra bytes
140 char_u *p_extra; // string of extra chars, plus NUL, only used
141 // when c_extra and c_final are NUL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100142 char_u *p_extra_free; // p_extra buffer that needs to be freed
Bram Moolenaaree28c702022-11-17 14:56:00 +0000143 int extra_attr; // attributes for p_extra, should be combined
144 // with win_attr if needed
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000145 int n_attr_skip; // chars to skip before using extra_attr
Bram Moolenaar1306b362022-08-06 15:59:06 +0100146 int c_extra; // extra chars, all the same
147 int c_final; // final char, mandatory if set
zeertzjq6e940d92023-08-17 23:21:40 +0200148 int extra_for_textprop; // n_extra set for textprop
149 int start_extra_for_textprop; // extra_for_textprop was just set
Bram Moolenaar1306b362022-08-06 15:59:06 +0100150
151 // saved "extra" items for when draw_state becomes WL_LINE (again)
152 int saved_n_extra;
153 char_u *saved_p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +0100154 char_u *saved_p_extra_free;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000155 int saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000156 int saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000157 int saved_extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100158 int saved_c_extra;
159 int saved_c_final;
160 int saved_char_attr;
161
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100162 char_u extra[NUMBUFLEN + MB_MAXBYTES];
163 // "%ld " and 'fdc' must fit in here, as well
164 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100165
Bram Moolenaar1306b362022-08-06 15:59:06 +0100166#ifdef FEAT_DIFF
167 hlf_T diff_hlf; // type of diff highlighting
168#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100169 int filler_lines; // nr of filler lines to be drawn
170 int filler_todo; // nr of filler lines still to do + 1
171#ifdef FEAT_SIGNS
172 sign_attrs_T sattr;
173#endif
Christian Brabandtdd75fcf2023-10-11 21:51:19 +0200174#ifdef FEAT_LINEBREAK
175 // do consider wrapping in linebreak mode only after encountering
176 // a non whitespace char
177 int need_lbr;
178#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100179} winlinevars_T;
180
181// draw_state values for items that are drawn in sequence:
182#define WL_START 0 // nothing done yet, must be zero
Martin Tournoij7904fa42022-10-04 16:28:45 +0100183#define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar1306b362022-08-06 15:59:06 +0100184#ifdef FEAT_FOLDING
185# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
186#else
187# define WL_FOLD WL_CMDLINE
188#endif
189#ifdef FEAT_SIGNS
190# define WL_SIGN (WL_FOLD + 1) // column for signs
191#else
192# define WL_SIGN WL_FOLD // column for signs
193#endif
194#define WL_NR (WL_SIGN + 1) // line number
195#ifdef FEAT_LINEBREAK
196# define WL_BRI (WL_NR + 1) // 'breakindent'
197#else
198# define WL_BRI WL_NR
199#endif
200#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
201# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
202#else
203# define WL_SBR WL_BRI
204#endif
205#define WL_LINE (WL_SBR + 1) // text in the line
206
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100207#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200208/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000209 * Return TRUE if CursorLineSign highlight is to be used.
210 */
211 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100212use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000213{
214 return wp->w_p_cul
215 && lnum == wp->w_cursor.lnum
216 && (wp->w_p_culopt_flags & CULOPT_NBR);
217}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100218#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000219
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100220
221#ifdef FEAT_FOLDING
222/*
223 * Setup for drawing the 'foldcolumn', if there is one.
224 */
225 static void
226handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
227{
228 int fdc = compute_foldcolumn(wp, 0);
229
230 if (fdc <= 0)
231 return;
232
233 // Allocate a buffer, "wlv->extra[]" may already be in use.
234 vim_free(wlv->p_extra_free);
235 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
Yegappan Lakshmanan465de3a2022-12-26 12:50:04 +0000236 if (wlv->p_extra_free == NULL)
237 return;
238
239 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
zeertzjq58e1e012023-06-04 18:46:28 +0100240 wp, FALSE, wlv->lnum);
Yegappan Lakshmanan465de3a2022-12-26 12:50:04 +0000241 wlv->p_extra_free[wlv->n_extra] = NUL;
242 wlv->p_extra = wlv->p_extra_free;
243 wlv->c_extra = NUL;
244 wlv->c_final = NUL;
245 if (use_cursor_line_highlight(wp, wlv->lnum))
246 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
247 else
248 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100249}
250#endif
251
252#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000253/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100254 * Get information needed to display the sign in line "wlv->lnum" in window
255 * "wp".
256 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200257 * Otherwise the sign is going to be displayed in the sign column.
258 */
259 static void
260get_sign_display_info(
261 int nrcol,
262 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100263 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200264{
265 int text_sign;
266# ifdef FEAT_SIGN_ICONS
267 int icon_sign;
268# endif
269
270 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100271 wlv->c_extra = ' ';
272 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200273 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100274 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200275 else
276 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100277 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100278 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000279 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100280 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100281 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200282 }
283
Bram Moolenaar1306b362022-08-06 15:59:06 +0100284 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200285#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100286 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200287#endif
288 )
289 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100290 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200291# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100292 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200293 if (gui.in_use && icon_sign != 0)
294 {
295 // Use the image in this position.
296 if (nrcol)
297 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100298 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100299 sprintf((char *)wlv->extra, "%-*c ",
300 number_width(wp), SIGN_BYTE);
301 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100302 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200303 }
304 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100305 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200306# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100307 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
308 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200309 {
310 if (nrcol)
311 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100312 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100313 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200314 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100315 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100316 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200317 }
318 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100319 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200320 }
321# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100322 wlv->c_final = NUL;
323 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200324 }
325 else
326# endif
327 if (text_sign != 0)
328 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100329 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100330 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200331 {
332 if (nrcol)
333 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100334 int width = number_width(wp) - 2;
335 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200336
337 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100338 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100339 vim_snprintf((char *)wlv->extra + n,
340 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100341 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200342 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100343 wlv->c_extra = NUL;
344 wlv->c_final = NUL;
345 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200346 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000347
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100348 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100349 && wlv->sattr.sat_culhl > 0)
350 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000351 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100352 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200353 }
354 }
355}
356#endif
357
Bram Moolenaard7657e92022-09-20 18:59:30 +0100358/*
359 * Display the absolute or relative line number. After the first row fill with
360 * blanks when the 'n' flag isn't in 'cpo'.
361 */
362 static void
363handle_lnum_col(
364 win_T *wp,
365 winlinevars_T *wlv,
366 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100367 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100368{
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100369 int has_cpo_n = vim_strchr(p_cpo, CPO_NUMCOL) != NULL;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100370 int lnum_row = wlv->startrow + wlv->filler_lines
371#ifdef FEAT_PROP_POPUP
372 + wlv->text_prop_above_count
373#endif
374 ;
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100375
Bram Moolenaard7657e92022-09-20 18:59:30 +0100376 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100377 && (wlv->row <= lnum_row || !has_cpo_n)
Bram Moolenaar37251162022-10-06 20:48:00 +0100378 // there is no line number in a wrapped line when "n" is in
379 // 'cpoptions', but 'breakindent' assumes it anyway.
380 && !((has_cpo_n
381#ifdef FEAT_LINEBREAK
382 && !wp->w_p_bri
383#endif
384 ) && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100385 {
386#ifdef FEAT_SIGNS
387 // If 'signcolumn' is set to 'number' and a sign is present
388 // in 'lnum', then display the sign instead of the line
389 // number.
390 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
391 get_sign_display_info(TRUE, wp, wlv);
392 else
393#endif
394 {
395 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100396 // When there are text properties above the line put the line number
397 // below them.
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100398 if (wlv->row == lnum_row
zeertzjq88bb3e02023-05-02 20:52:59 +0100399 && (wp->w_skipcol == 0 || wlv->row > 0
Bram Moolenaareb4de622022-10-15 13:42:17 +0100400 || (wp->w_p_nu && wp->w_p_rnu)))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100401 {
402 long num;
403 char *fmt = "%*ld ";
404
405 if (wp->w_p_nu && !wp->w_p_rnu)
406 // 'number' + 'norelativenumber'
407 num = (long)wlv->lnum;
408 else
409 {
410 // 'relativenumber', don't use negative numbers
411 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
412 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
413 {
414 // 'number' + 'relativenumber'
415 num = wlv->lnum;
416 fmt = "%-*ld ";
417 }
418 }
419
420 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100421 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100422 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
423 ++wlv->p_extra)
424 *wlv->p_extra = '-';
425#ifdef FEAT_RIGHTLEFT
426 if (wp->w_p_rl) // reverse line numbers
427 {
428 char_u *p1, *p2;
429 int t;
430
431 // like rl_mirror(), but keep the space at the end
432 p2 = skipwhite(wlv->extra);
433 p2 = skiptowhite(p2) - 1;
434 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
435 {
436 t = *p1;
437 *p1 = *p2;
438 *p2 = t;
439 }
440 }
441#endif
442 wlv->p_extra = wlv->extra;
443 wlv->c_extra = NUL;
444 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100445 }
446 else
447 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100448 wlv->c_extra = ' ';
449 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100450 }
451 wlv->n_extra = number_width(wp) + 1;
452 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
453#ifdef FEAT_SYN_HL
454 // When 'cursorline' is set highlight the line number of
455 // the current line differently.
456 // When 'cursorlineopt' does not have "line" only
457 // highlight the line number itself.
458 // TODO: Can we use CursorLine instead of CursorLineNr
459 // when CursorLineNr isn't set?
460 if (wp->w_p_cul
461 && wlv->lnum == wp->w_cursor.lnum
462 && (wp->w_p_culopt_flags & CULOPT_NBR)
463 && (wlv->row == wlv->startrow + wlv->filler_lines
464 || (wlv->row > wlv->startrow + wlv->filler_lines
465 && (wp->w_p_culopt_flags & CULOPT_LINE))))
466 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
467#endif
468 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
469 && HL_ATTR(HLF_LNA) != 0)
470 // Use LineNrAbove
471 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
472 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
473 && HL_ATTR(HLF_LNB) != 0)
474 // Use LineNrBelow
475 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
476 }
477#ifdef FEAT_SIGNS
478 if (num_attr)
479 wlv->char_attr = num_attr;
480#endif
481 }
482}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100483
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100484#ifdef FEAT_LINEBREAK
485 static void
486handle_breakindent(win_T *wp, winlinevars_T *wlv)
487{
488 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100489 && *get_showbreak_value(wp) != NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100490 // draw indent after showbreak value
491 wlv->draw_state = WL_BRI;
492 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
493 // After the showbreak, draw the breakindent
494 wlv->draw_state = WL_BRI - 1;
495
496 // draw 'breakindent': indent wrapped text accordingly
497 if (wlv->draw_state == WL_BRI - 1)
498 {
499 wlv->draw_state = WL_BRI;
500 // if wlv->need_showbreak is set, breakindent also applies
zeertzjq588f20d2023-12-05 15:47:09 +0100501 if (wp->w_p_bri && (wlv->row > wlv->startrow
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100502# ifdef FEAT_DIFF
zeertzjq588f20d2023-12-05 15:47:09 +0100503 + wlv->filler_lines
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100504# endif
zeertzjq588f20d2023-12-05 15:47:09 +0100505 || wlv->need_showbreak)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100506# ifdef FEAT_PROP_POPUP
507 && !wlv->dont_use_showbreak
508# endif
509 )
510 {
511 wlv->char_attr = 0;
512# ifdef FEAT_DIFF
513 if (wlv->diff_hlf != (hlf_T)0)
514 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
515# endif
516 wlv->p_extra = NULL;
517 wlv->c_extra = ' ';
518 wlv->c_final = NUL;
519 wlv->n_extra = get_breakindent_win(wp,
520 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
521 if (wlv->row == wlv->startrow)
522 {
523 wlv->n_extra -= win_col_off2(wp);
524 if (wlv->n_extra < 0)
525 wlv->n_extra = 0;
526 }
zeertzjq23627722023-12-27 19:08:53 +0100527
528 // Correct start of highlighted area for 'breakindent',
529 if (wlv->fromcol >= wlv->vcol
530 && wlv->fromcol < wlv->vcol + wlv->n_extra)
531 wlv->fromcol = wlv->vcol + wlv->n_extra;
532
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100533 // Correct end of highlighted area for 'breakindent',
534 // required when 'linebreak' is also set.
535 if (wlv->tocol == wlv->vcol)
536 wlv->tocol += wlv->n_extra;
537 }
zeertzjq7e4f62a2023-12-28 23:19:52 +0100538
539 if (wp->w_skipcol > 0 && wlv->startrow == 0 && wp->w_p_wrap
540 && wp->w_briopt_sbr)
541 wlv->need_showbreak = FALSE;
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100542 }
543}
544#endif
545
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100546#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
547 static void
548handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
549{
550# ifdef FEAT_DIFF
551 if (wlv->filler_todo > 0)
552 {
553 // Draw "deleted" diff line(s).
554 if (char2cells(wp->w_fill_chars.diff) > 1)
555 {
556 wlv->c_extra = '-';
557 wlv->c_final = NUL;
558 }
559 else
560 {
561 wlv->c_extra = wp->w_fill_chars.diff;
562 wlv->c_final = NUL;
563 }
564# ifdef FEAT_RIGHTLEFT
565 if (wp->w_p_rl)
566 wlv->n_extra = wlv->col + 1;
567 else
568# endif
569 wlv->n_extra = wp->w_width - wlv->col;
570 wlv->char_attr = HL_ATTR(HLF_DED);
571 }
572# endif
573
574# ifdef FEAT_LINEBREAK
575 char_u *sbr = get_showbreak_value(wp);
576 if (*sbr != NUL && wlv->need_showbreak)
577 {
578 // Draw 'showbreak' at the start of each broken line.
579 wlv->p_extra = sbr;
580 wlv->c_extra = NUL;
581 wlv->c_final = NUL;
582 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100583 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100584
585 // Correct start of highlighted area for 'showbreak'.
586 if (wlv->fromcol >= wlv->vcol && wlv->fromcol < wlv->vcol_sbr)
587 wlv->fromcol = wlv->vcol_sbr;
588
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100589 // Correct end of highlighted area for 'showbreak',
590 // required when 'linebreak' is also set.
591 if (wlv->tocol == wlv->vcol)
592 wlv->tocol += wlv->n_extra;
593 // combine 'showbreak' with 'wincolor'
594 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
595# ifdef FEAT_SYN_HL
596 // combine 'showbreak' with 'cursorline'
597 if (wlv->cul_attr != 0)
598 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
599# endif
600 }
zeertzjq7e4f62a2023-12-28 23:19:52 +0100601
602 if (wp->w_skipcol == 0 || wlv->startrow > 0 || !wp->w_p_wrap
603 || !wp->w_briopt_sbr)
604 wlv->need_showbreak = FALSE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100605# endif
606}
607#endif
608
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100609#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100610/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100611 * Return the cell size of virtual text after truncation.
612 */
613 static int
614textprop_size_after_trunc(
615 win_T *wp,
616 int flags, // TP_FLAG_ALIGN_*
617 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100618 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100619 char_u *text,
620 int *n_used_ptr)
621{
622 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100623 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100624 int len = (int)STRLEN(text);
625 int strsize = 0;
626 int n_used;
627
Bram Moolenaar7e017462022-10-11 21:02:09 +0100628 // if the remaining size is to small and 'wrap' is set we wrap anyway and
629 // use the next line
630 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100631 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100632 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100633 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100634 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
635 {
636 int clen = ptr2cells(text + n_used);
637
638 if (strsize + clen > space)
639 break;
640 strsize += clen;
641 }
642 *n_used_ptr = n_used;
643 return strsize;
644}
645
646/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100647 * Take care of padding, right-align and truncation of virtual text after a
648 * line.
649 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
650 * padding, right-align and truncation. Otherwise only the size is computed.
651 * When "n_attr" is NULL returns the number of screen cells used.
652 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100653 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100654 int
655text_prop_position(
656 win_T *wp,
657 textprop_T *tp,
porygonisaduck38854b52022-11-27 20:55:05 +0000658 int vcol, // current text column
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100659 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100660 int *n_extra, // nr of bytes for virtual text
661 char_u **p_extra, // virtual text
662 int *n_attr, // attribute cells, NULL if not used
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000663 int *n_attr_skip, // cells to skip attr, NULL if not used
664 int do_skip) // skip_cells is not zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200665{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100666 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100667 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100668 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
Bram Moolenaar1aeb3eb2023-01-01 14:04:51 +0000669 int wrap = tp->tp_col < MAXCOL || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100670 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
porygonisaduck38854b52022-11-27 20:55:05 +0000671 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100672 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100673 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100674 int before = room; // spaces before the text
675 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100676 int n_used = *n_extra;
677 char_u *l = NULL;
678 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100679 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100680 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200681
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100682 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100683 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100684 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100685
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100686 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100687 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100688 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100689 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar2354b662023-04-23 21:42:25 +0100690 if (after < 0)
691 {
692 // text "above" has too much padding to fit
693 padding += after;
694 after = 0;
695 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100696 }
697 else
698 {
699 // Right-align: fill with before
700 if (right)
701 before -= cells;
porygonisaduck38854b52022-11-27 20:55:05 +0000702
703 // Below-align: empty line add one character
Bram Moolenaar7c02ad92022-11-29 21:37:13 +0000704 if (below && vcol == 0 && col_with_padding == col_off
705 && wp->w_width - col_off == before)
706 col_with_padding += 1;
porygonisaduck38854b52022-11-27 20:55:05 +0000707
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100708 if (before < 0
709 || !(right || below)
porygonisaduck38854b52022-11-27 20:55:05 +0000710 || (below ? (col_with_padding <= col_off || !wp->w_p_wrap)
711 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100712 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100713 if (right && (wrap
714 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100715 {
716 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100717 before = wp->w_width - col_off - strsize + room;
718 if (before < 0)
719 before = 0;
720 else
721 n_used = *n_extra;
722 }
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000723 else if (below && before > vcol && do_skip)
724 before -= vcol;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100725 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100726 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100727 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100728 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100729
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100730 // With 'nowrap' add one to show the "extends" character if needed (it
731 // doesn't show if the text just fits).
732 if (!wp->w_p_wrap
733 && n_used < *n_extra
734 && wp->w_lcs_chars.ext != NUL
735 && wp->w_p_list)
736 ++n_used;
737
738 // add 1 for NUL, 2 for when '…' is used
739 if (n_attr != NULL)
Christian Brabandtf1cc4d52023-08-12 00:14:14 +0200740 l = alloc(n_used + before + after + (padding > 0 ? padding : 0) + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100741 if (n_attr == NULL || l != NULL)
742 {
743 int off = 0;
744
745 if (n_attr != NULL)
746 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100747 vim_memset(l, ' ', before);
748 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100749 if (padding > 0)
750 {
751 vim_memset(l + off, ' ', padding);
752 off += padding;
753 }
754 vim_strncpy(l + off, *p_extra, n_used);
755 off += n_used;
756 }
757 else
758 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100759 off = before + after + padding + n_used;
760 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100761 }
762 if (n_attr != NULL)
763 {
764 if (n_used < *n_extra && wp->w_p_wrap)
765 {
766 char_u *lp = l + off - 1;
767
768 if (has_mbyte)
769 {
h-east4c42c7e2023-04-17 21:44:57 +0100770 char_u buf[MB_MAXBYTES + 1];
771 char_u *cp = buf;
772
773 // change the last character to '…', converted to the
774 // current 'encoding'
775 STRCPY(buf, "…");
776 if (!enc_utf8)
777 {
778 vimconv_T vc;
779
780 vc.vc_type = CONV_NONE;
781 convert_setup(&vc, (char_u *)"utf-8", p_enc);
782 if (vc.vc_type != CONV_NONE)
783 {
784 cp = string_convert(&vc, buf, NULL);
785 if (cp == NULL)
786 {
787 // when conversion fails use '>'
788 cp = buf;
789 STRCPY(buf, ">");
790 }
791 convert_setup(&vc, NULL, NULL);
792 }
793 }
794
795 lp -= (*mb_ptr2cells)(cp) - 1;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100796 lp -= (*mb_head_off)(l, lp);
h-east4c42c7e2023-04-17 21:44:57 +0100797 STRCPY(lp, cp);
Bram Moolenaar13845c42022-10-09 15:26:03 +0100798 n_used = lp - l + 3 - before - padding;
h-east4c42c7e2023-04-17 21:44:57 +0100799 if (cp != buf)
800 vim_free(cp);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100801 }
802 else
803 // change last character to '>'
804 *lp = '>';
805 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100806 else if (after > 0)
807 {
808 vim_memset(l + off, ' ', after);
809 l[off + after] = NUL;
810 }
811
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100812 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100813 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100814 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100815 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100816 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100817
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000818 // n_attr_skip will not be decremented before draw_state is
819 // WL_LINE
Christian Brabandtf1cc4d52023-08-12 00:14:14 +0200820 *n_attr_skip = before + (padding > 0 ? padding : 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100821 }
822 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100823 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100824
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100825 if (n_attr == NULL)
826 return cells;
827 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200828}
829#endif
830
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100831/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100832 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100833 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
834 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100835 */
836 static void
837wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
838{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100839 if (wlv->row == 0 && wp->w_skipcol > 0
840#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100841 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100842 && *get_showbreak_value(wp) == NUL
843#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100844 // do not overwrite the 'listchars' "precedes" text with "<<<"
845 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100846 {
847 int off = (int)(current_ScreenLine - ScreenLines);
zeertzjqecb87dd2023-06-03 19:45:06 +0100848 int max_off = off + screen_Columns;
Bram Moolenaareb4de622022-10-15 13:42:17 +0100849 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100850
Bram Moolenaareb4de622022-10-15 13:42:17 +0100851 if (wp->w_p_nu && wp->w_p_rnu)
852 // Do not overwrite the line number, change "123 text" to
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100853 // "123<<<xt".
Bram Moolenaareb4de622022-10-15 13:42:17 +0100854 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
855 {
856 ++off;
857 ++skip;
858 }
859
860 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100861 {
zeertzjqecb87dd2023-06-03 19:45:06 +0100862 if ((*mb_off2cells)(off, max_off) > 1)
863 // When the first half of a double-width character is
864 // overwritten, change the second half to a space.
865 ScreenLines[off + 1] = ' ';
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100866 ScreenLines[off] = '<';
867 if (enc_utf8)
868 ScreenLinesUC[off] = 0;
869 ScreenAttrs[off] = HL_ATTR(HLF_AT);
870 ++off;
871 }
872 }
873
874 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
875 negative_width ? -wp->w_width : wp->w_width,
876 wlv->screen_line_flags);
877}
878
879/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100880 * Called when finished with the line: draw the screen line and handle any
881 * highlighting until the right of the window.
882 */
883 static void
884draw_screen_line(win_T *wp, winlinevars_T *wlv)
885{
886#ifdef FEAT_SYN_HL
887 long v;
888
889 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
890 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100891 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100892 else
893 v = wp->w_leftcol;
894
895 // check if line ends before left margin
896 if (wlv->vcol < v + wlv->col - win_col_off(wp))
897 wlv->vcol = v + wlv->col - win_col_off(wp);
898# ifdef FEAT_CONCEAL
899 // Get rid of the boguscols now, we want to draw until the right
900 // edge for 'cursorcolumn'.
901 wlv->col -= wlv->boguscols;
902 wlv->boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000903# define VCOL_HLC (wlv->vcol - wlv->vcol_off_co - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100904# else
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000905# define VCOL_HLC (wlv->vcol - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100906# endif
907
908 if (wlv->draw_color_col)
909 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
910
911 if (((wp->w_p_cuc
912 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
913 && (int)wp->w_virtcol <
914 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
915 && wlv->lnum != wp->w_cursor.lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000916 || wlv->draw_color_col
917# ifdef LINE_ATTR
918 || wlv->line_attr != 0
919# endif
920 || wlv->win_attr != 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100921# ifdef FEAT_RIGHTLEFT
922 && !wp->w_p_rl
923# endif
924 )
925 {
926 int rightmost_vcol = 0;
927 int i;
928
929 if (wp->w_p_cuc)
930 rightmost_vcol = wp->w_virtcol;
931 if (wlv->draw_color_col)
932 // determine rightmost colorcolumn to possibly draw
933 for (i = 0; wlv->color_cols[i] >= 0; ++i)
934 if (rightmost_vcol < wlv->color_cols[i])
935 rightmost_vcol = wlv->color_cols[i];
936
937 while (wlv->col < wp->w_width)
938 {
939 ScreenLines[wlv->off] = ' ';
940 if (enc_utf8)
941 ScreenLinesUC[wlv->off] = 0;
942 ScreenCols[wlv->off] = MAXCOL;
943 ++wlv->col;
944 if (wlv->draw_color_col)
945 wlv->draw_color_col = advance_color_col(
946 VCOL_HLC, &wlv->color_cols);
947
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000948 int attr = wlv->win_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100949 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000950 attr = HL_ATTR(HLF_CUC);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100951 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000952 attr = HL_ATTR(HLF_MC);
953# ifdef LINE_ATTR
954 else if (wlv->line_attr != 0)
955 attr = wlv->line_attr;
956# endif
957 ScreenAttrs[wlv->off++] = attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100958
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000959 if (VCOL_HLC >= rightmost_vcol
960# ifdef LINE_ATTR
961 && wlv->line_attr == 0
962# endif
963 && wlv->win_attr == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100964 break;
965
966 ++wlv->vcol;
967 }
968 }
969#endif
970
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100971 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100972 ++wlv->row;
973 ++wlv->screen_row;
974}
975#undef VCOL_HLC
976
977/*
978 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100979 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100980 */
981 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100982win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100983{
984 wlv->col = 0;
985 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
Christian Brabandtdd75fcf2023-10-11 21:51:19 +0200986#ifdef FEAT_LINEBREAK
987 wlv->need_lbr = FALSE;
988#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100989
990#ifdef FEAT_RIGHTLEFT
991 if (wp->w_p_rl)
992 {
993 // Rightleft window: process the text in the normal direction, but put
994 // it in current_ScreenLine[] from right to left. Start at the
995 // rightmost column of the window.
996 wlv->col = wp->w_width - 1;
997 wlv->off += wlv->col;
998 wlv->screen_line_flags |= SLF_RIGHTLEFT;
999 }
1000#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001001 if (save_extra)
1002 {
1003 // reset the drawing state for the start of a wrapped line
1004 wlv->draw_state = WL_START;
1005 wlv->saved_n_extra = wlv->n_extra;
1006 wlv->saved_p_extra = wlv->p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +01001007 vim_free(wlv->saved_p_extra_free);
1008 wlv->saved_p_extra_free = wlv->p_extra_free;
1009 wlv->p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001010 wlv->saved_extra_attr = wlv->extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001011 wlv->saved_n_attr_skip = wlv->n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001012 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001013 wlv->saved_c_extra = wlv->c_extra;
1014 wlv->saved_c_final = wlv->c_final;
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02001015#ifdef FEAT_LINEBREAK
1016 wlv->need_lbr = TRUE;
1017#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001018#ifdef FEAT_SYN_HL
1019 if (!(wlv->cul_screenline
1020# ifdef FEAT_DIFF
1021 && wlv->diff_hlf == (hlf_T)0
1022# endif
1023 ))
1024 wlv->saved_char_attr = wlv->char_attr;
1025 else
1026#endif
1027 wlv->saved_char_attr = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001028
1029 // these are not used until restored in win_line_continue()
Bram Moolenaar1306b362022-08-06 15:59:06 +01001030 wlv->n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001031 wlv->n_attr_skip = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001032 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001033}
1034
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001035/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001036 * Called when wlv->draw_state is set to WL_LINE.
1037 */
1038 static void
1039win_line_continue(winlinevars_T *wlv)
1040{
1041 if (wlv->saved_n_extra > 0)
1042 {
1043 // Continue item from end of wrapped line.
1044 wlv->n_extra = wlv->saved_n_extra;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001045 wlv->saved_n_extra = 0;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001046 wlv->c_extra = wlv->saved_c_extra;
1047 wlv->c_final = wlv->saved_c_final;
1048 wlv->p_extra = wlv->saved_p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +01001049 vim_free(wlv->p_extra_free);
1050 wlv->p_extra_free = wlv->saved_p_extra_free;
1051 wlv->saved_p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001052 wlv->extra_attr = wlv->saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001053 wlv->n_attr_skip = wlv->saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001054 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001055 wlv->char_attr = wlv->saved_char_attr;
1056 }
1057 else
1058 wlv->char_attr = wlv->win_attr;
1059}
1060
zeertzjqb7acea12022-12-12 13:20:43 +00001061#ifdef FEAT_SYN_HL
1062 static void
1063apply_cursorline_highlight(
1064 winlinevars_T *wlv,
1065 int sign_present UNUSED)
1066{
1067 wlv->cul_attr = HL_ATTR(HLF_CUL);
1068# ifdef FEAT_SIGNS
1069 // Combine the 'cursorline' and sign highlighting, depending on
1070 // the sign priority.
1071 if (sign_present && wlv->sattr.sat_linehl > 0)
1072 {
1073 if (wlv->sattr.sat_priority >= 100)
1074 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1075 else
1076 wlv->line_attr = hl_combine_attr(wlv->line_attr, wlv->cul_attr);
1077 }
1078 else
1079# endif
1080# if defined(FEAT_QUICKFIX)
1081 // let the line attribute overrule 'cursorline', otherwise
1082 // it disappears when both have background set;
1083 // 'cursorline' can use underline or bold to make it show
1084 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1085# else
1086 wlv->line_attr = wlv->cul_attr;
1087# endif
1088}
1089#endif
1090
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001091/*
Luuk van Baal30805a12023-05-27 22:22:10 +01001092 * Display line "lnum" of window "wp" on the screen.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001093 * Start at row "startrow", stop when "endrow" is reached.
Luuk van Baal30805a12023-05-27 22:22:10 +01001094 * When "number_only" is TRUE only update the number column.
1095 * "spv" is used to store information for spell checking, kept between
1096 * sequential calls for the same window.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001097 * wp->w_virtcol needs to be valid.
1098 *
1099 * Return the number of last row the line occupies.
1100 */
1101 int
1102win_line(
1103 win_T *wp,
1104 linenr_T lnum,
1105 int startrow,
1106 int endrow,
Luuk van Baal30805a12023-05-27 22:22:10 +01001107 int number_only,
1108 spellvars_T *spv UNUSED)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001109{
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001110 winlinevars_T wlv; // variables passed between functions
1111
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001112 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001113 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001114 char_u *line; // current line
1115 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001116
Bram Moolenaar1306b362022-08-06 15:59:06 +01001117#ifdef FEAT_PROP_POPUP
1118 char_u *p_extra_free2 = NULL; // another p_extra to be freed
1119#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001120#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001121 int in_linebreak = FALSE; // n_extra set for showing linebreak
1122#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001123 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +01001124 // displaying eol at end-of-line
1125 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001126 int lcs_prec_todo = wp->w_lcs_chars.prec;
1127 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001128
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001129 int n_attr = 0; // chars with special attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001130 int saved_attr2 = 0; // char_attr saved for n_attr
1131 int n_attr3 = 0; // chars with overruling special attr
1132 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001133
zeertzjqb557f482023-08-22 22:07:34 +02001134 int skip_cells = 0; // nr of cells to skip for w_leftcol or
1135 // w_skipcol or concealing
1136 int skipped_cells = 0; // nr of skipped cells for virtual text
1137 // to be added to wlv.vcol later
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001138 int fromcol_prev = -2; // start of inverting after cursor
1139 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001140 int lnum_in_visual_area = FALSE;
1141 pos_T pos;
1142 long v;
1143
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001144 int attr_pri = FALSE; // char_attr has priority
1145 int area_highlighting = FALSE; // Visual or incsearch highlighting
1146 // in this line
1147 int vi_attr = 0; // attributes for Visual and incsearch
1148 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001149 int area_attr = 0; // attributes desired by highlighting
1150 int search_attr = 0; // attributes desired by 'hlsearch'
1151#ifdef FEAT_SYN_HL
1152 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1153 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001154 int prev_syntax_col = -1; // column of prev_syntax_attr
1155 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001156 int has_syntax = FALSE; // this buffer has syntax highl.
1157 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001158#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001159#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001160 int did_line = FALSE; // set to TRUE when line text done
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001161 int text_prop_count;
zeertzjq4e26a9a2023-12-03 17:50:47 +01001162 int last_textprop_text_idx = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001163 int text_prop_next = 0; // next text property to use
1164 textprop_T *text_props = NULL;
1165 int *text_prop_idxs = NULL;
1166 int text_props_active = 0;
1167 proptype_T *text_prop_type = NULL;
1168 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001169 int text_prop_attr_comb = 0; // text_prop_attr combined with
1170 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001171 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001172 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001173 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001174 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001175 int saved_search_attr = 0; // search_attr to be used when n_extra
1176 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001177 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001178 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001179#endif
1180#ifdef FEAT_SPELL
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001181 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001182# define SPWORDLEN 150
1183 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1184 int nextlinecol = 0; // column where nextline[] starts
1185 int nextline_idx = 0; // index in nextline[] where next line
1186 // starts
1187 int spell_attr = 0; // attributes desired by spelling
1188 int word_end = 0; // last byte with same spell_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001189 int cur_checked_col = 0; // checked column for current line
1190#endif
1191 int extra_check = 0; // has extra highlighting
1192 int multi_attr = 0; // attributes desired by multibyte
1193 int mb_l = 1; // multi-byte byte length
1194 int mb_c = 0; // decoded multi-byte character
1195 int mb_utf8 = FALSE; // screen char is UTF-8 char
1196 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001197#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001198 int change_start = MAXCOL; // first col of changed area
1199 int change_end = -1; // last col of changed area
1200#endif
1201 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001202 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001203 int in_multispace = FALSE; // in multiple consecutive spaces
1204 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001205#ifdef LINE_ATTR
Bram Moolenaarbf915842022-08-06 22:38:02 +01001206 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001207#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001208 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001209 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001210#ifdef FEAT_ARABIC
1211 int prev_c = 0; // previous Arabic character
1212 int prev_c1 = 0; // first composing char for prev_c
1213#endif
1214#if defined(LINE_ATTR)
1215 int did_line_attr = 0;
1216#endif
1217#ifdef FEAT_TERMINAL
1218 int get_term_attr = FALSE;
1219#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001220
Martin Tournoijba43e762022-10-13 22:12:15 +01001221#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001222 // margin columns for the screen line, needed for when 'cursorlineopt'
1223 // contains "screenline"
1224 int left_curline_col = 0;
1225 int right_curline_col = 0;
1226#endif
1227
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001228#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1229 int feedback_col = 0;
1230 int feedback_old_attr = -1;
1231#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001232
1233#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1234 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001235#endif
1236#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001237 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001238#endif
1239#ifdef FEAT_CONCEAL
1240 int syntax_flags = 0;
1241 int syntax_seqnr = 0;
1242 int prev_syntax_id = 0;
1243 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1244 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001245 int did_wcol = FALSE;
1246 int old_boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001247# define VCOL_HLC (wlv.vcol - wlv.vcol_off_co - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001248# define FIX_FOR_BOGUSCOLS \
1249 { \
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001250 wlv.n_extra += wlv.vcol_off_co; \
1251 wlv.vcol -= wlv.vcol_off_co; \
1252 wlv.vcol_off_co = 0; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001253 wlv.col -= wlv.boguscols; \
1254 old_boguscols = wlv.boguscols; \
1255 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001256 }
1257#else
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001258# define VCOL_HLC (wlv.vcol - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001259#endif
1260
1261 if (startrow > endrow) // past the end already!
1262 return startrow;
1263
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001264 CLEAR_FIELD(wlv);
1265
1266 wlv.lnum = lnum;
1267 wlv.startrow = startrow;
1268 wlv.row = startrow;
1269 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001270 wlv.fromcol = -10;
1271 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001272#ifdef FEAT_LINEBREAK
1273 wlv.vcol_sbr = -1;
1274#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001275
1276 if (!number_only)
1277 {
1278 // To speed up the loop below, set extra_check when there is linebreak,
1279 // trailing white space and/or syntax processing to be done.
1280#ifdef FEAT_LINEBREAK
1281 extra_check = wp->w_p_lbr;
1282#endif
1283#ifdef FEAT_SYN_HL
1284 if (syntax_present(wp) && !wp->w_s->b_syn_error
1285# ifdef SYN_TIME_LIMIT
1286 && !wp->w_s->b_syn_slow
1287# endif
1288 )
1289 {
1290 // Prepare for syntax highlighting in this line. When there is an
1291 // error, stop syntax highlighting.
1292 save_did_emsg = did_emsg;
1293 did_emsg = FALSE;
1294 syntax_start(wp, lnum);
1295 if (did_emsg)
1296 wp->w_s->b_syn_error = TRUE;
1297 else
1298 {
1299 did_emsg = save_did_emsg;
1300#ifdef SYN_TIME_LIMIT
1301 if (!wp->w_s->b_syn_slow)
1302#endif
1303 {
1304 has_syntax = TRUE;
1305 extra_check = TRUE;
1306 }
1307 }
1308 }
1309
1310 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001311 wlv.color_cols = wp->w_p_cc_cols;
1312 if (wlv.color_cols != NULL)
1313 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001314#endif
1315
1316#ifdef FEAT_TERMINAL
1317 if (term_show_buffer(wp->w_buffer))
1318 {
1319 extra_check = TRUE;
1320 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001321 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001322 }
1323#endif
1324
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001325 // handle Visual active in this window
1326 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1327 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001328 pos_T *top, *bot;
1329
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001330 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1331 {
1332 // Visual is after curwin->w_cursor
1333 top = &curwin->w_cursor;
1334 bot = &VIsual;
1335 }
1336 else
1337 {
1338 // Visual is before curwin->w_cursor
1339 top = &VIsual;
1340 bot = &curwin->w_cursor;
1341 }
1342 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1343 if (VIsual_mode == Ctrl_V)
1344 {
1345 // block mode
1346 if (lnum_in_visual_area)
1347 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001348 wlv.fromcol = wp->w_old_cursor_fcol;
1349 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001350 }
1351 }
1352 else
1353 {
1354 // non-block mode
1355 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001356 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001357 else if (lnum == top->lnum)
1358 {
1359 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001360 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001361 else
1362 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001363 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001364 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001365 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001366 }
1367 }
1368 if (VIsual_mode != 'V' && lnum == bot->lnum)
1369 {
1370 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1371 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001372 wlv.fromcol = -10;
1373 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001374 }
1375 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001376 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001377 else
1378 {
1379 pos = *bot;
1380 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001381 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1382 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001383 else
1384 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001385 getvvcol(wp, &pos, NULL, NULL,
1386 (colnr_T *)&wlv.tocol);
1387 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001388 }
1389 }
1390 }
1391 }
1392
1393 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001394 if (!highlight_match && lnum == curwin->w_cursor.lnum
1395 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001396#ifdef FEAT_GUI
1397 && !gui.in_use
1398#endif
1399 )
1400 noinvcur = TRUE;
1401
1402 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001403 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001404 {
1405 area_highlighting = TRUE;
1406 vi_attr = HL_ATTR(HLF_V);
1407#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1408 if ((clip_star.available && !clip_star.owned
1409 && clip_isautosel_star())
1410 || (clip_plus.available && !clip_plus.owned
1411 && clip_isautosel_plus()))
1412 vi_attr = HL_ATTR(HLF_VNC);
1413#endif
1414 }
1415 }
1416
1417 // handle 'incsearch' and ":s///c" highlighting
1418 else if (highlight_match
1419 && wp == curwin
1420 && lnum >= curwin->w_cursor.lnum
1421 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1422 {
1423 if (lnum == curwin->w_cursor.lnum)
1424 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001425 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001426 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001427 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001428 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1429 {
1430 pos.lnum = lnum;
1431 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001432 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001433 }
1434 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001435 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001436 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001437 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1438 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001439 area_highlighting = TRUE;
1440 vi_attr = HL_ATTR(HLF_I);
1441 }
1442 }
1443
1444#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001445 wlv.filler_lines = diff_check(wp, lnum);
1446 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001447 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001448 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001449 {
1450 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001451 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001452 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001453 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001454 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001455 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001456 }
1457 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001458 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001459 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001460 area_highlighting = TRUE;
1461 }
1462 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001463 wlv.filler_lines = wp->w_topfill;
1464 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001465#endif
1466
1467#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001468 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001469 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001470 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001471#endif
1472
1473#ifdef LINE_ATTR
1474# ifdef FEAT_SIGNS
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001475 // If this line has a sign with line highlighting set wlv.line_attr.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001476 if (sign_present)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001477 wlv.line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001478# endif
1479# if defined(FEAT_QUICKFIX)
1480 // Highlight the current line in the quickfix window.
1481 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001482 wlv.line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001483# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001484 if (wlv.line_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001485 area_highlighting = TRUE;
1486#endif
1487
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001488#ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01001489 if (spv->spv_has_spell && !number_only)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001490 {
Luuk van Baal30805a12023-05-27 22:22:10 +01001491 // Prepare for spell checking.
1492 extra_check = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001493
Luuk van Baal30805a12023-05-27 22:22:10 +01001494 // When a word wrapped from the previous line the start of the
1495 // current line is valid.
1496 if (lnum == spv->spv_checked_lnum)
1497 cur_checked_col = spv->spv_checked_col;
Luuk van Baale84c7732023-05-31 18:57:36 +01001498 // Previous line was not spell checked, check for capital. This happens
1499 // for the first line in an updated region or after a closed fold.
1500 if (spv->spv_capcol_lnum == 0 && check_need_cap(wp, lnum, 0))
1501 spv->spv_cap_col = 0;
1502 else if (lnum != spv->spv_capcol_lnum)
Luuk van Baal30805a12023-05-27 22:22:10 +01001503 spv->spv_cap_col = -1;
1504 spv->spv_checked_lnum = 0;
1505
Luuk van Baal30805a12023-05-27 22:22:10 +01001506 // Get the start of the next line, so that words that wrap to the
1507 // next line are found too: "et<line-break>al.".
1508 // Trick: skip a few chars for C/shell/Vim comments
1509 nextline[SPWORDLEN] = NUL;
1510 if (lnum < wp->w_buffer->b_ml.ml_line_count)
Luuk van Baale84c7732023-05-31 18:57:36 +01001511 {
1512 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1513 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1514 }
1515 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1516
1517 // If current line is empty, check first word in next line for capital.
1518 ptr = skipwhite(line);
1519 if (*ptr == NUL)
1520 {
1521 spv->spv_cap_col = 0;
1522 spv->spv_capcol_lnum = lnum + 1;
1523 }
1524 // For checking first word with a capital skip white space.
1525 else if (spv->spv_cap_col == 0)
1526 spv->spv_cap_col = ptr - line;
1527
Luuk van Baal30805a12023-05-27 22:22:10 +01001528 // Copy the end of the current line into nextline[].
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001529 if (nextline[SPWORDLEN] == NUL)
1530 {
1531 // No next line or it is empty.
1532 nextlinecol = MAXCOL;
1533 nextline_idx = 0;
1534 }
1535 else
1536 {
1537 v = (long)STRLEN(line);
1538 if (v < SPWORDLEN)
1539 {
1540 // Short line, use it completely and append the start of the
1541 // next line.
1542 nextlinecol = 0;
1543 mch_memmove(nextline, line, (size_t)v);
1544 STRMOVE(nextline + v, nextline + SPWORDLEN);
1545 nextline_idx = v + 1;
1546 }
1547 else
1548 {
1549 // Long line, use only the last SPWORDLEN bytes.
1550 nextlinecol = v - SPWORDLEN;
1551 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1552 nextline_idx = SPWORDLEN + 1;
1553 }
1554 }
1555 }
1556#endif
1557
Luuk van Baale84c7732023-05-31 18:57:36 +01001558 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1559 ptr = line;
1560
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001561 if (wp->w_p_list)
1562 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001563 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001564 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001565 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001566 || wp->w_lcs_chars.trail
1567 || wp->w_lcs_chars.lead
1568 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001569 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001570
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001571 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001572 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001573 {
1574 trailcol = (colnr_T)STRLEN(ptr);
1575 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1576 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001577 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001578 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001579 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001580 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001581 {
1582 leadcol = 0;
1583 while (VIM_ISWHITE(ptr[leadcol]))
1584 ++leadcol;
1585 if (ptr[leadcol] == NUL)
1586 // in a line full of spaces all of them are treated as trailing
1587 leadcol = (colnr_T)0;
1588 else
1589 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001590 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001591 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001592 }
1593
Bram Moolenaard7657e92022-09-20 18:59:30 +01001594 wlv.wcr_attr = get_wcr_attr(wp);
1595 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001596 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001597 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001598 area_highlighting = TRUE;
1599 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001600
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001601 // When w_skipcol is non-zero and there is virtual text above the actual
1602 // text, then this much of the virtual text is skipped.
1603 int skipcol_in_text_prop_above = 0;
1604
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001605#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001606 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001607 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001608
1609 char_u *prop_start;
1610 text_prop_count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE);
1611 if (text_prop_count > 0)
1612 {
1613 // Make a copy of the properties, so that they are properly
1614 // aligned.
1615 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1616 if (text_props != NULL)
1617 mch_memmove(text_props, prop_start,
1618 text_prop_count * sizeof(textprop_T));
1619
1620 // Allocate an array for the indexes.
1621 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1622 if (text_prop_idxs == NULL)
1623 VIM_CLEAR(text_props);
1624
1625 if (text_props != NULL)
1626 {
1627 area_highlighting = TRUE;
1628 extra_check = TRUE;
1629
zeertzjq4e26a9a2023-12-03 17:50:47 +01001630 /* Find the last text property that inserts text. */
1631 for (int i = 0; i < text_prop_count; ++i)
1632 if (text_props[i].tp_id < 0)
1633 last_textprop_text_idx = i;
1634
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001635 // When skipping virtual text the props need to be sorted. The
1636 // order is reversed!
1637 if (lnum == wp->w_topline && wp->w_skipcol > 0)
1638 {
1639 for (int i = 0; i < text_prop_count; ++i)
1640 text_prop_idxs[i] = i;
1641 sort_text_props(wp->w_buffer, text_props,
1642 text_prop_idxs, text_prop_count);
1643 }
1644
1645 // Text props "above" move the line number down to where the text
1646 // is. Only count the ones that are visible, not those that are
1647 // skipped because of w_skipcol.
1648 int text_width = wp->w_width - win_col_off(wp);
1649 for (int i = text_prop_count - 1; i >= 0; --i)
1650 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1651 {
1652 if (lnum == wp->w_topline
1653 && wp->w_skipcol - skipcol_in_text_prop_above
1654 >= text_width)
1655 {
1656 // This virtual text above is skipped, remove it from
1657 // the array.
1658 skipcol_in_text_prop_above += text_width;
1659 for (int j = i + 1; j < text_prop_count; ++j)
1660 text_props[j - 1] = text_props[j];
1661 ++i;
1662 --text_prop_count;
1663 }
1664 else
1665 ++wlv.text_prop_above_count;
1666 }
1667 }
1668 }
Bram Moolenaara572b932023-02-19 14:34:37 +00001669
1670 if (number_only)
1671 {
1672 // skip over rows only used for virtual text above
1673 wlv.row += wlv.text_prop_above_count;
1674 if (wlv.row > endrow)
1675 return wlv.row;
1676 wlv.screen_row += wlv.text_prop_above_count;
1677 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001678#endif
1679
zeertzjqce53e3e2023-09-01 18:49:30 +02001680#if defined(FEAT_LINEBREAK) || defined(FEAT_PROP_POPUP)
1681 colnr_T vcol_first_char = 0;
1682 if (wp->w_p_lbr && !number_only)
1683 {
1684 chartabsize_T cts;
1685 init_chartabsize_arg(&cts, wp, lnum, 0, line, line);
1686 (void)win_lbr_chartabsize(&cts, NULL);
1687 vcol_first_char = cts.cts_first_char;
1688 clear_chartabsize_arg(&cts);
1689 }
1690#endif
1691
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001692 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1693 // first character to be displayed.
1694 if (wp->w_p_wrap)
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001695 v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001696 else
1697 v = wp->w_leftcol;
1698 if (v > 0 && !number_only)
1699 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001700 char_u *prev_ptr = ptr;
1701 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001702 int charsize = 0;
zeertzjqb557f482023-08-22 22:07:34 +02001703 int head = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001704
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001705 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
zeertzjqb557f482023-08-22 22:07:34 +02001706 cts.cts_max_head_vcol = v;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001707 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001708 {
zeertzjqb557f482023-08-22 22:07:34 +02001709 head = 0;
1710 charsize = win_lbr_chartabsize(&cts, &head);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001711 cts.cts_vcol += charsize;
1712 prev_ptr = cts.cts_ptr;
1713 MB_PTR_ADV(cts.cts_ptr);
zeertzjqabc80812023-09-24 23:32:18 +02001714 if (wp->w_p_list)
1715 {
1716 in_multispace = *prev_ptr == ' ' && (*cts.cts_ptr == ' '
1717 || (prev_ptr > line && prev_ptr[-1] == ' '));
1718 if (!in_multispace)
1719 multispace_pos = 0;
1720 else if (cts.cts_ptr >= line + leadcol
1721 && wp->w_lcs_chars.multispace != NULL)
1722 {
1723 ++multispace_pos;
1724 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
1725 multispace_pos = 0;
1726 }
1727 else if (cts.cts_ptr < line + leadcol
1728 && wp->w_lcs_chars.leadmultispace != NULL)
1729 {
1730 ++multispace_pos;
1731 if (wp->w_lcs_chars.leadmultispace[multispace_pos] == NUL)
1732 multispace_pos = 0;
1733 }
1734 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001735 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001736 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001737 ptr = cts.cts_ptr;
1738 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001739
1740 // When:
1741 // - 'cuc' is set, or
1742 // - 'colorcolumn' is set, or
1743 // - 'virtualedit' is set, or
1744 // - the visual mode is active,
1745 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001746 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001747#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001748 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001749#endif
1750 virtual_active() ||
1751 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001752 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001753
1754 // Handle a character that's not completely on the screen: Put ptr at
1755 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001756 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001757 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001758 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001759 ptr = prev_ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001760 }
zeertzjqb557f482023-08-22 22:07:34 +02001761 if (v > wlv.vcol)
1762 skip_cells = v - wlv.vcol - head;
Bram Moolenaarcd105412022-10-10 19:50:42 +01001763
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001764 // Adjust for when the inverted text is before the screen,
1765 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001766 if (wlv.tocol <= wlv.vcol)
1767 wlv.fromcol = 0;
1768 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1769 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001770
1771#ifdef FEAT_LINEBREAK
1772 // When w_skipcol is non-zero, first line needs 'showbreak'
1773 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001774 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001775#endif
1776#ifdef FEAT_SPELL
1777 // When spell checking a word we need to figure out the start of the
1778 // word and if it's badly spelled or not.
Luuk van Baal30805a12023-05-27 22:22:10 +01001779 if (spv->spv_has_spell)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001780 {
1781 int len;
1782 colnr_T linecol = (colnr_T)(ptr - line);
1783 hlf_T spell_hlf = HLF_COUNT;
1784
1785 pos = wp->w_cursor;
1786 wp->w_cursor.lnum = lnum;
1787 wp->w_cursor.col = linecol;
1788 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1789
1790 // spell_move_to() may call ml_get() and make "line" invalid
1791 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1792 ptr = line + linecol;
1793
1794 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1795 {
1796 // no bad word found at line start, don't check until end of a
1797 // word
1798 spell_hlf = HLF_COUNT;
1799 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1800 }
1801 else
1802 {
1803 // bad word found, use attributes until end of word
1804 word_end = wp->w_cursor.col + len + 1;
1805
1806 // Turn index into actual attributes.
1807 if (spell_hlf != HLF_COUNT)
1808 spell_attr = highlight_attr[spell_hlf];
1809 }
1810 wp->w_cursor = pos;
1811
1812# ifdef FEAT_SYN_HL
1813 // Need to restart syntax highlighting for this line.
1814 if (has_syntax)
1815 syntax_start(wp, lnum);
1816# endif
1817 }
1818#endif
1819 }
1820
1821 // Correct highlighting for cursor that can't be disabled.
1822 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001823 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001824 {
1825 if (noinvcur)
1826 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001827 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001828 {
1829 // highlighting starts at cursor, let it start just after the
1830 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001831 fromcol_prev = wlv.fromcol;
1832 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001833 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001834 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001835 // restart highlighting after the cursor
1836 fromcol_prev = wp->w_virtcol;
1837 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001838 if (wlv.fromcol >= wlv.tocol)
1839 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001840 }
1841
1842#ifdef FEAT_SEARCH_EXTRA
1843 if (!number_only)
1844 {
1845 v = (long)(ptr - line);
1846 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1847 &line, &screen_search_hl,
1848 &search_attr);
1849 ptr = line + v; // "line" may have been updated
1850 }
1851#endif
1852
1853#ifdef FEAT_SYN_HL
1854 // Cursor line highlighting for 'cursorline' in the current window.
1855 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1856 {
1857 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001858 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001859 if (!(wp == curwin && VIsual_active)
1860 && wp->w_p_culopt_flags != CULOPT_NBR)
1861 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001862 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001863 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1864
zeertzjqb7acea12022-12-12 13:20:43 +00001865 // Only apply CursorLine highlight here when "screenline" is not
1866 // present in 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001867 if (!wlv.cul_screenline)
zeertzjqb7acea12022-12-12 13:20:43 +00001868 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001869 else
1870 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001871 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001872 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1873 }
1874 area_highlighting = TRUE;
1875 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001876 }
1877#endif
1878
Bram Moolenaar1306b362022-08-06 15:59:06 +01001879 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001880
1881 // Repeat for the whole displayed line.
1882 for (;;)
1883 {
1884#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001885 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001886#endif
1887#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001888 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001889#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001890
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001891 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001892 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001893 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001894#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001895 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001896 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001897 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001898 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001899 }
1900#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001901 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001902 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001903 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001904 if (cmdwin_type != 0 && wp == curwin)
1905 {
1906 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001907 wlv.n_extra = 1;
1908 wlv.c_extra = cmdwin_type;
1909 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001910 wlv.char_attr =
1911 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001912 }
1913 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001914#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001915 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001916 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001917 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001918 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001919 }
1920#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001921#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001922 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001923 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001924 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001925 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001926 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001927 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001928 }
1929#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001930 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001931 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001932 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001933 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001934 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001935 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001936#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001937 // Check if 'breakindent' applies and show it.
1938 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1939 if (wlv.n_extra == 0)
1940 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001941#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001942#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001943 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001944 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001945 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001946 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001947 }
1948#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001949 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001950 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001951 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001952 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001953 }
1954 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001955
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001956#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001957 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001958 && wlv.vcol >= left_curline_col
1959 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001960 {
zeertzjqb7acea12022-12-12 13:20:43 +00001961 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001962 }
1963#endif
1964
1965 // When still displaying '$' of change command, stop at cursor.
1966 // When only displaying the (relative) line number and that's done,
1967 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001968 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001969 && lnum == wp->w_cursor.lnum
1970 && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001971 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001972#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001973 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001974#endif
1975 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001976 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001977 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001978 // Pretend we have finished updating the window. Except when
1979 // 'cursorcolumn' is set.
1980#ifdef FEAT_SYN_HL
1981 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001982 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001983 else
1984#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001985 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001986 break;
1987 }
1988
Bram Moolenaar1306b362022-08-06 15:59:06 +01001989 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001990 {
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001991#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001992 if (text_props != NULL)
1993 {
1994 int pi;
1995 int bcol = (int)(ptr - line);
1996
Bram Moolenaar1306b362022-08-06 15:59:06 +01001997 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001998# ifdef FEAT_LINEBREAK
1999 && !in_linebreak
2000# endif
2001 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002002 --bcol; // still working on the previous char, e.g. Tab
2003
2004 // Check if any active property ends.
2005 for (pi = 0; pi < text_props_active; ++pi)
2006 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002007 int tpi = text_prop_idxs[pi];
2008 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002009
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002010 // An inline property ends when after the start column plus
2011 // length. An "above" property ends when used and n_extra
2012 // is zero.
2013 if ((tp->tp_col != MAXCOL
2014 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002015 {
2016 if (pi + 1 < text_props_active)
2017 mch_memmove(text_prop_idxs + pi,
2018 text_prop_idxs + pi + 1,
2019 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002020 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002021 --text_props_active;
2022 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002023# ifdef FEAT_LINEBREAK
2024 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002025 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002026 syntax_attr = 0;
2027# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002028 }
2029 }
2030
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002031# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01002032 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002033 // not on the next char yet, don't start another prop
2034 --bcol;
2035# endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002036 int display_text_first = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002037
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002038 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002039 // With 'nowrap' and not in the first screen line only "below"
2040 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002041 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002042 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002043 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002044 && (wp->w_p_wrap
2045 || wlv.row == startrow
2046 || (text_props[text_prop_next].tp_flags
2047 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002048 || (bcol == 0
2049 && (text_props[text_prop_next].tp_flags
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002050 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002051 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002052 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01002053 if (text_props[text_prop_next].tp_col == MAXCOL
2054 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002055 + text_props[text_prop_next].tp_len)
2056 text_prop_idxs[text_props_active++] = text_prop_next;
2057 ++text_prop_next;
2058 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002059
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002060 if (wlv.n_extra == 0 ||
2061 (!wlv.extra_for_textprop
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002062 && !(text_prop_type != NULL &&
2063 text_prop_flags & PT_FLAG_OVERRIDE)
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002064 ))
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002065 {
2066 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002067 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002068 text_prop_flags = 0;
2069 text_prop_type = NULL;
2070 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002071 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002072 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002073 if (text_props_active > 0 && wlv.n_extra == 0
2074 && !display_text_first)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002075 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01002076 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002077 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002078 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002079
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002080 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002081 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002082
2083 // Sort the properties on priority and/or starting last.
2084 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002085 sort_text_props(wp->w_buffer, text_props,
2086 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002087
2088 for (pi = 0; pi < text_props_active; ++pi)
2089 {
2090 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002091 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002092 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002093 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002094
Bram Moolenaarcd105412022-10-10 19:50:42 +01002095 // Only use a text property that can be displayed.
2096 // Skip "after" properties when wrap is off and at the
2097 // end of the window.
2098 if (pt != NULL
2099 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2100 && tp->tp_id != -MAXCOL
2101 && !(tp->tp_id < 0
2102 && !wp->w_p_wrap
2103 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2104 | TP_FLAG_ALIGN_ABOVE
2105 | TP_FLAG_ALIGN_BELOW)) == 0
2106 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002107 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002108 if (tp->tp_col == MAXCOL
2109 && *ptr == NUL
2110 && ((wp->w_p_list && lcs_eol_one > 0
2111 && (tp->tp_flags
2112 & TP_FLAG_ALIGN_ABOVE) == 0)
2113 || (ptr == line
2114 && !did_line
2115 && (tp->tp_flags
2116 & TP_FLAG_ALIGN_BELOW))))
2117 {
2118 // skip this prop, first display the '$' after
2119 // the line or display an empty line
2120 text_prop_follows = TRUE;
2121 if (used_tpi < 0)
2122 display_text_first = TRUE;
2123 continue;
2124 }
2125
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002126 if (pt->pt_hl_id > 0)
2127 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002128 text_prop_type = pt;
2129 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002130 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002131 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2132 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002133 text_prop_flags = pt->pt_flags;
2134 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002135 used_tpi = tpi;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002136 display_text_first = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002137 }
2138 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002139 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002140 && -text_prop_id
2141 <= wp->w_buffer->b_textprop_text.ga_len)
2142 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002143 textprop_T *tp = &text_props[used_tpi];
2144 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002145 ->b_textprop_text.ga_data)[
2146 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002147 int above = (tp->tp_flags
2148 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002149 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002150
2151 // reset the ID in the copy to avoid it being used
2152 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002153 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002154
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002155 if (p != NULL)
2156 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002157 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002158 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002159 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002160 & TP_FLAG_ALIGN_BELOW);
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002161 int wrap = tp->tp_col < MAXCOL
2162 || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002163 int padding = tp->tp_col == MAXCOL
2164 && tp->tp_len > 1
2165 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002166
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002167 // Insert virtual text before the current
2168 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002169 wlv.p_extra = p;
2170 wlv.c_extra = NUL;
2171 wlv.c_final = NUL;
2172 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002173 wlv.extra_for_textprop = TRUE;
zeertzjq6e940d92023-08-17 23:21:40 +02002174 wlv.start_extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002175 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2176 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002177 n_attr = mb_charlen(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002178 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002179 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002180 if (*ptr == NUL)
2181 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002182 text_prop_flags &= ~PT_FLAG_COMBINE;
zeertzjq6b9c2022023-09-11 20:01:17 +02002183# ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002184 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002185 {
2186 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002187 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002188 wlv.need_showbreak = FALSE;
2189 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002190 }
zeertzjq6b9c2022023-09-11 20:01:17 +02002191# endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002192 if ((right || above || below || !wrap
2193 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002194 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002195 char_u *prev_p_extra = wlv.p_extra;
2196 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002197
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002198 // Take care of padding, right-align and
2199 // truncation.
2200 // Shared with win_lbr_chartabsize(), must do
2201 // exactly the same.
2202 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002203 wlv.vcol,
zeertzjq6b9c2022023-09-11 20:01:17 +02002204# ifdef FEAT_RIGHTLEFT
2205 wp->w_p_rl
2206 ? wp->w_width - wlv.col - 1
2207 :
2208# endif
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002209 wlv.col,
2210 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002211 &n_attr, &wlv.n_attr_skip,
2212 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002213 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002214 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002215 // wlv.p_extra was allocated
2216 vim_free(p_extra_free2);
2217 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002218 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002219
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002220 if (above)
2221 wlv.vcol_off_tp = wlv.n_extra;
2222
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002223 if (lcs_eol_one < 0
2224 && wp->w_p_wrap
2225 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002226 + wlv.n_extra - 2 > wp->w_width)
2227 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002228 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002229
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002230 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002231 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002232 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002233 {
2234 draw_screen_line(wp, &wlv);
2235
2236 // When line got too long for screen break
2237 // here.
2238 if (wlv.row == endrow)
2239 {
2240 ++wlv.row;
2241 break;
2242 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002243 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002244 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002245 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002246 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002247 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002248
Bram Moolenaarcd105412022-10-10 19:50:42 +01002249 // If the text didn't reach until the first window
2250 // column we need to skip cells.
2251 if (skip_cells > 0)
2252 {
2253 if (wlv.n_extra > skip_cells)
2254 {
2255 wlv.n_extra -= skip_cells;
2256 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002257 wlv.n_attr_skip -= skip_cells;
2258 if (wlv.n_attr_skip < 0)
2259 wlv.n_attr_skip = 0;
zeertzjqb557f482023-08-22 22:07:34 +02002260 skipped_cells += skip_cells;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002261 skip_cells = 0;
2262 }
2263 else
2264 {
2265 // the whole text is left of the window, drop
2266 // it and advance to the next one
2267 skip_cells -= wlv.n_extra;
zeertzjqb557f482023-08-22 22:07:34 +02002268 skipped_cells += wlv.n_extra;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002269 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002270 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002271 bail_out = TRUE;
2272 }
2273 }
2274
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002275 // If another text prop follows the condition below at
2276 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002277 // If this is an "above" text prop and 'nowrap' the we
2278 // must wrap anyway.
2279 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002280 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002281 && (wp->w_p_wrap
2282 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002283 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002284
2285 if (bail_out)
2286 // starting a new line for "below"
2287 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002288 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002289 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002290 else if (text_prop_next < text_prop_count
2291 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002292 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2293 || (!wp->w_p_wrap
2294 && wlv.col == wp->w_width - 1
2295 && (text_props[text_prop_next].tp_flags
2296 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002297 // When at last-but-one character and a text property
2298 // follows after it, we may need to flush the line after
2299 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002300 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002301 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002302 }
zeertzjq6e940d92023-08-17 23:21:40 +02002303
2304 if (wlv.start_extra_for_textprop)
2305 {
2306 wlv.start_extra_for_textprop = FALSE;
2307 // restore search_attr and area_attr when n_extra
2308 // is down to zero
2309 saved_search_attr = search_attr;
2310 saved_area_attr = area_attr;
2311 search_attr = 0;
2312 area_attr = 0;
2313 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002314#endif
2315
zeertzjq6e940d92023-08-17 23:21:40 +02002316 int *area_attr_p =
2317#ifdef FEAT_PROP_POPUP
2318 wlv.extra_for_textprop ? &saved_area_attr :
2319#endif
2320 &area_attr;
2321
2322 // handle Visual or match highlighting in this line
2323 if (wlv.vcol == wlv.fromcol
2324 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
2325 && ((wlv.n_extra == 0 && (*mb_ptr2cells)(ptr) > 1)
2326 || (wlv.n_extra > 0 && wlv.p_extra != NULL
2327 && (*mb_ptr2cells)(wlv.p_extra) > 1)))
2328 || ((int)vcol_prev == fromcol_prev
2329 && vcol_prev < wlv.vcol // not at margin
2330 && wlv.vcol < wlv.tocol))
2331 *area_attr_p = vi_attr; // start highlighting
2332 else if (*area_attr_p != 0
2333 && (wlv.vcol == wlv.tocol
2334 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
2335 *area_attr_p = 0; // stop highlighting
2336
zeertzjqe500ae82023-08-17 22:35:26 +02002337#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaare38fc862022-08-11 17:24:50 +01002338 if (wlv.n_extra == 0)
2339 {
2340 // Check for start/end of 'hlsearch' and other matches.
2341 // After end, check for start/end of next match.
2342 // When another match, have to check for start again.
2343 v = (long)(ptr - line);
2344 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2345 &screen_search_hl, &has_match_conc,
2346 &match_conc, did_line_attr, lcs_eol_one,
2347 &on_last_col);
2348 ptr = line + v; // "line" may have been changed
Bram Moolenaare38fc862022-08-11 17:24:50 +01002349
2350 // Do not allow a conceal over EOL otherwise EOL will be missed
2351 // and bad things happen.
2352 if (*ptr == NUL)
2353 has_match_conc = 0;
zeertzjqb25dbb32023-08-13 18:11:05 +02002354 }
zeertzjqe500ae82023-08-17 22:35:26 +02002355#endif
zeertzjqb25dbb32023-08-13 18:11:05 +02002356
Bram Moolenaare38fc862022-08-11 17:24:50 +01002357#ifdef FEAT_DIFF
2358 if (wlv.diff_hlf != (hlf_T)0)
2359 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002360 // When there is extra text (e.g. virtual text) it gets the
2361 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002362 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2363 && wlv.n_extra == 0)
2364 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002365 if (wlv.diff_hlf == HLF_TXD
2366 && ((ptr - line > change_end && wlv.n_extra == 0)
2367 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002368 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002369 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002370 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2371 && wp->w_p_culopt_flags != CULOPT_NBR
2372 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2373 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002374 wlv.line_attr = hl_combine_attr(
2375 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002376 }
2377#endif
2378
Bram Moolenaara74fda62019-10-19 17:38:03 +02002379#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002380 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002381 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002382 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002383# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002384 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002385 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002386# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002387 // Get syntax attribute.
2388 if (has_syntax)
2389 {
2390 // Get the syntax attribute for the character. If there
2391 // is an error, disable syntax highlighting.
2392 save_did_emsg = did_emsg;
2393 did_emsg = FALSE;
2394
2395 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002396 if (v == prev_syntax_col)
2397 // at same column again
2398 syntax_attr = prev_syntax_attr;
2399 else
2400 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002401# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002402 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002403# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002404 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002405# ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01002406 spv->spv_has_spell ? &can_spell :
Bram Moolenaar34390282019-10-16 14:38:26 +02002407# endif
Luuk van Baal30805a12023-05-27 22:22:10 +01002408 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002409 prev_syntax_col = v;
2410 prev_syntax_attr = syntax_attr;
2411 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002412
Bram Moolenaar34390282019-10-16 14:38:26 +02002413 if (did_emsg)
2414 {
2415 wp->w_s->b_syn_error = TRUE;
2416 has_syntax = FALSE;
2417 syntax_attr = 0;
2418 }
2419 else
2420 did_emsg = save_did_emsg;
2421# ifdef SYN_TIME_LIMIT
2422 if (wp->w_s->b_syn_slow)
2423 has_syntax = FALSE;
2424# endif
2425
2426 // Need to get the line again, a multi-line regexp may
2427 // have made it invalid.
2428 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2429 ptr = line + v;
2430# ifdef FEAT_CONCEAL
2431 // no concealing past the end of the line, it interferes
2432 // with line highlighting
2433 if (*ptr == NUL)
2434 syntax_flags = 0;
2435 else
2436 syntax_flags = get_syntax_info(&syntax_seqnr);
2437# endif
2438 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002439 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002440# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002441 // Combine text property highlight into syntax highlight.
2442 if (text_prop_type != NULL)
2443 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002444 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002445 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2446 else
2447 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002448 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002449 }
2450# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002451#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002452
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002453 // Decide which of the highlight attributes to use.
2454 attr_pri = TRUE;
2455#ifdef LINE_ATTR
2456 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002457 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002458 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002459 if (!highlight_match)
2460 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002461 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002462# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002463 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002464# endif
2465 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002466 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002467 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002468 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002469# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002470 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002471# endif
2472 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002473 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002474 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2475 || wlv.vcol < wlv.fromcol
2476 || vcol_prev < fromcol_prev
2477 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002478 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002479 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002480 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002481# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002482 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002483# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002484 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002485# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002486 attr_pri = FALSE;
2487 }
2488#else
2489 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002490 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002491 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002492 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002493#endif
2494 else
2495 {
2496 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002497#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002498 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002499#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002500 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002501#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002502 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002503#ifdef FEAT_PROP_POPUP
2504 // override with text property highlight when "override" is TRUE
2505 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002506 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002507#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002508 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002509
2510 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002511 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002512 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002513 if (wlv.char_attr == 0)
2514 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002515 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002516 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002517 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002518
2519 // Get the next character to put on the screen.
2520
2521 // The "p_extra" points to the extra stuff that is inserted to
2522 // represent special characters (non-printable stuff) and other
2523 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002524 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002525 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2526 // "p_extra[n_extra]".
2527 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002528 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002529 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002530 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002531 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002532 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2533 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002534 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2535 if (enc_utf8 && utf_char2len(c) > 1)
2536 {
2537 mb_utf8 = TRUE;
2538 u8cc[0] = 0;
2539 c = 0xc0;
2540 }
2541 else
2542 mb_utf8 = FALSE;
2543 }
2544 else
2545 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002546 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002547 if (has_mbyte)
2548 {
2549 mb_c = c;
2550 if (enc_utf8)
2551 {
2552 // If the UTF-8 character is more than one byte:
2553 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002554 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002555 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002556 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002557 mb_l = 1;
2558 else if (mb_l > 1)
2559 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002560 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002561 mb_utf8 = TRUE;
2562 c = 0xc0;
2563 }
2564 }
2565 else
2566 {
2567 // if this is a DBCS character, put it in "mb_c"
2568 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002569 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002570 mb_l = 1;
2571 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002572 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002573 }
2574 if (mb_l == 0) // at the NUL at end-of-line
2575 mb_l = 1;
2576
2577 // If a double-width char doesn't fit display a '>' in the
2578 // last column.
2579 if ((
2580# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002581 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002582# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002583 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002584 && (*mb_char2cells)(mb_c) == 2)
2585 {
2586 c = '>';
2587 mb_c = c;
2588 mb_l = 1;
2589 mb_utf8 = FALSE;
2590 multi_attr = HL_ATTR(HLF_AT);
2591#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002592 if (wlv.cul_attr)
2593 multi_attr = hl_combine_attr(
2594 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002595#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002596 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002597
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002598 // put the pointer back to output the double-width
2599 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002600 ++wlv.n_extra;
2601 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002602 }
2603 else
2604 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002605 wlv.n_extra -= mb_l - 1;
2606 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002607 }
2608 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002609 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002610 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002611 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002612#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002613 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002614 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002615 // Only restore search_attr and area_attr after "n_extra" in
2616 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002617 if (wlv.saved_n_extra <= 0)
2618 {
2619 if (search_attr == 0)
2620 search_attr = saved_search_attr;
2621 if (area_attr == 0 && *ptr != NUL)
2622 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002623
2624 if (wlv.extra_for_textprop)
2625 // wlv.extra_attr should be used at this position but
2626 // not any further.
2627 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002628 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002629
2630 wlv.extra_for_textprop = FALSE;
2631 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002632 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002633#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002634 }
2635 else
2636 {
2637#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002638 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002639#endif
zeertzjqe500ae82023-08-17 22:35:26 +02002640 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002641
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002642 // Get a character from the line itself.
2643 c = *ptr;
2644#ifdef FEAT_LINEBREAK
2645 c0 = *ptr;
2646#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002647 if (c == NUL)
zeertzjqb557f482023-08-22 22:07:34 +02002648 {
2649#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002650 // text is finished, may display a "below" virtual text
2651 did_line = TRUE;
2652#endif
zeertzjqb557f482023-08-22 22:07:34 +02002653 // no more cells to skip
2654 skip_cells = 0;
2655 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002656
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002657 if (has_mbyte)
2658 {
2659 mb_c = c;
2660 if (enc_utf8)
2661 {
2662 // If the UTF-8 character is more than one byte: Decode it
2663 // into "mb_c".
2664 mb_l = utfc_ptr2len(ptr);
2665 mb_utf8 = FALSE;
2666 if (mb_l > 1)
2667 {
2668 mb_c = utfc_ptr2char(ptr, u8cc);
2669 // Overlong encoded ASCII or ASCII with composing char
2670 // is displayed normally, except a NUL.
2671 if (mb_c < 0x80)
2672 {
2673 c = mb_c;
2674#ifdef FEAT_LINEBREAK
2675 c0 = mb_c;
2676#endif
2677 }
2678 mb_utf8 = TRUE;
2679
2680 // At start of the line we can have a composing char.
2681 // Draw it as a space with a composing char.
2682 if (utf_iscomposing(mb_c))
2683 {
2684 int i;
2685
2686 for (i = Screen_mco - 1; i > 0; --i)
2687 u8cc[i] = u8cc[i - 1];
2688 u8cc[0] = mb_c;
2689 mb_c = ' ';
2690 }
2691 }
2692
2693 if ((mb_l == 1 && c >= 0x80)
2694 || (mb_l >= 1 && mb_c == 0)
2695 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2696 {
2697 // Illegal UTF-8 byte: display as <xx>.
2698 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002699 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002700# ifdef FEAT_RIGHTLEFT
2701 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002702 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002703# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002704 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002705 c = *wlv.p_extra;
2706 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002707 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002708 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2709 wlv.c_extra = NUL;
2710 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002711 if (area_attr == 0 && search_attr == 0)
2712 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002713 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002714 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002715 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002716 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002717 }
2718 }
2719 else if (mb_l == 0) // at the NUL at end-of-line
2720 mb_l = 1;
2721#ifdef FEAT_ARABIC
2722 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2723 {
2724 // Do Arabic shaping.
2725 int pc, pc1, nc;
2726 int pcc[MAX_MCO];
2727
2728 // The idea of what is the previous and next
2729 // character depends on 'rightleft'.
2730 if (wp->w_p_rl)
2731 {
2732 pc = prev_c;
2733 pc1 = prev_c1;
2734 nc = utf_ptr2char(ptr + mb_l);
2735 prev_c1 = u8cc[0];
2736 }
2737 else
2738 {
2739 pc = utfc_ptr2char(ptr + mb_l, pcc);
2740 nc = prev_c;
2741 pc1 = pcc[0];
2742 }
2743 prev_c = mb_c;
2744
2745 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2746 }
2747 else
2748 prev_c = mb_c;
2749#endif
2750 }
2751 else // enc_dbcs
2752 {
2753 mb_l = MB_BYTE2LEN(c);
2754 if (mb_l == 0) // at the NUL at end-of-line
2755 mb_l = 1;
2756 else if (mb_l > 1)
2757 {
2758 // We assume a second byte below 32 is illegal.
2759 // Hopefully this is OK for all double-byte encodings!
2760 if (ptr[1] >= 32)
2761 mb_c = (c << 8) + ptr[1];
2762 else
2763 {
2764 if (ptr[1] == NUL)
2765 {
2766 // head byte at end of line
2767 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002768 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002769 }
2770 else
2771 {
2772 // illegal tail byte
2773 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002774 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002775 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002776 wlv.p_extra = wlv.extra;
2777 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002778 wlv.c_extra = NUL;
2779 wlv.c_final = NUL;
2780 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002781 if (area_attr == 0 && search_attr == 0)
2782 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002783 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002784 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002785 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002786 // save current attr
2787 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002788 }
2789 mb_c = c;
2790 }
2791 }
2792 }
2793 // If a double-width char doesn't fit display a '>' in the
2794 // last column; the character is displayed at the start of the
2795 // next line.
2796 if ((
2797# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002798 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002799# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002800 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002801 && (*mb_char2cells)(mb_c) == 2)
2802 {
2803 c = '>';
2804 mb_c = c;
2805 mb_utf8 = FALSE;
2806 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002807 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002808 // Put pointer back so that the character will be
2809 // displayed at the start of the next line.
2810 --ptr;
2811#ifdef FEAT_CONCEAL
2812 did_decrement_ptr = TRUE;
2813#endif
2814 }
2815 else if (*ptr != NUL)
2816 ptr += mb_l - 1;
2817
2818 // If a double-width char doesn't fit at the left side display
2819 // a '<' in the first column. Don't do this for unprintable
2820 // characters.
zeertzjqb557f482023-08-22 22:07:34 +02002821 if (skip_cells > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002822 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002823 wlv.n_extra = 1;
2824 wlv.c_extra = MB_FILLER_CHAR;
2825 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002826 c = ' ';
2827 if (area_attr == 0 && search_attr == 0)
2828 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002829 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002830 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002831 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002832 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002833 }
2834 mb_c = c;
2835 mb_utf8 = FALSE;
2836 mb_l = 1;
2837 }
2838
2839 }
2840 ++ptr;
2841
2842 if (extra_check)
2843 {
2844#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002845 // Check spelling (unless at the end of the line).
2846 // Only do this when there is no syntax highlighting, the
2847 // @Spell cluster is not used or the current syntax item
2848 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002849 v = (long)(ptr - line);
Luuk van Baal30805a12023-05-27 22:22:10 +01002850 if (spv->spv_has_spell && v >= word_end && v > cur_checked_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002851 {
2852 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002853 // do not calculate cap_col at the end of the line or when
2854 // only white space is following
2855 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002856# ifdef FEAT_SYN_HL
2857 !has_syntax ||
2858# endif
2859 can_spell))
2860 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002861 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002862 int len;
2863 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002864
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002865 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002866 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002867
2868 // Use nextline[] if possible, it has the start of the
2869 // next line concatenated.
2870 if ((prev_ptr - line) - nextlinecol >= 0)
2871 p = nextline + (prev_ptr - line) - nextlinecol;
2872 else
2873 p = prev_ptr;
Luuk van Baal30805a12023-05-27 22:22:10 +01002874 spv->spv_cap_col -= (int)(prev_ptr - line);
2875 len = spell_check(wp, p, &spell_hlf, &spv->spv_cap_col,
2876 spv->spv_unchanged);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002877 word_end = v + len;
2878
2879 // In Insert mode only highlight a word that
2880 // doesn't touch the cursor.
2881 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002882 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002883 && wp->w_cursor.lnum == lnum
2884 && wp->w_cursor.col >=
2885 (colnr_T)(prev_ptr - line)
2886 && wp->w_cursor.col < (colnr_T)word_end)
2887 {
2888 spell_hlf = HLF_COUNT;
2889 spell_redraw_lnum = lnum;
2890 }
2891
2892 if (spell_hlf == HLF_COUNT && p != prev_ptr
2893 && (p - nextline) + len > nextline_idx)
2894 {
2895 // Remember that the good word continues at the
2896 // start of the next line.
Luuk van Baal30805a12023-05-27 22:22:10 +01002897 spv->spv_checked_lnum = lnum + 1;
2898 spv->spv_checked_col = (p - nextline) + len
2899 - nextline_idx;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002900 }
2901
2902 // Turn index into actual attributes.
2903 if (spell_hlf != HLF_COUNT)
2904 spell_attr = highlight_attr[spell_hlf];
2905
Luuk van Baal30805a12023-05-27 22:22:10 +01002906 if (spv->spv_cap_col > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002907 {
2908 if (p != prev_ptr
Luuk van Baal30805a12023-05-27 22:22:10 +01002909 && (p - nextline) + spv->spv_cap_col
2910 >= nextline_idx)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002911 {
2912 // Remember that the word in the next line
2913 // must start with a capital.
Luuk van Baal30805a12023-05-27 22:22:10 +01002914 spv->spv_capcol_lnum = lnum + 1;
2915 spv->spv_cap_col = ((p - nextline)
2916 + spv->spv_cap_col - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002917 }
2918 else
2919 // Compute the actual column.
Luuk van Baal30805a12023-05-27 22:22:10 +01002920 spv->spv_cap_col += (prev_ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002921 }
2922 }
2923 }
2924 if (spell_attr != 0)
2925 {
2926 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002927 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2928 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002929 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002930 wlv.char_attr = hl_combine_attr(spell_attr,
2931 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002932 }
2933#endif
2934#ifdef FEAT_LINEBREAK
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02002935 // we don't want linebreak to apply for lines that start with
2936 // leading spaces, followed by long letters (since it would add
2937 // a break at the beginning of a line and this might be unexpected)
2938 //
2939 // So only allow to linebreak, once we have found chars not in
2940 // 'breakat' in the line.
2941 if ( wp->w_p_lbr && !wlv.need_lbr && c != NUL &&
2942 !VIM_ISBREAK((int)*ptr))
2943 wlv.need_lbr = TRUE;
2944#endif
2945#ifdef FEAT_LINEBREAK
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002946 // Found last space before word: check for line break.
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02002947 if (wp->w_p_lbr && c0 == c && wlv.need_lbr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002948 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2949 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002950 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2951 : 0;
2952 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002953 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002954
zeertzjqce53e3e2023-09-01 18:49:30 +02002955 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol
2956# ifdef FEAT_PROP_POPUP
2957 - vcol_first_char,
2958# endif
2959 line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002960# ifdef FEAT_PROP_POPUP
2961 // do not want virtual text counted here
2962 cts.cts_has_prop_with_text = FALSE;
2963# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002964 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002965 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002966
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002967 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002968 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002969 // line break, but for TABs the highlighting should
2970 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002971 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002972
Bram Moolenaar1306b362022-08-06 15:59:06 +01002973 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002974# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002975 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002976 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002977 wp->w_buffer->b_p_vts_array) - 1;
2978# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002979 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002980 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002981# endif
2982
Bram Moolenaar1306b362022-08-06 15:59:06 +01002983 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2984 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002985# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002986 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002987 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002988# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002989 if (VIM_ISWHITE(c))
2990 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002991# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002992 if (c == TAB)
2993 // See "Tab alignment" below.
2994 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002995# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002996 if (!wp->w_p_list)
2997 c = ' ';
2998 }
2999 }
3000#endif
zeertzjqabc80812023-09-24 23:32:18 +02003001 if (wp->w_p_list)
3002 {
3003 in_multispace = c == ' ' && (*ptr == ' '
3004 || (prev_ptr > line && prev_ptr[-1] == ' '));
3005 if (!in_multispace)
3006 multispace_pos = 0;
3007 }
zeertzjqf14b8ba2021-09-10 16:58:30 +02003008
Bram Moolenaareed9d462021-02-15 20:38:25 +01003009 // 'list': Change char 160 to 'nbsp' and space to 'space'
3010 // setting in 'listchars'. But not when the character is
3011 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003012 if (wp->w_p_list
3013 && ((((c == 160 && mb_l == 1)
3014 || (mb_utf8
3015 && ((mb_c == 160 && mb_l == 2)
3016 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01003017 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003018 || (c == ' '
3019 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02003020 && (wp->w_lcs_chars.space
3021 || (in_multispace
3022 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01003023 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003024 && ptr - line <= trailcol)))
3025 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02003026 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
3027 {
3028 c = wp->w_lcs_chars.multispace[multispace_pos++];
3029 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
3030 multispace_pos = 0;
3031 }
3032 else
3033 c = (c == ' ') ? wp->w_lcs_chars.space
3034 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003035 if (area_attr == 0 && search_attr == 0)
3036 {
3037 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003038 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003039 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003040 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003041 }
3042 mb_c = c;
3043 if (enc_utf8 && utf_char2len(c) > 1)
3044 {
3045 mb_utf8 = TRUE;
3046 u8cc[0] = 0;
3047 c = 0xc0;
3048 }
3049 else
3050 mb_utf8 = FALSE;
3051 }
3052
zeertzjq2e7cba32022-06-10 15:30:32 +01003053 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
3054 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003055 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003056 if (leadcol != 0 && in_multispace && ptr < line + leadcol
3057 && wp->w_lcs_chars.leadmultispace != NULL)
3058 {
3059 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01003060 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
3061 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003062 multispace_pos = 0;
3063 }
3064
3065 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
3066 c = wp->w_lcs_chars.trail;
3067
3068 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
3069 c = wp->w_lcs_chars.lead;
3070
zeertzjq2e7cba32022-06-10 15:30:32 +01003071 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003072 c = wp->w_lcs_chars.space;
3073
3074
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003075 if (!attr_pri)
3076 {
3077 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003078 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003079 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003080 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003081 }
3082 mb_c = c;
3083 if (enc_utf8 && utf_char2len(c) > 1)
3084 {
3085 mb_utf8 = TRUE;
3086 u8cc[0] = 0;
3087 c = 0xc0;
3088 }
3089 else
3090 mb_utf8 = FALSE;
3091 }
3092 }
3093
3094 // Handling of non-printable characters.
3095 if (!vim_isprintc(c))
3096 {
3097 // when getting a character from the file, we may have to
3098 // turn it into something else on the way to putting it
3099 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01003100 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003101 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003102 int tab_len = 0;
3103 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003104#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003105 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01003106
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003107 // only adjust the tab_len, when at the first column
3108 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01003109 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003110 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003111#endif
3112 // tab amount depends on current column
3113#ifdef FEAT_VARTABS
3114 tab_len = tabstop_padding(vcol_adjusted,
3115 wp->w_buffer->b_p_ts,
3116 wp->w_buffer->b_p_vts_array) - 1;
3117#else
3118 tab_len = (int)wp->w_buffer->b_p_ts
3119 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
3120#endif
3121
3122#ifdef FEAT_LINEBREAK
3123 if (!wp->w_p_lbr || !wp->w_p_list)
3124#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003125 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003126 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01003127 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003128 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003129#ifdef FEAT_LINEBREAK
3130 else
3131 {
3132 char_u *p;
3133 int len;
3134 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003135 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003136
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003137# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003138 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003139 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003140 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003141
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003142 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003143 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003144 && old_boguscols > 0
3145 && wlv.n_extra > tab_len)
3146 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003147# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003148 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003149 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003150 // If wlv.n_extra > 0, it gives the number of chars
3151 // to use for a tab, else we need to calculate the
3152 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003153 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3154 len = tab_len * tab2_len;
3155 if (wp->w_lcs_chars.tab3)
3156 len += mb_char2len(wp->w_lcs_chars.tab3)
3157 - tab2_len;
3158 if (wlv.n_extra > 0)
3159 len += wlv.n_extra - tab_len;
3160 c = wp->w_lcs_chars.tab1;
3161 p = alloc(len + 1);
3162 if (p == NULL)
3163 wlv.n_extra = 0;
3164 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003165 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003166 vim_memset(p, ' ', len);
3167 p[len] = NUL;
3168 vim_free(wlv.p_extra_free);
3169 wlv.p_extra_free = p;
3170 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003171 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003172 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003173
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003174 if (*p == NUL)
3175 {
3176 tab_len = i;
3177 break;
3178 }
3179
3180 // if tab3 is given, use it for the last
3181 // char
3182 if (wp->w_lcs_chars.tab3
3183 && i == tab_len - 1)
3184 lcs = wp->w_lcs_chars.tab3;
3185 p += mb_char2bytes(lcs, p);
3186 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003187 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003188 }
3189 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003190# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003191 // n_extra will be increased by
3192 // FIX_FOX_BOGUSCOLS macro below, so need to
3193 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003194 if (wlv.vcol_off_co > 0)
3195 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003196# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003197 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003198 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003199 }
3200#endif
3201#ifdef FEAT_CONCEAL
3202 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003203 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003204
3205 // Tab alignment should be identical regardless of
3206 // 'conceallevel' value. So tab compensates of all
3207 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003208 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003209 // line. Note that the tab can be longer than
3210 // 'tabstop' when there are concealed characters.
3211 FIX_FOR_BOGUSCOLS;
3212
3213 // Make sure, the highlighting for the tab char will be
3214 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003215 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003216 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003217 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003218 tab_len += vc_saved;
3219 }
3220#endif
3221 mb_utf8 = FALSE; // don't draw as UTF-8
3222 if (wp->w_p_list)
3223 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003224 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003225 ? wp->w_lcs_chars.tab3
3226 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003227#ifdef FEAT_LINEBREAK
h-east194555c2023-03-02 18:49:09 +00003228 if (wp->w_p_lbr && wlv.p_extra != NULL
3229 && *wlv.p_extra != NUL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003230 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003231 else
3232#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003233 wlv.c_extra = wp->w_lcs_chars.tab2;
3234 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003235 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003236 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003237 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003238 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003239 mb_c = c;
3240 if (enc_utf8 && utf_char2len(c) > 1)
3241 {
3242 mb_utf8 = TRUE;
3243 u8cc[0] = 0;
3244 c = 0xc0;
3245 }
3246 }
3247 else
3248 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003249 wlv.c_final = NUL;
3250 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003251 c = ' ';
3252 }
3253 }
3254 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003255 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003256 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003257 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3258 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003259 && VIsual_mode != Ctrl_V
3260 && (
3261# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003262 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003263# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003264 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003265 && !(noinvcur
3266 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003267 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003268 && lcs_eol_one > 0)
3269 {
3270 // Display a '$' after the line or highlight an extra
3271 // character if the line break is included.
3272#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3273 // For a diff line the highlighting continues after the
3274 // "$".
3275 if (
3276# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003277 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003278# ifdef LINE_ATTR
3279 &&
3280# endif
3281# endif
3282# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003283 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003284# endif
3285 )
3286#endif
3287 {
3288 // In virtualedit, visual selections may extend
3289 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003290 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003291 && wlv.tocol != MAXCOL
3292 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003293 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003294 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003295 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003296 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3297 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003298 else
3299 c = ' ';
3300 lcs_eol_one = -1;
3301 --ptr; // put it back at the NUL
3302 if (!attr_pri)
3303 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003304 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003305 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003306 n_attr = 1;
3307 }
3308 mb_c = c;
3309 if (enc_utf8 && utf_char2len(c) > 1)
3310 {
3311 mb_utf8 = TRUE;
3312 u8cc[0] = 0;
3313 c = 0xc0;
3314 }
3315 else
3316 mb_utf8 = FALSE; // don't draw as UTF-8
3317 }
3318 else if (c != NUL)
3319 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003320 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3321 if (wlv.n_extra == 0)
3322 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003323#ifdef FEAT_RIGHTLEFT
3324 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003325 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003326#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003327 wlv.c_extra = NUL;
3328 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003329#ifdef FEAT_LINEBREAK
3330 if (wp->w_p_lbr)
3331 {
3332 char_u *p;
3333
Bram Moolenaar1306b362022-08-06 15:59:06 +01003334 c = *wlv.p_extra;
3335 p = alloc(wlv.n_extra + 1);
3336 vim_memset(p, ' ', wlv.n_extra);
3337 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3338 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003339 vim_free(wlv.p_extra_free);
3340 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003341 }
3342 else
3343#endif
3344 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003345 wlv.n_extra = byte2cells(c) - 1;
3346 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003347 }
3348 if (!attr_pri)
3349 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003350 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003351 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003352 HL_ATTR(HLF_8));
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003353#ifdef FEAT_PROP_POPUP
3354 if (text_prop_type != NULL &&
3355 text_prop_flags & PT_FLAG_OVERRIDE)
3356 wlv.extra_attr = hl_combine_attr(text_prop_attr, wlv.extra_attr);
3357#endif
3358
Bram Moolenaar1306b362022-08-06 15:59:06 +01003359 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003360 }
3361 mb_utf8 = FALSE; // don't draw as UTF-8
3362 }
3363 else if (VIsual_active
3364 && (VIsual_mode == Ctrl_V
3365 || VIsual_mode == 'v')
3366 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003367 && wlv.tocol != MAXCOL
3368 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003369 && (
3370#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003371 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003372#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003373 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003374 {
3375 c = ' ';
3376 --ptr; // put it back at the NUL
3377 }
3378#if defined(LINE_ATTR)
3379 else if ((
3380# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003381 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003382# endif
3383# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003384 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003385# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003386 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003387 ) && (
3388# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003389 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003390# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003391 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003392# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003393 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003394# endif
3395 < wp->w_width)))
3396 {
3397 // Highlight until the right side of the window
3398 c = ' ';
3399 --ptr; // put it back at the NUL
3400
3401 // Remember we do the char for line highlighting.
3402 ++did_line_attr;
3403
3404 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003405 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003406 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003407 || (wp->w_p_list &&
3408 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003409 wlv.char_attr = wlv.line_attr;
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003410#ifdef FEAT_SIGNS
3411 // At end of line: if Sign is present with line highlight, reset char_attr
Christian Brabandte1eaae22023-08-19 22:36:12 +02003412 // but not when cursorline is active
3413 if (sign_present && wlv.sattr.sat_linehl > 0 && wlv.draw_state == WL_LINE
3414 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum))
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003415 wlv.char_attr = wlv.sattr.sat_linehl;
3416#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003417# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003418 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003419 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003420 wlv.diff_hlf = HLF_CHD;
3421 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003422 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003423 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003424 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3425 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003426 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003427 || (wlv.vcol >= left_curline_col
3428 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003429 wlv.char_attr = hl_combine_attr(
3430 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003431 }
3432 }
3433# endif
3434# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003435 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003436 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003437 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003438 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3439 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003440 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003441 if (!wlv.cul_screenline
3442 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003443 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003444 wlv.char_attr = hl_combine_attr(
3445 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003446 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003447 else if (wlv.line_attr)
3448 wlv.char_attr = hl_combine_attr(
3449 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003450 }
3451# endif
3452 }
3453#endif
3454 }
3455
3456#ifdef FEAT_CONCEAL
3457 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003458 && (wp != curwin || lnum != wp->w_cursor.lnum
3459 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003460 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3461 && !(lnum_in_visual_area
3462 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3463 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003464 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003465 if (((prev_syntax_id != syntax_seqnr
3466 && (syntax_flags & HL_CONCEAL) != 0)
3467 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003468 && (syn_get_sub_char() != NUL
3469 || (has_match_conc && match_conc)
3470 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003471 && wp->w_p_cole != 3)
3472 {
3473 // First time at this concealed item: display one
3474 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003475 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003476 c = match_conc;
3477 else if (syn_get_sub_char() != NUL)
3478 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003479 else if (wp->w_lcs_chars.conceal != NUL)
3480 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003481 else
3482 c = ' ';
3483
3484 prev_syntax_id = syntax_seqnr;
3485
Bram Moolenaar1306b362022-08-06 15:59:06 +01003486 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003487 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003488 wlv.vcol += wlv.n_extra;
3489 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003490 {
3491# ifdef FEAT_RIGHTLEFT
3492 if (wp->w_p_rl)
3493 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003494 wlv.col -= wlv.n_extra;
3495 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003496 }
3497 else
3498# endif
3499 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003500 wlv.boguscols += wlv.n_extra;
3501 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003502 }
3503 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003504 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003505 n_attr = 0;
3506 }
zeertzjqb557f482023-08-22 22:07:34 +02003507 else if (skip_cells == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003508 {
3509 is_concealing = TRUE;
zeertzjqb557f482023-08-22 22:07:34 +02003510 skip_cells = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003511 }
3512 mb_c = c;
3513 if (enc_utf8 && utf_char2len(c) > 1)
3514 {
3515 mb_utf8 = TRUE;
3516 u8cc[0] = 0;
3517 c = 0xc0;
3518 }
3519 else
3520 mb_utf8 = FALSE; // don't draw as UTF-8
3521 }
3522 else
3523 {
3524 prev_syntax_id = 0;
3525 is_concealing = FALSE;
3526 }
3527
zeertzjqb557f482023-08-22 22:07:34 +02003528 if (skip_cells > 0 && did_decrement_ptr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003529 // not showing the '>', put pointer back to avoid getting stuck
3530 ++ptr;
3531
3532#endif // FEAT_CONCEAL
3533 }
3534
3535#ifdef FEAT_CONCEAL
3536 // In the cursor line and we may be concealing characters: correct
3537 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003538 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003539 && wp == curwin && lnum == wp->w_cursor.lnum
3540 && conceal_cursor_line(wp)
zeertzjqb557f482023-08-22 22:07:34 +02003541 && (int)wp->w_virtcol <= wlv.vcol + skip_cells)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003542 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003543# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003544 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003545 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003546 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003547# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003548 wp->w_wcol = wlv.col - wlv.boguscols;
3549 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003550 did_wcol = TRUE;
3551 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003552# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003553 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003554# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003555 }
3556#endif
3557
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003558 // Use "wlv.extra_attr", but don't override visual selection
3559 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003560 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3561 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003562 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003563 && (!attr_pri
3564#ifdef FEAT_PROP_POPUP
3565 || (text_prop_flags & PT_FLAG_OVERRIDE)
3566#endif
3567 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003568 {
3569#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003570 if (wlv.line_attr)
3571 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003572 else
3573#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003574 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003575#ifdef FEAT_PROP_POPUP
3576 if (reset_extra_attr)
3577 {
3578 reset_extra_attr = FALSE;
3579 wlv.extra_attr = 0;
3580 }
3581#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003582 }
3583
3584#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3585 // XIM don't send preedit_start and preedit_end, but they send
3586 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3587 // im_is_preediting() here.
3588 if (p_imst == IM_ON_THE_SPOT
3589 && xic != NULL
3590 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003591 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003592 && !p_imdisable
3593 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003594 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003595 {
3596 colnr_T tcol;
3597
3598 if (preedit_end_col == MAXCOL)
3599 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3600 else
3601 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003602 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003603 {
3604 if (feedback_old_attr < 0)
3605 {
3606 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003607 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003608 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003609 wlv.char_attr = im_get_feedback_attr(feedback_col);
3610 if (wlv.char_attr < 0)
3611 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003612 feedback_col++;
3613 }
3614 else if (feedback_old_attr >= 0)
3615 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003616 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003617 feedback_old_attr = -1;
3618 feedback_col = 0;
3619 }
3620 }
3621#endif
3622 // Handle the case where we are in column 0 but not on the first
3623 // character of the line and the user wants us to show us a
3624 // special character (via 'listchars' option "precedes:<char>".
3625 if (lcs_prec_todo != NUL
3626 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003627 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3628 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003629#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003630 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003631#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003632 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003633 && c != NUL)
3634 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003635 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003636 lcs_prec_todo = NUL;
3637 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3638 {
3639 // Double-width character being overwritten by the "precedes"
3640 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003641 wlv.c_extra = MB_FILLER_CHAR;
3642 wlv.c_final = NUL;
3643 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003644 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003645 wlv.extra_attr =
3646 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003647 }
3648 mb_c = c;
3649 if (enc_utf8 && utf_char2len(c) > 1)
3650 {
3651 mb_utf8 = TRUE;
3652 u8cc[0] = 0;
3653 c = 0xc0;
3654 }
3655 else
3656 mb_utf8 = FALSE; // don't draw as UTF-8
3657 if (!attr_pri)
3658 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003659 saved_attr3 = wlv.char_attr; // save current attr
3660 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003661 n_attr3 = 1;
3662 }
3663 }
3664
3665 // At end of the text line or just after the last character.
3666 if ((c == NUL
3667#if defined(LINE_ATTR)
3668 || did_line_attr == 1
3669#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003670 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003671 {
3672#ifdef FEAT_SEARCH_EXTRA
3673 // flag to indicate whether prevcol equals startcol of search_hl or
3674 // one of the matches
3675 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3676 (long)(ptr - line) - (c == NUL));
3677#endif
3678 // Invert at least one char, used for Visual and empty line or
3679 // highlight match at end of line. If it's beyond the last
3680 // char on the screen, just overwrite that one (tricky!) Not
3681 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003682 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003683 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003684 && (VIsual_mode != Ctrl_V
3685 || lnum == VIsual.lnum
3686 || lnum == curwin->w_cursor.lnum)
3687 && c == NUL)
3688#ifdef FEAT_SEARCH_EXTRA
3689 // highlight 'hlsearch' match at end of line
3690 || (prevcol_hl_flag
3691# ifdef FEAT_SYN_HL
3692 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3693 && !(wp == curwin && VIsual_active))
3694# endif
3695# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003696 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003697# endif
3698# if defined(LINE_ATTR)
3699 && did_line_attr <= 1
3700# endif
3701 )
3702#endif
3703 ))
3704 {
3705 int n = 0;
3706
3707#ifdef FEAT_RIGHTLEFT
3708 if (wp->w_p_rl)
3709 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003710 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003711 n = 1;
3712 }
3713 else
3714#endif
3715 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003716 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003717 n = -1;
3718 }
3719 if (n != 0)
3720 {
3721 // At the window boundary, highlight the last character
3722 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003723 wlv.off += n;
3724 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003725 }
3726 else
3727 {
3728 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003729 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003730 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003731 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003732 }
3733#ifdef FEAT_SEARCH_EXTRA
3734 if (area_attr == 0)
3735 {
3736 // Use attributes from match with highest priority among
3737 // 'search_hl' and the match list.
3738 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003739 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003740 }
3741#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003742 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003743 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003744#ifdef FEAT_RIGHTLEFT
3745 if (wp->w_p_rl)
3746 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003747 --wlv.col;
3748 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003749 }
3750 else
3751#endif
3752 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003753 ++wlv.col;
3754 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003755 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003756 ++wlv.vcol;
3757 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003758 }
3759 }
3760
3761 // At end of the text line.
3762 if (c == NUL)
3763 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003764#ifdef FEAT_PROP_POPUP
3765 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003766 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003767 // Put the pointer back to the NUL.
3768 --ptr;
3769 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003770 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003771 else
3772#endif
3773 {
3774 draw_screen_line(wp, &wlv);
3775
3776 // Update w_cline_height and w_cline_folded if the cursor line
3777 // was updated (saves a call to plines() later).
3778 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3779 {
3780 curwin->w_cline_row = startrow;
3781 curwin->w_cline_height = wlv.row - startrow;
3782#ifdef FEAT_FOLDING
3783 curwin->w_cline_folded = FALSE;
3784#endif
3785 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3786 }
3787 break;
3788 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003789 }
3790
3791 // Show "extends" character from 'listchars' if beyond the line end and
3792 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003793 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003794 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003795 && wp->w_p_list
3796 && !wp->w_p_wrap
3797#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003798 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003799#endif
3800 && (
3801#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003802 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003803#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003804 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003805 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003806 || lcs_eol_one > 0
3807 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
zeertzjq6a389722023-08-27 19:04:14 +02003808 || *wlv.p_extra != NUL))
3809#ifdef FEAT_PROP_POPUP
zeertzjq4e26a9a2023-12-03 17:50:47 +01003810 || text_prop_next <= last_textprop_text_idx
zeertzjq6a389722023-08-27 19:04:14 +02003811#endif
3812 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003813 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003814 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003815 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003816 mb_c = c;
3817 if (enc_utf8 && utf_char2len(c) > 1)
3818 {
3819 mb_utf8 = TRUE;
3820 u8cc[0] = 0;
3821 c = 0xc0;
3822 }
3823 else
3824 mb_utf8 = FALSE;
3825 }
3826
3827#ifdef FEAT_SYN_HL
3828 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003829 if (wlv.draw_color_col)
3830 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003831
3832 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3833 // highlight the cursor position itself.
3834 // Also highlight the 'colorcolumn' if it is different than
3835 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003836 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3837 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003838 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003839 if (((wlv.draw_state == WL_LINE
3840 || wlv.draw_state == WL_BRI
3841 || wlv.draw_state == WL_SBR)
3842 && !lnum_in_visual_area
3843 && search_attr == 0
3844 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003845# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003846 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003847# endif
3848 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003849 {
3850 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3851 && lnum != wp->w_cursor.lnum)
3852 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003853 vcol_save_attr = wlv.char_attr;
3854 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3855 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003856 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003857 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003858 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003859 vcol_save_attr = wlv.char_attr;
3860 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003861 }
3862 }
3863#endif
3864
zeertzjq8fc6a1d2023-08-20 18:12:54 +02003865 if (wlv.draw_state == WL_LINE)
3866 vcol_prev = wlv.vcol;
3867
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003868 // Store character to be displayed.
3869 // Skip characters that are left of the screen for 'nowrap'.
zeertzjqb557f482023-08-22 22:07:34 +02003870 if (wlv.draw_state < WL_LINE || skip_cells <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003871 {
3872 // Store the character.
3873#if defined(FEAT_RIGHTLEFT)
3874 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3875 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003876 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003877 --wlv.off;
3878 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003879 }
3880#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003881 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003882 if (enc_dbcs == DBCS_JPNU)
3883 {
3884 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003885 ScreenLines[wlv.off] = 0x8e;
3886 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003887 }
3888 else if (enc_utf8)
3889 {
3890 if (mb_utf8)
3891 {
3892 int i;
3893
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003894 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003895 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003896 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003897 for (i = 0; i < Screen_mco; ++i)
3898 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003899 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003900 if (u8cc[i] == 0)
3901 break;
3902 }
3903 }
3904 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003905 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003906 }
3907 if (multi_attr)
3908 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003909 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003910 multi_attr = 0;
3911 }
3912 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003913 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003914
zeertzjqdb54e982023-09-21 16:33:09 +02003915 if (wlv.draw_state > WL_NR
3916#ifdef FEAT_DIFF
3917 && wlv.filler_todo <= 0
3918#endif
3919 )
3920 ScreenCols[wlv.off] = wlv.vcol;
3921 else
3922 ScreenCols[wlv.off] = -1;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003923
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003924 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3925 {
3926 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003927 ++wlv.off;
3928 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003929 if (enc_utf8)
3930 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003931 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003932 else
3933 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003934 ScreenLines[wlv.off] = mb_c & 0xff;
zeertzjqdb54e982023-09-21 16:33:09 +02003935
Bram Moolenaar1306b362022-08-06 15:59:06 +01003936 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003937#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003938 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003939#endif
3940 )
zeertzjqdb54e982023-09-21 16:33:09 +02003941 ScreenCols[wlv.off] = ++wlv.vcol;
3942 else
3943 ScreenCols[wlv.off] = -1;
3944
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003945 // When "wlv.tocol" is halfway a character, set it to the end
3946 // of the character, otherwise highlighting won't stop.
3947 if (wlv.tocol == wlv.vcol)
3948 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003949
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003950#ifdef FEAT_RIGHTLEFT
3951 if (wp->w_p_rl)
3952 {
3953 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003954 --wlv.off;
3955 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003956 }
3957#endif
3958 }
3959#ifdef FEAT_RIGHTLEFT
3960 if (wp->w_p_rl)
3961 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003962 --wlv.off;
3963 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003964 }
3965 else
3966#endif
3967 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003968 ++wlv.off;
3969 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003970 }
3971 }
3972#ifdef FEAT_CONCEAL
3973 else if (wp->w_p_cole > 0 && is_concealing)
3974 {
zeertzjqb557f482023-08-22 22:07:34 +02003975 --skip_cells;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003976 ++wlv.vcol_off_co;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003977 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003978 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003979 if (wp->w_p_wrap)
3980 {
3981 // Special voodoo required if 'wrap' is on.
3982 //
3983 // Advance the column indicator to force the line
3984 // drawing to wrap early. This will make the line
3985 // take up the same screen space when parts are concealed,
3986 // so that cursor line computations aren't messed up.
3987 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003988 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003989 // trailing junk to be written out of the screen line
3990 // we are building, 'boguscols' keeps track of the number
3991 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003992 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003993 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003994 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003995# ifdef FEAT_RIGHTLEFT
3996 if (wp->w_p_rl)
3997 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003998 wlv.col -= wlv.n_extra;
3999 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004000 }
4001 else
4002# endif
4003 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004004 wlv.col += wlv.n_extra;
4005 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004006 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01004007 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004008 n_attr = 0;
4009 }
4010
4011
4012 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
4013 {
4014 // Need to fill two screen columns.
4015# ifdef FEAT_RIGHTLEFT
4016 if (wp->w_p_rl)
4017 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004018 --wlv.boguscols;
4019 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004020 }
4021 else
4022# endif
4023 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004024 ++wlv.boguscols;
4025 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004026 }
4027 }
4028
4029# ifdef FEAT_RIGHTLEFT
4030 if (wp->w_p_rl)
4031 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004032 --wlv.boguscols;
4033 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004034 }
4035 else
4036# endif
4037 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004038 ++wlv.boguscols;
4039 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004040 }
4041 }
4042 else
4043 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004044 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004045 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004046 wlv.vcol += wlv.n_extra;
4047 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004048 n_attr = 0;
4049 }
4050 }
4051
4052 }
4053#endif // FEAT_CONCEAL
4054 else
zeertzjqb557f482023-08-22 22:07:34 +02004055 --skip_cells;
4056
4057 if (wlv.draw_state > WL_NR && skipped_cells > 0)
4058 {
4059 wlv.vcol += skipped_cells;
4060 skipped_cells = 0;
4061 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004062
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004063 // Only advance the "wlv.vcol" when after the 'number' or
4064 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004065 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004066#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004067 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004068#endif
4069 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004070 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004071
4072#ifdef FEAT_SYN_HL
4073 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004074 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004075#endif
4076
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004077 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01004078 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
4079 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004080
4081 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01004082 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004083 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004084 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004085 if (wlv.n_attr_skip > 0)
4086 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004087
4088 // At end of screen line and there is more to come: Display the line
4089 // so far. If there is no more to display it is caught above.
4090 if ((
4091#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004092 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004093#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004094 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01004095 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02004096 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004097#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004098 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004099#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004100#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004101 || text_prop_above || text_prop_follows
zeertzjq4e26a9a2023-12-03 17:50:47 +01004102 || text_prop_next <= last_textprop_text_idx
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004103#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01004104 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01004105 && wlv.p_extra != at_end_str)
4106 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
4107 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004108 )
4109 {
4110#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01004111 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01004112 wlv_screen_line(wp, &wlv, FALSE);
4113 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004114 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004115 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004116#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01004117 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004118#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004119 ++wlv.row;
4120 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004121
4122 // When not wrapping and finished diff lines, or when displayed
4123 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01004124 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004125#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004126 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004127#endif
4128#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01004129 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004130#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01004131 ) || lcs_eol_one == -1)
4132#ifdef FEAT_PROP_POPUP
4133 && !text_prop_follows
4134#endif
4135 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004136 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004137#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004138 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004139 {
4140 // do not output more of the line, only the "below" prop
4141 ptr += STRLEN(ptr);
4142# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004143 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004144# endif
4145 }
4146#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004147
4148 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004149 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004150#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004151 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004152#endif
4153 )
4154 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004155 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
4156 draw_vsep_win(wp, wlv.row);
4157 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004158 }
4159
4160 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004161 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004162 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004163 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004164 break;
4165 }
4166
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004167 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004168#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004169 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004170#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004171#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004172 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004173#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004174 && wp->w_width == Columns)
4175 {
4176 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004177 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004178
4179 // Special trick to make copy/paste of wrapped lines work with
4180 // xterm/screen: write an extra character beyond the end of
4181 // the line. This will work with all terminal types
4182 // (regardless of the xn,am settings).
4183 // Only do this on a fast tty.
4184 // Only do this if the cursor is on the current line
4185 // (something has been written in it).
4186 // Don't do this for the GUI.
4187 // Don't do this for double-width characters.
4188 // Don't do this for a window not at the right screen border.
4189 if (p_tf
4190#ifdef FEAT_GUI
4191 && !gui.in_use
4192#endif
4193 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004194 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4195 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004196 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004197 || (*mb_off2cells)(
4198 LineOffset[wlv.screen_row - 1]
4199 + (int)Columns - 2,
4200 LineOffset[wlv.screen_row]
4201 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004202 {
4203 // First make sure we are at the end of the screen line,
4204 // then output the same character again to let the
4205 // terminal know about the wrap. If the terminal doesn't
4206 // auto-wrap, we overwrite the character.
4207 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004208 screen_char(LineOffset[wlv.screen_row - 1]
4209 + (unsigned)Columns - 1,
4210 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004211
4212 // When there is a multi-byte character, just output a
4213 // space to keep it simple.
4214 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004215 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004216 out_char(' ');
4217 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004218 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004219 + (Columns - 1)]);
4220 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004221 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004222 screen_start(); // don't know where cursor is now
4223 }
4224 }
4225
Bram Moolenaar1306b362022-08-06 15:59:06 +01004226 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004227
Bram Moolenaareed9d462021-02-15 20:38:25 +01004228 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004229#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004230 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004231# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004232 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004233# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004234 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004235 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004236#endif
4237#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004238 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004239 // When the filler lines are actually below the last line of the
4240 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004241 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004242 break;
4243#endif
4244 }
4245
4246 } // for every character in the line
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004247#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004248 vim_free(text_props);
4249 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004250 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004251#endif
4252
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004253 vim_free(wlv.p_extra_free);
zeertzjq58e1e012023-06-04 18:46:28 +01004254 vim_free(wlv.saved_p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004255 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004256}