blob: 04e7ed8d5f0229d7b013685fae35aa345a9bbb75 [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
Bram Moolenaar1306b362022-08-06 15:59:06 +0100174} winlinevars_T;
175
176// draw_state values for items that are drawn in sequence:
177#define WL_START 0 // nothing done yet, must be zero
Martin Tournoij7904fa42022-10-04 16:28:45 +0100178#define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar1306b362022-08-06 15:59:06 +0100179#ifdef FEAT_FOLDING
180# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
181#else
182# define WL_FOLD WL_CMDLINE
183#endif
184#ifdef FEAT_SIGNS
185# define WL_SIGN (WL_FOLD + 1) // column for signs
186#else
187# define WL_SIGN WL_FOLD // column for signs
188#endif
189#define WL_NR (WL_SIGN + 1) // line number
190#ifdef FEAT_LINEBREAK
191# define WL_BRI (WL_NR + 1) // 'breakindent'
192#else
193# define WL_BRI WL_NR
194#endif
195#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
196# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
197#else
198# define WL_SBR WL_BRI
199#endif
200#define WL_LINE (WL_SBR + 1) // text in the line
201
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100202#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200203/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000204 * Return TRUE if CursorLineSign highlight is to be used.
205 */
206 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100207use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000208{
209 return wp->w_p_cul
210 && lnum == wp->w_cursor.lnum
211 && (wp->w_p_culopt_flags & CULOPT_NBR);
212}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100213#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000214
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100215
216#ifdef FEAT_FOLDING
217/*
218 * Setup for drawing the 'foldcolumn', if there is one.
219 */
220 static void
221handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
222{
223 int fdc = compute_foldcolumn(wp, 0);
224
225 if (fdc <= 0)
226 return;
227
228 // Allocate a buffer, "wlv->extra[]" may already be in use.
229 vim_free(wlv->p_extra_free);
230 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
Yegappan Lakshmanan465de3a2022-12-26 12:50:04 +0000231 if (wlv->p_extra_free == NULL)
232 return;
233
234 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
zeertzjq58e1e012023-06-04 18:46:28 +0100235 wp, FALSE, wlv->lnum);
Yegappan Lakshmanan465de3a2022-12-26 12:50:04 +0000236 wlv->p_extra_free[wlv->n_extra] = NUL;
237 wlv->p_extra = wlv->p_extra_free;
238 wlv->c_extra = NUL;
239 wlv->c_final = NUL;
240 if (use_cursor_line_highlight(wp, wlv->lnum))
241 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
242 else
243 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100244}
245#endif
246
247#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000248/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100249 * Get information needed to display the sign in line "wlv->lnum" in window
250 * "wp".
251 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200252 * Otherwise the sign is going to be displayed in the sign column.
253 */
254 static void
255get_sign_display_info(
256 int nrcol,
257 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100258 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200259{
260 int text_sign;
261# ifdef FEAT_SIGN_ICONS
262 int icon_sign;
263# endif
264
265 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100266 wlv->c_extra = ' ';
267 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200268 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100269 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200270 else
271 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100272 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100273 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000274 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100275 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100276 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200277 }
278
Bram Moolenaar1306b362022-08-06 15:59:06 +0100279 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200280#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100281 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200282#endif
283 )
284 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100285 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200286# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100287 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200288 if (gui.in_use && icon_sign != 0)
289 {
290 // Use the image in this position.
291 if (nrcol)
292 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100293 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100294 sprintf((char *)wlv->extra, "%-*c ",
295 number_width(wp), SIGN_BYTE);
296 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100297 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200298 }
299 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100300 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200301# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100302 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
303 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200304 {
305 if (nrcol)
306 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100307 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100308 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200309 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100310 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100311 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200312 }
313 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100314 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200315 }
316# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100317 wlv->c_final = NUL;
318 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200319 }
320 else
321# endif
322 if (text_sign != 0)
323 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100324 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100325 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200326 {
327 if (nrcol)
328 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100329 int width = number_width(wp) - 2;
330 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200331
332 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100333 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100334 vim_snprintf((char *)wlv->extra + n,
335 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100336 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200337 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100338 wlv->c_extra = NUL;
339 wlv->c_final = NUL;
340 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200341 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000342
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100343 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100344 && wlv->sattr.sat_culhl > 0)
345 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000346 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100347 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200348 }
349 }
350}
351#endif
352
Bram Moolenaard7657e92022-09-20 18:59:30 +0100353/*
354 * Display the absolute or relative line number. After the first row fill with
355 * blanks when the 'n' flag isn't in 'cpo'.
356 */
357 static void
358handle_lnum_col(
359 win_T *wp,
360 winlinevars_T *wlv,
361 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100362 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100363{
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100364 int has_cpo_n = vim_strchr(p_cpo, CPO_NUMCOL) != NULL;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100365 int lnum_row = wlv->startrow + wlv->filler_lines
366#ifdef FEAT_PROP_POPUP
367 + wlv->text_prop_above_count
368#endif
369 ;
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100370
Bram Moolenaard7657e92022-09-20 18:59:30 +0100371 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100372 && (wlv->row <= lnum_row || !has_cpo_n)
Bram Moolenaar37251162022-10-06 20:48:00 +0100373 // there is no line number in a wrapped line when "n" is in
374 // 'cpoptions', but 'breakindent' assumes it anyway.
375 && !((has_cpo_n
376#ifdef FEAT_LINEBREAK
377 && !wp->w_p_bri
378#endif
379 ) && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100380 {
381#ifdef FEAT_SIGNS
382 // If 'signcolumn' is set to 'number' and a sign is present
383 // in 'lnum', then display the sign instead of the line
384 // number.
385 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
386 get_sign_display_info(TRUE, wp, wlv);
387 else
388#endif
389 {
390 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100391 // When there are text properties above the line put the line number
392 // below them.
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100393 if (wlv->row == lnum_row
zeertzjq88bb3e02023-05-02 20:52:59 +0100394 && (wp->w_skipcol == 0 || wlv->row > 0
Bram Moolenaareb4de622022-10-15 13:42:17 +0100395 || (wp->w_p_nu && wp->w_p_rnu)))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100396 {
397 long num;
398 char *fmt = "%*ld ";
399
400 if (wp->w_p_nu && !wp->w_p_rnu)
401 // 'number' + 'norelativenumber'
402 num = (long)wlv->lnum;
403 else
404 {
405 // 'relativenumber', don't use negative numbers
406 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
407 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
408 {
409 // 'number' + 'relativenumber'
410 num = wlv->lnum;
411 fmt = "%-*ld ";
412 }
413 }
414
415 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100416 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100417 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
418 ++wlv->p_extra)
419 *wlv->p_extra = '-';
420#ifdef FEAT_RIGHTLEFT
421 if (wp->w_p_rl) // reverse line numbers
422 {
423 char_u *p1, *p2;
424 int t;
425
426 // like rl_mirror(), but keep the space at the end
427 p2 = skipwhite(wlv->extra);
428 p2 = skiptowhite(p2) - 1;
429 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
430 {
431 t = *p1;
432 *p1 = *p2;
433 *p2 = t;
434 }
435 }
436#endif
437 wlv->p_extra = wlv->extra;
438 wlv->c_extra = NUL;
439 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100440 }
441 else
442 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100443 wlv->c_extra = ' ';
444 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100445 }
446 wlv->n_extra = number_width(wp) + 1;
447 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
448#ifdef FEAT_SYN_HL
449 // When 'cursorline' is set highlight the line number of
450 // the current line differently.
451 // When 'cursorlineopt' does not have "line" only
452 // highlight the line number itself.
453 // TODO: Can we use CursorLine instead of CursorLineNr
454 // when CursorLineNr isn't set?
455 if (wp->w_p_cul
456 && wlv->lnum == wp->w_cursor.lnum
457 && (wp->w_p_culopt_flags & CULOPT_NBR)
458 && (wlv->row == wlv->startrow + wlv->filler_lines
459 || (wlv->row > wlv->startrow + wlv->filler_lines
460 && (wp->w_p_culopt_flags & CULOPT_LINE))))
461 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
462#endif
463 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
464 && HL_ATTR(HLF_LNA) != 0)
465 // Use LineNrAbove
466 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
467 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
468 && HL_ATTR(HLF_LNB) != 0)
469 // Use LineNrBelow
470 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
471 }
472#ifdef FEAT_SIGNS
473 if (num_attr)
474 wlv->char_attr = num_attr;
475#endif
476 }
477}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100478
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100479#ifdef FEAT_LINEBREAK
480 static void
481handle_breakindent(win_T *wp, winlinevars_T *wlv)
482{
483 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100484 && *get_showbreak_value(wp) != NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100485 // draw indent after showbreak value
486 wlv->draw_state = WL_BRI;
487 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
488 // After the showbreak, draw the breakindent
489 wlv->draw_state = WL_BRI - 1;
490
491 // draw 'breakindent': indent wrapped text accordingly
492 if (wlv->draw_state == WL_BRI - 1)
493 {
494 wlv->draw_state = WL_BRI;
495 // if wlv->need_showbreak is set, breakindent also applies
496 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
497# ifdef FEAT_DIFF
498 && wlv->filler_lines == 0
499# endif
500# ifdef FEAT_PROP_POPUP
501 && !wlv->dont_use_showbreak
502# endif
503 )
504 {
505 wlv->char_attr = 0;
506# ifdef FEAT_DIFF
507 if (wlv->diff_hlf != (hlf_T)0)
508 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
509# endif
510 wlv->p_extra = NULL;
511 wlv->c_extra = ' ';
512 wlv->c_final = NUL;
513 wlv->n_extra = get_breakindent_win(wp,
514 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
515 if (wlv->row == wlv->startrow)
516 {
517 wlv->n_extra -= win_col_off2(wp);
518 if (wlv->n_extra < 0)
519 wlv->n_extra = 0;
520 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100521 if (wp->w_skipcol > 0 && wlv->startrow == 0
522 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100523 wlv->need_showbreak = FALSE;
524 // Correct end of highlighted area for 'breakindent',
525 // required when 'linebreak' is also set.
526 if (wlv->tocol == wlv->vcol)
527 wlv->tocol += wlv->n_extra;
528 }
529 }
530}
531#endif
532
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100533#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
534 static void
535handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
536{
537# ifdef FEAT_DIFF
538 if (wlv->filler_todo > 0)
539 {
540 // Draw "deleted" diff line(s).
541 if (char2cells(wp->w_fill_chars.diff) > 1)
542 {
543 wlv->c_extra = '-';
544 wlv->c_final = NUL;
545 }
546 else
547 {
548 wlv->c_extra = wp->w_fill_chars.diff;
549 wlv->c_final = NUL;
550 }
551# ifdef FEAT_RIGHTLEFT
552 if (wp->w_p_rl)
553 wlv->n_extra = wlv->col + 1;
554 else
555# endif
556 wlv->n_extra = wp->w_width - wlv->col;
557 wlv->char_attr = HL_ATTR(HLF_DED);
558 }
559# endif
560
561# ifdef FEAT_LINEBREAK
562 char_u *sbr = get_showbreak_value(wp);
563 if (*sbr != NUL && wlv->need_showbreak)
564 {
565 // Draw 'showbreak' at the start of each broken line.
566 wlv->p_extra = sbr;
567 wlv->c_extra = NUL;
568 wlv->c_final = NUL;
569 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100570 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100571 wlv->need_showbreak = FALSE;
572 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100573
574 // Correct start of highlighted area for 'showbreak'.
575 if (wlv->fromcol >= wlv->vcol && wlv->fromcol < wlv->vcol_sbr)
576 wlv->fromcol = wlv->vcol_sbr;
577
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100578 // Correct end of highlighted area for 'showbreak',
579 // required when 'linebreak' is also set.
580 if (wlv->tocol == wlv->vcol)
581 wlv->tocol += wlv->n_extra;
582 // combine 'showbreak' with 'wincolor'
583 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
584# ifdef FEAT_SYN_HL
585 // combine 'showbreak' with 'cursorline'
586 if (wlv->cul_attr != 0)
587 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
588# endif
589 }
590# endif
591}
592#endif
593
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100594#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100595/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100596 * Return the cell size of virtual text after truncation.
597 */
598 static int
599textprop_size_after_trunc(
600 win_T *wp,
601 int flags, // TP_FLAG_ALIGN_*
602 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100603 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100604 char_u *text,
605 int *n_used_ptr)
606{
607 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100608 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100609 int len = (int)STRLEN(text);
610 int strsize = 0;
611 int n_used;
612
Bram Moolenaar7e017462022-10-11 21:02:09 +0100613 // if the remaining size is to small and 'wrap' is set we wrap anyway and
614 // use the next line
615 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100616 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100617 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100618 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100619 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
620 {
621 int clen = ptr2cells(text + n_used);
622
623 if (strsize + clen > space)
624 break;
625 strsize += clen;
626 }
627 *n_used_ptr = n_used;
628 return strsize;
629}
630
631/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100632 * Take care of padding, right-align and truncation of virtual text after a
633 * line.
634 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
635 * padding, right-align and truncation. Otherwise only the size is computed.
636 * When "n_attr" is NULL returns the number of screen cells used.
637 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100638 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100639 int
640text_prop_position(
641 win_T *wp,
642 textprop_T *tp,
porygonisaduck38854b52022-11-27 20:55:05 +0000643 int vcol, // current text column
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100644 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100645 int *n_extra, // nr of bytes for virtual text
646 char_u **p_extra, // virtual text
647 int *n_attr, // attribute cells, NULL if not used
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000648 int *n_attr_skip, // cells to skip attr, NULL if not used
649 int do_skip) // skip_cells is not zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200650{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100651 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100652 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100653 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
Bram Moolenaar1aeb3eb2023-01-01 14:04:51 +0000654 int wrap = tp->tp_col < MAXCOL || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100655 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
porygonisaduck38854b52022-11-27 20:55:05 +0000656 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100657 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100658 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100659 int before = room; // spaces before the text
660 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100661 int n_used = *n_extra;
662 char_u *l = NULL;
663 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100664 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100665 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200666
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100667 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100668 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100669 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100670
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100671 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100672 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100673 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100674 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar2354b662023-04-23 21:42:25 +0100675 if (after < 0)
676 {
677 // text "above" has too much padding to fit
678 padding += after;
679 after = 0;
680 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100681 }
682 else
683 {
684 // Right-align: fill with before
685 if (right)
686 before -= cells;
porygonisaduck38854b52022-11-27 20:55:05 +0000687
688 // Below-align: empty line add one character
Bram Moolenaar7c02ad92022-11-29 21:37:13 +0000689 if (below && vcol == 0 && col_with_padding == col_off
690 && wp->w_width - col_off == before)
691 col_with_padding += 1;
porygonisaduck38854b52022-11-27 20:55:05 +0000692
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100693 if (before < 0
694 || !(right || below)
porygonisaduck38854b52022-11-27 20:55:05 +0000695 || (below ? (col_with_padding <= col_off || !wp->w_p_wrap)
696 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100697 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100698 if (right && (wrap
699 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100700 {
701 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100702 before = wp->w_width - col_off - strsize + room;
703 if (before < 0)
704 before = 0;
705 else
706 n_used = *n_extra;
707 }
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000708 else if (below && before > vcol && do_skip)
709 before -= vcol;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100710 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100711 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100712 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100713 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100714
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100715 // With 'nowrap' add one to show the "extends" character if needed (it
716 // doesn't show if the text just fits).
717 if (!wp->w_p_wrap
718 && n_used < *n_extra
719 && wp->w_lcs_chars.ext != NUL
720 && wp->w_p_list)
721 ++n_used;
722
723 // add 1 for NUL, 2 for when '…' is used
724 if (n_attr != NULL)
Christian Brabandtf1cc4d52023-08-12 00:14:14 +0200725 l = alloc(n_used + before + after + (padding > 0 ? padding : 0) + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100726 if (n_attr == NULL || l != NULL)
727 {
728 int off = 0;
729
730 if (n_attr != NULL)
731 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100732 vim_memset(l, ' ', before);
733 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100734 if (padding > 0)
735 {
736 vim_memset(l + off, ' ', padding);
737 off += padding;
738 }
739 vim_strncpy(l + off, *p_extra, n_used);
740 off += n_used;
741 }
742 else
743 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100744 off = before + after + padding + n_used;
745 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100746 }
747 if (n_attr != NULL)
748 {
749 if (n_used < *n_extra && wp->w_p_wrap)
750 {
751 char_u *lp = l + off - 1;
752
753 if (has_mbyte)
754 {
h-east4c42c7e2023-04-17 21:44:57 +0100755 char_u buf[MB_MAXBYTES + 1];
756 char_u *cp = buf;
757
758 // change the last character to '…', converted to the
759 // current 'encoding'
760 STRCPY(buf, "…");
761 if (!enc_utf8)
762 {
763 vimconv_T vc;
764
765 vc.vc_type = CONV_NONE;
766 convert_setup(&vc, (char_u *)"utf-8", p_enc);
767 if (vc.vc_type != CONV_NONE)
768 {
769 cp = string_convert(&vc, buf, NULL);
770 if (cp == NULL)
771 {
772 // when conversion fails use '>'
773 cp = buf;
774 STRCPY(buf, ">");
775 }
776 convert_setup(&vc, NULL, NULL);
777 }
778 }
779
780 lp -= (*mb_ptr2cells)(cp) - 1;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100781 lp -= (*mb_head_off)(l, lp);
h-east4c42c7e2023-04-17 21:44:57 +0100782 STRCPY(lp, cp);
Bram Moolenaar13845c42022-10-09 15:26:03 +0100783 n_used = lp - l + 3 - before - padding;
h-east4c42c7e2023-04-17 21:44:57 +0100784 if (cp != buf)
785 vim_free(cp);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100786 }
787 else
788 // change last character to '>'
789 *lp = '>';
790 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100791 else if (after > 0)
792 {
793 vim_memset(l + off, ' ', after);
794 l[off + after] = NUL;
795 }
796
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100797 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100798 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100799 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100800 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100801 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100802
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000803 // n_attr_skip will not be decremented before draw_state is
804 // WL_LINE
Christian Brabandtf1cc4d52023-08-12 00:14:14 +0200805 *n_attr_skip = before + (padding > 0 ? padding : 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100806 }
807 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100808 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100809
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100810 if (n_attr == NULL)
811 return cells;
812 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200813}
814#endif
815
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100816/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100817 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100818 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
819 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100820 */
821 static void
822wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
823{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100824 if (wlv->row == 0 && wp->w_skipcol > 0
825#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100826 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100827 && *get_showbreak_value(wp) == NUL
828#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100829 // do not overwrite the 'listchars' "precedes" text with "<<<"
830 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100831 {
832 int off = (int)(current_ScreenLine - ScreenLines);
zeertzjqecb87dd2023-06-03 19:45:06 +0100833 int max_off = off + screen_Columns;
Bram Moolenaareb4de622022-10-15 13:42:17 +0100834 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100835
Bram Moolenaareb4de622022-10-15 13:42:17 +0100836 if (wp->w_p_nu && wp->w_p_rnu)
837 // Do not overwrite the line number, change "123 text" to
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100838 // "123<<<xt".
Bram Moolenaareb4de622022-10-15 13:42:17 +0100839 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
840 {
841 ++off;
842 ++skip;
843 }
844
845 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100846 {
zeertzjqecb87dd2023-06-03 19:45:06 +0100847 if ((*mb_off2cells)(off, max_off) > 1)
848 // When the first half of a double-width character is
849 // overwritten, change the second half to a space.
850 ScreenLines[off + 1] = ' ';
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100851 ScreenLines[off] = '<';
852 if (enc_utf8)
853 ScreenLinesUC[off] = 0;
854 ScreenAttrs[off] = HL_ATTR(HLF_AT);
855 ++off;
856 }
857 }
858
859 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
860 negative_width ? -wp->w_width : wp->w_width,
861 wlv->screen_line_flags);
862}
863
864/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100865 * Called when finished with the line: draw the screen line and handle any
866 * highlighting until the right of the window.
867 */
868 static void
869draw_screen_line(win_T *wp, winlinevars_T *wlv)
870{
871#ifdef FEAT_SYN_HL
872 long v;
873
874 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
875 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100876 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100877 else
878 v = wp->w_leftcol;
879
880 // check if line ends before left margin
881 if (wlv->vcol < v + wlv->col - win_col_off(wp))
882 wlv->vcol = v + wlv->col - win_col_off(wp);
883# ifdef FEAT_CONCEAL
884 // Get rid of the boguscols now, we want to draw until the right
885 // edge for 'cursorcolumn'.
886 wlv->col -= wlv->boguscols;
887 wlv->boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000888# define VCOL_HLC (wlv->vcol - wlv->vcol_off_co - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100889# else
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000890# define VCOL_HLC (wlv->vcol - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100891# endif
892
893 if (wlv->draw_color_col)
894 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
895
896 if (((wp->w_p_cuc
897 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
898 && (int)wp->w_virtcol <
899 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
900 && wlv->lnum != wp->w_cursor.lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000901 || wlv->draw_color_col
902# ifdef LINE_ATTR
903 || wlv->line_attr != 0
904# endif
905 || wlv->win_attr != 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100906# ifdef FEAT_RIGHTLEFT
907 && !wp->w_p_rl
908# endif
909 )
910 {
911 int rightmost_vcol = 0;
912 int i;
913
914 if (wp->w_p_cuc)
915 rightmost_vcol = wp->w_virtcol;
916 if (wlv->draw_color_col)
917 // determine rightmost colorcolumn to possibly draw
918 for (i = 0; wlv->color_cols[i] >= 0; ++i)
919 if (rightmost_vcol < wlv->color_cols[i])
920 rightmost_vcol = wlv->color_cols[i];
921
922 while (wlv->col < wp->w_width)
923 {
924 ScreenLines[wlv->off] = ' ';
925 if (enc_utf8)
926 ScreenLinesUC[wlv->off] = 0;
927 ScreenCols[wlv->off] = MAXCOL;
928 ++wlv->col;
929 if (wlv->draw_color_col)
930 wlv->draw_color_col = advance_color_col(
931 VCOL_HLC, &wlv->color_cols);
932
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000933 int attr = wlv->win_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100934 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000935 attr = HL_ATTR(HLF_CUC);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100936 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000937 attr = HL_ATTR(HLF_MC);
938# ifdef LINE_ATTR
939 else if (wlv->line_attr != 0)
940 attr = wlv->line_attr;
941# endif
942 ScreenAttrs[wlv->off++] = attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100943
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000944 if (VCOL_HLC >= rightmost_vcol
945# ifdef LINE_ATTR
946 && wlv->line_attr == 0
947# endif
948 && wlv->win_attr == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100949 break;
950
951 ++wlv->vcol;
952 }
953 }
954#endif
955
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100956 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100957 ++wlv->row;
958 ++wlv->screen_row;
959}
960#undef VCOL_HLC
961
962/*
963 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100964 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100965 */
966 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100967win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100968{
969 wlv->col = 0;
970 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
971
972#ifdef FEAT_RIGHTLEFT
973 if (wp->w_p_rl)
974 {
975 // Rightleft window: process the text in the normal direction, but put
976 // it in current_ScreenLine[] from right to left. Start at the
977 // rightmost column of the window.
978 wlv->col = wp->w_width - 1;
979 wlv->off += wlv->col;
980 wlv->screen_line_flags |= SLF_RIGHTLEFT;
981 }
982#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100983 if (save_extra)
984 {
985 // reset the drawing state for the start of a wrapped line
986 wlv->draw_state = WL_START;
987 wlv->saved_n_extra = wlv->n_extra;
988 wlv->saved_p_extra = wlv->p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +0100989 vim_free(wlv->saved_p_extra_free);
990 wlv->saved_p_extra_free = wlv->p_extra_free;
991 wlv->p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000992 wlv->saved_extra_attr = wlv->extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000993 wlv->saved_n_attr_skip = wlv->n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000994 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100995 wlv->saved_c_extra = wlv->c_extra;
996 wlv->saved_c_final = wlv->c_final;
997#ifdef FEAT_SYN_HL
998 if (!(wlv->cul_screenline
999# ifdef FEAT_DIFF
1000 && wlv->diff_hlf == (hlf_T)0
1001# endif
1002 ))
1003 wlv->saved_char_attr = wlv->char_attr;
1004 else
1005#endif
1006 wlv->saved_char_attr = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001007
1008 // these are not used until restored in win_line_continue()
Bram Moolenaar1306b362022-08-06 15:59:06 +01001009 wlv->n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001010 wlv->n_attr_skip = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001011 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001012}
1013
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001014/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001015 * Called when wlv->draw_state is set to WL_LINE.
1016 */
1017 static void
1018win_line_continue(winlinevars_T *wlv)
1019{
1020 if (wlv->saved_n_extra > 0)
1021 {
1022 // Continue item from end of wrapped line.
1023 wlv->n_extra = wlv->saved_n_extra;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001024 wlv->saved_n_extra = 0;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001025 wlv->c_extra = wlv->saved_c_extra;
1026 wlv->c_final = wlv->saved_c_final;
1027 wlv->p_extra = wlv->saved_p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +01001028 vim_free(wlv->p_extra_free);
1029 wlv->p_extra_free = wlv->saved_p_extra_free;
1030 wlv->saved_p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001031 wlv->extra_attr = wlv->saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001032 wlv->n_attr_skip = wlv->saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001033 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001034 wlv->char_attr = wlv->saved_char_attr;
1035 }
1036 else
1037 wlv->char_attr = wlv->win_attr;
1038}
1039
zeertzjqb7acea12022-12-12 13:20:43 +00001040#ifdef FEAT_SYN_HL
1041 static void
1042apply_cursorline_highlight(
1043 winlinevars_T *wlv,
1044 int sign_present UNUSED)
1045{
1046 wlv->cul_attr = HL_ATTR(HLF_CUL);
1047# ifdef FEAT_SIGNS
1048 // Combine the 'cursorline' and sign highlighting, depending on
1049 // the sign priority.
1050 if (sign_present && wlv->sattr.sat_linehl > 0)
1051 {
1052 if (wlv->sattr.sat_priority >= 100)
1053 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1054 else
1055 wlv->line_attr = hl_combine_attr(wlv->line_attr, wlv->cul_attr);
1056 }
1057 else
1058# endif
1059# if defined(FEAT_QUICKFIX)
1060 // let the line attribute overrule 'cursorline', otherwise
1061 // it disappears when both have background set;
1062 // 'cursorline' can use underline or bold to make it show
1063 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1064# else
1065 wlv->line_attr = wlv->cul_attr;
1066# endif
1067}
1068#endif
1069
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001070/*
Luuk van Baal30805a12023-05-27 22:22:10 +01001071 * Display line "lnum" of window "wp" on the screen.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001072 * Start at row "startrow", stop when "endrow" is reached.
Luuk van Baal30805a12023-05-27 22:22:10 +01001073 * When "number_only" is TRUE only update the number column.
1074 * "spv" is used to store information for spell checking, kept between
1075 * sequential calls for the same window.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001076 * wp->w_virtcol needs to be valid.
1077 *
1078 * Return the number of last row the line occupies.
1079 */
1080 int
1081win_line(
1082 win_T *wp,
1083 linenr_T lnum,
1084 int startrow,
1085 int endrow,
Luuk van Baal30805a12023-05-27 22:22:10 +01001086 int number_only,
1087 spellvars_T *spv UNUSED)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001088{
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001089 winlinevars_T wlv; // variables passed between functions
1090
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001091 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001092 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001093 char_u *line; // current line
1094 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001095
Bram Moolenaar1306b362022-08-06 15:59:06 +01001096#ifdef FEAT_PROP_POPUP
1097 char_u *p_extra_free2 = NULL; // another p_extra to be freed
1098#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001099#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001100 int in_linebreak = FALSE; // n_extra set for showing linebreak
1101#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001102 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +01001103 // displaying eol at end-of-line
1104 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001105 int lcs_prec_todo = wp->w_lcs_chars.prec;
1106 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001107
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001108 int n_attr = 0; // chars with special attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001109 int saved_attr2 = 0; // char_attr saved for n_attr
1110 int n_attr3 = 0; // chars with overruling special attr
1111 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001112
zeertzjqb557f482023-08-22 22:07:34 +02001113 int skip_cells = 0; // nr of cells to skip for w_leftcol or
1114 // w_skipcol or concealing
1115 int skipped_cells = 0; // nr of skipped cells for virtual text
1116 // to be added to wlv.vcol later
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001117 int fromcol_prev = -2; // start of inverting after cursor
1118 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001119 int lnum_in_visual_area = FALSE;
1120 pos_T pos;
1121 long v;
1122
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001123 int attr_pri = FALSE; // char_attr has priority
1124 int area_highlighting = FALSE; // Visual or incsearch highlighting
1125 // in this line
1126 int vi_attr = 0; // attributes for Visual and incsearch
1127 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001128 int area_attr = 0; // attributes desired by highlighting
1129 int search_attr = 0; // attributes desired by 'hlsearch'
1130#ifdef FEAT_SYN_HL
1131 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1132 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001133 int prev_syntax_col = -1; // column of prev_syntax_attr
1134 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001135 int has_syntax = FALSE; // this buffer has syntax highl.
1136 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001137#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001138#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001139 int did_line = FALSE; // set to TRUE when line text done
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001140 int text_prop_count;
1141 int text_prop_next = 0; // next text property to use
1142 textprop_T *text_props = NULL;
1143 int *text_prop_idxs = NULL;
1144 int text_props_active = 0;
1145 proptype_T *text_prop_type = NULL;
1146 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001147 int text_prop_attr_comb = 0; // text_prop_attr combined with
1148 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001149 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001150 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001151 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001152 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001153 int saved_search_attr = 0; // search_attr to be used when n_extra
1154 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001155 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001156 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001157#endif
1158#ifdef FEAT_SPELL
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001159 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001160# define SPWORDLEN 150
1161 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1162 int nextlinecol = 0; // column where nextline[] starts
1163 int nextline_idx = 0; // index in nextline[] where next line
1164 // starts
1165 int spell_attr = 0; // attributes desired by spelling
1166 int word_end = 0; // last byte with same spell_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001167 int cur_checked_col = 0; // checked column for current line
1168#endif
1169 int extra_check = 0; // has extra highlighting
1170 int multi_attr = 0; // attributes desired by multibyte
1171 int mb_l = 1; // multi-byte byte length
1172 int mb_c = 0; // decoded multi-byte character
1173 int mb_utf8 = FALSE; // screen char is UTF-8 char
1174 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001175#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001176 int change_start = MAXCOL; // first col of changed area
1177 int change_end = -1; // last col of changed area
1178#endif
1179 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001180 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001181 int in_multispace = FALSE; // in multiple consecutive spaces
1182 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001183#ifdef LINE_ATTR
Bram Moolenaarbf915842022-08-06 22:38:02 +01001184 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001185#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001186 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001187 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001188#ifdef FEAT_ARABIC
1189 int prev_c = 0; // previous Arabic character
1190 int prev_c1 = 0; // first composing char for prev_c
1191#endif
1192#if defined(LINE_ATTR)
1193 int did_line_attr = 0;
1194#endif
1195#ifdef FEAT_TERMINAL
1196 int get_term_attr = FALSE;
1197#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001198
Martin Tournoijba43e762022-10-13 22:12:15 +01001199#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001200 // margin columns for the screen line, needed for when 'cursorlineopt'
1201 // contains "screenline"
1202 int left_curline_col = 0;
1203 int right_curline_col = 0;
1204#endif
1205
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001206#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1207 int feedback_col = 0;
1208 int feedback_old_attr = -1;
1209#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001210
1211#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1212 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001213#endif
1214#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001215 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001216#endif
1217#ifdef FEAT_CONCEAL
1218 int syntax_flags = 0;
1219 int syntax_seqnr = 0;
1220 int prev_syntax_id = 0;
1221 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1222 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001223 int did_wcol = FALSE;
1224 int old_boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001225# define VCOL_HLC (wlv.vcol - wlv.vcol_off_co - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001226# define FIX_FOR_BOGUSCOLS \
1227 { \
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001228 wlv.n_extra += wlv.vcol_off_co; \
1229 wlv.vcol -= wlv.vcol_off_co; \
1230 wlv.vcol_off_co = 0; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001231 wlv.col -= wlv.boguscols; \
1232 old_boguscols = wlv.boguscols; \
1233 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001234 }
1235#else
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001236# define VCOL_HLC (wlv.vcol - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001237#endif
1238
1239 if (startrow > endrow) // past the end already!
1240 return startrow;
1241
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001242 CLEAR_FIELD(wlv);
1243
1244 wlv.lnum = lnum;
1245 wlv.startrow = startrow;
1246 wlv.row = startrow;
1247 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001248 wlv.fromcol = -10;
1249 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001250#ifdef FEAT_LINEBREAK
1251 wlv.vcol_sbr = -1;
1252#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001253
1254 if (!number_only)
1255 {
1256 // To speed up the loop below, set extra_check when there is linebreak,
1257 // trailing white space and/or syntax processing to be done.
1258#ifdef FEAT_LINEBREAK
1259 extra_check = wp->w_p_lbr;
1260#endif
1261#ifdef FEAT_SYN_HL
1262 if (syntax_present(wp) && !wp->w_s->b_syn_error
1263# ifdef SYN_TIME_LIMIT
1264 && !wp->w_s->b_syn_slow
1265# endif
1266 )
1267 {
1268 // Prepare for syntax highlighting in this line. When there is an
1269 // error, stop syntax highlighting.
1270 save_did_emsg = did_emsg;
1271 did_emsg = FALSE;
1272 syntax_start(wp, lnum);
1273 if (did_emsg)
1274 wp->w_s->b_syn_error = TRUE;
1275 else
1276 {
1277 did_emsg = save_did_emsg;
1278#ifdef SYN_TIME_LIMIT
1279 if (!wp->w_s->b_syn_slow)
1280#endif
1281 {
1282 has_syntax = TRUE;
1283 extra_check = TRUE;
1284 }
1285 }
1286 }
1287
1288 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001289 wlv.color_cols = wp->w_p_cc_cols;
1290 if (wlv.color_cols != NULL)
1291 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001292#endif
1293
1294#ifdef FEAT_TERMINAL
1295 if (term_show_buffer(wp->w_buffer))
1296 {
1297 extra_check = TRUE;
1298 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001299 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001300 }
1301#endif
1302
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001303 // handle Visual active in this window
1304 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1305 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001306 pos_T *top, *bot;
1307
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001308 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1309 {
1310 // Visual is after curwin->w_cursor
1311 top = &curwin->w_cursor;
1312 bot = &VIsual;
1313 }
1314 else
1315 {
1316 // Visual is before curwin->w_cursor
1317 top = &VIsual;
1318 bot = &curwin->w_cursor;
1319 }
1320 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1321 if (VIsual_mode == Ctrl_V)
1322 {
1323 // block mode
1324 if (lnum_in_visual_area)
1325 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001326 wlv.fromcol = wp->w_old_cursor_fcol;
1327 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001328 }
1329 }
1330 else
1331 {
1332 // non-block mode
1333 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001334 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001335 else if (lnum == top->lnum)
1336 {
1337 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001338 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001339 else
1340 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001341 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001342 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001343 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001344 }
1345 }
1346 if (VIsual_mode != 'V' && lnum == bot->lnum)
1347 {
1348 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1349 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001350 wlv.fromcol = -10;
1351 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001352 }
1353 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001354 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001355 else
1356 {
1357 pos = *bot;
1358 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001359 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1360 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001361 else
1362 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001363 getvvcol(wp, &pos, NULL, NULL,
1364 (colnr_T *)&wlv.tocol);
1365 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001366 }
1367 }
1368 }
1369 }
1370
1371 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001372 if (!highlight_match && lnum == curwin->w_cursor.lnum
1373 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001374#ifdef FEAT_GUI
1375 && !gui.in_use
1376#endif
1377 )
1378 noinvcur = TRUE;
1379
1380 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001381 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001382 {
1383 area_highlighting = TRUE;
1384 vi_attr = HL_ATTR(HLF_V);
1385#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1386 if ((clip_star.available && !clip_star.owned
1387 && clip_isautosel_star())
1388 || (clip_plus.available && !clip_plus.owned
1389 && clip_isautosel_plus()))
1390 vi_attr = HL_ATTR(HLF_VNC);
1391#endif
1392 }
1393 }
1394
1395 // handle 'incsearch' and ":s///c" highlighting
1396 else if (highlight_match
1397 && wp == curwin
1398 && lnum >= curwin->w_cursor.lnum
1399 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1400 {
1401 if (lnum == curwin->w_cursor.lnum)
1402 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001403 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001404 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001405 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001406 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1407 {
1408 pos.lnum = lnum;
1409 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001410 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001411 }
1412 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001413 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001414 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001415 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1416 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001417 area_highlighting = TRUE;
1418 vi_attr = HL_ATTR(HLF_I);
1419 }
1420 }
1421
1422#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001423 wlv.filler_lines = diff_check(wp, lnum);
1424 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001425 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001426 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001427 {
1428 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001429 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001430 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001431 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001432 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001433 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001434 }
1435 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001436 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001437 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001438 area_highlighting = TRUE;
1439 }
1440 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001441 wlv.filler_lines = wp->w_topfill;
1442 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001443#endif
1444
1445#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001446 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001447 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001448 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001449#endif
1450
1451#ifdef LINE_ATTR
1452# ifdef FEAT_SIGNS
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001453 // If this line has a sign with line highlighting set wlv.line_attr.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001454 if (sign_present)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001455 wlv.line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001456# endif
1457# if defined(FEAT_QUICKFIX)
1458 // Highlight the current line in the quickfix window.
1459 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001460 wlv.line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001461# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001462 if (wlv.line_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001463 area_highlighting = TRUE;
1464#endif
1465
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001466#ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01001467 if (spv->spv_has_spell && !number_only)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001468 {
Luuk van Baal30805a12023-05-27 22:22:10 +01001469 // Prepare for spell checking.
1470 extra_check = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001471
Luuk van Baal30805a12023-05-27 22:22:10 +01001472 // When a word wrapped from the previous line the start of the
1473 // current line is valid.
1474 if (lnum == spv->spv_checked_lnum)
1475 cur_checked_col = spv->spv_checked_col;
Luuk van Baale84c7732023-05-31 18:57:36 +01001476 // Previous line was not spell checked, check for capital. This happens
1477 // for the first line in an updated region or after a closed fold.
1478 if (spv->spv_capcol_lnum == 0 && check_need_cap(wp, lnum, 0))
1479 spv->spv_cap_col = 0;
1480 else if (lnum != spv->spv_capcol_lnum)
Luuk van Baal30805a12023-05-27 22:22:10 +01001481 spv->spv_cap_col = -1;
1482 spv->spv_checked_lnum = 0;
1483
Luuk van Baal30805a12023-05-27 22:22:10 +01001484 // Get the start of the next line, so that words that wrap to the
1485 // next line are found too: "et<line-break>al.".
1486 // Trick: skip a few chars for C/shell/Vim comments
1487 nextline[SPWORDLEN] = NUL;
1488 if (lnum < wp->w_buffer->b_ml.ml_line_count)
Luuk van Baale84c7732023-05-31 18:57:36 +01001489 {
1490 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1491 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1492 }
1493 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1494
1495 // If current line is empty, check first word in next line for capital.
1496 ptr = skipwhite(line);
1497 if (*ptr == NUL)
1498 {
1499 spv->spv_cap_col = 0;
1500 spv->spv_capcol_lnum = lnum + 1;
1501 }
1502 // For checking first word with a capital skip white space.
1503 else if (spv->spv_cap_col == 0)
1504 spv->spv_cap_col = ptr - line;
1505
Luuk van Baal30805a12023-05-27 22:22:10 +01001506 // Copy the end of the current line into nextline[].
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001507 if (nextline[SPWORDLEN] == NUL)
1508 {
1509 // No next line or it is empty.
1510 nextlinecol = MAXCOL;
1511 nextline_idx = 0;
1512 }
1513 else
1514 {
1515 v = (long)STRLEN(line);
1516 if (v < SPWORDLEN)
1517 {
1518 // Short line, use it completely and append the start of the
1519 // next line.
1520 nextlinecol = 0;
1521 mch_memmove(nextline, line, (size_t)v);
1522 STRMOVE(nextline + v, nextline + SPWORDLEN);
1523 nextline_idx = v + 1;
1524 }
1525 else
1526 {
1527 // Long line, use only the last SPWORDLEN bytes.
1528 nextlinecol = v - SPWORDLEN;
1529 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1530 nextline_idx = SPWORDLEN + 1;
1531 }
1532 }
1533 }
1534#endif
1535
Luuk van Baale84c7732023-05-31 18:57:36 +01001536 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1537 ptr = line;
1538
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001539 if (wp->w_p_list)
1540 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001541 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001542 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001543 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001544 || wp->w_lcs_chars.trail
1545 || wp->w_lcs_chars.lead
1546 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001547 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001548
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001549 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001550 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001551 {
1552 trailcol = (colnr_T)STRLEN(ptr);
1553 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1554 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001555 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001556 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001557 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001558 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001559 {
1560 leadcol = 0;
1561 while (VIM_ISWHITE(ptr[leadcol]))
1562 ++leadcol;
1563 if (ptr[leadcol] == NUL)
1564 // in a line full of spaces all of them are treated as trailing
1565 leadcol = (colnr_T)0;
1566 else
1567 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001568 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001569 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001570 }
1571
Bram Moolenaard7657e92022-09-20 18:59:30 +01001572 wlv.wcr_attr = get_wcr_attr(wp);
1573 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001574 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001575 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001576 area_highlighting = TRUE;
1577 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001578
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001579 // When w_skipcol is non-zero and there is virtual text above the actual
1580 // text, then this much of the virtual text is skipped.
1581 int skipcol_in_text_prop_above = 0;
1582
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001583#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001584 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001585 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001586
1587 char_u *prop_start;
1588 text_prop_count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE);
1589 if (text_prop_count > 0)
1590 {
1591 // Make a copy of the properties, so that they are properly
1592 // aligned.
1593 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1594 if (text_props != NULL)
1595 mch_memmove(text_props, prop_start,
1596 text_prop_count * sizeof(textprop_T));
1597
1598 // Allocate an array for the indexes.
1599 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1600 if (text_prop_idxs == NULL)
1601 VIM_CLEAR(text_props);
1602
1603 if (text_props != NULL)
1604 {
1605 area_highlighting = TRUE;
1606 extra_check = TRUE;
1607
1608 // When skipping virtual text the props need to be sorted. The
1609 // order is reversed!
1610 if (lnum == wp->w_topline && wp->w_skipcol > 0)
1611 {
1612 for (int i = 0; i < text_prop_count; ++i)
1613 text_prop_idxs[i] = i;
1614 sort_text_props(wp->w_buffer, text_props,
1615 text_prop_idxs, text_prop_count);
1616 }
1617
1618 // Text props "above" move the line number down to where the text
1619 // is. Only count the ones that are visible, not those that are
1620 // skipped because of w_skipcol.
1621 int text_width = wp->w_width - win_col_off(wp);
1622 for (int i = text_prop_count - 1; i >= 0; --i)
1623 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1624 {
1625 if (lnum == wp->w_topline
1626 && wp->w_skipcol - skipcol_in_text_prop_above
1627 >= text_width)
1628 {
1629 // This virtual text above is skipped, remove it from
1630 // the array.
1631 skipcol_in_text_prop_above += text_width;
1632 for (int j = i + 1; j < text_prop_count; ++j)
1633 text_props[j - 1] = text_props[j];
1634 ++i;
1635 --text_prop_count;
1636 }
1637 else
1638 ++wlv.text_prop_above_count;
1639 }
1640 }
1641 }
Bram Moolenaara572b932023-02-19 14:34:37 +00001642
1643 if (number_only)
1644 {
1645 // skip over rows only used for virtual text above
1646 wlv.row += wlv.text_prop_above_count;
1647 if (wlv.row > endrow)
1648 return wlv.row;
1649 wlv.screen_row += wlv.text_prop_above_count;
1650 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001651#endif
1652
zeertzjqce53e3e2023-09-01 18:49:30 +02001653#if defined(FEAT_LINEBREAK) || defined(FEAT_PROP_POPUP)
1654 colnr_T vcol_first_char = 0;
1655 if (wp->w_p_lbr && !number_only)
1656 {
1657 chartabsize_T cts;
1658 init_chartabsize_arg(&cts, wp, lnum, 0, line, line);
1659 (void)win_lbr_chartabsize(&cts, NULL);
1660 vcol_first_char = cts.cts_first_char;
1661 clear_chartabsize_arg(&cts);
1662 }
1663#endif
1664
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001665 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1666 // first character to be displayed.
1667 if (wp->w_p_wrap)
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001668 v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001669 else
1670 v = wp->w_leftcol;
1671 if (v > 0 && !number_only)
1672 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001673 char_u *prev_ptr = ptr;
1674 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001675 int charsize = 0;
zeertzjqb557f482023-08-22 22:07:34 +02001676 int head = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001677
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001678 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
zeertzjqb557f482023-08-22 22:07:34 +02001679 cts.cts_max_head_vcol = v;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001680 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001681 {
zeertzjqb557f482023-08-22 22:07:34 +02001682 head = 0;
1683 charsize = win_lbr_chartabsize(&cts, &head);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001684 cts.cts_vcol += charsize;
1685 prev_ptr = cts.cts_ptr;
1686 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001687 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001688 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001689 ptr = cts.cts_ptr;
1690 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001691
1692 // When:
1693 // - 'cuc' is set, or
1694 // - 'colorcolumn' is set, or
1695 // - 'virtualedit' is set, or
1696 // - the visual mode is active,
1697 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001698 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001699#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001700 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001701#endif
1702 virtual_active() ||
1703 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001704 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001705
1706 // Handle a character that's not completely on the screen: Put ptr at
1707 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001708 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001709 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001710 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001711 ptr = prev_ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001712 }
zeertzjqb557f482023-08-22 22:07:34 +02001713 if (v > wlv.vcol)
1714 skip_cells = v - wlv.vcol - head;
Bram Moolenaarcd105412022-10-10 19:50:42 +01001715
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001716 // Adjust for when the inverted text is before the screen,
1717 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001718 if (wlv.tocol <= wlv.vcol)
1719 wlv.fromcol = 0;
1720 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1721 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001722
1723#ifdef FEAT_LINEBREAK
1724 // When w_skipcol is non-zero, first line needs 'showbreak'
1725 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001726 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001727#endif
1728#ifdef FEAT_SPELL
1729 // When spell checking a word we need to figure out the start of the
1730 // word and if it's badly spelled or not.
Luuk van Baal30805a12023-05-27 22:22:10 +01001731 if (spv->spv_has_spell)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001732 {
1733 int len;
1734 colnr_T linecol = (colnr_T)(ptr - line);
1735 hlf_T spell_hlf = HLF_COUNT;
1736
1737 pos = wp->w_cursor;
1738 wp->w_cursor.lnum = lnum;
1739 wp->w_cursor.col = linecol;
1740 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1741
1742 // spell_move_to() may call ml_get() and make "line" invalid
1743 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1744 ptr = line + linecol;
1745
1746 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1747 {
1748 // no bad word found at line start, don't check until end of a
1749 // word
1750 spell_hlf = HLF_COUNT;
1751 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1752 }
1753 else
1754 {
1755 // bad word found, use attributes until end of word
1756 word_end = wp->w_cursor.col + len + 1;
1757
1758 // Turn index into actual attributes.
1759 if (spell_hlf != HLF_COUNT)
1760 spell_attr = highlight_attr[spell_hlf];
1761 }
1762 wp->w_cursor = pos;
1763
1764# ifdef FEAT_SYN_HL
1765 // Need to restart syntax highlighting for this line.
1766 if (has_syntax)
1767 syntax_start(wp, lnum);
1768# endif
1769 }
1770#endif
1771 }
1772
1773 // Correct highlighting for cursor that can't be disabled.
1774 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001775 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001776 {
1777 if (noinvcur)
1778 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001779 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001780 {
1781 // highlighting starts at cursor, let it start just after the
1782 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001783 fromcol_prev = wlv.fromcol;
1784 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001785 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001786 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001787 // restart highlighting after the cursor
1788 fromcol_prev = wp->w_virtcol;
1789 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001790 if (wlv.fromcol >= wlv.tocol)
1791 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001792 }
1793
1794#ifdef FEAT_SEARCH_EXTRA
1795 if (!number_only)
1796 {
1797 v = (long)(ptr - line);
1798 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1799 &line, &screen_search_hl,
1800 &search_attr);
1801 ptr = line + v; // "line" may have been updated
1802 }
1803#endif
1804
1805#ifdef FEAT_SYN_HL
1806 // Cursor line highlighting for 'cursorline' in the current window.
1807 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1808 {
1809 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001810 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001811 if (!(wp == curwin && VIsual_active)
1812 && wp->w_p_culopt_flags != CULOPT_NBR)
1813 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001814 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001815 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1816
zeertzjqb7acea12022-12-12 13:20:43 +00001817 // Only apply CursorLine highlight here when "screenline" is not
1818 // present in 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001819 if (!wlv.cul_screenline)
zeertzjqb7acea12022-12-12 13:20:43 +00001820 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001821 else
1822 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001823 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001824 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1825 }
1826 area_highlighting = TRUE;
1827 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001828 }
1829#endif
1830
Bram Moolenaar1306b362022-08-06 15:59:06 +01001831 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001832
1833 // Repeat for the whole displayed line.
1834 for (;;)
1835 {
1836#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001837 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001838#endif
1839#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001840 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001841#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001842
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001843 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001844 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001845 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001846#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001847 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001848 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001849 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001850 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001851 }
1852#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001853 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001854 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001855 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001856 if (cmdwin_type != 0 && wp == curwin)
1857 {
1858 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001859 wlv.n_extra = 1;
1860 wlv.c_extra = cmdwin_type;
1861 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001862 wlv.char_attr =
1863 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001864 }
1865 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001866#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001867 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001868 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001869 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001870 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001871 }
1872#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001873#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001874 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001875 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001876 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001877 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001878 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001879 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001880 }
1881#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001882 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001883 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001884 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001885 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001886 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001887 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001888#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001889 // Check if 'breakindent' applies and show it.
1890 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1891 if (wlv.n_extra == 0)
1892 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001893#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001894#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001895 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001896 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001897 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001898 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001899 }
1900#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001901 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001902 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001903 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001904 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001905 }
1906 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001907
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001908#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001909 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001910 && wlv.vcol >= left_curline_col
1911 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001912 {
zeertzjqb7acea12022-12-12 13:20:43 +00001913 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001914 }
1915#endif
1916
1917 // When still displaying '$' of change command, stop at cursor.
1918 // When only displaying the (relative) line number and that's done,
1919 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001920 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001921 && lnum == wp->w_cursor.lnum
1922 && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001923 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001924#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001925 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001926#endif
1927 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001928 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001929 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001930 // Pretend we have finished updating the window. Except when
1931 // 'cursorcolumn' is set.
1932#ifdef FEAT_SYN_HL
1933 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001934 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001935 else
1936#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001937 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001938 break;
1939 }
1940
Bram Moolenaar1306b362022-08-06 15:59:06 +01001941 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001942 {
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001943#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001944 if (text_props != NULL)
1945 {
1946 int pi;
1947 int bcol = (int)(ptr - line);
1948
Bram Moolenaar1306b362022-08-06 15:59:06 +01001949 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001950# ifdef FEAT_LINEBREAK
1951 && !in_linebreak
1952# endif
1953 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001954 --bcol; // still working on the previous char, e.g. Tab
1955
1956 // Check if any active property ends.
1957 for (pi = 0; pi < text_props_active; ++pi)
1958 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001959 int tpi = text_prop_idxs[pi];
1960 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001961
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001962 // An inline property ends when after the start column plus
1963 // length. An "above" property ends when used and n_extra
1964 // is zero.
1965 if ((tp->tp_col != MAXCOL
1966 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001967 {
1968 if (pi + 1 < text_props_active)
1969 mch_memmove(text_prop_idxs + pi,
1970 text_prop_idxs + pi + 1,
1971 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001972 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001973 --text_props_active;
1974 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001975# ifdef FEAT_LINEBREAK
1976 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001977 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001978 syntax_attr = 0;
1979# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001980 }
1981 }
1982
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001983# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001984 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001985 // not on the next char yet, don't start another prop
1986 --bcol;
1987# endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001988 int display_text_first = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001989
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001990 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001991 // With 'nowrap' and not in the first screen line only "below"
1992 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001993 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001994 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001995 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001996 && (wp->w_p_wrap
1997 || wlv.row == startrow
1998 || (text_props[text_prop_next].tp_flags
1999 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002000 || (bcol == 0
2001 && (text_props[text_prop_next].tp_flags
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002002 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002003 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002004 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01002005 if (text_props[text_prop_next].tp_col == MAXCOL
2006 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002007 + text_props[text_prop_next].tp_len)
2008 text_prop_idxs[text_props_active++] = text_prop_next;
2009 ++text_prop_next;
2010 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002011
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002012 if (wlv.n_extra == 0 ||
2013 (!wlv.extra_for_textprop
2014#ifdef FEAT_PROP_POPUP
2015 && !(text_prop_type != NULL &&
2016 text_prop_flags & PT_FLAG_OVERRIDE)
2017#endif
2018 ))
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002019 {
2020 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002021 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002022 text_prop_flags = 0;
2023 text_prop_type = NULL;
2024 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002025 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002026 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002027 if (text_props_active > 0 && wlv.n_extra == 0
2028 && !display_text_first)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002029 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01002030 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002031 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002032 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002033
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002034 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002035 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002036
2037 // Sort the properties on priority and/or starting last.
2038 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002039 sort_text_props(wp->w_buffer, text_props,
2040 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002041
2042 for (pi = 0; pi < text_props_active; ++pi)
2043 {
2044 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002045 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002046 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002047 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002048
Bram Moolenaarcd105412022-10-10 19:50:42 +01002049 // Only use a text property that can be displayed.
2050 // Skip "after" properties when wrap is off and at the
2051 // end of the window.
2052 if (pt != NULL
2053 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2054 && tp->tp_id != -MAXCOL
2055 && !(tp->tp_id < 0
2056 && !wp->w_p_wrap
2057 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2058 | TP_FLAG_ALIGN_ABOVE
2059 | TP_FLAG_ALIGN_BELOW)) == 0
2060 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002061 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002062 if (tp->tp_col == MAXCOL
2063 && *ptr == NUL
2064 && ((wp->w_p_list && lcs_eol_one > 0
2065 && (tp->tp_flags
2066 & TP_FLAG_ALIGN_ABOVE) == 0)
2067 || (ptr == line
2068 && !did_line
2069 && (tp->tp_flags
2070 & TP_FLAG_ALIGN_BELOW))))
2071 {
2072 // skip this prop, first display the '$' after
2073 // the line or display an empty line
2074 text_prop_follows = TRUE;
2075 if (used_tpi < 0)
2076 display_text_first = TRUE;
2077 continue;
2078 }
2079
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002080 if (pt->pt_hl_id > 0)
2081 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002082 text_prop_type = pt;
2083 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002084 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002085 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2086 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002087 text_prop_flags = pt->pt_flags;
2088 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002089 used_tpi = tpi;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002090 display_text_first = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002091 }
2092 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002093 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002094 && -text_prop_id
2095 <= wp->w_buffer->b_textprop_text.ga_len)
2096 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002097 textprop_T *tp = &text_props[used_tpi];
2098 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002099 ->b_textprop_text.ga_data)[
2100 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002101 int above = (tp->tp_flags
2102 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002103 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002104
2105 // reset the ID in the copy to avoid it being used
2106 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002107 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002108
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002109 if (p != NULL)
2110 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002111 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002112 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002113 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002114 & TP_FLAG_ALIGN_BELOW);
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002115 int wrap = tp->tp_col < MAXCOL
2116 || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002117 int padding = tp->tp_col == MAXCOL
2118 && tp->tp_len > 1
2119 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002120
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002121 // Insert virtual text before the current
2122 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002123 wlv.p_extra = p;
2124 wlv.c_extra = NUL;
2125 wlv.c_final = NUL;
2126 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002127 wlv.extra_for_textprop = TRUE;
zeertzjq6e940d92023-08-17 23:21:40 +02002128 wlv.start_extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002129 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2130 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002131 n_attr = mb_charlen(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002132 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002133 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002134 if (*ptr == NUL)
2135 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002136 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002137#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002138 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002139 {
2140 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002141 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002142 wlv.need_showbreak = FALSE;
2143 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002144 }
2145#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002146 if ((right || above || below || !wrap
2147 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002148 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002149 char_u *prev_p_extra = wlv.p_extra;
2150 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002151
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002152 // Take care of padding, right-align and
2153 // truncation.
2154 // Shared with win_lbr_chartabsize(), must do
2155 // exactly the same.
2156 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002157 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002158 wlv.col,
2159 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002160 &n_attr, &wlv.n_attr_skip,
2161 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002162 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002163 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002164 // wlv.p_extra was allocated
2165 vim_free(p_extra_free2);
2166 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002167 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002168
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002169 if (above)
2170 wlv.vcol_off_tp = wlv.n_extra;
2171
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002172 if (lcs_eol_one < 0
2173 && wp->w_p_wrap
2174 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002175 + wlv.n_extra - 2 > wp->w_width)
2176 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002177 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002178
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002179 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002180 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002181 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002182 {
2183 draw_screen_line(wp, &wlv);
2184
2185 // When line got too long for screen break
2186 // here.
2187 if (wlv.row == endrow)
2188 {
2189 ++wlv.row;
2190 break;
2191 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002192 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002193 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002194 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002195 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002196 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002197
Bram Moolenaarcd105412022-10-10 19:50:42 +01002198 // If the text didn't reach until the first window
2199 // column we need to skip cells.
2200 if (skip_cells > 0)
2201 {
2202 if (wlv.n_extra > skip_cells)
2203 {
2204 wlv.n_extra -= skip_cells;
2205 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002206 wlv.n_attr_skip -= skip_cells;
2207 if (wlv.n_attr_skip < 0)
2208 wlv.n_attr_skip = 0;
zeertzjqb557f482023-08-22 22:07:34 +02002209 skipped_cells += skip_cells;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002210 skip_cells = 0;
2211 }
2212 else
2213 {
2214 // the whole text is left of the window, drop
2215 // it and advance to the next one
2216 skip_cells -= wlv.n_extra;
zeertzjqb557f482023-08-22 22:07:34 +02002217 skipped_cells += wlv.n_extra;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002218 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002219 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002220 bail_out = TRUE;
2221 }
2222 }
2223
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002224 // If another text prop follows the condition below at
2225 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002226 // If this is an "above" text prop and 'nowrap' the we
2227 // must wrap anyway.
2228 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002229 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002230 && (wp->w_p_wrap
2231 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002232 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002233
2234 if (bail_out)
2235 // starting a new line for "below"
2236 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002237 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002238 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002239 else if (text_prop_next < text_prop_count
2240 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002241 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2242 || (!wp->w_p_wrap
2243 && wlv.col == wp->w_width - 1
2244 && (text_props[text_prop_next].tp_flags
2245 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002246 // When at last-but-one character and a text property
2247 // follows after it, we may need to flush the line after
2248 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002249 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002250 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002251 }
zeertzjq6e940d92023-08-17 23:21:40 +02002252
2253 if (wlv.start_extra_for_textprop)
2254 {
2255 wlv.start_extra_for_textprop = FALSE;
2256 // restore search_attr and area_attr when n_extra
2257 // is down to zero
2258 saved_search_attr = search_attr;
2259 saved_area_attr = area_attr;
2260 search_attr = 0;
2261 area_attr = 0;
2262 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002263#endif
2264
zeertzjq6e940d92023-08-17 23:21:40 +02002265 int *area_attr_p =
2266#ifdef FEAT_PROP_POPUP
2267 wlv.extra_for_textprop ? &saved_area_attr :
2268#endif
2269 &area_attr;
2270
2271 // handle Visual or match highlighting in this line
2272 if (wlv.vcol == wlv.fromcol
2273 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
2274 && ((wlv.n_extra == 0 && (*mb_ptr2cells)(ptr) > 1)
2275 || (wlv.n_extra > 0 && wlv.p_extra != NULL
2276 && (*mb_ptr2cells)(wlv.p_extra) > 1)))
2277 || ((int)vcol_prev == fromcol_prev
2278 && vcol_prev < wlv.vcol // not at margin
2279 && wlv.vcol < wlv.tocol))
2280 *area_attr_p = vi_attr; // start highlighting
2281 else if (*area_attr_p != 0
2282 && (wlv.vcol == wlv.tocol
2283 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
2284 *area_attr_p = 0; // stop highlighting
2285
zeertzjqe500ae82023-08-17 22:35:26 +02002286#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaare38fc862022-08-11 17:24:50 +01002287 if (wlv.n_extra == 0)
2288 {
2289 // Check for start/end of 'hlsearch' and other matches.
2290 // After end, check for start/end of next match.
2291 // When another match, have to check for start again.
2292 v = (long)(ptr - line);
2293 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2294 &screen_search_hl, &has_match_conc,
2295 &match_conc, did_line_attr, lcs_eol_one,
2296 &on_last_col);
2297 ptr = line + v; // "line" may have been changed
Bram Moolenaare38fc862022-08-11 17:24:50 +01002298
2299 // Do not allow a conceal over EOL otherwise EOL will be missed
2300 // and bad things happen.
2301 if (*ptr == NUL)
2302 has_match_conc = 0;
zeertzjqb25dbb32023-08-13 18:11:05 +02002303 }
zeertzjqe500ae82023-08-17 22:35:26 +02002304#endif
zeertzjqb25dbb32023-08-13 18:11:05 +02002305
Bram Moolenaare38fc862022-08-11 17:24:50 +01002306#ifdef FEAT_DIFF
2307 if (wlv.diff_hlf != (hlf_T)0)
2308 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002309 // When there is extra text (e.g. virtual text) it gets the
2310 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002311 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2312 && wlv.n_extra == 0)
2313 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002314 if (wlv.diff_hlf == HLF_TXD
2315 && ((ptr - line > change_end && wlv.n_extra == 0)
2316 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002317 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002318 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002319 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2320 && wp->w_p_culopt_flags != CULOPT_NBR
2321 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2322 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002323 wlv.line_attr = hl_combine_attr(
2324 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002325 }
2326#endif
2327
Bram Moolenaara74fda62019-10-19 17:38:03 +02002328#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002329 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002330 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002331 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002332# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002333 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002334 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002335# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002336 // Get syntax attribute.
2337 if (has_syntax)
2338 {
2339 // Get the syntax attribute for the character. If there
2340 // is an error, disable syntax highlighting.
2341 save_did_emsg = did_emsg;
2342 did_emsg = FALSE;
2343
2344 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002345 if (v == prev_syntax_col)
2346 // at same column again
2347 syntax_attr = prev_syntax_attr;
2348 else
2349 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002350# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002351 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002352# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002353 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002354# ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01002355 spv->spv_has_spell ? &can_spell :
Bram Moolenaar34390282019-10-16 14:38:26 +02002356# endif
Luuk van Baal30805a12023-05-27 22:22:10 +01002357 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002358 prev_syntax_col = v;
2359 prev_syntax_attr = syntax_attr;
2360 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002361
Bram Moolenaar34390282019-10-16 14:38:26 +02002362 if (did_emsg)
2363 {
2364 wp->w_s->b_syn_error = TRUE;
2365 has_syntax = FALSE;
2366 syntax_attr = 0;
2367 }
2368 else
2369 did_emsg = save_did_emsg;
2370# ifdef SYN_TIME_LIMIT
2371 if (wp->w_s->b_syn_slow)
2372 has_syntax = FALSE;
2373# endif
2374
2375 // Need to get the line again, a multi-line regexp may
2376 // have made it invalid.
2377 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2378 ptr = line + v;
2379# ifdef FEAT_CONCEAL
2380 // no concealing past the end of the line, it interferes
2381 // with line highlighting
2382 if (*ptr == NUL)
2383 syntax_flags = 0;
2384 else
2385 syntax_flags = get_syntax_info(&syntax_seqnr);
2386# endif
2387 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002388 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002389# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002390 // Combine text property highlight into syntax highlight.
2391 if (text_prop_type != NULL)
2392 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002393 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002394 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2395 else
2396 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002397 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002398 }
2399# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002400#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002401
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002402 // Decide which of the highlight attributes to use.
2403 attr_pri = TRUE;
2404#ifdef LINE_ATTR
2405 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002406 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002407 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002408 if (!highlight_match)
2409 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002410 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002411# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002412 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002413# endif
2414 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002415 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002416 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002417 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002418# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002419 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002420# endif
2421 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002422 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002423 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2424 || wlv.vcol < wlv.fromcol
2425 || vcol_prev < fromcol_prev
2426 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002427 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002428 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002429 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002430# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002431 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002432# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002433 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002434# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002435 attr_pri = FALSE;
2436 }
2437#else
2438 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002439 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002440 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002441 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002442#endif
2443 else
2444 {
2445 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002446#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002447 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002448#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002449 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002450#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002451 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002452#ifdef FEAT_PROP_POPUP
2453 // override with text property highlight when "override" is TRUE
2454 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002455 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002456#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002457 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002458
2459 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002460 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002461 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002462 if (wlv.char_attr == 0)
2463 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002464 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002465 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002466 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002467
2468 // Get the next character to put on the screen.
2469
2470 // The "p_extra" points to the extra stuff that is inserted to
2471 // represent special characters (non-printable stuff) and other
2472 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002473 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002474 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2475 // "p_extra[n_extra]".
2476 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002477 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002478 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002479 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002480 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002481 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2482 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002483 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2484 if (enc_utf8 && utf_char2len(c) > 1)
2485 {
2486 mb_utf8 = TRUE;
2487 u8cc[0] = 0;
2488 c = 0xc0;
2489 }
2490 else
2491 mb_utf8 = FALSE;
2492 }
2493 else
2494 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002495 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002496 if (has_mbyte)
2497 {
2498 mb_c = c;
2499 if (enc_utf8)
2500 {
2501 // If the UTF-8 character is more than one byte:
2502 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002503 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002504 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002505 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002506 mb_l = 1;
2507 else if (mb_l > 1)
2508 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002509 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002510 mb_utf8 = TRUE;
2511 c = 0xc0;
2512 }
2513 }
2514 else
2515 {
2516 // if this is a DBCS character, put it in "mb_c"
2517 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002518 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002519 mb_l = 1;
2520 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002521 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002522 }
2523 if (mb_l == 0) // at the NUL at end-of-line
2524 mb_l = 1;
2525
2526 // If a double-width char doesn't fit display a '>' in the
2527 // last column.
2528 if ((
2529# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002530 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002531# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002532 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002533 && (*mb_char2cells)(mb_c) == 2)
2534 {
2535 c = '>';
2536 mb_c = c;
2537 mb_l = 1;
2538 mb_utf8 = FALSE;
2539 multi_attr = HL_ATTR(HLF_AT);
2540#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002541 if (wlv.cul_attr)
2542 multi_attr = hl_combine_attr(
2543 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002544#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002545 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002546
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002547 // put the pointer back to output the double-width
2548 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002549 ++wlv.n_extra;
2550 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002551 }
2552 else
2553 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002554 wlv.n_extra -= mb_l - 1;
2555 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002556 }
2557 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002558 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002559 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002560 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002561#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002562 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002563 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002564 // Only restore search_attr and area_attr after "n_extra" in
2565 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002566 if (wlv.saved_n_extra <= 0)
2567 {
2568 if (search_attr == 0)
2569 search_attr = saved_search_attr;
2570 if (area_attr == 0 && *ptr != NUL)
2571 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002572
2573 if (wlv.extra_for_textprop)
2574 // wlv.extra_attr should be used at this position but
2575 // not any further.
2576 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002577 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002578
2579 wlv.extra_for_textprop = FALSE;
2580 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002581 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002582#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002583 }
2584 else
2585 {
2586#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002587 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002588#endif
zeertzjqe500ae82023-08-17 22:35:26 +02002589#ifdef FEAT_SPELL
2590 char_u *prev_ptr = ptr;
2591#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002592
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002593 // Get a character from the line itself.
2594 c = *ptr;
2595#ifdef FEAT_LINEBREAK
2596 c0 = *ptr;
2597#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002598 if (c == NUL)
zeertzjqb557f482023-08-22 22:07:34 +02002599 {
2600#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002601 // text is finished, may display a "below" virtual text
2602 did_line = TRUE;
2603#endif
zeertzjqb557f482023-08-22 22:07:34 +02002604 // no more cells to skip
2605 skip_cells = 0;
2606 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002607
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002608 if (has_mbyte)
2609 {
2610 mb_c = c;
2611 if (enc_utf8)
2612 {
2613 // If the UTF-8 character is more than one byte: Decode it
2614 // into "mb_c".
2615 mb_l = utfc_ptr2len(ptr);
2616 mb_utf8 = FALSE;
2617 if (mb_l > 1)
2618 {
2619 mb_c = utfc_ptr2char(ptr, u8cc);
2620 // Overlong encoded ASCII or ASCII with composing char
2621 // is displayed normally, except a NUL.
2622 if (mb_c < 0x80)
2623 {
2624 c = mb_c;
2625#ifdef FEAT_LINEBREAK
2626 c0 = mb_c;
2627#endif
2628 }
2629 mb_utf8 = TRUE;
2630
2631 // At start of the line we can have a composing char.
2632 // Draw it as a space with a composing char.
2633 if (utf_iscomposing(mb_c))
2634 {
2635 int i;
2636
2637 for (i = Screen_mco - 1; i > 0; --i)
2638 u8cc[i] = u8cc[i - 1];
2639 u8cc[0] = mb_c;
2640 mb_c = ' ';
2641 }
2642 }
2643
2644 if ((mb_l == 1 && c >= 0x80)
2645 || (mb_l >= 1 && mb_c == 0)
2646 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2647 {
2648 // Illegal UTF-8 byte: display as <xx>.
2649 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002650 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002651# ifdef FEAT_RIGHTLEFT
2652 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002653 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002654# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002655 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002656 c = *wlv.p_extra;
2657 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002658 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002659 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2660 wlv.c_extra = NUL;
2661 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002662 if (area_attr == 0 && search_attr == 0)
2663 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002664 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002665 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002666 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002667 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002668 }
2669 }
2670 else if (mb_l == 0) // at the NUL at end-of-line
2671 mb_l = 1;
2672#ifdef FEAT_ARABIC
2673 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2674 {
2675 // Do Arabic shaping.
2676 int pc, pc1, nc;
2677 int pcc[MAX_MCO];
2678
2679 // The idea of what is the previous and next
2680 // character depends on 'rightleft'.
2681 if (wp->w_p_rl)
2682 {
2683 pc = prev_c;
2684 pc1 = prev_c1;
2685 nc = utf_ptr2char(ptr + mb_l);
2686 prev_c1 = u8cc[0];
2687 }
2688 else
2689 {
2690 pc = utfc_ptr2char(ptr + mb_l, pcc);
2691 nc = prev_c;
2692 pc1 = pcc[0];
2693 }
2694 prev_c = mb_c;
2695
2696 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2697 }
2698 else
2699 prev_c = mb_c;
2700#endif
2701 }
2702 else // enc_dbcs
2703 {
2704 mb_l = MB_BYTE2LEN(c);
2705 if (mb_l == 0) // at the NUL at end-of-line
2706 mb_l = 1;
2707 else if (mb_l > 1)
2708 {
2709 // We assume a second byte below 32 is illegal.
2710 // Hopefully this is OK for all double-byte encodings!
2711 if (ptr[1] >= 32)
2712 mb_c = (c << 8) + ptr[1];
2713 else
2714 {
2715 if (ptr[1] == NUL)
2716 {
2717 // head byte at end of line
2718 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002719 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002720 }
2721 else
2722 {
2723 // illegal tail byte
2724 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002725 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002726 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002727 wlv.p_extra = wlv.extra;
2728 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002729 wlv.c_extra = NUL;
2730 wlv.c_final = NUL;
2731 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002732 if (area_attr == 0 && search_attr == 0)
2733 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002734 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002735 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002736 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002737 // save current attr
2738 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002739 }
2740 mb_c = c;
2741 }
2742 }
2743 }
2744 // If a double-width char doesn't fit display a '>' in the
2745 // last column; the character is displayed at the start of the
2746 // next line.
2747 if ((
2748# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002749 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002750# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002751 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002752 && (*mb_char2cells)(mb_c) == 2)
2753 {
2754 c = '>';
2755 mb_c = c;
2756 mb_utf8 = FALSE;
2757 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002758 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002759 // Put pointer back so that the character will be
2760 // displayed at the start of the next line.
2761 --ptr;
2762#ifdef FEAT_CONCEAL
2763 did_decrement_ptr = TRUE;
2764#endif
2765 }
2766 else if (*ptr != NUL)
2767 ptr += mb_l - 1;
2768
2769 // If a double-width char doesn't fit at the left side display
2770 // a '<' in the first column. Don't do this for unprintable
2771 // characters.
zeertzjqb557f482023-08-22 22:07:34 +02002772 if (skip_cells > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002773 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002774 wlv.n_extra = 1;
2775 wlv.c_extra = MB_FILLER_CHAR;
2776 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002777 c = ' ';
2778 if (area_attr == 0 && search_attr == 0)
2779 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002780 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002781 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002782 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002783 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002784 }
2785 mb_c = c;
2786 mb_utf8 = FALSE;
2787 mb_l = 1;
2788 }
2789
2790 }
2791 ++ptr;
2792
2793 if (extra_check)
2794 {
2795#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002796 // Check spelling (unless at the end of the line).
2797 // Only do this when there is no syntax highlighting, the
2798 // @Spell cluster is not used or the current syntax item
2799 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002800 v = (long)(ptr - line);
Luuk van Baal30805a12023-05-27 22:22:10 +01002801 if (spv->spv_has_spell && v >= word_end && v > cur_checked_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002802 {
2803 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002804 // do not calculate cap_col at the end of the line or when
2805 // only white space is following
2806 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002807# ifdef FEAT_SYN_HL
2808 !has_syntax ||
2809# endif
2810 can_spell))
2811 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002812 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002813 int len;
2814 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002815
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002816 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002817 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002818
2819 // Use nextline[] if possible, it has the start of the
2820 // next line concatenated.
2821 if ((prev_ptr - line) - nextlinecol >= 0)
2822 p = nextline + (prev_ptr - line) - nextlinecol;
2823 else
2824 p = prev_ptr;
Luuk van Baal30805a12023-05-27 22:22:10 +01002825 spv->spv_cap_col -= (int)(prev_ptr - line);
2826 len = spell_check(wp, p, &spell_hlf, &spv->spv_cap_col,
2827 spv->spv_unchanged);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002828 word_end = v + len;
2829
2830 // In Insert mode only highlight a word that
2831 // doesn't touch the cursor.
2832 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002833 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002834 && wp->w_cursor.lnum == lnum
2835 && wp->w_cursor.col >=
2836 (colnr_T)(prev_ptr - line)
2837 && wp->w_cursor.col < (colnr_T)word_end)
2838 {
2839 spell_hlf = HLF_COUNT;
2840 spell_redraw_lnum = lnum;
2841 }
2842
2843 if (spell_hlf == HLF_COUNT && p != prev_ptr
2844 && (p - nextline) + len > nextline_idx)
2845 {
2846 // Remember that the good word continues at the
2847 // start of the next line.
Luuk van Baal30805a12023-05-27 22:22:10 +01002848 spv->spv_checked_lnum = lnum + 1;
2849 spv->spv_checked_col = (p - nextline) + len
2850 - nextline_idx;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002851 }
2852
2853 // Turn index into actual attributes.
2854 if (spell_hlf != HLF_COUNT)
2855 spell_attr = highlight_attr[spell_hlf];
2856
Luuk van Baal30805a12023-05-27 22:22:10 +01002857 if (spv->spv_cap_col > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002858 {
2859 if (p != prev_ptr
Luuk van Baal30805a12023-05-27 22:22:10 +01002860 && (p - nextline) + spv->spv_cap_col
2861 >= nextline_idx)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002862 {
2863 // Remember that the word in the next line
2864 // must start with a capital.
Luuk van Baal30805a12023-05-27 22:22:10 +01002865 spv->spv_capcol_lnum = lnum + 1;
2866 spv->spv_cap_col = ((p - nextline)
2867 + spv->spv_cap_col - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002868 }
2869 else
2870 // Compute the actual column.
Luuk van Baal30805a12023-05-27 22:22:10 +01002871 spv->spv_cap_col += (prev_ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002872 }
2873 }
2874 }
2875 if (spell_attr != 0)
2876 {
2877 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002878 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2879 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002880 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002881 wlv.char_attr = hl_combine_attr(spell_attr,
2882 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002883 }
2884#endif
2885#ifdef FEAT_LINEBREAK
2886 // Found last space before word: check for line break.
2887 if (wp->w_p_lbr && c0 == c
2888 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2889 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002890 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2891 : 0;
2892 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002893 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002894
zeertzjqce53e3e2023-09-01 18:49:30 +02002895 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol
2896# ifdef FEAT_PROP_POPUP
2897 - vcol_first_char,
2898# endif
2899 line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002900# ifdef FEAT_PROP_POPUP
2901 // do not want virtual text counted here
2902 cts.cts_has_prop_with_text = FALSE;
2903# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002904 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002905 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002906
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002907 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002908 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002909 // line break, but for TABs the highlighting should
2910 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002911 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002912
Bram Moolenaar1306b362022-08-06 15:59:06 +01002913 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002914# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002915 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002916 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002917 wp->w_buffer->b_p_vts_array) - 1;
2918# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002919 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002920 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002921# endif
2922
Bram Moolenaar1306b362022-08-06 15:59:06 +01002923 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2924 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002925# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002926 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002927 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002928# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002929 if (VIM_ISWHITE(c))
2930 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002931# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002932 if (c == TAB)
2933 // See "Tab alignment" below.
2934 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002935# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002936 if (!wp->w_p_list)
2937 c = ' ';
2938 }
2939 }
2940#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002941 in_multispace = c == ' '
2942 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2943 if (!in_multispace)
2944 multispace_pos = 0;
2945
Bram Moolenaareed9d462021-02-15 20:38:25 +01002946 // 'list': Change char 160 to 'nbsp' and space to 'space'
2947 // setting in 'listchars'. But not when the character is
2948 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002949 if (wp->w_p_list
2950 && ((((c == 160 && mb_l == 1)
2951 || (mb_utf8
2952 && ((mb_c == 160 && mb_l == 2)
2953 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002954 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002955 || (c == ' '
2956 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002957 && (wp->w_lcs_chars.space
2958 || (in_multispace
2959 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002960 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002961 && ptr - line <= trailcol)))
2962 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002963 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2964 {
2965 c = wp->w_lcs_chars.multispace[multispace_pos++];
2966 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2967 multispace_pos = 0;
2968 }
2969 else
2970 c = (c == ' ') ? wp->w_lcs_chars.space
2971 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002972 if (area_attr == 0 && search_attr == 0)
2973 {
2974 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002975 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002976 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002977 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002978 }
2979 mb_c = c;
2980 if (enc_utf8 && utf_char2len(c) > 1)
2981 {
2982 mb_utf8 = TRUE;
2983 u8cc[0] = 0;
2984 c = 0xc0;
2985 }
2986 else
2987 mb_utf8 = FALSE;
2988 }
2989
zeertzjq2e7cba32022-06-10 15:30:32 +01002990 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2991 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002992 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002993 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2994 && wp->w_lcs_chars.leadmultispace != NULL)
2995 {
2996 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002997 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2998 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002999 multispace_pos = 0;
3000 }
3001
3002 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
3003 c = wp->w_lcs_chars.trail;
3004
3005 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
3006 c = wp->w_lcs_chars.lead;
3007
zeertzjq2e7cba32022-06-10 15:30:32 +01003008 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003009 c = wp->w_lcs_chars.space;
3010
3011
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003012 if (!attr_pri)
3013 {
3014 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003015 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003016 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003017 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003018 }
3019 mb_c = c;
3020 if (enc_utf8 && utf_char2len(c) > 1)
3021 {
3022 mb_utf8 = TRUE;
3023 u8cc[0] = 0;
3024 c = 0xc0;
3025 }
3026 else
3027 mb_utf8 = FALSE;
3028 }
3029 }
3030
3031 // Handling of non-printable characters.
3032 if (!vim_isprintc(c))
3033 {
3034 // when getting a character from the file, we may have to
3035 // turn it into something else on the way to putting it
3036 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01003037 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003038 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003039 int tab_len = 0;
3040 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003041#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003042 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01003043
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003044 // only adjust the tab_len, when at the first column
3045 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01003046 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003047 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003048#endif
3049 // tab amount depends on current column
3050#ifdef FEAT_VARTABS
3051 tab_len = tabstop_padding(vcol_adjusted,
3052 wp->w_buffer->b_p_ts,
3053 wp->w_buffer->b_p_vts_array) - 1;
3054#else
3055 tab_len = (int)wp->w_buffer->b_p_ts
3056 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
3057#endif
3058
3059#ifdef FEAT_LINEBREAK
3060 if (!wp->w_p_lbr || !wp->w_p_list)
3061#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003062 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003063 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01003064 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003065 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003066#ifdef FEAT_LINEBREAK
3067 else
3068 {
3069 char_u *p;
3070 int len;
3071 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003072 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003073
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003074# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003075 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003076 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003077 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003078
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003079 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003080 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003081 && old_boguscols > 0
3082 && wlv.n_extra > tab_len)
3083 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003084# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003085 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003086 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003087 // If wlv.n_extra > 0, it gives the number of chars
3088 // to use for a tab, else we need to calculate the
3089 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003090 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3091 len = tab_len * tab2_len;
3092 if (wp->w_lcs_chars.tab3)
3093 len += mb_char2len(wp->w_lcs_chars.tab3)
3094 - tab2_len;
3095 if (wlv.n_extra > 0)
3096 len += wlv.n_extra - tab_len;
3097 c = wp->w_lcs_chars.tab1;
3098 p = alloc(len + 1);
3099 if (p == NULL)
3100 wlv.n_extra = 0;
3101 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003102 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003103 vim_memset(p, ' ', len);
3104 p[len] = NUL;
3105 vim_free(wlv.p_extra_free);
3106 wlv.p_extra_free = p;
3107 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003108 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003109 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003110
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003111 if (*p == NUL)
3112 {
3113 tab_len = i;
3114 break;
3115 }
3116
3117 // if tab3 is given, use it for the last
3118 // char
3119 if (wp->w_lcs_chars.tab3
3120 && i == tab_len - 1)
3121 lcs = wp->w_lcs_chars.tab3;
3122 p += mb_char2bytes(lcs, p);
3123 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003124 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003125 }
3126 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003127# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003128 // n_extra will be increased by
3129 // FIX_FOX_BOGUSCOLS macro below, so need to
3130 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003131 if (wlv.vcol_off_co > 0)
3132 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003133# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003134 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003135 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003136 }
3137#endif
3138#ifdef FEAT_CONCEAL
3139 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003140 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003141
3142 // Tab alignment should be identical regardless of
3143 // 'conceallevel' value. So tab compensates of all
3144 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003145 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003146 // line. Note that the tab can be longer than
3147 // 'tabstop' when there are concealed characters.
3148 FIX_FOR_BOGUSCOLS;
3149
3150 // Make sure, the highlighting for the tab char will be
3151 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003152 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003153 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003154 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003155 tab_len += vc_saved;
3156 }
3157#endif
3158 mb_utf8 = FALSE; // don't draw as UTF-8
3159 if (wp->w_p_list)
3160 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003161 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003162 ? wp->w_lcs_chars.tab3
3163 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003164#ifdef FEAT_LINEBREAK
h-east194555c2023-03-02 18:49:09 +00003165 if (wp->w_p_lbr && wlv.p_extra != NULL
3166 && *wlv.p_extra != NUL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003167 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003168 else
3169#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003170 wlv.c_extra = wp->w_lcs_chars.tab2;
3171 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003172 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003173 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003174 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003175 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003176 mb_c = c;
3177 if (enc_utf8 && utf_char2len(c) > 1)
3178 {
3179 mb_utf8 = TRUE;
3180 u8cc[0] = 0;
3181 c = 0xc0;
3182 }
3183 }
3184 else
3185 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003186 wlv.c_final = NUL;
3187 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003188 c = ' ';
3189 }
3190 }
3191 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003192 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003193 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003194 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3195 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003196 && VIsual_mode != Ctrl_V
3197 && (
3198# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003199 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003200# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003201 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003202 && !(noinvcur
3203 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003204 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003205 && lcs_eol_one > 0)
3206 {
3207 // Display a '$' after the line or highlight an extra
3208 // character if the line break is included.
3209#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3210 // For a diff line the highlighting continues after the
3211 // "$".
3212 if (
3213# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003214 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003215# ifdef LINE_ATTR
3216 &&
3217# endif
3218# endif
3219# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003220 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003221# endif
3222 )
3223#endif
3224 {
3225 // In virtualedit, visual selections may extend
3226 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003227 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003228 && wlv.tocol != MAXCOL
3229 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003230 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003231 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003232 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003233 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3234 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003235 else
3236 c = ' ';
3237 lcs_eol_one = -1;
3238 --ptr; // put it back at the NUL
3239 if (!attr_pri)
3240 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003241 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003242 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003243 n_attr = 1;
3244 }
3245 mb_c = c;
3246 if (enc_utf8 && utf_char2len(c) > 1)
3247 {
3248 mb_utf8 = TRUE;
3249 u8cc[0] = 0;
3250 c = 0xc0;
3251 }
3252 else
3253 mb_utf8 = FALSE; // don't draw as UTF-8
3254 }
3255 else if (c != NUL)
3256 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003257 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3258 if (wlv.n_extra == 0)
3259 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003260#ifdef FEAT_RIGHTLEFT
3261 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003262 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003263#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003264 wlv.c_extra = NUL;
3265 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003266#ifdef FEAT_LINEBREAK
3267 if (wp->w_p_lbr)
3268 {
3269 char_u *p;
3270
Bram Moolenaar1306b362022-08-06 15:59:06 +01003271 c = *wlv.p_extra;
3272 p = alloc(wlv.n_extra + 1);
3273 vim_memset(p, ' ', wlv.n_extra);
3274 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3275 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003276 vim_free(wlv.p_extra_free);
3277 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003278 }
3279 else
3280#endif
3281 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003282 wlv.n_extra = byte2cells(c) - 1;
3283 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003284 }
3285 if (!attr_pri)
3286 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003287 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003288 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003289 HL_ATTR(HLF_8));
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003290#ifdef FEAT_PROP_POPUP
3291 if (text_prop_type != NULL &&
3292 text_prop_flags & PT_FLAG_OVERRIDE)
3293 wlv.extra_attr = hl_combine_attr(text_prop_attr, wlv.extra_attr);
3294#endif
3295
Bram Moolenaar1306b362022-08-06 15:59:06 +01003296 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003297 }
3298 mb_utf8 = FALSE; // don't draw as UTF-8
3299 }
3300 else if (VIsual_active
3301 && (VIsual_mode == Ctrl_V
3302 || VIsual_mode == 'v')
3303 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003304 && wlv.tocol != MAXCOL
3305 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003306 && (
3307#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003308 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003309#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003310 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003311 {
3312 c = ' ';
3313 --ptr; // put it back at the NUL
3314 }
3315#if defined(LINE_ATTR)
3316 else if ((
3317# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003318 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003319# endif
3320# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003321 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003322# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003323 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003324 ) && (
3325# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003326 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003327# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003328 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003329# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003330 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003331# endif
3332 < wp->w_width)))
3333 {
3334 // Highlight until the right side of the window
3335 c = ' ';
3336 --ptr; // put it back at the NUL
3337
3338 // Remember we do the char for line highlighting.
3339 ++did_line_attr;
3340
3341 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003342 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003343 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003344 || (wp->w_p_list &&
3345 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003346 wlv.char_attr = wlv.line_attr;
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003347#ifdef FEAT_SIGNS
3348 // At end of line: if Sign is present with line highlight, reset char_attr
Christian Brabandte1eaae22023-08-19 22:36:12 +02003349 // but not when cursorline is active
3350 if (sign_present && wlv.sattr.sat_linehl > 0 && wlv.draw_state == WL_LINE
3351 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum))
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003352 wlv.char_attr = wlv.sattr.sat_linehl;
3353#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003354# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003355 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003356 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003357 wlv.diff_hlf = HLF_CHD;
3358 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003359 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003360 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003361 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3362 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003363 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003364 || (wlv.vcol >= left_curline_col
3365 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003366 wlv.char_attr = hl_combine_attr(
3367 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003368 }
3369 }
3370# endif
3371# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003372 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003373 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003374 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003375 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3376 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003377 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003378 if (!wlv.cul_screenline
3379 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003380 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003381 wlv.char_attr = hl_combine_attr(
3382 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003383 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003384 else if (wlv.line_attr)
3385 wlv.char_attr = hl_combine_attr(
3386 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003387 }
3388# endif
3389 }
3390#endif
3391 }
3392
3393#ifdef FEAT_CONCEAL
3394 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003395 && (wp != curwin || lnum != wp->w_cursor.lnum
3396 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003397 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3398 && !(lnum_in_visual_area
3399 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3400 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003401 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003402 if (((prev_syntax_id != syntax_seqnr
3403 && (syntax_flags & HL_CONCEAL) != 0)
3404 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003405 && (syn_get_sub_char() != NUL
3406 || (has_match_conc && match_conc)
3407 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003408 && wp->w_p_cole != 3)
3409 {
3410 // First time at this concealed item: display one
3411 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003412 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003413 c = match_conc;
3414 else if (syn_get_sub_char() != NUL)
3415 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003416 else if (wp->w_lcs_chars.conceal != NUL)
3417 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003418 else
3419 c = ' ';
3420
3421 prev_syntax_id = syntax_seqnr;
3422
Bram Moolenaar1306b362022-08-06 15:59:06 +01003423 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003424 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003425 wlv.vcol += wlv.n_extra;
3426 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003427 {
3428# ifdef FEAT_RIGHTLEFT
3429 if (wp->w_p_rl)
3430 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003431 wlv.col -= wlv.n_extra;
3432 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003433 }
3434 else
3435# endif
3436 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003437 wlv.boguscols += wlv.n_extra;
3438 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003439 }
3440 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003441 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003442 n_attr = 0;
3443 }
zeertzjqb557f482023-08-22 22:07:34 +02003444 else if (skip_cells == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003445 {
3446 is_concealing = TRUE;
zeertzjqb557f482023-08-22 22:07:34 +02003447 skip_cells = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003448 }
3449 mb_c = c;
3450 if (enc_utf8 && utf_char2len(c) > 1)
3451 {
3452 mb_utf8 = TRUE;
3453 u8cc[0] = 0;
3454 c = 0xc0;
3455 }
3456 else
3457 mb_utf8 = FALSE; // don't draw as UTF-8
3458 }
3459 else
3460 {
3461 prev_syntax_id = 0;
3462 is_concealing = FALSE;
3463 }
3464
zeertzjqb557f482023-08-22 22:07:34 +02003465 if (skip_cells > 0 && did_decrement_ptr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003466 // not showing the '>', put pointer back to avoid getting stuck
3467 ++ptr;
3468
3469#endif // FEAT_CONCEAL
3470 }
3471
3472#ifdef FEAT_CONCEAL
3473 // In the cursor line and we may be concealing characters: correct
3474 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003475 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003476 && wp == curwin && lnum == wp->w_cursor.lnum
3477 && conceal_cursor_line(wp)
zeertzjqb557f482023-08-22 22:07:34 +02003478 && (int)wp->w_virtcol <= wlv.vcol + skip_cells)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003479 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003480# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003481 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003482 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003483 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003484# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003485 wp->w_wcol = wlv.col - wlv.boguscols;
3486 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003487 did_wcol = TRUE;
3488 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003489# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003490 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003491# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003492 }
3493#endif
3494
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003495 // Use "wlv.extra_attr", but don't override visual selection
3496 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003497 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3498 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003499 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003500 && (!attr_pri
3501#ifdef FEAT_PROP_POPUP
3502 || (text_prop_flags & PT_FLAG_OVERRIDE)
3503#endif
3504 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003505 {
3506#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003507 if (wlv.line_attr)
3508 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003509 else
3510#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003511 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003512#ifdef FEAT_PROP_POPUP
3513 if (reset_extra_attr)
3514 {
3515 reset_extra_attr = FALSE;
3516 wlv.extra_attr = 0;
3517 }
3518#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003519 }
3520
3521#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3522 // XIM don't send preedit_start and preedit_end, but they send
3523 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3524 // im_is_preediting() here.
3525 if (p_imst == IM_ON_THE_SPOT
3526 && xic != NULL
3527 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003528 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003529 && !p_imdisable
3530 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003531 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003532 {
3533 colnr_T tcol;
3534
3535 if (preedit_end_col == MAXCOL)
3536 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3537 else
3538 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003539 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003540 {
3541 if (feedback_old_attr < 0)
3542 {
3543 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003544 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003545 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003546 wlv.char_attr = im_get_feedback_attr(feedback_col);
3547 if (wlv.char_attr < 0)
3548 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003549 feedback_col++;
3550 }
3551 else if (feedback_old_attr >= 0)
3552 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003553 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003554 feedback_old_attr = -1;
3555 feedback_col = 0;
3556 }
3557 }
3558#endif
3559 // Handle the case where we are in column 0 but not on the first
3560 // character of the line and the user wants us to show us a
3561 // special character (via 'listchars' option "precedes:<char>".
3562 if (lcs_prec_todo != NUL
3563 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003564 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3565 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003566#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003567 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003568#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003569 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003570 && c != NUL)
3571 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003572 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003573 lcs_prec_todo = NUL;
3574 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3575 {
3576 // Double-width character being overwritten by the "precedes"
3577 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003578 wlv.c_extra = MB_FILLER_CHAR;
3579 wlv.c_final = NUL;
3580 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003581 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003582 wlv.extra_attr =
3583 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003584 }
3585 mb_c = c;
3586 if (enc_utf8 && utf_char2len(c) > 1)
3587 {
3588 mb_utf8 = TRUE;
3589 u8cc[0] = 0;
3590 c = 0xc0;
3591 }
3592 else
3593 mb_utf8 = FALSE; // don't draw as UTF-8
3594 if (!attr_pri)
3595 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003596 saved_attr3 = wlv.char_attr; // save current attr
3597 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003598 n_attr3 = 1;
3599 }
3600 }
3601
3602 // At end of the text line or just after the last character.
3603 if ((c == NUL
3604#if defined(LINE_ATTR)
3605 || did_line_attr == 1
3606#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003607 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003608 {
3609#ifdef FEAT_SEARCH_EXTRA
3610 // flag to indicate whether prevcol equals startcol of search_hl or
3611 // one of the matches
3612 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3613 (long)(ptr - line) - (c == NUL));
3614#endif
3615 // Invert at least one char, used for Visual and empty line or
3616 // highlight match at end of line. If it's beyond the last
3617 // char on the screen, just overwrite that one (tricky!) Not
3618 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003619 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003620 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003621 && (VIsual_mode != Ctrl_V
3622 || lnum == VIsual.lnum
3623 || lnum == curwin->w_cursor.lnum)
3624 && c == NUL)
3625#ifdef FEAT_SEARCH_EXTRA
3626 // highlight 'hlsearch' match at end of line
3627 || (prevcol_hl_flag
3628# ifdef FEAT_SYN_HL
3629 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3630 && !(wp == curwin && VIsual_active))
3631# endif
3632# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003633 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003634# endif
3635# if defined(LINE_ATTR)
3636 && did_line_attr <= 1
3637# endif
3638 )
3639#endif
3640 ))
3641 {
3642 int n = 0;
3643
3644#ifdef FEAT_RIGHTLEFT
3645 if (wp->w_p_rl)
3646 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003647 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003648 n = 1;
3649 }
3650 else
3651#endif
3652 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003653 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003654 n = -1;
3655 }
3656 if (n != 0)
3657 {
3658 // At the window boundary, highlight the last character
3659 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003660 wlv.off += n;
3661 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003662 }
3663 else
3664 {
3665 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003666 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003667 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003668 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003669 }
3670#ifdef FEAT_SEARCH_EXTRA
3671 if (area_attr == 0)
3672 {
3673 // Use attributes from match with highest priority among
3674 // 'search_hl' and the match list.
3675 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003676 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003677 }
3678#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003679 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003680 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003681#ifdef FEAT_RIGHTLEFT
3682 if (wp->w_p_rl)
3683 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003684 --wlv.col;
3685 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003686 }
3687 else
3688#endif
3689 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003690 ++wlv.col;
3691 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003692 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003693 ++wlv.vcol;
3694 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003695 }
3696 }
3697
3698 // At end of the text line.
3699 if (c == NUL)
3700 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003701#ifdef FEAT_PROP_POPUP
3702 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003703 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003704 // Put the pointer back to the NUL.
3705 --ptr;
3706 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003707 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003708 else
3709#endif
3710 {
3711 draw_screen_line(wp, &wlv);
3712
3713 // Update w_cline_height and w_cline_folded if the cursor line
3714 // was updated (saves a call to plines() later).
3715 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3716 {
3717 curwin->w_cline_row = startrow;
3718 curwin->w_cline_height = wlv.row - startrow;
3719#ifdef FEAT_FOLDING
3720 curwin->w_cline_folded = FALSE;
3721#endif
3722 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3723 }
3724 break;
3725 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003726 }
3727
3728 // Show "extends" character from 'listchars' if beyond the line end and
3729 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003730 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003731 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003732 && wp->w_p_list
3733 && !wp->w_p_wrap
3734#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003735 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003736#endif
3737 && (
3738#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003739 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003740#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003741 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003742 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003743 || lcs_eol_one > 0
3744 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
zeertzjq6a389722023-08-27 19:04:14 +02003745 || *wlv.p_extra != NUL))
3746#ifdef FEAT_PROP_POPUP
3747 || text_prop_next < text_prop_count
3748#endif
3749 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003750 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003751 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003752 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003753 mb_c = c;
3754 if (enc_utf8 && utf_char2len(c) > 1)
3755 {
3756 mb_utf8 = TRUE;
3757 u8cc[0] = 0;
3758 c = 0xc0;
3759 }
3760 else
3761 mb_utf8 = FALSE;
3762 }
3763
3764#ifdef FEAT_SYN_HL
3765 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003766 if (wlv.draw_color_col)
3767 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003768
3769 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3770 // highlight the cursor position itself.
3771 // Also highlight the 'colorcolumn' if it is different than
3772 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003773 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3774 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003775 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003776 if (((wlv.draw_state == WL_LINE
3777 || wlv.draw_state == WL_BRI
3778 || wlv.draw_state == WL_SBR)
3779 && !lnum_in_visual_area
3780 && search_attr == 0
3781 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003782# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003783 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003784# endif
3785 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003786 {
3787 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3788 && lnum != wp->w_cursor.lnum)
3789 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003790 vcol_save_attr = wlv.char_attr;
3791 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3792 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003793 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003794 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003795 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003796 vcol_save_attr = wlv.char_attr;
3797 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003798 }
3799 }
3800#endif
3801
zeertzjq8fc6a1d2023-08-20 18:12:54 +02003802 if (wlv.draw_state == WL_LINE)
3803 vcol_prev = wlv.vcol;
3804
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003805 // Store character to be displayed.
3806 // Skip characters that are left of the screen for 'nowrap'.
zeertzjqb557f482023-08-22 22:07:34 +02003807 if (wlv.draw_state < WL_LINE || skip_cells <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003808 {
3809 // Store the character.
3810#if defined(FEAT_RIGHTLEFT)
3811 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3812 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003813 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003814 --wlv.off;
3815 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003816 }
3817#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003818 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003819 if (enc_dbcs == DBCS_JPNU)
3820 {
3821 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003822 ScreenLines[wlv.off] = 0x8e;
3823 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003824 }
3825 else if (enc_utf8)
3826 {
3827 if (mb_utf8)
3828 {
3829 int i;
3830
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003831 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003832 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003833 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003834 for (i = 0; i < Screen_mco; ++i)
3835 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003836 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003837 if (u8cc[i] == 0)
3838 break;
3839 }
3840 }
3841 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003842 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003843 }
3844 if (multi_attr)
3845 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003846 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003847 multi_attr = 0;
3848 }
3849 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003850 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003851
zeertzjqe500ae82023-08-17 22:35:26 +02003852 ScreenCols[wlv.off] = wlv.vcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003853
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003854 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3855 {
3856 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003857 ++wlv.off;
3858 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003859 if (enc_utf8)
3860 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003861 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003862 else
3863 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003864 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003865 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003866#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003867 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003868#endif
3869 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003870 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003871 // When "wlv.tocol" is halfway a character, set it to the end
3872 // of the character, otherwise highlighting won't stop.
3873 if (wlv.tocol == wlv.vcol)
3874 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003875
zeertzjqe500ae82023-08-17 22:35:26 +02003876 ScreenCols[wlv.off] = wlv.vcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003877
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003878#ifdef FEAT_RIGHTLEFT
3879 if (wp->w_p_rl)
3880 {
3881 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003882 --wlv.off;
3883 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003884 }
3885#endif
3886 }
3887#ifdef FEAT_RIGHTLEFT
3888 if (wp->w_p_rl)
3889 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003890 --wlv.off;
3891 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003892 }
3893 else
3894#endif
3895 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003896 ++wlv.off;
3897 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003898 }
3899 }
3900#ifdef FEAT_CONCEAL
3901 else if (wp->w_p_cole > 0 && is_concealing)
3902 {
zeertzjqb557f482023-08-22 22:07:34 +02003903 --skip_cells;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003904 ++wlv.vcol_off_co;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003905 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003906 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003907 if (wp->w_p_wrap)
3908 {
3909 // Special voodoo required if 'wrap' is on.
3910 //
3911 // Advance the column indicator to force the line
3912 // drawing to wrap early. This will make the line
3913 // take up the same screen space when parts are concealed,
3914 // so that cursor line computations aren't messed up.
3915 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003916 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003917 // trailing junk to be written out of the screen line
3918 // we are building, 'boguscols' keeps track of the number
3919 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003920 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003921 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003922 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003923# ifdef FEAT_RIGHTLEFT
3924 if (wp->w_p_rl)
3925 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003926 wlv.col -= wlv.n_extra;
3927 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003928 }
3929 else
3930# endif
3931 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003932 wlv.col += wlv.n_extra;
3933 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003934 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003935 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003936 n_attr = 0;
3937 }
3938
3939
3940 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3941 {
3942 // Need to fill two screen columns.
3943# ifdef FEAT_RIGHTLEFT
3944 if (wp->w_p_rl)
3945 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003946 --wlv.boguscols;
3947 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003948 }
3949 else
3950# endif
3951 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003952 ++wlv.boguscols;
3953 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003954 }
3955 }
3956
3957# ifdef FEAT_RIGHTLEFT
3958 if (wp->w_p_rl)
3959 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003960 --wlv.boguscols;
3961 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003962 }
3963 else
3964# endif
3965 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003966 ++wlv.boguscols;
3967 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003968 }
3969 }
3970 else
3971 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003972 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003973 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003974 wlv.vcol += wlv.n_extra;
3975 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003976 n_attr = 0;
3977 }
3978 }
3979
3980 }
3981#endif // FEAT_CONCEAL
3982 else
zeertzjqb557f482023-08-22 22:07:34 +02003983 --skip_cells;
3984
3985 if (wlv.draw_state > WL_NR && skipped_cells > 0)
3986 {
3987 wlv.vcol += skipped_cells;
3988 skipped_cells = 0;
3989 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003990
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003991 // Only advance the "wlv.vcol" when after the 'number' or
3992 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003993 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003994#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003995 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003996#endif
3997 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003998 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003999
4000#ifdef FEAT_SYN_HL
4001 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004002 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004003#endif
4004
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004005 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01004006 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
4007 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004008
4009 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01004010 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004011 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004012 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004013 if (wlv.n_attr_skip > 0)
4014 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004015
4016 // At end of screen line and there is more to come: Display the line
4017 // so far. If there is no more to display it is caught above.
4018 if ((
4019#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004020 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004021#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004022 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01004023 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02004024 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004025#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004026 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004027#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004028#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004029 || text_prop_above || text_prop_follows
zeertzjq6a389722023-08-27 19:04:14 +02004030 || text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004031#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01004032 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01004033 && wlv.p_extra != at_end_str)
4034 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
4035 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004036 )
4037 {
4038#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01004039 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01004040 wlv_screen_line(wp, &wlv, FALSE);
4041 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004042 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004043 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004044#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01004045 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004046#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004047 ++wlv.row;
4048 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004049
4050 // When not wrapping and finished diff lines, or when displayed
4051 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01004052 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004053#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004054 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004055#endif
4056#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01004057 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004058#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01004059 ) || lcs_eol_one == -1)
4060#ifdef FEAT_PROP_POPUP
4061 && !text_prop_follows
4062#endif
4063 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004064 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004065#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004066 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004067 {
4068 // do not output more of the line, only the "below" prop
4069 ptr += STRLEN(ptr);
4070# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004071 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004072# endif
4073 }
4074#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004075
4076 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004077 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004078#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004079 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004080#endif
4081 )
4082 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004083 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
4084 draw_vsep_win(wp, wlv.row);
4085 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004086 }
4087
4088 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004089 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004090 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004091 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004092 break;
4093 }
4094
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004095 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004096#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004097 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004098#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004099#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004100 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004101#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004102 && wp->w_width == Columns)
4103 {
4104 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004105 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004106
4107 // Special trick to make copy/paste of wrapped lines work with
4108 // xterm/screen: write an extra character beyond the end of
4109 // the line. This will work with all terminal types
4110 // (regardless of the xn,am settings).
4111 // Only do this on a fast tty.
4112 // Only do this if the cursor is on the current line
4113 // (something has been written in it).
4114 // Don't do this for the GUI.
4115 // Don't do this for double-width characters.
4116 // Don't do this for a window not at the right screen border.
4117 if (p_tf
4118#ifdef FEAT_GUI
4119 && !gui.in_use
4120#endif
4121 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004122 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4123 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004124 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004125 || (*mb_off2cells)(
4126 LineOffset[wlv.screen_row - 1]
4127 + (int)Columns - 2,
4128 LineOffset[wlv.screen_row]
4129 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004130 {
4131 // First make sure we are at the end of the screen line,
4132 // then output the same character again to let the
4133 // terminal know about the wrap. If the terminal doesn't
4134 // auto-wrap, we overwrite the character.
4135 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004136 screen_char(LineOffset[wlv.screen_row - 1]
4137 + (unsigned)Columns - 1,
4138 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004139
4140 // When there is a multi-byte character, just output a
4141 // space to keep it simple.
4142 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004143 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004144 out_char(' ');
4145 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004146 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004147 + (Columns - 1)]);
4148 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004149 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004150 screen_start(); // don't know where cursor is now
4151 }
4152 }
4153
Bram Moolenaar1306b362022-08-06 15:59:06 +01004154 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004155
Bram Moolenaareed9d462021-02-15 20:38:25 +01004156 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004157#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004158 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004159# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004160 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004161# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004162 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004163 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004164#endif
4165#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004166 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004167 // When the filler lines are actually below the last line of the
4168 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004169 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004170 break;
4171#endif
4172 }
4173
4174 } // for every character in the line
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004175#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004176 vim_free(text_props);
4177 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004178 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004179#endif
4180
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004181 vim_free(wlv.p_extra_free);
zeertzjq58e1e012023-06-04 18:46:28 +01004182 vim_free(wlv.saved_p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004183 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004184}