blob: 90fbc2b1dac4b3aff3830ea61cb10bcdb056c292 [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 Moolenaar1306b362022-08-06 15:59:06 +010078// structure with variables passed between win_line() and other functions
79typedef struct {
80 int draw_state; // what to draw next
81
82 linenr_T lnum; // line number to be drawn
83
84 int startrow; // first row in the window to be drawn
85 int row; // row in the window, excl w_winrow
86 int screen_row; // row on the screen, incl w_winrow
87
88 long vcol; // virtual column, before wrapping
89 int col; // visual column on screen, after wrapping
90#ifdef FEAT_CONCEAL
91 int boguscols; // nonexistent columns added to "col" to force
92 // wrapping
93 int vcol_off; // offset for concealed characters
94#endif
95#ifdef FEAT_SYN_HL
96 int draw_color_col; // highlight colorcolumn
97 int *color_cols; // pointer to according columns array
98#endif
99 int eol_hl_off; // 1 if highlighted char after EOL
100
101 unsigned off; // offset in ScreenLines/ScreenAttrs
102
103 int win_attr; // background for the whole window, except
104 // margins and "~" lines.
Bram Moolenaard7657e92022-09-20 18:59:30 +0100105 int wcr_attr; // attributes from 'wincolor'
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100106#ifdef FEAT_SYN_HL
107 int cul_attr; // set when 'cursorline' active
108#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100109
110 int screen_line_flags; // flags for screen_line()
111
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100112 int fromcol; // start of inverting
113 int tocol; // end of inverting
114
115#ifdef FEAT_LINEBREAK
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100116 long vcol_sbr; // virtual column after showbreak
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100117 int need_showbreak; // overlong line, skipping first x chars
118 int dont_use_showbreak; // do not use 'showbreak'
119#endif
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100120#ifdef FEAT_PROP_POPUP
121 int text_prop_above_count;
122#endif
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100123
Bram Moolenaar1306b362022-08-06 15:59:06 +0100124 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
125 int cul_screenline;
126
127 int char_attr; // attributes for the next character
128
129 int n_extra; // number of extra bytes
130 char_u *p_extra; // string of extra chars, plus NUL, only used
131 // when c_extra and c_final are NUL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100132 char_u *p_extra_free; // p_extra buffer that needs to be freed
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000133 int extra_attr; // attributes for p_extra
Bram Moolenaar1306b362022-08-06 15:59:06 +0100134 int c_extra; // extra chars, all the same
135 int c_final; // final char, mandatory if set
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000136 int extra_for_textprop; // wlv.n_extra set for textprop
Bram Moolenaar1306b362022-08-06 15:59:06 +0100137
138 // saved "extra" items for when draw_state becomes WL_LINE (again)
139 int saved_n_extra;
140 char_u *saved_p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000141 int saved_extra_attr;
142 int saved_extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100143 int saved_c_extra;
144 int saved_c_final;
145 int saved_char_attr;
146
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100147 char_u extra[NUMBUFLEN + MB_MAXBYTES];
148 // "%ld " and 'fdc' must fit in here, as well
149 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100150
Bram Moolenaar1306b362022-08-06 15:59:06 +0100151#ifdef FEAT_DIFF
152 hlf_T diff_hlf; // type of diff highlighting
153#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100154 int filler_lines; // nr of filler lines to be drawn
155 int filler_todo; // nr of filler lines still to do + 1
156#ifdef FEAT_SIGNS
157 sign_attrs_T sattr;
158#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100159} winlinevars_T;
160
161// draw_state values for items that are drawn in sequence:
162#define WL_START 0 // nothing done yet, must be zero
Martin Tournoij7904fa42022-10-04 16:28:45 +0100163#define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar1306b362022-08-06 15:59:06 +0100164#ifdef FEAT_FOLDING
165# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
166#else
167# define WL_FOLD WL_CMDLINE
168#endif
169#ifdef FEAT_SIGNS
170# define WL_SIGN (WL_FOLD + 1) // column for signs
171#else
172# define WL_SIGN WL_FOLD // column for signs
173#endif
174#define WL_NR (WL_SIGN + 1) // line number
175#ifdef FEAT_LINEBREAK
176# define WL_BRI (WL_NR + 1) // 'breakindent'
177#else
178# define WL_BRI WL_NR
179#endif
180#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
181# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
182#else
183# define WL_SBR WL_BRI
184#endif
185#define WL_LINE (WL_SBR + 1) // text in the line
186
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100187#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200188/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000189 * Return TRUE if CursorLineSign highlight is to be used.
190 */
191 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100192use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000193{
194 return wp->w_p_cul
195 && lnum == wp->w_cursor.lnum
196 && (wp->w_p_culopt_flags & CULOPT_NBR);
197}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100198#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000199
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100200
201#ifdef FEAT_FOLDING
202/*
203 * Setup for drawing the 'foldcolumn', if there is one.
204 */
205 static void
206handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
207{
208 int fdc = compute_foldcolumn(wp, 0);
209
210 if (fdc <= 0)
211 return;
212
213 // Allocate a buffer, "wlv->extra[]" may already be in use.
214 vim_free(wlv->p_extra_free);
215 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
216 if (wlv->p_extra_free != NULL)
217 {
218 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
219 wp, FALSE, wlv->lnum);
220 wlv->p_extra_free[wlv->n_extra] = NUL;
221 wlv->p_extra = wlv->p_extra_free;
222 wlv->c_extra = NUL;
223 wlv->c_final = NUL;
224 if (use_cursor_line_highlight(wp, wlv->lnum))
225 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
226 else
227 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
228 }
229}
230#endif
231
232#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000233/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100234 * Get information needed to display the sign in line "wlv->lnum" in window
235 * "wp".
236 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200237 * Otherwise the sign is going to be displayed in the sign column.
238 */
239 static void
240get_sign_display_info(
241 int nrcol,
242 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100243 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200244{
245 int text_sign;
246# ifdef FEAT_SIGN_ICONS
247 int icon_sign;
248# endif
249
250 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100251 wlv->c_extra = ' ';
252 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200253 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100254 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200255 else
256 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100257 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100258 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000259 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100260 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100261 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200262 }
263
Bram Moolenaar1306b362022-08-06 15:59:06 +0100264 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200265#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100266 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200267#endif
268 )
269 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100270 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200271# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100272 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200273 if (gui.in_use && icon_sign != 0)
274 {
275 // Use the image in this position.
276 if (nrcol)
277 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100278 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100279 sprintf((char *)wlv->extra, "%-*c ",
280 number_width(wp), SIGN_BYTE);
281 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100282 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200283 }
284 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100285 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200286# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100287 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
288 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200289 {
290 if (nrcol)
291 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100292 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100293 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200294 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100295 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100296 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200297 }
298 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100299 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200300 }
301# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100302 wlv->c_final = NUL;
303 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200304 }
305 else
306# endif
307 if (text_sign != 0)
308 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100309 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100310 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200311 {
312 if (nrcol)
313 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100314 int width = number_width(wp) - 2;
315 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200316
317 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100318 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100319 vim_snprintf((char *)wlv->extra + n,
320 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100321 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200322 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100323 wlv->c_extra = NUL;
324 wlv->c_final = NUL;
325 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200326 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000327
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100328 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100329 && wlv->sattr.sat_culhl > 0)
330 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000331 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100332 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200333 }
334 }
335}
336#endif
337
Bram Moolenaard7657e92022-09-20 18:59:30 +0100338/*
339 * Display the absolute or relative line number. After the first row fill with
340 * blanks when the 'n' flag isn't in 'cpo'.
341 */
342 static void
343handle_lnum_col(
344 win_T *wp,
345 winlinevars_T *wlv,
346 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100347 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100348{
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100349 int has_cpo_n = vim_strchr(p_cpo, CPO_NUMCOL) != NULL;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100350 int lnum_row = wlv->startrow + wlv->filler_lines
351#ifdef FEAT_PROP_POPUP
352 + wlv->text_prop_above_count
353#endif
354 ;
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100355
Bram Moolenaard7657e92022-09-20 18:59:30 +0100356 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100357 && (wlv->row <= lnum_row || !has_cpo_n)
Bram Moolenaar37251162022-10-06 20:48:00 +0100358 // there is no line number in a wrapped line when "n" is in
359 // 'cpoptions', but 'breakindent' assumes it anyway.
360 && !((has_cpo_n
361#ifdef FEAT_LINEBREAK
362 && !wp->w_p_bri
363#endif
364 ) && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100365 {
366#ifdef FEAT_SIGNS
367 // If 'signcolumn' is set to 'number' and a sign is present
368 // in 'lnum', then display the sign instead of the line
369 // number.
370 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
371 get_sign_display_info(TRUE, wp, wlv);
372 else
373#endif
374 {
375 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100376 // When there are text properties above the line put the line number
377 // below them.
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100378 if (wlv->row == lnum_row
Bram Moolenaareb4de622022-10-15 13:42:17 +0100379 && (wp->w_skipcol == 0 || wlv->row > wp->w_winrow
380 || (wp->w_p_nu && wp->w_p_rnu)))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100381 {
382 long num;
383 char *fmt = "%*ld ";
384
385 if (wp->w_p_nu && !wp->w_p_rnu)
386 // 'number' + 'norelativenumber'
387 num = (long)wlv->lnum;
388 else
389 {
390 // 'relativenumber', don't use negative numbers
391 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
392 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
393 {
394 // 'number' + 'relativenumber'
395 num = wlv->lnum;
396 fmt = "%-*ld ";
397 }
398 }
399
400 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100401 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100402 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
403 ++wlv->p_extra)
404 *wlv->p_extra = '-';
405#ifdef FEAT_RIGHTLEFT
406 if (wp->w_p_rl) // reverse line numbers
407 {
408 char_u *p1, *p2;
409 int t;
410
411 // like rl_mirror(), but keep the space at the end
412 p2 = skipwhite(wlv->extra);
413 p2 = skiptowhite(p2) - 1;
414 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
415 {
416 t = *p1;
417 *p1 = *p2;
418 *p2 = t;
419 }
420 }
421#endif
422 wlv->p_extra = wlv->extra;
423 wlv->c_extra = NUL;
424 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100425 }
426 else
427 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100428 wlv->c_extra = ' ';
429 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100430 }
431 wlv->n_extra = number_width(wp) + 1;
432 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
433#ifdef FEAT_SYN_HL
434 // When 'cursorline' is set highlight the line number of
435 // the current line differently.
436 // When 'cursorlineopt' does not have "line" only
437 // highlight the line number itself.
438 // TODO: Can we use CursorLine instead of CursorLineNr
439 // when CursorLineNr isn't set?
440 if (wp->w_p_cul
441 && wlv->lnum == wp->w_cursor.lnum
442 && (wp->w_p_culopt_flags & CULOPT_NBR)
443 && (wlv->row == wlv->startrow + wlv->filler_lines
444 || (wlv->row > wlv->startrow + wlv->filler_lines
445 && (wp->w_p_culopt_flags & CULOPT_LINE))))
446 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
447#endif
448 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
449 && HL_ATTR(HLF_LNA) != 0)
450 // Use LineNrAbove
451 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
452 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
453 && HL_ATTR(HLF_LNB) != 0)
454 // Use LineNrBelow
455 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
456 }
457#ifdef FEAT_SIGNS
458 if (num_attr)
459 wlv->char_attr = num_attr;
460#endif
461 }
462}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100463
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100464#ifdef FEAT_LINEBREAK
465 static void
466handle_breakindent(win_T *wp, winlinevars_T *wlv)
467{
468 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100469 && *get_showbreak_value(wp) != NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100470 // draw indent after showbreak value
471 wlv->draw_state = WL_BRI;
472 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
473 // After the showbreak, draw the breakindent
474 wlv->draw_state = WL_BRI - 1;
475
476 // draw 'breakindent': indent wrapped text accordingly
477 if (wlv->draw_state == WL_BRI - 1)
478 {
479 wlv->draw_state = WL_BRI;
480 // if wlv->need_showbreak is set, breakindent also applies
481 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
482# ifdef FEAT_DIFF
483 && wlv->filler_lines == 0
484# endif
485# ifdef FEAT_PROP_POPUP
486 && !wlv->dont_use_showbreak
487# endif
488 )
489 {
490 wlv->char_attr = 0;
491# ifdef FEAT_DIFF
492 if (wlv->diff_hlf != (hlf_T)0)
493 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
494# endif
495 wlv->p_extra = NULL;
496 wlv->c_extra = ' ';
497 wlv->c_final = NUL;
498 wlv->n_extra = get_breakindent_win(wp,
499 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
500 if (wlv->row == wlv->startrow)
501 {
502 wlv->n_extra -= win_col_off2(wp);
503 if (wlv->n_extra < 0)
504 wlv->n_extra = 0;
505 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100506 if (wp->w_skipcol > 0 && wlv->startrow == 0
507 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100508 wlv->need_showbreak = FALSE;
509 // Correct end of highlighted area for 'breakindent',
510 // required when 'linebreak' is also set.
511 if (wlv->tocol == wlv->vcol)
512 wlv->tocol += wlv->n_extra;
513 }
514 }
515}
516#endif
517
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100518#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
519 static void
520handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
521{
522# ifdef FEAT_DIFF
523 if (wlv->filler_todo > 0)
524 {
525 // Draw "deleted" diff line(s).
526 if (char2cells(wp->w_fill_chars.diff) > 1)
527 {
528 wlv->c_extra = '-';
529 wlv->c_final = NUL;
530 }
531 else
532 {
533 wlv->c_extra = wp->w_fill_chars.diff;
534 wlv->c_final = NUL;
535 }
536# ifdef FEAT_RIGHTLEFT
537 if (wp->w_p_rl)
538 wlv->n_extra = wlv->col + 1;
539 else
540# endif
541 wlv->n_extra = wp->w_width - wlv->col;
542 wlv->char_attr = HL_ATTR(HLF_DED);
543 }
544# endif
545
546# ifdef FEAT_LINEBREAK
547 char_u *sbr = get_showbreak_value(wp);
548 if (*sbr != NUL && wlv->need_showbreak)
549 {
550 // Draw 'showbreak' at the start of each broken line.
551 wlv->p_extra = sbr;
552 wlv->c_extra = NUL;
553 wlv->c_final = NUL;
554 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100555 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100556 wlv->need_showbreak = FALSE;
557 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
558 // Correct end of highlighted area for 'showbreak',
559 // required when 'linebreak' is also set.
560 if (wlv->tocol == wlv->vcol)
561 wlv->tocol += wlv->n_extra;
562 // combine 'showbreak' with 'wincolor'
563 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
564# ifdef FEAT_SYN_HL
565 // combine 'showbreak' with 'cursorline'
566 if (wlv->cul_attr != 0)
567 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
568# endif
569 }
570# endif
571}
572#endif
573
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100574#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100575/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100576 * Return the cell size of virtual text after truncation.
577 */
578 static int
579textprop_size_after_trunc(
580 win_T *wp,
581 int flags, // TP_FLAG_ALIGN_*
582 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100583 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100584 char_u *text,
585 int *n_used_ptr)
586{
587 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100588 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100589 int len = (int)STRLEN(text);
590 int strsize = 0;
591 int n_used;
592
Bram Moolenaar7e017462022-10-11 21:02:09 +0100593 // if the remaining size is to small and 'wrap' is set we wrap anyway and
594 // use the next line
595 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100596 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100597 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100598 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100599 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
600 {
601 int clen = ptr2cells(text + n_used);
602
603 if (strsize + clen > space)
604 break;
605 strsize += clen;
606 }
607 *n_used_ptr = n_used;
608 return strsize;
609}
610
611/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100612 * Take care of padding, right-align and truncation of virtual text after a
613 * line.
614 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
615 * padding, right-align and truncation. Otherwise only the size is computed.
616 * When "n_attr" is NULL returns the number of screen cells used.
617 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100618 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100619 int
620text_prop_position(
621 win_T *wp,
622 textprop_T *tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100623 int vcol UNUSED, // current text column
624 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100625 int *n_extra, // nr of bytes for virtual text
626 char_u **p_extra, // virtual text
627 int *n_attr, // attribute cells, NULL if not used
628 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200629{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100630 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100631 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100632 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
633 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
634 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
635 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100636 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100637 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100638 int before = room; // spaces before the text
639 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100640 int n_used = *n_extra;
641 char_u *l = NULL;
642 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100643 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100644 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar1206c162022-10-10 15:40:04 +0100645 int cont_on_next_line = below && col_with_padding > win_col_off(wp)
646 && !wp->w_p_wrap;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200647
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100648 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100649 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100650 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100651 int skip_add = 0;
652
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100653 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100654 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100655 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100656 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100657 }
658 else
659 {
660 // Right-align: fill with before
661 if (right)
662 before -= cells;
663 if (before < 0
664 || !(right || below)
665 || (below
Bram Moolenaarccf28372022-10-10 21:10:03 +0100666 ? (col_with_padding <= col_off || !wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100667 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100668 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100669 if (right && (wrap
670 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100671 {
672 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100673 before = wp->w_width - col_off - strsize + room;
674 if (before < 0)
675 before = 0;
676 else
677 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100678 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100679 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100680 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100681 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100682 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100683 else if (below && before > 0)
684 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100685 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100686 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100687
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100688 // With 'nowrap' add one to show the "extends" character if needed (it
689 // doesn't show if the text just fits).
690 if (!wp->w_p_wrap
691 && n_used < *n_extra
692 && wp->w_lcs_chars.ext != NUL
693 && wp->w_p_list)
694 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100695 if (!wp->w_p_wrap && below && padding > 0)
696 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100697
698 // add 1 for NUL, 2 for when '…' is used
699 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100700 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100701 if (n_attr == NULL || l != NULL)
702 {
703 int off = 0;
704
705 if (n_attr != NULL)
706 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100707 vim_memset(l, ' ', before);
708 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100709 if (padding > 0)
710 {
711 vim_memset(l + off, ' ', padding);
712 off += padding;
713 }
714 vim_strncpy(l + off, *p_extra, n_used);
715 off += n_used;
716 }
717 else
718 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100719 off = before + after + padding + n_used;
720 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100721 }
722 if (n_attr != NULL)
723 {
724 if (n_used < *n_extra && wp->w_p_wrap)
725 {
726 char_u *lp = l + off - 1;
727
728 if (has_mbyte)
729 {
730 // change last character to '…'
731 lp -= (*mb_head_off)(l, lp);
732 STRCPY(lp, "…");
Bram Moolenaar13845c42022-10-09 15:26:03 +0100733 n_used = lp - l + 3 - before - padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100734 }
735 else
736 // change last character to '>'
737 *lp = '>';
738 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100739 else if (after > 0)
740 {
741 vim_memset(l + off, ' ', after);
742 l[off + after] = NUL;
743 }
744
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100745 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100746 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100747 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100748 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100749 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100750
751 // Add "skip_add" when starting a new line or wrapping,
752 // n_attr_skip will then be decremented in the number column.
753 *n_attr_skip = before + padding
754 + (cont_on_next_line || before > 0 ? skip_add : 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100755 }
756 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100757 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100758
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100759 if (n_attr == NULL)
760 return cells;
761 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200762}
763#endif
764
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100765/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100766 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100767 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
768 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100769 */
770 static void
771wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
772{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100773 if (wlv->row == 0 && wp->w_skipcol > 0
774#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100775 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100776 && *get_showbreak_value(wp) == NUL
777#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100778 // do not overwrite the 'listchars' "precedes" text with "<<<"
779 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100780 {
781 int off = (int)(current_ScreenLine - ScreenLines);
Bram Moolenaareb4de622022-10-15 13:42:17 +0100782 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100783
Bram Moolenaareb4de622022-10-15 13:42:17 +0100784 if (wp->w_p_nu && wp->w_p_rnu)
785 // Do not overwrite the line number, change "123 text" to
786 // "123>>>xt".
787 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
788 {
789 ++off;
790 ++skip;
791 }
792
793 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100794 {
795 ScreenLines[off] = '<';
796 if (enc_utf8)
797 ScreenLinesUC[off] = 0;
798 ScreenAttrs[off] = HL_ATTR(HLF_AT);
799 ++off;
800 }
801 }
802
803 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
804 negative_width ? -wp->w_width : wp->w_width,
805 wlv->screen_line_flags);
806}
807
808/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100809 * Called when finished with the line: draw the screen line and handle any
810 * highlighting until the right of the window.
811 */
812 static void
813draw_screen_line(win_T *wp, winlinevars_T *wlv)
814{
815#ifdef FEAT_SYN_HL
816 long v;
817
818 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
819 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100820 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100821 else
822 v = wp->w_leftcol;
823
824 // check if line ends before left margin
825 if (wlv->vcol < v + wlv->col - win_col_off(wp))
826 wlv->vcol = v + wlv->col - win_col_off(wp);
827# ifdef FEAT_CONCEAL
828 // Get rid of the boguscols now, we want to draw until the right
829 // edge for 'cursorcolumn'.
830 wlv->col -= wlv->boguscols;
831 wlv->boguscols = 0;
832# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
833# else
834# define VCOL_HLC (wlv->vcol)
835# endif
836
837 if (wlv->draw_color_col)
838 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
839
840 if (((wp->w_p_cuc
841 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
842 && (int)wp->w_virtcol <
843 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
844 && wlv->lnum != wp->w_cursor.lnum)
845 || wlv->draw_color_col
846 || wlv->win_attr != 0)
847# ifdef FEAT_RIGHTLEFT
848 && !wp->w_p_rl
849# endif
850 )
851 {
852 int rightmost_vcol = 0;
853 int i;
854
855 if (wp->w_p_cuc)
856 rightmost_vcol = wp->w_virtcol;
857 if (wlv->draw_color_col)
858 // determine rightmost colorcolumn to possibly draw
859 for (i = 0; wlv->color_cols[i] >= 0; ++i)
860 if (rightmost_vcol < wlv->color_cols[i])
861 rightmost_vcol = wlv->color_cols[i];
862
863 while (wlv->col < wp->w_width)
864 {
865 ScreenLines[wlv->off] = ' ';
866 if (enc_utf8)
867 ScreenLinesUC[wlv->off] = 0;
868 ScreenCols[wlv->off] = MAXCOL;
869 ++wlv->col;
870 if (wlv->draw_color_col)
871 wlv->draw_color_col = advance_color_col(
872 VCOL_HLC, &wlv->color_cols);
873
874 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
875 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
876 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
877 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
878 else
879 ScreenAttrs[wlv->off++] = wlv->win_attr;
880
881 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
882 break;
883
884 ++wlv->vcol;
885 }
886 }
887#endif
888
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100889 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100890 ++wlv->row;
891 ++wlv->screen_row;
892}
893#undef VCOL_HLC
894
895/*
896 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100897 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100898 */
899 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100900win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100901{
902 wlv->col = 0;
903 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
904
905#ifdef FEAT_RIGHTLEFT
906 if (wp->w_p_rl)
907 {
908 // Rightleft window: process the text in the normal direction, but put
909 // it in current_ScreenLine[] from right to left. Start at the
910 // rightmost column of the window.
911 wlv->col = wp->w_width - 1;
912 wlv->off += wlv->col;
913 wlv->screen_line_flags |= SLF_RIGHTLEFT;
914 }
915#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100916 if (save_extra)
917 {
918 // reset the drawing state for the start of a wrapped line
919 wlv->draw_state = WL_START;
920 wlv->saved_n_extra = wlv->n_extra;
921 wlv->saved_p_extra = wlv->p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000922 wlv->saved_extra_attr = wlv->extra_attr;
923 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100924 wlv->saved_c_extra = wlv->c_extra;
925 wlv->saved_c_final = wlv->c_final;
926#ifdef FEAT_SYN_HL
927 if (!(wlv->cul_screenline
928# ifdef FEAT_DIFF
929 && wlv->diff_hlf == (hlf_T)0
930# endif
931 ))
932 wlv->saved_char_attr = wlv->char_attr;
933 else
934#endif
935 wlv->saved_char_attr = 0;
936 wlv->n_extra = 0;
937 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100938}
939
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200940/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100941 * Called when wlv->draw_state is set to WL_LINE.
942 */
943 static void
944win_line_continue(winlinevars_T *wlv)
945{
946 if (wlv->saved_n_extra > 0)
947 {
948 // Continue item from end of wrapped line.
949 wlv->n_extra = wlv->saved_n_extra;
950 wlv->c_extra = wlv->saved_c_extra;
951 wlv->c_final = wlv->saved_c_final;
952 wlv->p_extra = wlv->saved_p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000953 wlv->extra_attr = wlv->saved_extra_attr;
954 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100955 wlv->char_attr = wlv->saved_char_attr;
956 }
957 else
958 wlv->char_attr = wlv->win_attr;
959}
960
961/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200962 * Display line "lnum" of window 'wp' on the screen.
963 * Start at row "startrow", stop when "endrow" is reached.
964 * wp->w_virtcol needs to be valid.
965 *
966 * Return the number of last row the line occupies.
967 */
968 int
969win_line(
970 win_T *wp,
971 linenr_T lnum,
972 int startrow,
973 int endrow,
974 int nochange UNUSED, // not updating for changed text
975 int number_only) // only update the number column
976{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100977 winlinevars_T wlv; // variables passed between functions
978
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200979 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100980 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200981 char_u *line; // current line
982 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200983
Bram Moolenaar1306b362022-08-06 15:59:06 +0100984#ifdef FEAT_PROP_POPUP
985 char_u *p_extra_free2 = NULL; // another p_extra to be freed
986#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000987#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000988 int in_linebreak = FALSE; // n_extra set for showing linebreak
989#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200990 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100991 // displaying eol at end-of-line
992 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000993 int lcs_prec_todo = wp->w_lcs_chars.prec;
994 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200995
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100996 int n_attr = 0; // chars with special attr
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000997 int n_attr_skip = 0; // chars to skip bef. using wlv.extra_attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100998 int saved_attr2 = 0; // char_attr saved for n_attr
999 int n_attr3 = 0; // chars with overruling special attr
1000 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001001
Bram Moolenaarcd105412022-10-10 19:50:42 +01001002 int n_skip = 0; // nr of cells to skip for 'nowrap' or
1003 // concealing
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001004#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001005 int skip_cells = 0; // nr of cells to skip for virtual text
1006 // after the line, when w_skipcol is
1007 // larger than the text length
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001008#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001009
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001010 int fromcol_prev = -2; // start of inverting after cursor
1011 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001012 int lnum_in_visual_area = FALSE;
1013 pos_T pos;
1014 long v;
1015
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001016 int attr_pri = FALSE; // char_attr has priority
1017 int area_highlighting = FALSE; // Visual or incsearch highlighting
1018 // in this line
1019 int vi_attr = 0; // attributes for Visual and incsearch
1020 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001021 int area_attr = 0; // attributes desired by highlighting
1022 int search_attr = 0; // attributes desired by 'hlsearch'
1023#ifdef FEAT_SYN_HL
1024 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1025 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001026 int prev_syntax_col = -1; // column of prev_syntax_attr
1027 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001028 int has_syntax = FALSE; // this buffer has syntax highl.
1029 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001030#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001031#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001032 int text_prop_count;
1033 int text_prop_next = 0; // next text property to use
1034 textprop_T *text_props = NULL;
1035 int *text_prop_idxs = NULL;
1036 int text_props_active = 0;
1037 proptype_T *text_prop_type = NULL;
1038 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001039 int text_prop_attr_comb = 0; // text_prop_attr combined with
1040 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001041 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001042 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001043 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001044 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001045 int saved_search_attr = 0; // search_attr to be used when n_extra
1046 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001047 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001048#endif
1049#ifdef FEAT_SPELL
1050 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001051 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001052# define SPWORDLEN 150
1053 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1054 int nextlinecol = 0; // column where nextline[] starts
1055 int nextline_idx = 0; // index in nextline[] where next line
1056 // starts
1057 int spell_attr = 0; // attributes desired by spelling
1058 int word_end = 0; // last byte with same spell_attr
1059 static linenr_T checked_lnum = 0; // line number for "checked_col"
1060 static int checked_col = 0; // column in "checked_lnum" up to which
1061 // there are no spell errors
1062 static int cap_col = -1; // column to check for Cap word
1063 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1064 int cur_checked_col = 0; // checked column for current line
1065#endif
1066 int extra_check = 0; // has extra highlighting
1067 int multi_attr = 0; // attributes desired by multibyte
1068 int mb_l = 1; // multi-byte byte length
1069 int mb_c = 0; // decoded multi-byte character
1070 int mb_utf8 = FALSE; // screen char is UTF-8 char
1071 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001072#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001073 int change_start = MAXCOL; // first col of changed area
1074 int change_end = -1; // last col of changed area
1075#endif
1076 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001077 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001078 int in_multispace = FALSE; // in multiple consecutive spaces
1079 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001080#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
1081 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
1082# define LINE_ATTR
1083 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +01001084 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001085#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001086 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001087 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001088#ifdef FEAT_ARABIC
1089 int prev_c = 0; // previous Arabic character
1090 int prev_c1 = 0; // first composing char for prev_c
1091#endif
1092#if defined(LINE_ATTR)
1093 int did_line_attr = 0;
1094#endif
1095#ifdef FEAT_TERMINAL
1096 int get_term_attr = FALSE;
1097#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001098
Martin Tournoijba43e762022-10-13 22:12:15 +01001099#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001100 // margin columns for the screen line, needed for when 'cursorlineopt'
1101 // contains "screenline"
1102 int left_curline_col = 0;
1103 int right_curline_col = 0;
1104#endif
1105
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001106#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1107 int feedback_col = 0;
1108 int feedback_old_attr = -1;
1109#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001110
1111#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1112 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001113#endif
1114#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001115 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001116#endif
1117#ifdef FEAT_CONCEAL
1118 int syntax_flags = 0;
1119 int syntax_seqnr = 0;
1120 int prev_syntax_id = 0;
1121 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1122 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001123 int did_wcol = FALSE;
1124 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001125# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001126# define FIX_FOR_BOGUSCOLS \
1127 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001128 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001129 wlv.vcol -= wlv.vcol_off; \
1130 wlv.vcol_off = 0; \
1131 wlv.col -= wlv.boguscols; \
1132 old_boguscols = wlv.boguscols; \
1133 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001134 }
1135#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001136# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001137#endif
1138
1139 if (startrow > endrow) // past the end already!
1140 return startrow;
1141
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001142 CLEAR_FIELD(wlv);
1143
1144 wlv.lnum = lnum;
1145 wlv.startrow = startrow;
1146 wlv.row = startrow;
1147 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001148 wlv.fromcol = -10;
1149 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001150#ifdef FEAT_LINEBREAK
1151 wlv.vcol_sbr = -1;
1152#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001153
1154 if (!number_only)
1155 {
1156 // To speed up the loop below, set extra_check when there is linebreak,
1157 // trailing white space and/or syntax processing to be done.
1158#ifdef FEAT_LINEBREAK
1159 extra_check = wp->w_p_lbr;
1160#endif
1161#ifdef FEAT_SYN_HL
1162 if (syntax_present(wp) && !wp->w_s->b_syn_error
1163# ifdef SYN_TIME_LIMIT
1164 && !wp->w_s->b_syn_slow
1165# endif
1166 )
1167 {
1168 // Prepare for syntax highlighting in this line. When there is an
1169 // error, stop syntax highlighting.
1170 save_did_emsg = did_emsg;
1171 did_emsg = FALSE;
1172 syntax_start(wp, lnum);
1173 if (did_emsg)
1174 wp->w_s->b_syn_error = TRUE;
1175 else
1176 {
1177 did_emsg = save_did_emsg;
1178#ifdef SYN_TIME_LIMIT
1179 if (!wp->w_s->b_syn_slow)
1180#endif
1181 {
1182 has_syntax = TRUE;
1183 extra_check = TRUE;
1184 }
1185 }
1186 }
1187
1188 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001189 wlv.color_cols = wp->w_p_cc_cols;
1190 if (wlv.color_cols != NULL)
1191 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001192#endif
1193
1194#ifdef FEAT_TERMINAL
1195 if (term_show_buffer(wp->w_buffer))
1196 {
1197 extra_check = TRUE;
1198 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001199 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001200 }
1201#endif
1202
1203#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001204 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001205 {
1206 // Prepare for spell checking.
1207 has_spell = TRUE;
1208 extra_check = TRUE;
1209
1210 // Get the start of the next line, so that words that wrap to the
1211 // next line are found too: "et<line-break>al.".
1212 // Trick: skip a few chars for C/shell/Vim comments
1213 nextline[SPWORDLEN] = NUL;
1214 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1215 {
1216 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1217 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1218 }
1219
1220 // When a word wrapped from the previous line the start of the
1221 // current line is valid.
1222 if (lnum == checked_lnum)
1223 cur_checked_col = checked_col;
1224 checked_lnum = 0;
1225
1226 // When there was a sentence end in the previous line may require a
1227 // word starting with capital in this line. In line 1 always check
1228 // the first word.
1229 if (lnum != capcol_lnum)
1230 cap_col = -1;
1231 if (lnum == 1)
1232 cap_col = 0;
1233 capcol_lnum = 0;
1234 }
1235#endif
1236
1237 // handle Visual active in this window
1238 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1239 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001240 pos_T *top, *bot;
1241
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001242 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1243 {
1244 // Visual is after curwin->w_cursor
1245 top = &curwin->w_cursor;
1246 bot = &VIsual;
1247 }
1248 else
1249 {
1250 // Visual is before curwin->w_cursor
1251 top = &VIsual;
1252 bot = &curwin->w_cursor;
1253 }
1254 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1255 if (VIsual_mode == Ctrl_V)
1256 {
1257 // block mode
1258 if (lnum_in_visual_area)
1259 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001260 wlv.fromcol = wp->w_old_cursor_fcol;
1261 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001262 }
1263 }
1264 else
1265 {
1266 // non-block mode
1267 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001268 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001269 else if (lnum == top->lnum)
1270 {
1271 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001272 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001273 else
1274 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001275 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001276 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001277 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001278 }
1279 }
1280 if (VIsual_mode != 'V' && lnum == bot->lnum)
1281 {
1282 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1283 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001284 wlv.fromcol = -10;
1285 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001286 }
1287 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001288 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001289 else
1290 {
1291 pos = *bot;
1292 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001293 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1294 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001295 else
1296 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001297 getvvcol(wp, &pos, NULL, NULL,
1298 (colnr_T *)&wlv.tocol);
1299 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001300 }
1301 }
1302 }
1303 }
1304
1305 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001306 if (!highlight_match && lnum == curwin->w_cursor.lnum
1307 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001308#ifdef FEAT_GUI
1309 && !gui.in_use
1310#endif
1311 )
1312 noinvcur = TRUE;
1313
1314 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001315 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001316 {
1317 area_highlighting = TRUE;
1318 vi_attr = HL_ATTR(HLF_V);
1319#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1320 if ((clip_star.available && !clip_star.owned
1321 && clip_isautosel_star())
1322 || (clip_plus.available && !clip_plus.owned
1323 && clip_isautosel_plus()))
1324 vi_attr = HL_ATTR(HLF_VNC);
1325#endif
1326 }
1327 }
1328
1329 // handle 'incsearch' and ":s///c" highlighting
1330 else if (highlight_match
1331 && wp == curwin
1332 && lnum >= curwin->w_cursor.lnum
1333 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1334 {
1335 if (lnum == curwin->w_cursor.lnum)
1336 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001337 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001338 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001339 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001340 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1341 {
1342 pos.lnum = lnum;
1343 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001344 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001345 }
1346 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001347 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001348 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001349 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1350 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001351 area_highlighting = TRUE;
1352 vi_attr = HL_ATTR(HLF_I);
1353 }
1354 }
1355
1356#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001357 wlv.filler_lines = diff_check(wp, lnum);
1358 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001359 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001360 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001361 {
1362 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001363 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001364 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001365 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001366 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001367 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001368 }
1369 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001370 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001371 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001372 area_highlighting = TRUE;
1373 }
1374 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001375 wlv.filler_lines = wp->w_topfill;
1376 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001377#endif
1378
1379#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001380 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001381 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001382 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001383#endif
1384
1385#ifdef LINE_ATTR
1386# ifdef FEAT_SIGNS
1387 // If this line has a sign with line highlighting set line_attr.
1388 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001389 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001390# endif
1391# if defined(FEAT_QUICKFIX)
1392 // Highlight the current line in the quickfix window.
1393 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1394 line_attr = HL_ATTR(HLF_QFL);
1395# endif
1396 if (line_attr != 0)
1397 area_highlighting = TRUE;
1398#endif
1399
1400 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1401 ptr = line;
1402
1403#ifdef FEAT_SPELL
1404 if (has_spell && !number_only)
1405 {
1406 // For checking first word with a capital skip white space.
1407 if (cap_col == 0)
1408 cap_col = getwhitecols(line);
1409
1410 // To be able to spell-check over line boundaries copy the end of the
1411 // current line into nextline[]. Above the start of the next line was
1412 // copied to nextline[SPWORDLEN].
1413 if (nextline[SPWORDLEN] == NUL)
1414 {
1415 // No next line or it is empty.
1416 nextlinecol = MAXCOL;
1417 nextline_idx = 0;
1418 }
1419 else
1420 {
1421 v = (long)STRLEN(line);
1422 if (v < SPWORDLEN)
1423 {
1424 // Short line, use it completely and append the start of the
1425 // next line.
1426 nextlinecol = 0;
1427 mch_memmove(nextline, line, (size_t)v);
1428 STRMOVE(nextline + v, nextline + SPWORDLEN);
1429 nextline_idx = v + 1;
1430 }
1431 else
1432 {
1433 // Long line, use only the last SPWORDLEN bytes.
1434 nextlinecol = v - SPWORDLEN;
1435 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1436 nextline_idx = SPWORDLEN + 1;
1437 }
1438 }
1439 }
1440#endif
1441
1442 if (wp->w_p_list)
1443 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001444 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001445 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001446 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001447 || wp->w_lcs_chars.trail
1448 || wp->w_lcs_chars.lead
1449 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001450 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001451
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001452 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001453 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001454 {
1455 trailcol = (colnr_T)STRLEN(ptr);
1456 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1457 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001458 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001459 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001460 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001461 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001462 {
1463 leadcol = 0;
1464 while (VIM_ISWHITE(ptr[leadcol]))
1465 ++leadcol;
1466 if (ptr[leadcol] == NUL)
1467 // in a line full of spaces all of them are treated as trailing
1468 leadcol = (colnr_T)0;
1469 else
1470 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001471 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001472 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001473 }
1474
Bram Moolenaard7657e92022-09-20 18:59:30 +01001475 wlv.wcr_attr = get_wcr_attr(wp);
1476 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001477 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001478 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001479 area_highlighting = TRUE;
1480 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001481
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001482#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001483 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001484 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001485#endif
1486
1487 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1488 // first character to be displayed.
1489 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001490 v = startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001491 else
1492 v = wp->w_leftcol;
1493 if (v > 0 && !number_only)
1494 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001495 char_u *prev_ptr = ptr;
1496 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001497 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001498
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001499 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001500 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001501 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001502 charsize = win_lbr_chartabsize(&cts, NULL);
1503 cts.cts_vcol += charsize;
1504 prev_ptr = cts.cts_ptr;
1505 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001506 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001507 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001508 ptr = cts.cts_ptr;
1509 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001510
1511 // When:
1512 // - 'cuc' is set, or
1513 // - 'colorcolumn' is set, or
1514 // - 'virtualedit' is set, or
1515 // - the visual mode is active,
1516 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001517 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001518#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001519 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001520#endif
1521 virtual_active() ||
1522 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001523 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001524
1525 // Handle a character that's not completely on the screen: Put ptr at
1526 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001527 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001528 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001529 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001530 ptr = prev_ptr;
1531 // If the character fits on the screen, don't need to skip it.
1532 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001533 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1534 && wlv.col == 0)
1535 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001536 }
1537
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001538#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001539 // If there the text doesn't reach to the desired column, need to skip
1540 // "skip_cells" cells when virtual text follows.
1541 if (!wp->w_p_wrap && v > wlv.vcol)
1542 skip_cells = v - wlv.vcol;
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001543#endif
Bram Moolenaarcd105412022-10-10 19:50:42 +01001544
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001545 // Adjust for when the inverted text is before the screen,
1546 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001547 if (wlv.tocol <= wlv.vcol)
1548 wlv.fromcol = 0;
1549 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1550 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001551
1552#ifdef FEAT_LINEBREAK
1553 // When w_skipcol is non-zero, first line needs 'showbreak'
1554 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001555 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001556#endif
1557#ifdef FEAT_SPELL
1558 // When spell checking a word we need to figure out the start of the
1559 // word and if it's badly spelled or not.
1560 if (has_spell)
1561 {
1562 int len;
1563 colnr_T linecol = (colnr_T)(ptr - line);
1564 hlf_T spell_hlf = HLF_COUNT;
1565
1566 pos = wp->w_cursor;
1567 wp->w_cursor.lnum = lnum;
1568 wp->w_cursor.col = linecol;
1569 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1570
1571 // spell_move_to() may call ml_get() and make "line" invalid
1572 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1573 ptr = line + linecol;
1574
1575 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1576 {
1577 // no bad word found at line start, don't check until end of a
1578 // word
1579 spell_hlf = HLF_COUNT;
1580 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1581 }
1582 else
1583 {
1584 // bad word found, use attributes until end of word
1585 word_end = wp->w_cursor.col + len + 1;
1586
1587 // Turn index into actual attributes.
1588 if (spell_hlf != HLF_COUNT)
1589 spell_attr = highlight_attr[spell_hlf];
1590 }
1591 wp->w_cursor = pos;
1592
1593# ifdef FEAT_SYN_HL
1594 // Need to restart syntax highlighting for this line.
1595 if (has_syntax)
1596 syntax_start(wp, lnum);
1597# endif
1598 }
1599#endif
1600 }
1601
1602 // Correct highlighting for cursor that can't be disabled.
1603 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001604 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001605 {
1606 if (noinvcur)
1607 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001608 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001609 {
1610 // highlighting starts at cursor, let it start just after the
1611 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001612 fromcol_prev = wlv.fromcol;
1613 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001614 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001615 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001616 // restart highlighting after the cursor
1617 fromcol_prev = wp->w_virtcol;
1618 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001619 if (wlv.fromcol >= wlv.tocol)
1620 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001621 }
1622
1623#ifdef FEAT_SEARCH_EXTRA
1624 if (!number_only)
1625 {
1626 v = (long)(ptr - line);
1627 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1628 &line, &screen_search_hl,
1629 &search_attr);
1630 ptr = line + v; // "line" may have been updated
1631 }
1632#endif
1633
1634#ifdef FEAT_SYN_HL
1635 // Cursor line highlighting for 'cursorline' in the current window.
1636 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1637 {
1638 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001639 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001640 if (!(wp == curwin && VIsual_active)
1641 && wp->w_p_culopt_flags != CULOPT_NBR)
1642 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001643 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001644 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1645
1646 // Only set line_attr here when "screenline" is not present in
1647 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001648 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001649 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001650 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001651# ifdef FEAT_SIGNS
1652 // Combine the 'cursorline' and sign highlighting, depending on
1653 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001654 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001655 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001656 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001657 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001658 else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001659 line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001660 }
1661 else
1662# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001663# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001664 // let the line attribute overrule 'cursorline', otherwise
1665 // it disappears when both have background set;
1666 // 'cursorline' can use underline or bold to make it show
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001667 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001668# else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001669 line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001670# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001671 }
1672 else
1673 {
1674 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001675 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1676 }
1677 area_highlighting = TRUE;
1678 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001679 }
1680#endif
1681
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001682#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001683 {
1684 char_u *prop_start;
1685
1686 text_prop_count = get_text_props(wp->w_buffer, lnum,
1687 &prop_start, FALSE);
1688 if (text_prop_count > 0)
1689 {
1690 // Make a copy of the properties, so that they are properly
1691 // aligned.
1692 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1693 if (text_props != NULL)
1694 mch_memmove(text_props, prop_start,
1695 text_prop_count * sizeof(textprop_T));
1696
1697 // Allocate an array for the indexes.
1698 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001699 if (text_prop_idxs == NULL)
1700 VIM_CLEAR(text_props);
1701
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001702 if (text_props != NULL)
1703 {
1704 area_highlighting = TRUE;
1705 extra_check = TRUE;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +01001706 // text props "above" move the line number down to where the
1707 // text is.
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001708 for (int i = 0; i < text_prop_count; ++i)
1709 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1710 ++wlv.text_prop_above_count;
1711 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001712 }
1713 }
1714#endif
1715
Bram Moolenaar1306b362022-08-06 15:59:06 +01001716 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001717
1718 // Repeat for the whole displayed line.
1719 for (;;)
1720 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001721 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001722#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001723 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001724#endif
1725#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001726 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001727#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001728
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001729 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001730 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001731 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001732#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001733 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001734 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001735 wlv.cul_attr = 0;
zeertzjq4f33bc22021-08-05 17:57:02 +02001736 line_attr = line_attr_save;
1737 }
1738#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001739 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001740 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001741 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001742 if (cmdwin_type != 0 && wp == curwin)
1743 {
1744 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001745 wlv.n_extra = 1;
1746 wlv.c_extra = cmdwin_type;
1747 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001748 wlv.char_attr =
1749 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001750 }
1751 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001752#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001753 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001754 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001755 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001756 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001757 }
1758#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001759#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001760 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001761 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001762 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001763 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001764 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001765 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001766 }
1767#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001768 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001769 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001770 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001771 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001772 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001773 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001774#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001775 // Check if 'breakindent' applies and show it.
1776 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1777 if (wlv.n_extra == 0)
1778 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001779#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001780#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001781 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001782 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001783 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001784 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001785 }
1786#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001787 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001788 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001789 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001790 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001791 }
1792 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001793
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001794#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001795 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001796 && wlv.vcol >= left_curline_col
1797 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001798 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001799 wlv.cul_attr = HL_ATTR(HLF_CUL);
1800 line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001801 }
1802#endif
1803
1804 // When still displaying '$' of change command, stop at cursor.
1805 // When only displaying the (relative) line number and that's done,
1806 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001807 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001808 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001809 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001810#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001811 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001812#endif
1813 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001814 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001815 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001816 // Pretend we have finished updating the window. Except when
1817 // 'cursorcolumn' is set.
1818#ifdef FEAT_SYN_HL
1819 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001820 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001821 else
1822#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001823 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001824 break;
1825 }
1826
Bram Moolenaar1306b362022-08-06 15:59:06 +01001827 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001828 {
1829 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001830 if (wlv.vcol == wlv.fromcol
1831 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1832 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001833 && (*mb_ptr2cells)(ptr) > 1)
1834 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001835 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001836 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001837 area_attr = vi_attr; // start highlighting
1838 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001839 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001840 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001841 area_attr = 0; // stop highlighting
1842
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001843#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001844 if (text_props != NULL)
1845 {
1846 int pi;
1847 int bcol = (int)(ptr - line);
1848
Bram Moolenaar1306b362022-08-06 15:59:06 +01001849 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001850# ifdef FEAT_LINEBREAK
1851 && !in_linebreak
1852# endif
1853 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001854 --bcol; // still working on the previous char, e.g. Tab
1855
1856 // Check if any active property ends.
1857 for (pi = 0; pi < text_props_active; ++pi)
1858 {
1859 int tpi = text_prop_idxs[pi];
1860
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001861 if (text_props[tpi].tp_col != MAXCOL
1862 && bcol >= text_props[tpi].tp_col - 1
1863 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001864 {
1865 if (pi + 1 < text_props_active)
1866 mch_memmove(text_prop_idxs + pi,
1867 text_prop_idxs + pi + 1,
1868 sizeof(int)
1869 * (text_props_active - (pi + 1)));
1870 --text_props_active;
1871 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001872# ifdef FEAT_LINEBREAK
1873 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001874 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001875 syntax_attr = 0;
1876# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001877 }
1878 }
1879
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001880# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001881 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001882 // not on the next char yet, don't start another prop
1883 --bcol;
1884# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001885 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001886 // With 'nowrap' and not in the first screen line only "below"
1887 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001888 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001889 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001890 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001891 && (wp->w_p_wrap
1892 || wlv.row == startrow
1893 || (text_props[text_prop_next].tp_flags
1894 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001895 || (bcol == 0 &&
1896 (text_props[text_prop_next].tp_flags
1897 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001898 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001899 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001900 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001901 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1902 {
1903 // first display the '$' after the line
1904 text_prop_follows = TRUE;
1905 break;
1906 }
1907 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001908 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001909 + text_props[text_prop_next].tp_len)
1910 text_prop_idxs[text_props_active++] = text_prop_next;
1911 ++text_prop_next;
1912 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001913
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001914 if (wlv.n_extra == 0 || !wlv.extra_for_textprop)
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001915 {
1916 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001917 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001918 text_prop_flags = 0;
1919 text_prop_type = NULL;
1920 text_prop_id = 0;
1921 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001922 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001923 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001924 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001925 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001926 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001927
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001928 // Sort the properties on priority and/or starting last.
1929 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001930 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001931 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001932 sort_text_props(wp->w_buffer, text_props,
1933 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001934
1935 for (pi = 0; pi < text_props_active; ++pi)
1936 {
1937 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001938 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001939 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01001940 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001941
Bram Moolenaarcd105412022-10-10 19:50:42 +01001942 // Only use a text property that can be displayed.
1943 // Skip "after" properties when wrap is off and at the
1944 // end of the window.
1945 if (pt != NULL
1946 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
1947 && tp->tp_id != -MAXCOL
1948 && !(tp->tp_id < 0
1949 && !wp->w_p_wrap
1950 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
1951 | TP_FLAG_ALIGN_ABOVE
1952 | TP_FLAG_ALIGN_BELOW)) == 0
1953 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001954 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001955 if (pt->pt_hl_id > 0)
1956 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001957 text_prop_type = pt;
1958 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001959 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001960 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001961 text_prop_flags = pt->pt_flags;
1962 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001963 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001964 }
1965 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001966 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001967 && -text_prop_id
1968 <= wp->w_buffer->b_textprop_text.ga_len)
1969 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001970 textprop_T *tp = &text_props[used_tpi];
1971 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001972 ->b_textprop_text.ga_data)[
1973 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001974 int above = (tp->tp_flags
1975 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01001976 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001977
1978 // reset the ID in the copy to avoid it being used
1979 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001980 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001981
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001982 if (p != NULL)
1983 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001984 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001985 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001986 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001987 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001988 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1989 int padding = tp->tp_col == MAXCOL
1990 && tp->tp_len > 1
1991 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001992
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001993 // Insert virtual text before the current
1994 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001995 wlv.p_extra = p;
1996 wlv.c_extra = NUL;
1997 wlv.c_final = NUL;
1998 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001999 wlv.extra_for_textprop = TRUE;
2000 wlv.extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002001 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002002 // restore search_attr and area_attr when n_extra
2003 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01002004 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002005 saved_area_attr = area_attr;
2006 search_attr = 0;
2007 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002008 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002009 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002010 if (*ptr == NUL)
2011 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002012 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002013#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002014 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002015 {
2016 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002017 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002018 wlv.need_showbreak = FALSE;
2019 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002020 }
2021#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002022 if ((right || above || below || !wrap
2023 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002024 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002025 char_u *prev_p_extra = wlv.p_extra;
2026 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002027
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002028 // Take care of padding, right-align and
2029 // truncation.
2030 // Shared with win_lbr_chartabsize(), must do
2031 // exactly the same.
2032 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002033 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002034 wlv.col,
2035 &wlv.n_extra, &wlv.p_extra,
2036 &n_attr, &n_attr_skip);
2037 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002038 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002039 // wlv.p_extra was allocated
2040 vim_free(p_extra_free2);
2041 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002042 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002043
Bram Moolenaara4abe512022-09-15 19:44:09 +01002044 if (lcs_eol_one < 0 && wlv.col
2045 + wlv.n_extra - 2 > wp->w_width)
2046 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002047 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002048
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002049 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002050 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002051 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002052 {
2053 draw_screen_line(wp, &wlv);
2054
2055 // When line got too long for screen break
2056 // here.
2057 if (wlv.row == endrow)
2058 {
2059 ++wlv.row;
2060 break;
2061 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002062 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002063 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002064 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002065 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002066 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002067
Bram Moolenaarcd105412022-10-10 19:50:42 +01002068 // If the text didn't reach until the first window
2069 // column we need to skip cells.
2070 if (skip_cells > 0)
2071 {
2072 if (wlv.n_extra > skip_cells)
2073 {
2074 wlv.n_extra -= skip_cells;
2075 wlv.p_extra += skip_cells;
2076 n_attr_skip -= skip_cells;
2077 if (n_attr_skip < 0)
2078 n_attr_skip = 0;
2079 skip_cells = 0;
2080 }
2081 else
2082 {
2083 // the whole text is left of the window, drop
2084 // it and advance to the next one
2085 skip_cells -= wlv.n_extra;
2086 wlv.n_extra = 0;
2087 n_attr_skip = 0;
2088 bail_out = TRUE;
2089 }
2090 }
2091
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002092 // If another text prop follows the condition below at
2093 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002094 // If this is an "above" text prop and 'nowrap' the we
2095 // must wrap anyway.
2096 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002097 text_prop_follows |= other_tpi != -1
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002098 && (wp->w_p_wrap
2099 || (text_props[other_tpi].tp_flags
2100 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002101
2102 if (bail_out)
2103 // starting a new line for "below"
2104 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002105 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002106 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002107 else if (text_prop_next < text_prop_count
2108 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002109 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2110 || (!wp->w_p_wrap
2111 && wlv.col == wp->w_width - 1
2112 && (text_props[text_prop_next].tp_flags
2113 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002114 // When at last-but-one character and a text property
2115 // follows after it, we may need to flush the line after
2116 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002117 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002118 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002119 }
2120#endif
2121
Bram Moolenaare38fc862022-08-11 17:24:50 +01002122#ifdef FEAT_SEARCH_EXTRA
2123 if (wlv.n_extra == 0)
2124 {
2125 // Check for start/end of 'hlsearch' and other matches.
2126 // After end, check for start/end of next match.
2127 // When another match, have to check for start again.
2128 v = (long)(ptr - line);
2129 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2130 &screen_search_hl, &has_match_conc,
2131 &match_conc, did_line_attr, lcs_eol_one,
2132 &on_last_col);
2133 ptr = line + v; // "line" may have been changed
2134 prev_ptr = ptr;
2135
2136 // Do not allow a conceal over EOL otherwise EOL will be missed
2137 // and bad things happen.
2138 if (*ptr == NUL)
2139 has_match_conc = 0;
2140 }
2141#endif
2142
2143#ifdef FEAT_DIFF
2144 if (wlv.diff_hlf != (hlf_T)0)
2145 {
2146 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2147 && wlv.n_extra == 0)
2148 wlv.diff_hlf = HLF_TXD; // changed text
2149 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2150 && wlv.n_extra == 0)
2151 wlv.diff_hlf = HLF_CHD; // changed line
2152 line_attr = HL_ATTR(wlv.diff_hlf);
2153 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2154 && wp->w_p_culopt_flags != CULOPT_NBR
2155 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2156 && wlv.vcol <= right_curline_col)))
2157 line_attr = hl_combine_attr(
2158 line_attr, HL_ATTR(HLF_CUL));
2159 }
2160#endif
2161
Bram Moolenaara74fda62019-10-19 17:38:03 +02002162#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002163 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002164 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002165 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002166# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002167 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002168 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002169# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002170 // Get syntax attribute.
2171 if (has_syntax)
2172 {
2173 // Get the syntax attribute for the character. If there
2174 // is an error, disable syntax highlighting.
2175 save_did_emsg = did_emsg;
2176 did_emsg = FALSE;
2177
2178 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002179 if (v == prev_syntax_col)
2180 // at same column again
2181 syntax_attr = prev_syntax_attr;
2182 else
2183 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002184# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002185 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002186# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002187 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002188# ifdef FEAT_SPELL
2189 has_spell ? &can_spell :
2190# endif
2191 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002192 prev_syntax_col = v;
2193 prev_syntax_attr = syntax_attr;
2194 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002195
Bram Moolenaar34390282019-10-16 14:38:26 +02002196 if (did_emsg)
2197 {
2198 wp->w_s->b_syn_error = TRUE;
2199 has_syntax = FALSE;
2200 syntax_attr = 0;
2201 }
2202 else
2203 did_emsg = save_did_emsg;
2204# ifdef SYN_TIME_LIMIT
2205 if (wp->w_s->b_syn_slow)
2206 has_syntax = FALSE;
2207# endif
2208
2209 // Need to get the line again, a multi-line regexp may
2210 // have made it invalid.
2211 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2212 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002213 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002214# ifdef FEAT_CONCEAL
2215 // no concealing past the end of the line, it interferes
2216 // with line highlighting
2217 if (*ptr == NUL)
2218 syntax_flags = 0;
2219 else
2220 syntax_flags = get_syntax_info(&syntax_seqnr);
2221# endif
2222 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002223 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002224# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002225 // Combine text property highlight into syntax highlight.
2226 if (text_prop_type != NULL)
2227 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002228 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002229 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2230 else
2231 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002232 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002233 }
2234# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002235#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002236
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002237 // Decide which of the highlight attributes to use.
2238 attr_pri = TRUE;
2239#ifdef LINE_ATTR
2240 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002241 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002242 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002243 if (!highlight_match)
2244 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002245 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002246# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002247 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002248# endif
2249 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002250 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002251 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002252 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002253# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002254 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002255# endif
2256 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002257 else if (line_attr != 0
2258 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2259 || wlv.vcol < wlv.fromcol
2260 || vcol_prev < fromcol_prev
2261 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002262 {
2263 // Use line_attr when not in the Visual or 'incsearch' area
2264 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002265# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002266 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002267# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002268 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002269# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002270 attr_pri = FALSE;
2271 }
2272#else
2273 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002274 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002275 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002276 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002277#endif
2278 else
2279 {
2280 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002281#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002282 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002283#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002284 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002285#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002286 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002287#ifdef FEAT_PROP_POPUP
2288 // override with text property highlight when "override" is TRUE
2289 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002290 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002291#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002292 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002293
2294 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002295 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002296 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002297 if (wlv.char_attr == 0)
2298 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002299 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002300 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002301 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002302
2303 // Get the next character to put on the screen.
2304
2305 // The "p_extra" points to the extra stuff that is inserted to
2306 // represent special characters (non-printable stuff) and other
2307 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002308 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002309 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2310 // "p_extra[n_extra]".
2311 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002312 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002313 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002314 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002315 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002316 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2317 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002318 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2319 if (enc_utf8 && utf_char2len(c) > 1)
2320 {
2321 mb_utf8 = TRUE;
2322 u8cc[0] = 0;
2323 c = 0xc0;
2324 }
2325 else
2326 mb_utf8 = FALSE;
2327 }
2328 else
2329 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002330 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002331 if (has_mbyte)
2332 {
2333 mb_c = c;
2334 if (enc_utf8)
2335 {
2336 // If the UTF-8 character is more than one byte:
2337 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002338 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002339 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002340 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002341 mb_l = 1;
2342 else if (mb_l > 1)
2343 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002344 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002345 mb_utf8 = TRUE;
2346 c = 0xc0;
2347 }
2348 }
2349 else
2350 {
2351 // if this is a DBCS character, put it in "mb_c"
2352 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002353 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002354 mb_l = 1;
2355 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002356 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002357 }
2358 if (mb_l == 0) // at the NUL at end-of-line
2359 mb_l = 1;
2360
2361 // If a double-width char doesn't fit display a '>' in the
2362 // last column.
2363 if ((
2364# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002365 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002366# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002367 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002368 && (*mb_char2cells)(mb_c) == 2)
2369 {
2370 c = '>';
2371 mb_c = c;
2372 mb_l = 1;
2373 mb_utf8 = FALSE;
2374 multi_attr = HL_ATTR(HLF_AT);
2375#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002376 if (wlv.cul_attr)
2377 multi_attr = hl_combine_attr(
2378 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002379#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002380 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002381
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002382 // put the pointer back to output the double-width
2383 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002384 ++wlv.n_extra;
2385 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002386 }
2387 else
2388 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002389 wlv.n_extra -= mb_l - 1;
2390 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002391 }
2392 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002393 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002394 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002395 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002396#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002397 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002398 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002399 wlv.extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002400 in_linebreak = FALSE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002401
2402 // only restore search_attr and area_attr after extra in the
2403 // next screen line is also done
2404 if (wlv.saved_n_extra <= 0)
2405 {
2406 if (search_attr == 0)
2407 search_attr = saved_search_attr;
2408 if (area_attr == 0 && *ptr != NUL)
2409 area_attr = saved_area_attr;
2410 }
Bram Moolenaare38fc862022-08-11 17:24:50 +01002411 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002412#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002413 }
2414 else
2415 {
2416#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002417 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002418#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002419 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002420
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002421 // Get a character from the line itself.
2422 c = *ptr;
2423#ifdef FEAT_LINEBREAK
2424 c0 = *ptr;
2425#endif
2426 if (has_mbyte)
2427 {
2428 mb_c = c;
2429 if (enc_utf8)
2430 {
2431 // If the UTF-8 character is more than one byte: Decode it
2432 // into "mb_c".
2433 mb_l = utfc_ptr2len(ptr);
2434 mb_utf8 = FALSE;
2435 if (mb_l > 1)
2436 {
2437 mb_c = utfc_ptr2char(ptr, u8cc);
2438 // Overlong encoded ASCII or ASCII with composing char
2439 // is displayed normally, except a NUL.
2440 if (mb_c < 0x80)
2441 {
2442 c = mb_c;
2443#ifdef FEAT_LINEBREAK
2444 c0 = mb_c;
2445#endif
2446 }
2447 mb_utf8 = TRUE;
2448
2449 // At start of the line we can have a composing char.
2450 // Draw it as a space with a composing char.
2451 if (utf_iscomposing(mb_c))
2452 {
2453 int i;
2454
2455 for (i = Screen_mco - 1; i > 0; --i)
2456 u8cc[i] = u8cc[i - 1];
2457 u8cc[0] = mb_c;
2458 mb_c = ' ';
2459 }
2460 }
2461
2462 if ((mb_l == 1 && c >= 0x80)
2463 || (mb_l >= 1 && mb_c == 0)
2464 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2465 {
2466 // Illegal UTF-8 byte: display as <xx>.
2467 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002468 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002469# ifdef FEAT_RIGHTLEFT
2470 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002471 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002472# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002473 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002474 c = *wlv.p_extra;
2475 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002476 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002477 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2478 wlv.c_extra = NUL;
2479 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002480 if (area_attr == 0 && search_attr == 0)
2481 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002482 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002483 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002484 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002485 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002486 }
2487 }
2488 else if (mb_l == 0) // at the NUL at end-of-line
2489 mb_l = 1;
2490#ifdef FEAT_ARABIC
2491 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2492 {
2493 // Do Arabic shaping.
2494 int pc, pc1, nc;
2495 int pcc[MAX_MCO];
2496
2497 // The idea of what is the previous and next
2498 // character depends on 'rightleft'.
2499 if (wp->w_p_rl)
2500 {
2501 pc = prev_c;
2502 pc1 = prev_c1;
2503 nc = utf_ptr2char(ptr + mb_l);
2504 prev_c1 = u8cc[0];
2505 }
2506 else
2507 {
2508 pc = utfc_ptr2char(ptr + mb_l, pcc);
2509 nc = prev_c;
2510 pc1 = pcc[0];
2511 }
2512 prev_c = mb_c;
2513
2514 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2515 }
2516 else
2517 prev_c = mb_c;
2518#endif
2519 }
2520 else // enc_dbcs
2521 {
2522 mb_l = MB_BYTE2LEN(c);
2523 if (mb_l == 0) // at the NUL at end-of-line
2524 mb_l = 1;
2525 else if (mb_l > 1)
2526 {
2527 // We assume a second byte below 32 is illegal.
2528 // Hopefully this is OK for all double-byte encodings!
2529 if (ptr[1] >= 32)
2530 mb_c = (c << 8) + ptr[1];
2531 else
2532 {
2533 if (ptr[1] == NUL)
2534 {
2535 // head byte at end of line
2536 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002537 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002538 }
2539 else
2540 {
2541 // illegal tail byte
2542 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002543 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002544 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002545 wlv.p_extra = wlv.extra;
2546 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002547 wlv.c_extra = NUL;
2548 wlv.c_final = NUL;
2549 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002550 if (area_attr == 0 && search_attr == 0)
2551 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002552 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002553 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002554 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002555 // save current attr
2556 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002557 }
2558 mb_c = c;
2559 }
2560 }
2561 }
2562 // If a double-width char doesn't fit display a '>' in the
2563 // last column; the character is displayed at the start of the
2564 // next line.
2565 if ((
2566# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002567 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002568# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002569 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002570 && (*mb_char2cells)(mb_c) == 2)
2571 {
2572 c = '>';
2573 mb_c = c;
2574 mb_utf8 = FALSE;
2575 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002576 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002577 // Put pointer back so that the character will be
2578 // displayed at the start of the next line.
2579 --ptr;
2580#ifdef FEAT_CONCEAL
2581 did_decrement_ptr = TRUE;
2582#endif
2583 }
2584 else if (*ptr != NUL)
2585 ptr += mb_l - 1;
2586
2587 // If a double-width char doesn't fit at the left side display
2588 // a '<' in the first column. Don't do this for unprintable
2589 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002590 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002591 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002592 wlv.n_extra = 1;
2593 wlv.c_extra = MB_FILLER_CHAR;
2594 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002595 c = ' ';
2596 if (area_attr == 0 && search_attr == 0)
2597 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002598 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002599 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002600 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002601 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002602 }
2603 mb_c = c;
2604 mb_utf8 = FALSE;
2605 mb_l = 1;
2606 }
2607
2608 }
2609 ++ptr;
2610
2611 if (extra_check)
2612 {
2613#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002614 // Check spelling (unless at the end of the line).
2615 // Only do this when there is no syntax highlighting, the
2616 // @Spell cluster is not used or the current syntax item
2617 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002618 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002619 if (has_spell && v >= word_end && v > cur_checked_col)
2620 {
2621 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002622 // do not calculate cap_col at the end of the line or when
2623 // only white space is following
2624 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002625# ifdef FEAT_SYN_HL
2626 !has_syntax ||
2627# endif
2628 can_spell))
2629 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002630 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002631 int len;
2632 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002633
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002634 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002635 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002636
2637 // Use nextline[] if possible, it has the start of the
2638 // next line concatenated.
2639 if ((prev_ptr - line) - nextlinecol >= 0)
2640 p = nextline + (prev_ptr - line) - nextlinecol;
2641 else
2642 p = prev_ptr;
2643 cap_col -= (int)(prev_ptr - line);
2644 len = spell_check(wp, p, &spell_hlf, &cap_col,
2645 nochange);
2646 word_end = v + len;
2647
2648 // In Insert mode only highlight a word that
2649 // doesn't touch the cursor.
2650 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002651 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002652 && wp->w_cursor.lnum == lnum
2653 && wp->w_cursor.col >=
2654 (colnr_T)(prev_ptr - line)
2655 && wp->w_cursor.col < (colnr_T)word_end)
2656 {
2657 spell_hlf = HLF_COUNT;
2658 spell_redraw_lnum = lnum;
2659 }
2660
2661 if (spell_hlf == HLF_COUNT && p != prev_ptr
2662 && (p - nextline) + len > nextline_idx)
2663 {
2664 // Remember that the good word continues at the
2665 // start of the next line.
2666 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002667 checked_col = (int)((p - nextline)
2668 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002669 }
2670
2671 // Turn index into actual attributes.
2672 if (spell_hlf != HLF_COUNT)
2673 spell_attr = highlight_attr[spell_hlf];
2674
2675 if (cap_col > 0)
2676 {
2677 if (p != prev_ptr
2678 && (p - nextline) + cap_col >= nextline_idx)
2679 {
2680 // Remember that the word in the next line
2681 // must start with a capital.
2682 capcol_lnum = lnum + 1;
2683 cap_col = (int)((p - nextline) + cap_col
2684 - nextline_idx);
2685 }
2686 else
2687 // Compute the actual column.
2688 cap_col += (int)(prev_ptr - line);
2689 }
2690 }
2691 }
2692 if (spell_attr != 0)
2693 {
2694 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002695 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2696 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002697 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002698 wlv.char_attr = hl_combine_attr(spell_attr,
2699 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002700 }
2701#endif
2702#ifdef FEAT_LINEBREAK
2703 // Found last space before word: check for line break.
2704 if (wp->w_p_lbr && c0 == c
2705 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2706 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002707 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2708 : 0;
2709 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002710 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002711
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002712 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002713# ifdef FEAT_PROP_POPUP
2714 // do not want virtual text counted here
2715 cts.cts_has_prop_with_text = FALSE;
2716# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002717 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002718 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002719
2720 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002721 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002722 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002723 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002724 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2725 if (wlv.n_extra < 0)
2726 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002727 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002728 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002729 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002730 // line break, but for TABs the highlighting should
2731 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002732 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002733
Bram Moolenaar1306b362022-08-06 15:59:06 +01002734 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002735# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002736 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002737 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002738 wp->w_buffer->b_p_vts_array) - 1;
2739# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002740 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002741 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002742# endif
2743
Bram Moolenaar1306b362022-08-06 15:59:06 +01002744 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2745 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002746# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002747 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002748 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002749# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002750 if (VIM_ISWHITE(c))
2751 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002752# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002753 if (c == TAB)
2754 // See "Tab alignment" below.
2755 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002756# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002757 if (!wp->w_p_list)
2758 c = ' ';
2759 }
2760 }
2761#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002762 in_multispace = c == ' '
2763 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2764 if (!in_multispace)
2765 multispace_pos = 0;
2766
Bram Moolenaareed9d462021-02-15 20:38:25 +01002767 // 'list': Change char 160 to 'nbsp' and space to 'space'
2768 // setting in 'listchars'. But not when the character is
2769 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002770 if (wp->w_p_list
2771 && ((((c == 160 && mb_l == 1)
2772 || (mb_utf8
2773 && ((mb_c == 160 && mb_l == 2)
2774 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002775 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002776 || (c == ' '
2777 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002778 && (wp->w_lcs_chars.space
2779 || (in_multispace
2780 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002781 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002782 && ptr - line <= trailcol)))
2783 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002784 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2785 {
2786 c = wp->w_lcs_chars.multispace[multispace_pos++];
2787 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2788 multispace_pos = 0;
2789 }
2790 else
2791 c = (c == ' ') ? wp->w_lcs_chars.space
2792 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002793 if (area_attr == 0 && search_attr == 0)
2794 {
2795 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002796 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002797 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002798 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002799 }
2800 mb_c = c;
2801 if (enc_utf8 && utf_char2len(c) > 1)
2802 {
2803 mb_utf8 = TRUE;
2804 u8cc[0] = 0;
2805 c = 0xc0;
2806 }
2807 else
2808 mb_utf8 = FALSE;
2809 }
2810
zeertzjq2e7cba32022-06-10 15:30:32 +01002811 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2812 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002813 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002814 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2815 && wp->w_lcs_chars.leadmultispace != NULL)
2816 {
2817 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002818 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2819 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002820 multispace_pos = 0;
2821 }
2822
2823 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2824 c = wp->w_lcs_chars.trail;
2825
2826 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2827 c = wp->w_lcs_chars.lead;
2828
zeertzjq2e7cba32022-06-10 15:30:32 +01002829 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002830 c = wp->w_lcs_chars.space;
2831
2832
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002833 if (!attr_pri)
2834 {
2835 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002836 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002837 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002838 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002839 }
2840 mb_c = c;
2841 if (enc_utf8 && utf_char2len(c) > 1)
2842 {
2843 mb_utf8 = TRUE;
2844 u8cc[0] = 0;
2845 c = 0xc0;
2846 }
2847 else
2848 mb_utf8 = FALSE;
2849 }
2850 }
2851
2852 // Handling of non-printable characters.
2853 if (!vim_isprintc(c))
2854 {
2855 // when getting a character from the file, we may have to
2856 // turn it into something else on the way to putting it
2857 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002858 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002859 {
2860 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002861 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002862#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002863 char_u *sbr = get_showbreak_value(wp);
2864
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002865 // only adjust the tab_len, when at the first column
2866 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002867 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002868 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002869#endif
2870 // tab amount depends on current column
2871#ifdef FEAT_VARTABS
2872 tab_len = tabstop_padding(vcol_adjusted,
2873 wp->w_buffer->b_p_ts,
2874 wp->w_buffer->b_p_vts_array) - 1;
2875#else
2876 tab_len = (int)wp->w_buffer->b_p_ts
2877 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2878#endif
2879
2880#ifdef FEAT_LINEBREAK
2881 if (!wp->w_p_lbr || !wp->w_p_list)
2882#endif
2883 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002884 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002885#ifdef FEAT_LINEBREAK
2886 else
2887 {
2888 char_u *p;
2889 int len;
2890 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002891 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002892
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002893# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002894 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002895 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002896 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002897
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002898 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002899 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002900 && old_boguscols > 0
2901 && wlv.n_extra > tab_len)
2902 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002903# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002904 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002905 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002906 // If wlv.n_extra > 0, it gives the number of
2907 // chars, to use for a tab, else we need to
2908 // calculate the width for a tab.
2909 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
2910 len = tab_len * tab2_len;
2911 if (wp->w_lcs_chars.tab3)
2912 len += mb_char2len(wp->w_lcs_chars.tab3)
2913 - tab2_len;
2914 if (wlv.n_extra > 0)
2915 len += wlv.n_extra - tab_len;
2916 c = wp->w_lcs_chars.tab1;
2917 p = alloc(len + 1);
2918 if (p == NULL)
2919 wlv.n_extra = 0;
2920 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002921 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002922 vim_memset(p, ' ', len);
2923 p[len] = NUL;
2924 vim_free(wlv.p_extra_free);
2925 wlv.p_extra_free = p;
2926 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002927 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002928 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002929
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002930 if (*p == NUL)
2931 {
2932 tab_len = i;
2933 break;
2934 }
2935
2936 // if tab3 is given, use it for the last
2937 // char
2938 if (wp->w_lcs_chars.tab3
2939 && i == tab_len - 1)
2940 lcs = wp->w_lcs_chars.tab3;
2941 p += mb_char2bytes(lcs, p);
2942 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002943 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002944 }
2945 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002946# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002947 // n_extra will be increased by
2948 // FIX_FOX_BOGUSCOLS macro below, so need to
2949 // adjust for that here
2950 if (wlv.vcol_off > 0)
2951 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002952# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002953 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002954 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002955 }
2956#endif
2957#ifdef FEAT_CONCEAL
2958 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002959 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002960
2961 // Tab alignment should be identical regardless of
2962 // 'conceallevel' value. So tab compensates of all
2963 // previous concealed characters, and thus resets
2964 // vcol_off and boguscols accumulated so far in the
2965 // line. Note that the tab can be longer than
2966 // 'tabstop' when there are concealed characters.
2967 FIX_FOR_BOGUSCOLS;
2968
2969 // Make sure, the highlighting for the tab char will be
2970 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002971 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002972 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002973 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002974 tab_len += vc_saved;
2975 }
2976#endif
2977 mb_utf8 = FALSE; // don't draw as UTF-8
2978 if (wp->w_p_list)
2979 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002980 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002981 ? wp->w_lcs_chars.tab3
2982 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002983#ifdef FEAT_LINEBREAK
2984 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002985 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002986 else
2987#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002988 wlv.c_extra = wp->w_lcs_chars.tab2;
2989 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002990 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002991 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002992 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002993 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002994 mb_c = c;
2995 if (enc_utf8 && utf_char2len(c) > 1)
2996 {
2997 mb_utf8 = TRUE;
2998 u8cc[0] = 0;
2999 c = 0xc0;
3000 }
3001 }
3002 else
3003 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003004 wlv.c_final = NUL;
3005 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003006 c = ' ';
3007 }
3008 }
3009 else if (c == NUL
3010 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003011 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3012 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003013 && VIsual_mode != Ctrl_V
3014 && (
3015# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003016 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003017# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003018 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003019 && !(noinvcur
3020 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003021 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003022 && lcs_eol_one > 0)
3023 {
3024 // Display a '$' after the line or highlight an extra
3025 // character if the line break is included.
3026#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3027 // For a diff line the highlighting continues after the
3028 // "$".
3029 if (
3030# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003031 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003032# ifdef LINE_ATTR
3033 &&
3034# endif
3035# endif
3036# ifdef LINE_ATTR
3037 line_attr == 0
3038# endif
3039 )
3040#endif
3041 {
3042 // In virtualedit, visual selections may extend
3043 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003044 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003045 && wlv.tocol != MAXCOL
3046 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003047 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003048 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003049 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003050 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3051 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003052 else
3053 c = ' ';
3054 lcs_eol_one = -1;
3055 --ptr; // put it back at the NUL
3056 if (!attr_pri)
3057 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003058 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003059 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003060 n_attr = 1;
3061 }
3062 mb_c = c;
3063 if (enc_utf8 && utf_char2len(c) > 1)
3064 {
3065 mb_utf8 = TRUE;
3066 u8cc[0] = 0;
3067 c = 0xc0;
3068 }
3069 else
3070 mb_utf8 = FALSE; // don't draw as UTF-8
3071 }
3072 else if (c != NUL)
3073 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003074 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3075 if (wlv.n_extra == 0)
3076 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003077#ifdef FEAT_RIGHTLEFT
3078 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003079 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003080#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003081 wlv.c_extra = NUL;
3082 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003083#ifdef FEAT_LINEBREAK
3084 if (wp->w_p_lbr)
3085 {
3086 char_u *p;
3087
Bram Moolenaar1306b362022-08-06 15:59:06 +01003088 c = *wlv.p_extra;
3089 p = alloc(wlv.n_extra + 1);
3090 vim_memset(p, ' ', wlv.n_extra);
3091 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3092 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003093 vim_free(wlv.p_extra_free);
3094 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003095 }
3096 else
3097#endif
3098 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003099 wlv.n_extra = byte2cells(c) - 1;
3100 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003101 }
3102 if (!attr_pri)
3103 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003104 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003105 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003106 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003107 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003108 }
3109 mb_utf8 = FALSE; // don't draw as UTF-8
3110 }
3111 else if (VIsual_active
3112 && (VIsual_mode == Ctrl_V
3113 || VIsual_mode == 'v')
3114 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003115 && wlv.tocol != MAXCOL
3116 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003117 && (
3118#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003119 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003120#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003121 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003122 {
3123 c = ' ';
3124 --ptr; // put it back at the NUL
3125 }
3126#if defined(LINE_ATTR)
3127 else if ((
3128# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003129 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003130# endif
3131# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003132 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003133# endif
3134 line_attr != 0
3135 ) && (
3136# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003137 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003138# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003139 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003140# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003141 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003142# endif
3143 < wp->w_width)))
3144 {
3145 // Highlight until the right side of the window
3146 c = ' ';
3147 --ptr; // put it back at the NUL
3148
3149 // Remember we do the char for line highlighting.
3150 ++did_line_attr;
3151
3152 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01003153 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003154 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003155 || (wp->w_p_list &&
3156 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003157 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003158# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003159 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003160 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003161 wlv.diff_hlf = HLF_CHD;
3162 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003163 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003164 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003165 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3166 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003167 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003168 || (wlv.vcol >= left_curline_col
3169 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003170 wlv.char_attr = hl_combine_attr(
3171 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003172 }
3173 }
3174# endif
3175# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003176 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003177 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003178 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003179 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3180 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003181 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003182 if (!wlv.cul_screenline
3183 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003184 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003185 wlv.char_attr = hl_combine_attr(
3186 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003187 }
3188 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003189 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3190 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003191 }
3192# endif
3193 }
3194#endif
3195 }
3196
3197#ifdef FEAT_CONCEAL
3198 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003199 && (wp != curwin || lnum != wp->w_cursor.lnum
3200 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003201 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3202 && !(lnum_in_visual_area
3203 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3204 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003205 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003206 if (((prev_syntax_id != syntax_seqnr
3207 && (syntax_flags & HL_CONCEAL) != 0)
3208 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003209 && (syn_get_sub_char() != NUL
3210 || (has_match_conc && match_conc)
3211 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003212 && wp->w_p_cole != 3)
3213 {
3214 // First time at this concealed item: display one
3215 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003216 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003217 c = match_conc;
3218 else if (syn_get_sub_char() != NUL)
3219 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003220 else if (wp->w_lcs_chars.conceal != NUL)
3221 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003222 else
3223 c = ' ';
3224
3225 prev_syntax_id = syntax_seqnr;
3226
Bram Moolenaar1306b362022-08-06 15:59:06 +01003227 if (wlv.n_extra > 0)
3228 wlv.vcol_off += wlv.n_extra;
3229 wlv.vcol += wlv.n_extra;
3230 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003231 {
3232# ifdef FEAT_RIGHTLEFT
3233 if (wp->w_p_rl)
3234 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003235 wlv.col -= wlv.n_extra;
3236 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003237 }
3238 else
3239# endif
3240 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003241 wlv.boguscols += wlv.n_extra;
3242 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003243 }
3244 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003245 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003246 n_attr = 0;
3247 }
3248 else if (n_skip == 0)
3249 {
3250 is_concealing = TRUE;
3251 n_skip = 1;
3252 }
3253 mb_c = c;
3254 if (enc_utf8 && utf_char2len(c) > 1)
3255 {
3256 mb_utf8 = TRUE;
3257 u8cc[0] = 0;
3258 c = 0xc0;
3259 }
3260 else
3261 mb_utf8 = FALSE; // don't draw as UTF-8
3262 }
3263 else
3264 {
3265 prev_syntax_id = 0;
3266 is_concealing = FALSE;
3267 }
3268
3269 if (n_skip > 0 && did_decrement_ptr)
3270 // not showing the '>', put pointer back to avoid getting stuck
3271 ++ptr;
3272
3273#endif // FEAT_CONCEAL
3274 }
3275
3276#ifdef FEAT_CONCEAL
3277 // In the cursor line and we may be concealing characters: correct
3278 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003279 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003280 && wp == curwin && lnum == wp->w_cursor.lnum
3281 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003282 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003283 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003284# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003285 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003286 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003287 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003288# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003289 wp->w_wcol = wlv.col - wlv.boguscols;
3290 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003291 did_wcol = TRUE;
3292 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003293# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003294 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003295# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003296 }
3297#endif
3298
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003299 // Use "wlv.extra_attr", but don't override visual selection
3300 // highlighting, unless text property overrides.
3301 // Don't use "wlv.extra_attr" until n_attr_skip is zero.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003302 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003303 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003304 && (!attr_pri
3305#ifdef FEAT_PROP_POPUP
3306 || (text_prop_flags & PT_FLAG_OVERRIDE)
3307#endif
3308 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003309 {
3310#ifdef LINE_ATTR
3311 if (line_attr)
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003312 wlv.char_attr = hl_combine_attr(line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003313 else
3314#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003315 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003316 }
3317
3318#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3319 // XIM don't send preedit_start and preedit_end, but they send
3320 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3321 // im_is_preediting() here.
3322 if (p_imst == IM_ON_THE_SPOT
3323 && xic != NULL
3324 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003325 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003326 && !p_imdisable
3327 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003328 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003329 {
3330 colnr_T tcol;
3331
3332 if (preedit_end_col == MAXCOL)
3333 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3334 else
3335 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003336 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003337 {
3338 if (feedback_old_attr < 0)
3339 {
3340 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003341 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003342 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003343 wlv.char_attr = im_get_feedback_attr(feedback_col);
3344 if (wlv.char_attr < 0)
3345 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003346 feedback_col++;
3347 }
3348 else if (feedback_old_attr >= 0)
3349 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003350 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003351 feedback_old_attr = -1;
3352 feedback_col = 0;
3353 }
3354 }
3355#endif
3356 // Handle the case where we are in column 0 but not on the first
3357 // character of the line and the user wants us to show us a
3358 // special character (via 'listchars' option "precedes:<char>".
3359 if (lcs_prec_todo != NUL
3360 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003361 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3362 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003363#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003364 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003365#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003366 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003367 && c != NUL)
3368 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003369 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003370 lcs_prec_todo = NUL;
3371 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3372 {
3373 // Double-width character being overwritten by the "precedes"
3374 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003375 wlv.c_extra = MB_FILLER_CHAR;
3376 wlv.c_final = NUL;
3377 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003378 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003379 wlv.extra_attr =
3380 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003381 }
3382 mb_c = c;
3383 if (enc_utf8 && utf_char2len(c) > 1)
3384 {
3385 mb_utf8 = TRUE;
3386 u8cc[0] = 0;
3387 c = 0xc0;
3388 }
3389 else
3390 mb_utf8 = FALSE; // don't draw as UTF-8
3391 if (!attr_pri)
3392 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003393 saved_attr3 = wlv.char_attr; // save current attr
3394 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003395 n_attr3 = 1;
3396 }
3397 }
3398
3399 // At end of the text line or just after the last character.
3400 if ((c == NUL
3401#if defined(LINE_ATTR)
3402 || did_line_attr == 1
3403#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003404 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003405 {
3406#ifdef FEAT_SEARCH_EXTRA
3407 // flag to indicate whether prevcol equals startcol of search_hl or
3408 // one of the matches
3409 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3410 (long)(ptr - line) - (c == NUL));
3411#endif
3412 // Invert at least one char, used for Visual and empty line or
3413 // highlight match at end of line. If it's beyond the last
3414 // char on the screen, just overwrite that one (tricky!) Not
3415 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003416 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003417 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003418 && (VIsual_mode != Ctrl_V
3419 || lnum == VIsual.lnum
3420 || lnum == curwin->w_cursor.lnum)
3421 && c == NUL)
3422#ifdef FEAT_SEARCH_EXTRA
3423 // highlight 'hlsearch' match at end of line
3424 || (prevcol_hl_flag
3425# ifdef FEAT_SYN_HL
3426 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3427 && !(wp == curwin && VIsual_active))
3428# endif
3429# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003430 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003431# endif
3432# if defined(LINE_ATTR)
3433 && did_line_attr <= 1
3434# endif
3435 )
3436#endif
3437 ))
3438 {
3439 int n = 0;
3440
3441#ifdef FEAT_RIGHTLEFT
3442 if (wp->w_p_rl)
3443 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003444 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003445 n = 1;
3446 }
3447 else
3448#endif
3449 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003450 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003451 n = -1;
3452 }
3453 if (n != 0)
3454 {
3455 // At the window boundary, highlight the last character
3456 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003457 wlv.off += n;
3458 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003459 }
3460 else
3461 {
3462 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003463 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003464 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003465 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003466 }
3467#ifdef FEAT_SEARCH_EXTRA
3468 if (area_attr == 0)
3469 {
3470 // Use attributes from match with highest priority among
3471 // 'search_hl' and the match list.
3472 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003473 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003474 }
3475#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003476 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003477 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003478#ifdef FEAT_RIGHTLEFT
3479 if (wp->w_p_rl)
3480 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003481 --wlv.col;
3482 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003483 }
3484 else
3485#endif
3486 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003487 ++wlv.col;
3488 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003489 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003490 ++wlv.vcol;
3491 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003492 }
3493 }
3494
3495 // At end of the text line.
3496 if (c == NUL)
3497 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003498 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003499
3500 // Update w_cline_height and w_cline_folded if the cursor line was
3501 // updated (saves a call to plines() later).
3502 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3503 {
3504 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003505 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003506#ifdef FEAT_FOLDING
3507 curwin->w_cline_folded = FALSE;
3508#endif
3509 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3510 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003511 break;
3512 }
3513
3514 // Show "extends" character from 'listchars' if beyond the line end and
3515 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003516 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003517 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003518 && wp->w_p_list
3519 && !wp->w_p_wrap
3520#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003521 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003522#endif
3523 && (
3524#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003525 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003526#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003527 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003528 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003529 || lcs_eol_one > 0
3530 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003531 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003532 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003533 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003534 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003535 mb_c = c;
3536 if (enc_utf8 && utf_char2len(c) > 1)
3537 {
3538 mb_utf8 = TRUE;
3539 u8cc[0] = 0;
3540 c = 0xc0;
3541 }
3542 else
3543 mb_utf8 = FALSE;
3544 }
3545
3546#ifdef FEAT_SYN_HL
3547 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003548 if (wlv.draw_color_col)
3549 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003550
3551 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3552 // highlight the cursor position itself.
3553 // Also highlight the 'colorcolumn' if it is different than
3554 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003555 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3556 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003557 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003558 if (((wlv.draw_state == WL_LINE
3559 || wlv.draw_state == WL_BRI
3560 || wlv.draw_state == WL_SBR)
3561 && !lnum_in_visual_area
3562 && search_attr == 0
3563 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003564# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003565 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003566# endif
3567 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003568 {
3569 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3570 && lnum != wp->w_cursor.lnum)
3571 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003572 vcol_save_attr = wlv.char_attr;
3573 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3574 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003575 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003576 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003577 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003578 vcol_save_attr = wlv.char_attr;
3579 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003580 }
3581 }
3582#endif
3583
3584 // Store character to be displayed.
3585 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003586 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003587 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003588 {
3589 // Store the character.
3590#if defined(FEAT_RIGHTLEFT)
3591 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3592 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003593 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003594 --wlv.off;
3595 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003596 }
3597#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003598 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003599 if (enc_dbcs == DBCS_JPNU)
3600 {
3601 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003602 ScreenLines[wlv.off] = 0x8e;
3603 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003604 }
3605 else if (enc_utf8)
3606 {
3607 if (mb_utf8)
3608 {
3609 int i;
3610
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003611 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003612 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003613 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003614 for (i = 0; i < Screen_mco; ++i)
3615 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003616 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003617 if (u8cc[i] == 0)
3618 break;
3619 }
3620 }
3621 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003622 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003623 }
3624 if (multi_attr)
3625 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003626 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003627 multi_attr = 0;
3628 }
3629 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003630 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003631
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003632 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003633
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003634 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3635 {
3636 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003637 ++wlv.off;
3638 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003639 if (enc_utf8)
3640 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003641 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003642 else
3643 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003644 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003645 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003646#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003647 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003648#endif
3649 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003650 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003651 // When "wlv.tocol" is halfway a character, set it to the end
3652 // of the character, otherwise highlighting won't stop.
3653 if (wlv.tocol == wlv.vcol)
3654 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003655
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003656 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003657
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003658#ifdef FEAT_RIGHTLEFT
3659 if (wp->w_p_rl)
3660 {
3661 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003662 --wlv.off;
3663 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003664 }
3665#endif
3666 }
3667#ifdef FEAT_RIGHTLEFT
3668 if (wp->w_p_rl)
3669 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003670 --wlv.off;
3671 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003672 }
3673 else
3674#endif
3675 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003676 ++wlv.off;
3677 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003678 }
3679 }
3680#ifdef FEAT_CONCEAL
3681 else if (wp->w_p_cole > 0 && is_concealing)
3682 {
3683 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003684 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003685 if (wlv.n_extra > 0)
3686 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003687 if (wp->w_p_wrap)
3688 {
3689 // Special voodoo required if 'wrap' is on.
3690 //
3691 // Advance the column indicator to force the line
3692 // drawing to wrap early. This will make the line
3693 // take up the same screen space when parts are concealed,
3694 // so that cursor line computations aren't messed up.
3695 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003696 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003697 // trailing junk to be written out of the screen line
3698 // we are building, 'boguscols' keeps track of the number
3699 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003700 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003701 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003702 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003703# ifdef FEAT_RIGHTLEFT
3704 if (wp->w_p_rl)
3705 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003706 wlv.col -= wlv.n_extra;
3707 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003708 }
3709 else
3710# endif
3711 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003712 wlv.col += wlv.n_extra;
3713 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003714 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003715 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003716 n_attr = 0;
3717 }
3718
3719
3720 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3721 {
3722 // Need to fill two screen columns.
3723# ifdef FEAT_RIGHTLEFT
3724 if (wp->w_p_rl)
3725 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003726 --wlv.boguscols;
3727 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003728 }
3729 else
3730# endif
3731 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003732 ++wlv.boguscols;
3733 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003734 }
3735 }
3736
3737# ifdef FEAT_RIGHTLEFT
3738 if (wp->w_p_rl)
3739 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003740 --wlv.boguscols;
3741 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003742 }
3743 else
3744# endif
3745 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003746 ++wlv.boguscols;
3747 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003748 }
3749 }
3750 else
3751 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003752 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003753 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003754 wlv.vcol += wlv.n_extra;
3755 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003756 n_attr = 0;
3757 }
3758 }
3759
3760 }
3761#endif // FEAT_CONCEAL
3762 else
3763 --n_skip;
3764
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003765 // Only advance the "wlv.vcol" when after the 'number' or
3766 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003767 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003768#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003769 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003770#endif
3771 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003772 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003773
3774#ifdef FEAT_SYN_HL
3775 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003776 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003777#endif
3778
3779 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003780 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3781 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003782
3783 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003784 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003785 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003786 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003787 if (n_attr_skip > 0)
3788 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003789
3790 // At end of screen line and there is more to come: Display the line
3791 // so far. If there is no more to display it is caught above.
3792 if ((
3793#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003794 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003795#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003796 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003797 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003798 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003799#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003800 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003801#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003802#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003803 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003804#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003805 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003806 && wlv.p_extra != at_end_str)
3807 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3808 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003809 )
3810 {
3811#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003812 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003813 wlv_screen_line(wp, &wlv, FALSE);
3814 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003815 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003816#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003817 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003818#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003819 ++wlv.row;
3820 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003821
3822 // When not wrapping and finished diff lines, or when displayed
3823 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01003824 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003825#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003826 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003827#endif
3828#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01003829 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003830#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01003831 ) || lcs_eol_one == -1)
3832#ifdef FEAT_PROP_POPUP
3833 && !text_prop_follows
3834#endif
3835 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003836 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003837#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003838 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003839 {
3840 // do not output more of the line, only the "below" prop
3841 ptr += STRLEN(ptr);
3842# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003843 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003844# endif
3845 }
3846#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003847
3848 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003849 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003850#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003851 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003852#endif
3853 )
3854 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003855 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3856 draw_vsep_win(wp, wlv.row);
3857 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003858 }
3859
3860 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003861 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003862 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003863 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003864 break;
3865 }
3866
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003867 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003868#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003869 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003870#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003871#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003872 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003873#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003874 && wp->w_width == Columns)
3875 {
3876 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003877 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003878
3879 // Special trick to make copy/paste of wrapped lines work with
3880 // xterm/screen: write an extra character beyond the end of
3881 // the line. This will work with all terminal types
3882 // (regardless of the xn,am settings).
3883 // Only do this on a fast tty.
3884 // Only do this if the cursor is on the current line
3885 // (something has been written in it).
3886 // Don't do this for the GUI.
3887 // Don't do this for double-width characters.
3888 // Don't do this for a window not at the right screen border.
3889 if (p_tf
3890#ifdef FEAT_GUI
3891 && !gui.in_use
3892#endif
3893 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003894 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3895 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003896 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003897 || (*mb_off2cells)(
3898 LineOffset[wlv.screen_row - 1]
3899 + (int)Columns - 2,
3900 LineOffset[wlv.screen_row]
3901 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003902 {
3903 // First make sure we are at the end of the screen line,
3904 // then output the same character again to let the
3905 // terminal know about the wrap. If the terminal doesn't
3906 // auto-wrap, we overwrite the character.
3907 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003908 screen_char(LineOffset[wlv.screen_row - 1]
3909 + (unsigned)Columns - 1,
3910 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003911
3912 // When there is a multi-byte character, just output a
3913 // space to keep it simple.
3914 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003915 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003916 out_char(' ');
3917 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003918 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003919 + (Columns - 1)]);
3920 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003921 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003922 screen_start(); // don't know where cursor is now
3923 }
3924 }
3925
Bram Moolenaar1306b362022-08-06 15:59:06 +01003926 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003927
Bram Moolenaareed9d462021-02-15 20:38:25 +01003928 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003929#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003930 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003931# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003932 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003933# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003934 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003935 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003936#endif
3937#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003938 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003939 // When the filler lines are actually below the last line of the
3940 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003941 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003942 break;
3943#endif
3944 }
3945
3946 } // for every character in the line
3947
3948#ifdef FEAT_SPELL
3949 // After an empty line check first word for capital.
3950 if (*skipwhite(line) == NUL)
3951 {
3952 capcol_lnum = lnum + 1;
3953 cap_col = 0;
3954 }
3955#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003956#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003957 vim_free(text_props);
3958 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003959 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003960#endif
3961
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003962 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003963 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003964}