blob: 79ce5140e95549bbf053fd926fc0a6c3d6c9ddd7 [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
159#ifdef FEAT_CMDWIN
160# define WL_CMDLINE (WL_START + 1) // cmdline window column
161#else
162# define WL_CMDLINE WL_START
163#endif
164#ifdef FEAT_FOLDING
165# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
166#else
167# define WL_FOLD WL_CMDLINE
168#endif
169#ifdef FEAT_SIGNS
170# define WL_SIGN (WL_FOLD + 1) // column for signs
171#else
172# define WL_SIGN WL_FOLD // column for signs
173#endif
174#define WL_NR (WL_SIGN + 1) // line number
175#ifdef FEAT_LINEBREAK
176# define WL_BRI (WL_NR + 1) // 'breakindent'
177#else
178# define WL_BRI WL_NR
179#endif
180#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
181# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
182#else
183# define WL_SBR WL_BRI
184#endif
185#define WL_LINE (WL_SBR + 1) // text in the line
186
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100187#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200188/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000189 * Return TRUE if CursorLineSign highlight is to be used.
190 */
191 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100192use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000193{
194 return wp->w_p_cul
195 && lnum == wp->w_cursor.lnum
196 && (wp->w_p_culopt_flags & CULOPT_NBR);
197}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100198#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000199
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100200
201#ifdef FEAT_FOLDING
202/*
203 * Setup for drawing the 'foldcolumn', if there is one.
204 */
205 static void
206handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
207{
208 int fdc = compute_foldcolumn(wp, 0);
209
210 if (fdc <= 0)
211 return;
212
213 // Allocate a buffer, "wlv->extra[]" may already be in use.
214 vim_free(wlv->p_extra_free);
215 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
216 if (wlv->p_extra_free != NULL)
217 {
218 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
219 wp, FALSE, wlv->lnum);
220 wlv->p_extra_free[wlv->n_extra] = NUL;
221 wlv->p_extra = wlv->p_extra_free;
222 wlv->c_extra = NUL;
223 wlv->c_final = NUL;
224 if (use_cursor_line_highlight(wp, wlv->lnum))
225 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
226 else
227 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
228 }
229}
230#endif
231
232#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000233/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100234 * Get information needed to display the sign in line "wlv->lnum" in window
235 * "wp".
236 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200237 * Otherwise the sign is going to be displayed in the sign column.
238 */
239 static void
240get_sign_display_info(
241 int nrcol,
242 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100243 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200244{
245 int text_sign;
246# ifdef FEAT_SIGN_ICONS
247 int icon_sign;
248# endif
249
250 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100251 wlv->c_extra = ' ';
252 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200253 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100254 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200255 else
256 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100257 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100258 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000259 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100260 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100261 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200262 }
263
Bram Moolenaar1306b362022-08-06 15:59:06 +0100264 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200265#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100266 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200267#endif
268 )
269 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100270 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200271# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100272 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200273 if (gui.in_use && icon_sign != 0)
274 {
275 // Use the image in this position.
276 if (nrcol)
277 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100278 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100279 sprintf((char *)wlv->extra, "%-*c ",
280 number_width(wp), SIGN_BYTE);
281 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100282 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200283 }
284 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100285 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200286# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100287 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
288 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200289 {
290 if (nrcol)
291 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100292 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100293 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200294 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100295 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100296 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200297 }
298 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100299 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200300 }
301# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100302 wlv->c_final = NUL;
303 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200304 }
305 else
306# endif
307 if (text_sign != 0)
308 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100309 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100310 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200311 {
312 if (nrcol)
313 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100314 int width = number_width(wp) - 2;
315 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200316
317 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100318 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100319 vim_snprintf((char *)wlv->extra + n,
320 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100321 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200322 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100323 wlv->c_extra = NUL;
324 wlv->c_final = NUL;
325 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200326 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000327
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100328 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100329 && wlv->sattr.sat_culhl > 0)
330 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000331 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100332 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200333 }
334 }
335}
336#endif
337
Bram Moolenaard7657e92022-09-20 18:59:30 +0100338/*
339 * Display the absolute or relative line number. After the first row fill with
340 * blanks when the 'n' flag isn't in 'cpo'.
341 */
342 static void
343handle_lnum_col(
344 win_T *wp,
345 winlinevars_T *wlv,
346 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100347 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100348{
349 if ((wp->w_p_nu || wp->w_p_rnu)
350 && (wlv->row == wlv->startrow + wlv->filler_lines
351 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
352 {
353#ifdef FEAT_SIGNS
354 // If 'signcolumn' is set to 'number' and a sign is present
355 // in 'lnum', then display the sign instead of the line
356 // number.
357 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
358 get_sign_display_info(TRUE, wp, wlv);
359 else
360#endif
361 {
362 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100363 // When there are text properties above the line put the line number
364 // below them.
365 if (wlv->row == wlv->startrow + wlv->filler_lines
366#ifdef FEAT_PROP_POPUP
367 + wlv->text_prop_above_count
Bram Moolenaard7657e92022-09-20 18:59:30 +0100368#endif
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100369 )
370 {
371 long num;
372 char *fmt = "%*ld ";
373
374 if (wp->w_p_nu && !wp->w_p_rnu)
375 // 'number' + 'norelativenumber'
376 num = (long)wlv->lnum;
377 else
378 {
379 // 'relativenumber', don't use negative numbers
380 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
381 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
382 {
383 // 'number' + 'relativenumber'
384 num = wlv->lnum;
385 fmt = "%-*ld ";
386 }
387 }
388
389 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100390 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100391 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
392 ++wlv->p_extra)
393 *wlv->p_extra = '-';
394#ifdef FEAT_RIGHTLEFT
395 if (wp->w_p_rl) // reverse line numbers
396 {
397 char_u *p1, *p2;
398 int t;
399
400 // like rl_mirror(), but keep the space at the end
401 p2 = skipwhite(wlv->extra);
402 p2 = skiptowhite(p2) - 1;
403 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
404 {
405 t = *p1;
406 *p1 = *p2;
407 *p2 = t;
408 }
409 }
410#endif
411 wlv->p_extra = wlv->extra;
412 wlv->c_extra = NUL;
413 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100414 }
415 else
416 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100417 wlv->c_extra = ' ';
418 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100419 }
420 wlv->n_extra = number_width(wp) + 1;
421 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
422#ifdef FEAT_SYN_HL
423 // When 'cursorline' is set highlight the line number of
424 // the current line differently.
425 // When 'cursorlineopt' does not have "line" only
426 // highlight the line number itself.
427 // TODO: Can we use CursorLine instead of CursorLineNr
428 // when CursorLineNr isn't set?
429 if (wp->w_p_cul
430 && wlv->lnum == wp->w_cursor.lnum
431 && (wp->w_p_culopt_flags & CULOPT_NBR)
432 && (wlv->row == wlv->startrow + wlv->filler_lines
433 || (wlv->row > wlv->startrow + wlv->filler_lines
434 && (wp->w_p_culopt_flags & CULOPT_LINE))))
435 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
436#endif
437 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
438 && HL_ATTR(HLF_LNA) != 0)
439 // Use LineNrAbove
440 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
441 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
442 && HL_ATTR(HLF_LNB) != 0)
443 // Use LineNrBelow
444 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
445 }
446#ifdef FEAT_SIGNS
447 if (num_attr)
448 wlv->char_attr = num_attr;
449#endif
450 }
451}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100452
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100453#ifdef FEAT_LINEBREAK
454 static void
455handle_breakindent(win_T *wp, winlinevars_T *wlv)
456{
457 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
458 && *get_showbreak_value(wp) != NUL)
459 // draw indent after showbreak value
460 wlv->draw_state = WL_BRI;
461 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
462 // After the showbreak, draw the breakindent
463 wlv->draw_state = WL_BRI - 1;
464
465 // draw 'breakindent': indent wrapped text accordingly
466 if (wlv->draw_state == WL_BRI - 1)
467 {
468 wlv->draw_state = WL_BRI;
469 // if wlv->need_showbreak is set, breakindent also applies
470 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
471# ifdef FEAT_DIFF
472 && wlv->filler_lines == 0
473# endif
474# ifdef FEAT_PROP_POPUP
475 && !wlv->dont_use_showbreak
476# endif
477 )
478 {
479 wlv->char_attr = 0;
480# ifdef FEAT_DIFF
481 if (wlv->diff_hlf != (hlf_T)0)
482 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
483# endif
484 wlv->p_extra = NULL;
485 wlv->c_extra = ' ';
486 wlv->c_final = NUL;
487 wlv->n_extra = get_breakindent_win(wp,
488 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
489 if (wlv->row == wlv->startrow)
490 {
491 wlv->n_extra -= win_col_off2(wp);
492 if (wlv->n_extra < 0)
493 wlv->n_extra = 0;
494 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100495 if (wp->w_skipcol > 0 && wlv->startrow == 0
496 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100497 wlv->need_showbreak = FALSE;
498 // Correct end of highlighted area for 'breakindent',
499 // required when 'linebreak' is also set.
500 if (wlv->tocol == wlv->vcol)
501 wlv->tocol += wlv->n_extra;
502 }
503 }
504}
505#endif
506
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100507#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
508 static void
509handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
510{
511# ifdef FEAT_DIFF
512 if (wlv->filler_todo > 0)
513 {
514 // Draw "deleted" diff line(s).
515 if (char2cells(wp->w_fill_chars.diff) > 1)
516 {
517 wlv->c_extra = '-';
518 wlv->c_final = NUL;
519 }
520 else
521 {
522 wlv->c_extra = wp->w_fill_chars.diff;
523 wlv->c_final = NUL;
524 }
525# ifdef FEAT_RIGHTLEFT
526 if (wp->w_p_rl)
527 wlv->n_extra = wlv->col + 1;
528 else
529# endif
530 wlv->n_extra = wp->w_width - wlv->col;
531 wlv->char_attr = HL_ATTR(HLF_DED);
532 }
533# endif
534
535# ifdef FEAT_LINEBREAK
536 char_u *sbr = get_showbreak_value(wp);
537 if (*sbr != NUL && wlv->need_showbreak)
538 {
539 // Draw 'showbreak' at the start of each broken line.
540 wlv->p_extra = sbr;
541 wlv->c_extra = NUL;
542 wlv->c_final = NUL;
543 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100544 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100545 wlv->need_showbreak = FALSE;
546 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
547 // Correct end of highlighted area for 'showbreak',
548 // required when 'linebreak' is also set.
549 if (wlv->tocol == wlv->vcol)
550 wlv->tocol += wlv->n_extra;
551 // combine 'showbreak' with 'wincolor'
552 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
553# ifdef FEAT_SYN_HL
554 // combine 'showbreak' with 'cursorline'
555 if (wlv->cul_attr != 0)
556 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
557# endif
558 }
559# endif
560}
561#endif
562
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100563#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100564/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100565 * Return the cell size of virtual text after truncation.
566 */
567 static int
568textprop_size_after_trunc(
569 win_T *wp,
570 int flags, // TP_FLAG_ALIGN_*
571 int added,
572 char_u *text,
573 int *n_used_ptr)
574{
575 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
576 ? wp->w_width : added;
577 int len = (int)STRLEN(text);
578 int strsize = 0;
579 int n_used;
580
581 // if the remaining size is to small wrap anyway and use the next line
582 if (space < PROP_TEXT_MIN_CELLS)
583 space += wp->w_width;
584 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
585 {
586 int clen = ptr2cells(text + n_used);
587
588 if (strsize + clen > space)
589 break;
590 strsize += clen;
591 }
592 *n_used_ptr = n_used;
593 return strsize;
594}
595
596/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100597 * Take care of padding, right-align and truncation of virtual text after a
598 * line.
599 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
600 * padding, right-align and truncation. Otherwise only the size is computed.
601 * When "n_attr" is NULL returns the number of screen cells used.
602 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100603 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100604 int
605text_prop_position(
606 win_T *wp,
607 textprop_T *tp,
608 int vcol, // current screen column
609 int *n_extra, // nr of bytes for virtual text
610 char_u **p_extra, // virtual text
611 int *n_attr, // attribute cells, NULL if not used
612 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200613{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100614 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100615 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100616 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
617 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
618 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
619 ? tp->tp_len - 1 : 0;
620 int col_with_padding = vcol + (below ? 0 : padding);
621 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100622 int before = room; // spaces before the text
623 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100624 int n_used = *n_extra;
625 char_u *l = NULL;
626 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100627 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
628 tp->tp_flags, before, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200629
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100630 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100631 {
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100632 int col_off = win_col_off(wp) + win_col_off2(wp);
633 int skip_add = 0;
634
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100635 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100636 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100637 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100638 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100639 }
640 else
641 {
642 // Right-align: fill with before
643 if (right)
644 before -= cells;
645 if (before < 0
646 || !(right || below)
647 || (below
648 ? (col_with_padding == 0 || !wp->w_p_wrap)
649 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100650 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100651 if (right && (wrap || room < PROP_TEXT_MIN_CELLS))
652 {
653 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100654 before = wp->w_width - col_off - strsize + room;
655 if (before < 0)
656 before = 0;
657 else
658 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100659 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100660 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100661 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100662 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100663 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100664 else if (below && before > 0)
665 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100666 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100667 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100668
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100669 // With 'nowrap' add one to show the "extends" character if needed (it
670 // doesn't show if the text just fits).
671 if (!wp->w_p_wrap
672 && n_used < *n_extra
673 && wp->w_lcs_chars.ext != NUL
674 && wp->w_p_list)
675 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100676 if (!wp->w_p_wrap && below && padding > 0)
677 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100678
679 // add 1 for NUL, 2 for when '…' is used
680 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100681 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100682 if (n_attr == NULL || l != NULL)
683 {
684 int off = 0;
685
686 if (n_attr != NULL)
687 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100688 vim_memset(l, ' ', before);
689 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100690 if (padding > 0)
691 {
692 vim_memset(l + off, ' ', padding);
693 off += padding;
694 }
695 vim_strncpy(l + off, *p_extra, n_used);
696 off += n_used;
697 }
698 else
699 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100700 off = before + after + padding + n_used;
701 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100702 }
703 if (n_attr != NULL)
704 {
705 if (n_used < *n_extra && wp->w_p_wrap)
706 {
707 char_u *lp = l + off - 1;
708
709 if (has_mbyte)
710 {
711 // change last character to '…'
712 lp -= (*mb_head_off)(l, lp);
713 STRCPY(lp, "…");
714 n_used = lp - l + 3 - padding;
715 }
716 else
717 // change last character to '>'
718 *lp = '>';
719 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100720 else if (after > 0)
721 {
722 vim_memset(l + off, ' ', after);
723 l[off + after] = NUL;
724 }
725
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100726 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100727 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100728 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100729 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100730 *n_attr -= padding + after;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100731 *n_attr_skip = before + padding + skip_add;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100732 }
733 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100734 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100735
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100736 if (n_attr == NULL)
737 return cells;
738 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200739}
740#endif
741
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100742/*
743 * Called when finished with the line: draw the screen line and handle any
744 * highlighting until the right of the window.
745 */
746 static void
747draw_screen_line(win_T *wp, winlinevars_T *wlv)
748{
749#ifdef FEAT_SYN_HL
750 long v;
751
752 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
753 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100754 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100755 else
756 v = wp->w_leftcol;
757
758 // check if line ends before left margin
759 if (wlv->vcol < v + wlv->col - win_col_off(wp))
760 wlv->vcol = v + wlv->col - win_col_off(wp);
761# ifdef FEAT_CONCEAL
762 // Get rid of the boguscols now, we want to draw until the right
763 // edge for 'cursorcolumn'.
764 wlv->col -= wlv->boguscols;
765 wlv->boguscols = 0;
766# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
767# else
768# define VCOL_HLC (wlv->vcol)
769# endif
770
771 if (wlv->draw_color_col)
772 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
773
774 if (((wp->w_p_cuc
775 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
776 && (int)wp->w_virtcol <
777 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
778 && wlv->lnum != wp->w_cursor.lnum)
779 || wlv->draw_color_col
780 || wlv->win_attr != 0)
781# ifdef FEAT_RIGHTLEFT
782 && !wp->w_p_rl
783# endif
784 )
785 {
786 int rightmost_vcol = 0;
787 int i;
788
789 if (wp->w_p_cuc)
790 rightmost_vcol = wp->w_virtcol;
791 if (wlv->draw_color_col)
792 // determine rightmost colorcolumn to possibly draw
793 for (i = 0; wlv->color_cols[i] >= 0; ++i)
794 if (rightmost_vcol < wlv->color_cols[i])
795 rightmost_vcol = wlv->color_cols[i];
796
797 while (wlv->col < wp->w_width)
798 {
799 ScreenLines[wlv->off] = ' ';
800 if (enc_utf8)
801 ScreenLinesUC[wlv->off] = 0;
802 ScreenCols[wlv->off] = MAXCOL;
803 ++wlv->col;
804 if (wlv->draw_color_col)
805 wlv->draw_color_col = advance_color_col(
806 VCOL_HLC, &wlv->color_cols);
807
808 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
809 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
810 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
811 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
812 else
813 ScreenAttrs[wlv->off++] = wlv->win_attr;
814
815 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
816 break;
817
818 ++wlv->vcol;
819 }
820 }
821#endif
822
823 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
824 wp->w_width, wlv->screen_line_flags);
825 ++wlv->row;
826 ++wlv->screen_row;
827}
828#undef VCOL_HLC
829
830/*
831 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100832 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100833 */
834 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100835win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100836{
837 wlv->col = 0;
838 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
839
840#ifdef FEAT_RIGHTLEFT
841 if (wp->w_p_rl)
842 {
843 // Rightleft window: process the text in the normal direction, but put
844 // it in current_ScreenLine[] from right to left. Start at the
845 // rightmost column of the window.
846 wlv->col = wp->w_width - 1;
847 wlv->off += wlv->col;
848 wlv->screen_line_flags |= SLF_RIGHTLEFT;
849 }
850#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100851 if (save_extra)
852 {
853 // reset the drawing state for the start of a wrapped line
854 wlv->draw_state = WL_START;
855 wlv->saved_n_extra = wlv->n_extra;
856 wlv->saved_p_extra = wlv->p_extra;
857 wlv->saved_c_extra = wlv->c_extra;
858 wlv->saved_c_final = wlv->c_final;
859#ifdef FEAT_SYN_HL
860 if (!(wlv->cul_screenline
861# ifdef FEAT_DIFF
862 && wlv->diff_hlf == (hlf_T)0
863# endif
864 ))
865 wlv->saved_char_attr = wlv->char_attr;
866 else
867#endif
868 wlv->saved_char_attr = 0;
869 wlv->n_extra = 0;
870 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100871}
872
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200873/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100874 * Called when wlv->draw_state is set to WL_LINE.
875 */
876 static void
877win_line_continue(winlinevars_T *wlv)
878{
879 if (wlv->saved_n_extra > 0)
880 {
881 // Continue item from end of wrapped line.
882 wlv->n_extra = wlv->saved_n_extra;
883 wlv->c_extra = wlv->saved_c_extra;
884 wlv->c_final = wlv->saved_c_final;
885 wlv->p_extra = wlv->saved_p_extra;
886 wlv->char_attr = wlv->saved_char_attr;
887 }
888 else
889 wlv->char_attr = wlv->win_attr;
890}
891
892/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200893 * Display line "lnum" of window 'wp' on the screen.
894 * Start at row "startrow", stop when "endrow" is reached.
895 * wp->w_virtcol needs to be valid.
896 *
897 * Return the number of last row the line occupies.
898 */
899 int
900win_line(
901 win_T *wp,
902 linenr_T lnum,
903 int startrow,
904 int endrow,
905 int nochange UNUSED, // not updating for changed text
906 int number_only) // only update the number column
907{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100908 winlinevars_T wlv; // variables passed between functions
909
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200910 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100911 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200912 char_u *line; // current line
913 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200914
Bram Moolenaar1306b362022-08-06 15:59:06 +0100915#ifdef FEAT_PROP_POPUP
916 char_u *p_extra_free2 = NULL; // another p_extra to be freed
917#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200918 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000919#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000920 int in_linebreak = FALSE; // n_extra set for showing linebreak
921#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200922 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100923 // displaying eol at end-of-line
924 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000925 int lcs_prec_todo = wp->w_lcs_chars.prec;
926 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200927
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100928 int n_attr = 0; // chars with special attr
929 int n_attr_skip = 0; // chars to skip before using extra_attr
930 int saved_attr2 = 0; // char_attr saved for n_attr
931 int n_attr3 = 0; // chars with overruling special attr
932 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200933
934 int n_skip = 0; // nr of chars to skip for 'nowrap'
935
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200936 int fromcol_prev = -2; // start of inverting after cursor
937 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200938 int lnum_in_visual_area = FALSE;
939 pos_T pos;
940 long v;
941
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200942 int attr_pri = FALSE; // char_attr has priority
943 int area_highlighting = FALSE; // Visual or incsearch highlighting
944 // in this line
945 int vi_attr = 0; // attributes for Visual and incsearch
946 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200947 int area_attr = 0; // attributes desired by highlighting
948 int search_attr = 0; // attributes desired by 'hlsearch'
949#ifdef FEAT_SYN_HL
950 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
951 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200952 int prev_syntax_col = -1; // column of prev_syntax_attr
953 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200954 int has_syntax = FALSE; // this buffer has syntax highl.
955 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200956#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100957#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200958 int text_prop_count;
959 int text_prop_next = 0; // next text property to use
960 textprop_T *text_props = NULL;
961 int *text_prop_idxs = NULL;
962 int text_props_active = 0;
963 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +0100964 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200965 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +0100966 int text_prop_attr_comb = 0; // text_prop_attr combined with
967 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100968 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100969 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +0100970 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100971 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +0100972 int saved_search_attr = 0; // search_attr to be used when n_extra
973 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +0100974 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200975#endif
976#ifdef FEAT_SPELL
977 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000978 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200979# define SPWORDLEN 150
980 char_u nextline[SPWORDLEN * 2];// text with start of the next line
981 int nextlinecol = 0; // column where nextline[] starts
982 int nextline_idx = 0; // index in nextline[] where next line
983 // starts
984 int spell_attr = 0; // attributes desired by spelling
985 int word_end = 0; // last byte with same spell_attr
986 static linenr_T checked_lnum = 0; // line number for "checked_col"
987 static int checked_col = 0; // column in "checked_lnum" up to which
988 // there are no spell errors
989 static int cap_col = -1; // column to check for Cap word
990 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
991 int cur_checked_col = 0; // checked column for current line
992#endif
993 int extra_check = 0; // has extra highlighting
994 int multi_attr = 0; // attributes desired by multibyte
995 int mb_l = 1; // multi-byte byte length
996 int mb_c = 0; // decoded multi-byte character
997 int mb_utf8 = FALSE; // screen char is UTF-8 char
998 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200999#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001000 int change_start = MAXCOL; // first col of changed area
1001 int change_end = -1; // last col of changed area
1002#endif
1003 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001004 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001005 int in_multispace = FALSE; // in multiple consecutive spaces
1006 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001007#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
1008 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
1009# define LINE_ATTR
1010 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +01001011 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001012#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001013 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001014 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001015#ifdef FEAT_ARABIC
1016 int prev_c = 0; // previous Arabic character
1017 int prev_c1 = 0; // first composing char for prev_c
1018#endif
1019#if defined(LINE_ATTR)
1020 int did_line_attr = 0;
1021#endif
1022#ifdef FEAT_TERMINAL
1023 int get_term_attr = FALSE;
1024#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001025
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001026#ifdef FEAT_SYN_HL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001027 // margin columns for the screen line, needed for when 'cursorlineopt'
1028 // contains "screenline"
1029 int left_curline_col = 0;
1030 int right_curline_col = 0;
1031#endif
1032
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001033#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1034 int feedback_col = 0;
1035 int feedback_old_attr = -1;
1036#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001037
1038#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1039 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001040 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001041#endif
1042#ifdef FEAT_CONCEAL
1043 int syntax_flags = 0;
1044 int syntax_seqnr = 0;
1045 int prev_syntax_id = 0;
1046 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1047 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001048 int did_wcol = FALSE;
1049 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001050# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001051# define FIX_FOR_BOGUSCOLS \
1052 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001053 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001054 wlv.vcol -= wlv.vcol_off; \
1055 wlv.vcol_off = 0; \
1056 wlv.col -= wlv.boguscols; \
1057 old_boguscols = wlv.boguscols; \
1058 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001059 }
1060#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001061# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001062#endif
1063
1064 if (startrow > endrow) // past the end already!
1065 return startrow;
1066
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001067 CLEAR_FIELD(wlv);
1068
1069 wlv.lnum = lnum;
1070 wlv.startrow = startrow;
1071 wlv.row = startrow;
1072 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001073 wlv.fromcol = -10;
1074 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001075#ifdef FEAT_LINEBREAK
1076 wlv.vcol_sbr = -1;
1077#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001078
1079 if (!number_only)
1080 {
1081 // To speed up the loop below, set extra_check when there is linebreak,
1082 // trailing white space and/or syntax processing to be done.
1083#ifdef FEAT_LINEBREAK
1084 extra_check = wp->w_p_lbr;
1085#endif
1086#ifdef FEAT_SYN_HL
1087 if (syntax_present(wp) && !wp->w_s->b_syn_error
1088# ifdef SYN_TIME_LIMIT
1089 && !wp->w_s->b_syn_slow
1090# endif
1091 )
1092 {
1093 // Prepare for syntax highlighting in this line. When there is an
1094 // error, stop syntax highlighting.
1095 save_did_emsg = did_emsg;
1096 did_emsg = FALSE;
1097 syntax_start(wp, lnum);
1098 if (did_emsg)
1099 wp->w_s->b_syn_error = TRUE;
1100 else
1101 {
1102 did_emsg = save_did_emsg;
1103#ifdef SYN_TIME_LIMIT
1104 if (!wp->w_s->b_syn_slow)
1105#endif
1106 {
1107 has_syntax = TRUE;
1108 extra_check = TRUE;
1109 }
1110 }
1111 }
1112
1113 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001114 wlv.color_cols = wp->w_p_cc_cols;
1115 if (wlv.color_cols != NULL)
1116 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001117#endif
1118
1119#ifdef FEAT_TERMINAL
1120 if (term_show_buffer(wp->w_buffer))
1121 {
1122 extra_check = TRUE;
1123 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001124 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001125 }
1126#endif
1127
1128#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001129 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001130 {
1131 // Prepare for spell checking.
1132 has_spell = TRUE;
1133 extra_check = TRUE;
1134
1135 // Get the start of the next line, so that words that wrap to the
1136 // next line are found too: "et<line-break>al.".
1137 // Trick: skip a few chars for C/shell/Vim comments
1138 nextline[SPWORDLEN] = NUL;
1139 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1140 {
1141 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1142 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1143 }
1144
1145 // When a word wrapped from the previous line the start of the
1146 // current line is valid.
1147 if (lnum == checked_lnum)
1148 cur_checked_col = checked_col;
1149 checked_lnum = 0;
1150
1151 // When there was a sentence end in the previous line may require a
1152 // word starting with capital in this line. In line 1 always check
1153 // the first word.
1154 if (lnum != capcol_lnum)
1155 cap_col = -1;
1156 if (lnum == 1)
1157 cap_col = 0;
1158 capcol_lnum = 0;
1159 }
1160#endif
1161
1162 // handle Visual active in this window
1163 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1164 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001165 pos_T *top, *bot;
1166
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001167 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1168 {
1169 // Visual is after curwin->w_cursor
1170 top = &curwin->w_cursor;
1171 bot = &VIsual;
1172 }
1173 else
1174 {
1175 // Visual is before curwin->w_cursor
1176 top = &VIsual;
1177 bot = &curwin->w_cursor;
1178 }
1179 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1180 if (VIsual_mode == Ctrl_V)
1181 {
1182 // block mode
1183 if (lnum_in_visual_area)
1184 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001185 wlv.fromcol = wp->w_old_cursor_fcol;
1186 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001187 }
1188 }
1189 else
1190 {
1191 // non-block mode
1192 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001193 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001194 else if (lnum == top->lnum)
1195 {
1196 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001197 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001198 else
1199 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001200 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001201 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001202 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001203 }
1204 }
1205 if (VIsual_mode != 'V' && lnum == bot->lnum)
1206 {
1207 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1208 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001209 wlv.fromcol = -10;
1210 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001211 }
1212 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001213 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001214 else
1215 {
1216 pos = *bot;
1217 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001218 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1219 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001220 else
1221 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001222 getvvcol(wp, &pos, NULL, NULL,
1223 (colnr_T *)&wlv.tocol);
1224 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001225 }
1226 }
1227 }
1228 }
1229
1230 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001231 if (!highlight_match && lnum == curwin->w_cursor.lnum
1232 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001233#ifdef FEAT_GUI
1234 && !gui.in_use
1235#endif
1236 )
1237 noinvcur = TRUE;
1238
1239 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001240 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001241 {
1242 area_highlighting = TRUE;
1243 vi_attr = HL_ATTR(HLF_V);
1244#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1245 if ((clip_star.available && !clip_star.owned
1246 && clip_isautosel_star())
1247 || (clip_plus.available && !clip_plus.owned
1248 && clip_isautosel_plus()))
1249 vi_attr = HL_ATTR(HLF_VNC);
1250#endif
1251 }
1252 }
1253
1254 // handle 'incsearch' and ":s///c" highlighting
1255 else if (highlight_match
1256 && wp == curwin
1257 && lnum >= curwin->w_cursor.lnum
1258 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1259 {
1260 if (lnum == curwin->w_cursor.lnum)
1261 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001262 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001263 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001264 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001265 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1266 {
1267 pos.lnum = lnum;
1268 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001269 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001270 }
1271 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001272 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001273 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001274 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1275 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001276 area_highlighting = TRUE;
1277 vi_attr = HL_ATTR(HLF_I);
1278 }
1279 }
1280
1281#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001282 wlv.filler_lines = diff_check(wp, lnum);
1283 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001284 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001285 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001286 {
1287 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001288 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001289 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001290 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001291 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001292 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001293 }
1294 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001295 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001296 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001297 area_highlighting = TRUE;
1298 }
1299 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001300 wlv.filler_lines = wp->w_topfill;
1301 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001302#endif
1303
1304#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001305 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001306 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001307 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001308#endif
1309
1310#ifdef LINE_ATTR
1311# ifdef FEAT_SIGNS
1312 // If this line has a sign with line highlighting set line_attr.
1313 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001314 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001315# endif
1316# if defined(FEAT_QUICKFIX)
1317 // Highlight the current line in the quickfix window.
1318 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1319 line_attr = HL_ATTR(HLF_QFL);
1320# endif
1321 if (line_attr != 0)
1322 area_highlighting = TRUE;
1323#endif
1324
1325 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1326 ptr = line;
1327
1328#ifdef FEAT_SPELL
1329 if (has_spell && !number_only)
1330 {
1331 // For checking first word with a capital skip white space.
1332 if (cap_col == 0)
1333 cap_col = getwhitecols(line);
1334
1335 // To be able to spell-check over line boundaries copy the end of the
1336 // current line into nextline[]. Above the start of the next line was
1337 // copied to nextline[SPWORDLEN].
1338 if (nextline[SPWORDLEN] == NUL)
1339 {
1340 // No next line or it is empty.
1341 nextlinecol = MAXCOL;
1342 nextline_idx = 0;
1343 }
1344 else
1345 {
1346 v = (long)STRLEN(line);
1347 if (v < SPWORDLEN)
1348 {
1349 // Short line, use it completely and append the start of the
1350 // next line.
1351 nextlinecol = 0;
1352 mch_memmove(nextline, line, (size_t)v);
1353 STRMOVE(nextline + v, nextline + SPWORDLEN);
1354 nextline_idx = v + 1;
1355 }
1356 else
1357 {
1358 // Long line, use only the last SPWORDLEN bytes.
1359 nextlinecol = v - SPWORDLEN;
1360 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1361 nextline_idx = SPWORDLEN + 1;
1362 }
1363 }
1364 }
1365#endif
1366
1367 if (wp->w_p_list)
1368 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001369 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001370 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001371 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001372 || wp->w_lcs_chars.trail
1373 || wp->w_lcs_chars.lead
1374 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001375 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001376
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001377 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001378 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001379 {
1380 trailcol = (colnr_T)STRLEN(ptr);
1381 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1382 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001383 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001384 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001385 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001386 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001387 {
1388 leadcol = 0;
1389 while (VIM_ISWHITE(ptr[leadcol]))
1390 ++leadcol;
1391 if (ptr[leadcol] == NUL)
1392 // in a line full of spaces all of them are treated as trailing
1393 leadcol = (colnr_T)0;
1394 else
1395 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001396 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001397 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001398 }
1399
Bram Moolenaard7657e92022-09-20 18:59:30 +01001400 wlv.wcr_attr = get_wcr_attr(wp);
1401 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001402 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001403 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001404 area_highlighting = TRUE;
1405 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001406
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001407#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001408 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001409 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001410#endif
1411
1412 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1413 // first character to be displayed.
1414 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001415 v = startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001416 else
1417 v = wp->w_leftcol;
1418 if (v > 0 && !number_only)
1419 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001420 char_u *prev_ptr = ptr;
1421 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001422 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001423
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001424 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001425 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001426 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001427 charsize = win_lbr_chartabsize(&cts, NULL);
1428 cts.cts_vcol += charsize;
1429 prev_ptr = cts.cts_ptr;
1430 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001431 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001432 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001433 ptr = cts.cts_ptr;
1434 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001435
1436 // When:
1437 // - 'cuc' is set, or
1438 // - 'colorcolumn' is set, or
1439 // - 'virtualedit' is set, or
1440 // - the visual mode is active,
1441 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001442 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001443#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001444 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001445#endif
1446 virtual_active() ||
1447 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001448 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001449
1450 // Handle a character that's not completely on the screen: Put ptr at
1451 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001452 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001453 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001454 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001455 ptr = prev_ptr;
1456 // If the character fits on the screen, don't need to skip it.
1457 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001458 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1459 && wlv.col == 0)
1460 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001461 }
1462
1463 // Adjust for when the inverted text is before the screen,
1464 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001465 if (wlv.tocol <= wlv.vcol)
1466 wlv.fromcol = 0;
1467 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1468 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001469
1470#ifdef FEAT_LINEBREAK
1471 // When w_skipcol is non-zero, first line needs 'showbreak'
1472 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001473 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001474#endif
1475#ifdef FEAT_SPELL
1476 // When spell checking a word we need to figure out the start of the
1477 // word and if it's badly spelled or not.
1478 if (has_spell)
1479 {
1480 int len;
1481 colnr_T linecol = (colnr_T)(ptr - line);
1482 hlf_T spell_hlf = HLF_COUNT;
1483
1484 pos = wp->w_cursor;
1485 wp->w_cursor.lnum = lnum;
1486 wp->w_cursor.col = linecol;
1487 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1488
1489 // spell_move_to() may call ml_get() and make "line" invalid
1490 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1491 ptr = line + linecol;
1492
1493 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1494 {
1495 // no bad word found at line start, don't check until end of a
1496 // word
1497 spell_hlf = HLF_COUNT;
1498 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1499 }
1500 else
1501 {
1502 // bad word found, use attributes until end of word
1503 word_end = wp->w_cursor.col + len + 1;
1504
1505 // Turn index into actual attributes.
1506 if (spell_hlf != HLF_COUNT)
1507 spell_attr = highlight_attr[spell_hlf];
1508 }
1509 wp->w_cursor = pos;
1510
1511# ifdef FEAT_SYN_HL
1512 // Need to restart syntax highlighting for this line.
1513 if (has_syntax)
1514 syntax_start(wp, lnum);
1515# endif
1516 }
1517#endif
1518 }
1519
1520 // Correct highlighting for cursor that can't be disabled.
1521 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001522 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001523 {
1524 if (noinvcur)
1525 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001526 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001527 {
1528 // highlighting starts at cursor, let it start just after the
1529 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001530 fromcol_prev = wlv.fromcol;
1531 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001532 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001533 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001534 // restart highlighting after the cursor
1535 fromcol_prev = wp->w_virtcol;
1536 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001537 if (wlv.fromcol >= wlv.tocol)
1538 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001539 }
1540
1541#ifdef FEAT_SEARCH_EXTRA
1542 if (!number_only)
1543 {
1544 v = (long)(ptr - line);
1545 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1546 &line, &screen_search_hl,
1547 &search_attr);
1548 ptr = line + v; // "line" may have been updated
1549 }
1550#endif
1551
1552#ifdef FEAT_SYN_HL
1553 // Cursor line highlighting for 'cursorline' in the current window.
1554 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1555 {
1556 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001557 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001558 if (!(wp == curwin && VIsual_active)
1559 && wp->w_p_culopt_flags != CULOPT_NBR)
1560 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001561 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001562 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1563
1564 // Only set line_attr here when "screenline" is not present in
1565 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001566 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001567 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001568 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001569# ifdef FEAT_SIGNS
1570 // Combine the 'cursorline' and sign highlighting, depending on
1571 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001572 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001573 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001574 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001575 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001576 else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001577 line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001578 }
1579 else
1580# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001581# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001582 // let the line attribute overrule 'cursorline', otherwise
1583 // it disappears when both have background set;
1584 // 'cursorline' can use underline or bold to make it show
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001585 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001586# else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001587 line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001588# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001589 }
1590 else
1591 {
1592 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001593 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1594 }
1595 area_highlighting = TRUE;
1596 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001597 }
1598#endif
1599
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001600#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001601 {
1602 char_u *prop_start;
1603
1604 text_prop_count = get_text_props(wp->w_buffer, lnum,
1605 &prop_start, FALSE);
1606 if (text_prop_count > 0)
1607 {
1608 // Make a copy of the properties, so that they are properly
1609 // aligned.
1610 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1611 if (text_props != NULL)
1612 mch_memmove(text_props, prop_start,
1613 text_prop_count * sizeof(textprop_T));
1614
1615 // Allocate an array for the indexes.
1616 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001617 if (text_prop_idxs == NULL)
1618 VIM_CLEAR(text_props);
1619
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001620 if (text_props != NULL)
1621 {
1622 area_highlighting = TRUE;
1623 extra_check = TRUE;
1624 for (int i = 0; i < text_prop_count; ++i)
1625 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1626 ++wlv.text_prop_above_count;
1627 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001628 }
1629 }
1630#endif
1631
Bram Moolenaar1306b362022-08-06 15:59:06 +01001632 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001633
1634 // Repeat for the whole displayed line.
1635 for (;;)
1636 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001637 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001638#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001639 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001640#endif
1641#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001642 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001643#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001644
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001645 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001646 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001647 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001648#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001649 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001650 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001651 wlv.cul_attr = 0;
zeertzjq4f33bc22021-08-05 17:57:02 +02001652 line_attr = line_attr_save;
1653 }
1654#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001655#ifdef FEAT_CMDWIN
Bram Moolenaar1306b362022-08-06 15:59:06 +01001656 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001657 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001658 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001659 if (cmdwin_type != 0 && wp == curwin)
1660 {
1661 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001662 wlv.n_extra = 1;
1663 wlv.c_extra = cmdwin_type;
1664 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001665 wlv.char_attr =
1666 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001667 }
1668 }
1669#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001670#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001671 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001672 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001673 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001674 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001675 }
1676#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001677#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001678 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001679 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001680 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001681 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001682 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001683 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001684 }
1685#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001686 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001687 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001688 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001689 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001690 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001691 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001692#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001693 // Check if 'breakindent' applies and show it.
1694 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1695 if (wlv.n_extra == 0)
1696 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001697#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001698#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001699 if (wlv.draw_state == WL_SBR - 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_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001702 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001703 }
1704#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001705 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001706 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001707 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001708 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001709 }
1710 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001711
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001712#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001713 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001714 && wlv.vcol >= left_curline_col
1715 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001716 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001717 wlv.cul_attr = HL_ATTR(HLF_CUL);
1718 line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001719 }
1720#endif
1721
1722 // When still displaying '$' of change command, stop at cursor.
1723 // When only displaying the (relative) line number and that's done,
1724 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001725 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001726 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001727 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001728#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001729 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001730#endif
1731 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001732 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001733 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col, -wp->w_width,
1734 wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001735 // Pretend we have finished updating the window. Except when
1736 // 'cursorcolumn' is set.
1737#ifdef FEAT_SYN_HL
1738 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001739 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001740 else
1741#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001742 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001743 break;
1744 }
1745
Bram Moolenaar1306b362022-08-06 15:59:06 +01001746 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001747 {
1748 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001749 if (wlv.vcol == wlv.fromcol
1750 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1751 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001752 && (*mb_ptr2cells)(ptr) > 1)
1753 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001754 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001755 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001756 area_attr = vi_attr; // start highlighting
1757 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001758 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001759 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001760 area_attr = 0; // stop highlighting
1761
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001762#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001763 if (text_props != NULL)
1764 {
1765 int pi;
1766 int bcol = (int)(ptr - line);
1767
Bram Moolenaar1306b362022-08-06 15:59:06 +01001768 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001769# ifdef FEAT_LINEBREAK
1770 && !in_linebreak
1771# endif
1772 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001773 --bcol; // still working on the previous char, e.g. Tab
1774
1775 // Check if any active property ends.
1776 for (pi = 0; pi < text_props_active; ++pi)
1777 {
1778 int tpi = text_prop_idxs[pi];
1779
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001780 if (text_props[tpi].tp_col != MAXCOL
1781 && bcol >= text_props[tpi].tp_col - 1
1782 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001783 {
1784 if (pi + 1 < text_props_active)
1785 mch_memmove(text_prop_idxs + pi,
1786 text_prop_idxs + pi + 1,
1787 sizeof(int)
1788 * (text_props_active - (pi + 1)));
1789 --text_props_active;
1790 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001791# ifdef FEAT_LINEBREAK
1792 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001793 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001794 syntax_attr = 0;
1795# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001796 }
1797 }
1798
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001799# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001800 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001801 // not on the next char yet, don't start another prop
1802 --bcol;
1803# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001804 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001805 // With 'nowrap' and not in the first screen line only "below"
1806 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001807 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001808 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001809 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001810 && (wp->w_p_wrap
1811 || wlv.row == startrow
1812 || (text_props[text_prop_next].tp_flags
1813 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001814 || (bcol == 0 &&
1815 (text_props[text_prop_next].tp_flags
1816 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001817 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001818 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001819 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001820 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1821 {
1822 // first display the '$' after the line
1823 text_prop_follows = TRUE;
1824 break;
1825 }
1826 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001827 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001828 + text_props[text_prop_next].tp_len)
1829 text_prop_idxs[text_props_active++] = text_prop_next;
1830 ++text_prop_next;
1831 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001832
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001833 if (wlv.n_extra == 0 || !extra_for_textprop)
1834 {
1835 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001836 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001837 text_prop_flags = 0;
1838 text_prop_type = NULL;
1839 text_prop_id = 0;
1840 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001841 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001842 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001843 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001844 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001845 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001846
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001847 // Sort the properties on priority and/or starting last.
1848 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001849 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001850 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001851 sort_text_props(wp->w_buffer, text_props,
1852 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001853
1854 for (pi = 0; pi < text_props_active; ++pi)
1855 {
1856 int tpi = text_prop_idxs[pi];
1857 proptype_T *pt = text_prop_type_by_id(
1858 wp->w_buffer, text_props[tpi].tp_type);
1859
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001860 if (pt != NULL && (pt->pt_hl_id > 0
1861 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001862 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001863 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001864 if (pt->pt_hl_id > 0)
1865 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001866 text_prop_type = pt;
1867 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001868 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001869 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001870 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001871 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001872 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001873 }
1874 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001875 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001876 && -text_prop_id
1877 <= wp->w_buffer->b_textprop_text.ga_len)
1878 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001879 textprop_T *tp = &text_props[used_tpi];
1880 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001881 ->b_textprop_text.ga_data)[
1882 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001883 int above = (tp->tp_flags
1884 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001885
1886 // reset the ID in the copy to avoid it being used
1887 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001888 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001889
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001890 if (p != NULL)
1891 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001892 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001893 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001894 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001895 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001896 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1897 int padding = tp->tp_col == MAXCOL
1898 && tp->tp_len > 1
1899 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001900
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001901 // Insert virtual text before the current
1902 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001903 wlv.p_extra = p;
1904 wlv.c_extra = NUL;
1905 wlv.c_final = NUL;
1906 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001907 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001908 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001909 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001910 // restore search_attr and area_attr when n_extra
1911 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001912 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001913 saved_area_attr = area_attr;
1914 search_attr = 0;
1915 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001916 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001917 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001918 if (*ptr == NUL)
1919 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001920 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001921#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001922 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001923 {
1924 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001925 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001926 wlv.need_showbreak = FALSE;
1927 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001928 }
1929#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001930 if ((right || above || below || !wrap
1931 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001932 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001933 char_u *prev_p_extra = wlv.p_extra;
1934 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001935
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001936 // Take care of padding, right-align and
1937 // truncation.
1938 // Shared with win_lbr_chartabsize(), must do
1939 // exactly the same.
1940 start_line = text_prop_position(wp, tp,
1941 wlv.col,
1942 &wlv.n_extra, &wlv.p_extra,
1943 &n_attr, &n_attr_skip);
1944 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001945 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001946 // wlv.p_extra was allocated
1947 vim_free(p_extra_free2);
1948 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001949 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001950
Bram Moolenaara4abe512022-09-15 19:44:09 +01001951 if (lcs_eol_one < 0 && wlv.col
1952 + wlv.n_extra - 2 > wp->w_width)
1953 // don't bail out at end of line
1954 lcs_eol_one = 0;
1955
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001956 // When 'wrap' is off then for "below" we need
1957 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001958 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001959 {
1960 draw_screen_line(wp, &wlv);
1961
1962 // When line got too long for screen break
1963 // here.
1964 if (wlv.row == endrow)
1965 {
1966 ++wlv.row;
1967 break;
1968 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001969 win_line_start(wp, &wlv, TRUE);
1970 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001971 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001972 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001973 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001974
1975 // If another text prop follows the condition below at
1976 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001977 // If this is an "above" text prop and 'nowrap' the we
1978 // must wrap anyway.
1979 text_prop_above = above;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001980 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001981 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001982 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001983 else if (text_prop_next < text_prop_count
1984 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001985 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
1986 || (!wp->w_p_wrap
1987 && wlv.col == wp->w_width - 1
1988 && (text_props[text_prop_next].tp_flags
1989 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001990 // When at last-but-one character and a text property
1991 // follows after it, we may need to flush the line after
1992 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001993 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01001994 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001995 }
1996#endif
1997
Bram Moolenaare38fc862022-08-11 17:24:50 +01001998#ifdef FEAT_SEARCH_EXTRA
1999 if (wlv.n_extra == 0)
2000 {
2001 // Check for start/end of 'hlsearch' and other matches.
2002 // After end, check for start/end of next match.
2003 // When another match, have to check for start again.
2004 v = (long)(ptr - line);
2005 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2006 &screen_search_hl, &has_match_conc,
2007 &match_conc, did_line_attr, lcs_eol_one,
2008 &on_last_col);
2009 ptr = line + v; // "line" may have been changed
2010 prev_ptr = ptr;
2011
2012 // Do not allow a conceal over EOL otherwise EOL will be missed
2013 // and bad things happen.
2014 if (*ptr == NUL)
2015 has_match_conc = 0;
2016 }
2017#endif
2018
2019#ifdef FEAT_DIFF
2020 if (wlv.diff_hlf != (hlf_T)0)
2021 {
2022 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2023 && wlv.n_extra == 0)
2024 wlv.diff_hlf = HLF_TXD; // changed text
2025 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2026 && wlv.n_extra == 0)
2027 wlv.diff_hlf = HLF_CHD; // changed line
2028 line_attr = HL_ATTR(wlv.diff_hlf);
2029 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2030 && wp->w_p_culopt_flags != CULOPT_NBR
2031 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2032 && wlv.vcol <= right_curline_col)))
2033 line_attr = hl_combine_attr(
2034 line_attr, HL_ATTR(HLF_CUL));
2035 }
2036#endif
2037
Bram Moolenaara74fda62019-10-19 17:38:03 +02002038#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002039 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002040 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002041 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002042# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002043 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002044 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002045# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002046 // Get syntax attribute.
2047 if (has_syntax)
2048 {
2049 // Get the syntax attribute for the character. If there
2050 // is an error, disable syntax highlighting.
2051 save_did_emsg = did_emsg;
2052 did_emsg = FALSE;
2053
2054 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002055 if (v == prev_syntax_col)
2056 // at same column again
2057 syntax_attr = prev_syntax_attr;
2058 else
2059 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002060# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002061 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002062# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002063 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002064# ifdef FEAT_SPELL
2065 has_spell ? &can_spell :
2066# endif
2067 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002068 prev_syntax_col = v;
2069 prev_syntax_attr = syntax_attr;
2070 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002071
Bram Moolenaar34390282019-10-16 14:38:26 +02002072 if (did_emsg)
2073 {
2074 wp->w_s->b_syn_error = TRUE;
2075 has_syntax = FALSE;
2076 syntax_attr = 0;
2077 }
2078 else
2079 did_emsg = save_did_emsg;
2080# ifdef SYN_TIME_LIMIT
2081 if (wp->w_s->b_syn_slow)
2082 has_syntax = FALSE;
2083# endif
2084
2085 // Need to get the line again, a multi-line regexp may
2086 // have made it invalid.
2087 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2088 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002089 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002090# ifdef FEAT_CONCEAL
2091 // no concealing past the end of the line, it interferes
2092 // with line highlighting
2093 if (*ptr == NUL)
2094 syntax_flags = 0;
2095 else
2096 syntax_flags = get_syntax_info(&syntax_seqnr);
2097# endif
2098 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002099 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002100# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002101 // Combine text property highlight into syntax highlight.
2102 if (text_prop_type != NULL)
2103 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002104 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002105 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2106 else
2107 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002108 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002109 }
2110# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002111#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002112
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002113 // Decide which of the highlight attributes to use.
2114 attr_pri = TRUE;
2115#ifdef LINE_ATTR
2116 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002117 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002118 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002119 if (!highlight_match)
2120 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002121 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002122# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002123 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002124# endif
2125 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002126 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002127 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002128 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002129# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002130 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002131# endif
2132 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002133 else if (line_attr != 0
2134 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2135 || wlv.vcol < wlv.fromcol
2136 || vcol_prev < fromcol_prev
2137 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002138 {
2139 // Use line_attr when not in the Visual or 'incsearch' area
2140 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002141# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002142 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002143# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002144 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002145# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002146 attr_pri = FALSE;
2147 }
2148#else
2149 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002150 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002151 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002152 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002153#endif
2154 else
2155 {
2156 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002157#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002158 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002159#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002160 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002161#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002162 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002163#ifdef FEAT_PROP_POPUP
2164 // override with text property highlight when "override" is TRUE
2165 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002166 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002167#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002168 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002169
2170 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002171 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002172 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002173 if (wlv.char_attr == 0)
2174 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002175 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002176 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002177 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002178
2179 // Get the next character to put on the screen.
2180
2181 // The "p_extra" points to the extra stuff that is inserted to
2182 // represent special characters (non-printable stuff) and other
2183 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002184 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002185 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2186 // "p_extra[n_extra]".
2187 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002188 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002189 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002190 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002191 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002192 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2193 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002194 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2195 if (enc_utf8 && utf_char2len(c) > 1)
2196 {
2197 mb_utf8 = TRUE;
2198 u8cc[0] = 0;
2199 c = 0xc0;
2200 }
2201 else
2202 mb_utf8 = FALSE;
2203 }
2204 else
2205 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002206 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002207 if (has_mbyte)
2208 {
2209 mb_c = c;
2210 if (enc_utf8)
2211 {
2212 // If the UTF-8 character is more than one byte:
2213 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002214 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002215 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002216 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002217 mb_l = 1;
2218 else if (mb_l > 1)
2219 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002220 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002221 mb_utf8 = TRUE;
2222 c = 0xc0;
2223 }
2224 }
2225 else
2226 {
2227 // if this is a DBCS character, put it in "mb_c"
2228 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002229 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002230 mb_l = 1;
2231 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002232 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002233 }
2234 if (mb_l == 0) // at the NUL at end-of-line
2235 mb_l = 1;
2236
2237 // If a double-width char doesn't fit display a '>' in the
2238 // last column.
2239 if ((
2240# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002241 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002242# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002243 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002244 && (*mb_char2cells)(mb_c) == 2)
2245 {
2246 c = '>';
2247 mb_c = c;
2248 mb_l = 1;
2249 mb_utf8 = FALSE;
2250 multi_attr = HL_ATTR(HLF_AT);
2251#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002252 if (wlv.cul_attr)
2253 multi_attr = hl_combine_attr(
2254 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002255#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002256 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002257
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002258 // put the pointer back to output the double-width
2259 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002260 ++wlv.n_extra;
2261 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002262 }
2263 else
2264 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002265 wlv.n_extra -= mb_l - 1;
2266 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002267 }
2268 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002269 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002270 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002271 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002272#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002273 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002274 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002275 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002276 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002277 if (search_attr == 0)
2278 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002279 if (area_attr == 0 && *ptr != NUL)
2280 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002281 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002282#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002283 }
2284 else
2285 {
2286#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002287 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002288#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002289 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002290
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002291 // Get a character from the line itself.
2292 c = *ptr;
2293#ifdef FEAT_LINEBREAK
2294 c0 = *ptr;
2295#endif
2296 if (has_mbyte)
2297 {
2298 mb_c = c;
2299 if (enc_utf8)
2300 {
2301 // If the UTF-8 character is more than one byte: Decode it
2302 // into "mb_c".
2303 mb_l = utfc_ptr2len(ptr);
2304 mb_utf8 = FALSE;
2305 if (mb_l > 1)
2306 {
2307 mb_c = utfc_ptr2char(ptr, u8cc);
2308 // Overlong encoded ASCII or ASCII with composing char
2309 // is displayed normally, except a NUL.
2310 if (mb_c < 0x80)
2311 {
2312 c = mb_c;
2313#ifdef FEAT_LINEBREAK
2314 c0 = mb_c;
2315#endif
2316 }
2317 mb_utf8 = TRUE;
2318
2319 // At start of the line we can have a composing char.
2320 // Draw it as a space with a composing char.
2321 if (utf_iscomposing(mb_c))
2322 {
2323 int i;
2324
2325 for (i = Screen_mco - 1; i > 0; --i)
2326 u8cc[i] = u8cc[i - 1];
2327 u8cc[0] = mb_c;
2328 mb_c = ' ';
2329 }
2330 }
2331
2332 if ((mb_l == 1 && c >= 0x80)
2333 || (mb_l >= 1 && mb_c == 0)
2334 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2335 {
2336 // Illegal UTF-8 byte: display as <xx>.
2337 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002338 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002339# ifdef FEAT_RIGHTLEFT
2340 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002341 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002342# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002343 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002344 c = *wlv.p_extra;
2345 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002346 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002347 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2348 wlv.c_extra = NUL;
2349 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002350 if (area_attr == 0 && search_attr == 0)
2351 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002352 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002353 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002354 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002355 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002356 }
2357 }
2358 else if (mb_l == 0) // at the NUL at end-of-line
2359 mb_l = 1;
2360#ifdef FEAT_ARABIC
2361 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2362 {
2363 // Do Arabic shaping.
2364 int pc, pc1, nc;
2365 int pcc[MAX_MCO];
2366
2367 // The idea of what is the previous and next
2368 // character depends on 'rightleft'.
2369 if (wp->w_p_rl)
2370 {
2371 pc = prev_c;
2372 pc1 = prev_c1;
2373 nc = utf_ptr2char(ptr + mb_l);
2374 prev_c1 = u8cc[0];
2375 }
2376 else
2377 {
2378 pc = utfc_ptr2char(ptr + mb_l, pcc);
2379 nc = prev_c;
2380 pc1 = pcc[0];
2381 }
2382 prev_c = mb_c;
2383
2384 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2385 }
2386 else
2387 prev_c = mb_c;
2388#endif
2389 }
2390 else // enc_dbcs
2391 {
2392 mb_l = MB_BYTE2LEN(c);
2393 if (mb_l == 0) // at the NUL at end-of-line
2394 mb_l = 1;
2395 else if (mb_l > 1)
2396 {
2397 // We assume a second byte below 32 is illegal.
2398 // Hopefully this is OK for all double-byte encodings!
2399 if (ptr[1] >= 32)
2400 mb_c = (c << 8) + ptr[1];
2401 else
2402 {
2403 if (ptr[1] == NUL)
2404 {
2405 // head byte at end of line
2406 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002407 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002408 }
2409 else
2410 {
2411 // illegal tail byte
2412 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002413 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002414 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002415 wlv.p_extra = wlv.extra;
2416 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002417 wlv.c_extra = NUL;
2418 wlv.c_final = NUL;
2419 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002420 if (area_attr == 0 && search_attr == 0)
2421 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002422 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002423 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002424 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002425 // save current attr
2426 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002427 }
2428 mb_c = c;
2429 }
2430 }
2431 }
2432 // If a double-width char doesn't fit display a '>' in the
2433 // last column; the character is displayed at the start of the
2434 // next line.
2435 if ((
2436# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002437 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002438# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002439 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002440 && (*mb_char2cells)(mb_c) == 2)
2441 {
2442 c = '>';
2443 mb_c = c;
2444 mb_utf8 = FALSE;
2445 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002446 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002447 // Put pointer back so that the character will be
2448 // displayed at the start of the next line.
2449 --ptr;
2450#ifdef FEAT_CONCEAL
2451 did_decrement_ptr = TRUE;
2452#endif
2453 }
2454 else if (*ptr != NUL)
2455 ptr += mb_l - 1;
2456
2457 // If a double-width char doesn't fit at the left side display
2458 // a '<' in the first column. Don't do this for unprintable
2459 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002460 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002461 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002462 wlv.n_extra = 1;
2463 wlv.c_extra = MB_FILLER_CHAR;
2464 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002465 c = ' ';
2466 if (area_attr == 0 && search_attr == 0)
2467 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002468 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002469 extra_attr = hl_combine_attr(
2470 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002471 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002472 }
2473 mb_c = c;
2474 mb_utf8 = FALSE;
2475 mb_l = 1;
2476 }
2477
2478 }
2479 ++ptr;
2480
2481 if (extra_check)
2482 {
2483#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002484 // Check spelling (unless at the end of the line).
2485 // Only do this when there is no syntax highlighting, the
2486 // @Spell cluster is not used or the current syntax item
2487 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002488 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002489 if (has_spell && v >= word_end && v > cur_checked_col)
2490 {
2491 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002492 // do not calculate cap_col at the end of the line or when
2493 // only white space is following
2494 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002495# ifdef FEAT_SYN_HL
2496 !has_syntax ||
2497# endif
2498 can_spell))
2499 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002500 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002501 int len;
2502 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002503
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002504 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002505 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002506
2507 // Use nextline[] if possible, it has the start of the
2508 // next line concatenated.
2509 if ((prev_ptr - line) - nextlinecol >= 0)
2510 p = nextline + (prev_ptr - line) - nextlinecol;
2511 else
2512 p = prev_ptr;
2513 cap_col -= (int)(prev_ptr - line);
2514 len = spell_check(wp, p, &spell_hlf, &cap_col,
2515 nochange);
2516 word_end = v + len;
2517
2518 // In Insert mode only highlight a word that
2519 // doesn't touch the cursor.
2520 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002521 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002522 && wp->w_cursor.lnum == lnum
2523 && wp->w_cursor.col >=
2524 (colnr_T)(prev_ptr - line)
2525 && wp->w_cursor.col < (colnr_T)word_end)
2526 {
2527 spell_hlf = HLF_COUNT;
2528 spell_redraw_lnum = lnum;
2529 }
2530
2531 if (spell_hlf == HLF_COUNT && p != prev_ptr
2532 && (p - nextline) + len > nextline_idx)
2533 {
2534 // Remember that the good word continues at the
2535 // start of the next line.
2536 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002537 checked_col = (int)((p - nextline)
2538 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002539 }
2540
2541 // Turn index into actual attributes.
2542 if (spell_hlf != HLF_COUNT)
2543 spell_attr = highlight_attr[spell_hlf];
2544
2545 if (cap_col > 0)
2546 {
2547 if (p != prev_ptr
2548 && (p - nextline) + cap_col >= nextline_idx)
2549 {
2550 // Remember that the word in the next line
2551 // must start with a capital.
2552 capcol_lnum = lnum + 1;
2553 cap_col = (int)((p - nextline) + cap_col
2554 - nextline_idx);
2555 }
2556 else
2557 // Compute the actual column.
2558 cap_col += (int)(prev_ptr - line);
2559 }
2560 }
2561 }
2562 if (spell_attr != 0)
2563 {
2564 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002565 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2566 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002567 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002568 wlv.char_attr = hl_combine_attr(spell_attr,
2569 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002570 }
2571#endif
2572#ifdef FEAT_LINEBREAK
2573 // Found last space before word: check for line break.
2574 if (wp->w_p_lbr && c0 == c
2575 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2576 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002577 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2578 : 0;
2579 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002580 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002581
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002582 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002583# ifdef FEAT_PROP_POPUP
2584 // do not want virtual text counted here
2585 cts.cts_has_prop_with_text = FALSE;
2586# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002587 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002588 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002589
2590 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002591 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002592 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002593 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002594 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2595 if (wlv.n_extra < 0)
2596 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002597 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002598 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002599 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002600 // line break, but for TABs the highlighting should
2601 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002602 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002603
Bram Moolenaar1306b362022-08-06 15:59:06 +01002604 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002605# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002606 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002607 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002608 wp->w_buffer->b_p_vts_array) - 1;
2609# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002610 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002611 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002612# endif
2613
Bram Moolenaar1306b362022-08-06 15:59:06 +01002614 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2615 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002616# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002617 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002618 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002619# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002620 if (VIM_ISWHITE(c))
2621 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002622# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002623 if (c == TAB)
2624 // See "Tab alignment" below.
2625 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002626# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002627 if (!wp->w_p_list)
2628 c = ' ';
2629 }
2630 }
2631#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002632 in_multispace = c == ' '
2633 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2634 if (!in_multispace)
2635 multispace_pos = 0;
2636
Bram Moolenaareed9d462021-02-15 20:38:25 +01002637 // 'list': Change char 160 to 'nbsp' and space to 'space'
2638 // setting in 'listchars'. But not when the character is
2639 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002640 if (wp->w_p_list
2641 && ((((c == 160 && mb_l == 1)
2642 || (mb_utf8
2643 && ((mb_c == 160 && mb_l == 2)
2644 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002645 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002646 || (c == ' '
2647 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002648 && (wp->w_lcs_chars.space
2649 || (in_multispace
2650 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002651 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002652 && ptr - line <= trailcol)))
2653 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002654 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2655 {
2656 c = wp->w_lcs_chars.multispace[multispace_pos++];
2657 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2658 multispace_pos = 0;
2659 }
2660 else
2661 c = (c == ' ') ? wp->w_lcs_chars.space
2662 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002663 if (area_attr == 0 && search_attr == 0)
2664 {
2665 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002666 extra_attr = hl_combine_attr(wlv.win_attr,
2667 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002668 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002669 }
2670 mb_c = c;
2671 if (enc_utf8 && utf_char2len(c) > 1)
2672 {
2673 mb_utf8 = TRUE;
2674 u8cc[0] = 0;
2675 c = 0xc0;
2676 }
2677 else
2678 mb_utf8 = FALSE;
2679 }
2680
zeertzjq2e7cba32022-06-10 15:30:32 +01002681 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2682 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002683 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002684 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2685 && wp->w_lcs_chars.leadmultispace != NULL)
2686 {
2687 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002688 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2689 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002690 multispace_pos = 0;
2691 }
2692
2693 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2694 c = wp->w_lcs_chars.trail;
2695
2696 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2697 c = wp->w_lcs_chars.lead;
2698
zeertzjq2e7cba32022-06-10 15:30:32 +01002699 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002700 c = wp->w_lcs_chars.space;
2701
2702
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002703 if (!attr_pri)
2704 {
2705 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002706 extra_attr = hl_combine_attr(wlv.win_attr,
2707 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002708 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002709 }
2710 mb_c = c;
2711 if (enc_utf8 && utf_char2len(c) > 1)
2712 {
2713 mb_utf8 = TRUE;
2714 u8cc[0] = 0;
2715 c = 0xc0;
2716 }
2717 else
2718 mb_utf8 = FALSE;
2719 }
2720 }
2721
2722 // Handling of non-printable characters.
2723 if (!vim_isprintc(c))
2724 {
2725 // when getting a character from the file, we may have to
2726 // turn it into something else on the way to putting it
2727 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002728 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002729 {
2730 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002731 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002732#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002733 char_u *sbr = get_showbreak_value(wp);
2734
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002735 // only adjust the tab_len, when at the first column
2736 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002737 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002738 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002739#endif
2740 // tab amount depends on current column
2741#ifdef FEAT_VARTABS
2742 tab_len = tabstop_padding(vcol_adjusted,
2743 wp->w_buffer->b_p_ts,
2744 wp->w_buffer->b_p_vts_array) - 1;
2745#else
2746 tab_len = (int)wp->w_buffer->b_p_ts
2747 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2748#endif
2749
2750#ifdef FEAT_LINEBREAK
2751 if (!wp->w_p_lbr || !wp->w_p_list)
2752#endif
2753 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002754 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002755#ifdef FEAT_LINEBREAK
2756 else
2757 {
2758 char_u *p;
2759 int len;
2760 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002761 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002762
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002763# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002764 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002765 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002766 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002767
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002768 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002769 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002770 && old_boguscols > 0
2771 && wlv.n_extra > tab_len)
2772 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002773# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002774 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002775 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002776 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002777 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002778 if (wp->w_lcs_chars.tab3)
2779 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002780 if (wlv.n_extra > 0)
2781 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002782 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002783 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002784 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002785 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002786 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002787 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002788 vim_memset(p, ' ', len);
2789 p[len] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002790 vim_free(wlv.p_extra_free);
2791 wlv.p_extra_free = p;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002792 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002793 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002794 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002795
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002796 if (*p == NUL)
2797 {
2798 tab_len = i;
2799 break;
2800 }
2801
2802 // if tab3 is given, use it for the last char
2803 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2804 lcs = wp->w_lcs_chars.tab3;
2805 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002806 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002807 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002808 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002809 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002810# ifdef FEAT_CONCEAL
2811 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2812 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002813 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002814 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002815# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002816 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002817 }
2818#endif
2819#ifdef FEAT_CONCEAL
2820 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002821 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002822
2823 // Tab alignment should be identical regardless of
2824 // 'conceallevel' value. So tab compensates of all
2825 // previous concealed characters, and thus resets
2826 // vcol_off and boguscols accumulated so far in the
2827 // line. Note that the tab can be longer than
2828 // 'tabstop' when there are concealed characters.
2829 FIX_FOR_BOGUSCOLS;
2830
2831 // Make sure, the highlighting for the tab char will be
2832 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002833 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002834 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002835 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002836 tab_len += vc_saved;
2837 }
2838#endif
2839 mb_utf8 = FALSE; // don't draw as UTF-8
2840 if (wp->w_p_list)
2841 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002842 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002843 ? wp->w_lcs_chars.tab3
2844 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002845#ifdef FEAT_LINEBREAK
2846 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002847 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002848 else
2849#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002850 wlv.c_extra = wp->w_lcs_chars.tab2;
2851 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002852 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002853 extra_attr = hl_combine_attr(wlv.win_attr,
2854 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002855 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002856 mb_c = c;
2857 if (enc_utf8 && utf_char2len(c) > 1)
2858 {
2859 mb_utf8 = TRUE;
2860 u8cc[0] = 0;
2861 c = 0xc0;
2862 }
2863 }
2864 else
2865 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002866 wlv.c_final = NUL;
2867 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002868 c = ' ';
2869 }
2870 }
2871 else if (c == NUL
2872 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002873 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
2874 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002875 && VIsual_mode != Ctrl_V
2876 && (
2877# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002878 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002879# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002880 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002881 && !(noinvcur
2882 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002883 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002884 && lcs_eol_one > 0)
2885 {
2886 // Display a '$' after the line or highlight an extra
2887 // character if the line break is included.
2888#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2889 // For a diff line the highlighting continues after the
2890 // "$".
2891 if (
2892# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002893 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002894# ifdef LINE_ATTR
2895 &&
2896# endif
2897# endif
2898# ifdef LINE_ATTR
2899 line_attr == 0
2900# endif
2901 )
2902#endif
2903 {
2904 // In virtualedit, visual selections may extend
2905 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002906 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002907 && wlv.tocol != MAXCOL
2908 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002909 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002910 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002911 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002912 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2913 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002914 else
2915 c = ' ';
2916 lcs_eol_one = -1;
2917 --ptr; // put it back at the NUL
2918 if (!attr_pri)
2919 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002920 extra_attr = hl_combine_attr(wlv.win_attr,
2921 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002922 n_attr = 1;
2923 }
2924 mb_c = c;
2925 if (enc_utf8 && utf_char2len(c) > 1)
2926 {
2927 mb_utf8 = TRUE;
2928 u8cc[0] = 0;
2929 c = 0xc0;
2930 }
2931 else
2932 mb_utf8 = FALSE; // don't draw as UTF-8
2933 }
2934 else if (c != NUL)
2935 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002936 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2937 if (wlv.n_extra == 0)
2938 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002939#ifdef FEAT_RIGHTLEFT
2940 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002941 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002942#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002943 wlv.c_extra = NUL;
2944 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002945#ifdef FEAT_LINEBREAK
2946 if (wp->w_p_lbr)
2947 {
2948 char_u *p;
2949
Bram Moolenaar1306b362022-08-06 15:59:06 +01002950 c = *wlv.p_extra;
2951 p = alloc(wlv.n_extra + 1);
2952 vim_memset(p, ' ', wlv.n_extra);
2953 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2954 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002955 vim_free(wlv.p_extra_free);
2956 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002957 }
2958 else
2959#endif
2960 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002961 wlv.n_extra = byte2cells(c) - 1;
2962 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002963 }
2964 if (!attr_pri)
2965 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002966 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002967 extra_attr = hl_combine_attr(wlv.win_attr,
2968 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002969 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002970 }
2971 mb_utf8 = FALSE; // don't draw as UTF-8
2972 }
2973 else if (VIsual_active
2974 && (VIsual_mode == Ctrl_V
2975 || VIsual_mode == 'v')
2976 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002977 && wlv.tocol != MAXCOL
2978 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002979 && (
2980#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002981 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002982#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002983 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002984 {
2985 c = ' ';
2986 --ptr; // put it back at the NUL
2987 }
2988#if defined(LINE_ATTR)
2989 else if ((
2990# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002991 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002992# endif
2993# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002994 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002995# endif
2996 line_attr != 0
2997 ) && (
2998# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002999 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003000# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003001 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003002# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003003 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003004# endif
3005 < wp->w_width)))
3006 {
3007 // Highlight until the right side of the window
3008 c = ' ';
3009 --ptr; // put it back at the NUL
3010
3011 // Remember we do the char for line highlighting.
3012 ++did_line_attr;
3013
3014 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01003015 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003016 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003017 || (wp->w_p_list &&
3018 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003019 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003020# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003021 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003022 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003023 wlv.diff_hlf = HLF_CHD;
3024 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003025 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003026 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003027 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3028 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003029 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003030 || (wlv.vcol >= left_curline_col
3031 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003032 wlv.char_attr = hl_combine_attr(
3033 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003034 }
3035 }
3036# endif
3037# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003038 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003039 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003040 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003041 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3042 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003043 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003044 if (!wlv.cul_screenline
3045 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003046 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003047 wlv.char_attr = hl_combine_attr(
3048 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003049 }
3050 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003051 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3052 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003053 }
3054# endif
3055 }
3056#endif
3057 }
3058
3059#ifdef FEAT_CONCEAL
3060 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003061 && (wp != curwin || lnum != wp->w_cursor.lnum
3062 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003063 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3064 && !(lnum_in_visual_area
3065 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3066 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003067 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003068 if (((prev_syntax_id != syntax_seqnr
3069 && (syntax_flags & HL_CONCEAL) != 0)
3070 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003071 && (syn_get_sub_char() != NUL
3072 || (has_match_conc && match_conc)
3073 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003074 && wp->w_p_cole != 3)
3075 {
3076 // First time at this concealed item: display one
3077 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003078 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003079 c = match_conc;
3080 else if (syn_get_sub_char() != NUL)
3081 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003082 else if (wp->w_lcs_chars.conceal != NUL)
3083 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003084 else
3085 c = ' ';
3086
3087 prev_syntax_id = syntax_seqnr;
3088
Bram Moolenaar1306b362022-08-06 15:59:06 +01003089 if (wlv.n_extra > 0)
3090 wlv.vcol_off += wlv.n_extra;
3091 wlv.vcol += wlv.n_extra;
3092 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003093 {
3094# ifdef FEAT_RIGHTLEFT
3095 if (wp->w_p_rl)
3096 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003097 wlv.col -= wlv.n_extra;
3098 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003099 }
3100 else
3101# endif
3102 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003103 wlv.boguscols += wlv.n_extra;
3104 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003105 }
3106 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003107 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003108 n_attr = 0;
3109 }
3110 else if (n_skip == 0)
3111 {
3112 is_concealing = TRUE;
3113 n_skip = 1;
3114 }
3115 mb_c = c;
3116 if (enc_utf8 && utf_char2len(c) > 1)
3117 {
3118 mb_utf8 = TRUE;
3119 u8cc[0] = 0;
3120 c = 0xc0;
3121 }
3122 else
3123 mb_utf8 = FALSE; // don't draw as UTF-8
3124 }
3125 else
3126 {
3127 prev_syntax_id = 0;
3128 is_concealing = FALSE;
3129 }
3130
3131 if (n_skip > 0 && did_decrement_ptr)
3132 // not showing the '>', put pointer back to avoid getting stuck
3133 ++ptr;
3134
3135#endif // FEAT_CONCEAL
3136 }
3137
3138#ifdef FEAT_CONCEAL
3139 // In the cursor line and we may be concealing characters: correct
3140 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003141 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003142 && wp == curwin && lnum == wp->w_cursor.lnum
3143 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003144 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003145 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003146# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003147 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003148 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003149 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003150# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003151 wp->w_wcol = wlv.col - wlv.boguscols;
3152 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003153 did_wcol = TRUE;
3154 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003155# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003156 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003157# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003158 }
3159#endif
3160
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003161 // Use "extra_attr", but don't override visual selection highlighting,
3162 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003163 // Don't use "extra_attr" until n_attr_skip is zero.
3164 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003165 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003166 && (!attr_pri
3167#ifdef FEAT_PROP_POPUP
3168 || (text_prop_flags & PT_FLAG_OVERRIDE)
3169#endif
3170 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003171 {
3172#ifdef LINE_ATTR
3173 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003174 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003175 else
3176#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003177 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003178 }
3179
3180#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3181 // XIM don't send preedit_start and preedit_end, but they send
3182 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3183 // im_is_preediting() here.
3184 if (p_imst == IM_ON_THE_SPOT
3185 && xic != NULL
3186 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003187 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003188 && !p_imdisable
3189 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003190 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003191 {
3192 colnr_T tcol;
3193
3194 if (preedit_end_col == MAXCOL)
3195 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3196 else
3197 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003198 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003199 {
3200 if (feedback_old_attr < 0)
3201 {
3202 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003203 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003204 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003205 wlv.char_attr = im_get_feedback_attr(feedback_col);
3206 if (wlv.char_attr < 0)
3207 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003208 feedback_col++;
3209 }
3210 else if (feedback_old_attr >= 0)
3211 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003212 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003213 feedback_old_attr = -1;
3214 feedback_col = 0;
3215 }
3216 }
3217#endif
3218 // Handle the case where we are in column 0 but not on the first
3219 // character of the line and the user wants us to show us a
3220 // special character (via 'listchars' option "precedes:<char>".
3221 if (lcs_prec_todo != NUL
3222 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003223 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3224 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003225#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003226 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003227#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003228 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003229 && c != NUL)
3230 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003231 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003232 lcs_prec_todo = NUL;
3233 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3234 {
3235 // Double-width character being overwritten by the "precedes"
3236 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003237 wlv.c_extra = MB_FILLER_CHAR;
3238 wlv.c_final = NUL;
3239 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003240 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003241 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003242 }
3243 mb_c = c;
3244 if (enc_utf8 && utf_char2len(c) > 1)
3245 {
3246 mb_utf8 = TRUE;
3247 u8cc[0] = 0;
3248 c = 0xc0;
3249 }
3250 else
3251 mb_utf8 = FALSE; // don't draw as UTF-8
3252 if (!attr_pri)
3253 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003254 saved_attr3 = wlv.char_attr; // save current attr
3255 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003256 n_attr3 = 1;
3257 }
3258 }
3259
3260 // At end of the text line or just after the last character.
3261 if ((c == NUL
3262#if defined(LINE_ATTR)
3263 || did_line_attr == 1
3264#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003265 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003266 {
3267#ifdef FEAT_SEARCH_EXTRA
3268 // flag to indicate whether prevcol equals startcol of search_hl or
3269 // one of the matches
3270 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3271 (long)(ptr - line) - (c == NUL));
3272#endif
3273 // Invert at least one char, used for Visual and empty line or
3274 // highlight match at end of line. If it's beyond the last
3275 // char on the screen, just overwrite that one (tricky!) Not
3276 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003277 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003278 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003279 && (VIsual_mode != Ctrl_V
3280 || lnum == VIsual.lnum
3281 || lnum == curwin->w_cursor.lnum)
3282 && c == NUL)
3283#ifdef FEAT_SEARCH_EXTRA
3284 // highlight 'hlsearch' match at end of line
3285 || (prevcol_hl_flag
3286# ifdef FEAT_SYN_HL
3287 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3288 && !(wp == curwin && VIsual_active))
3289# endif
3290# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003291 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003292# endif
3293# if defined(LINE_ATTR)
3294 && did_line_attr <= 1
3295# endif
3296 )
3297#endif
3298 ))
3299 {
3300 int n = 0;
3301
3302#ifdef FEAT_RIGHTLEFT
3303 if (wp->w_p_rl)
3304 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003305 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003306 n = 1;
3307 }
3308 else
3309#endif
3310 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003311 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003312 n = -1;
3313 }
3314 if (n != 0)
3315 {
3316 // At the window boundary, highlight the last character
3317 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003318 wlv.off += n;
3319 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003320 }
3321 else
3322 {
3323 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003324 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003325 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003326 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003327 }
3328#ifdef FEAT_SEARCH_EXTRA
3329 if (area_attr == 0)
3330 {
3331 // Use attributes from match with highest priority among
3332 // 'search_hl' and the match list.
3333 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003334 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003335 }
3336#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003337 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003338 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003339#ifdef FEAT_RIGHTLEFT
3340 if (wp->w_p_rl)
3341 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003342 --wlv.col;
3343 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003344 }
3345 else
3346#endif
3347 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003348 ++wlv.col;
3349 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003350 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003351 ++wlv.vcol;
3352 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003353 }
3354 }
3355
3356 // At end of the text line.
3357 if (c == NUL)
3358 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003359 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003360
3361 // Update w_cline_height and w_cline_folded if the cursor line was
3362 // updated (saves a call to plines() later).
3363 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3364 {
3365 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003366 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003367#ifdef FEAT_FOLDING
3368 curwin->w_cline_folded = FALSE;
3369#endif
3370 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3371 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003372 break;
3373 }
3374
3375 // Show "extends" character from 'listchars' if beyond the line end and
3376 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003377 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003378 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003379 && wp->w_p_list
3380 && !wp->w_p_wrap
3381#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003382 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003383#endif
3384 && (
3385#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003386 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003387#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003388 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003389 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003390 || lcs_eol_one > 0
3391 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003392 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003393 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003394 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003395 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003396 mb_c = c;
3397 if (enc_utf8 && utf_char2len(c) > 1)
3398 {
3399 mb_utf8 = TRUE;
3400 u8cc[0] = 0;
3401 c = 0xc0;
3402 }
3403 else
3404 mb_utf8 = FALSE;
3405 }
3406
3407#ifdef FEAT_SYN_HL
3408 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003409 if (wlv.draw_color_col)
3410 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003411
3412 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3413 // highlight the cursor position itself.
3414 // Also highlight the 'colorcolumn' if it is different than
3415 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003416 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3417 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003418 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003419 if (((wlv.draw_state == WL_LINE
3420 || wlv.draw_state == WL_BRI
3421 || wlv.draw_state == WL_SBR)
3422 && !lnum_in_visual_area
3423 && search_attr == 0
3424 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003425# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003426 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003427# endif
3428 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003429 {
3430 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3431 && lnum != wp->w_cursor.lnum)
3432 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003433 vcol_save_attr = wlv.char_attr;
3434 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3435 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003436 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003437 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003438 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003439 vcol_save_attr = wlv.char_attr;
3440 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003441 }
3442 }
3443#endif
3444
3445 // Store character to be displayed.
3446 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003447 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003448 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003449 {
3450 // Store the character.
3451#if defined(FEAT_RIGHTLEFT)
3452 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3453 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003454 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003455 --wlv.off;
3456 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003457 }
3458#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003459 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003460 if (enc_dbcs == DBCS_JPNU)
3461 {
3462 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003463 ScreenLines[wlv.off] = 0x8e;
3464 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003465 }
3466 else if (enc_utf8)
3467 {
3468 if (mb_utf8)
3469 {
3470 int i;
3471
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003472 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003473 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003474 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003475 for (i = 0; i < Screen_mco; ++i)
3476 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003477 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003478 if (u8cc[i] == 0)
3479 break;
3480 }
3481 }
3482 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003483 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003484 }
3485 if (multi_attr)
3486 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003487 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003488 multi_attr = 0;
3489 }
3490 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003491 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003492
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003493 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003494
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003495 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3496 {
3497 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003498 ++wlv.off;
3499 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003500 if (enc_utf8)
3501 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003502 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003503 else
3504 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003505 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003506 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003507#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003508 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003509#endif
3510 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003511 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003512 // When "wlv.tocol" is halfway a character, set it to the end
3513 // of the character, otherwise highlighting won't stop.
3514 if (wlv.tocol == wlv.vcol)
3515 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003516
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003517 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003518
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003519#ifdef FEAT_RIGHTLEFT
3520 if (wp->w_p_rl)
3521 {
3522 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003523 --wlv.off;
3524 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003525 }
3526#endif
3527 }
3528#ifdef FEAT_RIGHTLEFT
3529 if (wp->w_p_rl)
3530 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003531 --wlv.off;
3532 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003533 }
3534 else
3535#endif
3536 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003537 ++wlv.off;
3538 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003539 }
3540 }
3541#ifdef FEAT_CONCEAL
3542 else if (wp->w_p_cole > 0 && is_concealing)
3543 {
3544 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003545 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003546 if (wlv.n_extra > 0)
3547 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003548 if (wp->w_p_wrap)
3549 {
3550 // Special voodoo required if 'wrap' is on.
3551 //
3552 // Advance the column indicator to force the line
3553 // drawing to wrap early. This will make the line
3554 // take up the same screen space when parts are concealed,
3555 // so that cursor line computations aren't messed up.
3556 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003557 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003558 // trailing junk to be written out of the screen line
3559 // we are building, 'boguscols' keeps track of the number
3560 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003561 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003562 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003563 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003564# ifdef FEAT_RIGHTLEFT
3565 if (wp->w_p_rl)
3566 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003567 wlv.col -= wlv.n_extra;
3568 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003569 }
3570 else
3571# endif
3572 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003573 wlv.col += wlv.n_extra;
3574 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003575 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003576 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003577 n_attr = 0;
3578 }
3579
3580
3581 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3582 {
3583 // Need to fill two screen columns.
3584# ifdef FEAT_RIGHTLEFT
3585 if (wp->w_p_rl)
3586 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003587 --wlv.boguscols;
3588 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003589 }
3590 else
3591# endif
3592 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003593 ++wlv.boguscols;
3594 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003595 }
3596 }
3597
3598# ifdef FEAT_RIGHTLEFT
3599 if (wp->w_p_rl)
3600 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003601 --wlv.boguscols;
3602 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003603 }
3604 else
3605# endif
3606 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003607 ++wlv.boguscols;
3608 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003609 }
3610 }
3611 else
3612 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003613 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003614 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003615 wlv.vcol += wlv.n_extra;
3616 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003617 n_attr = 0;
3618 }
3619 }
3620
3621 }
3622#endif // FEAT_CONCEAL
3623 else
3624 --n_skip;
3625
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003626 // Only advance the "wlv.vcol" when after the 'number' or
3627 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003628 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003629#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003630 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003631#endif
3632 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003633 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003634
3635#ifdef FEAT_SYN_HL
3636 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003637 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003638#endif
3639
3640 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003641 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3642 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003643
3644 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003645 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003646 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003647 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003648 if (n_attr_skip > 0)
3649 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003650
3651 // At end of screen line and there is more to come: Display the line
3652 // so far. If there is no more to display it is caught above.
3653 if ((
3654#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003655 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003656#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003657 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003658 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003659 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003660#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003661 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003662#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003663#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003664 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003665#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003666 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003667 && wlv.p_extra != at_end_str)
3668 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3669 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003670 )
3671 {
3672#ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003673 screen_line(wp, wlv.screen_row, wp->w_wincol,
3674 wlv.col - wlv.boguscols,
3675 wp->w_width, wlv.screen_line_flags);
3676 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003677#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003678 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col,
3679 wp->w_width, wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003680#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003681 ++wlv.row;
3682 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003683
3684 // When not wrapping and finished diff lines, or when displayed
3685 // '$' and highlighting until last column, break here.
3686 if ((!wp->w_p_wrap
3687#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003688 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003689#endif
3690#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003691 && !text_prop_above && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003692#endif
3693 ) || lcs_eol_one == -1)
3694 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003695#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003696 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003697 {
3698 // do not output more of the line, only the "below" prop
3699 ptr += STRLEN(ptr);
3700# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003701 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003702# endif
3703 }
3704#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003705
3706 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003707 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003708#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003709 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003710#endif
3711 )
3712 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003713 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3714 draw_vsep_win(wp, wlv.row);
3715 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003716 }
3717
3718 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003719 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003720 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003721 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003722 break;
3723 }
3724
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003725 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003726#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003727 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003728#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003729#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003730 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003731#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003732 && wp->w_width == Columns)
3733 {
3734 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003735 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003736
3737 // Special trick to make copy/paste of wrapped lines work with
3738 // xterm/screen: write an extra character beyond the end of
3739 // the line. This will work with all terminal types
3740 // (regardless of the xn,am settings).
3741 // Only do this on a fast tty.
3742 // Only do this if the cursor is on the current line
3743 // (something has been written in it).
3744 // Don't do this for the GUI.
3745 // Don't do this for double-width characters.
3746 // Don't do this for a window not at the right screen border.
3747 if (p_tf
3748#ifdef FEAT_GUI
3749 && !gui.in_use
3750#endif
3751 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003752 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3753 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003754 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003755 || (*mb_off2cells)(
3756 LineOffset[wlv.screen_row - 1]
3757 + (int)Columns - 2,
3758 LineOffset[wlv.screen_row]
3759 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003760 {
3761 // First make sure we are at the end of the screen line,
3762 // then output the same character again to let the
3763 // terminal know about the wrap. If the terminal doesn't
3764 // auto-wrap, we overwrite the character.
3765 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003766 screen_char(LineOffset[wlv.screen_row - 1]
3767 + (unsigned)Columns - 1,
3768 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003769
3770 // When there is a multi-byte character, just output a
3771 // space to keep it simple.
3772 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003773 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003774 out_char(' ');
3775 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003776 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003777 + (Columns - 1)]);
3778 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003779 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003780 screen_start(); // don't know where cursor is now
3781 }
3782 }
3783
Bram Moolenaar1306b362022-08-06 15:59:06 +01003784 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003785
Bram Moolenaareed9d462021-02-15 20:38:25 +01003786 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003787#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003788 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003789# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003790 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003791# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003792 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003793 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003794#endif
3795#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003796 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003797 // When the filler lines are actually below the last line of the
3798 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003799 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003800 break;
3801#endif
3802 }
3803
3804 } // for every character in the line
3805
3806#ifdef FEAT_SPELL
3807 // After an empty line check first word for capital.
3808 if (*skipwhite(line) == NUL)
3809 {
3810 capcol_lnum = lnum + 1;
3811 cap_col = 0;
3812 }
3813#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003814#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003815 vim_free(text_props);
3816 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003817 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003818#endif
3819
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003820 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003821 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003822}