blob: 9aad81b9cccdb87f82d3b610828b5cce03688895 [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 Moolenaar1306b362022-08-06 15:59:06 +0100133 int c_extra; // extra chars, all the same
134 int c_final; // final char, mandatory if set
135
136 // saved "extra" items for when draw_state becomes WL_LINE (again)
137 int saved_n_extra;
138 char_u *saved_p_extra;
139 int saved_c_extra;
140 int saved_c_final;
141 int saved_char_attr;
142
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100143 char_u extra[NUMBUFLEN + MB_MAXBYTES];
144 // "%ld " and 'fdc' must fit in here, as well
145 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100146
Bram Moolenaar1306b362022-08-06 15:59:06 +0100147#ifdef FEAT_DIFF
148 hlf_T diff_hlf; // type of diff highlighting
149#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100150 int filler_lines; // nr of filler lines to be drawn
151 int filler_todo; // nr of filler lines still to do + 1
152#ifdef FEAT_SIGNS
153 sign_attrs_T sattr;
154#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100155} winlinevars_T;
156
157// draw_state values for items that are drawn in sequence:
158#define WL_START 0 // nothing done yet, must be zero
Martin Tournoij7904fa42022-10-04 16:28:45 +0100159#define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar1306b362022-08-06 15:59:06 +0100160#ifdef FEAT_FOLDING
161# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
162#else
163# define WL_FOLD WL_CMDLINE
164#endif
165#ifdef FEAT_SIGNS
166# define WL_SIGN (WL_FOLD + 1) // column for signs
167#else
168# define WL_SIGN WL_FOLD // column for signs
169#endif
170#define WL_NR (WL_SIGN + 1) // line number
171#ifdef FEAT_LINEBREAK
172# define WL_BRI (WL_NR + 1) // 'breakindent'
173#else
174# define WL_BRI WL_NR
175#endif
176#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
177# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
178#else
179# define WL_SBR WL_BRI
180#endif
181#define WL_LINE (WL_SBR + 1) // text in the line
182
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100183#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200184/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000185 * Return TRUE if CursorLineSign highlight is to be used.
186 */
187 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100188use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000189{
190 return wp->w_p_cul
191 && lnum == wp->w_cursor.lnum
192 && (wp->w_p_culopt_flags & CULOPT_NBR);
193}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100194#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000195
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100196
197#ifdef FEAT_FOLDING
198/*
199 * Setup for drawing the 'foldcolumn', if there is one.
200 */
201 static void
202handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
203{
204 int fdc = compute_foldcolumn(wp, 0);
205
206 if (fdc <= 0)
207 return;
208
209 // Allocate a buffer, "wlv->extra[]" may already be in use.
210 vim_free(wlv->p_extra_free);
211 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
212 if (wlv->p_extra_free != NULL)
213 {
214 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
215 wp, FALSE, wlv->lnum);
216 wlv->p_extra_free[wlv->n_extra] = NUL;
217 wlv->p_extra = wlv->p_extra_free;
218 wlv->c_extra = NUL;
219 wlv->c_final = NUL;
220 if (use_cursor_line_highlight(wp, wlv->lnum))
221 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
222 else
223 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
224 }
225}
226#endif
227
228#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000229/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100230 * Get information needed to display the sign in line "wlv->lnum" in window
231 * "wp".
232 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200233 * Otherwise the sign is going to be displayed in the sign column.
234 */
235 static void
236get_sign_display_info(
237 int nrcol,
238 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100239 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200240{
241 int text_sign;
242# ifdef FEAT_SIGN_ICONS
243 int icon_sign;
244# endif
245
246 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100247 wlv->c_extra = ' ';
248 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200249 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100250 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200251 else
252 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100253 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100254 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000255 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100256 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100257 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200258 }
259
Bram Moolenaar1306b362022-08-06 15:59:06 +0100260 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200261#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100262 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200263#endif
264 )
265 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100266 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200267# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100268 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200269 if (gui.in_use && icon_sign != 0)
270 {
271 // Use the image in this position.
272 if (nrcol)
273 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100274 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100275 sprintf((char *)wlv->extra, "%-*c ",
276 number_width(wp), SIGN_BYTE);
277 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100278 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200279 }
280 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100281 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200282# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100283 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
284 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200285 {
286 if (nrcol)
287 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100288 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100289 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200290 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100291 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100292 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200293 }
294 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100295 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200296 }
297# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100298 wlv->c_final = NUL;
299 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200300 }
301 else
302# endif
303 if (text_sign != 0)
304 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100305 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100306 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200307 {
308 if (nrcol)
309 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100310 int width = number_width(wp) - 2;
311 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200312
313 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100314 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100315 vim_snprintf((char *)wlv->extra + n,
316 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100317 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200318 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100319 wlv->c_extra = NUL;
320 wlv->c_final = NUL;
321 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200322 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000323
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100324 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100325 && wlv->sattr.sat_culhl > 0)
326 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000327 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100328 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200329 }
330 }
331}
332#endif
333
Bram Moolenaard7657e92022-09-20 18:59:30 +0100334/*
335 * Display the absolute or relative line number. After the first row fill with
336 * blanks when the 'n' flag isn't in 'cpo'.
337 */
338 static void
339handle_lnum_col(
340 win_T *wp,
341 winlinevars_T *wlv,
342 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100343 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100344{
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100345 int has_cpo_n = vim_strchr(p_cpo, CPO_NUMCOL) != NULL;
346
Bram Moolenaard7657e92022-09-20 18:59:30 +0100347 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100348 && (wlv->row == wlv->startrow + wlv->filler_lines || !has_cpo_n)
Bram Moolenaar37251162022-10-06 20:48:00 +0100349 // there is no line number in a wrapped line when "n" is in
350 // 'cpoptions', but 'breakindent' assumes it anyway.
351 && !((has_cpo_n
352#ifdef FEAT_LINEBREAK
353 && !wp->w_p_bri
354#endif
355 ) && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100356 {
357#ifdef FEAT_SIGNS
358 // If 'signcolumn' is set to 'number' and a sign is present
359 // in 'lnum', then display the sign instead of the line
360 // number.
361 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
362 get_sign_display_info(TRUE, wp, wlv);
363 else
364#endif
365 {
366 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100367 // When there are text properties above the line put the line number
368 // below them.
369 if (wlv->row == wlv->startrow + wlv->filler_lines
370#ifdef FEAT_PROP_POPUP
371 + wlv->text_prop_above_count
Bram Moolenaard7657e92022-09-20 18:59:30 +0100372#endif
Bram Moolenaar06618f92022-10-06 19:21:20 +0100373 && (wp->w_skipcol == 0 || wlv->row > wp->w_winrow))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100374 {
375 long num;
376 char *fmt = "%*ld ";
377
378 if (wp->w_p_nu && !wp->w_p_rnu)
379 // 'number' + 'norelativenumber'
380 num = (long)wlv->lnum;
381 else
382 {
383 // 'relativenumber', don't use negative numbers
384 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
385 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
386 {
387 // 'number' + 'relativenumber'
388 num = wlv->lnum;
389 fmt = "%-*ld ";
390 }
391 }
392
393 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100394 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100395 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
396 ++wlv->p_extra)
397 *wlv->p_extra = '-';
398#ifdef FEAT_RIGHTLEFT
399 if (wp->w_p_rl) // reverse line numbers
400 {
401 char_u *p1, *p2;
402 int t;
403
404 // like rl_mirror(), but keep the space at the end
405 p2 = skipwhite(wlv->extra);
406 p2 = skiptowhite(p2) - 1;
407 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
408 {
409 t = *p1;
410 *p1 = *p2;
411 *p2 = t;
412 }
413 }
414#endif
415 wlv->p_extra = wlv->extra;
416 wlv->c_extra = NUL;
417 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100418 }
419 else
420 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100421 wlv->c_extra = ' ';
422 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100423 }
424 wlv->n_extra = number_width(wp) + 1;
425 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
426#ifdef FEAT_SYN_HL
427 // When 'cursorline' is set highlight the line number of
428 // the current line differently.
429 // When 'cursorlineopt' does not have "line" only
430 // highlight the line number itself.
431 // TODO: Can we use CursorLine instead of CursorLineNr
432 // when CursorLineNr isn't set?
433 if (wp->w_p_cul
434 && wlv->lnum == wp->w_cursor.lnum
435 && (wp->w_p_culopt_flags & CULOPT_NBR)
436 && (wlv->row == wlv->startrow + wlv->filler_lines
437 || (wlv->row > wlv->startrow + wlv->filler_lines
438 && (wp->w_p_culopt_flags & CULOPT_LINE))))
439 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
440#endif
441 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
442 && HL_ATTR(HLF_LNA) != 0)
443 // Use LineNrAbove
444 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
445 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
446 && HL_ATTR(HLF_LNB) != 0)
447 // Use LineNrBelow
448 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
449 }
450#ifdef FEAT_SIGNS
451 if (num_attr)
452 wlv->char_attr = num_attr;
453#endif
454 }
455}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100456
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100457#ifdef FEAT_LINEBREAK
458 static void
459handle_breakindent(win_T *wp, winlinevars_T *wlv)
460{
461 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
462 && *get_showbreak_value(wp) != NUL)
463 // draw indent after showbreak value
464 wlv->draw_state = WL_BRI;
465 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
466 // After the showbreak, draw the breakindent
467 wlv->draw_state = WL_BRI - 1;
468
469 // draw 'breakindent': indent wrapped text accordingly
470 if (wlv->draw_state == WL_BRI - 1)
471 {
472 wlv->draw_state = WL_BRI;
473 // if wlv->need_showbreak is set, breakindent also applies
474 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
475# ifdef FEAT_DIFF
476 && wlv->filler_lines == 0
477# endif
478# ifdef FEAT_PROP_POPUP
479 && !wlv->dont_use_showbreak
480# endif
481 )
482 {
483 wlv->char_attr = 0;
484# ifdef FEAT_DIFF
485 if (wlv->diff_hlf != (hlf_T)0)
486 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
487# endif
488 wlv->p_extra = NULL;
489 wlv->c_extra = ' ';
490 wlv->c_final = NUL;
491 wlv->n_extra = get_breakindent_win(wp,
492 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
493 if (wlv->row == wlv->startrow)
494 {
495 wlv->n_extra -= win_col_off2(wp);
496 if (wlv->n_extra < 0)
497 wlv->n_extra = 0;
498 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100499 if (wp->w_skipcol > 0 && wlv->startrow == 0
500 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100501 wlv->need_showbreak = FALSE;
502 // Correct end of highlighted area for 'breakindent',
503 // required when 'linebreak' is also set.
504 if (wlv->tocol == wlv->vcol)
505 wlv->tocol += wlv->n_extra;
506 }
507 }
508}
509#endif
510
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100511#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
512 static void
513handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
514{
515# ifdef FEAT_DIFF
516 if (wlv->filler_todo > 0)
517 {
518 // Draw "deleted" diff line(s).
519 if (char2cells(wp->w_fill_chars.diff) > 1)
520 {
521 wlv->c_extra = '-';
522 wlv->c_final = NUL;
523 }
524 else
525 {
526 wlv->c_extra = wp->w_fill_chars.diff;
527 wlv->c_final = NUL;
528 }
529# ifdef FEAT_RIGHTLEFT
530 if (wp->w_p_rl)
531 wlv->n_extra = wlv->col + 1;
532 else
533# endif
534 wlv->n_extra = wp->w_width - wlv->col;
535 wlv->char_attr = HL_ATTR(HLF_DED);
536 }
537# endif
538
539# ifdef FEAT_LINEBREAK
540 char_u *sbr = get_showbreak_value(wp);
541 if (*sbr != NUL && wlv->need_showbreak)
542 {
543 // Draw 'showbreak' at the start of each broken line.
544 wlv->p_extra = sbr;
545 wlv->c_extra = NUL;
546 wlv->c_final = NUL;
547 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100548 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100549 wlv->need_showbreak = FALSE;
550 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
551 // Correct end of highlighted area for 'showbreak',
552 // required when 'linebreak' is also set.
553 if (wlv->tocol == wlv->vcol)
554 wlv->tocol += wlv->n_extra;
555 // combine 'showbreak' with 'wincolor'
556 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
557# ifdef FEAT_SYN_HL
558 // combine 'showbreak' with 'cursorline'
559 if (wlv->cul_attr != 0)
560 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
561# endif
562 }
563# endif
564}
565#endif
566
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100567#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100568/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100569 * Return the cell size of virtual text after truncation.
570 */
571 static int
572textprop_size_after_trunc(
573 win_T *wp,
574 int flags, // TP_FLAG_ALIGN_*
575 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100576 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100577 char_u *text,
578 int *n_used_ptr)
579{
580 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100581 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100582 int len = (int)STRLEN(text);
583 int strsize = 0;
584 int n_used;
585
586 // if the remaining size is to small wrap anyway and use the next line
587 if (space < PROP_TEXT_MIN_CELLS)
588 space += wp->w_width;
Bram Moolenaar13845c42022-10-09 15:26:03 +0100589 if (flags & TP_FLAG_ALIGN_BELOW)
590 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100591 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
592 {
593 int clen = ptr2cells(text + n_used);
594
595 if (strsize + clen > space)
596 break;
597 strsize += clen;
598 }
599 *n_used_ptr = n_used;
600 return strsize;
601}
602
603/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100604 * Take care of padding, right-align and truncation of virtual text after a
605 * line.
606 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
607 * padding, right-align and truncation. Otherwise only the size is computed.
608 * When "n_attr" is NULL returns the number of screen cells used.
609 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100610 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100611 int
612text_prop_position(
613 win_T *wp,
614 textprop_T *tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100615 int vcol UNUSED, // current text column
616 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100617 int *n_extra, // nr of bytes for virtual text
618 char_u **p_extra, // virtual text
619 int *n_attr, // attribute cells, NULL if not used
620 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200621{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100622 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100623 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100624 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
625 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
626 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
627 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100628 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100629 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100630 int before = room; // spaces before the text
631 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100632 int n_used = *n_extra;
633 char_u *l = NULL;
634 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100635 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100636 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar1206c162022-10-10 15:40:04 +0100637 int cont_on_next_line = below && col_with_padding > win_col_off(wp)
638 && !wp->w_p_wrap;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200639
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100640 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100641 {
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100642 int col_off = win_col_off(wp) + win_col_off2(wp);
643 int skip_add = 0;
644
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100645 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100646 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100647 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100648 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100649 }
650 else
651 {
652 // Right-align: fill with before
653 if (right)
654 before -= cells;
655 if (before < 0
656 || !(right || below)
657 || (below
658 ? (col_with_padding == 0 || !wp->w_p_wrap)
659 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100660 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100661 if (right && (wrap || room < PROP_TEXT_MIN_CELLS))
662 {
663 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100664 before = wp->w_width - col_off - strsize + room;
665 if (before < 0)
666 before = 0;
667 else
668 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100669 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100670 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100671 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100672 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100673 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100674 else if (below && before > 0)
675 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100676 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100677 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100678
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100679 // With 'nowrap' add one to show the "extends" character if needed (it
680 // doesn't show if the text just fits).
681 if (!wp->w_p_wrap
682 && n_used < *n_extra
683 && wp->w_lcs_chars.ext != NUL
684 && wp->w_p_list)
685 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100686 if (!wp->w_p_wrap && below && padding > 0)
687 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100688
689 // add 1 for NUL, 2 for when '…' is used
690 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100691 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100692 if (n_attr == NULL || l != NULL)
693 {
694 int off = 0;
695
696 if (n_attr != NULL)
697 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100698 vim_memset(l, ' ', before);
699 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100700 if (padding > 0)
701 {
702 vim_memset(l + off, ' ', padding);
703 off += padding;
704 }
705 vim_strncpy(l + off, *p_extra, n_used);
706 off += n_used;
707 }
708 else
709 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100710 off = before + after + padding + n_used;
711 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100712 }
713 if (n_attr != NULL)
714 {
715 if (n_used < *n_extra && wp->w_p_wrap)
716 {
717 char_u *lp = l + off - 1;
718
719 if (has_mbyte)
720 {
721 // change last character to '…'
722 lp -= (*mb_head_off)(l, lp);
723 STRCPY(lp, "…");
Bram Moolenaar13845c42022-10-09 15:26:03 +0100724 n_used = lp - l + 3 - before - padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100725 }
726 else
727 // change last character to '>'
728 *lp = '>';
729 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100730 else if (after > 0)
731 {
732 vim_memset(l + off, ' ', after);
733 l[off + after] = NUL;
734 }
735
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100736 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100737 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100738 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100739 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100740 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100741
742 // Add "skip_add" when starting a new line or wrapping,
743 // n_attr_skip will then be decremented in the number column.
744 *n_attr_skip = before + padding
745 + (cont_on_next_line || before > 0 ? skip_add : 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100746 }
747 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100748 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100749
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100750 if (n_attr == NULL)
751 return cells;
752 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200753}
754#endif
755
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100756/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100757 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100758 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
759 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100760 */
761 static void
762wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
763{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100764 if (wlv->row == 0 && wp->w_skipcol > 0
765#if defined(FEAT_LINEBREAK)
766 && *get_showbreak_value(wp) == NUL
767#endif
768 )
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100769 {
770 int off = (int)(current_ScreenLine - ScreenLines);
771
772 for (int i = 0; i < 3; ++i)
773 {
774 ScreenLines[off] = '<';
775 if (enc_utf8)
776 ScreenLinesUC[off] = 0;
777 ScreenAttrs[off] = HL_ATTR(HLF_AT);
778 ++off;
779 }
780 }
781
782 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
783 negative_width ? -wp->w_width : wp->w_width,
784 wlv->screen_line_flags);
785}
786
787/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100788 * Called when finished with the line: draw the screen line and handle any
789 * highlighting until the right of the window.
790 */
791 static void
792draw_screen_line(win_T *wp, winlinevars_T *wlv)
793{
794#ifdef FEAT_SYN_HL
795 long v;
796
797 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
798 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100799 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100800 else
801 v = wp->w_leftcol;
802
803 // check if line ends before left margin
804 if (wlv->vcol < v + wlv->col - win_col_off(wp))
805 wlv->vcol = v + wlv->col - win_col_off(wp);
806# ifdef FEAT_CONCEAL
807 // Get rid of the boguscols now, we want to draw until the right
808 // edge for 'cursorcolumn'.
809 wlv->col -= wlv->boguscols;
810 wlv->boguscols = 0;
811# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
812# else
813# define VCOL_HLC (wlv->vcol)
814# endif
815
816 if (wlv->draw_color_col)
817 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
818
819 if (((wp->w_p_cuc
820 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
821 && (int)wp->w_virtcol <
822 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
823 && wlv->lnum != wp->w_cursor.lnum)
824 || wlv->draw_color_col
825 || wlv->win_attr != 0)
826# ifdef FEAT_RIGHTLEFT
827 && !wp->w_p_rl
828# endif
829 )
830 {
831 int rightmost_vcol = 0;
832 int i;
833
834 if (wp->w_p_cuc)
835 rightmost_vcol = wp->w_virtcol;
836 if (wlv->draw_color_col)
837 // determine rightmost colorcolumn to possibly draw
838 for (i = 0; wlv->color_cols[i] >= 0; ++i)
839 if (rightmost_vcol < wlv->color_cols[i])
840 rightmost_vcol = wlv->color_cols[i];
841
842 while (wlv->col < wp->w_width)
843 {
844 ScreenLines[wlv->off] = ' ';
845 if (enc_utf8)
846 ScreenLinesUC[wlv->off] = 0;
847 ScreenCols[wlv->off] = MAXCOL;
848 ++wlv->col;
849 if (wlv->draw_color_col)
850 wlv->draw_color_col = advance_color_col(
851 VCOL_HLC, &wlv->color_cols);
852
853 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
854 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
855 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
856 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
857 else
858 ScreenAttrs[wlv->off++] = wlv->win_attr;
859
860 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
861 break;
862
863 ++wlv->vcol;
864 }
865 }
866#endif
867
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100868 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100869 ++wlv->row;
870 ++wlv->screen_row;
871}
872#undef VCOL_HLC
873
874/*
875 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100876 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100877 */
878 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100879win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100880{
881 wlv->col = 0;
882 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
883
884#ifdef FEAT_RIGHTLEFT
885 if (wp->w_p_rl)
886 {
887 // Rightleft window: process the text in the normal direction, but put
888 // it in current_ScreenLine[] from right to left. Start at the
889 // rightmost column of the window.
890 wlv->col = wp->w_width - 1;
891 wlv->off += wlv->col;
892 wlv->screen_line_flags |= SLF_RIGHTLEFT;
893 }
894#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100895 if (save_extra)
896 {
897 // reset the drawing state for the start of a wrapped line
898 wlv->draw_state = WL_START;
899 wlv->saved_n_extra = wlv->n_extra;
900 wlv->saved_p_extra = wlv->p_extra;
901 wlv->saved_c_extra = wlv->c_extra;
902 wlv->saved_c_final = wlv->c_final;
903#ifdef FEAT_SYN_HL
904 if (!(wlv->cul_screenline
905# ifdef FEAT_DIFF
906 && wlv->diff_hlf == (hlf_T)0
907# endif
908 ))
909 wlv->saved_char_attr = wlv->char_attr;
910 else
911#endif
912 wlv->saved_char_attr = 0;
913 wlv->n_extra = 0;
914 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100915}
916
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200917/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100918 * Called when wlv->draw_state is set to WL_LINE.
919 */
920 static void
921win_line_continue(winlinevars_T *wlv)
922{
923 if (wlv->saved_n_extra > 0)
924 {
925 // Continue item from end of wrapped line.
926 wlv->n_extra = wlv->saved_n_extra;
927 wlv->c_extra = wlv->saved_c_extra;
928 wlv->c_final = wlv->saved_c_final;
929 wlv->p_extra = wlv->saved_p_extra;
930 wlv->char_attr = wlv->saved_char_attr;
931 }
932 else
933 wlv->char_attr = wlv->win_attr;
934}
935
936/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200937 * Display line "lnum" of window 'wp' on the screen.
938 * Start at row "startrow", stop when "endrow" is reached.
939 * wp->w_virtcol needs to be valid.
940 *
941 * Return the number of last row the line occupies.
942 */
943 int
944win_line(
945 win_T *wp,
946 linenr_T lnum,
947 int startrow,
948 int endrow,
949 int nochange UNUSED, // not updating for changed text
950 int number_only) // only update the number column
951{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100952 winlinevars_T wlv; // variables passed between functions
953
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200954 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100955 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200956 char_u *line; // current line
957 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200958
Bram Moolenaar1306b362022-08-06 15:59:06 +0100959#ifdef FEAT_PROP_POPUP
960 char_u *p_extra_free2 = NULL; // another p_extra to be freed
961#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200962 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000963#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000964 int in_linebreak = FALSE; // n_extra set for showing linebreak
965#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200966 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100967 // displaying eol at end-of-line
968 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000969 int lcs_prec_todo = wp->w_lcs_chars.prec;
970 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200971
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100972 int n_attr = 0; // chars with special attr
973 int n_attr_skip = 0; // chars to skip before using extra_attr
974 int saved_attr2 = 0; // char_attr saved for n_attr
975 int n_attr3 = 0; // chars with overruling special attr
976 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200977
978 int n_skip = 0; // nr of chars to skip for 'nowrap'
979
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200980 int fromcol_prev = -2; // start of inverting after cursor
981 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200982 int lnum_in_visual_area = FALSE;
983 pos_T pos;
984 long v;
985
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200986 int attr_pri = FALSE; // char_attr has priority
987 int area_highlighting = FALSE; // Visual or incsearch highlighting
988 // in this line
989 int vi_attr = 0; // attributes for Visual and incsearch
990 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200991 int area_attr = 0; // attributes desired by highlighting
992 int search_attr = 0; // attributes desired by 'hlsearch'
993#ifdef FEAT_SYN_HL
994 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
995 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200996 int prev_syntax_col = -1; // column of prev_syntax_attr
997 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200998 int has_syntax = FALSE; // this buffer has syntax highl.
999 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001000#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001001#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001002 int text_prop_count;
1003 int text_prop_next = 0; // next text property to use
1004 textprop_T *text_props = NULL;
1005 int *text_prop_idxs = NULL;
1006 int text_props_active = 0;
1007 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001008 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001009 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001010 int text_prop_attr_comb = 0; // text_prop_attr combined with
1011 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001012 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001013 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001014 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001015 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001016 int saved_search_attr = 0; // search_attr to be used when n_extra
1017 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001018 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001019#endif
1020#ifdef FEAT_SPELL
1021 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001022 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001023# define SPWORDLEN 150
1024 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1025 int nextlinecol = 0; // column where nextline[] starts
1026 int nextline_idx = 0; // index in nextline[] where next line
1027 // starts
1028 int spell_attr = 0; // attributes desired by spelling
1029 int word_end = 0; // last byte with same spell_attr
1030 static linenr_T checked_lnum = 0; // line number for "checked_col"
1031 static int checked_col = 0; // column in "checked_lnum" up to which
1032 // there are no spell errors
1033 static int cap_col = -1; // column to check for Cap word
1034 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1035 int cur_checked_col = 0; // checked column for current line
1036#endif
1037 int extra_check = 0; // has extra highlighting
1038 int multi_attr = 0; // attributes desired by multibyte
1039 int mb_l = 1; // multi-byte byte length
1040 int mb_c = 0; // decoded multi-byte character
1041 int mb_utf8 = FALSE; // screen char is UTF-8 char
1042 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001043#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001044 int change_start = MAXCOL; // first col of changed area
1045 int change_end = -1; // last col of changed area
1046#endif
1047 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001048 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001049 int in_multispace = FALSE; // in multiple consecutive spaces
1050 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001051#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
1052 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
1053# define LINE_ATTR
1054 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +01001055 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001056#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001057 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001058 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001059#ifdef FEAT_ARABIC
1060 int prev_c = 0; // previous Arabic character
1061 int prev_c1 = 0; // first composing char for prev_c
1062#endif
1063#if defined(LINE_ATTR)
1064 int did_line_attr = 0;
1065#endif
1066#ifdef FEAT_TERMINAL
1067 int get_term_attr = FALSE;
1068#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001069
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001070#ifdef FEAT_SYN_HL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001071 // margin columns for the screen line, needed for when 'cursorlineopt'
1072 // contains "screenline"
1073 int left_curline_col = 0;
1074 int right_curline_col = 0;
1075#endif
1076
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001077#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1078 int feedback_col = 0;
1079 int feedback_old_attr = -1;
1080#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001081
1082#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1083 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001084 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001085#endif
1086#ifdef FEAT_CONCEAL
1087 int syntax_flags = 0;
1088 int syntax_seqnr = 0;
1089 int prev_syntax_id = 0;
1090 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1091 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001092 int did_wcol = FALSE;
1093 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001094# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001095# define FIX_FOR_BOGUSCOLS \
1096 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001097 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001098 wlv.vcol -= wlv.vcol_off; \
1099 wlv.vcol_off = 0; \
1100 wlv.col -= wlv.boguscols; \
1101 old_boguscols = wlv.boguscols; \
1102 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001103 }
1104#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001105# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001106#endif
1107
1108 if (startrow > endrow) // past the end already!
1109 return startrow;
1110
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001111 CLEAR_FIELD(wlv);
1112
1113 wlv.lnum = lnum;
1114 wlv.startrow = startrow;
1115 wlv.row = startrow;
1116 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001117 wlv.fromcol = -10;
1118 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001119#ifdef FEAT_LINEBREAK
1120 wlv.vcol_sbr = -1;
1121#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001122
1123 if (!number_only)
1124 {
1125 // To speed up the loop below, set extra_check when there is linebreak,
1126 // trailing white space and/or syntax processing to be done.
1127#ifdef FEAT_LINEBREAK
1128 extra_check = wp->w_p_lbr;
1129#endif
1130#ifdef FEAT_SYN_HL
1131 if (syntax_present(wp) && !wp->w_s->b_syn_error
1132# ifdef SYN_TIME_LIMIT
1133 && !wp->w_s->b_syn_slow
1134# endif
1135 )
1136 {
1137 // Prepare for syntax highlighting in this line. When there is an
1138 // error, stop syntax highlighting.
1139 save_did_emsg = did_emsg;
1140 did_emsg = FALSE;
1141 syntax_start(wp, lnum);
1142 if (did_emsg)
1143 wp->w_s->b_syn_error = TRUE;
1144 else
1145 {
1146 did_emsg = save_did_emsg;
1147#ifdef SYN_TIME_LIMIT
1148 if (!wp->w_s->b_syn_slow)
1149#endif
1150 {
1151 has_syntax = TRUE;
1152 extra_check = TRUE;
1153 }
1154 }
1155 }
1156
1157 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001158 wlv.color_cols = wp->w_p_cc_cols;
1159 if (wlv.color_cols != NULL)
1160 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001161#endif
1162
1163#ifdef FEAT_TERMINAL
1164 if (term_show_buffer(wp->w_buffer))
1165 {
1166 extra_check = TRUE;
1167 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001168 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001169 }
1170#endif
1171
1172#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001173 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001174 {
1175 // Prepare for spell checking.
1176 has_spell = TRUE;
1177 extra_check = TRUE;
1178
1179 // Get the start of the next line, so that words that wrap to the
1180 // next line are found too: "et<line-break>al.".
1181 // Trick: skip a few chars for C/shell/Vim comments
1182 nextline[SPWORDLEN] = NUL;
1183 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1184 {
1185 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1186 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1187 }
1188
1189 // When a word wrapped from the previous line the start of the
1190 // current line is valid.
1191 if (lnum == checked_lnum)
1192 cur_checked_col = checked_col;
1193 checked_lnum = 0;
1194
1195 // When there was a sentence end in the previous line may require a
1196 // word starting with capital in this line. In line 1 always check
1197 // the first word.
1198 if (lnum != capcol_lnum)
1199 cap_col = -1;
1200 if (lnum == 1)
1201 cap_col = 0;
1202 capcol_lnum = 0;
1203 }
1204#endif
1205
1206 // handle Visual active in this window
1207 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1208 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001209 pos_T *top, *bot;
1210
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001211 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1212 {
1213 // Visual is after curwin->w_cursor
1214 top = &curwin->w_cursor;
1215 bot = &VIsual;
1216 }
1217 else
1218 {
1219 // Visual is before curwin->w_cursor
1220 top = &VIsual;
1221 bot = &curwin->w_cursor;
1222 }
1223 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1224 if (VIsual_mode == Ctrl_V)
1225 {
1226 // block mode
1227 if (lnum_in_visual_area)
1228 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001229 wlv.fromcol = wp->w_old_cursor_fcol;
1230 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001231 }
1232 }
1233 else
1234 {
1235 // non-block mode
1236 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001237 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001238 else if (lnum == top->lnum)
1239 {
1240 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001241 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001242 else
1243 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001244 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001245 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001246 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001247 }
1248 }
1249 if (VIsual_mode != 'V' && lnum == bot->lnum)
1250 {
1251 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1252 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001253 wlv.fromcol = -10;
1254 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001255 }
1256 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001257 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001258 else
1259 {
1260 pos = *bot;
1261 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001262 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1263 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001264 else
1265 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001266 getvvcol(wp, &pos, NULL, NULL,
1267 (colnr_T *)&wlv.tocol);
1268 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001269 }
1270 }
1271 }
1272 }
1273
1274 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001275 if (!highlight_match && lnum == curwin->w_cursor.lnum
1276 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001277#ifdef FEAT_GUI
1278 && !gui.in_use
1279#endif
1280 )
1281 noinvcur = TRUE;
1282
1283 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001284 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001285 {
1286 area_highlighting = TRUE;
1287 vi_attr = HL_ATTR(HLF_V);
1288#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1289 if ((clip_star.available && !clip_star.owned
1290 && clip_isautosel_star())
1291 || (clip_plus.available && !clip_plus.owned
1292 && clip_isautosel_plus()))
1293 vi_attr = HL_ATTR(HLF_VNC);
1294#endif
1295 }
1296 }
1297
1298 // handle 'incsearch' and ":s///c" highlighting
1299 else if (highlight_match
1300 && wp == curwin
1301 && lnum >= curwin->w_cursor.lnum
1302 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1303 {
1304 if (lnum == curwin->w_cursor.lnum)
1305 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001306 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001307 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001308 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001309 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1310 {
1311 pos.lnum = lnum;
1312 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001313 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001314 }
1315 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001316 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001317 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001318 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1319 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001320 area_highlighting = TRUE;
1321 vi_attr = HL_ATTR(HLF_I);
1322 }
1323 }
1324
1325#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001326 wlv.filler_lines = diff_check(wp, lnum);
1327 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001328 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001329 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001330 {
1331 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001332 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001333 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001334 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001335 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001336 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001337 }
1338 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001339 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001340 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001341 area_highlighting = TRUE;
1342 }
1343 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001344 wlv.filler_lines = wp->w_topfill;
1345 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001346#endif
1347
1348#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001349 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001350 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001351 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001352#endif
1353
1354#ifdef LINE_ATTR
1355# ifdef FEAT_SIGNS
1356 // If this line has a sign with line highlighting set line_attr.
1357 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001358 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001359# endif
1360# if defined(FEAT_QUICKFIX)
1361 // Highlight the current line in the quickfix window.
1362 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1363 line_attr = HL_ATTR(HLF_QFL);
1364# endif
1365 if (line_attr != 0)
1366 area_highlighting = TRUE;
1367#endif
1368
1369 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1370 ptr = line;
1371
1372#ifdef FEAT_SPELL
1373 if (has_spell && !number_only)
1374 {
1375 // For checking first word with a capital skip white space.
1376 if (cap_col == 0)
1377 cap_col = getwhitecols(line);
1378
1379 // To be able to spell-check over line boundaries copy the end of the
1380 // current line into nextline[]. Above the start of the next line was
1381 // copied to nextline[SPWORDLEN].
1382 if (nextline[SPWORDLEN] == NUL)
1383 {
1384 // No next line or it is empty.
1385 nextlinecol = MAXCOL;
1386 nextline_idx = 0;
1387 }
1388 else
1389 {
1390 v = (long)STRLEN(line);
1391 if (v < SPWORDLEN)
1392 {
1393 // Short line, use it completely and append the start of the
1394 // next line.
1395 nextlinecol = 0;
1396 mch_memmove(nextline, line, (size_t)v);
1397 STRMOVE(nextline + v, nextline + SPWORDLEN);
1398 nextline_idx = v + 1;
1399 }
1400 else
1401 {
1402 // Long line, use only the last SPWORDLEN bytes.
1403 nextlinecol = v - SPWORDLEN;
1404 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1405 nextline_idx = SPWORDLEN + 1;
1406 }
1407 }
1408 }
1409#endif
1410
1411 if (wp->w_p_list)
1412 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001413 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001414 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001415 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001416 || wp->w_lcs_chars.trail
1417 || wp->w_lcs_chars.lead
1418 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001419 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001420
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001421 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001422 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001423 {
1424 trailcol = (colnr_T)STRLEN(ptr);
1425 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1426 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001427 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001428 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001429 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001430 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001431 {
1432 leadcol = 0;
1433 while (VIM_ISWHITE(ptr[leadcol]))
1434 ++leadcol;
1435 if (ptr[leadcol] == NUL)
1436 // in a line full of spaces all of them are treated as trailing
1437 leadcol = (colnr_T)0;
1438 else
1439 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001440 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001441 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001442 }
1443
Bram Moolenaard7657e92022-09-20 18:59:30 +01001444 wlv.wcr_attr = get_wcr_attr(wp);
1445 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001446 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001447 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001448 area_highlighting = TRUE;
1449 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001450
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001451#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001452 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001453 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001454#endif
1455
1456 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1457 // first character to be displayed.
1458 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001459 v = startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001460 else
1461 v = wp->w_leftcol;
1462 if (v > 0 && !number_only)
1463 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001464 char_u *prev_ptr = ptr;
1465 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001466 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001467
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001468 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001469 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001470 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001471 charsize = win_lbr_chartabsize(&cts, NULL);
1472 cts.cts_vcol += charsize;
1473 prev_ptr = cts.cts_ptr;
1474 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001475 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001476 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001477 ptr = cts.cts_ptr;
1478 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001479
1480 // When:
1481 // - 'cuc' is set, or
1482 // - 'colorcolumn' is set, or
1483 // - 'virtualedit' is set, or
1484 // - the visual mode is active,
1485 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001486 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001487#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001488 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001489#endif
1490 virtual_active() ||
1491 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001492 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001493
1494 // Handle a character that's not completely on the screen: Put ptr at
1495 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001496 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001497 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001498 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001499 ptr = prev_ptr;
1500 // If the character fits on the screen, don't need to skip it.
1501 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001502 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1503 && wlv.col == 0)
1504 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001505 }
1506
1507 // Adjust for when the inverted text is before the screen,
1508 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001509 if (wlv.tocol <= wlv.vcol)
1510 wlv.fromcol = 0;
1511 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1512 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001513
1514#ifdef FEAT_LINEBREAK
1515 // When w_skipcol is non-zero, first line needs 'showbreak'
1516 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001517 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001518#endif
1519#ifdef FEAT_SPELL
1520 // When spell checking a word we need to figure out the start of the
1521 // word and if it's badly spelled or not.
1522 if (has_spell)
1523 {
1524 int len;
1525 colnr_T linecol = (colnr_T)(ptr - line);
1526 hlf_T spell_hlf = HLF_COUNT;
1527
1528 pos = wp->w_cursor;
1529 wp->w_cursor.lnum = lnum;
1530 wp->w_cursor.col = linecol;
1531 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1532
1533 // spell_move_to() may call ml_get() and make "line" invalid
1534 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1535 ptr = line + linecol;
1536
1537 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1538 {
1539 // no bad word found at line start, don't check until end of a
1540 // word
1541 spell_hlf = HLF_COUNT;
1542 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1543 }
1544 else
1545 {
1546 // bad word found, use attributes until end of word
1547 word_end = wp->w_cursor.col + len + 1;
1548
1549 // Turn index into actual attributes.
1550 if (spell_hlf != HLF_COUNT)
1551 spell_attr = highlight_attr[spell_hlf];
1552 }
1553 wp->w_cursor = pos;
1554
1555# ifdef FEAT_SYN_HL
1556 // Need to restart syntax highlighting for this line.
1557 if (has_syntax)
1558 syntax_start(wp, lnum);
1559# endif
1560 }
1561#endif
1562 }
1563
1564 // Correct highlighting for cursor that can't be disabled.
1565 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001566 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001567 {
1568 if (noinvcur)
1569 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001570 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001571 {
1572 // highlighting starts at cursor, let it start just after the
1573 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001574 fromcol_prev = wlv.fromcol;
1575 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001576 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001577 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001578 // restart highlighting after the cursor
1579 fromcol_prev = wp->w_virtcol;
1580 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001581 if (wlv.fromcol >= wlv.tocol)
1582 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001583 }
1584
1585#ifdef FEAT_SEARCH_EXTRA
1586 if (!number_only)
1587 {
1588 v = (long)(ptr - line);
1589 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1590 &line, &screen_search_hl,
1591 &search_attr);
1592 ptr = line + v; // "line" may have been updated
1593 }
1594#endif
1595
1596#ifdef FEAT_SYN_HL
1597 // Cursor line highlighting for 'cursorline' in the current window.
1598 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1599 {
1600 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001601 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001602 if (!(wp == curwin && VIsual_active)
1603 && wp->w_p_culopt_flags != CULOPT_NBR)
1604 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001605 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001606 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1607
1608 // Only set line_attr here when "screenline" is not present in
1609 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001610 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001611 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001612 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001613# ifdef FEAT_SIGNS
1614 // Combine the 'cursorline' and sign highlighting, depending on
1615 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001616 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001617 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001618 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001619 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001620 else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001621 line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001622 }
1623 else
1624# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001625# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001626 // let the line attribute overrule 'cursorline', otherwise
1627 // it disappears when both have background set;
1628 // 'cursorline' can use underline or bold to make it show
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001629 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001630# else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001631 line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001632# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001633 }
1634 else
1635 {
1636 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001637 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1638 }
1639 area_highlighting = TRUE;
1640 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001641 }
1642#endif
1643
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001644#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001645 {
1646 char_u *prop_start;
1647
1648 text_prop_count = get_text_props(wp->w_buffer, lnum,
1649 &prop_start, FALSE);
1650 if (text_prop_count > 0)
1651 {
1652 // Make a copy of the properties, so that they are properly
1653 // aligned.
1654 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1655 if (text_props != NULL)
1656 mch_memmove(text_props, prop_start,
1657 text_prop_count * sizeof(textprop_T));
1658
1659 // Allocate an array for the indexes.
1660 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001661 if (text_prop_idxs == NULL)
1662 VIM_CLEAR(text_props);
1663
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001664 if (text_props != NULL)
1665 {
1666 area_highlighting = TRUE;
1667 extra_check = TRUE;
1668 for (int i = 0; i < text_prop_count; ++i)
1669 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1670 ++wlv.text_prop_above_count;
1671 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001672 }
1673 }
1674#endif
1675
Bram Moolenaar1306b362022-08-06 15:59:06 +01001676 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001677
1678 // Repeat for the whole displayed line.
1679 for (;;)
1680 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001681 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001682#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001683 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001684#endif
1685#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001686 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001687#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001688
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001689 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001690 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001691 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001692#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001693 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001694 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001695 wlv.cul_attr = 0;
zeertzjq4f33bc22021-08-05 17:57:02 +02001696 line_attr = line_attr_save;
1697 }
1698#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001699 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001700 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001701 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001702 if (cmdwin_type != 0 && wp == curwin)
1703 {
1704 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001705 wlv.n_extra = 1;
1706 wlv.c_extra = cmdwin_type;
1707 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001708 wlv.char_attr =
1709 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001710 }
1711 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001712#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001713 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001714 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001715 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001716 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001717 }
1718#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001719#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001720 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001721 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001722 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001723 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001724 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001725 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001726 }
1727#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001728 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001729 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001730 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001731 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001732 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001733 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001734#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001735 // Check if 'breakindent' applies and show it.
1736 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1737 if (wlv.n_extra == 0)
1738 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001739#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001740#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001741 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001742 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001743 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001744 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001745 }
1746#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001747 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001748 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001749 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001750 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001751 }
1752 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001753
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001754#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001755 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001756 && wlv.vcol >= left_curline_col
1757 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001758 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001759 wlv.cul_attr = HL_ATTR(HLF_CUL);
1760 line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001761 }
1762#endif
1763
1764 // When still displaying '$' of change command, stop at cursor.
1765 // When only displaying the (relative) line number and that's done,
1766 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001767 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001768 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001769 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001770#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001771 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001772#endif
1773 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001774 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001775 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001776 // Pretend we have finished updating the window. Except when
1777 // 'cursorcolumn' is set.
1778#ifdef FEAT_SYN_HL
1779 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001780 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001781 else
1782#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001783 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001784 break;
1785 }
1786
Bram Moolenaar1306b362022-08-06 15:59:06 +01001787 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001788 {
1789 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001790 if (wlv.vcol == wlv.fromcol
1791 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1792 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001793 && (*mb_ptr2cells)(ptr) > 1)
1794 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001795 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001796 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001797 area_attr = vi_attr; // start highlighting
1798 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001799 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001800 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001801 area_attr = 0; // stop highlighting
1802
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001803#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001804 if (text_props != NULL)
1805 {
1806 int pi;
1807 int bcol = (int)(ptr - line);
1808
Bram Moolenaar1306b362022-08-06 15:59:06 +01001809 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001810# ifdef FEAT_LINEBREAK
1811 && !in_linebreak
1812# endif
1813 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001814 --bcol; // still working on the previous char, e.g. Tab
1815
1816 // Check if any active property ends.
1817 for (pi = 0; pi < text_props_active; ++pi)
1818 {
1819 int tpi = text_prop_idxs[pi];
1820
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001821 if (text_props[tpi].tp_col != MAXCOL
1822 && bcol >= text_props[tpi].tp_col - 1
1823 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001824 {
1825 if (pi + 1 < text_props_active)
1826 mch_memmove(text_prop_idxs + pi,
1827 text_prop_idxs + pi + 1,
1828 sizeof(int)
1829 * (text_props_active - (pi + 1)));
1830 --text_props_active;
1831 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001832# ifdef FEAT_LINEBREAK
1833 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001834 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001835 syntax_attr = 0;
1836# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001837 }
1838 }
1839
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001840# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001841 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001842 // not on the next char yet, don't start another prop
1843 --bcol;
1844# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001845 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001846 // With 'nowrap' and not in the first screen line only "below"
1847 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001848 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001849 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001850 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001851 && (wp->w_p_wrap
1852 || wlv.row == startrow
1853 || (text_props[text_prop_next].tp_flags
1854 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001855 || (bcol == 0 &&
1856 (text_props[text_prop_next].tp_flags
1857 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001858 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001859 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001860 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001861 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1862 {
1863 // first display the '$' after the line
1864 text_prop_follows = TRUE;
1865 break;
1866 }
1867 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001868 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001869 + text_props[text_prop_next].tp_len)
1870 text_prop_idxs[text_props_active++] = text_prop_next;
1871 ++text_prop_next;
1872 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001873
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001874 if (wlv.n_extra == 0 || !extra_for_textprop)
1875 {
1876 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001877 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001878 text_prop_flags = 0;
1879 text_prop_type = NULL;
1880 text_prop_id = 0;
1881 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001882 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001883 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001884 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001885 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001886 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001887
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001888 // Sort the properties on priority and/or starting last.
1889 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001890 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001891 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001892 sort_text_props(wp->w_buffer, text_props,
1893 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001894
1895 for (pi = 0; pi < text_props_active; ++pi)
1896 {
1897 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001898 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001899 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001900 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001901
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001902 if (pt != NULL && (pt->pt_hl_id > 0
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001903 || tp->tp_id < 0) && tp->tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001904 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001905 if (pt->pt_hl_id > 0)
1906 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001907 text_prop_type = pt;
1908 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001909 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001910 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001911 text_prop_flags = pt->pt_flags;
1912 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001913 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001914 }
1915 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001916 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001917 && -text_prop_id
1918 <= wp->w_buffer->b_textprop_text.ga_len)
1919 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001920 textprop_T *tp = &text_props[used_tpi];
1921 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001922 ->b_textprop_text.ga_data)[
1923 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001924 int above = (tp->tp_flags
1925 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01001926 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001927
1928 // reset the ID in the copy to avoid it being used
1929 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001930 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001931
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001932 if (p != NULL)
1933 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001934 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001935 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001936 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001937 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001938 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1939 int padding = tp->tp_col == MAXCOL
1940 && tp->tp_len > 1
1941 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001942
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001943 // Insert virtual text before the current
1944 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001945 wlv.p_extra = p;
1946 wlv.c_extra = NUL;
1947 wlv.c_final = NUL;
1948 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001949 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001950 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001951 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001952 // restore search_attr and area_attr when n_extra
1953 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001954 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001955 saved_area_attr = area_attr;
1956 search_attr = 0;
1957 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001958 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001959 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001960 if (*ptr == NUL)
1961 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001962 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001963#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001964 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001965 {
1966 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001967 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001968 wlv.need_showbreak = FALSE;
1969 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001970 }
1971#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001972 if ((right || above || below || !wrap
1973 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001974 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001975 char_u *prev_p_extra = wlv.p_extra;
1976 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001977
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001978 // Take care of padding, right-align and
1979 // truncation.
1980 // Shared with win_lbr_chartabsize(), must do
1981 // exactly the same.
1982 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001983 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001984 wlv.col,
1985 &wlv.n_extra, &wlv.p_extra,
1986 &n_attr, &n_attr_skip);
1987 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001988 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001989 // wlv.p_extra was allocated
1990 vim_free(p_extra_free2);
1991 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001992 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001993
Bram Moolenaara4abe512022-09-15 19:44:09 +01001994 if (lcs_eol_one < 0 && wlv.col
1995 + wlv.n_extra - 2 > wp->w_width)
1996 // don't bail out at end of line
1997 lcs_eol_one = 0;
1998
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001999 // When 'wrap' is off then for "below" we need
2000 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002001 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002002 {
2003 draw_screen_line(wp, &wlv);
2004
2005 // When line got too long for screen break
2006 // here.
2007 if (wlv.row == endrow)
2008 {
2009 ++wlv.row;
2010 break;
2011 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002012 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002013 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002014 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002015 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002016 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002017
2018 // If another text prop follows the condition below at
2019 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002020 // If this is an "above" text prop and 'nowrap' the we
2021 // must wrap anyway.
2022 text_prop_above = above;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002023 text_prop_follows = other_tpi != -1
2024 && (wp->w_p_wrap
2025 || (text_props[other_tpi].tp_flags
2026 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002027
2028 if (bail_out)
2029 // starting a new line for "below"
2030 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002031 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002032 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002033 else if (text_prop_next < text_prop_count
2034 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002035 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2036 || (!wp->w_p_wrap
2037 && wlv.col == wp->w_width - 1
2038 && (text_props[text_prop_next].tp_flags
2039 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002040 // When at last-but-one character and a text property
2041 // follows after it, we may need to flush the line after
2042 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002043 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002044 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002045 }
2046#endif
2047
Bram Moolenaare38fc862022-08-11 17:24:50 +01002048#ifdef FEAT_SEARCH_EXTRA
2049 if (wlv.n_extra == 0)
2050 {
2051 // Check for start/end of 'hlsearch' and other matches.
2052 // After end, check for start/end of next match.
2053 // When another match, have to check for start again.
2054 v = (long)(ptr - line);
2055 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2056 &screen_search_hl, &has_match_conc,
2057 &match_conc, did_line_attr, lcs_eol_one,
2058 &on_last_col);
2059 ptr = line + v; // "line" may have been changed
2060 prev_ptr = ptr;
2061
2062 // Do not allow a conceal over EOL otherwise EOL will be missed
2063 // and bad things happen.
2064 if (*ptr == NUL)
2065 has_match_conc = 0;
2066 }
2067#endif
2068
2069#ifdef FEAT_DIFF
2070 if (wlv.diff_hlf != (hlf_T)0)
2071 {
2072 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2073 && wlv.n_extra == 0)
2074 wlv.diff_hlf = HLF_TXD; // changed text
2075 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2076 && wlv.n_extra == 0)
2077 wlv.diff_hlf = HLF_CHD; // changed line
2078 line_attr = HL_ATTR(wlv.diff_hlf);
2079 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2080 && wp->w_p_culopt_flags != CULOPT_NBR
2081 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2082 && wlv.vcol <= right_curline_col)))
2083 line_attr = hl_combine_attr(
2084 line_attr, HL_ATTR(HLF_CUL));
2085 }
2086#endif
2087
Bram Moolenaara74fda62019-10-19 17:38:03 +02002088#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002089 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002090 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002091 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002092# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002093 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002094 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002095# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002096 // Get syntax attribute.
2097 if (has_syntax)
2098 {
2099 // Get the syntax attribute for the character. If there
2100 // is an error, disable syntax highlighting.
2101 save_did_emsg = did_emsg;
2102 did_emsg = FALSE;
2103
2104 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002105 if (v == prev_syntax_col)
2106 // at same column again
2107 syntax_attr = prev_syntax_attr;
2108 else
2109 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002110# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002111 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002112# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002113 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002114# ifdef FEAT_SPELL
2115 has_spell ? &can_spell :
2116# endif
2117 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002118 prev_syntax_col = v;
2119 prev_syntax_attr = syntax_attr;
2120 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002121
Bram Moolenaar34390282019-10-16 14:38:26 +02002122 if (did_emsg)
2123 {
2124 wp->w_s->b_syn_error = TRUE;
2125 has_syntax = FALSE;
2126 syntax_attr = 0;
2127 }
2128 else
2129 did_emsg = save_did_emsg;
2130# ifdef SYN_TIME_LIMIT
2131 if (wp->w_s->b_syn_slow)
2132 has_syntax = FALSE;
2133# endif
2134
2135 // Need to get the line again, a multi-line regexp may
2136 // have made it invalid.
2137 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2138 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002139 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002140# ifdef FEAT_CONCEAL
2141 // no concealing past the end of the line, it interferes
2142 // with line highlighting
2143 if (*ptr == NUL)
2144 syntax_flags = 0;
2145 else
2146 syntax_flags = get_syntax_info(&syntax_seqnr);
2147# endif
2148 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002149 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002150# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002151 // Combine text property highlight into syntax highlight.
2152 if (text_prop_type != NULL)
2153 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002154 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002155 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2156 else
2157 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002158 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002159 }
2160# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002161#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002162
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002163 // Decide which of the highlight attributes to use.
2164 attr_pri = TRUE;
2165#ifdef LINE_ATTR
2166 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002167 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002168 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002169 if (!highlight_match)
2170 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002171 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002172# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002173 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002174# endif
2175 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002176 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002177 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002178 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002179# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002180 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002181# endif
2182 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002183 else if (line_attr != 0
2184 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2185 || wlv.vcol < wlv.fromcol
2186 || vcol_prev < fromcol_prev
2187 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002188 {
2189 // Use line_attr when not in the Visual or 'incsearch' area
2190 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002191# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002192 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002193# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002194 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002195# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002196 attr_pri = FALSE;
2197 }
2198#else
2199 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002200 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002201 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002202 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002203#endif
2204 else
2205 {
2206 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002207#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002208 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002209#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002210 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002211#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002212 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002213#ifdef FEAT_PROP_POPUP
2214 // override with text property highlight when "override" is TRUE
2215 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002216 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002217#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002218 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002219
2220 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002221 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002222 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002223 if (wlv.char_attr == 0)
2224 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002225 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002226 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002227 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002228
2229 // Get the next character to put on the screen.
2230
2231 // The "p_extra" points to the extra stuff that is inserted to
2232 // represent special characters (non-printable stuff) and other
2233 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002234 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002235 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2236 // "p_extra[n_extra]".
2237 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002238 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002239 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002240 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002241 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002242 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2243 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002244 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2245 if (enc_utf8 && utf_char2len(c) > 1)
2246 {
2247 mb_utf8 = TRUE;
2248 u8cc[0] = 0;
2249 c = 0xc0;
2250 }
2251 else
2252 mb_utf8 = FALSE;
2253 }
2254 else
2255 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002256 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002257 if (has_mbyte)
2258 {
2259 mb_c = c;
2260 if (enc_utf8)
2261 {
2262 // If the UTF-8 character is more than one byte:
2263 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002264 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002265 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002266 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002267 mb_l = 1;
2268 else if (mb_l > 1)
2269 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002270 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002271 mb_utf8 = TRUE;
2272 c = 0xc0;
2273 }
2274 }
2275 else
2276 {
2277 // if this is a DBCS character, put it in "mb_c"
2278 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002279 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002280 mb_l = 1;
2281 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002282 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002283 }
2284 if (mb_l == 0) // at the NUL at end-of-line
2285 mb_l = 1;
2286
2287 // If a double-width char doesn't fit display a '>' in the
2288 // last column.
2289 if ((
2290# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002291 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002292# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002293 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002294 && (*mb_char2cells)(mb_c) == 2)
2295 {
2296 c = '>';
2297 mb_c = c;
2298 mb_l = 1;
2299 mb_utf8 = FALSE;
2300 multi_attr = HL_ATTR(HLF_AT);
2301#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002302 if (wlv.cul_attr)
2303 multi_attr = hl_combine_attr(
2304 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002305#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002306 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002307
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002308 // put the pointer back to output the double-width
2309 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002310 ++wlv.n_extra;
2311 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002312 }
2313 else
2314 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002315 wlv.n_extra -= mb_l - 1;
2316 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002317 }
2318 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002319 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002320 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002321 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002322#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002323 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002324 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002325 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002326 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002327 if (search_attr == 0)
2328 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002329 if (area_attr == 0 && *ptr != NUL)
2330 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002331 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002332#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002333 }
2334 else
2335 {
2336#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002337 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002338#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002339 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002340
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002341 // Get a character from the line itself.
2342 c = *ptr;
2343#ifdef FEAT_LINEBREAK
2344 c0 = *ptr;
2345#endif
2346 if (has_mbyte)
2347 {
2348 mb_c = c;
2349 if (enc_utf8)
2350 {
2351 // If the UTF-8 character is more than one byte: Decode it
2352 // into "mb_c".
2353 mb_l = utfc_ptr2len(ptr);
2354 mb_utf8 = FALSE;
2355 if (mb_l > 1)
2356 {
2357 mb_c = utfc_ptr2char(ptr, u8cc);
2358 // Overlong encoded ASCII or ASCII with composing char
2359 // is displayed normally, except a NUL.
2360 if (mb_c < 0x80)
2361 {
2362 c = mb_c;
2363#ifdef FEAT_LINEBREAK
2364 c0 = mb_c;
2365#endif
2366 }
2367 mb_utf8 = TRUE;
2368
2369 // At start of the line we can have a composing char.
2370 // Draw it as a space with a composing char.
2371 if (utf_iscomposing(mb_c))
2372 {
2373 int i;
2374
2375 for (i = Screen_mco - 1; i > 0; --i)
2376 u8cc[i] = u8cc[i - 1];
2377 u8cc[0] = mb_c;
2378 mb_c = ' ';
2379 }
2380 }
2381
2382 if ((mb_l == 1 && c >= 0x80)
2383 || (mb_l >= 1 && mb_c == 0)
2384 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2385 {
2386 // Illegal UTF-8 byte: display as <xx>.
2387 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002388 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002389# ifdef FEAT_RIGHTLEFT
2390 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002391 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002392# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002393 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002394 c = *wlv.p_extra;
2395 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002396 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002397 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2398 wlv.c_extra = NUL;
2399 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002400 if (area_attr == 0 && search_attr == 0)
2401 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002402 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002403 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002404 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002405 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002406 }
2407 }
2408 else if (mb_l == 0) // at the NUL at end-of-line
2409 mb_l = 1;
2410#ifdef FEAT_ARABIC
2411 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2412 {
2413 // Do Arabic shaping.
2414 int pc, pc1, nc;
2415 int pcc[MAX_MCO];
2416
2417 // The idea of what is the previous and next
2418 // character depends on 'rightleft'.
2419 if (wp->w_p_rl)
2420 {
2421 pc = prev_c;
2422 pc1 = prev_c1;
2423 nc = utf_ptr2char(ptr + mb_l);
2424 prev_c1 = u8cc[0];
2425 }
2426 else
2427 {
2428 pc = utfc_ptr2char(ptr + mb_l, pcc);
2429 nc = prev_c;
2430 pc1 = pcc[0];
2431 }
2432 prev_c = mb_c;
2433
2434 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2435 }
2436 else
2437 prev_c = mb_c;
2438#endif
2439 }
2440 else // enc_dbcs
2441 {
2442 mb_l = MB_BYTE2LEN(c);
2443 if (mb_l == 0) // at the NUL at end-of-line
2444 mb_l = 1;
2445 else if (mb_l > 1)
2446 {
2447 // We assume a second byte below 32 is illegal.
2448 // Hopefully this is OK for all double-byte encodings!
2449 if (ptr[1] >= 32)
2450 mb_c = (c << 8) + ptr[1];
2451 else
2452 {
2453 if (ptr[1] == NUL)
2454 {
2455 // head byte at end of line
2456 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002457 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002458 }
2459 else
2460 {
2461 // illegal tail byte
2462 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002463 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002464 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002465 wlv.p_extra = wlv.extra;
2466 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002467 wlv.c_extra = NUL;
2468 wlv.c_final = NUL;
2469 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002470 if (area_attr == 0 && search_attr == 0)
2471 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002472 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002473 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002474 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002475 // save current attr
2476 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002477 }
2478 mb_c = c;
2479 }
2480 }
2481 }
2482 // If a double-width char doesn't fit display a '>' in the
2483 // last column; the character is displayed at the start of the
2484 // next line.
2485 if ((
2486# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002487 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002488# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002489 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002490 && (*mb_char2cells)(mb_c) == 2)
2491 {
2492 c = '>';
2493 mb_c = c;
2494 mb_utf8 = FALSE;
2495 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002496 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002497 // Put pointer back so that the character will be
2498 // displayed at the start of the next line.
2499 --ptr;
2500#ifdef FEAT_CONCEAL
2501 did_decrement_ptr = TRUE;
2502#endif
2503 }
2504 else if (*ptr != NUL)
2505 ptr += mb_l - 1;
2506
2507 // If a double-width char doesn't fit at the left side display
2508 // a '<' in the first column. Don't do this for unprintable
2509 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002510 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002511 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002512 wlv.n_extra = 1;
2513 wlv.c_extra = MB_FILLER_CHAR;
2514 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002515 c = ' ';
2516 if (area_attr == 0 && search_attr == 0)
2517 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002518 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002519 extra_attr = hl_combine_attr(
2520 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002521 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002522 }
2523 mb_c = c;
2524 mb_utf8 = FALSE;
2525 mb_l = 1;
2526 }
2527
2528 }
2529 ++ptr;
2530
2531 if (extra_check)
2532 {
2533#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002534 // Check spelling (unless at the end of the line).
2535 // Only do this when there is no syntax highlighting, the
2536 // @Spell cluster is not used or the current syntax item
2537 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002538 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002539 if (has_spell && v >= word_end && v > cur_checked_col)
2540 {
2541 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002542 // do not calculate cap_col at the end of the line or when
2543 // only white space is following
2544 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002545# ifdef FEAT_SYN_HL
2546 !has_syntax ||
2547# endif
2548 can_spell))
2549 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002550 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002551 int len;
2552 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002553
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002554 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002555 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002556
2557 // Use nextline[] if possible, it has the start of the
2558 // next line concatenated.
2559 if ((prev_ptr - line) - nextlinecol >= 0)
2560 p = nextline + (prev_ptr - line) - nextlinecol;
2561 else
2562 p = prev_ptr;
2563 cap_col -= (int)(prev_ptr - line);
2564 len = spell_check(wp, p, &spell_hlf, &cap_col,
2565 nochange);
2566 word_end = v + len;
2567
2568 // In Insert mode only highlight a word that
2569 // doesn't touch the cursor.
2570 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002571 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002572 && wp->w_cursor.lnum == lnum
2573 && wp->w_cursor.col >=
2574 (colnr_T)(prev_ptr - line)
2575 && wp->w_cursor.col < (colnr_T)word_end)
2576 {
2577 spell_hlf = HLF_COUNT;
2578 spell_redraw_lnum = lnum;
2579 }
2580
2581 if (spell_hlf == HLF_COUNT && p != prev_ptr
2582 && (p - nextline) + len > nextline_idx)
2583 {
2584 // Remember that the good word continues at the
2585 // start of the next line.
2586 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002587 checked_col = (int)((p - nextline)
2588 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002589 }
2590
2591 // Turn index into actual attributes.
2592 if (spell_hlf != HLF_COUNT)
2593 spell_attr = highlight_attr[spell_hlf];
2594
2595 if (cap_col > 0)
2596 {
2597 if (p != prev_ptr
2598 && (p - nextline) + cap_col >= nextline_idx)
2599 {
2600 // Remember that the word in the next line
2601 // must start with a capital.
2602 capcol_lnum = lnum + 1;
2603 cap_col = (int)((p - nextline) + cap_col
2604 - nextline_idx);
2605 }
2606 else
2607 // Compute the actual column.
2608 cap_col += (int)(prev_ptr - line);
2609 }
2610 }
2611 }
2612 if (spell_attr != 0)
2613 {
2614 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002615 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2616 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002617 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002618 wlv.char_attr = hl_combine_attr(spell_attr,
2619 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002620 }
2621#endif
2622#ifdef FEAT_LINEBREAK
2623 // Found last space before word: check for line break.
2624 if (wp->w_p_lbr && c0 == c
2625 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2626 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002627 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2628 : 0;
2629 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002630 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002631
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002632 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002633# ifdef FEAT_PROP_POPUP
2634 // do not want virtual text counted here
2635 cts.cts_has_prop_with_text = FALSE;
2636# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002637 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002638 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002639
2640 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002641 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002642 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002643 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002644 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2645 if (wlv.n_extra < 0)
2646 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002647 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002648 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002649 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002650 // line break, but for TABs the highlighting should
2651 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002652 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002653
Bram Moolenaar1306b362022-08-06 15:59:06 +01002654 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002655# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002656 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002657 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002658 wp->w_buffer->b_p_vts_array) - 1;
2659# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002660 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002661 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002662# endif
2663
Bram Moolenaar1306b362022-08-06 15:59:06 +01002664 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2665 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002666# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002667 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002668 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002669# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002670 if (VIM_ISWHITE(c))
2671 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002672# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002673 if (c == TAB)
2674 // See "Tab alignment" below.
2675 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002676# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002677 if (!wp->w_p_list)
2678 c = ' ';
2679 }
2680 }
2681#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002682 in_multispace = c == ' '
2683 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2684 if (!in_multispace)
2685 multispace_pos = 0;
2686
Bram Moolenaareed9d462021-02-15 20:38:25 +01002687 // 'list': Change char 160 to 'nbsp' and space to 'space'
2688 // setting in 'listchars'. But not when the character is
2689 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002690 if (wp->w_p_list
2691 && ((((c == 160 && mb_l == 1)
2692 || (mb_utf8
2693 && ((mb_c == 160 && mb_l == 2)
2694 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002695 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002696 || (c == ' '
2697 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002698 && (wp->w_lcs_chars.space
2699 || (in_multispace
2700 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002701 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002702 && ptr - line <= trailcol)))
2703 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002704 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2705 {
2706 c = wp->w_lcs_chars.multispace[multispace_pos++];
2707 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2708 multispace_pos = 0;
2709 }
2710 else
2711 c = (c == ' ') ? wp->w_lcs_chars.space
2712 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002713 if (area_attr == 0 && search_attr == 0)
2714 {
2715 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002716 extra_attr = hl_combine_attr(wlv.win_attr,
2717 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002718 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002719 }
2720 mb_c = c;
2721 if (enc_utf8 && utf_char2len(c) > 1)
2722 {
2723 mb_utf8 = TRUE;
2724 u8cc[0] = 0;
2725 c = 0xc0;
2726 }
2727 else
2728 mb_utf8 = FALSE;
2729 }
2730
zeertzjq2e7cba32022-06-10 15:30:32 +01002731 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2732 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002733 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002734 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2735 && wp->w_lcs_chars.leadmultispace != NULL)
2736 {
2737 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002738 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2739 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002740 multispace_pos = 0;
2741 }
2742
2743 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2744 c = wp->w_lcs_chars.trail;
2745
2746 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2747 c = wp->w_lcs_chars.lead;
2748
zeertzjq2e7cba32022-06-10 15:30:32 +01002749 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002750 c = wp->w_lcs_chars.space;
2751
2752
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002753 if (!attr_pri)
2754 {
2755 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002756 extra_attr = hl_combine_attr(wlv.win_attr,
2757 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002758 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002759 }
2760 mb_c = c;
2761 if (enc_utf8 && utf_char2len(c) > 1)
2762 {
2763 mb_utf8 = TRUE;
2764 u8cc[0] = 0;
2765 c = 0xc0;
2766 }
2767 else
2768 mb_utf8 = FALSE;
2769 }
2770 }
2771
2772 // Handling of non-printable characters.
2773 if (!vim_isprintc(c))
2774 {
2775 // when getting a character from the file, we may have to
2776 // turn it into something else on the way to putting it
2777 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002778 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002779 {
2780 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002781 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002782#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002783 char_u *sbr = get_showbreak_value(wp);
2784
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002785 // only adjust the tab_len, when at the first column
2786 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002787 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002788 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002789#endif
2790 // tab amount depends on current column
2791#ifdef FEAT_VARTABS
2792 tab_len = tabstop_padding(vcol_adjusted,
2793 wp->w_buffer->b_p_ts,
2794 wp->w_buffer->b_p_vts_array) - 1;
2795#else
2796 tab_len = (int)wp->w_buffer->b_p_ts
2797 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2798#endif
2799
2800#ifdef FEAT_LINEBREAK
2801 if (!wp->w_p_lbr || !wp->w_p_list)
2802#endif
2803 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002804 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002805#ifdef FEAT_LINEBREAK
2806 else
2807 {
2808 char_u *p;
2809 int len;
2810 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002811 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002812
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002813# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002814 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002815 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002816 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002817
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002818 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002819 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002820 && old_boguscols > 0
2821 && wlv.n_extra > tab_len)
2822 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002823# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002824 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002825 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002826 // If wlv.n_extra > 0, it gives the number of
2827 // chars, to use for a tab, else we need to
2828 // calculate the width for a tab.
2829 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
2830 len = tab_len * tab2_len;
2831 if (wp->w_lcs_chars.tab3)
2832 len += mb_char2len(wp->w_lcs_chars.tab3)
2833 - tab2_len;
2834 if (wlv.n_extra > 0)
2835 len += wlv.n_extra - tab_len;
2836 c = wp->w_lcs_chars.tab1;
2837 p = alloc(len + 1);
2838 if (p == NULL)
2839 wlv.n_extra = 0;
2840 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002841 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002842 vim_memset(p, ' ', len);
2843 p[len] = NUL;
2844 vim_free(wlv.p_extra_free);
2845 wlv.p_extra_free = p;
2846 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002847 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002848 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002849
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002850 if (*p == NUL)
2851 {
2852 tab_len = i;
2853 break;
2854 }
2855
2856 // if tab3 is given, use it for the last
2857 // char
2858 if (wp->w_lcs_chars.tab3
2859 && i == tab_len - 1)
2860 lcs = wp->w_lcs_chars.tab3;
2861 p += mb_char2bytes(lcs, p);
2862 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002863 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002864 }
2865 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002866# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002867 // n_extra will be increased by
2868 // FIX_FOX_BOGUSCOLS macro below, so need to
2869 // adjust for that here
2870 if (wlv.vcol_off > 0)
2871 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002872# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002873 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002874 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002875 }
2876#endif
2877#ifdef FEAT_CONCEAL
2878 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002879 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002880
2881 // Tab alignment should be identical regardless of
2882 // 'conceallevel' value. So tab compensates of all
2883 // previous concealed characters, and thus resets
2884 // vcol_off and boguscols accumulated so far in the
2885 // line. Note that the tab can be longer than
2886 // 'tabstop' when there are concealed characters.
2887 FIX_FOR_BOGUSCOLS;
2888
2889 // Make sure, the highlighting for the tab char will be
2890 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002891 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002892 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002893 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002894 tab_len += vc_saved;
2895 }
2896#endif
2897 mb_utf8 = FALSE; // don't draw as UTF-8
2898 if (wp->w_p_list)
2899 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002900 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002901 ? wp->w_lcs_chars.tab3
2902 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002903#ifdef FEAT_LINEBREAK
2904 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002905 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002906 else
2907#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002908 wlv.c_extra = wp->w_lcs_chars.tab2;
2909 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002910 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002911 extra_attr = hl_combine_attr(wlv.win_attr,
2912 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002913 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002914 mb_c = c;
2915 if (enc_utf8 && utf_char2len(c) > 1)
2916 {
2917 mb_utf8 = TRUE;
2918 u8cc[0] = 0;
2919 c = 0xc0;
2920 }
2921 }
2922 else
2923 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002924 wlv.c_final = NUL;
2925 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002926 c = ' ';
2927 }
2928 }
2929 else if (c == NUL
2930 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002931 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
2932 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002933 && VIsual_mode != Ctrl_V
2934 && (
2935# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002936 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002937# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002938 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002939 && !(noinvcur
2940 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002941 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002942 && lcs_eol_one > 0)
2943 {
2944 // Display a '$' after the line or highlight an extra
2945 // character if the line break is included.
2946#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2947 // For a diff line the highlighting continues after the
2948 // "$".
2949 if (
2950# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002951 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002952# ifdef LINE_ATTR
2953 &&
2954# endif
2955# endif
2956# ifdef LINE_ATTR
2957 line_attr == 0
2958# endif
2959 )
2960#endif
2961 {
2962 // In virtualedit, visual selections may extend
2963 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002964 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002965 && wlv.tocol != MAXCOL
2966 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002967 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002968 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002969 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002970 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2971 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002972 else
2973 c = ' ';
2974 lcs_eol_one = -1;
2975 --ptr; // put it back at the NUL
2976 if (!attr_pri)
2977 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002978 extra_attr = hl_combine_attr(wlv.win_attr,
2979 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002980 n_attr = 1;
2981 }
2982 mb_c = c;
2983 if (enc_utf8 && utf_char2len(c) > 1)
2984 {
2985 mb_utf8 = TRUE;
2986 u8cc[0] = 0;
2987 c = 0xc0;
2988 }
2989 else
2990 mb_utf8 = FALSE; // don't draw as UTF-8
2991 }
2992 else if (c != NUL)
2993 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002994 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2995 if (wlv.n_extra == 0)
2996 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002997#ifdef FEAT_RIGHTLEFT
2998 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002999 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003000#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003001 wlv.c_extra = NUL;
3002 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003003#ifdef FEAT_LINEBREAK
3004 if (wp->w_p_lbr)
3005 {
3006 char_u *p;
3007
Bram Moolenaar1306b362022-08-06 15:59:06 +01003008 c = *wlv.p_extra;
3009 p = alloc(wlv.n_extra + 1);
3010 vim_memset(p, ' ', wlv.n_extra);
3011 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3012 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003013 vim_free(wlv.p_extra_free);
3014 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003015 }
3016 else
3017#endif
3018 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003019 wlv.n_extra = byte2cells(c) - 1;
3020 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003021 }
3022 if (!attr_pri)
3023 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003024 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003025 extra_attr = hl_combine_attr(wlv.win_attr,
3026 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003027 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003028 }
3029 mb_utf8 = FALSE; // don't draw as UTF-8
3030 }
3031 else if (VIsual_active
3032 && (VIsual_mode == Ctrl_V
3033 || VIsual_mode == 'v')
3034 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003035 && wlv.tocol != MAXCOL
3036 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003037 && (
3038#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003039 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003040#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003041 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003042 {
3043 c = ' ';
3044 --ptr; // put it back at the NUL
3045 }
3046#if defined(LINE_ATTR)
3047 else if ((
3048# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003049 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003050# endif
3051# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003052 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003053# endif
3054 line_attr != 0
3055 ) && (
3056# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003057 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003058# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003059 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003060# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003061 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003062# endif
3063 < wp->w_width)))
3064 {
3065 // Highlight until the right side of the window
3066 c = ' ';
3067 --ptr; // put it back at the NUL
3068
3069 // Remember we do the char for line highlighting.
3070 ++did_line_attr;
3071
3072 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01003073 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003074 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003075 || (wp->w_p_list &&
3076 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003077 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003078# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003079 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003080 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003081 wlv.diff_hlf = HLF_CHD;
3082 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003083 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003084 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003085 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3086 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003087 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003088 || (wlv.vcol >= left_curline_col
3089 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003090 wlv.char_attr = hl_combine_attr(
3091 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003092 }
3093 }
3094# endif
3095# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003096 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003097 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003098 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003099 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3100 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003101 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003102 if (!wlv.cul_screenline
3103 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003104 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003105 wlv.char_attr = hl_combine_attr(
3106 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003107 }
3108 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003109 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3110 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003111 }
3112# endif
3113 }
3114#endif
3115 }
3116
3117#ifdef FEAT_CONCEAL
3118 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003119 && (wp != curwin || lnum != wp->w_cursor.lnum
3120 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003121 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3122 && !(lnum_in_visual_area
3123 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3124 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003125 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003126 if (((prev_syntax_id != syntax_seqnr
3127 && (syntax_flags & HL_CONCEAL) != 0)
3128 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003129 && (syn_get_sub_char() != NUL
3130 || (has_match_conc && match_conc)
3131 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003132 && wp->w_p_cole != 3)
3133 {
3134 // First time at this concealed item: display one
3135 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003136 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003137 c = match_conc;
3138 else if (syn_get_sub_char() != NUL)
3139 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003140 else if (wp->w_lcs_chars.conceal != NUL)
3141 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003142 else
3143 c = ' ';
3144
3145 prev_syntax_id = syntax_seqnr;
3146
Bram Moolenaar1306b362022-08-06 15:59:06 +01003147 if (wlv.n_extra > 0)
3148 wlv.vcol_off += wlv.n_extra;
3149 wlv.vcol += wlv.n_extra;
3150 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003151 {
3152# ifdef FEAT_RIGHTLEFT
3153 if (wp->w_p_rl)
3154 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003155 wlv.col -= wlv.n_extra;
3156 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003157 }
3158 else
3159# endif
3160 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003161 wlv.boguscols += wlv.n_extra;
3162 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003163 }
3164 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003165 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003166 n_attr = 0;
3167 }
3168 else if (n_skip == 0)
3169 {
3170 is_concealing = TRUE;
3171 n_skip = 1;
3172 }
3173 mb_c = c;
3174 if (enc_utf8 && utf_char2len(c) > 1)
3175 {
3176 mb_utf8 = TRUE;
3177 u8cc[0] = 0;
3178 c = 0xc0;
3179 }
3180 else
3181 mb_utf8 = FALSE; // don't draw as UTF-8
3182 }
3183 else
3184 {
3185 prev_syntax_id = 0;
3186 is_concealing = FALSE;
3187 }
3188
3189 if (n_skip > 0 && did_decrement_ptr)
3190 // not showing the '>', put pointer back to avoid getting stuck
3191 ++ptr;
3192
3193#endif // FEAT_CONCEAL
3194 }
3195
3196#ifdef FEAT_CONCEAL
3197 // In the cursor line and we may be concealing characters: correct
3198 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003199 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003200 && wp == curwin && lnum == wp->w_cursor.lnum
3201 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003202 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003203 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003204# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003205 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003206 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003207 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003208# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003209 wp->w_wcol = wlv.col - wlv.boguscols;
3210 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003211 did_wcol = TRUE;
3212 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003213# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003214 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003215# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003216 }
3217#endif
3218
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003219 // Use "extra_attr", but don't override visual selection highlighting,
3220 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003221 // Don't use "extra_attr" until n_attr_skip is zero.
3222 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003223 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003224 && (!attr_pri
3225#ifdef FEAT_PROP_POPUP
3226 || (text_prop_flags & PT_FLAG_OVERRIDE)
3227#endif
3228 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003229 {
3230#ifdef LINE_ATTR
3231 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003232 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003233 else
3234#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003235 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003236 }
3237
3238#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3239 // XIM don't send preedit_start and preedit_end, but they send
3240 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3241 // im_is_preediting() here.
3242 if (p_imst == IM_ON_THE_SPOT
3243 && xic != NULL
3244 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003245 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003246 && !p_imdisable
3247 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003248 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003249 {
3250 colnr_T tcol;
3251
3252 if (preedit_end_col == MAXCOL)
3253 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3254 else
3255 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003256 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003257 {
3258 if (feedback_old_attr < 0)
3259 {
3260 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003261 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003262 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003263 wlv.char_attr = im_get_feedback_attr(feedback_col);
3264 if (wlv.char_attr < 0)
3265 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003266 feedback_col++;
3267 }
3268 else if (feedback_old_attr >= 0)
3269 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003270 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003271 feedback_old_attr = -1;
3272 feedback_col = 0;
3273 }
3274 }
3275#endif
3276 // Handle the case where we are in column 0 but not on the first
3277 // character of the line and the user wants us to show us a
3278 // special character (via 'listchars' option "precedes:<char>".
3279 if (lcs_prec_todo != NUL
3280 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003281 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3282 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003283#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003284 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003285#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003286 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003287 && c != NUL)
3288 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003289 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003290 lcs_prec_todo = NUL;
3291 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3292 {
3293 // Double-width character being overwritten by the "precedes"
3294 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003295 wlv.c_extra = MB_FILLER_CHAR;
3296 wlv.c_final = NUL;
3297 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003298 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003299 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003300 }
3301 mb_c = c;
3302 if (enc_utf8 && utf_char2len(c) > 1)
3303 {
3304 mb_utf8 = TRUE;
3305 u8cc[0] = 0;
3306 c = 0xc0;
3307 }
3308 else
3309 mb_utf8 = FALSE; // don't draw as UTF-8
3310 if (!attr_pri)
3311 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003312 saved_attr3 = wlv.char_attr; // save current attr
3313 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003314 n_attr3 = 1;
3315 }
3316 }
3317
3318 // At end of the text line or just after the last character.
3319 if ((c == NUL
3320#if defined(LINE_ATTR)
3321 || did_line_attr == 1
3322#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003323 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003324 {
3325#ifdef FEAT_SEARCH_EXTRA
3326 // flag to indicate whether prevcol equals startcol of search_hl or
3327 // one of the matches
3328 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3329 (long)(ptr - line) - (c == NUL));
3330#endif
3331 // Invert at least one char, used for Visual and empty line or
3332 // highlight match at end of line. If it's beyond the last
3333 // char on the screen, just overwrite that one (tricky!) Not
3334 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003335 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003336 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003337 && (VIsual_mode != Ctrl_V
3338 || lnum == VIsual.lnum
3339 || lnum == curwin->w_cursor.lnum)
3340 && c == NUL)
3341#ifdef FEAT_SEARCH_EXTRA
3342 // highlight 'hlsearch' match at end of line
3343 || (prevcol_hl_flag
3344# ifdef FEAT_SYN_HL
3345 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3346 && !(wp == curwin && VIsual_active))
3347# endif
3348# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003349 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003350# endif
3351# if defined(LINE_ATTR)
3352 && did_line_attr <= 1
3353# endif
3354 )
3355#endif
3356 ))
3357 {
3358 int n = 0;
3359
3360#ifdef FEAT_RIGHTLEFT
3361 if (wp->w_p_rl)
3362 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003363 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003364 n = 1;
3365 }
3366 else
3367#endif
3368 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003369 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003370 n = -1;
3371 }
3372 if (n != 0)
3373 {
3374 // At the window boundary, highlight the last character
3375 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003376 wlv.off += n;
3377 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003378 }
3379 else
3380 {
3381 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003382 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003383 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003384 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003385 }
3386#ifdef FEAT_SEARCH_EXTRA
3387 if (area_attr == 0)
3388 {
3389 // Use attributes from match with highest priority among
3390 // 'search_hl' and the match list.
3391 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003392 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003393 }
3394#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003395 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003396 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003397#ifdef FEAT_RIGHTLEFT
3398 if (wp->w_p_rl)
3399 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003400 --wlv.col;
3401 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003402 }
3403 else
3404#endif
3405 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003406 ++wlv.col;
3407 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003408 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003409 ++wlv.vcol;
3410 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003411 }
3412 }
3413
3414 // At end of the text line.
3415 if (c == NUL)
3416 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003417 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003418
3419 // Update w_cline_height and w_cline_folded if the cursor line was
3420 // updated (saves a call to plines() later).
3421 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3422 {
3423 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003424 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003425#ifdef FEAT_FOLDING
3426 curwin->w_cline_folded = FALSE;
3427#endif
3428 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3429 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003430 break;
3431 }
3432
3433 // Show "extends" character from 'listchars' if beyond the line end and
3434 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003435 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003436 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003437 && wp->w_p_list
3438 && !wp->w_p_wrap
3439#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003440 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003441#endif
3442 && (
3443#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003444 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003445#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003446 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003447 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003448 || lcs_eol_one > 0
3449 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003450 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003451 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003452 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003453 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003454 mb_c = c;
3455 if (enc_utf8 && utf_char2len(c) > 1)
3456 {
3457 mb_utf8 = TRUE;
3458 u8cc[0] = 0;
3459 c = 0xc0;
3460 }
3461 else
3462 mb_utf8 = FALSE;
3463 }
3464
3465#ifdef FEAT_SYN_HL
3466 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003467 if (wlv.draw_color_col)
3468 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003469
3470 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3471 // highlight the cursor position itself.
3472 // Also highlight the 'colorcolumn' if it is different than
3473 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003474 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3475 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003476 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003477 if (((wlv.draw_state == WL_LINE
3478 || wlv.draw_state == WL_BRI
3479 || wlv.draw_state == WL_SBR)
3480 && !lnum_in_visual_area
3481 && search_attr == 0
3482 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003483# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003484 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003485# endif
3486 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003487 {
3488 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3489 && lnum != wp->w_cursor.lnum)
3490 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003491 vcol_save_attr = wlv.char_attr;
3492 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3493 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003494 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003495 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003496 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003497 vcol_save_attr = wlv.char_attr;
3498 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003499 }
3500 }
3501#endif
3502
3503 // Store character to be displayed.
3504 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003505 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003506 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003507 {
3508 // Store the character.
3509#if defined(FEAT_RIGHTLEFT)
3510 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3511 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003512 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003513 --wlv.off;
3514 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003515 }
3516#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003517 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003518 if (enc_dbcs == DBCS_JPNU)
3519 {
3520 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003521 ScreenLines[wlv.off] = 0x8e;
3522 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003523 }
3524 else if (enc_utf8)
3525 {
3526 if (mb_utf8)
3527 {
3528 int i;
3529
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003530 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003531 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003532 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003533 for (i = 0; i < Screen_mco; ++i)
3534 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003535 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003536 if (u8cc[i] == 0)
3537 break;
3538 }
3539 }
3540 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003541 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003542 }
3543 if (multi_attr)
3544 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003545 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003546 multi_attr = 0;
3547 }
3548 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003549 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003550
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003551 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003552
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003553 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3554 {
3555 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003556 ++wlv.off;
3557 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003558 if (enc_utf8)
3559 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003560 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003561 else
3562 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003563 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003564 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003565#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003566 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003567#endif
3568 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003569 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003570 // When "wlv.tocol" is halfway a character, set it to the end
3571 // of the character, otherwise highlighting won't stop.
3572 if (wlv.tocol == wlv.vcol)
3573 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003574
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003575 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003576
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003577#ifdef FEAT_RIGHTLEFT
3578 if (wp->w_p_rl)
3579 {
3580 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003581 --wlv.off;
3582 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003583 }
3584#endif
3585 }
3586#ifdef FEAT_RIGHTLEFT
3587 if (wp->w_p_rl)
3588 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003589 --wlv.off;
3590 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003591 }
3592 else
3593#endif
3594 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003595 ++wlv.off;
3596 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003597 }
3598 }
3599#ifdef FEAT_CONCEAL
3600 else if (wp->w_p_cole > 0 && is_concealing)
3601 {
3602 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003603 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003604 if (wlv.n_extra > 0)
3605 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003606 if (wp->w_p_wrap)
3607 {
3608 // Special voodoo required if 'wrap' is on.
3609 //
3610 // Advance the column indicator to force the line
3611 // drawing to wrap early. This will make the line
3612 // take up the same screen space when parts are concealed,
3613 // so that cursor line computations aren't messed up.
3614 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003615 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003616 // trailing junk to be written out of the screen line
3617 // we are building, 'boguscols' keeps track of the number
3618 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003619 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003620 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003621 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003622# ifdef FEAT_RIGHTLEFT
3623 if (wp->w_p_rl)
3624 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003625 wlv.col -= wlv.n_extra;
3626 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003627 }
3628 else
3629# endif
3630 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003631 wlv.col += wlv.n_extra;
3632 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003633 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003634 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003635 n_attr = 0;
3636 }
3637
3638
3639 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3640 {
3641 // Need to fill two screen columns.
3642# ifdef FEAT_RIGHTLEFT
3643 if (wp->w_p_rl)
3644 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003645 --wlv.boguscols;
3646 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003647 }
3648 else
3649# endif
3650 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003651 ++wlv.boguscols;
3652 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003653 }
3654 }
3655
3656# ifdef FEAT_RIGHTLEFT
3657 if (wp->w_p_rl)
3658 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003659 --wlv.boguscols;
3660 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003661 }
3662 else
3663# endif
3664 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003665 ++wlv.boguscols;
3666 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003667 }
3668 }
3669 else
3670 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003671 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003672 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003673 wlv.vcol += wlv.n_extra;
3674 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003675 n_attr = 0;
3676 }
3677 }
3678
3679 }
3680#endif // FEAT_CONCEAL
3681 else
3682 --n_skip;
3683
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003684 // Only advance the "wlv.vcol" when after the 'number' or
3685 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003686 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003687#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003688 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003689#endif
3690 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003691 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003692
3693#ifdef FEAT_SYN_HL
3694 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003695 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003696#endif
3697
3698 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003699 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3700 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003701
3702 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003703 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003704 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003705 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003706 if (n_attr_skip > 0)
3707 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003708
3709 // At end of screen line and there is more to come: Display the line
3710 // so far. If there is no more to display it is caught above.
3711 if ((
3712#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003713 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003714#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003715 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003716 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003717 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003718#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003719 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003720#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003721#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003722 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003723#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003724 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003725 && wlv.p_extra != at_end_str)
3726 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3727 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003728 )
3729 {
3730#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003731 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003732 wlv_screen_line(wp, &wlv, FALSE);
3733 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003734 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003735#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003736 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003737#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003738 ++wlv.row;
3739 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003740
3741 // When not wrapping and finished diff lines, or when displayed
3742 // '$' and highlighting until last column, break here.
3743 if ((!wp->w_p_wrap
3744#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003745 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003746#endif
3747#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003748 && !text_prop_above && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003749#endif
3750 ) || lcs_eol_one == -1)
3751 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003752#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003753 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003754 {
3755 // do not output more of the line, only the "below" prop
3756 ptr += STRLEN(ptr);
3757# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003758 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003759# endif
3760 }
3761#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003762
3763 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003764 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003765#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003766 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003767#endif
3768 )
3769 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003770 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3771 draw_vsep_win(wp, wlv.row);
3772 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003773 }
3774
3775 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003776 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003777 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003778 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003779 break;
3780 }
3781
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003782 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003783#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003784 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003785#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003786#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003787 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003788#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003789 && wp->w_width == Columns)
3790 {
3791 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003792 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003793
3794 // Special trick to make copy/paste of wrapped lines work with
3795 // xterm/screen: write an extra character beyond the end of
3796 // the line. This will work with all terminal types
3797 // (regardless of the xn,am settings).
3798 // Only do this on a fast tty.
3799 // Only do this if the cursor is on the current line
3800 // (something has been written in it).
3801 // Don't do this for the GUI.
3802 // Don't do this for double-width characters.
3803 // Don't do this for a window not at the right screen border.
3804 if (p_tf
3805#ifdef FEAT_GUI
3806 && !gui.in_use
3807#endif
3808 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003809 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3810 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003811 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003812 || (*mb_off2cells)(
3813 LineOffset[wlv.screen_row - 1]
3814 + (int)Columns - 2,
3815 LineOffset[wlv.screen_row]
3816 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003817 {
3818 // First make sure we are at the end of the screen line,
3819 // then output the same character again to let the
3820 // terminal know about the wrap. If the terminal doesn't
3821 // auto-wrap, we overwrite the character.
3822 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003823 screen_char(LineOffset[wlv.screen_row - 1]
3824 + (unsigned)Columns - 1,
3825 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003826
3827 // When there is a multi-byte character, just output a
3828 // space to keep it simple.
3829 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003830 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003831 out_char(' ');
3832 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003833 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003834 + (Columns - 1)]);
3835 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003836 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003837 screen_start(); // don't know where cursor is now
3838 }
3839 }
3840
Bram Moolenaar1306b362022-08-06 15:59:06 +01003841 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003842
Bram Moolenaareed9d462021-02-15 20:38:25 +01003843 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003844#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003845 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003846# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003847 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003848# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003849 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003850 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003851#endif
3852#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003853 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003854 // When the filler lines are actually below the last line of the
3855 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003856 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003857 break;
3858#endif
3859 }
3860
3861 } // for every character in the line
3862
3863#ifdef FEAT_SPELL
3864 // After an empty line check first word for capital.
3865 if (*skipwhite(line) == NUL)
3866 {
3867 capcol_lnum = lnum + 1;
3868 cap_col = 0;
3869 }
3870#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003871#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003872 vim_free(text_props);
3873 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003874 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003875#endif
3876
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003877 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003878 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003879}