blob: 4d63fae34da3ca5beebec5fe1332858994daeb7e [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);
zeertzjqabc80812023-09-24 23:32:18 +02001687 if (wp->w_p_list)
1688 {
1689 in_multispace = *prev_ptr == ' ' && (*cts.cts_ptr == ' '
1690 || (prev_ptr > line && prev_ptr[-1] == ' '));
1691 if (!in_multispace)
1692 multispace_pos = 0;
1693 else if (cts.cts_ptr >= line + leadcol
1694 && wp->w_lcs_chars.multispace != NULL)
1695 {
1696 ++multispace_pos;
1697 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
1698 multispace_pos = 0;
1699 }
1700 else if (cts.cts_ptr < line + leadcol
1701 && wp->w_lcs_chars.leadmultispace != NULL)
1702 {
1703 ++multispace_pos;
1704 if (wp->w_lcs_chars.leadmultispace[multispace_pos] == NUL)
1705 multispace_pos = 0;
1706 }
1707 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001708 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001709 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001710 ptr = cts.cts_ptr;
1711 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001712
1713 // When:
1714 // - 'cuc' is set, or
1715 // - 'colorcolumn' is set, or
1716 // - 'virtualedit' is set, or
1717 // - the visual mode is active,
1718 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001719 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001720#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001721 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001722#endif
1723 virtual_active() ||
1724 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001725 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001726
1727 // Handle a character that's not completely on the screen: Put ptr at
1728 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001729 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001730 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001731 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001732 ptr = prev_ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001733 }
zeertzjqb557f482023-08-22 22:07:34 +02001734 if (v > wlv.vcol)
1735 skip_cells = v - wlv.vcol - head;
Bram Moolenaarcd105412022-10-10 19:50:42 +01001736
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001737 // Adjust for when the inverted text is before the screen,
1738 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001739 if (wlv.tocol <= wlv.vcol)
1740 wlv.fromcol = 0;
1741 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1742 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001743
1744#ifdef FEAT_LINEBREAK
1745 // When w_skipcol is non-zero, first line needs 'showbreak'
1746 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001747 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001748#endif
1749#ifdef FEAT_SPELL
1750 // When spell checking a word we need to figure out the start of the
1751 // word and if it's badly spelled or not.
Luuk van Baal30805a12023-05-27 22:22:10 +01001752 if (spv->spv_has_spell)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001753 {
1754 int len;
1755 colnr_T linecol = (colnr_T)(ptr - line);
1756 hlf_T spell_hlf = HLF_COUNT;
1757
1758 pos = wp->w_cursor;
1759 wp->w_cursor.lnum = lnum;
1760 wp->w_cursor.col = linecol;
1761 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1762
1763 // spell_move_to() may call ml_get() and make "line" invalid
1764 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1765 ptr = line + linecol;
1766
1767 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1768 {
1769 // no bad word found at line start, don't check until end of a
1770 // word
1771 spell_hlf = HLF_COUNT;
1772 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1773 }
1774 else
1775 {
1776 // bad word found, use attributes until end of word
1777 word_end = wp->w_cursor.col + len + 1;
1778
1779 // Turn index into actual attributes.
1780 if (spell_hlf != HLF_COUNT)
1781 spell_attr = highlight_attr[spell_hlf];
1782 }
1783 wp->w_cursor = pos;
1784
1785# ifdef FEAT_SYN_HL
1786 // Need to restart syntax highlighting for this line.
1787 if (has_syntax)
1788 syntax_start(wp, lnum);
1789# endif
1790 }
1791#endif
1792 }
1793
1794 // Correct highlighting for cursor that can't be disabled.
1795 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001796 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001797 {
1798 if (noinvcur)
1799 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001800 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001801 {
1802 // highlighting starts at cursor, let it start just after the
1803 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001804 fromcol_prev = wlv.fromcol;
1805 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001806 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001807 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001808 // restart highlighting after the cursor
1809 fromcol_prev = wp->w_virtcol;
1810 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001811 if (wlv.fromcol >= wlv.tocol)
1812 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001813 }
1814
1815#ifdef FEAT_SEARCH_EXTRA
1816 if (!number_only)
1817 {
1818 v = (long)(ptr - line);
1819 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1820 &line, &screen_search_hl,
1821 &search_attr);
1822 ptr = line + v; // "line" may have been updated
1823 }
1824#endif
1825
1826#ifdef FEAT_SYN_HL
1827 // Cursor line highlighting for 'cursorline' in the current window.
1828 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1829 {
1830 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001831 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001832 if (!(wp == curwin && VIsual_active)
1833 && wp->w_p_culopt_flags != CULOPT_NBR)
1834 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001835 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001836 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1837
zeertzjqb7acea12022-12-12 13:20:43 +00001838 // Only apply CursorLine highlight here when "screenline" is not
1839 // present in 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001840 if (!wlv.cul_screenline)
zeertzjqb7acea12022-12-12 13:20:43 +00001841 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001842 else
1843 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001844 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001845 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1846 }
1847 area_highlighting = TRUE;
1848 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001849 }
1850#endif
1851
Bram Moolenaar1306b362022-08-06 15:59:06 +01001852 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001853
1854 // Repeat for the whole displayed line.
1855 for (;;)
1856 {
1857#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001858 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001859#endif
1860#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001861 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001862#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001863
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001864 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001865 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001866 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001867#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001868 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001869 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001870 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001871 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001872 }
1873#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001874 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001875 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001876 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001877 if (cmdwin_type != 0 && wp == curwin)
1878 {
1879 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001880 wlv.n_extra = 1;
1881 wlv.c_extra = cmdwin_type;
1882 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001883 wlv.char_attr =
1884 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001885 }
1886 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001887#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001888 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001889 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001890 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001891 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001892 }
1893#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001894#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001895 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001896 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001897 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001898 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001899 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001900 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001901 }
1902#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001903 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001904 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001905 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001906 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001907 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001908 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001909#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001910 // Check if 'breakindent' applies and show it.
1911 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1912 if (wlv.n_extra == 0)
1913 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001914#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001915#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001916 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001917 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001918 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001919 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001920 }
1921#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001922 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001923 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001924 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001925 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001926 }
1927 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001928
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001929#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001930 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001931 && wlv.vcol >= left_curline_col
1932 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001933 {
zeertzjqb7acea12022-12-12 13:20:43 +00001934 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001935 }
1936#endif
1937
1938 // When still displaying '$' of change command, stop at cursor.
1939 // When only displaying the (relative) line number and that's done,
1940 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001941 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001942 && lnum == wp->w_cursor.lnum
1943 && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001944 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001945#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001946 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001947#endif
1948 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001949 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001950 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001951 // Pretend we have finished updating the window. Except when
1952 // 'cursorcolumn' is set.
1953#ifdef FEAT_SYN_HL
1954 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001955 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001956 else
1957#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001958 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001959 break;
1960 }
1961
Bram Moolenaar1306b362022-08-06 15:59:06 +01001962 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001963 {
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001964#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001965 if (text_props != NULL)
1966 {
1967 int pi;
1968 int bcol = (int)(ptr - line);
1969
Bram Moolenaar1306b362022-08-06 15:59:06 +01001970 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001971# ifdef FEAT_LINEBREAK
1972 && !in_linebreak
1973# endif
1974 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001975 --bcol; // still working on the previous char, e.g. Tab
1976
1977 // Check if any active property ends.
1978 for (pi = 0; pi < text_props_active; ++pi)
1979 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001980 int tpi = text_prop_idxs[pi];
1981 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001982
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001983 // An inline property ends when after the start column plus
1984 // length. An "above" property ends when used and n_extra
1985 // is zero.
1986 if ((tp->tp_col != MAXCOL
1987 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001988 {
1989 if (pi + 1 < text_props_active)
1990 mch_memmove(text_prop_idxs + pi,
1991 text_prop_idxs + pi + 1,
1992 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001993 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001994 --text_props_active;
1995 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001996# ifdef FEAT_LINEBREAK
1997 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001998 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001999 syntax_attr = 0;
2000# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002001 }
2002 }
2003
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002004# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01002005 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002006 // not on the next char yet, don't start another prop
2007 --bcol;
2008# endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002009 int display_text_first = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002010
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002011 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002012 // With 'nowrap' and not in the first screen line only "below"
2013 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002014 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002015 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002016 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002017 && (wp->w_p_wrap
2018 || wlv.row == startrow
2019 || (text_props[text_prop_next].tp_flags
2020 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002021 || (bcol == 0
2022 && (text_props[text_prop_next].tp_flags
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002023 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002024 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002025 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01002026 if (text_props[text_prop_next].tp_col == MAXCOL
2027 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002028 + text_props[text_prop_next].tp_len)
2029 text_prop_idxs[text_props_active++] = text_prop_next;
2030 ++text_prop_next;
2031 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002032
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002033 if (wlv.n_extra == 0 ||
2034 (!wlv.extra_for_textprop
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002035 && !(text_prop_type != NULL &&
2036 text_prop_flags & PT_FLAG_OVERRIDE)
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002037 ))
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002038 {
2039 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002040 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002041 text_prop_flags = 0;
2042 text_prop_type = NULL;
2043 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002044 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002045 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002046 if (text_props_active > 0 && wlv.n_extra == 0
2047 && !display_text_first)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002048 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01002049 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002050 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002051 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002052
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002053 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002054 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002055
2056 // Sort the properties on priority and/or starting last.
2057 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002058 sort_text_props(wp->w_buffer, text_props,
2059 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002060
2061 for (pi = 0; pi < text_props_active; ++pi)
2062 {
2063 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002064 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002065 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002066 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002067
Bram Moolenaarcd105412022-10-10 19:50:42 +01002068 // Only use a text property that can be displayed.
2069 // Skip "after" properties when wrap is off and at the
2070 // end of the window.
2071 if (pt != NULL
2072 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2073 && tp->tp_id != -MAXCOL
2074 && !(tp->tp_id < 0
2075 && !wp->w_p_wrap
2076 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2077 | TP_FLAG_ALIGN_ABOVE
2078 | TP_FLAG_ALIGN_BELOW)) == 0
2079 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002080 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002081 if (tp->tp_col == MAXCOL
2082 && *ptr == NUL
2083 && ((wp->w_p_list && lcs_eol_one > 0
2084 && (tp->tp_flags
2085 & TP_FLAG_ALIGN_ABOVE) == 0)
2086 || (ptr == line
2087 && !did_line
2088 && (tp->tp_flags
2089 & TP_FLAG_ALIGN_BELOW))))
2090 {
2091 // skip this prop, first display the '$' after
2092 // the line or display an empty line
2093 text_prop_follows = TRUE;
2094 if (used_tpi < 0)
2095 display_text_first = TRUE;
2096 continue;
2097 }
2098
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002099 if (pt->pt_hl_id > 0)
2100 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002101 text_prop_type = pt;
2102 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002103 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002104 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2105 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002106 text_prop_flags = pt->pt_flags;
2107 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002108 used_tpi = tpi;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002109 display_text_first = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002110 }
2111 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002112 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002113 && -text_prop_id
2114 <= wp->w_buffer->b_textprop_text.ga_len)
2115 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002116 textprop_T *tp = &text_props[used_tpi];
2117 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002118 ->b_textprop_text.ga_data)[
2119 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002120 int above = (tp->tp_flags
2121 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002122 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002123
2124 // reset the ID in the copy to avoid it being used
2125 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002126 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002127
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002128 if (p != NULL)
2129 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002130 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002131 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002132 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002133 & TP_FLAG_ALIGN_BELOW);
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002134 int wrap = tp->tp_col < MAXCOL
2135 || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002136 int padding = tp->tp_col == MAXCOL
2137 && tp->tp_len > 1
2138 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002139
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002140 // Insert virtual text before the current
2141 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002142 wlv.p_extra = p;
2143 wlv.c_extra = NUL;
2144 wlv.c_final = NUL;
2145 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002146 wlv.extra_for_textprop = TRUE;
zeertzjq6e940d92023-08-17 23:21:40 +02002147 wlv.start_extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002148 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2149 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002150 n_attr = mb_charlen(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002151 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002152 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002153 if (*ptr == NUL)
2154 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002155 text_prop_flags &= ~PT_FLAG_COMBINE;
zeertzjq6b9c2022023-09-11 20:01:17 +02002156# ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002157 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002158 {
2159 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002160 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002161 wlv.need_showbreak = FALSE;
2162 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002163 }
zeertzjq6b9c2022023-09-11 20:01:17 +02002164# endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002165 if ((right || above || below || !wrap
2166 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002167 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002168 char_u *prev_p_extra = wlv.p_extra;
2169 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002170
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002171 // Take care of padding, right-align and
2172 // truncation.
2173 // Shared with win_lbr_chartabsize(), must do
2174 // exactly the same.
2175 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002176 wlv.vcol,
zeertzjq6b9c2022023-09-11 20:01:17 +02002177# ifdef FEAT_RIGHTLEFT
2178 wp->w_p_rl
2179 ? wp->w_width - wlv.col - 1
2180 :
2181# endif
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002182 wlv.col,
2183 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002184 &n_attr, &wlv.n_attr_skip,
2185 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002186 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002187 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002188 // wlv.p_extra was allocated
2189 vim_free(p_extra_free2);
2190 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002191 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002192
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002193 if (above)
2194 wlv.vcol_off_tp = wlv.n_extra;
2195
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002196 if (lcs_eol_one < 0
2197 && wp->w_p_wrap
2198 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002199 + wlv.n_extra - 2 > wp->w_width)
2200 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002201 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002202
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002203 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002204 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002205 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002206 {
2207 draw_screen_line(wp, &wlv);
2208
2209 // When line got too long for screen break
2210 // here.
2211 if (wlv.row == endrow)
2212 {
2213 ++wlv.row;
2214 break;
2215 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002216 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002217 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002218 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002219 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002220 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002221
Bram Moolenaarcd105412022-10-10 19:50:42 +01002222 // If the text didn't reach until the first window
2223 // column we need to skip cells.
2224 if (skip_cells > 0)
2225 {
2226 if (wlv.n_extra > skip_cells)
2227 {
2228 wlv.n_extra -= skip_cells;
2229 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002230 wlv.n_attr_skip -= skip_cells;
2231 if (wlv.n_attr_skip < 0)
2232 wlv.n_attr_skip = 0;
zeertzjqb557f482023-08-22 22:07:34 +02002233 skipped_cells += skip_cells;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002234 skip_cells = 0;
2235 }
2236 else
2237 {
2238 // the whole text is left of the window, drop
2239 // it and advance to the next one
2240 skip_cells -= wlv.n_extra;
zeertzjqb557f482023-08-22 22:07:34 +02002241 skipped_cells += wlv.n_extra;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002242 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002243 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002244 bail_out = TRUE;
2245 }
2246 }
2247
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002248 // If another text prop follows the condition below at
2249 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002250 // If this is an "above" text prop and 'nowrap' the we
2251 // must wrap anyway.
2252 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002253 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002254 && (wp->w_p_wrap
2255 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002256 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002257
2258 if (bail_out)
2259 // starting a new line for "below"
2260 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002261 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002262 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002263 else if (text_prop_next < text_prop_count
2264 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002265 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2266 || (!wp->w_p_wrap
2267 && wlv.col == wp->w_width - 1
2268 && (text_props[text_prop_next].tp_flags
2269 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002270 // When at last-but-one character and a text property
2271 // follows after it, we may need to flush the line after
2272 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002273 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002274 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002275 }
zeertzjq6e940d92023-08-17 23:21:40 +02002276
2277 if (wlv.start_extra_for_textprop)
2278 {
2279 wlv.start_extra_for_textprop = FALSE;
2280 // restore search_attr and area_attr when n_extra
2281 // is down to zero
2282 saved_search_attr = search_attr;
2283 saved_area_attr = area_attr;
2284 search_attr = 0;
2285 area_attr = 0;
2286 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002287#endif
2288
zeertzjq6e940d92023-08-17 23:21:40 +02002289 int *area_attr_p =
2290#ifdef FEAT_PROP_POPUP
2291 wlv.extra_for_textprop ? &saved_area_attr :
2292#endif
2293 &area_attr;
2294
2295 // handle Visual or match highlighting in this line
2296 if (wlv.vcol == wlv.fromcol
2297 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
2298 && ((wlv.n_extra == 0 && (*mb_ptr2cells)(ptr) > 1)
2299 || (wlv.n_extra > 0 && wlv.p_extra != NULL
2300 && (*mb_ptr2cells)(wlv.p_extra) > 1)))
2301 || ((int)vcol_prev == fromcol_prev
2302 && vcol_prev < wlv.vcol // not at margin
2303 && wlv.vcol < wlv.tocol))
2304 *area_attr_p = vi_attr; // start highlighting
2305 else if (*area_attr_p != 0
2306 && (wlv.vcol == wlv.tocol
2307 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
2308 *area_attr_p = 0; // stop highlighting
2309
zeertzjqe500ae82023-08-17 22:35:26 +02002310#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaare38fc862022-08-11 17:24:50 +01002311 if (wlv.n_extra == 0)
2312 {
2313 // Check for start/end of 'hlsearch' and other matches.
2314 // After end, check for start/end of next match.
2315 // When another match, have to check for start again.
2316 v = (long)(ptr - line);
2317 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2318 &screen_search_hl, &has_match_conc,
2319 &match_conc, did_line_attr, lcs_eol_one,
2320 &on_last_col);
2321 ptr = line + v; // "line" may have been changed
Bram Moolenaare38fc862022-08-11 17:24:50 +01002322
2323 // Do not allow a conceal over EOL otherwise EOL will be missed
2324 // and bad things happen.
2325 if (*ptr == NUL)
2326 has_match_conc = 0;
zeertzjqb25dbb32023-08-13 18:11:05 +02002327 }
zeertzjqe500ae82023-08-17 22:35:26 +02002328#endif
zeertzjqb25dbb32023-08-13 18:11:05 +02002329
Bram Moolenaare38fc862022-08-11 17:24:50 +01002330#ifdef FEAT_DIFF
2331 if (wlv.diff_hlf != (hlf_T)0)
2332 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002333 // When there is extra text (e.g. virtual text) it gets the
2334 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002335 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2336 && wlv.n_extra == 0)
2337 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002338 if (wlv.diff_hlf == HLF_TXD
2339 && ((ptr - line > change_end && wlv.n_extra == 0)
2340 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002341 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002342 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002343 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2344 && wp->w_p_culopt_flags != CULOPT_NBR
2345 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2346 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002347 wlv.line_attr = hl_combine_attr(
2348 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002349 }
2350#endif
2351
Bram Moolenaara74fda62019-10-19 17:38:03 +02002352#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002353 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002354 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002355 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002356# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002357 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002358 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002359# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002360 // Get syntax attribute.
2361 if (has_syntax)
2362 {
2363 // Get the syntax attribute for the character. If there
2364 // is an error, disable syntax highlighting.
2365 save_did_emsg = did_emsg;
2366 did_emsg = FALSE;
2367
2368 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002369 if (v == prev_syntax_col)
2370 // at same column again
2371 syntax_attr = prev_syntax_attr;
2372 else
2373 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002374# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002375 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002376# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002377 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002378# ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01002379 spv->spv_has_spell ? &can_spell :
Bram Moolenaar34390282019-10-16 14:38:26 +02002380# endif
Luuk van Baal30805a12023-05-27 22:22:10 +01002381 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002382 prev_syntax_col = v;
2383 prev_syntax_attr = syntax_attr;
2384 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002385
Bram Moolenaar34390282019-10-16 14:38:26 +02002386 if (did_emsg)
2387 {
2388 wp->w_s->b_syn_error = TRUE;
2389 has_syntax = FALSE;
2390 syntax_attr = 0;
2391 }
2392 else
2393 did_emsg = save_did_emsg;
2394# ifdef SYN_TIME_LIMIT
2395 if (wp->w_s->b_syn_slow)
2396 has_syntax = FALSE;
2397# endif
2398
2399 // Need to get the line again, a multi-line regexp may
2400 // have made it invalid.
2401 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2402 ptr = line + v;
2403# ifdef FEAT_CONCEAL
2404 // no concealing past the end of the line, it interferes
2405 // with line highlighting
2406 if (*ptr == NUL)
2407 syntax_flags = 0;
2408 else
2409 syntax_flags = get_syntax_info(&syntax_seqnr);
2410# endif
2411 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002412 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002413# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002414 // Combine text property highlight into syntax highlight.
2415 if (text_prop_type != NULL)
2416 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002417 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002418 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2419 else
2420 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002421 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002422 }
2423# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002424#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002425
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002426 // Decide which of the highlight attributes to use.
2427 attr_pri = TRUE;
2428#ifdef LINE_ATTR
2429 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002430 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002431 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002432 if (!highlight_match)
2433 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002434 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002435# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002436 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002437# endif
2438 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002439 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002440 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002441 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002442# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002443 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002444# endif
2445 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002446 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002447 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2448 || wlv.vcol < wlv.fromcol
2449 || vcol_prev < fromcol_prev
2450 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002451 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002452 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002453 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002454# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002455 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002456# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002457 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002458# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002459 attr_pri = FALSE;
2460 }
2461#else
2462 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002463 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002464 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002465 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002466#endif
2467 else
2468 {
2469 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002470#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002471 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002472#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002473 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002474#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002475 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002476#ifdef FEAT_PROP_POPUP
2477 // override with text property highlight when "override" is TRUE
2478 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002479 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002480#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002481 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002482
2483 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002484 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002485 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002486 if (wlv.char_attr == 0)
2487 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002488 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002489 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002490 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002491
2492 // Get the next character to put on the screen.
2493
2494 // The "p_extra" points to the extra stuff that is inserted to
2495 // represent special characters (non-printable stuff) and other
2496 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002497 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002498 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2499 // "p_extra[n_extra]".
2500 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002501 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002502 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002503 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002504 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002505 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2506 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002507 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2508 if (enc_utf8 && utf_char2len(c) > 1)
2509 {
2510 mb_utf8 = TRUE;
2511 u8cc[0] = 0;
2512 c = 0xc0;
2513 }
2514 else
2515 mb_utf8 = FALSE;
2516 }
2517 else
2518 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002519 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002520 if (has_mbyte)
2521 {
2522 mb_c = c;
2523 if (enc_utf8)
2524 {
2525 // If the UTF-8 character is more than one byte:
2526 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002527 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002528 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002529 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002530 mb_l = 1;
2531 else if (mb_l > 1)
2532 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002533 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002534 mb_utf8 = TRUE;
2535 c = 0xc0;
2536 }
2537 }
2538 else
2539 {
2540 // if this is a DBCS character, put it in "mb_c"
2541 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002542 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002543 mb_l = 1;
2544 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002545 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002546 }
2547 if (mb_l == 0) // at the NUL at end-of-line
2548 mb_l = 1;
2549
2550 // If a double-width char doesn't fit display a '>' in the
2551 // last column.
2552 if ((
2553# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002554 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002555# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002556 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002557 && (*mb_char2cells)(mb_c) == 2)
2558 {
2559 c = '>';
2560 mb_c = c;
2561 mb_l = 1;
2562 mb_utf8 = FALSE;
2563 multi_attr = HL_ATTR(HLF_AT);
2564#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002565 if (wlv.cul_attr)
2566 multi_attr = hl_combine_attr(
2567 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002568#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002569 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002570
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002571 // put the pointer back to output the double-width
2572 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002573 ++wlv.n_extra;
2574 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002575 }
2576 else
2577 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002578 wlv.n_extra -= mb_l - 1;
2579 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002580 }
2581 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002582 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002583 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002584 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002585#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002586 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002587 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002588 // Only restore search_attr and area_attr after "n_extra" in
2589 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002590 if (wlv.saved_n_extra <= 0)
2591 {
2592 if (search_attr == 0)
2593 search_attr = saved_search_attr;
2594 if (area_attr == 0 && *ptr != NUL)
2595 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002596
2597 if (wlv.extra_for_textprop)
2598 // wlv.extra_attr should be used at this position but
2599 // not any further.
2600 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002601 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002602
2603 wlv.extra_for_textprop = FALSE;
2604 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002605 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002606#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002607 }
2608 else
2609 {
2610#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002611 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002612#endif
zeertzjqe500ae82023-08-17 22:35:26 +02002613 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002614
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002615 // Get a character from the line itself.
2616 c = *ptr;
2617#ifdef FEAT_LINEBREAK
2618 c0 = *ptr;
2619#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002620 if (c == NUL)
zeertzjqb557f482023-08-22 22:07:34 +02002621 {
2622#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002623 // text is finished, may display a "below" virtual text
2624 did_line = TRUE;
2625#endif
zeertzjqb557f482023-08-22 22:07:34 +02002626 // no more cells to skip
2627 skip_cells = 0;
2628 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002629
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002630 if (has_mbyte)
2631 {
2632 mb_c = c;
2633 if (enc_utf8)
2634 {
2635 // If the UTF-8 character is more than one byte: Decode it
2636 // into "mb_c".
2637 mb_l = utfc_ptr2len(ptr);
2638 mb_utf8 = FALSE;
2639 if (mb_l > 1)
2640 {
2641 mb_c = utfc_ptr2char(ptr, u8cc);
2642 // Overlong encoded ASCII or ASCII with composing char
2643 // is displayed normally, except a NUL.
2644 if (mb_c < 0x80)
2645 {
2646 c = mb_c;
2647#ifdef FEAT_LINEBREAK
2648 c0 = mb_c;
2649#endif
2650 }
2651 mb_utf8 = TRUE;
2652
2653 // At start of the line we can have a composing char.
2654 // Draw it as a space with a composing char.
2655 if (utf_iscomposing(mb_c))
2656 {
2657 int i;
2658
2659 for (i = Screen_mco - 1; i > 0; --i)
2660 u8cc[i] = u8cc[i - 1];
2661 u8cc[0] = mb_c;
2662 mb_c = ' ';
2663 }
2664 }
2665
2666 if ((mb_l == 1 && c >= 0x80)
2667 || (mb_l >= 1 && mb_c == 0)
2668 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2669 {
2670 // Illegal UTF-8 byte: display as <xx>.
2671 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002672 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002673# ifdef FEAT_RIGHTLEFT
2674 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002675 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002676# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002677 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002678 c = *wlv.p_extra;
2679 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002680 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002681 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2682 wlv.c_extra = NUL;
2683 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002684 if (area_attr == 0 && search_attr == 0)
2685 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002686 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002687 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002688 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002689 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002690 }
2691 }
2692 else if (mb_l == 0) // at the NUL at end-of-line
2693 mb_l = 1;
2694#ifdef FEAT_ARABIC
2695 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2696 {
2697 // Do Arabic shaping.
2698 int pc, pc1, nc;
2699 int pcc[MAX_MCO];
2700
2701 // The idea of what is the previous and next
2702 // character depends on 'rightleft'.
2703 if (wp->w_p_rl)
2704 {
2705 pc = prev_c;
2706 pc1 = prev_c1;
2707 nc = utf_ptr2char(ptr + mb_l);
2708 prev_c1 = u8cc[0];
2709 }
2710 else
2711 {
2712 pc = utfc_ptr2char(ptr + mb_l, pcc);
2713 nc = prev_c;
2714 pc1 = pcc[0];
2715 }
2716 prev_c = mb_c;
2717
2718 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2719 }
2720 else
2721 prev_c = mb_c;
2722#endif
2723 }
2724 else // enc_dbcs
2725 {
2726 mb_l = MB_BYTE2LEN(c);
2727 if (mb_l == 0) // at the NUL at end-of-line
2728 mb_l = 1;
2729 else if (mb_l > 1)
2730 {
2731 // We assume a second byte below 32 is illegal.
2732 // Hopefully this is OK for all double-byte encodings!
2733 if (ptr[1] >= 32)
2734 mb_c = (c << 8) + ptr[1];
2735 else
2736 {
2737 if (ptr[1] == NUL)
2738 {
2739 // head byte at end of line
2740 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002741 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002742 }
2743 else
2744 {
2745 // illegal tail byte
2746 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002747 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002748 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002749 wlv.p_extra = wlv.extra;
2750 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002751 wlv.c_extra = NUL;
2752 wlv.c_final = NUL;
2753 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002754 if (area_attr == 0 && search_attr == 0)
2755 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002756 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002757 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002758 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002759 // save current attr
2760 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002761 }
2762 mb_c = c;
2763 }
2764 }
2765 }
2766 // If a double-width char doesn't fit display a '>' in the
2767 // last column; the character is displayed at the start of the
2768 // next line.
2769 if ((
2770# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002771 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002772# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002773 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002774 && (*mb_char2cells)(mb_c) == 2)
2775 {
2776 c = '>';
2777 mb_c = c;
2778 mb_utf8 = FALSE;
2779 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002780 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002781 // Put pointer back so that the character will be
2782 // displayed at the start of the next line.
2783 --ptr;
2784#ifdef FEAT_CONCEAL
2785 did_decrement_ptr = TRUE;
2786#endif
2787 }
2788 else if (*ptr != NUL)
2789 ptr += mb_l - 1;
2790
2791 // If a double-width char doesn't fit at the left side display
2792 // a '<' in the first column. Don't do this for unprintable
2793 // characters.
zeertzjqb557f482023-08-22 22:07:34 +02002794 if (skip_cells > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002795 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002796 wlv.n_extra = 1;
2797 wlv.c_extra = MB_FILLER_CHAR;
2798 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002799 c = ' ';
2800 if (area_attr == 0 && search_attr == 0)
2801 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002802 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002803 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002804 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002805 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002806 }
2807 mb_c = c;
2808 mb_utf8 = FALSE;
2809 mb_l = 1;
2810 }
2811
2812 }
2813 ++ptr;
2814
2815 if (extra_check)
2816 {
2817#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002818 // Check spelling (unless at the end of the line).
2819 // Only do this when there is no syntax highlighting, the
2820 // @Spell cluster is not used or the current syntax item
2821 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002822 v = (long)(ptr - line);
Luuk van Baal30805a12023-05-27 22:22:10 +01002823 if (spv->spv_has_spell && v >= word_end && v > cur_checked_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002824 {
2825 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002826 // do not calculate cap_col at the end of the line or when
2827 // only white space is following
2828 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002829# ifdef FEAT_SYN_HL
2830 !has_syntax ||
2831# endif
2832 can_spell))
2833 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002834 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002835 int len;
2836 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002837
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002838 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002839 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002840
2841 // Use nextline[] if possible, it has the start of the
2842 // next line concatenated.
2843 if ((prev_ptr - line) - nextlinecol >= 0)
2844 p = nextline + (prev_ptr - line) - nextlinecol;
2845 else
2846 p = prev_ptr;
Luuk van Baal30805a12023-05-27 22:22:10 +01002847 spv->spv_cap_col -= (int)(prev_ptr - line);
2848 len = spell_check(wp, p, &spell_hlf, &spv->spv_cap_col,
2849 spv->spv_unchanged);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002850 word_end = v + len;
2851
2852 // In Insert mode only highlight a word that
2853 // doesn't touch the cursor.
2854 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002855 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002856 && wp->w_cursor.lnum == lnum
2857 && wp->w_cursor.col >=
2858 (colnr_T)(prev_ptr - line)
2859 && wp->w_cursor.col < (colnr_T)word_end)
2860 {
2861 spell_hlf = HLF_COUNT;
2862 spell_redraw_lnum = lnum;
2863 }
2864
2865 if (spell_hlf == HLF_COUNT && p != prev_ptr
2866 && (p - nextline) + len > nextline_idx)
2867 {
2868 // Remember that the good word continues at the
2869 // start of the next line.
Luuk van Baal30805a12023-05-27 22:22:10 +01002870 spv->spv_checked_lnum = lnum + 1;
2871 spv->spv_checked_col = (p - nextline) + len
2872 - nextline_idx;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002873 }
2874
2875 // Turn index into actual attributes.
2876 if (spell_hlf != HLF_COUNT)
2877 spell_attr = highlight_attr[spell_hlf];
2878
Luuk van Baal30805a12023-05-27 22:22:10 +01002879 if (spv->spv_cap_col > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002880 {
2881 if (p != prev_ptr
Luuk van Baal30805a12023-05-27 22:22:10 +01002882 && (p - nextline) + spv->spv_cap_col
2883 >= nextline_idx)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002884 {
2885 // Remember that the word in the next line
2886 // must start with a capital.
Luuk van Baal30805a12023-05-27 22:22:10 +01002887 spv->spv_capcol_lnum = lnum + 1;
2888 spv->spv_cap_col = ((p - nextline)
2889 + spv->spv_cap_col - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002890 }
2891 else
2892 // Compute the actual column.
Luuk van Baal30805a12023-05-27 22:22:10 +01002893 spv->spv_cap_col += (prev_ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002894 }
2895 }
2896 }
2897 if (spell_attr != 0)
2898 {
2899 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002900 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2901 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002902 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002903 wlv.char_attr = hl_combine_attr(spell_attr,
2904 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002905 }
2906#endif
2907#ifdef FEAT_LINEBREAK
2908 // Found last space before word: check for line break.
2909 if (wp->w_p_lbr && c0 == c
2910 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2911 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002912 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2913 : 0;
2914 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002915 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002916
zeertzjqce53e3e2023-09-01 18:49:30 +02002917 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol
2918# ifdef FEAT_PROP_POPUP
2919 - vcol_first_char,
2920# endif
2921 line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002922# ifdef FEAT_PROP_POPUP
2923 // do not want virtual text counted here
2924 cts.cts_has_prop_with_text = FALSE;
2925# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002926 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002927 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002928
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002929 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002930 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002931 // line break, but for TABs the highlighting should
2932 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002933 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002934
Bram Moolenaar1306b362022-08-06 15:59:06 +01002935 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002936# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002937 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002938 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002939 wp->w_buffer->b_p_vts_array) - 1;
2940# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002941 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002942 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002943# endif
2944
Bram Moolenaar1306b362022-08-06 15:59:06 +01002945 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2946 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002947# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002948 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002949 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002950# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002951 if (VIM_ISWHITE(c))
2952 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002953# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002954 if (c == TAB)
2955 // See "Tab alignment" below.
2956 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002957# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002958 if (!wp->w_p_list)
2959 c = ' ';
2960 }
2961 }
2962#endif
zeertzjqabc80812023-09-24 23:32:18 +02002963 if (wp->w_p_list)
2964 {
2965 in_multispace = c == ' ' && (*ptr == ' '
2966 || (prev_ptr > line && prev_ptr[-1] == ' '));
2967 if (!in_multispace)
2968 multispace_pos = 0;
2969 }
zeertzjqf14b8ba2021-09-10 16:58:30 +02002970
Bram Moolenaareed9d462021-02-15 20:38:25 +01002971 // 'list': Change char 160 to 'nbsp' and space to 'space'
2972 // setting in 'listchars'. But not when the character is
2973 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002974 if (wp->w_p_list
2975 && ((((c == 160 && mb_l == 1)
2976 || (mb_utf8
2977 && ((mb_c == 160 && mb_l == 2)
2978 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002979 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002980 || (c == ' '
2981 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002982 && (wp->w_lcs_chars.space
2983 || (in_multispace
2984 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002985 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002986 && ptr - line <= trailcol)))
2987 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002988 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2989 {
2990 c = wp->w_lcs_chars.multispace[multispace_pos++];
2991 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2992 multispace_pos = 0;
2993 }
2994 else
2995 c = (c == ' ') ? wp->w_lcs_chars.space
2996 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002997 if (area_attr == 0 && search_attr == 0)
2998 {
2999 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003000 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003001 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003002 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003003 }
3004 mb_c = c;
3005 if (enc_utf8 && utf_char2len(c) > 1)
3006 {
3007 mb_utf8 = TRUE;
3008 u8cc[0] = 0;
3009 c = 0xc0;
3010 }
3011 else
3012 mb_utf8 = FALSE;
3013 }
3014
zeertzjq2e7cba32022-06-10 15:30:32 +01003015 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
3016 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003017 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003018 if (leadcol != 0 && in_multispace && ptr < line + leadcol
3019 && wp->w_lcs_chars.leadmultispace != NULL)
3020 {
3021 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01003022 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
3023 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003024 multispace_pos = 0;
3025 }
3026
3027 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
3028 c = wp->w_lcs_chars.trail;
3029
3030 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
3031 c = wp->w_lcs_chars.lead;
3032
zeertzjq2e7cba32022-06-10 15:30:32 +01003033 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003034 c = wp->w_lcs_chars.space;
3035
3036
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003037 if (!attr_pri)
3038 {
3039 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003040 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003041 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003042 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003043 }
3044 mb_c = c;
3045 if (enc_utf8 && utf_char2len(c) > 1)
3046 {
3047 mb_utf8 = TRUE;
3048 u8cc[0] = 0;
3049 c = 0xc0;
3050 }
3051 else
3052 mb_utf8 = FALSE;
3053 }
3054 }
3055
3056 // Handling of non-printable characters.
3057 if (!vim_isprintc(c))
3058 {
3059 // when getting a character from the file, we may have to
3060 // turn it into something else on the way to putting it
3061 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01003062 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003063 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003064 int tab_len = 0;
3065 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003066#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003067 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01003068
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003069 // only adjust the tab_len, when at the first column
3070 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01003071 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003072 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003073#endif
3074 // tab amount depends on current column
3075#ifdef FEAT_VARTABS
3076 tab_len = tabstop_padding(vcol_adjusted,
3077 wp->w_buffer->b_p_ts,
3078 wp->w_buffer->b_p_vts_array) - 1;
3079#else
3080 tab_len = (int)wp->w_buffer->b_p_ts
3081 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
3082#endif
3083
3084#ifdef FEAT_LINEBREAK
3085 if (!wp->w_p_lbr || !wp->w_p_list)
3086#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003087 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003088 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01003089 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003090 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003091#ifdef FEAT_LINEBREAK
3092 else
3093 {
3094 char_u *p;
3095 int len;
3096 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003097 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003098
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003099# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003100 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003101 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003102 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003103
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003104 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003105 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003106 && old_boguscols > 0
3107 && wlv.n_extra > tab_len)
3108 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003109# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003110 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003111 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003112 // If wlv.n_extra > 0, it gives the number of chars
3113 // to use for a tab, else we need to calculate the
3114 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003115 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3116 len = tab_len * tab2_len;
3117 if (wp->w_lcs_chars.tab3)
3118 len += mb_char2len(wp->w_lcs_chars.tab3)
3119 - tab2_len;
3120 if (wlv.n_extra > 0)
3121 len += wlv.n_extra - tab_len;
3122 c = wp->w_lcs_chars.tab1;
3123 p = alloc(len + 1);
3124 if (p == NULL)
3125 wlv.n_extra = 0;
3126 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003127 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003128 vim_memset(p, ' ', len);
3129 p[len] = NUL;
3130 vim_free(wlv.p_extra_free);
3131 wlv.p_extra_free = p;
3132 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003133 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003134 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003135
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003136 if (*p == NUL)
3137 {
3138 tab_len = i;
3139 break;
3140 }
3141
3142 // if tab3 is given, use it for the last
3143 // char
3144 if (wp->w_lcs_chars.tab3
3145 && i == tab_len - 1)
3146 lcs = wp->w_lcs_chars.tab3;
3147 p += mb_char2bytes(lcs, p);
3148 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003149 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003150 }
3151 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003152# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003153 // n_extra will be increased by
3154 // FIX_FOX_BOGUSCOLS macro below, so need to
3155 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003156 if (wlv.vcol_off_co > 0)
3157 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003158# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003159 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003160 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003161 }
3162#endif
3163#ifdef FEAT_CONCEAL
3164 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003165 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003166
3167 // Tab alignment should be identical regardless of
3168 // 'conceallevel' value. So tab compensates of all
3169 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003170 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003171 // line. Note that the tab can be longer than
3172 // 'tabstop' when there are concealed characters.
3173 FIX_FOR_BOGUSCOLS;
3174
3175 // Make sure, the highlighting for the tab char will be
3176 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003177 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003178 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003179 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003180 tab_len += vc_saved;
3181 }
3182#endif
3183 mb_utf8 = FALSE; // don't draw as UTF-8
3184 if (wp->w_p_list)
3185 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003186 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003187 ? wp->w_lcs_chars.tab3
3188 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003189#ifdef FEAT_LINEBREAK
h-east194555c2023-03-02 18:49:09 +00003190 if (wp->w_p_lbr && wlv.p_extra != NULL
3191 && *wlv.p_extra != NUL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003192 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003193 else
3194#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003195 wlv.c_extra = wp->w_lcs_chars.tab2;
3196 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003197 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003198 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003199 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003200 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003201 mb_c = c;
3202 if (enc_utf8 && utf_char2len(c) > 1)
3203 {
3204 mb_utf8 = TRUE;
3205 u8cc[0] = 0;
3206 c = 0xc0;
3207 }
3208 }
3209 else
3210 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003211 wlv.c_final = NUL;
3212 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003213 c = ' ';
3214 }
3215 }
3216 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003217 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003218 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003219 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3220 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003221 && VIsual_mode != Ctrl_V
3222 && (
3223# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003224 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003225# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003226 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003227 && !(noinvcur
3228 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003229 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003230 && lcs_eol_one > 0)
3231 {
3232 // Display a '$' after the line or highlight an extra
3233 // character if the line break is included.
3234#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3235 // For a diff line the highlighting continues after the
3236 // "$".
3237 if (
3238# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003239 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003240# ifdef LINE_ATTR
3241 &&
3242# endif
3243# endif
3244# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003245 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003246# endif
3247 )
3248#endif
3249 {
3250 // In virtualedit, visual selections may extend
3251 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003252 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003253 && wlv.tocol != MAXCOL
3254 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003255 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003256 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003257 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003258 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3259 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003260 else
3261 c = ' ';
3262 lcs_eol_one = -1;
3263 --ptr; // put it back at the NUL
3264 if (!attr_pri)
3265 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003266 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003267 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003268 n_attr = 1;
3269 }
3270 mb_c = c;
3271 if (enc_utf8 && utf_char2len(c) > 1)
3272 {
3273 mb_utf8 = TRUE;
3274 u8cc[0] = 0;
3275 c = 0xc0;
3276 }
3277 else
3278 mb_utf8 = FALSE; // don't draw as UTF-8
3279 }
3280 else if (c != NUL)
3281 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003282 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3283 if (wlv.n_extra == 0)
3284 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003285#ifdef FEAT_RIGHTLEFT
3286 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003287 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003288#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003289 wlv.c_extra = NUL;
3290 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003291#ifdef FEAT_LINEBREAK
3292 if (wp->w_p_lbr)
3293 {
3294 char_u *p;
3295
Bram Moolenaar1306b362022-08-06 15:59:06 +01003296 c = *wlv.p_extra;
3297 p = alloc(wlv.n_extra + 1);
3298 vim_memset(p, ' ', wlv.n_extra);
3299 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3300 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003301 vim_free(wlv.p_extra_free);
3302 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003303 }
3304 else
3305#endif
3306 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003307 wlv.n_extra = byte2cells(c) - 1;
3308 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003309 }
3310 if (!attr_pri)
3311 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003312 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003313 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003314 HL_ATTR(HLF_8));
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003315#ifdef FEAT_PROP_POPUP
3316 if (text_prop_type != NULL &&
3317 text_prop_flags & PT_FLAG_OVERRIDE)
3318 wlv.extra_attr = hl_combine_attr(text_prop_attr, wlv.extra_attr);
3319#endif
3320
Bram Moolenaar1306b362022-08-06 15:59:06 +01003321 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003322 }
3323 mb_utf8 = FALSE; // don't draw as UTF-8
3324 }
3325 else if (VIsual_active
3326 && (VIsual_mode == Ctrl_V
3327 || VIsual_mode == 'v')
3328 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003329 && wlv.tocol != MAXCOL
3330 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003331 && (
3332#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003333 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003334#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003335 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003336 {
3337 c = ' ';
3338 --ptr; // put it back at the NUL
3339 }
3340#if defined(LINE_ATTR)
3341 else if ((
3342# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003343 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003344# endif
3345# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003346 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003347# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003348 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003349 ) && (
3350# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003351 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003352# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003353 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003354# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003355 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003356# endif
3357 < wp->w_width)))
3358 {
3359 // Highlight until the right side of the window
3360 c = ' ';
3361 --ptr; // put it back at the NUL
3362
3363 // Remember we do the char for line highlighting.
3364 ++did_line_attr;
3365
3366 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003367 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003368 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003369 || (wp->w_p_list &&
3370 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003371 wlv.char_attr = wlv.line_attr;
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003372#ifdef FEAT_SIGNS
3373 // At end of line: if Sign is present with line highlight, reset char_attr
Christian Brabandte1eaae22023-08-19 22:36:12 +02003374 // but not when cursorline is active
3375 if (sign_present && wlv.sattr.sat_linehl > 0 && wlv.draw_state == WL_LINE
3376 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum))
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003377 wlv.char_attr = wlv.sattr.sat_linehl;
3378#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003379# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003380 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003381 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003382 wlv.diff_hlf = HLF_CHD;
3383 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003384 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003385 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003386 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3387 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003388 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003389 || (wlv.vcol >= left_curline_col
3390 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003391 wlv.char_attr = hl_combine_attr(
3392 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003393 }
3394 }
3395# endif
3396# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003397 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003398 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003399 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003400 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3401 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003402 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003403 if (!wlv.cul_screenline
3404 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003405 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003406 wlv.char_attr = hl_combine_attr(
3407 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003408 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003409 else if (wlv.line_attr)
3410 wlv.char_attr = hl_combine_attr(
3411 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003412 }
3413# endif
3414 }
3415#endif
3416 }
3417
3418#ifdef FEAT_CONCEAL
3419 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003420 && (wp != curwin || lnum != wp->w_cursor.lnum
3421 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003422 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3423 && !(lnum_in_visual_area
3424 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3425 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003426 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003427 if (((prev_syntax_id != syntax_seqnr
3428 && (syntax_flags & HL_CONCEAL) != 0)
3429 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003430 && (syn_get_sub_char() != NUL
3431 || (has_match_conc && match_conc)
3432 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003433 && wp->w_p_cole != 3)
3434 {
3435 // First time at this concealed item: display one
3436 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003437 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003438 c = match_conc;
3439 else if (syn_get_sub_char() != NUL)
3440 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003441 else if (wp->w_lcs_chars.conceal != NUL)
3442 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003443 else
3444 c = ' ';
3445
3446 prev_syntax_id = syntax_seqnr;
3447
Bram Moolenaar1306b362022-08-06 15:59:06 +01003448 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003449 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003450 wlv.vcol += wlv.n_extra;
3451 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003452 {
3453# ifdef FEAT_RIGHTLEFT
3454 if (wp->w_p_rl)
3455 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003456 wlv.col -= wlv.n_extra;
3457 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003458 }
3459 else
3460# endif
3461 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003462 wlv.boguscols += wlv.n_extra;
3463 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003464 }
3465 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003466 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003467 n_attr = 0;
3468 }
zeertzjqb557f482023-08-22 22:07:34 +02003469 else if (skip_cells == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003470 {
3471 is_concealing = TRUE;
zeertzjqb557f482023-08-22 22:07:34 +02003472 skip_cells = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003473 }
3474 mb_c = c;
3475 if (enc_utf8 && utf_char2len(c) > 1)
3476 {
3477 mb_utf8 = TRUE;
3478 u8cc[0] = 0;
3479 c = 0xc0;
3480 }
3481 else
3482 mb_utf8 = FALSE; // don't draw as UTF-8
3483 }
3484 else
3485 {
3486 prev_syntax_id = 0;
3487 is_concealing = FALSE;
3488 }
3489
zeertzjqb557f482023-08-22 22:07:34 +02003490 if (skip_cells > 0 && did_decrement_ptr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003491 // not showing the '>', put pointer back to avoid getting stuck
3492 ++ptr;
3493
3494#endif // FEAT_CONCEAL
3495 }
3496
3497#ifdef FEAT_CONCEAL
3498 // In the cursor line and we may be concealing characters: correct
3499 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003500 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003501 && wp == curwin && lnum == wp->w_cursor.lnum
3502 && conceal_cursor_line(wp)
zeertzjqb557f482023-08-22 22:07:34 +02003503 && (int)wp->w_virtcol <= wlv.vcol + skip_cells)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003504 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003505# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003506 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003507 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003508 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003509# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003510 wp->w_wcol = wlv.col - wlv.boguscols;
3511 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003512 did_wcol = TRUE;
3513 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003514# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003515 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003516# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003517 }
3518#endif
3519
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003520 // Use "wlv.extra_attr", but don't override visual selection
3521 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003522 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3523 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003524 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003525 && (!attr_pri
3526#ifdef FEAT_PROP_POPUP
3527 || (text_prop_flags & PT_FLAG_OVERRIDE)
3528#endif
3529 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003530 {
3531#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003532 if (wlv.line_attr)
3533 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003534 else
3535#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003536 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003537#ifdef FEAT_PROP_POPUP
3538 if (reset_extra_attr)
3539 {
3540 reset_extra_attr = FALSE;
3541 wlv.extra_attr = 0;
3542 }
3543#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003544 }
3545
3546#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3547 // XIM don't send preedit_start and preedit_end, but they send
3548 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3549 // im_is_preediting() here.
3550 if (p_imst == IM_ON_THE_SPOT
3551 && xic != NULL
3552 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003553 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003554 && !p_imdisable
3555 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003556 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003557 {
3558 colnr_T tcol;
3559
3560 if (preedit_end_col == MAXCOL)
3561 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3562 else
3563 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003564 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003565 {
3566 if (feedback_old_attr < 0)
3567 {
3568 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003569 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003570 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003571 wlv.char_attr = im_get_feedback_attr(feedback_col);
3572 if (wlv.char_attr < 0)
3573 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003574 feedback_col++;
3575 }
3576 else if (feedback_old_attr >= 0)
3577 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003578 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003579 feedback_old_attr = -1;
3580 feedback_col = 0;
3581 }
3582 }
3583#endif
3584 // Handle the case where we are in column 0 but not on the first
3585 // character of the line and the user wants us to show us a
3586 // special character (via 'listchars' option "precedes:<char>".
3587 if (lcs_prec_todo != NUL
3588 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003589 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3590 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003591#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003592 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003593#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003594 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003595 && c != NUL)
3596 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003597 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003598 lcs_prec_todo = NUL;
3599 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3600 {
3601 // Double-width character being overwritten by the "precedes"
3602 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003603 wlv.c_extra = MB_FILLER_CHAR;
3604 wlv.c_final = NUL;
3605 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003606 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003607 wlv.extra_attr =
3608 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003609 }
3610 mb_c = c;
3611 if (enc_utf8 && utf_char2len(c) > 1)
3612 {
3613 mb_utf8 = TRUE;
3614 u8cc[0] = 0;
3615 c = 0xc0;
3616 }
3617 else
3618 mb_utf8 = FALSE; // don't draw as UTF-8
3619 if (!attr_pri)
3620 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003621 saved_attr3 = wlv.char_attr; // save current attr
3622 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003623 n_attr3 = 1;
3624 }
3625 }
3626
3627 // At end of the text line or just after the last character.
3628 if ((c == NUL
3629#if defined(LINE_ATTR)
3630 || did_line_attr == 1
3631#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003632 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003633 {
3634#ifdef FEAT_SEARCH_EXTRA
3635 // flag to indicate whether prevcol equals startcol of search_hl or
3636 // one of the matches
3637 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3638 (long)(ptr - line) - (c == NUL));
3639#endif
3640 // Invert at least one char, used for Visual and empty line or
3641 // highlight match at end of line. If it's beyond the last
3642 // char on the screen, just overwrite that one (tricky!) Not
3643 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003644 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003645 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003646 && (VIsual_mode != Ctrl_V
3647 || lnum == VIsual.lnum
3648 || lnum == curwin->w_cursor.lnum)
3649 && c == NUL)
3650#ifdef FEAT_SEARCH_EXTRA
3651 // highlight 'hlsearch' match at end of line
3652 || (prevcol_hl_flag
3653# ifdef FEAT_SYN_HL
3654 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3655 && !(wp == curwin && VIsual_active))
3656# endif
3657# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003658 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003659# endif
3660# if defined(LINE_ATTR)
3661 && did_line_attr <= 1
3662# endif
3663 )
3664#endif
3665 ))
3666 {
3667 int n = 0;
3668
3669#ifdef FEAT_RIGHTLEFT
3670 if (wp->w_p_rl)
3671 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003672 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003673 n = 1;
3674 }
3675 else
3676#endif
3677 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003678 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003679 n = -1;
3680 }
3681 if (n != 0)
3682 {
3683 // At the window boundary, highlight the last character
3684 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003685 wlv.off += n;
3686 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003687 }
3688 else
3689 {
3690 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003691 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003692 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003693 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003694 }
3695#ifdef FEAT_SEARCH_EXTRA
3696 if (area_attr == 0)
3697 {
3698 // Use attributes from match with highest priority among
3699 // 'search_hl' and the match list.
3700 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003701 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003702 }
3703#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003704 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003705 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003706#ifdef FEAT_RIGHTLEFT
3707 if (wp->w_p_rl)
3708 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003709 --wlv.col;
3710 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003711 }
3712 else
3713#endif
3714 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003715 ++wlv.col;
3716 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003717 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003718 ++wlv.vcol;
3719 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003720 }
3721 }
3722
3723 // At end of the text line.
3724 if (c == NUL)
3725 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003726#ifdef FEAT_PROP_POPUP
3727 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003728 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003729 // Put the pointer back to the NUL.
3730 --ptr;
3731 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003732 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003733 else
3734#endif
3735 {
3736 draw_screen_line(wp, &wlv);
3737
3738 // Update w_cline_height and w_cline_folded if the cursor line
3739 // was updated (saves a call to plines() later).
3740 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3741 {
3742 curwin->w_cline_row = startrow;
3743 curwin->w_cline_height = wlv.row - startrow;
3744#ifdef FEAT_FOLDING
3745 curwin->w_cline_folded = FALSE;
3746#endif
3747 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3748 }
3749 break;
3750 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003751 }
3752
3753 // Show "extends" character from 'listchars' if beyond the line end and
3754 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003755 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003756 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003757 && wp->w_p_list
3758 && !wp->w_p_wrap
3759#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003760 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003761#endif
3762 && (
3763#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003764 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003765#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003766 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003767 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003768 || lcs_eol_one > 0
3769 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
zeertzjq6a389722023-08-27 19:04:14 +02003770 || *wlv.p_extra != NUL))
3771#ifdef FEAT_PROP_POPUP
3772 || text_prop_next < text_prop_count
3773#endif
3774 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003775 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003776 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003777 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003778 mb_c = c;
3779 if (enc_utf8 && utf_char2len(c) > 1)
3780 {
3781 mb_utf8 = TRUE;
3782 u8cc[0] = 0;
3783 c = 0xc0;
3784 }
3785 else
3786 mb_utf8 = FALSE;
3787 }
3788
3789#ifdef FEAT_SYN_HL
3790 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003791 if (wlv.draw_color_col)
3792 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003793
3794 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3795 // highlight the cursor position itself.
3796 // Also highlight the 'colorcolumn' if it is different than
3797 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003798 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3799 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003800 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003801 if (((wlv.draw_state == WL_LINE
3802 || wlv.draw_state == WL_BRI
3803 || wlv.draw_state == WL_SBR)
3804 && !lnum_in_visual_area
3805 && search_attr == 0
3806 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003807# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003808 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003809# endif
3810 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003811 {
3812 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3813 && lnum != wp->w_cursor.lnum)
3814 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003815 vcol_save_attr = wlv.char_attr;
3816 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3817 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003818 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003819 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003820 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003821 vcol_save_attr = wlv.char_attr;
3822 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003823 }
3824 }
3825#endif
3826
zeertzjq8fc6a1d2023-08-20 18:12:54 +02003827 if (wlv.draw_state == WL_LINE)
3828 vcol_prev = wlv.vcol;
3829
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003830 // Store character to be displayed.
3831 // Skip characters that are left of the screen for 'nowrap'.
zeertzjqb557f482023-08-22 22:07:34 +02003832 if (wlv.draw_state < WL_LINE || skip_cells <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003833 {
3834 // Store the character.
3835#if defined(FEAT_RIGHTLEFT)
3836 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3837 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003838 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003839 --wlv.off;
3840 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003841 }
3842#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003843 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003844 if (enc_dbcs == DBCS_JPNU)
3845 {
3846 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003847 ScreenLines[wlv.off] = 0x8e;
3848 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003849 }
3850 else if (enc_utf8)
3851 {
3852 if (mb_utf8)
3853 {
3854 int i;
3855
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003856 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003857 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003858 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003859 for (i = 0; i < Screen_mco; ++i)
3860 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003861 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003862 if (u8cc[i] == 0)
3863 break;
3864 }
3865 }
3866 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003867 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003868 }
3869 if (multi_attr)
3870 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003871 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003872 multi_attr = 0;
3873 }
3874 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003875 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003876
zeertzjqdb54e982023-09-21 16:33:09 +02003877 if (wlv.draw_state > WL_NR
3878#ifdef FEAT_DIFF
3879 && wlv.filler_todo <= 0
3880#endif
3881 )
3882 ScreenCols[wlv.off] = wlv.vcol;
3883 else
3884 ScreenCols[wlv.off] = -1;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003885
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003886 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3887 {
3888 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003889 ++wlv.off;
3890 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003891 if (enc_utf8)
3892 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003893 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003894 else
3895 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003896 ScreenLines[wlv.off] = mb_c & 0xff;
zeertzjqdb54e982023-09-21 16:33:09 +02003897
Bram Moolenaar1306b362022-08-06 15:59:06 +01003898 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003899#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003900 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003901#endif
3902 )
zeertzjqdb54e982023-09-21 16:33:09 +02003903 ScreenCols[wlv.off] = ++wlv.vcol;
3904 else
3905 ScreenCols[wlv.off] = -1;
3906
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003907 // When "wlv.tocol" is halfway a character, set it to the end
3908 // of the character, otherwise highlighting won't stop.
3909 if (wlv.tocol == wlv.vcol)
3910 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003911
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003912#ifdef FEAT_RIGHTLEFT
3913 if (wp->w_p_rl)
3914 {
3915 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003916 --wlv.off;
3917 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003918 }
3919#endif
3920 }
3921#ifdef FEAT_RIGHTLEFT
3922 if (wp->w_p_rl)
3923 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003924 --wlv.off;
3925 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003926 }
3927 else
3928#endif
3929 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003930 ++wlv.off;
3931 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003932 }
3933 }
3934#ifdef FEAT_CONCEAL
3935 else if (wp->w_p_cole > 0 && is_concealing)
3936 {
zeertzjqb557f482023-08-22 22:07:34 +02003937 --skip_cells;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003938 ++wlv.vcol_off_co;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003939 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003940 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003941 if (wp->w_p_wrap)
3942 {
3943 // Special voodoo required if 'wrap' is on.
3944 //
3945 // Advance the column indicator to force the line
3946 // drawing to wrap early. This will make the line
3947 // take up the same screen space when parts are concealed,
3948 // so that cursor line computations aren't messed up.
3949 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003950 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003951 // trailing junk to be written out of the screen line
3952 // we are building, 'boguscols' keeps track of the number
3953 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003954 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003955 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003956 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003957# ifdef FEAT_RIGHTLEFT
3958 if (wp->w_p_rl)
3959 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003960 wlv.col -= wlv.n_extra;
3961 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003962 }
3963 else
3964# endif
3965 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003966 wlv.col += wlv.n_extra;
3967 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003968 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003969 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003970 n_attr = 0;
3971 }
3972
3973
3974 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3975 {
3976 // Need to fill two screen columns.
3977# ifdef FEAT_RIGHTLEFT
3978 if (wp->w_p_rl)
3979 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003980 --wlv.boguscols;
3981 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003982 }
3983 else
3984# endif
3985 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003986 ++wlv.boguscols;
3987 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003988 }
3989 }
3990
3991# ifdef FEAT_RIGHTLEFT
3992 if (wp->w_p_rl)
3993 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003994 --wlv.boguscols;
3995 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003996 }
3997 else
3998# endif
3999 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004000 ++wlv.boguscols;
4001 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004002 }
4003 }
4004 else
4005 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004006 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004007 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004008 wlv.vcol += wlv.n_extra;
4009 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004010 n_attr = 0;
4011 }
4012 }
4013
4014 }
4015#endif // FEAT_CONCEAL
4016 else
zeertzjqb557f482023-08-22 22:07:34 +02004017 --skip_cells;
4018
4019 if (wlv.draw_state > WL_NR && skipped_cells > 0)
4020 {
4021 wlv.vcol += skipped_cells;
4022 skipped_cells = 0;
4023 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004024
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004025 // Only advance the "wlv.vcol" when after the 'number' or
4026 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004027 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004028#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004029 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004030#endif
4031 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004032 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004033
4034#ifdef FEAT_SYN_HL
4035 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004036 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004037#endif
4038
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004039 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01004040 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
4041 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004042
4043 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01004044 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004045 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004046 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004047 if (wlv.n_attr_skip > 0)
4048 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004049
4050 // At end of screen line and there is more to come: Display the line
4051 // so far. If there is no more to display it is caught above.
4052 if ((
4053#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004054 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004055#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004056 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01004057 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02004058 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004059#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004060 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004061#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004062#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004063 || text_prop_above || text_prop_follows
zeertzjq6a389722023-08-27 19:04:14 +02004064 || text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004065#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01004066 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01004067 && wlv.p_extra != at_end_str)
4068 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
4069 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004070 )
4071 {
4072#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01004073 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01004074 wlv_screen_line(wp, &wlv, FALSE);
4075 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004076 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004077 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004078#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01004079 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004080#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004081 ++wlv.row;
4082 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004083
4084 // When not wrapping and finished diff lines, or when displayed
4085 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01004086 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004087#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004088 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004089#endif
4090#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01004091 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004092#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01004093 ) || lcs_eol_one == -1)
4094#ifdef FEAT_PROP_POPUP
4095 && !text_prop_follows
4096#endif
4097 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004098 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004099#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004100 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004101 {
4102 // do not output more of the line, only the "below" prop
4103 ptr += STRLEN(ptr);
4104# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004105 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004106# endif
4107 }
4108#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004109
4110 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004111 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004112#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004113 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004114#endif
4115 )
4116 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004117 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
4118 draw_vsep_win(wp, wlv.row);
4119 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004120 }
4121
4122 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004123 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004124 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004125 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004126 break;
4127 }
4128
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004129 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004130#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004131 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004132#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004133#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004134 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004135#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004136 && wp->w_width == Columns)
4137 {
4138 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004139 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004140
4141 // Special trick to make copy/paste of wrapped lines work with
4142 // xterm/screen: write an extra character beyond the end of
4143 // the line. This will work with all terminal types
4144 // (regardless of the xn,am settings).
4145 // Only do this on a fast tty.
4146 // Only do this if the cursor is on the current line
4147 // (something has been written in it).
4148 // Don't do this for the GUI.
4149 // Don't do this for double-width characters.
4150 // Don't do this for a window not at the right screen border.
4151 if (p_tf
4152#ifdef FEAT_GUI
4153 && !gui.in_use
4154#endif
4155 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004156 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4157 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004158 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004159 || (*mb_off2cells)(
4160 LineOffset[wlv.screen_row - 1]
4161 + (int)Columns - 2,
4162 LineOffset[wlv.screen_row]
4163 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004164 {
4165 // First make sure we are at the end of the screen line,
4166 // then output the same character again to let the
4167 // terminal know about the wrap. If the terminal doesn't
4168 // auto-wrap, we overwrite the character.
4169 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004170 screen_char(LineOffset[wlv.screen_row - 1]
4171 + (unsigned)Columns - 1,
4172 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004173
4174 // When there is a multi-byte character, just output a
4175 // space to keep it simple.
4176 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004177 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004178 out_char(' ');
4179 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004180 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004181 + (Columns - 1)]);
4182 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004183 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004184 screen_start(); // don't know where cursor is now
4185 }
4186 }
4187
Bram Moolenaar1306b362022-08-06 15:59:06 +01004188 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004189
Bram Moolenaareed9d462021-02-15 20:38:25 +01004190 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004191#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004192 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004193# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004194 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004195# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004196 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004197 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004198#endif
4199#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004200 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004201 // When the filler lines are actually below the last line of the
4202 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004203 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004204 break;
4205#endif
4206 }
4207
4208 } // for every character in the line
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004209#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004210 vim_free(text_props);
4211 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004212 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004213#endif
4214
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004215 vim_free(wlv.p_extra_free);
zeertzjq58e1e012023-06-04 18:46:28 +01004216 vim_free(wlv.saved_p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004217 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004218}