blob: 793d8a9996970c27bff3dde7a7240632ecdcfceb [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/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100743 * Call screen_line() using values from "wlv".
744 * Also takes care of putting "<<<" on the first line for 'smoothscroll'.
745 */
746 static void
747wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
748{
749 if (wlv->row == 0 && wp->w_skipcol > 0)
750 {
751 int off = (int)(current_ScreenLine - ScreenLines);
752
753 for (int i = 0; i < 3; ++i)
754 {
755 ScreenLines[off] = '<';
756 if (enc_utf8)
757 ScreenLinesUC[off] = 0;
758 ScreenAttrs[off] = HL_ATTR(HLF_AT);
759 ++off;
760 }
761 }
762
763 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
764 negative_width ? -wp->w_width : wp->w_width,
765 wlv->screen_line_flags);
766}
767
768/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100769 * Called when finished with the line: draw the screen line and handle any
770 * highlighting until the right of the window.
771 */
772 static void
773draw_screen_line(win_T *wp, winlinevars_T *wlv)
774{
775#ifdef FEAT_SYN_HL
776 long v;
777
778 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
779 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100780 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100781 else
782 v = wp->w_leftcol;
783
784 // check if line ends before left margin
785 if (wlv->vcol < v + wlv->col - win_col_off(wp))
786 wlv->vcol = v + wlv->col - win_col_off(wp);
787# ifdef FEAT_CONCEAL
788 // Get rid of the boguscols now, we want to draw until the right
789 // edge for 'cursorcolumn'.
790 wlv->col -= wlv->boguscols;
791 wlv->boguscols = 0;
792# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
793# else
794# define VCOL_HLC (wlv->vcol)
795# endif
796
797 if (wlv->draw_color_col)
798 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
799
800 if (((wp->w_p_cuc
801 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
802 && (int)wp->w_virtcol <
803 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
804 && wlv->lnum != wp->w_cursor.lnum)
805 || wlv->draw_color_col
806 || wlv->win_attr != 0)
807# ifdef FEAT_RIGHTLEFT
808 && !wp->w_p_rl
809# endif
810 )
811 {
812 int rightmost_vcol = 0;
813 int i;
814
815 if (wp->w_p_cuc)
816 rightmost_vcol = wp->w_virtcol;
817 if (wlv->draw_color_col)
818 // determine rightmost colorcolumn to possibly draw
819 for (i = 0; wlv->color_cols[i] >= 0; ++i)
820 if (rightmost_vcol < wlv->color_cols[i])
821 rightmost_vcol = wlv->color_cols[i];
822
823 while (wlv->col < wp->w_width)
824 {
825 ScreenLines[wlv->off] = ' ';
826 if (enc_utf8)
827 ScreenLinesUC[wlv->off] = 0;
828 ScreenCols[wlv->off] = MAXCOL;
829 ++wlv->col;
830 if (wlv->draw_color_col)
831 wlv->draw_color_col = advance_color_col(
832 VCOL_HLC, &wlv->color_cols);
833
834 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
835 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
836 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
837 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
838 else
839 ScreenAttrs[wlv->off++] = wlv->win_attr;
840
841 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
842 break;
843
844 ++wlv->vcol;
845 }
846 }
847#endif
848
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100849 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100850 ++wlv->row;
851 ++wlv->screen_row;
852}
853#undef VCOL_HLC
854
855/*
856 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100857 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100858 */
859 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100860win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100861{
862 wlv->col = 0;
863 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
864
865#ifdef FEAT_RIGHTLEFT
866 if (wp->w_p_rl)
867 {
868 // Rightleft window: process the text in the normal direction, but put
869 // it in current_ScreenLine[] from right to left. Start at the
870 // rightmost column of the window.
871 wlv->col = wp->w_width - 1;
872 wlv->off += wlv->col;
873 wlv->screen_line_flags |= SLF_RIGHTLEFT;
874 }
875#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100876 if (save_extra)
877 {
878 // reset the drawing state for the start of a wrapped line
879 wlv->draw_state = WL_START;
880 wlv->saved_n_extra = wlv->n_extra;
881 wlv->saved_p_extra = wlv->p_extra;
882 wlv->saved_c_extra = wlv->c_extra;
883 wlv->saved_c_final = wlv->c_final;
884#ifdef FEAT_SYN_HL
885 if (!(wlv->cul_screenline
886# ifdef FEAT_DIFF
887 && wlv->diff_hlf == (hlf_T)0
888# endif
889 ))
890 wlv->saved_char_attr = wlv->char_attr;
891 else
892#endif
893 wlv->saved_char_attr = 0;
894 wlv->n_extra = 0;
895 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100896}
897
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200898/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100899 * Called when wlv->draw_state is set to WL_LINE.
900 */
901 static void
902win_line_continue(winlinevars_T *wlv)
903{
904 if (wlv->saved_n_extra > 0)
905 {
906 // Continue item from end of wrapped line.
907 wlv->n_extra = wlv->saved_n_extra;
908 wlv->c_extra = wlv->saved_c_extra;
909 wlv->c_final = wlv->saved_c_final;
910 wlv->p_extra = wlv->saved_p_extra;
911 wlv->char_attr = wlv->saved_char_attr;
912 }
913 else
914 wlv->char_attr = wlv->win_attr;
915}
916
917/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200918 * Display line "lnum" of window 'wp' on the screen.
919 * Start at row "startrow", stop when "endrow" is reached.
920 * wp->w_virtcol needs to be valid.
921 *
922 * Return the number of last row the line occupies.
923 */
924 int
925win_line(
926 win_T *wp,
927 linenr_T lnum,
928 int startrow,
929 int endrow,
930 int nochange UNUSED, // not updating for changed text
931 int number_only) // only update the number column
932{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100933 winlinevars_T wlv; // variables passed between functions
934
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200935 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100936 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200937 char_u *line; // current line
938 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200939
Bram Moolenaar1306b362022-08-06 15:59:06 +0100940#ifdef FEAT_PROP_POPUP
941 char_u *p_extra_free2 = NULL; // another p_extra to be freed
942#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200943 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000944#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000945 int in_linebreak = FALSE; // n_extra set for showing linebreak
946#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200947 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100948 // displaying eol at end-of-line
949 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000950 int lcs_prec_todo = wp->w_lcs_chars.prec;
951 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200952
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100953 int n_attr = 0; // chars with special attr
954 int n_attr_skip = 0; // chars to skip before using extra_attr
955 int saved_attr2 = 0; // char_attr saved for n_attr
956 int n_attr3 = 0; // chars with overruling special attr
957 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200958
959 int n_skip = 0; // nr of chars to skip for 'nowrap'
960
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200961 int fromcol_prev = -2; // start of inverting after cursor
962 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200963 int lnum_in_visual_area = FALSE;
964 pos_T pos;
965 long v;
966
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200967 int attr_pri = FALSE; // char_attr has priority
968 int area_highlighting = FALSE; // Visual or incsearch highlighting
969 // in this line
970 int vi_attr = 0; // attributes for Visual and incsearch
971 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200972 int area_attr = 0; // attributes desired by highlighting
973 int search_attr = 0; // attributes desired by 'hlsearch'
974#ifdef FEAT_SYN_HL
975 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
976 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200977 int prev_syntax_col = -1; // column of prev_syntax_attr
978 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200979 int has_syntax = FALSE; // this buffer has syntax highl.
980 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200981#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100982#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200983 int text_prop_count;
984 int text_prop_next = 0; // next text property to use
985 textprop_T *text_props = NULL;
986 int *text_prop_idxs = NULL;
987 int text_props_active = 0;
988 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +0100989 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200990 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +0100991 int text_prop_attr_comb = 0; // text_prop_attr combined with
992 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100993 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100994 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +0100995 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100996 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +0100997 int saved_search_attr = 0; // search_attr to be used when n_extra
998 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +0100999 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001000#endif
1001#ifdef FEAT_SPELL
1002 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001003 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001004# define SPWORDLEN 150
1005 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1006 int nextlinecol = 0; // column where nextline[] starts
1007 int nextline_idx = 0; // index in nextline[] where next line
1008 // starts
1009 int spell_attr = 0; // attributes desired by spelling
1010 int word_end = 0; // last byte with same spell_attr
1011 static linenr_T checked_lnum = 0; // line number for "checked_col"
1012 static int checked_col = 0; // column in "checked_lnum" up to which
1013 // there are no spell errors
1014 static int cap_col = -1; // column to check for Cap word
1015 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1016 int cur_checked_col = 0; // checked column for current line
1017#endif
1018 int extra_check = 0; // has extra highlighting
1019 int multi_attr = 0; // attributes desired by multibyte
1020 int mb_l = 1; // multi-byte byte length
1021 int mb_c = 0; // decoded multi-byte character
1022 int mb_utf8 = FALSE; // screen char is UTF-8 char
1023 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001024#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001025 int change_start = MAXCOL; // first col of changed area
1026 int change_end = -1; // last col of changed area
1027#endif
1028 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001029 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001030 int in_multispace = FALSE; // in multiple consecutive spaces
1031 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001032#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
1033 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
1034# define LINE_ATTR
1035 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +01001036 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001037#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001038 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001039 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001040#ifdef FEAT_ARABIC
1041 int prev_c = 0; // previous Arabic character
1042 int prev_c1 = 0; // first composing char for prev_c
1043#endif
1044#if defined(LINE_ATTR)
1045 int did_line_attr = 0;
1046#endif
1047#ifdef FEAT_TERMINAL
1048 int get_term_attr = FALSE;
1049#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001050
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001051#ifdef FEAT_SYN_HL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001052 // margin columns for the screen line, needed for when 'cursorlineopt'
1053 // contains "screenline"
1054 int left_curline_col = 0;
1055 int right_curline_col = 0;
1056#endif
1057
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001058#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1059 int feedback_col = 0;
1060 int feedback_old_attr = -1;
1061#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001062
1063#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1064 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001065 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001066#endif
1067#ifdef FEAT_CONCEAL
1068 int syntax_flags = 0;
1069 int syntax_seqnr = 0;
1070 int prev_syntax_id = 0;
1071 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1072 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001073 int did_wcol = FALSE;
1074 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001075# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001076# define FIX_FOR_BOGUSCOLS \
1077 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001078 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001079 wlv.vcol -= wlv.vcol_off; \
1080 wlv.vcol_off = 0; \
1081 wlv.col -= wlv.boguscols; \
1082 old_boguscols = wlv.boguscols; \
1083 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001084 }
1085#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001086# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001087#endif
1088
1089 if (startrow > endrow) // past the end already!
1090 return startrow;
1091
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001092 CLEAR_FIELD(wlv);
1093
1094 wlv.lnum = lnum;
1095 wlv.startrow = startrow;
1096 wlv.row = startrow;
1097 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001098 wlv.fromcol = -10;
1099 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001100#ifdef FEAT_LINEBREAK
1101 wlv.vcol_sbr = -1;
1102#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001103
1104 if (!number_only)
1105 {
1106 // To speed up the loop below, set extra_check when there is linebreak,
1107 // trailing white space and/or syntax processing to be done.
1108#ifdef FEAT_LINEBREAK
1109 extra_check = wp->w_p_lbr;
1110#endif
1111#ifdef FEAT_SYN_HL
1112 if (syntax_present(wp) && !wp->w_s->b_syn_error
1113# ifdef SYN_TIME_LIMIT
1114 && !wp->w_s->b_syn_slow
1115# endif
1116 )
1117 {
1118 // Prepare for syntax highlighting in this line. When there is an
1119 // error, stop syntax highlighting.
1120 save_did_emsg = did_emsg;
1121 did_emsg = FALSE;
1122 syntax_start(wp, lnum);
1123 if (did_emsg)
1124 wp->w_s->b_syn_error = TRUE;
1125 else
1126 {
1127 did_emsg = save_did_emsg;
1128#ifdef SYN_TIME_LIMIT
1129 if (!wp->w_s->b_syn_slow)
1130#endif
1131 {
1132 has_syntax = TRUE;
1133 extra_check = TRUE;
1134 }
1135 }
1136 }
1137
1138 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001139 wlv.color_cols = wp->w_p_cc_cols;
1140 if (wlv.color_cols != NULL)
1141 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001142#endif
1143
1144#ifdef FEAT_TERMINAL
1145 if (term_show_buffer(wp->w_buffer))
1146 {
1147 extra_check = TRUE;
1148 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001149 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001150 }
1151#endif
1152
1153#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001154 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001155 {
1156 // Prepare for spell checking.
1157 has_spell = TRUE;
1158 extra_check = TRUE;
1159
1160 // Get the start of the next line, so that words that wrap to the
1161 // next line are found too: "et<line-break>al.".
1162 // Trick: skip a few chars for C/shell/Vim comments
1163 nextline[SPWORDLEN] = NUL;
1164 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1165 {
1166 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1167 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1168 }
1169
1170 // When a word wrapped from the previous line the start of the
1171 // current line is valid.
1172 if (lnum == checked_lnum)
1173 cur_checked_col = checked_col;
1174 checked_lnum = 0;
1175
1176 // When there was a sentence end in the previous line may require a
1177 // word starting with capital in this line. In line 1 always check
1178 // the first word.
1179 if (lnum != capcol_lnum)
1180 cap_col = -1;
1181 if (lnum == 1)
1182 cap_col = 0;
1183 capcol_lnum = 0;
1184 }
1185#endif
1186
1187 // handle Visual active in this window
1188 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1189 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001190 pos_T *top, *bot;
1191
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001192 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1193 {
1194 // Visual is after curwin->w_cursor
1195 top = &curwin->w_cursor;
1196 bot = &VIsual;
1197 }
1198 else
1199 {
1200 // Visual is before curwin->w_cursor
1201 top = &VIsual;
1202 bot = &curwin->w_cursor;
1203 }
1204 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1205 if (VIsual_mode == Ctrl_V)
1206 {
1207 // block mode
1208 if (lnum_in_visual_area)
1209 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001210 wlv.fromcol = wp->w_old_cursor_fcol;
1211 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001212 }
1213 }
1214 else
1215 {
1216 // non-block mode
1217 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001218 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001219 else if (lnum == top->lnum)
1220 {
1221 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001222 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001223 else
1224 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001225 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001226 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001227 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001228 }
1229 }
1230 if (VIsual_mode != 'V' && lnum == bot->lnum)
1231 {
1232 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1233 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001234 wlv.fromcol = -10;
1235 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001236 }
1237 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001238 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001239 else
1240 {
1241 pos = *bot;
1242 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001243 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1244 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001245 else
1246 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001247 getvvcol(wp, &pos, NULL, NULL,
1248 (colnr_T *)&wlv.tocol);
1249 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001250 }
1251 }
1252 }
1253 }
1254
1255 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001256 if (!highlight_match && lnum == curwin->w_cursor.lnum
1257 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001258#ifdef FEAT_GUI
1259 && !gui.in_use
1260#endif
1261 )
1262 noinvcur = TRUE;
1263
1264 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001265 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001266 {
1267 area_highlighting = TRUE;
1268 vi_attr = HL_ATTR(HLF_V);
1269#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1270 if ((clip_star.available && !clip_star.owned
1271 && clip_isautosel_star())
1272 || (clip_plus.available && !clip_plus.owned
1273 && clip_isautosel_plus()))
1274 vi_attr = HL_ATTR(HLF_VNC);
1275#endif
1276 }
1277 }
1278
1279 // handle 'incsearch' and ":s///c" highlighting
1280 else if (highlight_match
1281 && wp == curwin
1282 && lnum >= curwin->w_cursor.lnum
1283 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1284 {
1285 if (lnum == curwin->w_cursor.lnum)
1286 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001287 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001288 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001289 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001290 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1291 {
1292 pos.lnum = lnum;
1293 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001294 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001295 }
1296 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001297 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001298 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001299 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1300 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001301 area_highlighting = TRUE;
1302 vi_attr = HL_ATTR(HLF_I);
1303 }
1304 }
1305
1306#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001307 wlv.filler_lines = diff_check(wp, lnum);
1308 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001309 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001310 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001311 {
1312 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001313 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001314 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001315 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001316 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001317 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001318 }
1319 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001320 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001321 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001322 area_highlighting = TRUE;
1323 }
1324 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001325 wlv.filler_lines = wp->w_topfill;
1326 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001327#endif
1328
1329#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001330 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001331 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001332 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001333#endif
1334
1335#ifdef LINE_ATTR
1336# ifdef FEAT_SIGNS
1337 // If this line has a sign with line highlighting set line_attr.
1338 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001339 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001340# endif
1341# if defined(FEAT_QUICKFIX)
1342 // Highlight the current line in the quickfix window.
1343 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1344 line_attr = HL_ATTR(HLF_QFL);
1345# endif
1346 if (line_attr != 0)
1347 area_highlighting = TRUE;
1348#endif
1349
1350 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1351 ptr = line;
1352
1353#ifdef FEAT_SPELL
1354 if (has_spell && !number_only)
1355 {
1356 // For checking first word with a capital skip white space.
1357 if (cap_col == 0)
1358 cap_col = getwhitecols(line);
1359
1360 // To be able to spell-check over line boundaries copy the end of the
1361 // current line into nextline[]. Above the start of the next line was
1362 // copied to nextline[SPWORDLEN].
1363 if (nextline[SPWORDLEN] == NUL)
1364 {
1365 // No next line or it is empty.
1366 nextlinecol = MAXCOL;
1367 nextline_idx = 0;
1368 }
1369 else
1370 {
1371 v = (long)STRLEN(line);
1372 if (v < SPWORDLEN)
1373 {
1374 // Short line, use it completely and append the start of the
1375 // next line.
1376 nextlinecol = 0;
1377 mch_memmove(nextline, line, (size_t)v);
1378 STRMOVE(nextline + v, nextline + SPWORDLEN);
1379 nextline_idx = v + 1;
1380 }
1381 else
1382 {
1383 // Long line, use only the last SPWORDLEN bytes.
1384 nextlinecol = v - SPWORDLEN;
1385 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1386 nextline_idx = SPWORDLEN + 1;
1387 }
1388 }
1389 }
1390#endif
1391
1392 if (wp->w_p_list)
1393 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001394 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001395 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001396 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001397 || wp->w_lcs_chars.trail
1398 || wp->w_lcs_chars.lead
1399 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001400 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001401
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001402 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001403 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001404 {
1405 trailcol = (colnr_T)STRLEN(ptr);
1406 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1407 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001408 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001409 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001410 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001411 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001412 {
1413 leadcol = 0;
1414 while (VIM_ISWHITE(ptr[leadcol]))
1415 ++leadcol;
1416 if (ptr[leadcol] == NUL)
1417 // in a line full of spaces all of them are treated as trailing
1418 leadcol = (colnr_T)0;
1419 else
1420 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001421 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001422 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001423 }
1424
Bram Moolenaard7657e92022-09-20 18:59:30 +01001425 wlv.wcr_attr = get_wcr_attr(wp);
1426 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001427 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001428 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001429 area_highlighting = TRUE;
1430 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001431
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001432#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001433 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001434 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001435#endif
1436
1437 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1438 // first character to be displayed.
1439 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001440 v = startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001441 else
1442 v = wp->w_leftcol;
1443 if (v > 0 && !number_only)
1444 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001445 char_u *prev_ptr = ptr;
1446 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001447 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001448
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001449 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001450 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001451 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001452 charsize = win_lbr_chartabsize(&cts, NULL);
1453 cts.cts_vcol += charsize;
1454 prev_ptr = cts.cts_ptr;
1455 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001456 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001457 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001458 ptr = cts.cts_ptr;
1459 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001460
1461 // When:
1462 // - 'cuc' is set, or
1463 // - 'colorcolumn' is set, or
1464 // - 'virtualedit' is set, or
1465 // - the visual mode is active,
1466 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001467 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001468#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001469 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001470#endif
1471 virtual_active() ||
1472 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001473 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001474
1475 // Handle a character that's not completely on the screen: Put ptr at
1476 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001477 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001478 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001479 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001480 ptr = prev_ptr;
1481 // If the character fits on the screen, don't need to skip it.
1482 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001483 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1484 && wlv.col == 0)
1485 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001486 }
1487
1488 // Adjust for when the inverted text is before the screen,
1489 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001490 if (wlv.tocol <= wlv.vcol)
1491 wlv.fromcol = 0;
1492 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1493 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001494
1495#ifdef FEAT_LINEBREAK
1496 // When w_skipcol is non-zero, first line needs 'showbreak'
1497 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001498 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001499#endif
1500#ifdef FEAT_SPELL
1501 // When spell checking a word we need to figure out the start of the
1502 // word and if it's badly spelled or not.
1503 if (has_spell)
1504 {
1505 int len;
1506 colnr_T linecol = (colnr_T)(ptr - line);
1507 hlf_T spell_hlf = HLF_COUNT;
1508
1509 pos = wp->w_cursor;
1510 wp->w_cursor.lnum = lnum;
1511 wp->w_cursor.col = linecol;
1512 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1513
1514 // spell_move_to() may call ml_get() and make "line" invalid
1515 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1516 ptr = line + linecol;
1517
1518 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1519 {
1520 // no bad word found at line start, don't check until end of a
1521 // word
1522 spell_hlf = HLF_COUNT;
1523 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1524 }
1525 else
1526 {
1527 // bad word found, use attributes until end of word
1528 word_end = wp->w_cursor.col + len + 1;
1529
1530 // Turn index into actual attributes.
1531 if (spell_hlf != HLF_COUNT)
1532 spell_attr = highlight_attr[spell_hlf];
1533 }
1534 wp->w_cursor = pos;
1535
1536# ifdef FEAT_SYN_HL
1537 // Need to restart syntax highlighting for this line.
1538 if (has_syntax)
1539 syntax_start(wp, lnum);
1540# endif
1541 }
1542#endif
1543 }
1544
1545 // Correct highlighting for cursor that can't be disabled.
1546 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001547 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001548 {
1549 if (noinvcur)
1550 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001551 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001552 {
1553 // highlighting starts at cursor, let it start just after the
1554 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001555 fromcol_prev = wlv.fromcol;
1556 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001557 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001558 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001559 // restart highlighting after the cursor
1560 fromcol_prev = wp->w_virtcol;
1561 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001562 if (wlv.fromcol >= wlv.tocol)
1563 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001564 }
1565
1566#ifdef FEAT_SEARCH_EXTRA
1567 if (!number_only)
1568 {
1569 v = (long)(ptr - line);
1570 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1571 &line, &screen_search_hl,
1572 &search_attr);
1573 ptr = line + v; // "line" may have been updated
1574 }
1575#endif
1576
1577#ifdef FEAT_SYN_HL
1578 // Cursor line highlighting for 'cursorline' in the current window.
1579 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1580 {
1581 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001582 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001583 if (!(wp == curwin && VIsual_active)
1584 && wp->w_p_culopt_flags != CULOPT_NBR)
1585 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001586 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001587 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1588
1589 // Only set line_attr here when "screenline" is not present in
1590 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001591 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001592 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001593 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001594# ifdef FEAT_SIGNS
1595 // Combine the 'cursorline' and sign highlighting, depending on
1596 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001597 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001598 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001599 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001600 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001601 else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001602 line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001603 }
1604 else
1605# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001606# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001607 // let the line attribute overrule 'cursorline', otherwise
1608 // it disappears when both have background set;
1609 // 'cursorline' can use underline or bold to make it show
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001610 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001611# else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001612 line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001613# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001614 }
1615 else
1616 {
1617 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001618 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1619 }
1620 area_highlighting = TRUE;
1621 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001622 }
1623#endif
1624
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001625#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001626 {
1627 char_u *prop_start;
1628
1629 text_prop_count = get_text_props(wp->w_buffer, lnum,
1630 &prop_start, FALSE);
1631 if (text_prop_count > 0)
1632 {
1633 // Make a copy of the properties, so that they are properly
1634 // aligned.
1635 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1636 if (text_props != NULL)
1637 mch_memmove(text_props, prop_start,
1638 text_prop_count * sizeof(textprop_T));
1639
1640 // Allocate an array for the indexes.
1641 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001642 if (text_prop_idxs == NULL)
1643 VIM_CLEAR(text_props);
1644
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001645 if (text_props != NULL)
1646 {
1647 area_highlighting = TRUE;
1648 extra_check = TRUE;
1649 for (int i = 0; i < text_prop_count; ++i)
1650 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1651 ++wlv.text_prop_above_count;
1652 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001653 }
1654 }
1655#endif
1656
Bram Moolenaar1306b362022-08-06 15:59:06 +01001657 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001658
1659 // Repeat for the whole displayed line.
1660 for (;;)
1661 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001662 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001663#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001664 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001665#endif
1666#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001667 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001668#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001669
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001670 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001671 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001672 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001673#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001674 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001675 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001676 wlv.cul_attr = 0;
zeertzjq4f33bc22021-08-05 17:57:02 +02001677 line_attr = line_attr_save;
1678 }
1679#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001680#ifdef FEAT_CMDWIN
Bram Moolenaar1306b362022-08-06 15:59:06 +01001681 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001682 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001683 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001684 if (cmdwin_type != 0 && wp == curwin)
1685 {
1686 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001687 wlv.n_extra = 1;
1688 wlv.c_extra = cmdwin_type;
1689 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001690 wlv.char_attr =
1691 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001692 }
1693 }
1694#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001695#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001696 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001697 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001698 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001699 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001700 }
1701#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001702#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001703 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001704 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001705 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001706 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001707 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001708 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001709 }
1710#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001711 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001712 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001713 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001714 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001715 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001716 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001717#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001718 // Check if 'breakindent' applies and show it.
1719 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1720 if (wlv.n_extra == 0)
1721 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001722#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001723#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001724 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001725 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001726 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001727 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001728 }
1729#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001730 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001731 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001732 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001733 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001734 }
1735 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001736
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001737#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001738 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001739 && wlv.vcol >= left_curline_col
1740 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001741 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001742 wlv.cul_attr = HL_ATTR(HLF_CUL);
1743 line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001744 }
1745#endif
1746
1747 // When still displaying '$' of change command, stop at cursor.
1748 // When only displaying the (relative) line number and that's done,
1749 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001750 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001751 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001752 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001753#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001754 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001755#endif
1756 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001757 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001758 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001759 // Pretend we have finished updating the window. Except when
1760 // 'cursorcolumn' is set.
1761#ifdef FEAT_SYN_HL
1762 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001763 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001764 else
1765#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001766 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001767 break;
1768 }
1769
Bram Moolenaar1306b362022-08-06 15:59:06 +01001770 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001771 {
1772 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001773 if (wlv.vcol == wlv.fromcol
1774 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1775 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001776 && (*mb_ptr2cells)(ptr) > 1)
1777 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001778 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001779 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001780 area_attr = vi_attr; // start highlighting
1781 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001782 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001783 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001784 area_attr = 0; // stop highlighting
1785
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001786#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001787 if (text_props != NULL)
1788 {
1789 int pi;
1790 int bcol = (int)(ptr - line);
1791
Bram Moolenaar1306b362022-08-06 15:59:06 +01001792 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001793# ifdef FEAT_LINEBREAK
1794 && !in_linebreak
1795# endif
1796 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001797 --bcol; // still working on the previous char, e.g. Tab
1798
1799 // Check if any active property ends.
1800 for (pi = 0; pi < text_props_active; ++pi)
1801 {
1802 int tpi = text_prop_idxs[pi];
1803
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001804 if (text_props[tpi].tp_col != MAXCOL
1805 && bcol >= text_props[tpi].tp_col - 1
1806 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001807 {
1808 if (pi + 1 < text_props_active)
1809 mch_memmove(text_prop_idxs + pi,
1810 text_prop_idxs + pi + 1,
1811 sizeof(int)
1812 * (text_props_active - (pi + 1)));
1813 --text_props_active;
1814 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001815# ifdef FEAT_LINEBREAK
1816 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001817 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001818 syntax_attr = 0;
1819# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001820 }
1821 }
1822
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001823# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001824 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001825 // not on the next char yet, don't start another prop
1826 --bcol;
1827# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001828 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001829 // With 'nowrap' and not in the first screen line only "below"
1830 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001831 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001832 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001833 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001834 && (wp->w_p_wrap
1835 || wlv.row == startrow
1836 || (text_props[text_prop_next].tp_flags
1837 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001838 || (bcol == 0 &&
1839 (text_props[text_prop_next].tp_flags
1840 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001841 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001842 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001843 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001844 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1845 {
1846 // first display the '$' after the line
1847 text_prop_follows = TRUE;
1848 break;
1849 }
1850 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001851 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001852 + text_props[text_prop_next].tp_len)
1853 text_prop_idxs[text_props_active++] = text_prop_next;
1854 ++text_prop_next;
1855 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001856
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001857 if (wlv.n_extra == 0 || !extra_for_textprop)
1858 {
1859 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001860 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001861 text_prop_flags = 0;
1862 text_prop_type = NULL;
1863 text_prop_id = 0;
1864 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001865 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001866 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001867 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001868 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001869 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001870
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001871 // Sort the properties on priority and/or starting last.
1872 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001873 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001874 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001875 sort_text_props(wp->w_buffer, text_props,
1876 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001877
1878 for (pi = 0; pi < text_props_active; ++pi)
1879 {
1880 int tpi = text_prop_idxs[pi];
1881 proptype_T *pt = text_prop_type_by_id(
1882 wp->w_buffer, text_props[tpi].tp_type);
1883
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001884 if (pt != NULL && (pt->pt_hl_id > 0
1885 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001886 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001887 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001888 if (pt->pt_hl_id > 0)
1889 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001890 text_prop_type = pt;
1891 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001892 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001893 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001894 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001895 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001896 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001897 }
1898 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001899 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001900 && -text_prop_id
1901 <= wp->w_buffer->b_textprop_text.ga_len)
1902 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001903 textprop_T *tp = &text_props[used_tpi];
1904 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001905 ->b_textprop_text.ga_data)[
1906 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001907 int above = (tp->tp_flags
1908 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001909
1910 // reset the ID in the copy to avoid it being used
1911 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001912 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001913
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001914 if (p != NULL)
1915 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001916 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001917 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001918 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001919 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001920 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1921 int padding = tp->tp_col == MAXCOL
1922 && tp->tp_len > 1
1923 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001924
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001925 // Insert virtual text before the current
1926 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001927 wlv.p_extra = p;
1928 wlv.c_extra = NUL;
1929 wlv.c_final = NUL;
1930 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001931 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001932 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001933 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001934 // restore search_attr and area_attr when n_extra
1935 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001936 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001937 saved_area_attr = area_attr;
1938 search_attr = 0;
1939 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001940 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001941 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001942 if (*ptr == NUL)
1943 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001944 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001945#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001946 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001947 {
1948 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001949 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001950 wlv.need_showbreak = FALSE;
1951 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001952 }
1953#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001954 if ((right || above || below || !wrap
1955 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001956 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001957 char_u *prev_p_extra = wlv.p_extra;
1958 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001959
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001960 // Take care of padding, right-align and
1961 // truncation.
1962 // Shared with win_lbr_chartabsize(), must do
1963 // exactly the same.
1964 start_line = text_prop_position(wp, tp,
1965 wlv.col,
1966 &wlv.n_extra, &wlv.p_extra,
1967 &n_attr, &n_attr_skip);
1968 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001969 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001970 // wlv.p_extra was allocated
1971 vim_free(p_extra_free2);
1972 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001973 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001974
Bram Moolenaara4abe512022-09-15 19:44:09 +01001975 if (lcs_eol_one < 0 && wlv.col
1976 + wlv.n_extra - 2 > wp->w_width)
1977 // don't bail out at end of line
1978 lcs_eol_one = 0;
1979
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001980 // When 'wrap' is off then for "below" we need
1981 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001982 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001983 {
1984 draw_screen_line(wp, &wlv);
1985
1986 // When line got too long for screen break
1987 // here.
1988 if (wlv.row == endrow)
1989 {
1990 ++wlv.row;
1991 break;
1992 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001993 win_line_start(wp, &wlv, TRUE);
1994 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001995 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001996 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001997 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001998
1999 // If another text prop follows the condition below at
2000 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002001 // If this is an "above" text prop and 'nowrap' the we
2002 // must wrap anyway.
2003 text_prop_above = above;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002004 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002005 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002006 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002007 else if (text_prop_next < text_prop_count
2008 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002009 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2010 || (!wp->w_p_wrap
2011 && wlv.col == wp->w_width - 1
2012 && (text_props[text_prop_next].tp_flags
2013 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002014 // When at last-but-one character and a text property
2015 // follows after it, we may need to flush the line after
2016 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002017 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002018 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002019 }
2020#endif
2021
Bram Moolenaare38fc862022-08-11 17:24:50 +01002022#ifdef FEAT_SEARCH_EXTRA
2023 if (wlv.n_extra == 0)
2024 {
2025 // Check for start/end of 'hlsearch' and other matches.
2026 // After end, check for start/end of next match.
2027 // When another match, have to check for start again.
2028 v = (long)(ptr - line);
2029 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2030 &screen_search_hl, &has_match_conc,
2031 &match_conc, did_line_attr, lcs_eol_one,
2032 &on_last_col);
2033 ptr = line + v; // "line" may have been changed
2034 prev_ptr = ptr;
2035
2036 // Do not allow a conceal over EOL otherwise EOL will be missed
2037 // and bad things happen.
2038 if (*ptr == NUL)
2039 has_match_conc = 0;
2040 }
2041#endif
2042
2043#ifdef FEAT_DIFF
2044 if (wlv.diff_hlf != (hlf_T)0)
2045 {
2046 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2047 && wlv.n_extra == 0)
2048 wlv.diff_hlf = HLF_TXD; // changed text
2049 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2050 && wlv.n_extra == 0)
2051 wlv.diff_hlf = HLF_CHD; // changed line
2052 line_attr = HL_ATTR(wlv.diff_hlf);
2053 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2054 && wp->w_p_culopt_flags != CULOPT_NBR
2055 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2056 && wlv.vcol <= right_curline_col)))
2057 line_attr = hl_combine_attr(
2058 line_attr, HL_ATTR(HLF_CUL));
2059 }
2060#endif
2061
Bram Moolenaara74fda62019-10-19 17:38:03 +02002062#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002063 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002064 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002065 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002066# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002067 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002068 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002069# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002070 // Get syntax attribute.
2071 if (has_syntax)
2072 {
2073 // Get the syntax attribute for the character. If there
2074 // is an error, disable syntax highlighting.
2075 save_did_emsg = did_emsg;
2076 did_emsg = FALSE;
2077
2078 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002079 if (v == prev_syntax_col)
2080 // at same column again
2081 syntax_attr = prev_syntax_attr;
2082 else
2083 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002084# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002085 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002086# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002087 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002088# ifdef FEAT_SPELL
2089 has_spell ? &can_spell :
2090# endif
2091 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002092 prev_syntax_col = v;
2093 prev_syntax_attr = syntax_attr;
2094 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002095
Bram Moolenaar34390282019-10-16 14:38:26 +02002096 if (did_emsg)
2097 {
2098 wp->w_s->b_syn_error = TRUE;
2099 has_syntax = FALSE;
2100 syntax_attr = 0;
2101 }
2102 else
2103 did_emsg = save_did_emsg;
2104# ifdef SYN_TIME_LIMIT
2105 if (wp->w_s->b_syn_slow)
2106 has_syntax = FALSE;
2107# endif
2108
2109 // Need to get the line again, a multi-line regexp may
2110 // have made it invalid.
2111 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2112 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002113 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002114# ifdef FEAT_CONCEAL
2115 // no concealing past the end of the line, it interferes
2116 // with line highlighting
2117 if (*ptr == NUL)
2118 syntax_flags = 0;
2119 else
2120 syntax_flags = get_syntax_info(&syntax_seqnr);
2121# endif
2122 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002123 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002124# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002125 // Combine text property highlight into syntax highlight.
2126 if (text_prop_type != NULL)
2127 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002128 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002129 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2130 else
2131 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002132 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002133 }
2134# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002135#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002136
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002137 // Decide which of the highlight attributes to use.
2138 attr_pri = TRUE;
2139#ifdef LINE_ATTR
2140 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002141 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002142 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002143 if (!highlight_match)
2144 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002145 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002146# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002147 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002148# endif
2149 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002150 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002151 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002152 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002153# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002154 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002155# endif
2156 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002157 else if (line_attr != 0
2158 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2159 || wlv.vcol < wlv.fromcol
2160 || vcol_prev < fromcol_prev
2161 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002162 {
2163 // Use line_attr when not in the Visual or 'incsearch' area
2164 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002165# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002166 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002167# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002168 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002169# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002170 attr_pri = FALSE;
2171 }
2172#else
2173 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002174 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002175 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002176 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002177#endif
2178 else
2179 {
2180 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002181#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002182 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002183#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002184 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002185#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002186 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002187#ifdef FEAT_PROP_POPUP
2188 // override with text property highlight when "override" is TRUE
2189 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002190 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002191#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002192 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002193
2194 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002195 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002196 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002197 if (wlv.char_attr == 0)
2198 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002199 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002200 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002201 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002202
2203 // Get the next character to put on the screen.
2204
2205 // The "p_extra" points to the extra stuff that is inserted to
2206 // represent special characters (non-printable stuff) and other
2207 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002208 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002209 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2210 // "p_extra[n_extra]".
2211 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002212 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002213 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002214 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002215 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002216 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2217 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002218 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2219 if (enc_utf8 && utf_char2len(c) > 1)
2220 {
2221 mb_utf8 = TRUE;
2222 u8cc[0] = 0;
2223 c = 0xc0;
2224 }
2225 else
2226 mb_utf8 = FALSE;
2227 }
2228 else
2229 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002230 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002231 if (has_mbyte)
2232 {
2233 mb_c = c;
2234 if (enc_utf8)
2235 {
2236 // If the UTF-8 character is more than one byte:
2237 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002238 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002239 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002240 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002241 mb_l = 1;
2242 else if (mb_l > 1)
2243 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002244 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002245 mb_utf8 = TRUE;
2246 c = 0xc0;
2247 }
2248 }
2249 else
2250 {
2251 // if this is a DBCS character, put it in "mb_c"
2252 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002253 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002254 mb_l = 1;
2255 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002256 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002257 }
2258 if (mb_l == 0) // at the NUL at end-of-line
2259 mb_l = 1;
2260
2261 // If a double-width char doesn't fit display a '>' in the
2262 // last column.
2263 if ((
2264# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002265 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002266# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002267 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002268 && (*mb_char2cells)(mb_c) == 2)
2269 {
2270 c = '>';
2271 mb_c = c;
2272 mb_l = 1;
2273 mb_utf8 = FALSE;
2274 multi_attr = HL_ATTR(HLF_AT);
2275#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002276 if (wlv.cul_attr)
2277 multi_attr = hl_combine_attr(
2278 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002279#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002280 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002281
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002282 // put the pointer back to output the double-width
2283 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002284 ++wlv.n_extra;
2285 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002286 }
2287 else
2288 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002289 wlv.n_extra -= mb_l - 1;
2290 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002291 }
2292 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002293 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002294 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002295 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002296#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002297 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002298 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002299 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002300 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002301 if (search_attr == 0)
2302 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002303 if (area_attr == 0 && *ptr != NUL)
2304 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002305 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002306#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002307 }
2308 else
2309 {
2310#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002311 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002312#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002313 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002314
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002315 // Get a character from the line itself.
2316 c = *ptr;
2317#ifdef FEAT_LINEBREAK
2318 c0 = *ptr;
2319#endif
2320 if (has_mbyte)
2321 {
2322 mb_c = c;
2323 if (enc_utf8)
2324 {
2325 // If the UTF-8 character is more than one byte: Decode it
2326 // into "mb_c".
2327 mb_l = utfc_ptr2len(ptr);
2328 mb_utf8 = FALSE;
2329 if (mb_l > 1)
2330 {
2331 mb_c = utfc_ptr2char(ptr, u8cc);
2332 // Overlong encoded ASCII or ASCII with composing char
2333 // is displayed normally, except a NUL.
2334 if (mb_c < 0x80)
2335 {
2336 c = mb_c;
2337#ifdef FEAT_LINEBREAK
2338 c0 = mb_c;
2339#endif
2340 }
2341 mb_utf8 = TRUE;
2342
2343 // At start of the line we can have a composing char.
2344 // Draw it as a space with a composing char.
2345 if (utf_iscomposing(mb_c))
2346 {
2347 int i;
2348
2349 for (i = Screen_mco - 1; i > 0; --i)
2350 u8cc[i] = u8cc[i - 1];
2351 u8cc[0] = mb_c;
2352 mb_c = ' ';
2353 }
2354 }
2355
2356 if ((mb_l == 1 && c >= 0x80)
2357 || (mb_l >= 1 && mb_c == 0)
2358 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2359 {
2360 // Illegal UTF-8 byte: display as <xx>.
2361 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002362 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002363# ifdef FEAT_RIGHTLEFT
2364 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002365 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002366# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002367 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002368 c = *wlv.p_extra;
2369 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002370 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002371 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2372 wlv.c_extra = NUL;
2373 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002374 if (area_attr == 0 && search_attr == 0)
2375 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002376 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002377 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002378 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002379 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002380 }
2381 }
2382 else if (mb_l == 0) // at the NUL at end-of-line
2383 mb_l = 1;
2384#ifdef FEAT_ARABIC
2385 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2386 {
2387 // Do Arabic shaping.
2388 int pc, pc1, nc;
2389 int pcc[MAX_MCO];
2390
2391 // The idea of what is the previous and next
2392 // character depends on 'rightleft'.
2393 if (wp->w_p_rl)
2394 {
2395 pc = prev_c;
2396 pc1 = prev_c1;
2397 nc = utf_ptr2char(ptr + mb_l);
2398 prev_c1 = u8cc[0];
2399 }
2400 else
2401 {
2402 pc = utfc_ptr2char(ptr + mb_l, pcc);
2403 nc = prev_c;
2404 pc1 = pcc[0];
2405 }
2406 prev_c = mb_c;
2407
2408 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2409 }
2410 else
2411 prev_c = mb_c;
2412#endif
2413 }
2414 else // enc_dbcs
2415 {
2416 mb_l = MB_BYTE2LEN(c);
2417 if (mb_l == 0) // at the NUL at end-of-line
2418 mb_l = 1;
2419 else if (mb_l > 1)
2420 {
2421 // We assume a second byte below 32 is illegal.
2422 // Hopefully this is OK for all double-byte encodings!
2423 if (ptr[1] >= 32)
2424 mb_c = (c << 8) + ptr[1];
2425 else
2426 {
2427 if (ptr[1] == NUL)
2428 {
2429 // head byte at end of line
2430 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002431 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002432 }
2433 else
2434 {
2435 // illegal tail byte
2436 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002437 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002438 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002439 wlv.p_extra = wlv.extra;
2440 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002441 wlv.c_extra = NUL;
2442 wlv.c_final = NUL;
2443 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002444 if (area_attr == 0 && search_attr == 0)
2445 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002446 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002447 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002448 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002449 // save current attr
2450 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002451 }
2452 mb_c = c;
2453 }
2454 }
2455 }
2456 // If a double-width char doesn't fit display a '>' in the
2457 // last column; the character is displayed at the start of the
2458 // next line.
2459 if ((
2460# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002461 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002462# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002463 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002464 && (*mb_char2cells)(mb_c) == 2)
2465 {
2466 c = '>';
2467 mb_c = c;
2468 mb_utf8 = FALSE;
2469 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002470 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002471 // Put pointer back so that the character will be
2472 // displayed at the start of the next line.
2473 --ptr;
2474#ifdef FEAT_CONCEAL
2475 did_decrement_ptr = TRUE;
2476#endif
2477 }
2478 else if (*ptr != NUL)
2479 ptr += mb_l - 1;
2480
2481 // If a double-width char doesn't fit at the left side display
2482 // a '<' in the first column. Don't do this for unprintable
2483 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002484 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002485 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002486 wlv.n_extra = 1;
2487 wlv.c_extra = MB_FILLER_CHAR;
2488 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002489 c = ' ';
2490 if (area_attr == 0 && search_attr == 0)
2491 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002492 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002493 extra_attr = hl_combine_attr(
2494 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002495 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002496 }
2497 mb_c = c;
2498 mb_utf8 = FALSE;
2499 mb_l = 1;
2500 }
2501
2502 }
2503 ++ptr;
2504
2505 if (extra_check)
2506 {
2507#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002508 // Check spelling (unless at the end of the line).
2509 // Only do this when there is no syntax highlighting, the
2510 // @Spell cluster is not used or the current syntax item
2511 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002512 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002513 if (has_spell && v >= word_end && v > cur_checked_col)
2514 {
2515 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002516 // do not calculate cap_col at the end of the line or when
2517 // only white space is following
2518 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002519# ifdef FEAT_SYN_HL
2520 !has_syntax ||
2521# endif
2522 can_spell))
2523 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002524 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002525 int len;
2526 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002527
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002528 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002529 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002530
2531 // Use nextline[] if possible, it has the start of the
2532 // next line concatenated.
2533 if ((prev_ptr - line) - nextlinecol >= 0)
2534 p = nextline + (prev_ptr - line) - nextlinecol;
2535 else
2536 p = prev_ptr;
2537 cap_col -= (int)(prev_ptr - line);
2538 len = spell_check(wp, p, &spell_hlf, &cap_col,
2539 nochange);
2540 word_end = v + len;
2541
2542 // In Insert mode only highlight a word that
2543 // doesn't touch the cursor.
2544 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002545 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002546 && wp->w_cursor.lnum == lnum
2547 && wp->w_cursor.col >=
2548 (colnr_T)(prev_ptr - line)
2549 && wp->w_cursor.col < (colnr_T)word_end)
2550 {
2551 spell_hlf = HLF_COUNT;
2552 spell_redraw_lnum = lnum;
2553 }
2554
2555 if (spell_hlf == HLF_COUNT && p != prev_ptr
2556 && (p - nextline) + len > nextline_idx)
2557 {
2558 // Remember that the good word continues at the
2559 // start of the next line.
2560 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002561 checked_col = (int)((p - nextline)
2562 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002563 }
2564
2565 // Turn index into actual attributes.
2566 if (spell_hlf != HLF_COUNT)
2567 spell_attr = highlight_attr[spell_hlf];
2568
2569 if (cap_col > 0)
2570 {
2571 if (p != prev_ptr
2572 && (p - nextline) + cap_col >= nextline_idx)
2573 {
2574 // Remember that the word in the next line
2575 // must start with a capital.
2576 capcol_lnum = lnum + 1;
2577 cap_col = (int)((p - nextline) + cap_col
2578 - nextline_idx);
2579 }
2580 else
2581 // Compute the actual column.
2582 cap_col += (int)(prev_ptr - line);
2583 }
2584 }
2585 }
2586 if (spell_attr != 0)
2587 {
2588 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002589 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2590 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002591 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002592 wlv.char_attr = hl_combine_attr(spell_attr,
2593 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002594 }
2595#endif
2596#ifdef FEAT_LINEBREAK
2597 // Found last space before word: check for line break.
2598 if (wp->w_p_lbr && c0 == c
2599 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2600 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002601 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2602 : 0;
2603 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002604 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002605
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002606 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002607# ifdef FEAT_PROP_POPUP
2608 // do not want virtual text counted here
2609 cts.cts_has_prop_with_text = FALSE;
2610# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002611 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002612 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002613
2614 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002615 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002616 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002617 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002618 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2619 if (wlv.n_extra < 0)
2620 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002621 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002622 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002623 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002624 // line break, but for TABs the highlighting should
2625 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002626 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002627
Bram Moolenaar1306b362022-08-06 15:59:06 +01002628 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002629# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002630 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002631 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002632 wp->w_buffer->b_p_vts_array) - 1;
2633# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002634 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002635 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002636# endif
2637
Bram Moolenaar1306b362022-08-06 15:59:06 +01002638 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2639 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002640# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002641 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002642 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002643# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002644 if (VIM_ISWHITE(c))
2645 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002646# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002647 if (c == TAB)
2648 // See "Tab alignment" below.
2649 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002650# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002651 if (!wp->w_p_list)
2652 c = ' ';
2653 }
2654 }
2655#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002656 in_multispace = c == ' '
2657 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2658 if (!in_multispace)
2659 multispace_pos = 0;
2660
Bram Moolenaareed9d462021-02-15 20:38:25 +01002661 // 'list': Change char 160 to 'nbsp' and space to 'space'
2662 // setting in 'listchars'. But not when the character is
2663 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002664 if (wp->w_p_list
2665 && ((((c == 160 && mb_l == 1)
2666 || (mb_utf8
2667 && ((mb_c == 160 && mb_l == 2)
2668 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002669 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002670 || (c == ' '
2671 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002672 && (wp->w_lcs_chars.space
2673 || (in_multispace
2674 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002675 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002676 && ptr - line <= trailcol)))
2677 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002678 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2679 {
2680 c = wp->w_lcs_chars.multispace[multispace_pos++];
2681 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2682 multispace_pos = 0;
2683 }
2684 else
2685 c = (c == ' ') ? wp->w_lcs_chars.space
2686 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002687 if (area_attr == 0 && search_attr == 0)
2688 {
2689 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002690 extra_attr = hl_combine_attr(wlv.win_attr,
2691 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002692 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002693 }
2694 mb_c = c;
2695 if (enc_utf8 && utf_char2len(c) > 1)
2696 {
2697 mb_utf8 = TRUE;
2698 u8cc[0] = 0;
2699 c = 0xc0;
2700 }
2701 else
2702 mb_utf8 = FALSE;
2703 }
2704
zeertzjq2e7cba32022-06-10 15:30:32 +01002705 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2706 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002707 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002708 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2709 && wp->w_lcs_chars.leadmultispace != NULL)
2710 {
2711 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002712 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2713 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002714 multispace_pos = 0;
2715 }
2716
2717 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2718 c = wp->w_lcs_chars.trail;
2719
2720 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2721 c = wp->w_lcs_chars.lead;
2722
zeertzjq2e7cba32022-06-10 15:30:32 +01002723 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002724 c = wp->w_lcs_chars.space;
2725
2726
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002727 if (!attr_pri)
2728 {
2729 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002730 extra_attr = hl_combine_attr(wlv.win_attr,
2731 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002732 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002733 }
2734 mb_c = c;
2735 if (enc_utf8 && utf_char2len(c) > 1)
2736 {
2737 mb_utf8 = TRUE;
2738 u8cc[0] = 0;
2739 c = 0xc0;
2740 }
2741 else
2742 mb_utf8 = FALSE;
2743 }
2744 }
2745
2746 // Handling of non-printable characters.
2747 if (!vim_isprintc(c))
2748 {
2749 // when getting a character from the file, we may have to
2750 // turn it into something else on the way to putting it
2751 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002752 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002753 {
2754 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002755 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002756#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002757 char_u *sbr = get_showbreak_value(wp);
2758
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002759 // only adjust the tab_len, when at the first column
2760 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002761 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002762 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002763#endif
2764 // tab amount depends on current column
2765#ifdef FEAT_VARTABS
2766 tab_len = tabstop_padding(vcol_adjusted,
2767 wp->w_buffer->b_p_ts,
2768 wp->w_buffer->b_p_vts_array) - 1;
2769#else
2770 tab_len = (int)wp->w_buffer->b_p_ts
2771 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2772#endif
2773
2774#ifdef FEAT_LINEBREAK
2775 if (!wp->w_p_lbr || !wp->w_p_list)
2776#endif
2777 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002778 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002779#ifdef FEAT_LINEBREAK
2780 else
2781 {
2782 char_u *p;
2783 int len;
2784 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002785 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002786
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002787# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002788 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002789 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002790 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002791
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002792 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002793 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002794 && old_boguscols > 0
2795 && wlv.n_extra > tab_len)
2796 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002797# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002798 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002799 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002800 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002801 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002802 if (wp->w_lcs_chars.tab3)
2803 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002804 if (wlv.n_extra > 0)
2805 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002806 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002807 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002808 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002809 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002810 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002811 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002812 vim_memset(p, ' ', len);
2813 p[len] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002814 vim_free(wlv.p_extra_free);
2815 wlv.p_extra_free = p;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002816 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002817 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002818 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002819
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002820 if (*p == NUL)
2821 {
2822 tab_len = i;
2823 break;
2824 }
2825
2826 // if tab3 is given, use it for the last char
2827 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2828 lcs = wp->w_lcs_chars.tab3;
2829 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002830 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002831 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002832 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002833 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002834# ifdef FEAT_CONCEAL
2835 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2836 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002837 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002838 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002839# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002840 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002841 }
2842#endif
2843#ifdef FEAT_CONCEAL
2844 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002845 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002846
2847 // Tab alignment should be identical regardless of
2848 // 'conceallevel' value. So tab compensates of all
2849 // previous concealed characters, and thus resets
2850 // vcol_off and boguscols accumulated so far in the
2851 // line. Note that the tab can be longer than
2852 // 'tabstop' when there are concealed characters.
2853 FIX_FOR_BOGUSCOLS;
2854
2855 // Make sure, the highlighting for the tab char will be
2856 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002857 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002858 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002859 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002860 tab_len += vc_saved;
2861 }
2862#endif
2863 mb_utf8 = FALSE; // don't draw as UTF-8
2864 if (wp->w_p_list)
2865 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002866 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002867 ? wp->w_lcs_chars.tab3
2868 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002869#ifdef FEAT_LINEBREAK
2870 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002871 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002872 else
2873#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002874 wlv.c_extra = wp->w_lcs_chars.tab2;
2875 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002876 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002877 extra_attr = hl_combine_attr(wlv.win_attr,
2878 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002879 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002880 mb_c = c;
2881 if (enc_utf8 && utf_char2len(c) > 1)
2882 {
2883 mb_utf8 = TRUE;
2884 u8cc[0] = 0;
2885 c = 0xc0;
2886 }
2887 }
2888 else
2889 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002890 wlv.c_final = NUL;
2891 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002892 c = ' ';
2893 }
2894 }
2895 else if (c == NUL
2896 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002897 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
2898 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002899 && VIsual_mode != Ctrl_V
2900 && (
2901# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002902 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002903# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002904 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002905 && !(noinvcur
2906 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002907 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002908 && lcs_eol_one > 0)
2909 {
2910 // Display a '$' after the line or highlight an extra
2911 // character if the line break is included.
2912#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2913 // For a diff line the highlighting continues after the
2914 // "$".
2915 if (
2916# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002917 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002918# ifdef LINE_ATTR
2919 &&
2920# endif
2921# endif
2922# ifdef LINE_ATTR
2923 line_attr == 0
2924# endif
2925 )
2926#endif
2927 {
2928 // In virtualedit, visual selections may extend
2929 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002930 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002931 && wlv.tocol != MAXCOL
2932 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002933 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002934 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002935 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002936 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2937 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002938 else
2939 c = ' ';
2940 lcs_eol_one = -1;
2941 --ptr; // put it back at the NUL
2942 if (!attr_pri)
2943 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002944 extra_attr = hl_combine_attr(wlv.win_attr,
2945 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002946 n_attr = 1;
2947 }
2948 mb_c = c;
2949 if (enc_utf8 && utf_char2len(c) > 1)
2950 {
2951 mb_utf8 = TRUE;
2952 u8cc[0] = 0;
2953 c = 0xc0;
2954 }
2955 else
2956 mb_utf8 = FALSE; // don't draw as UTF-8
2957 }
2958 else if (c != NUL)
2959 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002960 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2961 if (wlv.n_extra == 0)
2962 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002963#ifdef FEAT_RIGHTLEFT
2964 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002965 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002966#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002967 wlv.c_extra = NUL;
2968 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002969#ifdef FEAT_LINEBREAK
2970 if (wp->w_p_lbr)
2971 {
2972 char_u *p;
2973
Bram Moolenaar1306b362022-08-06 15:59:06 +01002974 c = *wlv.p_extra;
2975 p = alloc(wlv.n_extra + 1);
2976 vim_memset(p, ' ', wlv.n_extra);
2977 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2978 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002979 vim_free(wlv.p_extra_free);
2980 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002981 }
2982 else
2983#endif
2984 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002985 wlv.n_extra = byte2cells(c) - 1;
2986 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002987 }
2988 if (!attr_pri)
2989 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002990 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002991 extra_attr = hl_combine_attr(wlv.win_attr,
2992 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002993 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002994 }
2995 mb_utf8 = FALSE; // don't draw as UTF-8
2996 }
2997 else if (VIsual_active
2998 && (VIsual_mode == Ctrl_V
2999 || VIsual_mode == 'v')
3000 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003001 && wlv.tocol != MAXCOL
3002 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003003 && (
3004#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003005 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003006#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003007 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003008 {
3009 c = ' ';
3010 --ptr; // put it back at the NUL
3011 }
3012#if defined(LINE_ATTR)
3013 else if ((
3014# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003015 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003016# endif
3017# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003018 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003019# endif
3020 line_attr != 0
3021 ) && (
3022# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003023 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003024# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003025 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003026# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003027 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003028# endif
3029 < wp->w_width)))
3030 {
3031 // Highlight until the right side of the window
3032 c = ' ';
3033 --ptr; // put it back at the NUL
3034
3035 // Remember we do the char for line highlighting.
3036 ++did_line_attr;
3037
3038 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01003039 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003040 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003041 || (wp->w_p_list &&
3042 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003043 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003044# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003045 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003046 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003047 wlv.diff_hlf = HLF_CHD;
3048 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003049 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003050 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003051 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3052 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003053 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003054 || (wlv.vcol >= left_curline_col
3055 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003056 wlv.char_attr = hl_combine_attr(
3057 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003058 }
3059 }
3060# endif
3061# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003062 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003063 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003064 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003065 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3066 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003067 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003068 if (!wlv.cul_screenline
3069 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003070 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003071 wlv.char_attr = hl_combine_attr(
3072 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003073 }
3074 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003075 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3076 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003077 }
3078# endif
3079 }
3080#endif
3081 }
3082
3083#ifdef FEAT_CONCEAL
3084 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003085 && (wp != curwin || lnum != wp->w_cursor.lnum
3086 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003087 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3088 && !(lnum_in_visual_area
3089 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3090 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003091 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003092 if (((prev_syntax_id != syntax_seqnr
3093 && (syntax_flags & HL_CONCEAL) != 0)
3094 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003095 && (syn_get_sub_char() != NUL
3096 || (has_match_conc && match_conc)
3097 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003098 && wp->w_p_cole != 3)
3099 {
3100 // First time at this concealed item: display one
3101 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003102 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003103 c = match_conc;
3104 else if (syn_get_sub_char() != NUL)
3105 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003106 else if (wp->w_lcs_chars.conceal != NUL)
3107 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003108 else
3109 c = ' ';
3110
3111 prev_syntax_id = syntax_seqnr;
3112
Bram Moolenaar1306b362022-08-06 15:59:06 +01003113 if (wlv.n_extra > 0)
3114 wlv.vcol_off += wlv.n_extra;
3115 wlv.vcol += wlv.n_extra;
3116 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003117 {
3118# ifdef FEAT_RIGHTLEFT
3119 if (wp->w_p_rl)
3120 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003121 wlv.col -= wlv.n_extra;
3122 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003123 }
3124 else
3125# endif
3126 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003127 wlv.boguscols += wlv.n_extra;
3128 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003129 }
3130 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003131 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003132 n_attr = 0;
3133 }
3134 else if (n_skip == 0)
3135 {
3136 is_concealing = TRUE;
3137 n_skip = 1;
3138 }
3139 mb_c = c;
3140 if (enc_utf8 && utf_char2len(c) > 1)
3141 {
3142 mb_utf8 = TRUE;
3143 u8cc[0] = 0;
3144 c = 0xc0;
3145 }
3146 else
3147 mb_utf8 = FALSE; // don't draw as UTF-8
3148 }
3149 else
3150 {
3151 prev_syntax_id = 0;
3152 is_concealing = FALSE;
3153 }
3154
3155 if (n_skip > 0 && did_decrement_ptr)
3156 // not showing the '>', put pointer back to avoid getting stuck
3157 ++ptr;
3158
3159#endif // FEAT_CONCEAL
3160 }
3161
3162#ifdef FEAT_CONCEAL
3163 // In the cursor line and we may be concealing characters: correct
3164 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003165 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003166 && wp == curwin && lnum == wp->w_cursor.lnum
3167 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003168 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003169 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003170# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003171 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003172 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003173 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003174# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003175 wp->w_wcol = wlv.col - wlv.boguscols;
3176 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003177 did_wcol = TRUE;
3178 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003179# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003180 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003181# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003182 }
3183#endif
3184
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003185 // Use "extra_attr", but don't override visual selection highlighting,
3186 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003187 // Don't use "extra_attr" until n_attr_skip is zero.
3188 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003189 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003190 && (!attr_pri
3191#ifdef FEAT_PROP_POPUP
3192 || (text_prop_flags & PT_FLAG_OVERRIDE)
3193#endif
3194 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003195 {
3196#ifdef LINE_ATTR
3197 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003198 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003199 else
3200#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003201 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003202 }
3203
3204#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3205 // XIM don't send preedit_start and preedit_end, but they send
3206 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3207 // im_is_preediting() here.
3208 if (p_imst == IM_ON_THE_SPOT
3209 && xic != NULL
3210 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003211 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003212 && !p_imdisable
3213 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003214 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003215 {
3216 colnr_T tcol;
3217
3218 if (preedit_end_col == MAXCOL)
3219 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3220 else
3221 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003222 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003223 {
3224 if (feedback_old_attr < 0)
3225 {
3226 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003227 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003228 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003229 wlv.char_attr = im_get_feedback_attr(feedback_col);
3230 if (wlv.char_attr < 0)
3231 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003232 feedback_col++;
3233 }
3234 else if (feedback_old_attr >= 0)
3235 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003236 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003237 feedback_old_attr = -1;
3238 feedback_col = 0;
3239 }
3240 }
3241#endif
3242 // Handle the case where we are in column 0 but not on the first
3243 // character of the line and the user wants us to show us a
3244 // special character (via 'listchars' option "precedes:<char>".
3245 if (lcs_prec_todo != NUL
3246 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003247 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3248 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003249#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003250 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003251#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003252 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003253 && c != NUL)
3254 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003255 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003256 lcs_prec_todo = NUL;
3257 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3258 {
3259 // Double-width character being overwritten by the "precedes"
3260 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003261 wlv.c_extra = MB_FILLER_CHAR;
3262 wlv.c_final = NUL;
3263 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003264 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003265 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003266 }
3267 mb_c = c;
3268 if (enc_utf8 && utf_char2len(c) > 1)
3269 {
3270 mb_utf8 = TRUE;
3271 u8cc[0] = 0;
3272 c = 0xc0;
3273 }
3274 else
3275 mb_utf8 = FALSE; // don't draw as UTF-8
3276 if (!attr_pri)
3277 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003278 saved_attr3 = wlv.char_attr; // save current attr
3279 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003280 n_attr3 = 1;
3281 }
3282 }
3283
3284 // At end of the text line or just after the last character.
3285 if ((c == NUL
3286#if defined(LINE_ATTR)
3287 || did_line_attr == 1
3288#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003289 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003290 {
3291#ifdef FEAT_SEARCH_EXTRA
3292 // flag to indicate whether prevcol equals startcol of search_hl or
3293 // one of the matches
3294 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3295 (long)(ptr - line) - (c == NUL));
3296#endif
3297 // Invert at least one char, used for Visual and empty line or
3298 // highlight match at end of line. If it's beyond the last
3299 // char on the screen, just overwrite that one (tricky!) Not
3300 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003301 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003302 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003303 && (VIsual_mode != Ctrl_V
3304 || lnum == VIsual.lnum
3305 || lnum == curwin->w_cursor.lnum)
3306 && c == NUL)
3307#ifdef FEAT_SEARCH_EXTRA
3308 // highlight 'hlsearch' match at end of line
3309 || (prevcol_hl_flag
3310# ifdef FEAT_SYN_HL
3311 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3312 && !(wp == curwin && VIsual_active))
3313# endif
3314# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003315 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003316# endif
3317# if defined(LINE_ATTR)
3318 && did_line_attr <= 1
3319# endif
3320 )
3321#endif
3322 ))
3323 {
3324 int n = 0;
3325
3326#ifdef FEAT_RIGHTLEFT
3327 if (wp->w_p_rl)
3328 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003329 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003330 n = 1;
3331 }
3332 else
3333#endif
3334 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003335 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003336 n = -1;
3337 }
3338 if (n != 0)
3339 {
3340 // At the window boundary, highlight the last character
3341 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003342 wlv.off += n;
3343 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003344 }
3345 else
3346 {
3347 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003348 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003349 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003350 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003351 }
3352#ifdef FEAT_SEARCH_EXTRA
3353 if (area_attr == 0)
3354 {
3355 // Use attributes from match with highest priority among
3356 // 'search_hl' and the match list.
3357 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003358 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003359 }
3360#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003361 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003362 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003363#ifdef FEAT_RIGHTLEFT
3364 if (wp->w_p_rl)
3365 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003366 --wlv.col;
3367 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003368 }
3369 else
3370#endif
3371 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003372 ++wlv.col;
3373 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003374 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003375 ++wlv.vcol;
3376 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003377 }
3378 }
3379
3380 // At end of the text line.
3381 if (c == NUL)
3382 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003383 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003384
3385 // Update w_cline_height and w_cline_folded if the cursor line was
3386 // updated (saves a call to plines() later).
3387 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3388 {
3389 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003390 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003391#ifdef FEAT_FOLDING
3392 curwin->w_cline_folded = FALSE;
3393#endif
3394 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3395 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003396 break;
3397 }
3398
3399 // Show "extends" character from 'listchars' if beyond the line end and
3400 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003401 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003402 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003403 && wp->w_p_list
3404 && !wp->w_p_wrap
3405#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003406 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003407#endif
3408 && (
3409#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003410 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003411#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003412 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003413 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003414 || lcs_eol_one > 0
3415 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003416 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003417 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003418 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003419 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003420 mb_c = c;
3421 if (enc_utf8 && utf_char2len(c) > 1)
3422 {
3423 mb_utf8 = TRUE;
3424 u8cc[0] = 0;
3425 c = 0xc0;
3426 }
3427 else
3428 mb_utf8 = FALSE;
3429 }
3430
3431#ifdef FEAT_SYN_HL
3432 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003433 if (wlv.draw_color_col)
3434 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003435
3436 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3437 // highlight the cursor position itself.
3438 // Also highlight the 'colorcolumn' if it is different than
3439 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003440 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3441 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003442 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003443 if (((wlv.draw_state == WL_LINE
3444 || wlv.draw_state == WL_BRI
3445 || wlv.draw_state == WL_SBR)
3446 && !lnum_in_visual_area
3447 && search_attr == 0
3448 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003449# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003450 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003451# endif
3452 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003453 {
3454 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3455 && lnum != wp->w_cursor.lnum)
3456 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003457 vcol_save_attr = wlv.char_attr;
3458 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3459 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003460 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003461 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003462 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003463 vcol_save_attr = wlv.char_attr;
3464 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003465 }
3466 }
3467#endif
3468
3469 // Store character to be displayed.
3470 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003471 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003472 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003473 {
3474 // Store the character.
3475#if defined(FEAT_RIGHTLEFT)
3476 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3477 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003478 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003479 --wlv.off;
3480 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003481 }
3482#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003483 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003484 if (enc_dbcs == DBCS_JPNU)
3485 {
3486 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003487 ScreenLines[wlv.off] = 0x8e;
3488 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003489 }
3490 else if (enc_utf8)
3491 {
3492 if (mb_utf8)
3493 {
3494 int i;
3495
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003496 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003497 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003498 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003499 for (i = 0; i < Screen_mco; ++i)
3500 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003501 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003502 if (u8cc[i] == 0)
3503 break;
3504 }
3505 }
3506 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003507 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003508 }
3509 if (multi_attr)
3510 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003511 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003512 multi_attr = 0;
3513 }
3514 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003515 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003516
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 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3520 {
3521 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003522 ++wlv.off;
3523 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003524 if (enc_utf8)
3525 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003526 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003527 else
3528 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003529 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003530 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003531#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003532 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003533#endif
3534 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003535 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003536 // When "wlv.tocol" is halfway a character, set it to the end
3537 // of the character, otherwise highlighting won't stop.
3538 if (wlv.tocol == wlv.vcol)
3539 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003540
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003541 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003542
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003543#ifdef FEAT_RIGHTLEFT
3544 if (wp->w_p_rl)
3545 {
3546 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003547 --wlv.off;
3548 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003549 }
3550#endif
3551 }
3552#ifdef FEAT_RIGHTLEFT
3553 if (wp->w_p_rl)
3554 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003555 --wlv.off;
3556 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003557 }
3558 else
3559#endif
3560 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003561 ++wlv.off;
3562 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003563 }
3564 }
3565#ifdef FEAT_CONCEAL
3566 else if (wp->w_p_cole > 0 && is_concealing)
3567 {
3568 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003569 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003570 if (wlv.n_extra > 0)
3571 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003572 if (wp->w_p_wrap)
3573 {
3574 // Special voodoo required if 'wrap' is on.
3575 //
3576 // Advance the column indicator to force the line
3577 // drawing to wrap early. This will make the line
3578 // take up the same screen space when parts are concealed,
3579 // so that cursor line computations aren't messed up.
3580 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003581 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003582 // trailing junk to be written out of the screen line
3583 // we are building, 'boguscols' keeps track of the number
3584 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003585 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003586 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003587 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003588# ifdef FEAT_RIGHTLEFT
3589 if (wp->w_p_rl)
3590 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003591 wlv.col -= wlv.n_extra;
3592 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003593 }
3594 else
3595# endif
3596 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003597 wlv.col += wlv.n_extra;
3598 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003599 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003600 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003601 n_attr = 0;
3602 }
3603
3604
3605 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3606 {
3607 // Need to fill two screen columns.
3608# ifdef FEAT_RIGHTLEFT
3609 if (wp->w_p_rl)
3610 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003611 --wlv.boguscols;
3612 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003613 }
3614 else
3615# endif
3616 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003617 ++wlv.boguscols;
3618 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003619 }
3620 }
3621
3622# ifdef FEAT_RIGHTLEFT
3623 if (wp->w_p_rl)
3624 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003625 --wlv.boguscols;
3626 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003627 }
3628 else
3629# endif
3630 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003631 ++wlv.boguscols;
3632 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003633 }
3634 }
3635 else
3636 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003637 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003638 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003639 wlv.vcol += wlv.n_extra;
3640 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003641 n_attr = 0;
3642 }
3643 }
3644
3645 }
3646#endif // FEAT_CONCEAL
3647 else
3648 --n_skip;
3649
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003650 // Only advance the "wlv.vcol" when after the 'number' or
3651 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003652 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003653#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003654 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003655#endif
3656 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003657 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003658
3659#ifdef FEAT_SYN_HL
3660 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003661 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003662#endif
3663
3664 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003665 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3666 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003667
3668 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003669 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003670 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003671 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003672 if (n_attr_skip > 0)
3673 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003674
3675 // At end of screen line and there is more to come: Display the line
3676 // so far. If there is no more to display it is caught above.
3677 if ((
3678#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003679 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003680#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003681 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003682 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003683 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003684#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003685 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003686#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003687#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003688 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003689#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003690 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003691 && wlv.p_extra != at_end_str)
3692 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3693 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003694 )
3695 {
3696#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003697 wlv.col += wlv.boguscols;
3698 wlv_screen_line(wp, &wlv, FALSE);
3699 wlv.col -= wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003700 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003701#else
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003702 screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003703#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003704 ++wlv.row;
3705 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003706
3707 // When not wrapping and finished diff lines, or when displayed
3708 // '$' and highlighting until last column, break here.
3709 if ((!wp->w_p_wrap
3710#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003711 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003712#endif
3713#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003714 && !text_prop_above && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003715#endif
3716 ) || lcs_eol_one == -1)
3717 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003718#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003719 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003720 {
3721 // do not output more of the line, only the "below" prop
3722 ptr += STRLEN(ptr);
3723# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003724 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003725# endif
3726 }
3727#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003728
3729 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003730 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003731#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003732 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003733#endif
3734 )
3735 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003736 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3737 draw_vsep_win(wp, wlv.row);
3738 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003739 }
3740
3741 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003742 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003743 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003744 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003745 break;
3746 }
3747
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003748 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003749#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003750 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003751#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003752#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003753 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003754#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003755 && wp->w_width == Columns)
3756 {
3757 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003758 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003759
3760 // Special trick to make copy/paste of wrapped lines work with
3761 // xterm/screen: write an extra character beyond the end of
3762 // the line. This will work with all terminal types
3763 // (regardless of the xn,am settings).
3764 // Only do this on a fast tty.
3765 // Only do this if the cursor is on the current line
3766 // (something has been written in it).
3767 // Don't do this for the GUI.
3768 // Don't do this for double-width characters.
3769 // Don't do this for a window not at the right screen border.
3770 if (p_tf
3771#ifdef FEAT_GUI
3772 && !gui.in_use
3773#endif
3774 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003775 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3776 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003777 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003778 || (*mb_off2cells)(
3779 LineOffset[wlv.screen_row - 1]
3780 + (int)Columns - 2,
3781 LineOffset[wlv.screen_row]
3782 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003783 {
3784 // First make sure we are at the end of the screen line,
3785 // then output the same character again to let the
3786 // terminal know about the wrap. If the terminal doesn't
3787 // auto-wrap, we overwrite the character.
3788 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003789 screen_char(LineOffset[wlv.screen_row - 1]
3790 + (unsigned)Columns - 1,
3791 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003792
3793 // When there is a multi-byte character, just output a
3794 // space to keep it simple.
3795 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003796 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003797 out_char(' ');
3798 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003799 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003800 + (Columns - 1)]);
3801 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003802 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003803 screen_start(); // don't know where cursor is now
3804 }
3805 }
3806
Bram Moolenaar1306b362022-08-06 15:59:06 +01003807 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003808
Bram Moolenaareed9d462021-02-15 20:38:25 +01003809 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003810#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003811 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003812# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003813 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003814# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003815 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003816 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003817#endif
3818#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003819 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003820 // When the filler lines are actually below the last line of the
3821 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003822 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003823 break;
3824#endif
3825 }
3826
3827 } // for every character in the line
3828
3829#ifdef FEAT_SPELL
3830 // After an empty line check first word for capital.
3831 if (*skipwhite(line) == NUL)
3832 {
3833 capcol_lnum = lnum + 1;
3834 cap_col = 0;
3835 }
3836#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003837#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003838 vim_free(text_props);
3839 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003840 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003841#endif
3842
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003843 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003844 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003845}