blob: 6909e0f1fdcaac6244d8a3ff759a3c967ab3f1ec [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
501 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
502# ifdef FEAT_DIFF
503 && wlv->filler_lines == 0
504# endif
505# ifdef FEAT_PROP_POPUP
506 && !wlv->dont_use_showbreak
507# endif
508 )
509 {
510 wlv->char_attr = 0;
511# ifdef FEAT_DIFF
512 if (wlv->diff_hlf != (hlf_T)0)
513 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
514# endif
515 wlv->p_extra = NULL;
516 wlv->c_extra = ' ';
517 wlv->c_final = NUL;
518 wlv->n_extra = get_breakindent_win(wp,
519 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
520 if (wlv->row == wlv->startrow)
521 {
522 wlv->n_extra -= win_col_off2(wp);
523 if (wlv->n_extra < 0)
524 wlv->n_extra = 0;
525 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100526 if (wp->w_skipcol > 0 && wlv->startrow == 0
527 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100528 wlv->need_showbreak = FALSE;
529 // Correct end of highlighted area for 'breakindent',
530 // required when 'linebreak' is also set.
531 if (wlv->tocol == wlv->vcol)
532 wlv->tocol += wlv->n_extra;
533 }
534 }
535}
536#endif
537
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100538#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
539 static void
540handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
541{
542# ifdef FEAT_DIFF
543 if (wlv->filler_todo > 0)
544 {
545 // Draw "deleted" diff line(s).
546 if (char2cells(wp->w_fill_chars.diff) > 1)
547 {
548 wlv->c_extra = '-';
549 wlv->c_final = NUL;
550 }
551 else
552 {
553 wlv->c_extra = wp->w_fill_chars.diff;
554 wlv->c_final = NUL;
555 }
556# ifdef FEAT_RIGHTLEFT
557 if (wp->w_p_rl)
558 wlv->n_extra = wlv->col + 1;
559 else
560# endif
561 wlv->n_extra = wp->w_width - wlv->col;
562 wlv->char_attr = HL_ATTR(HLF_DED);
563 }
564# endif
565
566# ifdef FEAT_LINEBREAK
567 char_u *sbr = get_showbreak_value(wp);
568 if (*sbr != NUL && wlv->need_showbreak)
569 {
570 // Draw 'showbreak' at the start of each broken line.
571 wlv->p_extra = sbr;
572 wlv->c_extra = NUL;
573 wlv->c_final = NUL;
574 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100575 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100576 wlv->need_showbreak = FALSE;
577 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100578
579 // Correct start of highlighted area for 'showbreak'.
580 if (wlv->fromcol >= wlv->vcol && wlv->fromcol < wlv->vcol_sbr)
581 wlv->fromcol = wlv->vcol_sbr;
582
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100583 // Correct end of highlighted area for 'showbreak',
584 // required when 'linebreak' is also set.
585 if (wlv->tocol == wlv->vcol)
586 wlv->tocol += wlv->n_extra;
587 // combine 'showbreak' with 'wincolor'
588 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
589# ifdef FEAT_SYN_HL
590 // combine 'showbreak' with 'cursorline'
591 if (wlv->cul_attr != 0)
592 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
593# endif
594 }
595# endif
596}
597#endif
598
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100599#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100600/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100601 * Return the cell size of virtual text after truncation.
602 */
603 static int
604textprop_size_after_trunc(
605 win_T *wp,
606 int flags, // TP_FLAG_ALIGN_*
607 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100608 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100609 char_u *text,
610 int *n_used_ptr)
611{
612 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100613 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100614 int len = (int)STRLEN(text);
615 int strsize = 0;
616 int n_used;
617
Bram Moolenaar7e017462022-10-11 21:02:09 +0100618 // if the remaining size is to small and 'wrap' is set we wrap anyway and
619 // use the next line
620 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100621 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100622 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100623 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100624 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
625 {
626 int clen = ptr2cells(text + n_used);
627
628 if (strsize + clen > space)
629 break;
630 strsize += clen;
631 }
632 *n_used_ptr = n_used;
633 return strsize;
634}
635
636/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100637 * Take care of padding, right-align and truncation of virtual text after a
638 * line.
639 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
640 * padding, right-align and truncation. Otherwise only the size is computed.
641 * When "n_attr" is NULL returns the number of screen cells used.
642 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100643 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100644 int
645text_prop_position(
646 win_T *wp,
647 textprop_T *tp,
porygonisaduck38854b52022-11-27 20:55:05 +0000648 int vcol, // current text column
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100649 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100650 int *n_extra, // nr of bytes for virtual text
651 char_u **p_extra, // virtual text
652 int *n_attr, // attribute cells, NULL if not used
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000653 int *n_attr_skip, // cells to skip attr, NULL if not used
654 int do_skip) // skip_cells is not zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200655{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100656 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100657 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100658 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
Bram Moolenaar1aeb3eb2023-01-01 14:04:51 +0000659 int wrap = tp->tp_col < MAXCOL || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100660 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
porygonisaduck38854b52022-11-27 20:55:05 +0000661 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100662 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100663 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100664 int before = room; // spaces before the text
665 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100666 int n_used = *n_extra;
667 char_u *l = NULL;
668 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100669 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100670 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200671
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100672 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100673 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100674 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100675
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100676 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100677 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100678 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100679 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar2354b662023-04-23 21:42:25 +0100680 if (after < 0)
681 {
682 // text "above" has too much padding to fit
683 padding += after;
684 after = 0;
685 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100686 }
687 else
688 {
689 // Right-align: fill with before
690 if (right)
691 before -= cells;
porygonisaduck38854b52022-11-27 20:55:05 +0000692
693 // Below-align: empty line add one character
Bram Moolenaar7c02ad92022-11-29 21:37:13 +0000694 if (below && vcol == 0 && col_with_padding == col_off
695 && wp->w_width - col_off == before)
696 col_with_padding += 1;
porygonisaduck38854b52022-11-27 20:55:05 +0000697
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100698 if (before < 0
699 || !(right || below)
porygonisaduck38854b52022-11-27 20:55:05 +0000700 || (below ? (col_with_padding <= col_off || !wp->w_p_wrap)
701 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100702 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100703 if (right && (wrap
704 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100705 {
706 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100707 before = wp->w_width - col_off - strsize + room;
708 if (before < 0)
709 before = 0;
710 else
711 n_used = *n_extra;
712 }
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000713 else if (below && before > vcol && do_skip)
714 before -= vcol;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100715 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100716 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100717 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100718 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100719
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100720 // With 'nowrap' add one to show the "extends" character if needed (it
721 // doesn't show if the text just fits).
722 if (!wp->w_p_wrap
723 && n_used < *n_extra
724 && wp->w_lcs_chars.ext != NUL
725 && wp->w_p_list)
726 ++n_used;
727
728 // add 1 for NUL, 2 for when '…' is used
729 if (n_attr != NULL)
Christian Brabandtf1cc4d52023-08-12 00:14:14 +0200730 l = alloc(n_used + before + after + (padding > 0 ? padding : 0) + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100731 if (n_attr == NULL || l != NULL)
732 {
733 int off = 0;
734
735 if (n_attr != NULL)
736 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100737 vim_memset(l, ' ', before);
738 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100739 if (padding > 0)
740 {
741 vim_memset(l + off, ' ', padding);
742 off += padding;
743 }
744 vim_strncpy(l + off, *p_extra, n_used);
745 off += n_used;
746 }
747 else
748 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100749 off = before + after + padding + n_used;
750 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100751 }
752 if (n_attr != NULL)
753 {
754 if (n_used < *n_extra && wp->w_p_wrap)
755 {
756 char_u *lp = l + off - 1;
757
758 if (has_mbyte)
759 {
h-east4c42c7e2023-04-17 21:44:57 +0100760 char_u buf[MB_MAXBYTES + 1];
761 char_u *cp = buf;
762
763 // change the last character to '…', converted to the
764 // current 'encoding'
765 STRCPY(buf, "…");
766 if (!enc_utf8)
767 {
768 vimconv_T vc;
769
770 vc.vc_type = CONV_NONE;
771 convert_setup(&vc, (char_u *)"utf-8", p_enc);
772 if (vc.vc_type != CONV_NONE)
773 {
774 cp = string_convert(&vc, buf, NULL);
775 if (cp == NULL)
776 {
777 // when conversion fails use '>'
778 cp = buf;
779 STRCPY(buf, ">");
780 }
781 convert_setup(&vc, NULL, NULL);
782 }
783 }
784
785 lp -= (*mb_ptr2cells)(cp) - 1;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100786 lp -= (*mb_head_off)(l, lp);
h-east4c42c7e2023-04-17 21:44:57 +0100787 STRCPY(lp, cp);
Bram Moolenaar13845c42022-10-09 15:26:03 +0100788 n_used = lp - l + 3 - before - padding;
h-east4c42c7e2023-04-17 21:44:57 +0100789 if (cp != buf)
790 vim_free(cp);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100791 }
792 else
793 // change last character to '>'
794 *lp = '>';
795 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100796 else if (after > 0)
797 {
798 vim_memset(l + off, ' ', after);
799 l[off + after] = NUL;
800 }
801
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100802 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100803 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100804 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100805 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100806 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100807
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000808 // n_attr_skip will not be decremented before draw_state is
809 // WL_LINE
Christian Brabandtf1cc4d52023-08-12 00:14:14 +0200810 *n_attr_skip = before + (padding > 0 ? padding : 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100811 }
812 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100813 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100814
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100815 if (n_attr == NULL)
816 return cells;
817 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200818}
819#endif
820
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100821/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100822 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100823 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
824 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100825 */
826 static void
827wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
828{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100829 if (wlv->row == 0 && wp->w_skipcol > 0
830#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100831 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100832 && *get_showbreak_value(wp) == NUL
833#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100834 // do not overwrite the 'listchars' "precedes" text with "<<<"
835 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100836 {
837 int off = (int)(current_ScreenLine - ScreenLines);
zeertzjqecb87dd2023-06-03 19:45:06 +0100838 int max_off = off + screen_Columns;
Bram Moolenaareb4de622022-10-15 13:42:17 +0100839 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100840
Bram Moolenaareb4de622022-10-15 13:42:17 +0100841 if (wp->w_p_nu && wp->w_p_rnu)
842 // Do not overwrite the line number, change "123 text" to
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100843 // "123<<<xt".
Bram Moolenaareb4de622022-10-15 13:42:17 +0100844 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
845 {
846 ++off;
847 ++skip;
848 }
849
850 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100851 {
zeertzjqecb87dd2023-06-03 19:45:06 +0100852 if ((*mb_off2cells)(off, max_off) > 1)
853 // When the first half of a double-width character is
854 // overwritten, change the second half to a space.
855 ScreenLines[off + 1] = ' ';
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100856 ScreenLines[off] = '<';
857 if (enc_utf8)
858 ScreenLinesUC[off] = 0;
859 ScreenAttrs[off] = HL_ATTR(HLF_AT);
860 ++off;
861 }
862 }
863
864 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
865 negative_width ? -wp->w_width : wp->w_width,
866 wlv->screen_line_flags);
867}
868
869/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100870 * Called when finished with the line: draw the screen line and handle any
871 * highlighting until the right of the window.
872 */
873 static void
874draw_screen_line(win_T *wp, winlinevars_T *wlv)
875{
876#ifdef FEAT_SYN_HL
877 long v;
878
879 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
880 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100881 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100882 else
883 v = wp->w_leftcol;
884
885 // check if line ends before left margin
886 if (wlv->vcol < v + wlv->col - win_col_off(wp))
887 wlv->vcol = v + wlv->col - win_col_off(wp);
888# ifdef FEAT_CONCEAL
889 // Get rid of the boguscols now, we want to draw until the right
890 // edge for 'cursorcolumn'.
891 wlv->col -= wlv->boguscols;
892 wlv->boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000893# define VCOL_HLC (wlv->vcol - wlv->vcol_off_co - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100894# else
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000895# define VCOL_HLC (wlv->vcol - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100896# endif
897
898 if (wlv->draw_color_col)
899 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
900
901 if (((wp->w_p_cuc
902 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
903 && (int)wp->w_virtcol <
904 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
905 && wlv->lnum != wp->w_cursor.lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000906 || wlv->draw_color_col
907# ifdef LINE_ATTR
908 || wlv->line_attr != 0
909# endif
910 || wlv->win_attr != 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100911# ifdef FEAT_RIGHTLEFT
912 && !wp->w_p_rl
913# endif
914 )
915 {
916 int rightmost_vcol = 0;
917 int i;
918
919 if (wp->w_p_cuc)
920 rightmost_vcol = wp->w_virtcol;
921 if (wlv->draw_color_col)
922 // determine rightmost colorcolumn to possibly draw
923 for (i = 0; wlv->color_cols[i] >= 0; ++i)
924 if (rightmost_vcol < wlv->color_cols[i])
925 rightmost_vcol = wlv->color_cols[i];
926
927 while (wlv->col < wp->w_width)
928 {
929 ScreenLines[wlv->off] = ' ';
930 if (enc_utf8)
931 ScreenLinesUC[wlv->off] = 0;
932 ScreenCols[wlv->off] = MAXCOL;
933 ++wlv->col;
934 if (wlv->draw_color_col)
935 wlv->draw_color_col = advance_color_col(
936 VCOL_HLC, &wlv->color_cols);
937
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000938 int attr = wlv->win_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100939 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000940 attr = HL_ATTR(HLF_CUC);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100941 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000942 attr = HL_ATTR(HLF_MC);
943# ifdef LINE_ATTR
944 else if (wlv->line_attr != 0)
945 attr = wlv->line_attr;
946# endif
947 ScreenAttrs[wlv->off++] = attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100948
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000949 if (VCOL_HLC >= rightmost_vcol
950# ifdef LINE_ATTR
951 && wlv->line_attr == 0
952# endif
953 && wlv->win_attr == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100954 break;
955
956 ++wlv->vcol;
957 }
958 }
959#endif
960
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100961 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100962 ++wlv->row;
963 ++wlv->screen_row;
964}
965#undef VCOL_HLC
966
967/*
968 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100969 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100970 */
971 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100972win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100973{
974 wlv->col = 0;
975 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
Christian Brabandtdd75fcf2023-10-11 21:51:19 +0200976#ifdef FEAT_LINEBREAK
977 wlv->need_lbr = FALSE;
978#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100979
980#ifdef FEAT_RIGHTLEFT
981 if (wp->w_p_rl)
982 {
983 // Rightleft window: process the text in the normal direction, but put
984 // it in current_ScreenLine[] from right to left. Start at the
985 // rightmost column of the window.
986 wlv->col = wp->w_width - 1;
987 wlv->off += wlv->col;
988 wlv->screen_line_flags |= SLF_RIGHTLEFT;
989 }
990#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100991 if (save_extra)
992 {
993 // reset the drawing state for the start of a wrapped line
994 wlv->draw_state = WL_START;
995 wlv->saved_n_extra = wlv->n_extra;
996 wlv->saved_p_extra = wlv->p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +0100997 vim_free(wlv->saved_p_extra_free);
998 wlv->saved_p_extra_free = wlv->p_extra_free;
999 wlv->p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001000 wlv->saved_extra_attr = wlv->extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001001 wlv->saved_n_attr_skip = wlv->n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001002 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001003 wlv->saved_c_extra = wlv->c_extra;
1004 wlv->saved_c_final = wlv->c_final;
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02001005#ifdef FEAT_LINEBREAK
1006 wlv->need_lbr = TRUE;
1007#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001008#ifdef FEAT_SYN_HL
1009 if (!(wlv->cul_screenline
1010# ifdef FEAT_DIFF
1011 && wlv->diff_hlf == (hlf_T)0
1012# endif
1013 ))
1014 wlv->saved_char_attr = wlv->char_attr;
1015 else
1016#endif
1017 wlv->saved_char_attr = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001018
1019 // these are not used until restored in win_line_continue()
Bram Moolenaar1306b362022-08-06 15:59:06 +01001020 wlv->n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001021 wlv->n_attr_skip = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001022 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001023}
1024
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001025/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001026 * Called when wlv->draw_state is set to WL_LINE.
1027 */
1028 static void
1029win_line_continue(winlinevars_T *wlv)
1030{
1031 if (wlv->saved_n_extra > 0)
1032 {
1033 // Continue item from end of wrapped line.
1034 wlv->n_extra = wlv->saved_n_extra;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001035 wlv->saved_n_extra = 0;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001036 wlv->c_extra = wlv->saved_c_extra;
1037 wlv->c_final = wlv->saved_c_final;
1038 wlv->p_extra = wlv->saved_p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +01001039 vim_free(wlv->p_extra_free);
1040 wlv->p_extra_free = wlv->saved_p_extra_free;
1041 wlv->saved_p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001042 wlv->extra_attr = wlv->saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001043 wlv->n_attr_skip = wlv->saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001044 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001045 wlv->char_attr = wlv->saved_char_attr;
1046 }
1047 else
1048 wlv->char_attr = wlv->win_attr;
1049}
1050
zeertzjqb7acea12022-12-12 13:20:43 +00001051#ifdef FEAT_SYN_HL
1052 static void
1053apply_cursorline_highlight(
1054 winlinevars_T *wlv,
1055 int sign_present UNUSED)
1056{
1057 wlv->cul_attr = HL_ATTR(HLF_CUL);
1058# ifdef FEAT_SIGNS
1059 // Combine the 'cursorline' and sign highlighting, depending on
1060 // the sign priority.
1061 if (sign_present && wlv->sattr.sat_linehl > 0)
1062 {
1063 if (wlv->sattr.sat_priority >= 100)
1064 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1065 else
1066 wlv->line_attr = hl_combine_attr(wlv->line_attr, wlv->cul_attr);
1067 }
1068 else
1069# endif
1070# if defined(FEAT_QUICKFIX)
1071 // let the line attribute overrule 'cursorline', otherwise
1072 // it disappears when both have background set;
1073 // 'cursorline' can use underline or bold to make it show
1074 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1075# else
1076 wlv->line_attr = wlv->cul_attr;
1077# endif
1078}
1079#endif
1080
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001081/*
Luuk van Baal30805a12023-05-27 22:22:10 +01001082 * Display line "lnum" of window "wp" on the screen.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001083 * Start at row "startrow", stop when "endrow" is reached.
Luuk van Baal30805a12023-05-27 22:22:10 +01001084 * When "number_only" is TRUE only update the number column.
1085 * "spv" is used to store information for spell checking, kept between
1086 * sequential calls for the same window.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001087 * wp->w_virtcol needs to be valid.
1088 *
1089 * Return the number of last row the line occupies.
1090 */
1091 int
1092win_line(
1093 win_T *wp,
1094 linenr_T lnum,
1095 int startrow,
1096 int endrow,
Luuk van Baal30805a12023-05-27 22:22:10 +01001097 int number_only,
1098 spellvars_T *spv UNUSED)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001099{
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001100 winlinevars_T wlv; // variables passed between functions
1101
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001102 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001103 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001104 char_u *line; // current line
1105 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001106
Bram Moolenaar1306b362022-08-06 15:59:06 +01001107#ifdef FEAT_PROP_POPUP
1108 char_u *p_extra_free2 = NULL; // another p_extra to be freed
1109#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001110#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001111 int in_linebreak = FALSE; // n_extra set for showing linebreak
1112#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001113 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +01001114 // displaying eol at end-of-line
1115 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001116 int lcs_prec_todo = wp->w_lcs_chars.prec;
1117 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001118
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001119 int n_attr = 0; // chars with special attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001120 int saved_attr2 = 0; // char_attr saved for n_attr
1121 int n_attr3 = 0; // chars with overruling special attr
1122 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001123
zeertzjqb557f482023-08-22 22:07:34 +02001124 int skip_cells = 0; // nr of cells to skip for w_leftcol or
1125 // w_skipcol or concealing
1126 int skipped_cells = 0; // nr of skipped cells for virtual text
1127 // to be added to wlv.vcol later
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001128 int fromcol_prev = -2; // start of inverting after cursor
1129 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001130 int lnum_in_visual_area = FALSE;
1131 pos_T pos;
1132 long v;
1133
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001134 int attr_pri = FALSE; // char_attr has priority
1135 int area_highlighting = FALSE; // Visual or incsearch highlighting
1136 // in this line
1137 int vi_attr = 0; // attributes for Visual and incsearch
1138 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001139 int area_attr = 0; // attributes desired by highlighting
1140 int search_attr = 0; // attributes desired by 'hlsearch'
1141#ifdef FEAT_SYN_HL
1142 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1143 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001144 int prev_syntax_col = -1; // column of prev_syntax_attr
1145 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001146 int has_syntax = FALSE; // this buffer has syntax highl.
1147 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001148#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001149#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001150 int did_line = FALSE; // set to TRUE when line text done
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001151 int text_prop_count;
zeertzjq4e26a9a2023-12-03 17:50:47 +01001152 int last_textprop_text_idx = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001153 int text_prop_next = 0; // next text property to use
1154 textprop_T *text_props = NULL;
1155 int *text_prop_idxs = NULL;
1156 int text_props_active = 0;
1157 proptype_T *text_prop_type = NULL;
1158 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001159 int text_prop_attr_comb = 0; // text_prop_attr combined with
1160 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001161 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001162 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001163 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001164 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001165 int saved_search_attr = 0; // search_attr to be used when n_extra
1166 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001167 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001168 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001169#endif
1170#ifdef FEAT_SPELL
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001171 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001172# define SPWORDLEN 150
1173 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1174 int nextlinecol = 0; // column where nextline[] starts
1175 int nextline_idx = 0; // index in nextline[] where next line
1176 // starts
1177 int spell_attr = 0; // attributes desired by spelling
1178 int word_end = 0; // last byte with same spell_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001179 int cur_checked_col = 0; // checked column for current line
1180#endif
1181 int extra_check = 0; // has extra highlighting
1182 int multi_attr = 0; // attributes desired by multibyte
1183 int mb_l = 1; // multi-byte byte length
1184 int mb_c = 0; // decoded multi-byte character
1185 int mb_utf8 = FALSE; // screen char is UTF-8 char
1186 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001187#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001188 int change_start = MAXCOL; // first col of changed area
1189 int change_end = -1; // last col of changed area
1190#endif
1191 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001192 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001193 int in_multispace = FALSE; // in multiple consecutive spaces
1194 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001195#ifdef LINE_ATTR
Bram Moolenaarbf915842022-08-06 22:38:02 +01001196 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001197#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001198 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001199 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001200#ifdef FEAT_ARABIC
1201 int prev_c = 0; // previous Arabic character
1202 int prev_c1 = 0; // first composing char for prev_c
1203#endif
1204#if defined(LINE_ATTR)
1205 int did_line_attr = 0;
1206#endif
1207#ifdef FEAT_TERMINAL
1208 int get_term_attr = FALSE;
1209#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001210
Martin Tournoijba43e762022-10-13 22:12:15 +01001211#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001212 // margin columns for the screen line, needed for when 'cursorlineopt'
1213 // contains "screenline"
1214 int left_curline_col = 0;
1215 int right_curline_col = 0;
1216#endif
1217
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001218#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1219 int feedback_col = 0;
1220 int feedback_old_attr = -1;
1221#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001222
1223#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1224 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001225#endif
1226#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001227 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001228#endif
1229#ifdef FEAT_CONCEAL
1230 int syntax_flags = 0;
1231 int syntax_seqnr = 0;
1232 int prev_syntax_id = 0;
1233 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1234 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001235 int did_wcol = FALSE;
1236 int old_boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001237# define VCOL_HLC (wlv.vcol - wlv.vcol_off_co - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001238# define FIX_FOR_BOGUSCOLS \
1239 { \
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001240 wlv.n_extra += wlv.vcol_off_co; \
1241 wlv.vcol -= wlv.vcol_off_co; \
1242 wlv.vcol_off_co = 0; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001243 wlv.col -= wlv.boguscols; \
1244 old_boguscols = wlv.boguscols; \
1245 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001246 }
1247#else
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001248# define VCOL_HLC (wlv.vcol - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001249#endif
1250
1251 if (startrow > endrow) // past the end already!
1252 return startrow;
1253
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001254 CLEAR_FIELD(wlv);
1255
1256 wlv.lnum = lnum;
1257 wlv.startrow = startrow;
1258 wlv.row = startrow;
1259 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001260 wlv.fromcol = -10;
1261 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001262#ifdef FEAT_LINEBREAK
1263 wlv.vcol_sbr = -1;
1264#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001265
1266 if (!number_only)
1267 {
1268 // To speed up the loop below, set extra_check when there is linebreak,
1269 // trailing white space and/or syntax processing to be done.
1270#ifdef FEAT_LINEBREAK
1271 extra_check = wp->w_p_lbr;
1272#endif
1273#ifdef FEAT_SYN_HL
1274 if (syntax_present(wp) && !wp->w_s->b_syn_error
1275# ifdef SYN_TIME_LIMIT
1276 && !wp->w_s->b_syn_slow
1277# endif
1278 )
1279 {
1280 // Prepare for syntax highlighting in this line. When there is an
1281 // error, stop syntax highlighting.
1282 save_did_emsg = did_emsg;
1283 did_emsg = FALSE;
1284 syntax_start(wp, lnum);
1285 if (did_emsg)
1286 wp->w_s->b_syn_error = TRUE;
1287 else
1288 {
1289 did_emsg = save_did_emsg;
1290#ifdef SYN_TIME_LIMIT
1291 if (!wp->w_s->b_syn_slow)
1292#endif
1293 {
1294 has_syntax = TRUE;
1295 extra_check = TRUE;
1296 }
1297 }
1298 }
1299
1300 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001301 wlv.color_cols = wp->w_p_cc_cols;
1302 if (wlv.color_cols != NULL)
1303 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001304#endif
1305
1306#ifdef FEAT_TERMINAL
1307 if (term_show_buffer(wp->w_buffer))
1308 {
1309 extra_check = TRUE;
1310 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001311 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001312 }
1313#endif
1314
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001315 // handle Visual active in this window
1316 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1317 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001318 pos_T *top, *bot;
1319
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001320 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1321 {
1322 // Visual is after curwin->w_cursor
1323 top = &curwin->w_cursor;
1324 bot = &VIsual;
1325 }
1326 else
1327 {
1328 // Visual is before curwin->w_cursor
1329 top = &VIsual;
1330 bot = &curwin->w_cursor;
1331 }
1332 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1333 if (VIsual_mode == Ctrl_V)
1334 {
1335 // block mode
1336 if (lnum_in_visual_area)
1337 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001338 wlv.fromcol = wp->w_old_cursor_fcol;
1339 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001340 }
1341 }
1342 else
1343 {
1344 // non-block mode
1345 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001346 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001347 else if (lnum == top->lnum)
1348 {
1349 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001350 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001351 else
1352 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001353 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001354 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001355 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001356 }
1357 }
1358 if (VIsual_mode != 'V' && lnum == bot->lnum)
1359 {
1360 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1361 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001362 wlv.fromcol = -10;
1363 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001364 }
1365 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001366 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001367 else
1368 {
1369 pos = *bot;
1370 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001371 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1372 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001373 else
1374 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001375 getvvcol(wp, &pos, NULL, NULL,
1376 (colnr_T *)&wlv.tocol);
1377 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001378 }
1379 }
1380 }
1381 }
1382
1383 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001384 if (!highlight_match && lnum == curwin->w_cursor.lnum
1385 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001386#ifdef FEAT_GUI
1387 && !gui.in_use
1388#endif
1389 )
1390 noinvcur = TRUE;
1391
1392 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001393 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001394 {
1395 area_highlighting = TRUE;
1396 vi_attr = HL_ATTR(HLF_V);
1397#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1398 if ((clip_star.available && !clip_star.owned
1399 && clip_isautosel_star())
1400 || (clip_plus.available && !clip_plus.owned
1401 && clip_isautosel_plus()))
1402 vi_attr = HL_ATTR(HLF_VNC);
1403#endif
1404 }
1405 }
1406
1407 // handle 'incsearch' and ":s///c" highlighting
1408 else if (highlight_match
1409 && wp == curwin
1410 && lnum >= curwin->w_cursor.lnum
1411 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1412 {
1413 if (lnum == curwin->w_cursor.lnum)
1414 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001415 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001416 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001417 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001418 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1419 {
1420 pos.lnum = lnum;
1421 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001422 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001423 }
1424 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001425 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001426 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001427 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1428 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001429 area_highlighting = TRUE;
1430 vi_attr = HL_ATTR(HLF_I);
1431 }
1432 }
1433
1434#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001435 wlv.filler_lines = diff_check(wp, lnum);
1436 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001437 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001438 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001439 {
1440 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001441 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001442 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001443 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001444 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001445 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001446 }
1447 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001448 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001449 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001450 area_highlighting = TRUE;
1451 }
1452 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001453 wlv.filler_lines = wp->w_topfill;
1454 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001455#endif
1456
1457#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001458 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001459 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001460 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001461#endif
1462
1463#ifdef LINE_ATTR
1464# ifdef FEAT_SIGNS
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001465 // If this line has a sign with line highlighting set wlv.line_attr.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001466 if (sign_present)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001467 wlv.line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001468# endif
1469# if defined(FEAT_QUICKFIX)
1470 // Highlight the current line in the quickfix window.
1471 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001472 wlv.line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001473# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001474 if (wlv.line_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001475 area_highlighting = TRUE;
1476#endif
1477
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001478#ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01001479 if (spv->spv_has_spell && !number_only)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001480 {
Luuk van Baal30805a12023-05-27 22:22:10 +01001481 // Prepare for spell checking.
1482 extra_check = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001483
Luuk van Baal30805a12023-05-27 22:22:10 +01001484 // When a word wrapped from the previous line the start of the
1485 // current line is valid.
1486 if (lnum == spv->spv_checked_lnum)
1487 cur_checked_col = spv->spv_checked_col;
Luuk van Baale84c7732023-05-31 18:57:36 +01001488 // Previous line was not spell checked, check for capital. This happens
1489 // for the first line in an updated region or after a closed fold.
1490 if (spv->spv_capcol_lnum == 0 && check_need_cap(wp, lnum, 0))
1491 spv->spv_cap_col = 0;
1492 else if (lnum != spv->spv_capcol_lnum)
Luuk van Baal30805a12023-05-27 22:22:10 +01001493 spv->spv_cap_col = -1;
1494 spv->spv_checked_lnum = 0;
1495
Luuk van Baal30805a12023-05-27 22:22:10 +01001496 // Get the start of the next line, so that words that wrap to the
1497 // next line are found too: "et<line-break>al.".
1498 // Trick: skip a few chars for C/shell/Vim comments
1499 nextline[SPWORDLEN] = NUL;
1500 if (lnum < wp->w_buffer->b_ml.ml_line_count)
Luuk van Baale84c7732023-05-31 18:57:36 +01001501 {
1502 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1503 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1504 }
1505 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1506
1507 // If current line is empty, check first word in next line for capital.
1508 ptr = skipwhite(line);
1509 if (*ptr == NUL)
1510 {
1511 spv->spv_cap_col = 0;
1512 spv->spv_capcol_lnum = lnum + 1;
1513 }
1514 // For checking first word with a capital skip white space.
1515 else if (spv->spv_cap_col == 0)
1516 spv->spv_cap_col = ptr - line;
1517
Luuk van Baal30805a12023-05-27 22:22:10 +01001518 // Copy the end of the current line into nextline[].
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001519 if (nextline[SPWORDLEN] == NUL)
1520 {
1521 // No next line or it is empty.
1522 nextlinecol = MAXCOL;
1523 nextline_idx = 0;
1524 }
1525 else
1526 {
1527 v = (long)STRLEN(line);
1528 if (v < SPWORDLEN)
1529 {
1530 // Short line, use it completely and append the start of the
1531 // next line.
1532 nextlinecol = 0;
1533 mch_memmove(nextline, line, (size_t)v);
1534 STRMOVE(nextline + v, nextline + SPWORDLEN);
1535 nextline_idx = v + 1;
1536 }
1537 else
1538 {
1539 // Long line, use only the last SPWORDLEN bytes.
1540 nextlinecol = v - SPWORDLEN;
1541 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1542 nextline_idx = SPWORDLEN + 1;
1543 }
1544 }
1545 }
1546#endif
1547
Luuk van Baale84c7732023-05-31 18:57:36 +01001548 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1549 ptr = line;
1550
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001551 if (wp->w_p_list)
1552 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001553 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001554 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001555 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001556 || wp->w_lcs_chars.trail
1557 || wp->w_lcs_chars.lead
1558 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001559 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001560
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001561 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001562 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001563 {
1564 trailcol = (colnr_T)STRLEN(ptr);
1565 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1566 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001567 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001568 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001569 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001570 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001571 {
1572 leadcol = 0;
1573 while (VIM_ISWHITE(ptr[leadcol]))
1574 ++leadcol;
1575 if (ptr[leadcol] == NUL)
1576 // in a line full of spaces all of them are treated as trailing
1577 leadcol = (colnr_T)0;
1578 else
1579 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001580 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001581 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001582 }
1583
Bram Moolenaard7657e92022-09-20 18:59:30 +01001584 wlv.wcr_attr = get_wcr_attr(wp);
1585 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001586 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001587 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001588 area_highlighting = TRUE;
1589 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001590
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001591 // When w_skipcol is non-zero and there is virtual text above the actual
1592 // text, then this much of the virtual text is skipped.
1593 int skipcol_in_text_prop_above = 0;
1594
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001595#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001596 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001597 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001598
1599 char_u *prop_start;
1600 text_prop_count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE);
1601 if (text_prop_count > 0)
1602 {
1603 // Make a copy of the properties, so that they are properly
1604 // aligned.
1605 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1606 if (text_props != NULL)
1607 mch_memmove(text_props, prop_start,
1608 text_prop_count * sizeof(textprop_T));
1609
1610 // Allocate an array for the indexes.
1611 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1612 if (text_prop_idxs == NULL)
1613 VIM_CLEAR(text_props);
1614
1615 if (text_props != NULL)
1616 {
1617 area_highlighting = TRUE;
1618 extra_check = TRUE;
1619
zeertzjq4e26a9a2023-12-03 17:50:47 +01001620 /* Find the last text property that inserts text. */
1621 for (int i = 0; i < text_prop_count; ++i)
1622 if (text_props[i].tp_id < 0)
1623 last_textprop_text_idx = i;
1624
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001625 // When skipping virtual text the props need to be sorted. The
1626 // order is reversed!
1627 if (lnum == wp->w_topline && wp->w_skipcol > 0)
1628 {
1629 for (int i = 0; i < text_prop_count; ++i)
1630 text_prop_idxs[i] = i;
1631 sort_text_props(wp->w_buffer, text_props,
1632 text_prop_idxs, text_prop_count);
1633 }
1634
1635 // Text props "above" move the line number down to where the text
1636 // is. Only count the ones that are visible, not those that are
1637 // skipped because of w_skipcol.
1638 int text_width = wp->w_width - win_col_off(wp);
1639 for (int i = text_prop_count - 1; i >= 0; --i)
1640 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1641 {
1642 if (lnum == wp->w_topline
1643 && wp->w_skipcol - skipcol_in_text_prop_above
1644 >= text_width)
1645 {
1646 // This virtual text above is skipped, remove it from
1647 // the array.
1648 skipcol_in_text_prop_above += text_width;
1649 for (int j = i + 1; j < text_prop_count; ++j)
1650 text_props[j - 1] = text_props[j];
1651 ++i;
1652 --text_prop_count;
1653 }
1654 else
1655 ++wlv.text_prop_above_count;
1656 }
1657 }
1658 }
Bram Moolenaara572b932023-02-19 14:34:37 +00001659
1660 if (number_only)
1661 {
1662 // skip over rows only used for virtual text above
1663 wlv.row += wlv.text_prop_above_count;
1664 if (wlv.row > endrow)
1665 return wlv.row;
1666 wlv.screen_row += wlv.text_prop_above_count;
1667 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001668#endif
1669
zeertzjqce53e3e2023-09-01 18:49:30 +02001670#if defined(FEAT_LINEBREAK) || defined(FEAT_PROP_POPUP)
1671 colnr_T vcol_first_char = 0;
1672 if (wp->w_p_lbr && !number_only)
1673 {
1674 chartabsize_T cts;
1675 init_chartabsize_arg(&cts, wp, lnum, 0, line, line);
1676 (void)win_lbr_chartabsize(&cts, NULL);
1677 vcol_first_char = cts.cts_first_char;
1678 clear_chartabsize_arg(&cts);
1679 }
1680#endif
1681
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001682 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1683 // first character to be displayed.
1684 if (wp->w_p_wrap)
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001685 v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001686 else
1687 v = wp->w_leftcol;
1688 if (v > 0 && !number_only)
1689 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001690 char_u *prev_ptr = ptr;
1691 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001692 int charsize = 0;
zeertzjqb557f482023-08-22 22:07:34 +02001693 int head = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001694
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001695 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
zeertzjqb557f482023-08-22 22:07:34 +02001696 cts.cts_max_head_vcol = v;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001697 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001698 {
zeertzjqb557f482023-08-22 22:07:34 +02001699 head = 0;
1700 charsize = win_lbr_chartabsize(&cts, &head);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001701 cts.cts_vcol += charsize;
1702 prev_ptr = cts.cts_ptr;
1703 MB_PTR_ADV(cts.cts_ptr);
zeertzjqabc80812023-09-24 23:32:18 +02001704 if (wp->w_p_list)
1705 {
1706 in_multispace = *prev_ptr == ' ' && (*cts.cts_ptr == ' '
1707 || (prev_ptr > line && prev_ptr[-1] == ' '));
1708 if (!in_multispace)
1709 multispace_pos = 0;
1710 else if (cts.cts_ptr >= line + leadcol
1711 && wp->w_lcs_chars.multispace != NULL)
1712 {
1713 ++multispace_pos;
1714 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
1715 multispace_pos = 0;
1716 }
1717 else if (cts.cts_ptr < line + leadcol
1718 && wp->w_lcs_chars.leadmultispace != NULL)
1719 {
1720 ++multispace_pos;
1721 if (wp->w_lcs_chars.leadmultispace[multispace_pos] == NUL)
1722 multispace_pos = 0;
1723 }
1724 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001725 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001726 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001727 ptr = cts.cts_ptr;
1728 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001729
1730 // When:
1731 // - 'cuc' is set, or
1732 // - 'colorcolumn' is set, or
1733 // - 'virtualedit' is set, or
1734 // - the visual mode is active,
1735 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001736 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001737#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001738 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001739#endif
1740 virtual_active() ||
1741 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001742 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001743
1744 // Handle a character that's not completely on the screen: Put ptr at
1745 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001746 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001747 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001748 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001749 ptr = prev_ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001750 }
zeertzjqb557f482023-08-22 22:07:34 +02001751 if (v > wlv.vcol)
1752 skip_cells = v - wlv.vcol - head;
Bram Moolenaarcd105412022-10-10 19:50:42 +01001753
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001754 // Adjust for when the inverted text is before the screen,
1755 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001756 if (wlv.tocol <= wlv.vcol)
1757 wlv.fromcol = 0;
1758 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1759 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001760
1761#ifdef FEAT_LINEBREAK
1762 // When w_skipcol is non-zero, first line needs 'showbreak'
1763 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001764 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001765#endif
1766#ifdef FEAT_SPELL
1767 // When spell checking a word we need to figure out the start of the
1768 // word and if it's badly spelled or not.
Luuk van Baal30805a12023-05-27 22:22:10 +01001769 if (spv->spv_has_spell)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001770 {
1771 int len;
1772 colnr_T linecol = (colnr_T)(ptr - line);
1773 hlf_T spell_hlf = HLF_COUNT;
1774
1775 pos = wp->w_cursor;
1776 wp->w_cursor.lnum = lnum;
1777 wp->w_cursor.col = linecol;
1778 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1779
1780 // spell_move_to() may call ml_get() and make "line" invalid
1781 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1782 ptr = line + linecol;
1783
1784 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1785 {
1786 // no bad word found at line start, don't check until end of a
1787 // word
1788 spell_hlf = HLF_COUNT;
1789 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1790 }
1791 else
1792 {
1793 // bad word found, use attributes until end of word
1794 word_end = wp->w_cursor.col + len + 1;
1795
1796 // Turn index into actual attributes.
1797 if (spell_hlf != HLF_COUNT)
1798 spell_attr = highlight_attr[spell_hlf];
1799 }
1800 wp->w_cursor = pos;
1801
1802# ifdef FEAT_SYN_HL
1803 // Need to restart syntax highlighting for this line.
1804 if (has_syntax)
1805 syntax_start(wp, lnum);
1806# endif
1807 }
1808#endif
1809 }
1810
1811 // Correct highlighting for cursor that can't be disabled.
1812 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001813 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001814 {
1815 if (noinvcur)
1816 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001817 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001818 {
1819 // highlighting starts at cursor, let it start just after the
1820 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001821 fromcol_prev = wlv.fromcol;
1822 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001823 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001824 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001825 // restart highlighting after the cursor
1826 fromcol_prev = wp->w_virtcol;
1827 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001828 if (wlv.fromcol >= wlv.tocol)
1829 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001830 }
1831
1832#ifdef FEAT_SEARCH_EXTRA
1833 if (!number_only)
1834 {
1835 v = (long)(ptr - line);
1836 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1837 &line, &screen_search_hl,
1838 &search_attr);
1839 ptr = line + v; // "line" may have been updated
1840 }
1841#endif
1842
1843#ifdef FEAT_SYN_HL
1844 // Cursor line highlighting for 'cursorline' in the current window.
1845 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1846 {
1847 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001848 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001849 if (!(wp == curwin && VIsual_active)
1850 && wp->w_p_culopt_flags != CULOPT_NBR)
1851 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001852 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001853 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1854
zeertzjqb7acea12022-12-12 13:20:43 +00001855 // Only apply CursorLine highlight here when "screenline" is not
1856 // present in 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001857 if (!wlv.cul_screenline)
zeertzjqb7acea12022-12-12 13:20:43 +00001858 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001859 else
1860 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001861 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001862 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1863 }
1864 area_highlighting = TRUE;
1865 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001866 }
1867#endif
1868
Bram Moolenaar1306b362022-08-06 15:59:06 +01001869 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001870
1871 // Repeat for the whole displayed line.
1872 for (;;)
1873 {
1874#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001875 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001876#endif
1877#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001878 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001879#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001880
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001881 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001882 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001883 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001884#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001885 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001886 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001887 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001888 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001889 }
1890#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001891 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001892 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001893 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001894 if (cmdwin_type != 0 && wp == curwin)
1895 {
1896 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001897 wlv.n_extra = 1;
1898 wlv.c_extra = cmdwin_type;
1899 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001900 wlv.char_attr =
1901 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001902 }
1903 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001904#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001905 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001906 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001907 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001908 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001909 }
1910#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001911#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001912 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001913 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001914 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001915 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001916 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001917 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001918 }
1919#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001920 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001921 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001922 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001923 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001924 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001925 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001926#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001927 // Check if 'breakindent' applies and show it.
1928 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1929 if (wlv.n_extra == 0)
1930 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001931#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001932#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001933 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001934 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001935 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001936 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001937 }
1938#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001939 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001940 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001941 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001942 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001943 }
1944 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001945
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001946#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001947 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001948 && wlv.vcol >= left_curline_col
1949 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001950 {
zeertzjqb7acea12022-12-12 13:20:43 +00001951 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001952 }
1953#endif
1954
1955 // When still displaying '$' of change command, stop at cursor.
1956 // When only displaying the (relative) line number and that's done,
1957 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001958 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001959 && lnum == wp->w_cursor.lnum
1960 && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001961 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001962#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001963 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001964#endif
1965 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001966 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001967 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001968 // Pretend we have finished updating the window. Except when
1969 // 'cursorcolumn' is set.
1970#ifdef FEAT_SYN_HL
1971 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001972 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001973 else
1974#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001975 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001976 break;
1977 }
1978
Bram Moolenaar1306b362022-08-06 15:59:06 +01001979 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001980 {
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001981#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001982 if (text_props != NULL)
1983 {
1984 int pi;
1985 int bcol = (int)(ptr - line);
1986
Bram Moolenaar1306b362022-08-06 15:59:06 +01001987 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001988# ifdef FEAT_LINEBREAK
1989 && !in_linebreak
1990# endif
1991 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001992 --bcol; // still working on the previous char, e.g. Tab
1993
1994 // Check if any active property ends.
1995 for (pi = 0; pi < text_props_active; ++pi)
1996 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001997 int tpi = text_prop_idxs[pi];
1998 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001999
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002000 // An inline property ends when after the start column plus
2001 // length. An "above" property ends when used and n_extra
2002 // is zero.
2003 if ((tp->tp_col != MAXCOL
2004 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002005 {
2006 if (pi + 1 < text_props_active)
2007 mch_memmove(text_prop_idxs + pi,
2008 text_prop_idxs + pi + 1,
2009 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002010 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002011 --text_props_active;
2012 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002013# ifdef FEAT_LINEBREAK
2014 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002015 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002016 syntax_attr = 0;
2017# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002018 }
2019 }
2020
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002021# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01002022 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002023 // not on the next char yet, don't start another prop
2024 --bcol;
2025# endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002026 int display_text_first = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002027
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002028 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002029 // With 'nowrap' and not in the first screen line only "below"
2030 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002031 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002032 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002033 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002034 && (wp->w_p_wrap
2035 || wlv.row == startrow
2036 || (text_props[text_prop_next].tp_flags
2037 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002038 || (bcol == 0
2039 && (text_props[text_prop_next].tp_flags
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002040 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002041 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002042 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01002043 if (text_props[text_prop_next].tp_col == MAXCOL
2044 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002045 + text_props[text_prop_next].tp_len)
2046 text_prop_idxs[text_props_active++] = text_prop_next;
2047 ++text_prop_next;
2048 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002049
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002050 if (wlv.n_extra == 0 ||
2051 (!wlv.extra_for_textprop
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002052 && !(text_prop_type != NULL &&
2053 text_prop_flags & PT_FLAG_OVERRIDE)
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002054 ))
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002055 {
2056 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002057 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002058 text_prop_flags = 0;
2059 text_prop_type = NULL;
2060 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002061 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002062 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002063 if (text_props_active > 0 && wlv.n_extra == 0
2064 && !display_text_first)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002065 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01002066 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002067 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002068 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002069
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002070 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002071 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002072
2073 // Sort the properties on priority and/or starting last.
2074 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002075 sort_text_props(wp->w_buffer, text_props,
2076 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002077
2078 for (pi = 0; pi < text_props_active; ++pi)
2079 {
2080 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002081 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002082 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002083 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002084
Bram Moolenaarcd105412022-10-10 19:50:42 +01002085 // Only use a text property that can be displayed.
2086 // Skip "after" properties when wrap is off and at the
2087 // end of the window.
2088 if (pt != NULL
2089 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2090 && tp->tp_id != -MAXCOL
2091 && !(tp->tp_id < 0
2092 && !wp->w_p_wrap
2093 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2094 | TP_FLAG_ALIGN_ABOVE
2095 | TP_FLAG_ALIGN_BELOW)) == 0
2096 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002097 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002098 if (tp->tp_col == MAXCOL
2099 && *ptr == NUL
2100 && ((wp->w_p_list && lcs_eol_one > 0
2101 && (tp->tp_flags
2102 & TP_FLAG_ALIGN_ABOVE) == 0)
2103 || (ptr == line
2104 && !did_line
2105 && (tp->tp_flags
2106 & TP_FLAG_ALIGN_BELOW))))
2107 {
2108 // skip this prop, first display the '$' after
2109 // the line or display an empty line
2110 text_prop_follows = TRUE;
2111 if (used_tpi < 0)
2112 display_text_first = TRUE;
2113 continue;
2114 }
2115
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002116 if (pt->pt_hl_id > 0)
2117 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002118 text_prop_type = pt;
2119 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002120 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002121 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2122 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002123 text_prop_flags = pt->pt_flags;
2124 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002125 used_tpi = tpi;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002126 display_text_first = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002127 }
2128 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002129 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002130 && -text_prop_id
2131 <= wp->w_buffer->b_textprop_text.ga_len)
2132 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002133 textprop_T *tp = &text_props[used_tpi];
2134 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002135 ->b_textprop_text.ga_data)[
2136 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002137 int above = (tp->tp_flags
2138 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002139 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002140
2141 // reset the ID in the copy to avoid it being used
2142 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002143 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002144
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002145 if (p != NULL)
2146 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002147 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002148 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002149 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002150 & TP_FLAG_ALIGN_BELOW);
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002151 int wrap = tp->tp_col < MAXCOL
2152 || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002153 int padding = tp->tp_col == MAXCOL
2154 && tp->tp_len > 1
2155 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002156
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002157 // Insert virtual text before the current
2158 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002159 wlv.p_extra = p;
2160 wlv.c_extra = NUL;
2161 wlv.c_final = NUL;
2162 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002163 wlv.extra_for_textprop = TRUE;
zeertzjq6e940d92023-08-17 23:21:40 +02002164 wlv.start_extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002165 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2166 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002167 n_attr = mb_charlen(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002168 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002169 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002170 if (*ptr == NUL)
2171 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002172 text_prop_flags &= ~PT_FLAG_COMBINE;
zeertzjq6b9c2022023-09-11 20:01:17 +02002173# ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002174 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002175 {
2176 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002177 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002178 wlv.need_showbreak = FALSE;
2179 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002180 }
zeertzjq6b9c2022023-09-11 20:01:17 +02002181# endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002182 if ((right || above || below || !wrap
2183 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002184 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002185 char_u *prev_p_extra = wlv.p_extra;
2186 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002187
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002188 // Take care of padding, right-align and
2189 // truncation.
2190 // Shared with win_lbr_chartabsize(), must do
2191 // exactly the same.
2192 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002193 wlv.vcol,
zeertzjq6b9c2022023-09-11 20:01:17 +02002194# ifdef FEAT_RIGHTLEFT
2195 wp->w_p_rl
2196 ? wp->w_width - wlv.col - 1
2197 :
2198# endif
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002199 wlv.col,
2200 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002201 &n_attr, &wlv.n_attr_skip,
2202 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002203 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002204 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002205 // wlv.p_extra was allocated
2206 vim_free(p_extra_free2);
2207 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002208 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002209
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002210 if (above)
2211 wlv.vcol_off_tp = wlv.n_extra;
2212
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002213 if (lcs_eol_one < 0
2214 && wp->w_p_wrap
2215 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002216 + wlv.n_extra - 2 > wp->w_width)
2217 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002218 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002219
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002220 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002221 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002222 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002223 {
2224 draw_screen_line(wp, &wlv);
2225
2226 // When line got too long for screen break
2227 // here.
2228 if (wlv.row == endrow)
2229 {
2230 ++wlv.row;
2231 break;
2232 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002233 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002234 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002235 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002236 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002237 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002238
Bram Moolenaarcd105412022-10-10 19:50:42 +01002239 // If the text didn't reach until the first window
2240 // column we need to skip cells.
2241 if (skip_cells > 0)
2242 {
2243 if (wlv.n_extra > skip_cells)
2244 {
2245 wlv.n_extra -= skip_cells;
2246 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002247 wlv.n_attr_skip -= skip_cells;
2248 if (wlv.n_attr_skip < 0)
2249 wlv.n_attr_skip = 0;
zeertzjqb557f482023-08-22 22:07:34 +02002250 skipped_cells += skip_cells;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002251 skip_cells = 0;
2252 }
2253 else
2254 {
2255 // the whole text is left of the window, drop
2256 // it and advance to the next one
2257 skip_cells -= wlv.n_extra;
zeertzjqb557f482023-08-22 22:07:34 +02002258 skipped_cells += wlv.n_extra;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002259 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002260 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002261 bail_out = TRUE;
2262 }
2263 }
2264
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002265 // If another text prop follows the condition below at
2266 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002267 // If this is an "above" text prop and 'nowrap' the we
2268 // must wrap anyway.
2269 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002270 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002271 && (wp->w_p_wrap
2272 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002273 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002274
2275 if (bail_out)
2276 // starting a new line for "below"
2277 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002278 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002279 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002280 else if (text_prop_next < text_prop_count
2281 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002282 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2283 || (!wp->w_p_wrap
2284 && wlv.col == wp->w_width - 1
2285 && (text_props[text_prop_next].tp_flags
2286 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002287 // When at last-but-one character and a text property
2288 // follows after it, we may need to flush the line after
2289 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002290 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002291 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002292 }
zeertzjq6e940d92023-08-17 23:21:40 +02002293
2294 if (wlv.start_extra_for_textprop)
2295 {
2296 wlv.start_extra_for_textprop = FALSE;
2297 // restore search_attr and area_attr when n_extra
2298 // is down to zero
2299 saved_search_attr = search_attr;
2300 saved_area_attr = area_attr;
2301 search_attr = 0;
2302 area_attr = 0;
2303 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002304#endif
2305
zeertzjq6e940d92023-08-17 23:21:40 +02002306 int *area_attr_p =
2307#ifdef FEAT_PROP_POPUP
2308 wlv.extra_for_textprop ? &saved_area_attr :
2309#endif
2310 &area_attr;
2311
2312 // handle Visual or match highlighting in this line
2313 if (wlv.vcol == wlv.fromcol
2314 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
2315 && ((wlv.n_extra == 0 && (*mb_ptr2cells)(ptr) > 1)
2316 || (wlv.n_extra > 0 && wlv.p_extra != NULL
2317 && (*mb_ptr2cells)(wlv.p_extra) > 1)))
2318 || ((int)vcol_prev == fromcol_prev
2319 && vcol_prev < wlv.vcol // not at margin
2320 && wlv.vcol < wlv.tocol))
2321 *area_attr_p = vi_attr; // start highlighting
2322 else if (*area_attr_p != 0
2323 && (wlv.vcol == wlv.tocol
2324 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
2325 *area_attr_p = 0; // stop highlighting
2326
zeertzjqe500ae82023-08-17 22:35:26 +02002327#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaare38fc862022-08-11 17:24:50 +01002328 if (wlv.n_extra == 0)
2329 {
2330 // Check for start/end of 'hlsearch' and other matches.
2331 // After end, check for start/end of next match.
2332 // When another match, have to check for start again.
2333 v = (long)(ptr - line);
2334 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2335 &screen_search_hl, &has_match_conc,
2336 &match_conc, did_line_attr, lcs_eol_one,
2337 &on_last_col);
2338 ptr = line + v; // "line" may have been changed
Bram Moolenaare38fc862022-08-11 17:24:50 +01002339
2340 // Do not allow a conceal over EOL otherwise EOL will be missed
2341 // and bad things happen.
2342 if (*ptr == NUL)
2343 has_match_conc = 0;
zeertzjqb25dbb32023-08-13 18:11:05 +02002344 }
zeertzjqe500ae82023-08-17 22:35:26 +02002345#endif
zeertzjqb25dbb32023-08-13 18:11:05 +02002346
Bram Moolenaare38fc862022-08-11 17:24:50 +01002347#ifdef FEAT_DIFF
2348 if (wlv.diff_hlf != (hlf_T)0)
2349 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002350 // When there is extra text (e.g. virtual text) it gets the
2351 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002352 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2353 && wlv.n_extra == 0)
2354 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002355 if (wlv.diff_hlf == HLF_TXD
2356 && ((ptr - line > change_end && wlv.n_extra == 0)
2357 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002358 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002359 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002360 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2361 && wp->w_p_culopt_flags != CULOPT_NBR
2362 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2363 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002364 wlv.line_attr = hl_combine_attr(
2365 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002366 }
2367#endif
2368
Bram Moolenaara74fda62019-10-19 17:38:03 +02002369#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002370 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002371 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002372 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002373# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002374 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002375 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002376# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002377 // Get syntax attribute.
2378 if (has_syntax)
2379 {
2380 // Get the syntax attribute for the character. If there
2381 // is an error, disable syntax highlighting.
2382 save_did_emsg = did_emsg;
2383 did_emsg = FALSE;
2384
2385 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002386 if (v == prev_syntax_col)
2387 // at same column again
2388 syntax_attr = prev_syntax_attr;
2389 else
2390 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002391# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002392 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002393# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002394 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002395# ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01002396 spv->spv_has_spell ? &can_spell :
Bram Moolenaar34390282019-10-16 14:38:26 +02002397# endif
Luuk van Baal30805a12023-05-27 22:22:10 +01002398 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002399 prev_syntax_col = v;
2400 prev_syntax_attr = syntax_attr;
2401 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002402
Bram Moolenaar34390282019-10-16 14:38:26 +02002403 if (did_emsg)
2404 {
2405 wp->w_s->b_syn_error = TRUE;
2406 has_syntax = FALSE;
2407 syntax_attr = 0;
2408 }
2409 else
2410 did_emsg = save_did_emsg;
2411# ifdef SYN_TIME_LIMIT
2412 if (wp->w_s->b_syn_slow)
2413 has_syntax = FALSE;
2414# endif
2415
2416 // Need to get the line again, a multi-line regexp may
2417 // have made it invalid.
2418 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2419 ptr = line + v;
2420# ifdef FEAT_CONCEAL
2421 // no concealing past the end of the line, it interferes
2422 // with line highlighting
2423 if (*ptr == NUL)
2424 syntax_flags = 0;
2425 else
2426 syntax_flags = get_syntax_info(&syntax_seqnr);
2427# endif
2428 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002429 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002430# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002431 // Combine text property highlight into syntax highlight.
2432 if (text_prop_type != NULL)
2433 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002434 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002435 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2436 else
2437 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002438 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002439 }
2440# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002441#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002442
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002443 // Decide which of the highlight attributes to use.
2444 attr_pri = TRUE;
2445#ifdef LINE_ATTR
2446 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002447 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002448 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002449 if (!highlight_match)
2450 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002451 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002452# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002453 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002454# endif
2455 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002456 else if (search_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, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002459# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002460 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002461# endif
2462 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002463 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002464 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2465 || wlv.vcol < wlv.fromcol
2466 || vcol_prev < fromcol_prev
2467 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002468 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002469 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002470 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002471# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002472 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002473# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002474 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002475# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002476 attr_pri = FALSE;
2477 }
2478#else
2479 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002480 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002481 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002482 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002483#endif
2484 else
2485 {
2486 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002487#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002488 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002489#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002490 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002491#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002492 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002493#ifdef FEAT_PROP_POPUP
2494 // override with text property highlight when "override" is TRUE
2495 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002496 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002497#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002498 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002499
2500 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002501 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002502 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002503 if (wlv.char_attr == 0)
2504 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002505 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002506 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002507 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002508
2509 // Get the next character to put on the screen.
2510
2511 // The "p_extra" points to the extra stuff that is inserted to
2512 // represent special characters (non-printable stuff) and other
2513 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002514 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002515 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2516 // "p_extra[n_extra]".
2517 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002518 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002519 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002520 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002521 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002522 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2523 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002524 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2525 if (enc_utf8 && utf_char2len(c) > 1)
2526 {
2527 mb_utf8 = TRUE;
2528 u8cc[0] = 0;
2529 c = 0xc0;
2530 }
2531 else
2532 mb_utf8 = FALSE;
2533 }
2534 else
2535 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002536 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002537 if (has_mbyte)
2538 {
2539 mb_c = c;
2540 if (enc_utf8)
2541 {
2542 // If the UTF-8 character is more than one byte:
2543 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002544 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002545 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002546 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002547 mb_l = 1;
2548 else if (mb_l > 1)
2549 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002550 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002551 mb_utf8 = TRUE;
2552 c = 0xc0;
2553 }
2554 }
2555 else
2556 {
2557 // if this is a DBCS character, put it in "mb_c"
2558 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002559 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002560 mb_l = 1;
2561 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002562 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002563 }
2564 if (mb_l == 0) // at the NUL at end-of-line
2565 mb_l = 1;
2566
2567 // If a double-width char doesn't fit display a '>' in the
2568 // last column.
2569 if ((
2570# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002571 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002572# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002573 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002574 && (*mb_char2cells)(mb_c) == 2)
2575 {
2576 c = '>';
2577 mb_c = c;
2578 mb_l = 1;
2579 mb_utf8 = FALSE;
2580 multi_attr = HL_ATTR(HLF_AT);
2581#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002582 if (wlv.cul_attr)
2583 multi_attr = hl_combine_attr(
2584 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002585#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002586 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002587
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002588 // put the pointer back to output the double-width
2589 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002590 ++wlv.n_extra;
2591 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002592 }
2593 else
2594 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002595 wlv.n_extra -= mb_l - 1;
2596 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002597 }
2598 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002599 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002600 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002601 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002602#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002603 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002604 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002605 // Only restore search_attr and area_attr after "n_extra" in
2606 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002607 if (wlv.saved_n_extra <= 0)
2608 {
2609 if (search_attr == 0)
2610 search_attr = saved_search_attr;
2611 if (area_attr == 0 && *ptr != NUL)
2612 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002613
2614 if (wlv.extra_for_textprop)
2615 // wlv.extra_attr should be used at this position but
2616 // not any further.
2617 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002618 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002619
2620 wlv.extra_for_textprop = FALSE;
2621 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002622 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002623#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002624 }
2625 else
2626 {
2627#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002628 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002629#endif
zeertzjqe500ae82023-08-17 22:35:26 +02002630 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002631
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002632 // Get a character from the line itself.
2633 c = *ptr;
2634#ifdef FEAT_LINEBREAK
2635 c0 = *ptr;
2636#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002637 if (c == NUL)
zeertzjqb557f482023-08-22 22:07:34 +02002638 {
2639#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002640 // text is finished, may display a "below" virtual text
2641 did_line = TRUE;
2642#endif
zeertzjqb557f482023-08-22 22:07:34 +02002643 // no more cells to skip
2644 skip_cells = 0;
2645 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002646
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002647 if (has_mbyte)
2648 {
2649 mb_c = c;
2650 if (enc_utf8)
2651 {
2652 // If the UTF-8 character is more than one byte: Decode it
2653 // into "mb_c".
2654 mb_l = utfc_ptr2len(ptr);
2655 mb_utf8 = FALSE;
2656 if (mb_l > 1)
2657 {
2658 mb_c = utfc_ptr2char(ptr, u8cc);
2659 // Overlong encoded ASCII or ASCII with composing char
2660 // is displayed normally, except a NUL.
2661 if (mb_c < 0x80)
2662 {
2663 c = mb_c;
2664#ifdef FEAT_LINEBREAK
2665 c0 = mb_c;
2666#endif
2667 }
2668 mb_utf8 = TRUE;
2669
2670 // At start of the line we can have a composing char.
2671 // Draw it as a space with a composing char.
2672 if (utf_iscomposing(mb_c))
2673 {
2674 int i;
2675
2676 for (i = Screen_mco - 1; i > 0; --i)
2677 u8cc[i] = u8cc[i - 1];
2678 u8cc[0] = mb_c;
2679 mb_c = ' ';
2680 }
2681 }
2682
2683 if ((mb_l == 1 && c >= 0x80)
2684 || (mb_l >= 1 && mb_c == 0)
2685 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2686 {
2687 // Illegal UTF-8 byte: display as <xx>.
2688 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002689 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002690# ifdef FEAT_RIGHTLEFT
2691 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002692 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002693# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002694 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002695 c = *wlv.p_extra;
2696 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002697 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002698 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2699 wlv.c_extra = NUL;
2700 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002701 if (area_attr == 0 && search_attr == 0)
2702 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002703 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002704 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002705 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002706 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002707 }
2708 }
2709 else if (mb_l == 0) // at the NUL at end-of-line
2710 mb_l = 1;
2711#ifdef FEAT_ARABIC
2712 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2713 {
2714 // Do Arabic shaping.
2715 int pc, pc1, nc;
2716 int pcc[MAX_MCO];
2717
2718 // The idea of what is the previous and next
2719 // character depends on 'rightleft'.
2720 if (wp->w_p_rl)
2721 {
2722 pc = prev_c;
2723 pc1 = prev_c1;
2724 nc = utf_ptr2char(ptr + mb_l);
2725 prev_c1 = u8cc[0];
2726 }
2727 else
2728 {
2729 pc = utfc_ptr2char(ptr + mb_l, pcc);
2730 nc = prev_c;
2731 pc1 = pcc[0];
2732 }
2733 prev_c = mb_c;
2734
2735 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2736 }
2737 else
2738 prev_c = mb_c;
2739#endif
2740 }
2741 else // enc_dbcs
2742 {
2743 mb_l = MB_BYTE2LEN(c);
2744 if (mb_l == 0) // at the NUL at end-of-line
2745 mb_l = 1;
2746 else if (mb_l > 1)
2747 {
2748 // We assume a second byte below 32 is illegal.
2749 // Hopefully this is OK for all double-byte encodings!
2750 if (ptr[1] >= 32)
2751 mb_c = (c << 8) + ptr[1];
2752 else
2753 {
2754 if (ptr[1] == NUL)
2755 {
2756 // head byte at end of line
2757 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002758 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002759 }
2760 else
2761 {
2762 // illegal tail byte
2763 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002764 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002765 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002766 wlv.p_extra = wlv.extra;
2767 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002768 wlv.c_extra = NUL;
2769 wlv.c_final = NUL;
2770 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002771 if (area_attr == 0 && search_attr == 0)
2772 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002773 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002774 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002775 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002776 // save current attr
2777 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002778 }
2779 mb_c = c;
2780 }
2781 }
2782 }
2783 // If a double-width char doesn't fit display a '>' in the
2784 // last column; the character is displayed at the start of the
2785 // next line.
2786 if ((
2787# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002788 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002789# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002790 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002791 && (*mb_char2cells)(mb_c) == 2)
2792 {
2793 c = '>';
2794 mb_c = c;
2795 mb_utf8 = FALSE;
2796 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002797 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002798 // Put pointer back so that the character will be
2799 // displayed at the start of the next line.
2800 --ptr;
2801#ifdef FEAT_CONCEAL
2802 did_decrement_ptr = TRUE;
2803#endif
2804 }
2805 else if (*ptr != NUL)
2806 ptr += mb_l - 1;
2807
2808 // If a double-width char doesn't fit at the left side display
2809 // a '<' in the first column. Don't do this for unprintable
2810 // characters.
zeertzjqb557f482023-08-22 22:07:34 +02002811 if (skip_cells > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002812 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002813 wlv.n_extra = 1;
2814 wlv.c_extra = MB_FILLER_CHAR;
2815 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002816 c = ' ';
2817 if (area_attr == 0 && search_attr == 0)
2818 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002819 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002820 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002821 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002822 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002823 }
2824 mb_c = c;
2825 mb_utf8 = FALSE;
2826 mb_l = 1;
2827 }
2828
2829 }
2830 ++ptr;
2831
2832 if (extra_check)
2833 {
2834#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002835 // Check spelling (unless at the end of the line).
2836 // Only do this when there is no syntax highlighting, the
2837 // @Spell cluster is not used or the current syntax item
2838 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002839 v = (long)(ptr - line);
Luuk van Baal30805a12023-05-27 22:22:10 +01002840 if (spv->spv_has_spell && v >= word_end && v > cur_checked_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002841 {
2842 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002843 // do not calculate cap_col at the end of the line or when
2844 // only white space is following
2845 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002846# ifdef FEAT_SYN_HL
2847 !has_syntax ||
2848# endif
2849 can_spell))
2850 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002851 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002852 int len;
2853 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002854
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002855 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002856 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002857
2858 // Use nextline[] if possible, it has the start of the
2859 // next line concatenated.
2860 if ((prev_ptr - line) - nextlinecol >= 0)
2861 p = nextline + (prev_ptr - line) - nextlinecol;
2862 else
2863 p = prev_ptr;
Luuk van Baal30805a12023-05-27 22:22:10 +01002864 spv->spv_cap_col -= (int)(prev_ptr - line);
2865 len = spell_check(wp, p, &spell_hlf, &spv->spv_cap_col,
2866 spv->spv_unchanged);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002867 word_end = v + len;
2868
2869 // In Insert mode only highlight a word that
2870 // doesn't touch the cursor.
2871 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002872 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002873 && wp->w_cursor.lnum == lnum
2874 && wp->w_cursor.col >=
2875 (colnr_T)(prev_ptr - line)
2876 && wp->w_cursor.col < (colnr_T)word_end)
2877 {
2878 spell_hlf = HLF_COUNT;
2879 spell_redraw_lnum = lnum;
2880 }
2881
2882 if (spell_hlf == HLF_COUNT && p != prev_ptr
2883 && (p - nextline) + len > nextline_idx)
2884 {
2885 // Remember that the good word continues at the
2886 // start of the next line.
Luuk van Baal30805a12023-05-27 22:22:10 +01002887 spv->spv_checked_lnum = lnum + 1;
2888 spv->spv_checked_col = (p - nextline) + len
2889 - nextline_idx;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002890 }
2891
2892 // Turn index into actual attributes.
2893 if (spell_hlf != HLF_COUNT)
2894 spell_attr = highlight_attr[spell_hlf];
2895
Luuk van Baal30805a12023-05-27 22:22:10 +01002896 if (spv->spv_cap_col > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002897 {
2898 if (p != prev_ptr
Luuk van Baal30805a12023-05-27 22:22:10 +01002899 && (p - nextline) + spv->spv_cap_col
2900 >= nextline_idx)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002901 {
2902 // Remember that the word in the next line
2903 // must start with a capital.
Luuk van Baal30805a12023-05-27 22:22:10 +01002904 spv->spv_capcol_lnum = lnum + 1;
2905 spv->spv_cap_col = ((p - nextline)
2906 + spv->spv_cap_col - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002907 }
2908 else
2909 // Compute the actual column.
Luuk van Baal30805a12023-05-27 22:22:10 +01002910 spv->spv_cap_col += (prev_ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002911 }
2912 }
2913 }
2914 if (spell_attr != 0)
2915 {
2916 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002917 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2918 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002919 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002920 wlv.char_attr = hl_combine_attr(spell_attr,
2921 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002922 }
2923#endif
2924#ifdef FEAT_LINEBREAK
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02002925 // we don't want linebreak to apply for lines that start with
2926 // leading spaces, followed by long letters (since it would add
2927 // a break at the beginning of a line and this might be unexpected)
2928 //
2929 // So only allow to linebreak, once we have found chars not in
2930 // 'breakat' in the line.
2931 if ( wp->w_p_lbr && !wlv.need_lbr && c != NUL &&
2932 !VIM_ISBREAK((int)*ptr))
2933 wlv.need_lbr = TRUE;
2934#endif
2935#ifdef FEAT_LINEBREAK
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002936 // Found last space before word: check for line break.
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02002937 if (wp->w_p_lbr && c0 == c && wlv.need_lbr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002938 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2939 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002940 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2941 : 0;
2942 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002943 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002944
zeertzjqce53e3e2023-09-01 18:49:30 +02002945 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol
2946# ifdef FEAT_PROP_POPUP
2947 - vcol_first_char,
2948# endif
2949 line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002950# ifdef FEAT_PROP_POPUP
2951 // do not want virtual text counted here
2952 cts.cts_has_prop_with_text = FALSE;
2953# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002954 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002955 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002956
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002957 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002958 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002959 // line break, but for TABs the highlighting should
2960 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002961 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002962
Bram Moolenaar1306b362022-08-06 15:59:06 +01002963 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002964# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002965 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002966 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002967 wp->w_buffer->b_p_vts_array) - 1;
2968# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002969 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002970 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002971# endif
2972
Bram Moolenaar1306b362022-08-06 15:59:06 +01002973 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2974 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002975# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002976 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002977 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002978# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002979 if (VIM_ISWHITE(c))
2980 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002981# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002982 if (c == TAB)
2983 // See "Tab alignment" below.
2984 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002985# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002986 if (!wp->w_p_list)
2987 c = ' ';
2988 }
2989 }
2990#endif
zeertzjqabc80812023-09-24 23:32:18 +02002991 if (wp->w_p_list)
2992 {
2993 in_multispace = c == ' ' && (*ptr == ' '
2994 || (prev_ptr > line && prev_ptr[-1] == ' '));
2995 if (!in_multispace)
2996 multispace_pos = 0;
2997 }
zeertzjqf14b8ba2021-09-10 16:58:30 +02002998
Bram Moolenaareed9d462021-02-15 20:38:25 +01002999 // 'list': Change char 160 to 'nbsp' and space to 'space'
3000 // setting in 'listchars'. But not when the character is
3001 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003002 if (wp->w_p_list
3003 && ((((c == 160 && mb_l == 1)
3004 || (mb_utf8
3005 && ((mb_c == 160 && mb_l == 2)
3006 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01003007 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003008 || (c == ' '
3009 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02003010 && (wp->w_lcs_chars.space
3011 || (in_multispace
3012 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01003013 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003014 && ptr - line <= trailcol)))
3015 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02003016 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
3017 {
3018 c = wp->w_lcs_chars.multispace[multispace_pos++];
3019 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
3020 multispace_pos = 0;
3021 }
3022 else
3023 c = (c == ' ') ? wp->w_lcs_chars.space
3024 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003025 if (area_attr == 0 && search_attr == 0)
3026 {
3027 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003028 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003029 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003030 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003031 }
3032 mb_c = c;
3033 if (enc_utf8 && utf_char2len(c) > 1)
3034 {
3035 mb_utf8 = TRUE;
3036 u8cc[0] = 0;
3037 c = 0xc0;
3038 }
3039 else
3040 mb_utf8 = FALSE;
3041 }
3042
zeertzjq2e7cba32022-06-10 15:30:32 +01003043 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
3044 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003045 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003046 if (leadcol != 0 && in_multispace && ptr < line + leadcol
3047 && wp->w_lcs_chars.leadmultispace != NULL)
3048 {
3049 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01003050 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
3051 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003052 multispace_pos = 0;
3053 }
3054
3055 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
3056 c = wp->w_lcs_chars.trail;
3057
3058 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
3059 c = wp->w_lcs_chars.lead;
3060
zeertzjq2e7cba32022-06-10 15:30:32 +01003061 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003062 c = wp->w_lcs_chars.space;
3063
3064
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003065 if (!attr_pri)
3066 {
3067 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003068 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003069 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003070 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003071 }
3072 mb_c = c;
3073 if (enc_utf8 && utf_char2len(c) > 1)
3074 {
3075 mb_utf8 = TRUE;
3076 u8cc[0] = 0;
3077 c = 0xc0;
3078 }
3079 else
3080 mb_utf8 = FALSE;
3081 }
3082 }
3083
3084 // Handling of non-printable characters.
3085 if (!vim_isprintc(c))
3086 {
3087 // when getting a character from the file, we may have to
3088 // turn it into something else on the way to putting it
3089 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01003090 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003091 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003092 int tab_len = 0;
3093 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003094#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003095 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01003096
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003097 // only adjust the tab_len, when at the first column
3098 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01003099 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003100 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003101#endif
3102 // tab amount depends on current column
3103#ifdef FEAT_VARTABS
3104 tab_len = tabstop_padding(vcol_adjusted,
3105 wp->w_buffer->b_p_ts,
3106 wp->w_buffer->b_p_vts_array) - 1;
3107#else
3108 tab_len = (int)wp->w_buffer->b_p_ts
3109 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
3110#endif
3111
3112#ifdef FEAT_LINEBREAK
3113 if (!wp->w_p_lbr || !wp->w_p_list)
3114#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003115 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003116 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01003117 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003118 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003119#ifdef FEAT_LINEBREAK
3120 else
3121 {
3122 char_u *p;
3123 int len;
3124 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003125 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003126
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003127# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003128 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003129 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003130 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003131
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003132 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003133 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003134 && old_boguscols > 0
3135 && wlv.n_extra > tab_len)
3136 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003137# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003138 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003139 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003140 // If wlv.n_extra > 0, it gives the number of chars
3141 // to use for a tab, else we need to calculate the
3142 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003143 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3144 len = tab_len * tab2_len;
3145 if (wp->w_lcs_chars.tab3)
3146 len += mb_char2len(wp->w_lcs_chars.tab3)
3147 - tab2_len;
3148 if (wlv.n_extra > 0)
3149 len += wlv.n_extra - tab_len;
3150 c = wp->w_lcs_chars.tab1;
3151 p = alloc(len + 1);
3152 if (p == NULL)
3153 wlv.n_extra = 0;
3154 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003155 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003156 vim_memset(p, ' ', len);
3157 p[len] = NUL;
3158 vim_free(wlv.p_extra_free);
3159 wlv.p_extra_free = p;
3160 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003161 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003162 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003163
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003164 if (*p == NUL)
3165 {
3166 tab_len = i;
3167 break;
3168 }
3169
3170 // if tab3 is given, use it for the last
3171 // char
3172 if (wp->w_lcs_chars.tab3
3173 && i == tab_len - 1)
3174 lcs = wp->w_lcs_chars.tab3;
3175 p += mb_char2bytes(lcs, p);
3176 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003177 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003178 }
3179 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003180# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003181 // n_extra will be increased by
3182 // FIX_FOX_BOGUSCOLS macro below, so need to
3183 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003184 if (wlv.vcol_off_co > 0)
3185 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003186# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003187 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003188 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003189 }
3190#endif
3191#ifdef FEAT_CONCEAL
3192 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003193 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003194
3195 // Tab alignment should be identical regardless of
3196 // 'conceallevel' value. So tab compensates of all
3197 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003198 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003199 // line. Note that the tab can be longer than
3200 // 'tabstop' when there are concealed characters.
3201 FIX_FOR_BOGUSCOLS;
3202
3203 // Make sure, the highlighting for the tab char will be
3204 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003205 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003206 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003207 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003208 tab_len += vc_saved;
3209 }
3210#endif
3211 mb_utf8 = FALSE; // don't draw as UTF-8
3212 if (wp->w_p_list)
3213 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003214 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003215 ? wp->w_lcs_chars.tab3
3216 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003217#ifdef FEAT_LINEBREAK
h-east194555c2023-03-02 18:49:09 +00003218 if (wp->w_p_lbr && wlv.p_extra != NULL
3219 && *wlv.p_extra != NUL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003220 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003221 else
3222#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003223 wlv.c_extra = wp->w_lcs_chars.tab2;
3224 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003225 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003226 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003227 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003228 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003229 mb_c = c;
3230 if (enc_utf8 && utf_char2len(c) > 1)
3231 {
3232 mb_utf8 = TRUE;
3233 u8cc[0] = 0;
3234 c = 0xc0;
3235 }
3236 }
3237 else
3238 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003239 wlv.c_final = NUL;
3240 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003241 c = ' ';
3242 }
3243 }
3244 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003245 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003246 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003247 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3248 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003249 && VIsual_mode != Ctrl_V
3250 && (
3251# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003252 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003253# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003254 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003255 && !(noinvcur
3256 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003257 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003258 && lcs_eol_one > 0)
3259 {
3260 // Display a '$' after the line or highlight an extra
3261 // character if the line break is included.
3262#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3263 // For a diff line the highlighting continues after the
3264 // "$".
3265 if (
3266# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003267 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003268# ifdef LINE_ATTR
3269 &&
3270# endif
3271# endif
3272# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003273 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003274# endif
3275 )
3276#endif
3277 {
3278 // In virtualedit, visual selections may extend
3279 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003280 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003281 && wlv.tocol != MAXCOL
3282 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003283 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003284 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003285 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003286 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3287 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003288 else
3289 c = ' ';
3290 lcs_eol_one = -1;
3291 --ptr; // put it back at the NUL
3292 if (!attr_pri)
3293 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003294 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003295 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003296 n_attr = 1;
3297 }
3298 mb_c = c;
3299 if (enc_utf8 && utf_char2len(c) > 1)
3300 {
3301 mb_utf8 = TRUE;
3302 u8cc[0] = 0;
3303 c = 0xc0;
3304 }
3305 else
3306 mb_utf8 = FALSE; // don't draw as UTF-8
3307 }
3308 else if (c != NUL)
3309 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003310 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3311 if (wlv.n_extra == 0)
3312 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003313#ifdef FEAT_RIGHTLEFT
3314 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003315 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003316#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003317 wlv.c_extra = NUL;
3318 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003319#ifdef FEAT_LINEBREAK
3320 if (wp->w_p_lbr)
3321 {
3322 char_u *p;
3323
Bram Moolenaar1306b362022-08-06 15:59:06 +01003324 c = *wlv.p_extra;
3325 p = alloc(wlv.n_extra + 1);
3326 vim_memset(p, ' ', wlv.n_extra);
3327 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3328 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003329 vim_free(wlv.p_extra_free);
3330 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003331 }
3332 else
3333#endif
3334 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003335 wlv.n_extra = byte2cells(c) - 1;
3336 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003337 }
3338 if (!attr_pri)
3339 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003340 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003341 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003342 HL_ATTR(HLF_8));
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003343#ifdef FEAT_PROP_POPUP
3344 if (text_prop_type != NULL &&
3345 text_prop_flags & PT_FLAG_OVERRIDE)
3346 wlv.extra_attr = hl_combine_attr(text_prop_attr, wlv.extra_attr);
3347#endif
3348
Bram Moolenaar1306b362022-08-06 15:59:06 +01003349 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003350 }
3351 mb_utf8 = FALSE; // don't draw as UTF-8
3352 }
3353 else if (VIsual_active
3354 && (VIsual_mode == Ctrl_V
3355 || VIsual_mode == 'v')
3356 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003357 && wlv.tocol != MAXCOL
3358 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003359 && (
3360#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003361 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003362#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003363 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003364 {
3365 c = ' ';
3366 --ptr; // put it back at the NUL
3367 }
3368#if defined(LINE_ATTR)
3369 else if ((
3370# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003371 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003372# endif
3373# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003374 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003375# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003376 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003377 ) && (
3378# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003379 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003380# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003381 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003382# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003383 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003384# endif
3385 < wp->w_width)))
3386 {
3387 // Highlight until the right side of the window
3388 c = ' ';
3389 --ptr; // put it back at the NUL
3390
3391 // Remember we do the char for line highlighting.
3392 ++did_line_attr;
3393
3394 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003395 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003396 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003397 || (wp->w_p_list &&
3398 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003399 wlv.char_attr = wlv.line_attr;
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003400#ifdef FEAT_SIGNS
3401 // At end of line: if Sign is present with line highlight, reset char_attr
Christian Brabandte1eaae22023-08-19 22:36:12 +02003402 // but not when cursorline is active
3403 if (sign_present && wlv.sattr.sat_linehl > 0 && wlv.draw_state == WL_LINE
3404 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum))
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003405 wlv.char_attr = wlv.sattr.sat_linehl;
3406#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003407# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003408 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003409 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003410 wlv.diff_hlf = HLF_CHD;
3411 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003412 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003413 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003414 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3415 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003416 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003417 || (wlv.vcol >= left_curline_col
3418 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003419 wlv.char_attr = hl_combine_attr(
3420 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003421 }
3422 }
3423# endif
3424# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003425 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003426 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003427 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003428 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3429 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003430 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003431 if (!wlv.cul_screenline
3432 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003433 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003434 wlv.char_attr = hl_combine_attr(
3435 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003436 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003437 else if (wlv.line_attr)
3438 wlv.char_attr = hl_combine_attr(
3439 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003440 }
3441# endif
3442 }
3443#endif
3444 }
3445
3446#ifdef FEAT_CONCEAL
3447 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003448 && (wp != curwin || lnum != wp->w_cursor.lnum
3449 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003450 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3451 && !(lnum_in_visual_area
3452 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3453 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003454 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003455 if (((prev_syntax_id != syntax_seqnr
3456 && (syntax_flags & HL_CONCEAL) != 0)
3457 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003458 && (syn_get_sub_char() != NUL
3459 || (has_match_conc && match_conc)
3460 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003461 && wp->w_p_cole != 3)
3462 {
3463 // First time at this concealed item: display one
3464 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003465 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003466 c = match_conc;
3467 else if (syn_get_sub_char() != NUL)
3468 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003469 else if (wp->w_lcs_chars.conceal != NUL)
3470 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003471 else
3472 c = ' ';
3473
3474 prev_syntax_id = syntax_seqnr;
3475
Bram Moolenaar1306b362022-08-06 15:59:06 +01003476 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003477 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003478 wlv.vcol += wlv.n_extra;
3479 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003480 {
3481# ifdef FEAT_RIGHTLEFT
3482 if (wp->w_p_rl)
3483 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003484 wlv.col -= wlv.n_extra;
3485 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003486 }
3487 else
3488# endif
3489 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003490 wlv.boguscols += wlv.n_extra;
3491 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003492 }
3493 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003494 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003495 n_attr = 0;
3496 }
zeertzjqb557f482023-08-22 22:07:34 +02003497 else if (skip_cells == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003498 {
3499 is_concealing = TRUE;
zeertzjqb557f482023-08-22 22:07:34 +02003500 skip_cells = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003501 }
3502 mb_c = c;
3503 if (enc_utf8 && utf_char2len(c) > 1)
3504 {
3505 mb_utf8 = TRUE;
3506 u8cc[0] = 0;
3507 c = 0xc0;
3508 }
3509 else
3510 mb_utf8 = FALSE; // don't draw as UTF-8
3511 }
3512 else
3513 {
3514 prev_syntax_id = 0;
3515 is_concealing = FALSE;
3516 }
3517
zeertzjqb557f482023-08-22 22:07:34 +02003518 if (skip_cells > 0 && did_decrement_ptr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003519 // not showing the '>', put pointer back to avoid getting stuck
3520 ++ptr;
3521
3522#endif // FEAT_CONCEAL
3523 }
3524
3525#ifdef FEAT_CONCEAL
3526 // In the cursor line and we may be concealing characters: correct
3527 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003528 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003529 && wp == curwin && lnum == wp->w_cursor.lnum
3530 && conceal_cursor_line(wp)
zeertzjqb557f482023-08-22 22:07:34 +02003531 && (int)wp->w_virtcol <= wlv.vcol + skip_cells)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003532 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003533# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003534 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003535 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003536 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003537# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003538 wp->w_wcol = wlv.col - wlv.boguscols;
3539 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003540 did_wcol = TRUE;
3541 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003542# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003543 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003544# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003545 }
3546#endif
3547
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003548 // Use "wlv.extra_attr", but don't override visual selection
3549 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003550 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3551 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003552 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003553 && (!attr_pri
3554#ifdef FEAT_PROP_POPUP
3555 || (text_prop_flags & PT_FLAG_OVERRIDE)
3556#endif
3557 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003558 {
3559#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003560 if (wlv.line_attr)
3561 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003562 else
3563#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003564 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003565#ifdef FEAT_PROP_POPUP
3566 if (reset_extra_attr)
3567 {
3568 reset_extra_attr = FALSE;
3569 wlv.extra_attr = 0;
3570 }
3571#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003572 }
3573
3574#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3575 // XIM don't send preedit_start and preedit_end, but they send
3576 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3577 // im_is_preediting() here.
3578 if (p_imst == IM_ON_THE_SPOT
3579 && xic != NULL
3580 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003581 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003582 && !p_imdisable
3583 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003584 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003585 {
3586 colnr_T tcol;
3587
3588 if (preedit_end_col == MAXCOL)
3589 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3590 else
3591 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003592 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003593 {
3594 if (feedback_old_attr < 0)
3595 {
3596 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003597 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003598 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003599 wlv.char_attr = im_get_feedback_attr(feedback_col);
3600 if (wlv.char_attr < 0)
3601 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003602 feedback_col++;
3603 }
3604 else if (feedback_old_attr >= 0)
3605 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003606 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003607 feedback_old_attr = -1;
3608 feedback_col = 0;
3609 }
3610 }
3611#endif
3612 // Handle the case where we are in column 0 but not on the first
3613 // character of the line and the user wants us to show us a
3614 // special character (via 'listchars' option "precedes:<char>".
3615 if (lcs_prec_todo != NUL
3616 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003617 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3618 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003619#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003620 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003621#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003622 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003623 && c != NUL)
3624 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003625 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003626 lcs_prec_todo = NUL;
3627 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3628 {
3629 // Double-width character being overwritten by the "precedes"
3630 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003631 wlv.c_extra = MB_FILLER_CHAR;
3632 wlv.c_final = NUL;
3633 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003634 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003635 wlv.extra_attr =
3636 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003637 }
3638 mb_c = c;
3639 if (enc_utf8 && utf_char2len(c) > 1)
3640 {
3641 mb_utf8 = TRUE;
3642 u8cc[0] = 0;
3643 c = 0xc0;
3644 }
3645 else
3646 mb_utf8 = FALSE; // don't draw as UTF-8
3647 if (!attr_pri)
3648 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003649 saved_attr3 = wlv.char_attr; // save current attr
3650 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003651 n_attr3 = 1;
3652 }
3653 }
3654
3655 // At end of the text line or just after the last character.
3656 if ((c == NUL
3657#if defined(LINE_ATTR)
3658 || did_line_attr == 1
3659#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003660 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003661 {
3662#ifdef FEAT_SEARCH_EXTRA
3663 // flag to indicate whether prevcol equals startcol of search_hl or
3664 // one of the matches
3665 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3666 (long)(ptr - line) - (c == NUL));
3667#endif
3668 // Invert at least one char, used for Visual and empty line or
3669 // highlight match at end of line. If it's beyond the last
3670 // char on the screen, just overwrite that one (tricky!) Not
3671 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003672 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003673 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003674 && (VIsual_mode != Ctrl_V
3675 || lnum == VIsual.lnum
3676 || lnum == curwin->w_cursor.lnum)
3677 && c == NUL)
3678#ifdef FEAT_SEARCH_EXTRA
3679 // highlight 'hlsearch' match at end of line
3680 || (prevcol_hl_flag
3681# ifdef FEAT_SYN_HL
3682 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3683 && !(wp == curwin && VIsual_active))
3684# endif
3685# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003686 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003687# endif
3688# if defined(LINE_ATTR)
3689 && did_line_attr <= 1
3690# endif
3691 )
3692#endif
3693 ))
3694 {
3695 int n = 0;
3696
3697#ifdef FEAT_RIGHTLEFT
3698 if (wp->w_p_rl)
3699 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003700 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003701 n = 1;
3702 }
3703 else
3704#endif
3705 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003706 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003707 n = -1;
3708 }
3709 if (n != 0)
3710 {
3711 // At the window boundary, highlight the last character
3712 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003713 wlv.off += n;
3714 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003715 }
3716 else
3717 {
3718 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003719 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003720 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003721 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003722 }
3723#ifdef FEAT_SEARCH_EXTRA
3724 if (area_attr == 0)
3725 {
3726 // Use attributes from match with highest priority among
3727 // 'search_hl' and the match list.
3728 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003729 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003730 }
3731#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003732 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003733 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003734#ifdef FEAT_RIGHTLEFT
3735 if (wp->w_p_rl)
3736 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003737 --wlv.col;
3738 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003739 }
3740 else
3741#endif
3742 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003743 ++wlv.col;
3744 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003745 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003746 ++wlv.vcol;
3747 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003748 }
3749 }
3750
3751 // At end of the text line.
3752 if (c == NUL)
3753 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003754#ifdef FEAT_PROP_POPUP
3755 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003756 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003757 // Put the pointer back to the NUL.
3758 --ptr;
3759 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003760 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003761 else
3762#endif
3763 {
3764 draw_screen_line(wp, &wlv);
3765
3766 // Update w_cline_height and w_cline_folded if the cursor line
3767 // was updated (saves a call to plines() later).
3768 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3769 {
3770 curwin->w_cline_row = startrow;
3771 curwin->w_cline_height = wlv.row - startrow;
3772#ifdef FEAT_FOLDING
3773 curwin->w_cline_folded = FALSE;
3774#endif
3775 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3776 }
3777 break;
3778 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003779 }
3780
3781 // Show "extends" character from 'listchars' if beyond the line end and
3782 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003783 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003784 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003785 && wp->w_p_list
3786 && !wp->w_p_wrap
3787#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003788 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003789#endif
3790 && (
3791#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003792 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003793#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003794 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003795 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003796 || lcs_eol_one > 0
3797 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
zeertzjq6a389722023-08-27 19:04:14 +02003798 || *wlv.p_extra != NUL))
3799#ifdef FEAT_PROP_POPUP
zeertzjq4e26a9a2023-12-03 17:50:47 +01003800 || text_prop_next <= last_textprop_text_idx
zeertzjq6a389722023-08-27 19:04:14 +02003801#endif
3802 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003803 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003804 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003805 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003806 mb_c = c;
3807 if (enc_utf8 && utf_char2len(c) > 1)
3808 {
3809 mb_utf8 = TRUE;
3810 u8cc[0] = 0;
3811 c = 0xc0;
3812 }
3813 else
3814 mb_utf8 = FALSE;
3815 }
3816
3817#ifdef FEAT_SYN_HL
3818 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003819 if (wlv.draw_color_col)
3820 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003821
3822 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3823 // highlight the cursor position itself.
3824 // Also highlight the 'colorcolumn' if it is different than
3825 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003826 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3827 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003828 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003829 if (((wlv.draw_state == WL_LINE
3830 || wlv.draw_state == WL_BRI
3831 || wlv.draw_state == WL_SBR)
3832 && !lnum_in_visual_area
3833 && search_attr == 0
3834 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003835# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003836 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003837# endif
3838 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003839 {
3840 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3841 && lnum != wp->w_cursor.lnum)
3842 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003843 vcol_save_attr = wlv.char_attr;
3844 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3845 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003846 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003847 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003848 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003849 vcol_save_attr = wlv.char_attr;
3850 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003851 }
3852 }
3853#endif
3854
zeertzjq8fc6a1d2023-08-20 18:12:54 +02003855 if (wlv.draw_state == WL_LINE)
3856 vcol_prev = wlv.vcol;
3857
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003858 // Store character to be displayed.
3859 // Skip characters that are left of the screen for 'nowrap'.
zeertzjqb557f482023-08-22 22:07:34 +02003860 if (wlv.draw_state < WL_LINE || skip_cells <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003861 {
3862 // Store the character.
3863#if defined(FEAT_RIGHTLEFT)
3864 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3865 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003866 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003867 --wlv.off;
3868 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003869 }
3870#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003871 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003872 if (enc_dbcs == DBCS_JPNU)
3873 {
3874 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003875 ScreenLines[wlv.off] = 0x8e;
3876 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003877 }
3878 else if (enc_utf8)
3879 {
3880 if (mb_utf8)
3881 {
3882 int i;
3883
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003884 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003885 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003886 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003887 for (i = 0; i < Screen_mco; ++i)
3888 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003889 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003890 if (u8cc[i] == 0)
3891 break;
3892 }
3893 }
3894 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003895 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003896 }
3897 if (multi_attr)
3898 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003899 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003900 multi_attr = 0;
3901 }
3902 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003903 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003904
zeertzjqdb54e982023-09-21 16:33:09 +02003905 if (wlv.draw_state > WL_NR
3906#ifdef FEAT_DIFF
3907 && wlv.filler_todo <= 0
3908#endif
3909 )
3910 ScreenCols[wlv.off] = wlv.vcol;
3911 else
3912 ScreenCols[wlv.off] = -1;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003913
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003914 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3915 {
3916 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003917 ++wlv.off;
3918 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003919 if (enc_utf8)
3920 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003921 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003922 else
3923 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003924 ScreenLines[wlv.off] = mb_c & 0xff;
zeertzjqdb54e982023-09-21 16:33:09 +02003925
Bram Moolenaar1306b362022-08-06 15:59:06 +01003926 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003927#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003928 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003929#endif
3930 )
zeertzjqdb54e982023-09-21 16:33:09 +02003931 ScreenCols[wlv.off] = ++wlv.vcol;
3932 else
3933 ScreenCols[wlv.off] = -1;
3934
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003935 // When "wlv.tocol" is halfway a character, set it to the end
3936 // of the character, otherwise highlighting won't stop.
3937 if (wlv.tocol == wlv.vcol)
3938 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003939
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003940#ifdef FEAT_RIGHTLEFT
3941 if (wp->w_p_rl)
3942 {
3943 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003944 --wlv.off;
3945 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003946 }
3947#endif
3948 }
3949#ifdef FEAT_RIGHTLEFT
3950 if (wp->w_p_rl)
3951 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003952 --wlv.off;
3953 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003954 }
3955 else
3956#endif
3957 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003958 ++wlv.off;
3959 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003960 }
3961 }
3962#ifdef FEAT_CONCEAL
3963 else if (wp->w_p_cole > 0 && is_concealing)
3964 {
zeertzjqb557f482023-08-22 22:07:34 +02003965 --skip_cells;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003966 ++wlv.vcol_off_co;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003967 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003968 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003969 if (wp->w_p_wrap)
3970 {
3971 // Special voodoo required if 'wrap' is on.
3972 //
3973 // Advance the column indicator to force the line
3974 // drawing to wrap early. This will make the line
3975 // take up the same screen space when parts are concealed,
3976 // so that cursor line computations aren't messed up.
3977 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003978 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003979 // trailing junk to be written out of the screen line
3980 // we are building, 'boguscols' keeps track of the number
3981 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003982 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003983 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003984 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003985# ifdef FEAT_RIGHTLEFT
3986 if (wp->w_p_rl)
3987 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003988 wlv.col -= wlv.n_extra;
3989 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003990 }
3991 else
3992# endif
3993 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003994 wlv.col += wlv.n_extra;
3995 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003996 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003997 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003998 n_attr = 0;
3999 }
4000
4001
4002 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
4003 {
4004 // Need to fill two screen columns.
4005# ifdef FEAT_RIGHTLEFT
4006 if (wp->w_p_rl)
4007 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004008 --wlv.boguscols;
4009 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004010 }
4011 else
4012# endif
4013 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004014 ++wlv.boguscols;
4015 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004016 }
4017 }
4018
4019# ifdef FEAT_RIGHTLEFT
4020 if (wp->w_p_rl)
4021 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004022 --wlv.boguscols;
4023 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004024 }
4025 else
4026# endif
4027 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004028 ++wlv.boguscols;
4029 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004030 }
4031 }
4032 else
4033 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004034 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004035 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004036 wlv.vcol += wlv.n_extra;
4037 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004038 n_attr = 0;
4039 }
4040 }
4041
4042 }
4043#endif // FEAT_CONCEAL
4044 else
zeertzjqb557f482023-08-22 22:07:34 +02004045 --skip_cells;
4046
4047 if (wlv.draw_state > WL_NR && skipped_cells > 0)
4048 {
4049 wlv.vcol += skipped_cells;
4050 skipped_cells = 0;
4051 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004052
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004053 // Only advance the "wlv.vcol" when after the 'number' or
4054 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004055 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004056#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004057 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004058#endif
4059 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004060 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004061
4062#ifdef FEAT_SYN_HL
4063 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004064 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004065#endif
4066
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004067 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01004068 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
4069 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004070
4071 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01004072 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004073 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004074 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004075 if (wlv.n_attr_skip > 0)
4076 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004077
4078 // At end of screen line and there is more to come: Display the line
4079 // so far. If there is no more to display it is caught above.
4080 if ((
4081#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004082 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004083#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004084 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01004085 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02004086 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004087#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004088 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004089#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004090#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004091 || text_prop_above || text_prop_follows
zeertzjq4e26a9a2023-12-03 17:50:47 +01004092 || text_prop_next <= last_textprop_text_idx
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004093#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01004094 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01004095 && wlv.p_extra != at_end_str)
4096 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
4097 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004098 )
4099 {
4100#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01004101 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01004102 wlv_screen_line(wp, &wlv, FALSE);
4103 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004104 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004105 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004106#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01004107 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004108#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004109 ++wlv.row;
4110 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004111
4112 // When not wrapping and finished diff lines, or when displayed
4113 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01004114 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004115#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004116 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004117#endif
4118#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01004119 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004120#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01004121 ) || lcs_eol_one == -1)
4122#ifdef FEAT_PROP_POPUP
4123 && !text_prop_follows
4124#endif
4125 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004126 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004127#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004128 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004129 {
4130 // do not output more of the line, only the "below" prop
4131 ptr += STRLEN(ptr);
4132# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004133 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004134# endif
4135 }
4136#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004137
4138 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004139 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004140#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004141 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004142#endif
4143 )
4144 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004145 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
4146 draw_vsep_win(wp, wlv.row);
4147 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004148 }
4149
4150 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004151 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004152 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004153 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004154 break;
4155 }
4156
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004157 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004158#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004159 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004160#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004161#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004162 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004163#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004164 && wp->w_width == Columns)
4165 {
4166 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004167 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004168
4169 // Special trick to make copy/paste of wrapped lines work with
4170 // xterm/screen: write an extra character beyond the end of
4171 // the line. This will work with all terminal types
4172 // (regardless of the xn,am settings).
4173 // Only do this on a fast tty.
4174 // Only do this if the cursor is on the current line
4175 // (something has been written in it).
4176 // Don't do this for the GUI.
4177 // Don't do this for double-width characters.
4178 // Don't do this for a window not at the right screen border.
4179 if (p_tf
4180#ifdef FEAT_GUI
4181 && !gui.in_use
4182#endif
4183 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004184 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4185 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004186 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004187 || (*mb_off2cells)(
4188 LineOffset[wlv.screen_row - 1]
4189 + (int)Columns - 2,
4190 LineOffset[wlv.screen_row]
4191 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004192 {
4193 // First make sure we are at the end of the screen line,
4194 // then output the same character again to let the
4195 // terminal know about the wrap. If the terminal doesn't
4196 // auto-wrap, we overwrite the character.
4197 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004198 screen_char(LineOffset[wlv.screen_row - 1]
4199 + (unsigned)Columns - 1,
4200 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004201
4202 // When there is a multi-byte character, just output a
4203 // space to keep it simple.
4204 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004205 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004206 out_char(' ');
4207 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004208 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004209 + (Columns - 1)]);
4210 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004211 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004212 screen_start(); // don't know where cursor is now
4213 }
4214 }
4215
Bram Moolenaar1306b362022-08-06 15:59:06 +01004216 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004217
Bram Moolenaareed9d462021-02-15 20:38:25 +01004218 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004219#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004220 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004221# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004222 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004223# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004224 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004225 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004226#endif
4227#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004228 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004229 // When the filler lines are actually below the last line of the
4230 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004231 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004232 break;
4233#endif
4234 }
4235
4236 } // for every character in the line
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004237#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004238 vim_free(text_props);
4239 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004240 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004241#endif
4242
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004243 vim_free(wlv.p_extra_free);
zeertzjq58e1e012023-06-04 18:46:28 +01004244 vim_free(wlv.saved_p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004245 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004246}