blob: d36eee7f59512e5c6f1dd524a4e06916c52244e6 [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)
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100350 && ((wlv->row == wlv->startrow + wlv->filler_lines
351 && (wp->w_skipcol == 0 || wlv->row > wp->w_winrow))
352 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100353 {
354#ifdef FEAT_SIGNS
355 // If 'signcolumn' is set to 'number' and a sign is present
356 // in 'lnum', then display the sign instead of the line
357 // number.
358 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
359 get_sign_display_info(TRUE, wp, wlv);
360 else
361#endif
362 {
363 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100364 // When there are text properties above the line put the line number
365 // below them.
366 if (wlv->row == wlv->startrow + wlv->filler_lines
367#ifdef FEAT_PROP_POPUP
368 + wlv->text_prop_above_count
Bram Moolenaard7657e92022-09-20 18:59:30 +0100369#endif
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100370 )
371 {
372 long num;
373 char *fmt = "%*ld ";
374
375 if (wp->w_p_nu && !wp->w_p_rnu)
376 // 'number' + 'norelativenumber'
377 num = (long)wlv->lnum;
378 else
379 {
380 // 'relativenumber', don't use negative numbers
381 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
382 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
383 {
384 // 'number' + 'relativenumber'
385 num = wlv->lnum;
386 fmt = "%-*ld ";
387 }
388 }
389
390 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100391 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100392 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
393 ++wlv->p_extra)
394 *wlv->p_extra = '-';
395#ifdef FEAT_RIGHTLEFT
396 if (wp->w_p_rl) // reverse line numbers
397 {
398 char_u *p1, *p2;
399 int t;
400
401 // like rl_mirror(), but keep the space at the end
402 p2 = skipwhite(wlv->extra);
403 p2 = skiptowhite(p2) - 1;
404 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
405 {
406 t = *p1;
407 *p1 = *p2;
408 *p2 = t;
409 }
410 }
411#endif
412 wlv->p_extra = wlv->extra;
413 wlv->c_extra = NUL;
414 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100415 }
416 else
417 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100418 wlv->c_extra = ' ';
419 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100420 }
421 wlv->n_extra = number_width(wp) + 1;
422 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
423#ifdef FEAT_SYN_HL
424 // When 'cursorline' is set highlight the line number of
425 // the current line differently.
426 // When 'cursorlineopt' does not have "line" only
427 // highlight the line number itself.
428 // TODO: Can we use CursorLine instead of CursorLineNr
429 // when CursorLineNr isn't set?
430 if (wp->w_p_cul
431 && wlv->lnum == wp->w_cursor.lnum
432 && (wp->w_p_culopt_flags & CULOPT_NBR)
433 && (wlv->row == wlv->startrow + wlv->filler_lines
434 || (wlv->row > wlv->startrow + wlv->filler_lines
435 && (wp->w_p_culopt_flags & CULOPT_LINE))))
436 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
437#endif
438 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
439 && HL_ATTR(HLF_LNA) != 0)
440 // Use LineNrAbove
441 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
442 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
443 && HL_ATTR(HLF_LNB) != 0)
444 // Use LineNrBelow
445 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
446 }
447#ifdef FEAT_SIGNS
448 if (num_attr)
449 wlv->char_attr = num_attr;
450#endif
451 }
452}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100453
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100454#ifdef FEAT_LINEBREAK
455 static void
456handle_breakindent(win_T *wp, winlinevars_T *wlv)
457{
458 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
459 && *get_showbreak_value(wp) != NUL)
460 // draw indent after showbreak value
461 wlv->draw_state = WL_BRI;
462 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
463 // After the showbreak, draw the breakindent
464 wlv->draw_state = WL_BRI - 1;
465
466 // draw 'breakindent': indent wrapped text accordingly
467 if (wlv->draw_state == WL_BRI - 1)
468 {
469 wlv->draw_state = WL_BRI;
470 // if wlv->need_showbreak is set, breakindent also applies
471 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
472# ifdef FEAT_DIFF
473 && wlv->filler_lines == 0
474# endif
475# ifdef FEAT_PROP_POPUP
476 && !wlv->dont_use_showbreak
477# endif
478 )
479 {
480 wlv->char_attr = 0;
481# ifdef FEAT_DIFF
482 if (wlv->diff_hlf != (hlf_T)0)
483 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
484# endif
485 wlv->p_extra = NULL;
486 wlv->c_extra = ' ';
487 wlv->c_final = NUL;
488 wlv->n_extra = get_breakindent_win(wp,
489 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
490 if (wlv->row == wlv->startrow)
491 {
492 wlv->n_extra -= win_col_off2(wp);
493 if (wlv->n_extra < 0)
494 wlv->n_extra = 0;
495 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100496 if (wp->w_skipcol > 0 && wlv->startrow == 0
497 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100498 wlv->need_showbreak = FALSE;
499 // Correct end of highlighted area for 'breakindent',
500 // required when 'linebreak' is also set.
501 if (wlv->tocol == wlv->vcol)
502 wlv->tocol += wlv->n_extra;
503 }
504 }
505}
506#endif
507
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100508#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
509 static void
510handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
511{
512# ifdef FEAT_DIFF
513 if (wlv->filler_todo > 0)
514 {
515 // Draw "deleted" diff line(s).
516 if (char2cells(wp->w_fill_chars.diff) > 1)
517 {
518 wlv->c_extra = '-';
519 wlv->c_final = NUL;
520 }
521 else
522 {
523 wlv->c_extra = wp->w_fill_chars.diff;
524 wlv->c_final = NUL;
525 }
526# ifdef FEAT_RIGHTLEFT
527 if (wp->w_p_rl)
528 wlv->n_extra = wlv->col + 1;
529 else
530# endif
531 wlv->n_extra = wp->w_width - wlv->col;
532 wlv->char_attr = HL_ATTR(HLF_DED);
533 }
534# endif
535
536# ifdef FEAT_LINEBREAK
537 char_u *sbr = get_showbreak_value(wp);
538 if (*sbr != NUL && wlv->need_showbreak)
539 {
540 // Draw 'showbreak' at the start of each broken line.
541 wlv->p_extra = sbr;
542 wlv->c_extra = NUL;
543 wlv->c_final = NUL;
544 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100545 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100546 wlv->need_showbreak = FALSE;
547 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
548 // Correct end of highlighted area for 'showbreak',
549 // required when 'linebreak' is also set.
550 if (wlv->tocol == wlv->vcol)
551 wlv->tocol += wlv->n_extra;
552 // combine 'showbreak' with 'wincolor'
553 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
554# ifdef FEAT_SYN_HL
555 // combine 'showbreak' with 'cursorline'
556 if (wlv->cul_attr != 0)
557 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
558# endif
559 }
560# endif
561}
562#endif
563
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100564#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100565/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100566 * Return the cell size of virtual text after truncation.
567 */
568 static int
569textprop_size_after_trunc(
570 win_T *wp,
571 int flags, // TP_FLAG_ALIGN_*
572 int added,
573 char_u *text,
574 int *n_used_ptr)
575{
576 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
577 ? wp->w_width : added;
578 int len = (int)STRLEN(text);
579 int strsize = 0;
580 int n_used;
581
582 // if the remaining size is to small wrap anyway and use the next line
583 if (space < PROP_TEXT_MIN_CELLS)
584 space += wp->w_width;
585 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
586 {
587 int clen = ptr2cells(text + n_used);
588
589 if (strsize + clen > space)
590 break;
591 strsize += clen;
592 }
593 *n_used_ptr = n_used;
594 return strsize;
595}
596
597/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100598 * Take care of padding, right-align and truncation of virtual text after a
599 * line.
600 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
601 * padding, right-align and truncation. Otherwise only the size is computed.
602 * When "n_attr" is NULL returns the number of screen cells used.
603 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100604 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100605 int
606text_prop_position(
607 win_T *wp,
608 textprop_T *tp,
609 int vcol, // current screen column
610 int *n_extra, // nr of bytes for virtual text
611 char_u **p_extra, // virtual text
612 int *n_attr, // attribute cells, NULL if not used
613 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200614{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100615 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100616 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100617 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
618 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
619 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
620 ? tp->tp_len - 1 : 0;
621 int col_with_padding = vcol + (below ? 0 : padding);
622 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100623 int before = room; // spaces before the text
624 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100625 int n_used = *n_extra;
626 char_u *l = NULL;
627 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100628 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
629 tp->tp_flags, before, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200630
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100631 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100632 {
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100633 int col_off = win_col_off(wp) + win_col_off2(wp);
634 int skip_add = 0;
635
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100636 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100637 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100638 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100639 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100640 }
641 else
642 {
643 // Right-align: fill with before
644 if (right)
645 before -= cells;
646 if (before < 0
647 || !(right || below)
648 || (below
649 ? (col_with_padding == 0 || !wp->w_p_wrap)
650 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100651 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100652 if (right && (wrap || room < PROP_TEXT_MIN_CELLS))
653 {
654 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100655 before = wp->w_width - col_off - strsize + room;
656 if (before < 0)
657 before = 0;
658 else
659 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100660 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100661 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100662 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100663 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100664 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100665 else if (below && before > 0)
666 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100667 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100668 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100669
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100670 // With 'nowrap' add one to show the "extends" character if needed (it
671 // doesn't show if the text just fits).
672 if (!wp->w_p_wrap
673 && n_used < *n_extra
674 && wp->w_lcs_chars.ext != NUL
675 && wp->w_p_list)
676 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100677 if (!wp->w_p_wrap && below && padding > 0)
678 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100679
680 // add 1 for NUL, 2 for when '…' is used
681 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100682 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100683 if (n_attr == NULL || l != NULL)
684 {
685 int off = 0;
686
687 if (n_attr != NULL)
688 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100689 vim_memset(l, ' ', before);
690 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100691 if (padding > 0)
692 {
693 vim_memset(l + off, ' ', padding);
694 off += padding;
695 }
696 vim_strncpy(l + off, *p_extra, n_used);
697 off += n_used;
698 }
699 else
700 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100701 off = before + after + padding + n_used;
702 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100703 }
704 if (n_attr != NULL)
705 {
706 if (n_used < *n_extra && wp->w_p_wrap)
707 {
708 char_u *lp = l + off - 1;
709
710 if (has_mbyte)
711 {
712 // change last character to '…'
713 lp -= (*mb_head_off)(l, lp);
714 STRCPY(lp, "…");
715 n_used = lp - l + 3 - padding;
716 }
717 else
718 // change last character to '>'
719 *lp = '>';
720 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100721 else if (after > 0)
722 {
723 vim_memset(l + off, ' ', after);
724 l[off + after] = NUL;
725 }
726
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100727 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100728 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100729 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100730 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100731 *n_attr -= padding + after;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100732 *n_attr_skip = before + padding + skip_add;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100733 }
734 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100735 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100736
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100737 if (n_attr == NULL)
738 return cells;
739 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200740}
741#endif
742
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100743/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100744 * Call screen_line() using values from "wlv".
745 * Also takes care of putting "<<<" on the first line for 'smoothscroll'.
746 */
747 static void
748wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
749{
750 if (wlv->row == 0 && wp->w_skipcol > 0)
751 {
752 int off = (int)(current_ScreenLine - ScreenLines);
753
754 for (int i = 0; i < 3; ++i)
755 {
756 ScreenLines[off] = '<';
757 if (enc_utf8)
758 ScreenLinesUC[off] = 0;
759 ScreenAttrs[off] = HL_ATTR(HLF_AT);
760 ++off;
761 }
762 }
763
764 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
765 negative_width ? -wp->w_width : wp->w_width,
766 wlv->screen_line_flags);
767}
768
769/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100770 * Called when finished with the line: draw the screen line and handle any
771 * highlighting until the right of the window.
772 */
773 static void
774draw_screen_line(win_T *wp, winlinevars_T *wlv)
775{
776#ifdef FEAT_SYN_HL
777 long v;
778
779 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
780 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100781 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100782 else
783 v = wp->w_leftcol;
784
785 // check if line ends before left margin
786 if (wlv->vcol < v + wlv->col - win_col_off(wp))
787 wlv->vcol = v + wlv->col - win_col_off(wp);
788# ifdef FEAT_CONCEAL
789 // Get rid of the boguscols now, we want to draw until the right
790 // edge for 'cursorcolumn'.
791 wlv->col -= wlv->boguscols;
792 wlv->boguscols = 0;
793# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
794# else
795# define VCOL_HLC (wlv->vcol)
796# endif
797
798 if (wlv->draw_color_col)
799 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
800
801 if (((wp->w_p_cuc
802 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
803 && (int)wp->w_virtcol <
804 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
805 && wlv->lnum != wp->w_cursor.lnum)
806 || wlv->draw_color_col
807 || wlv->win_attr != 0)
808# ifdef FEAT_RIGHTLEFT
809 && !wp->w_p_rl
810# endif
811 )
812 {
813 int rightmost_vcol = 0;
814 int i;
815
816 if (wp->w_p_cuc)
817 rightmost_vcol = wp->w_virtcol;
818 if (wlv->draw_color_col)
819 // determine rightmost colorcolumn to possibly draw
820 for (i = 0; wlv->color_cols[i] >= 0; ++i)
821 if (rightmost_vcol < wlv->color_cols[i])
822 rightmost_vcol = wlv->color_cols[i];
823
824 while (wlv->col < wp->w_width)
825 {
826 ScreenLines[wlv->off] = ' ';
827 if (enc_utf8)
828 ScreenLinesUC[wlv->off] = 0;
829 ScreenCols[wlv->off] = MAXCOL;
830 ++wlv->col;
831 if (wlv->draw_color_col)
832 wlv->draw_color_col = advance_color_col(
833 VCOL_HLC, &wlv->color_cols);
834
835 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
836 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
837 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
838 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
839 else
840 ScreenAttrs[wlv->off++] = wlv->win_attr;
841
842 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
843 break;
844
845 ++wlv->vcol;
846 }
847 }
848#endif
849
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100850 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100851 ++wlv->row;
852 ++wlv->screen_row;
853}
854#undef VCOL_HLC
855
856/*
857 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100858 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100859 */
860 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100861win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100862{
863 wlv->col = 0;
864 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
865
866#ifdef FEAT_RIGHTLEFT
867 if (wp->w_p_rl)
868 {
869 // Rightleft window: process the text in the normal direction, but put
870 // it in current_ScreenLine[] from right to left. Start at the
871 // rightmost column of the window.
872 wlv->col = wp->w_width - 1;
873 wlv->off += wlv->col;
874 wlv->screen_line_flags |= SLF_RIGHTLEFT;
875 }
876#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100877 if (save_extra)
878 {
879 // reset the drawing state for the start of a wrapped line
880 wlv->draw_state = WL_START;
881 wlv->saved_n_extra = wlv->n_extra;
882 wlv->saved_p_extra = wlv->p_extra;
883 wlv->saved_c_extra = wlv->c_extra;
884 wlv->saved_c_final = wlv->c_final;
885#ifdef FEAT_SYN_HL
886 if (!(wlv->cul_screenline
887# ifdef FEAT_DIFF
888 && wlv->diff_hlf == (hlf_T)0
889# endif
890 ))
891 wlv->saved_char_attr = wlv->char_attr;
892 else
893#endif
894 wlv->saved_char_attr = 0;
895 wlv->n_extra = 0;
896 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100897}
898
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200899/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100900 * Called when wlv->draw_state is set to WL_LINE.
901 */
902 static void
903win_line_continue(winlinevars_T *wlv)
904{
905 if (wlv->saved_n_extra > 0)
906 {
907 // Continue item from end of wrapped line.
908 wlv->n_extra = wlv->saved_n_extra;
909 wlv->c_extra = wlv->saved_c_extra;
910 wlv->c_final = wlv->saved_c_final;
911 wlv->p_extra = wlv->saved_p_extra;
912 wlv->char_attr = wlv->saved_char_attr;
913 }
914 else
915 wlv->char_attr = wlv->win_attr;
916}
917
918/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200919 * Display line "lnum" of window 'wp' on the screen.
920 * Start at row "startrow", stop when "endrow" is reached.
921 * wp->w_virtcol needs to be valid.
922 *
923 * Return the number of last row the line occupies.
924 */
925 int
926win_line(
927 win_T *wp,
928 linenr_T lnum,
929 int startrow,
930 int endrow,
931 int nochange UNUSED, // not updating for changed text
932 int number_only) // only update the number column
933{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100934 winlinevars_T wlv; // variables passed between functions
935
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200936 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100937 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200938 char_u *line; // current line
939 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200940
Bram Moolenaar1306b362022-08-06 15:59:06 +0100941#ifdef FEAT_PROP_POPUP
942 char_u *p_extra_free2 = NULL; // another p_extra to be freed
943#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200944 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000945#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000946 int in_linebreak = FALSE; // n_extra set for showing linebreak
947#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200948 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100949 // displaying eol at end-of-line
950 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000951 int lcs_prec_todo = wp->w_lcs_chars.prec;
952 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200953
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100954 int n_attr = 0; // chars with special attr
955 int n_attr_skip = 0; // chars to skip before using extra_attr
956 int saved_attr2 = 0; // char_attr saved for n_attr
957 int n_attr3 = 0; // chars with overruling special attr
958 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200959
960 int n_skip = 0; // nr of chars to skip for 'nowrap'
961
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200962 int fromcol_prev = -2; // start of inverting after cursor
963 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200964 int lnum_in_visual_area = FALSE;
965 pos_T pos;
966 long v;
967
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200968 int attr_pri = FALSE; // char_attr has priority
969 int area_highlighting = FALSE; // Visual or incsearch highlighting
970 // in this line
971 int vi_attr = 0; // attributes for Visual and incsearch
972 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200973 int area_attr = 0; // attributes desired by highlighting
974 int search_attr = 0; // attributes desired by 'hlsearch'
975#ifdef FEAT_SYN_HL
976 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
977 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200978 int prev_syntax_col = -1; // column of prev_syntax_attr
979 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200980 int has_syntax = FALSE; // this buffer has syntax highl.
981 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200982#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100983#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200984 int text_prop_count;
985 int text_prop_next = 0; // next text property to use
986 textprop_T *text_props = NULL;
987 int *text_prop_idxs = NULL;
988 int text_props_active = 0;
989 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +0100990 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200991 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +0100992 int text_prop_attr_comb = 0; // text_prop_attr combined with
993 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100994 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100995 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +0100996 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100997 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +0100998 int saved_search_attr = 0; // search_attr to be used when n_extra
999 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001000 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001001#endif
1002#ifdef FEAT_SPELL
1003 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001004 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001005# define SPWORDLEN 150
1006 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1007 int nextlinecol = 0; // column where nextline[] starts
1008 int nextline_idx = 0; // index in nextline[] where next line
1009 // starts
1010 int spell_attr = 0; // attributes desired by spelling
1011 int word_end = 0; // last byte with same spell_attr
1012 static linenr_T checked_lnum = 0; // line number for "checked_col"
1013 static int checked_col = 0; // column in "checked_lnum" up to which
1014 // there are no spell errors
1015 static int cap_col = -1; // column to check for Cap word
1016 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1017 int cur_checked_col = 0; // checked column for current line
1018#endif
1019 int extra_check = 0; // has extra highlighting
1020 int multi_attr = 0; // attributes desired by multibyte
1021 int mb_l = 1; // multi-byte byte length
1022 int mb_c = 0; // decoded multi-byte character
1023 int mb_utf8 = FALSE; // screen char is UTF-8 char
1024 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001025#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001026 int change_start = MAXCOL; // first col of changed area
1027 int change_end = -1; // last col of changed area
1028#endif
1029 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001030 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001031 int in_multispace = FALSE; // in multiple consecutive spaces
1032 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001033#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
1034 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
1035# define LINE_ATTR
1036 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +01001037 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001038#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001039 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001040 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001041#ifdef FEAT_ARABIC
1042 int prev_c = 0; // previous Arabic character
1043 int prev_c1 = 0; // first composing char for prev_c
1044#endif
1045#if defined(LINE_ATTR)
1046 int did_line_attr = 0;
1047#endif
1048#ifdef FEAT_TERMINAL
1049 int get_term_attr = FALSE;
1050#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001051
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001052#ifdef FEAT_SYN_HL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001053 // margin columns for the screen line, needed for when 'cursorlineopt'
1054 // contains "screenline"
1055 int left_curline_col = 0;
1056 int right_curline_col = 0;
1057#endif
1058
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001059#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1060 int feedback_col = 0;
1061 int feedback_old_attr = -1;
1062#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001063
1064#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1065 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001066 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001067#endif
1068#ifdef FEAT_CONCEAL
1069 int syntax_flags = 0;
1070 int syntax_seqnr = 0;
1071 int prev_syntax_id = 0;
1072 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1073 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001074 int did_wcol = FALSE;
1075 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001076# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001077# define FIX_FOR_BOGUSCOLS \
1078 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001079 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001080 wlv.vcol -= wlv.vcol_off; \
1081 wlv.vcol_off = 0; \
1082 wlv.col -= wlv.boguscols; \
1083 old_boguscols = wlv.boguscols; \
1084 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001085 }
1086#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001087# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001088#endif
1089
1090 if (startrow > endrow) // past the end already!
1091 return startrow;
1092
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001093 CLEAR_FIELD(wlv);
1094
1095 wlv.lnum = lnum;
1096 wlv.startrow = startrow;
1097 wlv.row = startrow;
1098 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001099 wlv.fromcol = -10;
1100 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001101#ifdef FEAT_LINEBREAK
1102 wlv.vcol_sbr = -1;
1103#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001104
1105 if (!number_only)
1106 {
1107 // To speed up the loop below, set extra_check when there is linebreak,
1108 // trailing white space and/or syntax processing to be done.
1109#ifdef FEAT_LINEBREAK
1110 extra_check = wp->w_p_lbr;
1111#endif
1112#ifdef FEAT_SYN_HL
1113 if (syntax_present(wp) && !wp->w_s->b_syn_error
1114# ifdef SYN_TIME_LIMIT
1115 && !wp->w_s->b_syn_slow
1116# endif
1117 )
1118 {
1119 // Prepare for syntax highlighting in this line. When there is an
1120 // error, stop syntax highlighting.
1121 save_did_emsg = did_emsg;
1122 did_emsg = FALSE;
1123 syntax_start(wp, lnum);
1124 if (did_emsg)
1125 wp->w_s->b_syn_error = TRUE;
1126 else
1127 {
1128 did_emsg = save_did_emsg;
1129#ifdef SYN_TIME_LIMIT
1130 if (!wp->w_s->b_syn_slow)
1131#endif
1132 {
1133 has_syntax = TRUE;
1134 extra_check = TRUE;
1135 }
1136 }
1137 }
1138
1139 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001140 wlv.color_cols = wp->w_p_cc_cols;
1141 if (wlv.color_cols != NULL)
1142 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001143#endif
1144
1145#ifdef FEAT_TERMINAL
1146 if (term_show_buffer(wp->w_buffer))
1147 {
1148 extra_check = TRUE;
1149 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001150 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001151 }
1152#endif
1153
1154#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001155 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001156 {
1157 // Prepare for spell checking.
1158 has_spell = TRUE;
1159 extra_check = TRUE;
1160
1161 // Get the start of the next line, so that words that wrap to the
1162 // next line are found too: "et<line-break>al.".
1163 // Trick: skip a few chars for C/shell/Vim comments
1164 nextline[SPWORDLEN] = NUL;
1165 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1166 {
1167 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1168 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1169 }
1170
1171 // When a word wrapped from the previous line the start of the
1172 // current line is valid.
1173 if (lnum == checked_lnum)
1174 cur_checked_col = checked_col;
1175 checked_lnum = 0;
1176
1177 // When there was a sentence end in the previous line may require a
1178 // word starting with capital in this line. In line 1 always check
1179 // the first word.
1180 if (lnum != capcol_lnum)
1181 cap_col = -1;
1182 if (lnum == 1)
1183 cap_col = 0;
1184 capcol_lnum = 0;
1185 }
1186#endif
1187
1188 // handle Visual active in this window
1189 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1190 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001191 pos_T *top, *bot;
1192
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001193 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1194 {
1195 // Visual is after curwin->w_cursor
1196 top = &curwin->w_cursor;
1197 bot = &VIsual;
1198 }
1199 else
1200 {
1201 // Visual is before curwin->w_cursor
1202 top = &VIsual;
1203 bot = &curwin->w_cursor;
1204 }
1205 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1206 if (VIsual_mode == Ctrl_V)
1207 {
1208 // block mode
1209 if (lnum_in_visual_area)
1210 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001211 wlv.fromcol = wp->w_old_cursor_fcol;
1212 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001213 }
1214 }
1215 else
1216 {
1217 // non-block mode
1218 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001219 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001220 else if (lnum == top->lnum)
1221 {
1222 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001223 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001224 else
1225 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001226 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001227 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001228 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001229 }
1230 }
1231 if (VIsual_mode != 'V' && lnum == bot->lnum)
1232 {
1233 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1234 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001235 wlv.fromcol = -10;
1236 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001237 }
1238 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001239 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001240 else
1241 {
1242 pos = *bot;
1243 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001244 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1245 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001246 else
1247 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001248 getvvcol(wp, &pos, NULL, NULL,
1249 (colnr_T *)&wlv.tocol);
1250 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001251 }
1252 }
1253 }
1254 }
1255
1256 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001257 if (!highlight_match && lnum == curwin->w_cursor.lnum
1258 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001259#ifdef FEAT_GUI
1260 && !gui.in_use
1261#endif
1262 )
1263 noinvcur = TRUE;
1264
1265 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001266 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001267 {
1268 area_highlighting = TRUE;
1269 vi_attr = HL_ATTR(HLF_V);
1270#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1271 if ((clip_star.available && !clip_star.owned
1272 && clip_isautosel_star())
1273 || (clip_plus.available && !clip_plus.owned
1274 && clip_isautosel_plus()))
1275 vi_attr = HL_ATTR(HLF_VNC);
1276#endif
1277 }
1278 }
1279
1280 // handle 'incsearch' and ":s///c" highlighting
1281 else if (highlight_match
1282 && wp == curwin
1283 && lnum >= curwin->w_cursor.lnum
1284 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1285 {
1286 if (lnum == curwin->w_cursor.lnum)
1287 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001288 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001289 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001290 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001291 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1292 {
1293 pos.lnum = lnum;
1294 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001295 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001296 }
1297 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001298 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001299 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001300 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1301 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001302 area_highlighting = TRUE;
1303 vi_attr = HL_ATTR(HLF_I);
1304 }
1305 }
1306
1307#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001308 wlv.filler_lines = diff_check(wp, lnum);
1309 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001310 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001311 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001312 {
1313 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001314 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001315 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001316 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001317 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001318 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001319 }
1320 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001321 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001322 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001323 area_highlighting = TRUE;
1324 }
1325 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001326 wlv.filler_lines = wp->w_topfill;
1327 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001328#endif
1329
1330#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001331 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001332 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001333 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001334#endif
1335
1336#ifdef LINE_ATTR
1337# ifdef FEAT_SIGNS
1338 // If this line has a sign with line highlighting set line_attr.
1339 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001340 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001341# endif
1342# if defined(FEAT_QUICKFIX)
1343 // Highlight the current line in the quickfix window.
1344 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1345 line_attr = HL_ATTR(HLF_QFL);
1346# endif
1347 if (line_attr != 0)
1348 area_highlighting = TRUE;
1349#endif
1350
1351 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1352 ptr = line;
1353
1354#ifdef FEAT_SPELL
1355 if (has_spell && !number_only)
1356 {
1357 // For checking first word with a capital skip white space.
1358 if (cap_col == 0)
1359 cap_col = getwhitecols(line);
1360
1361 // To be able to spell-check over line boundaries copy the end of the
1362 // current line into nextline[]. Above the start of the next line was
1363 // copied to nextline[SPWORDLEN].
1364 if (nextline[SPWORDLEN] == NUL)
1365 {
1366 // No next line or it is empty.
1367 nextlinecol = MAXCOL;
1368 nextline_idx = 0;
1369 }
1370 else
1371 {
1372 v = (long)STRLEN(line);
1373 if (v < SPWORDLEN)
1374 {
1375 // Short line, use it completely and append the start of the
1376 // next line.
1377 nextlinecol = 0;
1378 mch_memmove(nextline, line, (size_t)v);
1379 STRMOVE(nextline + v, nextline + SPWORDLEN);
1380 nextline_idx = v + 1;
1381 }
1382 else
1383 {
1384 // Long line, use only the last SPWORDLEN bytes.
1385 nextlinecol = v - SPWORDLEN;
1386 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1387 nextline_idx = SPWORDLEN + 1;
1388 }
1389 }
1390 }
1391#endif
1392
1393 if (wp->w_p_list)
1394 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001395 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001396 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001397 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001398 || wp->w_lcs_chars.trail
1399 || wp->w_lcs_chars.lead
1400 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001401 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001402
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001403 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001404 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001405 {
1406 trailcol = (colnr_T)STRLEN(ptr);
1407 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1408 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001409 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001410 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001411 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001412 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001413 {
1414 leadcol = 0;
1415 while (VIM_ISWHITE(ptr[leadcol]))
1416 ++leadcol;
1417 if (ptr[leadcol] == NUL)
1418 // in a line full of spaces all of them are treated as trailing
1419 leadcol = (colnr_T)0;
1420 else
1421 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001422 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001423 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001424 }
1425
Bram Moolenaard7657e92022-09-20 18:59:30 +01001426 wlv.wcr_attr = get_wcr_attr(wp);
1427 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001428 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001429 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001430 area_highlighting = TRUE;
1431 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001432
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001433#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001434 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001435 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001436#endif
1437
1438 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1439 // first character to be displayed.
1440 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001441 v = startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001442 else
1443 v = wp->w_leftcol;
1444 if (v > 0 && !number_only)
1445 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001446 char_u *prev_ptr = ptr;
1447 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001448 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001449
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001450 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001451 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001452 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001453 charsize = win_lbr_chartabsize(&cts, NULL);
1454 cts.cts_vcol += charsize;
1455 prev_ptr = cts.cts_ptr;
1456 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001457 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001458 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001459 ptr = cts.cts_ptr;
1460 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001461
1462 // When:
1463 // - 'cuc' is set, or
1464 // - 'colorcolumn' is set, or
1465 // - 'virtualedit' is set, or
1466 // - the visual mode is active,
1467 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001468 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001469#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001470 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001471#endif
1472 virtual_active() ||
1473 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001474 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001475
1476 // Handle a character that's not completely on the screen: Put ptr at
1477 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001478 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001479 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001480 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001481 ptr = prev_ptr;
1482 // If the character fits on the screen, don't need to skip it.
1483 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001484 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1485 && wlv.col == 0)
1486 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001487 }
1488
1489 // Adjust for when the inverted text is before the screen,
1490 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001491 if (wlv.tocol <= wlv.vcol)
1492 wlv.fromcol = 0;
1493 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1494 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001495
1496#ifdef FEAT_LINEBREAK
1497 // When w_skipcol is non-zero, first line needs 'showbreak'
1498 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001499 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001500#endif
1501#ifdef FEAT_SPELL
1502 // When spell checking a word we need to figure out the start of the
1503 // word and if it's badly spelled or not.
1504 if (has_spell)
1505 {
1506 int len;
1507 colnr_T linecol = (colnr_T)(ptr - line);
1508 hlf_T spell_hlf = HLF_COUNT;
1509
1510 pos = wp->w_cursor;
1511 wp->w_cursor.lnum = lnum;
1512 wp->w_cursor.col = linecol;
1513 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1514
1515 // spell_move_to() may call ml_get() and make "line" invalid
1516 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1517 ptr = line + linecol;
1518
1519 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1520 {
1521 // no bad word found at line start, don't check until end of a
1522 // word
1523 spell_hlf = HLF_COUNT;
1524 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1525 }
1526 else
1527 {
1528 // bad word found, use attributes until end of word
1529 word_end = wp->w_cursor.col + len + 1;
1530
1531 // Turn index into actual attributes.
1532 if (spell_hlf != HLF_COUNT)
1533 spell_attr = highlight_attr[spell_hlf];
1534 }
1535 wp->w_cursor = pos;
1536
1537# ifdef FEAT_SYN_HL
1538 // Need to restart syntax highlighting for this line.
1539 if (has_syntax)
1540 syntax_start(wp, lnum);
1541# endif
1542 }
1543#endif
1544 }
1545
1546 // Correct highlighting for cursor that can't be disabled.
1547 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001548 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001549 {
1550 if (noinvcur)
1551 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001552 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001553 {
1554 // highlighting starts at cursor, let it start just after the
1555 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001556 fromcol_prev = wlv.fromcol;
1557 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001558 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001559 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001560 // restart highlighting after the cursor
1561 fromcol_prev = wp->w_virtcol;
1562 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001563 if (wlv.fromcol >= wlv.tocol)
1564 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001565 }
1566
1567#ifdef FEAT_SEARCH_EXTRA
1568 if (!number_only)
1569 {
1570 v = (long)(ptr - line);
1571 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1572 &line, &screen_search_hl,
1573 &search_attr);
1574 ptr = line + v; // "line" may have been updated
1575 }
1576#endif
1577
1578#ifdef FEAT_SYN_HL
1579 // Cursor line highlighting for 'cursorline' in the current window.
1580 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1581 {
1582 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001583 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001584 if (!(wp == curwin && VIsual_active)
1585 && wp->w_p_culopt_flags != CULOPT_NBR)
1586 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001587 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001588 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1589
1590 // Only set line_attr here when "screenline" is not present in
1591 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001592 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001593 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001594 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001595# ifdef FEAT_SIGNS
1596 // Combine the 'cursorline' and sign highlighting, depending on
1597 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001598 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001599 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001600 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001601 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001602 else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001603 line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001604 }
1605 else
1606# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001607# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001608 // let the line attribute overrule 'cursorline', otherwise
1609 // it disappears when both have background set;
1610 // 'cursorline' can use underline or bold to make it show
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001611 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001612# else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001613 line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001614# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001615 }
1616 else
1617 {
1618 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001619 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1620 }
1621 area_highlighting = TRUE;
1622 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001623 }
1624#endif
1625
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001626#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001627 {
1628 char_u *prop_start;
1629
1630 text_prop_count = get_text_props(wp->w_buffer, lnum,
1631 &prop_start, FALSE);
1632 if (text_prop_count > 0)
1633 {
1634 // Make a copy of the properties, so that they are properly
1635 // aligned.
1636 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1637 if (text_props != NULL)
1638 mch_memmove(text_props, prop_start,
1639 text_prop_count * sizeof(textprop_T));
1640
1641 // Allocate an array for the indexes.
1642 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001643 if (text_prop_idxs == NULL)
1644 VIM_CLEAR(text_props);
1645
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001646 if (text_props != NULL)
1647 {
1648 area_highlighting = TRUE;
1649 extra_check = TRUE;
1650 for (int i = 0; i < text_prop_count; ++i)
1651 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1652 ++wlv.text_prop_above_count;
1653 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001654 }
1655 }
1656#endif
1657
Bram Moolenaar1306b362022-08-06 15:59:06 +01001658 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001659
1660 // Repeat for the whole displayed line.
1661 for (;;)
1662 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001663 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001664#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001665 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001666#endif
1667#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001668 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001669#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001670
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001671 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001672 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001673 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001674#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001675 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001676 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001677 wlv.cul_attr = 0;
zeertzjq4f33bc22021-08-05 17:57:02 +02001678 line_attr = line_attr_save;
1679 }
1680#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001681#ifdef FEAT_CMDWIN
Bram Moolenaar1306b362022-08-06 15:59:06 +01001682 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001683 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001684 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001685 if (cmdwin_type != 0 && wp == curwin)
1686 {
1687 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001688 wlv.n_extra = 1;
1689 wlv.c_extra = cmdwin_type;
1690 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001691 wlv.char_attr =
1692 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001693 }
1694 }
1695#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001696#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001697 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001698 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001699 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001700 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001701 }
1702#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001703#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001704 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001705 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001706 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001707 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001708 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001709 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001710 }
1711#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001712 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001713 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001714 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001715 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001716 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001717 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001718#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001719 // Check if 'breakindent' applies and show it.
1720 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1721 if (wlv.n_extra == 0)
1722 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001723#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001724#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001725 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001726 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001727 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001728 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001729 }
1730#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001731 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001732 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001733 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001734 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001735 }
1736 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001737
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001738#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001739 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001740 && wlv.vcol >= left_curline_col
1741 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001742 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001743 wlv.cul_attr = HL_ATTR(HLF_CUL);
1744 line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001745 }
1746#endif
1747
1748 // When still displaying '$' of change command, stop at cursor.
1749 // When only displaying the (relative) line number and that's done,
1750 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001751 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001752 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001753 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001754#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001755 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001756#endif
1757 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001758 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001759 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001760 // Pretend we have finished updating the window. Except when
1761 // 'cursorcolumn' is set.
1762#ifdef FEAT_SYN_HL
1763 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001764 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001765 else
1766#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001767 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001768 break;
1769 }
1770
Bram Moolenaar1306b362022-08-06 15:59:06 +01001771 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001772 {
1773 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001774 if (wlv.vcol == wlv.fromcol
1775 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1776 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001777 && (*mb_ptr2cells)(ptr) > 1)
1778 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001779 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001780 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001781 area_attr = vi_attr; // start highlighting
1782 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001783 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001784 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001785 area_attr = 0; // stop highlighting
1786
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001787#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001788 if (text_props != NULL)
1789 {
1790 int pi;
1791 int bcol = (int)(ptr - line);
1792
Bram Moolenaar1306b362022-08-06 15:59:06 +01001793 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001794# ifdef FEAT_LINEBREAK
1795 && !in_linebreak
1796# endif
1797 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001798 --bcol; // still working on the previous char, e.g. Tab
1799
1800 // Check if any active property ends.
1801 for (pi = 0; pi < text_props_active; ++pi)
1802 {
1803 int tpi = text_prop_idxs[pi];
1804
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001805 if (text_props[tpi].tp_col != MAXCOL
1806 && bcol >= text_props[tpi].tp_col - 1
1807 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001808 {
1809 if (pi + 1 < text_props_active)
1810 mch_memmove(text_prop_idxs + pi,
1811 text_prop_idxs + pi + 1,
1812 sizeof(int)
1813 * (text_props_active - (pi + 1)));
1814 --text_props_active;
1815 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001816# ifdef FEAT_LINEBREAK
1817 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001818 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001819 syntax_attr = 0;
1820# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001821 }
1822 }
1823
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001824# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001825 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001826 // not on the next char yet, don't start another prop
1827 --bcol;
1828# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001829 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001830 // With 'nowrap' and not in the first screen line only "below"
1831 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001832 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001833 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001834 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001835 && (wp->w_p_wrap
1836 || wlv.row == startrow
1837 || (text_props[text_prop_next].tp_flags
1838 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001839 || (bcol == 0 &&
1840 (text_props[text_prop_next].tp_flags
1841 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001842 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001843 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001844 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001845 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1846 {
1847 // first display the '$' after the line
1848 text_prop_follows = TRUE;
1849 break;
1850 }
1851 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001852 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001853 + text_props[text_prop_next].tp_len)
1854 text_prop_idxs[text_props_active++] = text_prop_next;
1855 ++text_prop_next;
1856 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001857
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001858 if (wlv.n_extra == 0 || !extra_for_textprop)
1859 {
1860 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001861 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001862 text_prop_flags = 0;
1863 text_prop_type = NULL;
1864 text_prop_id = 0;
1865 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001866 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001867 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001868 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001869 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001870 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001871
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001872 // Sort the properties on priority and/or starting last.
1873 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001874 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001875 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001876 sort_text_props(wp->w_buffer, text_props,
1877 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001878
1879 for (pi = 0; pi < text_props_active; ++pi)
1880 {
1881 int tpi = text_prop_idxs[pi];
1882 proptype_T *pt = text_prop_type_by_id(
1883 wp->w_buffer, text_props[tpi].tp_type);
1884
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001885 if (pt != NULL && (pt->pt_hl_id > 0
1886 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001887 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001888 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001889 if (pt->pt_hl_id > 0)
1890 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001891 text_prop_type = pt;
1892 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001893 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001894 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001895 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001896 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001897 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001898 }
1899 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001900 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001901 && -text_prop_id
1902 <= wp->w_buffer->b_textprop_text.ga_len)
1903 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001904 textprop_T *tp = &text_props[used_tpi];
1905 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001906 ->b_textprop_text.ga_data)[
1907 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001908 int above = (tp->tp_flags
1909 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001910
1911 // reset the ID in the copy to avoid it being used
1912 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001913 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001914
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001915 if (p != NULL)
1916 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001917 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001918 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001919 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001920 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001921 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1922 int padding = tp->tp_col == MAXCOL
1923 && tp->tp_len > 1
1924 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001925
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001926 // Insert virtual text before the current
1927 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001928 wlv.p_extra = p;
1929 wlv.c_extra = NUL;
1930 wlv.c_final = NUL;
1931 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001932 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001933 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001934 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001935 // restore search_attr and area_attr when n_extra
1936 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001937 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001938 saved_area_attr = area_attr;
1939 search_attr = 0;
1940 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001941 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001942 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001943 if (*ptr == NUL)
1944 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001945 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001946#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001947 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001948 {
1949 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001950 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001951 wlv.need_showbreak = FALSE;
1952 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001953 }
1954#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001955 if ((right || above || below || !wrap
1956 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001957 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001958 char_u *prev_p_extra = wlv.p_extra;
1959 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001960
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001961 // Take care of padding, right-align and
1962 // truncation.
1963 // Shared with win_lbr_chartabsize(), must do
1964 // exactly the same.
1965 start_line = text_prop_position(wp, tp,
1966 wlv.col,
1967 &wlv.n_extra, &wlv.p_extra,
1968 &n_attr, &n_attr_skip);
1969 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001970 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001971 // wlv.p_extra was allocated
1972 vim_free(p_extra_free2);
1973 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001974 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001975
Bram Moolenaara4abe512022-09-15 19:44:09 +01001976 if (lcs_eol_one < 0 && wlv.col
1977 + wlv.n_extra - 2 > wp->w_width)
1978 // don't bail out at end of line
1979 lcs_eol_one = 0;
1980
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001981 // When 'wrap' is off then for "below" we need
1982 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001983 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001984 {
1985 draw_screen_line(wp, &wlv);
1986
1987 // When line got too long for screen break
1988 // here.
1989 if (wlv.row == endrow)
1990 {
1991 ++wlv.row;
1992 break;
1993 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001994 win_line_start(wp, &wlv, TRUE);
1995 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001996 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001997 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001998 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001999
2000 // If another text prop follows the condition below at
2001 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002002 // If this is an "above" text prop and 'nowrap' the we
2003 // must wrap anyway.
2004 text_prop_above = above;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002005 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002006 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002007 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002008 else if (text_prop_next < text_prop_count
2009 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002010 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2011 || (!wp->w_p_wrap
2012 && wlv.col == wp->w_width - 1
2013 && (text_props[text_prop_next].tp_flags
2014 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002015 // When at last-but-one character and a text property
2016 // follows after it, we may need to flush the line after
2017 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002018 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002019 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002020 }
2021#endif
2022
Bram Moolenaare38fc862022-08-11 17:24:50 +01002023#ifdef FEAT_SEARCH_EXTRA
2024 if (wlv.n_extra == 0)
2025 {
2026 // Check for start/end of 'hlsearch' and other matches.
2027 // After end, check for start/end of next match.
2028 // When another match, have to check for start again.
2029 v = (long)(ptr - line);
2030 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2031 &screen_search_hl, &has_match_conc,
2032 &match_conc, did_line_attr, lcs_eol_one,
2033 &on_last_col);
2034 ptr = line + v; // "line" may have been changed
2035 prev_ptr = ptr;
2036
2037 // Do not allow a conceal over EOL otherwise EOL will be missed
2038 // and bad things happen.
2039 if (*ptr == NUL)
2040 has_match_conc = 0;
2041 }
2042#endif
2043
2044#ifdef FEAT_DIFF
2045 if (wlv.diff_hlf != (hlf_T)0)
2046 {
2047 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2048 && wlv.n_extra == 0)
2049 wlv.diff_hlf = HLF_TXD; // changed text
2050 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2051 && wlv.n_extra == 0)
2052 wlv.diff_hlf = HLF_CHD; // changed line
2053 line_attr = HL_ATTR(wlv.diff_hlf);
2054 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2055 && wp->w_p_culopt_flags != CULOPT_NBR
2056 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2057 && wlv.vcol <= right_curline_col)))
2058 line_attr = hl_combine_attr(
2059 line_attr, HL_ATTR(HLF_CUL));
2060 }
2061#endif
2062
Bram Moolenaara74fda62019-10-19 17:38:03 +02002063#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002064 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002065 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002066 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002067# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002068 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002069 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002070# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002071 // Get syntax attribute.
2072 if (has_syntax)
2073 {
2074 // Get the syntax attribute for the character. If there
2075 // is an error, disable syntax highlighting.
2076 save_did_emsg = did_emsg;
2077 did_emsg = FALSE;
2078
2079 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002080 if (v == prev_syntax_col)
2081 // at same column again
2082 syntax_attr = prev_syntax_attr;
2083 else
2084 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002085# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002086 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002087# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002088 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002089# ifdef FEAT_SPELL
2090 has_spell ? &can_spell :
2091# endif
2092 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002093 prev_syntax_col = v;
2094 prev_syntax_attr = syntax_attr;
2095 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002096
Bram Moolenaar34390282019-10-16 14:38:26 +02002097 if (did_emsg)
2098 {
2099 wp->w_s->b_syn_error = TRUE;
2100 has_syntax = FALSE;
2101 syntax_attr = 0;
2102 }
2103 else
2104 did_emsg = save_did_emsg;
2105# ifdef SYN_TIME_LIMIT
2106 if (wp->w_s->b_syn_slow)
2107 has_syntax = FALSE;
2108# endif
2109
2110 // Need to get the line again, a multi-line regexp may
2111 // have made it invalid.
2112 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2113 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002114 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002115# ifdef FEAT_CONCEAL
2116 // no concealing past the end of the line, it interferes
2117 // with line highlighting
2118 if (*ptr == NUL)
2119 syntax_flags = 0;
2120 else
2121 syntax_flags = get_syntax_info(&syntax_seqnr);
2122# endif
2123 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002124 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002125# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002126 // Combine text property highlight into syntax highlight.
2127 if (text_prop_type != NULL)
2128 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002129 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002130 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2131 else
2132 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002133 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002134 }
2135# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002136#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002137
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002138 // Decide which of the highlight attributes to use.
2139 attr_pri = TRUE;
2140#ifdef LINE_ATTR
2141 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002142 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002143 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002144 if (!highlight_match)
2145 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002146 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002147# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002148 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002149# endif
2150 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002151 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002152 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002153 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002154# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002155 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002156# endif
2157 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002158 else if (line_attr != 0
2159 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2160 || wlv.vcol < wlv.fromcol
2161 || vcol_prev < fromcol_prev
2162 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002163 {
2164 // Use line_attr when not in the Visual or 'incsearch' area
2165 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002166# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002167 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002168# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002169 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002170# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002171 attr_pri = FALSE;
2172 }
2173#else
2174 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002175 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002176 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002177 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002178#endif
2179 else
2180 {
2181 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002182#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002183 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002184#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002185 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002186#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002187 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002188#ifdef FEAT_PROP_POPUP
2189 // override with text property highlight when "override" is TRUE
2190 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002191 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002192#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002193 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002194
2195 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002196 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002197 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002198 if (wlv.char_attr == 0)
2199 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002200 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002201 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002202 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002203
2204 // Get the next character to put on the screen.
2205
2206 // The "p_extra" points to the extra stuff that is inserted to
2207 // represent special characters (non-printable stuff) and other
2208 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002209 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002210 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2211 // "p_extra[n_extra]".
2212 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002213 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002214 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002215 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002216 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002217 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2218 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002219 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2220 if (enc_utf8 && utf_char2len(c) > 1)
2221 {
2222 mb_utf8 = TRUE;
2223 u8cc[0] = 0;
2224 c = 0xc0;
2225 }
2226 else
2227 mb_utf8 = FALSE;
2228 }
2229 else
2230 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002231 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002232 if (has_mbyte)
2233 {
2234 mb_c = c;
2235 if (enc_utf8)
2236 {
2237 // If the UTF-8 character is more than one byte:
2238 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002239 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002240 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002241 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002242 mb_l = 1;
2243 else if (mb_l > 1)
2244 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002245 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002246 mb_utf8 = TRUE;
2247 c = 0xc0;
2248 }
2249 }
2250 else
2251 {
2252 // if this is a DBCS character, put it in "mb_c"
2253 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002254 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002255 mb_l = 1;
2256 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002257 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002258 }
2259 if (mb_l == 0) // at the NUL at end-of-line
2260 mb_l = 1;
2261
2262 // If a double-width char doesn't fit display a '>' in the
2263 // last column.
2264 if ((
2265# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002266 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002267# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002268 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002269 && (*mb_char2cells)(mb_c) == 2)
2270 {
2271 c = '>';
2272 mb_c = c;
2273 mb_l = 1;
2274 mb_utf8 = FALSE;
2275 multi_attr = HL_ATTR(HLF_AT);
2276#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002277 if (wlv.cul_attr)
2278 multi_attr = hl_combine_attr(
2279 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002280#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002281 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002282
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002283 // put the pointer back to output the double-width
2284 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002285 ++wlv.n_extra;
2286 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002287 }
2288 else
2289 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002290 wlv.n_extra -= mb_l - 1;
2291 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002292 }
2293 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002294 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002295 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002296 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002297#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002298 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002299 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002300 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002301 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002302 if (search_attr == 0)
2303 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002304 if (area_attr == 0 && *ptr != NUL)
2305 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002306 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002307#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002308 }
2309 else
2310 {
2311#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002312 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002313#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002314 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002315
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002316 // Get a character from the line itself.
2317 c = *ptr;
2318#ifdef FEAT_LINEBREAK
2319 c0 = *ptr;
2320#endif
2321 if (has_mbyte)
2322 {
2323 mb_c = c;
2324 if (enc_utf8)
2325 {
2326 // If the UTF-8 character is more than one byte: Decode it
2327 // into "mb_c".
2328 mb_l = utfc_ptr2len(ptr);
2329 mb_utf8 = FALSE;
2330 if (mb_l > 1)
2331 {
2332 mb_c = utfc_ptr2char(ptr, u8cc);
2333 // Overlong encoded ASCII or ASCII with composing char
2334 // is displayed normally, except a NUL.
2335 if (mb_c < 0x80)
2336 {
2337 c = mb_c;
2338#ifdef FEAT_LINEBREAK
2339 c0 = mb_c;
2340#endif
2341 }
2342 mb_utf8 = TRUE;
2343
2344 // At start of the line we can have a composing char.
2345 // Draw it as a space with a composing char.
2346 if (utf_iscomposing(mb_c))
2347 {
2348 int i;
2349
2350 for (i = Screen_mco - 1; i > 0; --i)
2351 u8cc[i] = u8cc[i - 1];
2352 u8cc[0] = mb_c;
2353 mb_c = ' ';
2354 }
2355 }
2356
2357 if ((mb_l == 1 && c >= 0x80)
2358 || (mb_l >= 1 && mb_c == 0)
2359 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2360 {
2361 // Illegal UTF-8 byte: display as <xx>.
2362 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002363 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002364# ifdef FEAT_RIGHTLEFT
2365 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002366 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002367# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002368 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002369 c = *wlv.p_extra;
2370 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002371 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002372 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2373 wlv.c_extra = NUL;
2374 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002375 if (area_attr == 0 && search_attr == 0)
2376 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002377 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002378 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002379 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002380 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002381 }
2382 }
2383 else if (mb_l == 0) // at the NUL at end-of-line
2384 mb_l = 1;
2385#ifdef FEAT_ARABIC
2386 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2387 {
2388 // Do Arabic shaping.
2389 int pc, pc1, nc;
2390 int pcc[MAX_MCO];
2391
2392 // The idea of what is the previous and next
2393 // character depends on 'rightleft'.
2394 if (wp->w_p_rl)
2395 {
2396 pc = prev_c;
2397 pc1 = prev_c1;
2398 nc = utf_ptr2char(ptr + mb_l);
2399 prev_c1 = u8cc[0];
2400 }
2401 else
2402 {
2403 pc = utfc_ptr2char(ptr + mb_l, pcc);
2404 nc = prev_c;
2405 pc1 = pcc[0];
2406 }
2407 prev_c = mb_c;
2408
2409 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2410 }
2411 else
2412 prev_c = mb_c;
2413#endif
2414 }
2415 else // enc_dbcs
2416 {
2417 mb_l = MB_BYTE2LEN(c);
2418 if (mb_l == 0) // at the NUL at end-of-line
2419 mb_l = 1;
2420 else if (mb_l > 1)
2421 {
2422 // We assume a second byte below 32 is illegal.
2423 // Hopefully this is OK for all double-byte encodings!
2424 if (ptr[1] >= 32)
2425 mb_c = (c << 8) + ptr[1];
2426 else
2427 {
2428 if (ptr[1] == NUL)
2429 {
2430 // head byte at end of line
2431 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002432 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002433 }
2434 else
2435 {
2436 // illegal tail byte
2437 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002438 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002439 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002440 wlv.p_extra = wlv.extra;
2441 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002442 wlv.c_extra = NUL;
2443 wlv.c_final = NUL;
2444 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002445 if (area_attr == 0 && search_attr == 0)
2446 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002447 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002448 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002449 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002450 // save current attr
2451 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002452 }
2453 mb_c = c;
2454 }
2455 }
2456 }
2457 // If a double-width char doesn't fit display a '>' in the
2458 // last column; the character is displayed at the start of the
2459 // next line.
2460 if ((
2461# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002462 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002463# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002464 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002465 && (*mb_char2cells)(mb_c) == 2)
2466 {
2467 c = '>';
2468 mb_c = c;
2469 mb_utf8 = FALSE;
2470 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002471 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002472 // Put pointer back so that the character will be
2473 // displayed at the start of the next line.
2474 --ptr;
2475#ifdef FEAT_CONCEAL
2476 did_decrement_ptr = TRUE;
2477#endif
2478 }
2479 else if (*ptr != NUL)
2480 ptr += mb_l - 1;
2481
2482 // If a double-width char doesn't fit at the left side display
2483 // a '<' in the first column. Don't do this for unprintable
2484 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002485 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002486 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002487 wlv.n_extra = 1;
2488 wlv.c_extra = MB_FILLER_CHAR;
2489 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002490 c = ' ';
2491 if (area_attr == 0 && search_attr == 0)
2492 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002493 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002494 extra_attr = hl_combine_attr(
2495 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002496 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002497 }
2498 mb_c = c;
2499 mb_utf8 = FALSE;
2500 mb_l = 1;
2501 }
2502
2503 }
2504 ++ptr;
2505
2506 if (extra_check)
2507 {
2508#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002509 // Check spelling (unless at the end of the line).
2510 // Only do this when there is no syntax highlighting, the
2511 // @Spell cluster is not used or the current syntax item
2512 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002513 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002514 if (has_spell && v >= word_end && v > cur_checked_col)
2515 {
2516 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002517 // do not calculate cap_col at the end of the line or when
2518 // only white space is following
2519 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002520# ifdef FEAT_SYN_HL
2521 !has_syntax ||
2522# endif
2523 can_spell))
2524 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002525 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002526 int len;
2527 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002528
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002529 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002530 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002531
2532 // Use nextline[] if possible, it has the start of the
2533 // next line concatenated.
2534 if ((prev_ptr - line) - nextlinecol >= 0)
2535 p = nextline + (prev_ptr - line) - nextlinecol;
2536 else
2537 p = prev_ptr;
2538 cap_col -= (int)(prev_ptr - line);
2539 len = spell_check(wp, p, &spell_hlf, &cap_col,
2540 nochange);
2541 word_end = v + len;
2542
2543 // In Insert mode only highlight a word that
2544 // doesn't touch the cursor.
2545 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002546 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002547 && wp->w_cursor.lnum == lnum
2548 && wp->w_cursor.col >=
2549 (colnr_T)(prev_ptr - line)
2550 && wp->w_cursor.col < (colnr_T)word_end)
2551 {
2552 spell_hlf = HLF_COUNT;
2553 spell_redraw_lnum = lnum;
2554 }
2555
2556 if (spell_hlf == HLF_COUNT && p != prev_ptr
2557 && (p - nextline) + len > nextline_idx)
2558 {
2559 // Remember that the good word continues at the
2560 // start of the next line.
2561 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002562 checked_col = (int)((p - nextline)
2563 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002564 }
2565
2566 // Turn index into actual attributes.
2567 if (spell_hlf != HLF_COUNT)
2568 spell_attr = highlight_attr[spell_hlf];
2569
2570 if (cap_col > 0)
2571 {
2572 if (p != prev_ptr
2573 && (p - nextline) + cap_col >= nextline_idx)
2574 {
2575 // Remember that the word in the next line
2576 // must start with a capital.
2577 capcol_lnum = lnum + 1;
2578 cap_col = (int)((p - nextline) + cap_col
2579 - nextline_idx);
2580 }
2581 else
2582 // Compute the actual column.
2583 cap_col += (int)(prev_ptr - line);
2584 }
2585 }
2586 }
2587 if (spell_attr != 0)
2588 {
2589 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002590 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2591 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002592 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002593 wlv.char_attr = hl_combine_attr(spell_attr,
2594 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002595 }
2596#endif
2597#ifdef FEAT_LINEBREAK
2598 // Found last space before word: check for line break.
2599 if (wp->w_p_lbr && c0 == c
2600 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2601 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002602 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2603 : 0;
2604 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002605 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002606
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002607 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002608# ifdef FEAT_PROP_POPUP
2609 // do not want virtual text counted here
2610 cts.cts_has_prop_with_text = FALSE;
2611# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002612 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002613 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002614
2615 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002616 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002617 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002618 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002619 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2620 if (wlv.n_extra < 0)
2621 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002622 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002623 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002624 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002625 // line break, but for TABs the highlighting should
2626 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002627 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002628
Bram Moolenaar1306b362022-08-06 15:59:06 +01002629 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002630# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002631 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002632 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002633 wp->w_buffer->b_p_vts_array) - 1;
2634# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002635 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002636 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002637# endif
2638
Bram Moolenaar1306b362022-08-06 15:59:06 +01002639 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2640 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002641# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002642 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002643 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002644# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002645 if (VIM_ISWHITE(c))
2646 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002647# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002648 if (c == TAB)
2649 // See "Tab alignment" below.
2650 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002651# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002652 if (!wp->w_p_list)
2653 c = ' ';
2654 }
2655 }
2656#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002657 in_multispace = c == ' '
2658 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2659 if (!in_multispace)
2660 multispace_pos = 0;
2661
Bram Moolenaareed9d462021-02-15 20:38:25 +01002662 // 'list': Change char 160 to 'nbsp' and space to 'space'
2663 // setting in 'listchars'. But not when the character is
2664 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002665 if (wp->w_p_list
2666 && ((((c == 160 && mb_l == 1)
2667 || (mb_utf8
2668 && ((mb_c == 160 && mb_l == 2)
2669 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002670 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002671 || (c == ' '
2672 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002673 && (wp->w_lcs_chars.space
2674 || (in_multispace
2675 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002676 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002677 && ptr - line <= trailcol)))
2678 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002679 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2680 {
2681 c = wp->w_lcs_chars.multispace[multispace_pos++];
2682 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2683 multispace_pos = 0;
2684 }
2685 else
2686 c = (c == ' ') ? wp->w_lcs_chars.space
2687 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002688 if (area_attr == 0 && search_attr == 0)
2689 {
2690 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002691 extra_attr = hl_combine_attr(wlv.win_attr,
2692 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002693 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002694 }
2695 mb_c = c;
2696 if (enc_utf8 && utf_char2len(c) > 1)
2697 {
2698 mb_utf8 = TRUE;
2699 u8cc[0] = 0;
2700 c = 0xc0;
2701 }
2702 else
2703 mb_utf8 = FALSE;
2704 }
2705
zeertzjq2e7cba32022-06-10 15:30:32 +01002706 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2707 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002708 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002709 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2710 && wp->w_lcs_chars.leadmultispace != NULL)
2711 {
2712 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002713 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2714 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002715 multispace_pos = 0;
2716 }
2717
2718 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2719 c = wp->w_lcs_chars.trail;
2720
2721 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2722 c = wp->w_lcs_chars.lead;
2723
zeertzjq2e7cba32022-06-10 15:30:32 +01002724 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002725 c = wp->w_lcs_chars.space;
2726
2727
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002728 if (!attr_pri)
2729 {
2730 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002731 extra_attr = hl_combine_attr(wlv.win_attr,
2732 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002733 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002734 }
2735 mb_c = c;
2736 if (enc_utf8 && utf_char2len(c) > 1)
2737 {
2738 mb_utf8 = TRUE;
2739 u8cc[0] = 0;
2740 c = 0xc0;
2741 }
2742 else
2743 mb_utf8 = FALSE;
2744 }
2745 }
2746
2747 // Handling of non-printable characters.
2748 if (!vim_isprintc(c))
2749 {
2750 // when getting a character from the file, we may have to
2751 // turn it into something else on the way to putting it
2752 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002753 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002754 {
2755 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002756 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002757#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002758 char_u *sbr = get_showbreak_value(wp);
2759
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002760 // only adjust the tab_len, when at the first column
2761 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002762 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002763 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002764#endif
2765 // tab amount depends on current column
2766#ifdef FEAT_VARTABS
2767 tab_len = tabstop_padding(vcol_adjusted,
2768 wp->w_buffer->b_p_ts,
2769 wp->w_buffer->b_p_vts_array) - 1;
2770#else
2771 tab_len = (int)wp->w_buffer->b_p_ts
2772 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2773#endif
2774
2775#ifdef FEAT_LINEBREAK
2776 if (!wp->w_p_lbr || !wp->w_p_list)
2777#endif
2778 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002779 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002780#ifdef FEAT_LINEBREAK
2781 else
2782 {
2783 char_u *p;
2784 int len;
2785 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002786 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002787
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002788# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002789 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002790 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002791 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002792
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002793 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002794 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002795 && old_boguscols > 0
2796 && wlv.n_extra > tab_len)
2797 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002798# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002799 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002800 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002801 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002802 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002803 if (wp->w_lcs_chars.tab3)
2804 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002805 if (wlv.n_extra > 0)
2806 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002807 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002808 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002809 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002810 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002811 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002812 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002813 vim_memset(p, ' ', len);
2814 p[len] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002815 vim_free(wlv.p_extra_free);
2816 wlv.p_extra_free = p;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002817 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002818 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002819 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002820
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002821 if (*p == NUL)
2822 {
2823 tab_len = i;
2824 break;
2825 }
2826
2827 // if tab3 is given, use it for the last char
2828 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2829 lcs = wp->w_lcs_chars.tab3;
2830 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002831 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002832 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002833 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002834 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002835# ifdef FEAT_CONCEAL
2836 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2837 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002838 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002839 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002840# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002841 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002842 }
2843#endif
2844#ifdef FEAT_CONCEAL
2845 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002846 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002847
2848 // Tab alignment should be identical regardless of
2849 // 'conceallevel' value. So tab compensates of all
2850 // previous concealed characters, and thus resets
2851 // vcol_off and boguscols accumulated so far in the
2852 // line. Note that the tab can be longer than
2853 // 'tabstop' when there are concealed characters.
2854 FIX_FOR_BOGUSCOLS;
2855
2856 // Make sure, the highlighting for the tab char will be
2857 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002858 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002859 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002860 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002861 tab_len += vc_saved;
2862 }
2863#endif
2864 mb_utf8 = FALSE; // don't draw as UTF-8
2865 if (wp->w_p_list)
2866 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002867 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002868 ? wp->w_lcs_chars.tab3
2869 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002870#ifdef FEAT_LINEBREAK
2871 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002872 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002873 else
2874#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002875 wlv.c_extra = wp->w_lcs_chars.tab2;
2876 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002877 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002878 extra_attr = hl_combine_attr(wlv.win_attr,
2879 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002880 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002881 mb_c = c;
2882 if (enc_utf8 && utf_char2len(c) > 1)
2883 {
2884 mb_utf8 = TRUE;
2885 u8cc[0] = 0;
2886 c = 0xc0;
2887 }
2888 }
2889 else
2890 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002891 wlv.c_final = NUL;
2892 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002893 c = ' ';
2894 }
2895 }
2896 else if (c == NUL
2897 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002898 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
2899 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002900 && VIsual_mode != Ctrl_V
2901 && (
2902# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002903 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002904# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002905 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002906 && !(noinvcur
2907 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002908 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002909 && lcs_eol_one > 0)
2910 {
2911 // Display a '$' after the line or highlight an extra
2912 // character if the line break is included.
2913#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2914 // For a diff line the highlighting continues after the
2915 // "$".
2916 if (
2917# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002918 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002919# ifdef LINE_ATTR
2920 &&
2921# endif
2922# endif
2923# ifdef LINE_ATTR
2924 line_attr == 0
2925# endif
2926 )
2927#endif
2928 {
2929 // In virtualedit, visual selections may extend
2930 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002931 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002932 && wlv.tocol != MAXCOL
2933 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002934 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002935 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002936 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002937 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2938 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002939 else
2940 c = ' ';
2941 lcs_eol_one = -1;
2942 --ptr; // put it back at the NUL
2943 if (!attr_pri)
2944 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002945 extra_attr = hl_combine_attr(wlv.win_attr,
2946 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002947 n_attr = 1;
2948 }
2949 mb_c = c;
2950 if (enc_utf8 && utf_char2len(c) > 1)
2951 {
2952 mb_utf8 = TRUE;
2953 u8cc[0] = 0;
2954 c = 0xc0;
2955 }
2956 else
2957 mb_utf8 = FALSE; // don't draw as UTF-8
2958 }
2959 else if (c != NUL)
2960 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002961 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2962 if (wlv.n_extra == 0)
2963 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002964#ifdef FEAT_RIGHTLEFT
2965 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002966 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002967#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002968 wlv.c_extra = NUL;
2969 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002970#ifdef FEAT_LINEBREAK
2971 if (wp->w_p_lbr)
2972 {
2973 char_u *p;
2974
Bram Moolenaar1306b362022-08-06 15:59:06 +01002975 c = *wlv.p_extra;
2976 p = alloc(wlv.n_extra + 1);
2977 vim_memset(p, ' ', wlv.n_extra);
2978 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2979 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002980 vim_free(wlv.p_extra_free);
2981 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002982 }
2983 else
2984#endif
2985 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002986 wlv.n_extra = byte2cells(c) - 1;
2987 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002988 }
2989 if (!attr_pri)
2990 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002991 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002992 extra_attr = hl_combine_attr(wlv.win_attr,
2993 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002994 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002995 }
2996 mb_utf8 = FALSE; // don't draw as UTF-8
2997 }
2998 else if (VIsual_active
2999 && (VIsual_mode == Ctrl_V
3000 || VIsual_mode == 'v')
3001 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003002 && wlv.tocol != MAXCOL
3003 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003004 && (
3005#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003006 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003007#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003008 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003009 {
3010 c = ' ';
3011 --ptr; // put it back at the NUL
3012 }
3013#if defined(LINE_ATTR)
3014 else if ((
3015# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003016 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003017# endif
3018# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003019 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003020# endif
3021 line_attr != 0
3022 ) && (
3023# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003024 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003025# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003026 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003027# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003028 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003029# endif
3030 < wp->w_width)))
3031 {
3032 // Highlight until the right side of the window
3033 c = ' ';
3034 --ptr; // put it back at the NUL
3035
3036 // Remember we do the char for line highlighting.
3037 ++did_line_attr;
3038
3039 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01003040 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003041 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003042 || (wp->w_p_list &&
3043 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003044 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003045# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003046 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003047 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003048 wlv.diff_hlf = HLF_CHD;
3049 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003050 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003051 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003052 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3053 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003054 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003055 || (wlv.vcol >= left_curline_col
3056 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003057 wlv.char_attr = hl_combine_attr(
3058 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003059 }
3060 }
3061# endif
3062# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003063 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003064 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003065 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003066 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3067 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003068 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003069 if (!wlv.cul_screenline
3070 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003071 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003072 wlv.char_attr = hl_combine_attr(
3073 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003074 }
3075 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003076 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3077 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003078 }
3079# endif
3080 }
3081#endif
3082 }
3083
3084#ifdef FEAT_CONCEAL
3085 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003086 && (wp != curwin || lnum != wp->w_cursor.lnum
3087 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003088 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3089 && !(lnum_in_visual_area
3090 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3091 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003092 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003093 if (((prev_syntax_id != syntax_seqnr
3094 && (syntax_flags & HL_CONCEAL) != 0)
3095 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003096 && (syn_get_sub_char() != NUL
3097 || (has_match_conc && match_conc)
3098 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003099 && wp->w_p_cole != 3)
3100 {
3101 // First time at this concealed item: display one
3102 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003103 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003104 c = match_conc;
3105 else if (syn_get_sub_char() != NUL)
3106 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003107 else if (wp->w_lcs_chars.conceal != NUL)
3108 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003109 else
3110 c = ' ';
3111
3112 prev_syntax_id = syntax_seqnr;
3113
Bram Moolenaar1306b362022-08-06 15:59:06 +01003114 if (wlv.n_extra > 0)
3115 wlv.vcol_off += wlv.n_extra;
3116 wlv.vcol += wlv.n_extra;
3117 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003118 {
3119# ifdef FEAT_RIGHTLEFT
3120 if (wp->w_p_rl)
3121 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003122 wlv.col -= wlv.n_extra;
3123 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003124 }
3125 else
3126# endif
3127 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003128 wlv.boguscols += wlv.n_extra;
3129 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003130 }
3131 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003132 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003133 n_attr = 0;
3134 }
3135 else if (n_skip == 0)
3136 {
3137 is_concealing = TRUE;
3138 n_skip = 1;
3139 }
3140 mb_c = c;
3141 if (enc_utf8 && utf_char2len(c) > 1)
3142 {
3143 mb_utf8 = TRUE;
3144 u8cc[0] = 0;
3145 c = 0xc0;
3146 }
3147 else
3148 mb_utf8 = FALSE; // don't draw as UTF-8
3149 }
3150 else
3151 {
3152 prev_syntax_id = 0;
3153 is_concealing = FALSE;
3154 }
3155
3156 if (n_skip > 0 && did_decrement_ptr)
3157 // not showing the '>', put pointer back to avoid getting stuck
3158 ++ptr;
3159
3160#endif // FEAT_CONCEAL
3161 }
3162
3163#ifdef FEAT_CONCEAL
3164 // In the cursor line and we may be concealing characters: correct
3165 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003166 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003167 && wp == curwin && lnum == wp->w_cursor.lnum
3168 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003169 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003170 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003171# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003172 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003173 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003174 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003175# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003176 wp->w_wcol = wlv.col - wlv.boguscols;
3177 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003178 did_wcol = TRUE;
3179 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003180# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003181 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003182# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003183 }
3184#endif
3185
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003186 // Use "extra_attr", but don't override visual selection highlighting,
3187 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003188 // Don't use "extra_attr" until n_attr_skip is zero.
3189 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003190 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003191 && (!attr_pri
3192#ifdef FEAT_PROP_POPUP
3193 || (text_prop_flags & PT_FLAG_OVERRIDE)
3194#endif
3195 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003196 {
3197#ifdef LINE_ATTR
3198 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003199 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003200 else
3201#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003202 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003203 }
3204
3205#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3206 // XIM don't send preedit_start and preedit_end, but they send
3207 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3208 // im_is_preediting() here.
3209 if (p_imst == IM_ON_THE_SPOT
3210 && xic != NULL
3211 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003212 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003213 && !p_imdisable
3214 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003215 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003216 {
3217 colnr_T tcol;
3218
3219 if (preedit_end_col == MAXCOL)
3220 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3221 else
3222 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003223 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003224 {
3225 if (feedback_old_attr < 0)
3226 {
3227 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003228 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003229 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003230 wlv.char_attr = im_get_feedback_attr(feedback_col);
3231 if (wlv.char_attr < 0)
3232 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003233 feedback_col++;
3234 }
3235 else if (feedback_old_attr >= 0)
3236 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003237 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003238 feedback_old_attr = -1;
3239 feedback_col = 0;
3240 }
3241 }
3242#endif
3243 // Handle the case where we are in column 0 but not on the first
3244 // character of the line and the user wants us to show us a
3245 // special character (via 'listchars' option "precedes:<char>".
3246 if (lcs_prec_todo != NUL
3247 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003248 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3249 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003250#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003251 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003252#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003253 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003254 && c != NUL)
3255 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003256 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003257 lcs_prec_todo = NUL;
3258 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3259 {
3260 // Double-width character being overwritten by the "precedes"
3261 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003262 wlv.c_extra = MB_FILLER_CHAR;
3263 wlv.c_final = NUL;
3264 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003265 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003266 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003267 }
3268 mb_c = c;
3269 if (enc_utf8 && utf_char2len(c) > 1)
3270 {
3271 mb_utf8 = TRUE;
3272 u8cc[0] = 0;
3273 c = 0xc0;
3274 }
3275 else
3276 mb_utf8 = FALSE; // don't draw as UTF-8
3277 if (!attr_pri)
3278 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003279 saved_attr3 = wlv.char_attr; // save current attr
3280 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003281 n_attr3 = 1;
3282 }
3283 }
3284
3285 // At end of the text line or just after the last character.
3286 if ((c == NUL
3287#if defined(LINE_ATTR)
3288 || did_line_attr == 1
3289#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003290 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003291 {
3292#ifdef FEAT_SEARCH_EXTRA
3293 // flag to indicate whether prevcol equals startcol of search_hl or
3294 // one of the matches
3295 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3296 (long)(ptr - line) - (c == NUL));
3297#endif
3298 // Invert at least one char, used for Visual and empty line or
3299 // highlight match at end of line. If it's beyond the last
3300 // char on the screen, just overwrite that one (tricky!) Not
3301 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003302 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003303 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003304 && (VIsual_mode != Ctrl_V
3305 || lnum == VIsual.lnum
3306 || lnum == curwin->w_cursor.lnum)
3307 && c == NUL)
3308#ifdef FEAT_SEARCH_EXTRA
3309 // highlight 'hlsearch' match at end of line
3310 || (prevcol_hl_flag
3311# ifdef FEAT_SYN_HL
3312 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3313 && !(wp == curwin && VIsual_active))
3314# endif
3315# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003316 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003317# endif
3318# if defined(LINE_ATTR)
3319 && did_line_attr <= 1
3320# endif
3321 )
3322#endif
3323 ))
3324 {
3325 int n = 0;
3326
3327#ifdef FEAT_RIGHTLEFT
3328 if (wp->w_p_rl)
3329 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003330 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003331 n = 1;
3332 }
3333 else
3334#endif
3335 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003336 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003337 n = -1;
3338 }
3339 if (n != 0)
3340 {
3341 // At the window boundary, highlight the last character
3342 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003343 wlv.off += n;
3344 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003345 }
3346 else
3347 {
3348 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003349 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003350 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003351 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003352 }
3353#ifdef FEAT_SEARCH_EXTRA
3354 if (area_attr == 0)
3355 {
3356 // Use attributes from match with highest priority among
3357 // 'search_hl' and the match list.
3358 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003359 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003360 }
3361#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003362 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003363 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003364#ifdef FEAT_RIGHTLEFT
3365 if (wp->w_p_rl)
3366 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003367 --wlv.col;
3368 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003369 }
3370 else
3371#endif
3372 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003373 ++wlv.col;
3374 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003375 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003376 ++wlv.vcol;
3377 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003378 }
3379 }
3380
3381 // At end of the text line.
3382 if (c == NUL)
3383 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003384 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003385
3386 // Update w_cline_height and w_cline_folded if the cursor line was
3387 // updated (saves a call to plines() later).
3388 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3389 {
3390 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003391 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003392#ifdef FEAT_FOLDING
3393 curwin->w_cline_folded = FALSE;
3394#endif
3395 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3396 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003397 break;
3398 }
3399
3400 // Show "extends" character from 'listchars' if beyond the line end and
3401 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003402 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003403 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003404 && wp->w_p_list
3405 && !wp->w_p_wrap
3406#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003407 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003408#endif
3409 && (
3410#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003411 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003412#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003413 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003414 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003415 || lcs_eol_one > 0
3416 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003417 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003418 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003419 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003420 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003421 mb_c = c;
3422 if (enc_utf8 && utf_char2len(c) > 1)
3423 {
3424 mb_utf8 = TRUE;
3425 u8cc[0] = 0;
3426 c = 0xc0;
3427 }
3428 else
3429 mb_utf8 = FALSE;
3430 }
3431
3432#ifdef FEAT_SYN_HL
3433 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003434 if (wlv.draw_color_col)
3435 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003436
3437 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3438 // highlight the cursor position itself.
3439 // Also highlight the 'colorcolumn' if it is different than
3440 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003441 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3442 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003443 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003444 if (((wlv.draw_state == WL_LINE
3445 || wlv.draw_state == WL_BRI
3446 || wlv.draw_state == WL_SBR)
3447 && !lnum_in_visual_area
3448 && search_attr == 0
3449 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003450# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003451 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003452# endif
3453 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003454 {
3455 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3456 && lnum != wp->w_cursor.lnum)
3457 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003458 vcol_save_attr = wlv.char_attr;
3459 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3460 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003461 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003462 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003463 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003464 vcol_save_attr = wlv.char_attr;
3465 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003466 }
3467 }
3468#endif
3469
3470 // Store character to be displayed.
3471 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003472 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003473 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003474 {
3475 // Store the character.
3476#if defined(FEAT_RIGHTLEFT)
3477 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3478 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003479 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003480 --wlv.off;
3481 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003482 }
3483#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003484 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003485 if (enc_dbcs == DBCS_JPNU)
3486 {
3487 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003488 ScreenLines[wlv.off] = 0x8e;
3489 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003490 }
3491 else if (enc_utf8)
3492 {
3493 if (mb_utf8)
3494 {
3495 int i;
3496
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003497 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003498 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003499 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003500 for (i = 0; i < Screen_mco; ++i)
3501 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003502 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003503 if (u8cc[i] == 0)
3504 break;
3505 }
3506 }
3507 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003508 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003509 }
3510 if (multi_attr)
3511 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003512 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003513 multi_attr = 0;
3514 }
3515 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003516 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003517
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003518 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003519
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003520 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3521 {
3522 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003523 ++wlv.off;
3524 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003525 if (enc_utf8)
3526 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003527 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003528 else
3529 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003530 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003531 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003532#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003533 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003534#endif
3535 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003536 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003537 // When "wlv.tocol" is halfway a character, set it to the end
3538 // of the character, otherwise highlighting won't stop.
3539 if (wlv.tocol == wlv.vcol)
3540 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003541
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003542 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003543
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003544#ifdef FEAT_RIGHTLEFT
3545 if (wp->w_p_rl)
3546 {
3547 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003548 --wlv.off;
3549 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003550 }
3551#endif
3552 }
3553#ifdef FEAT_RIGHTLEFT
3554 if (wp->w_p_rl)
3555 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003556 --wlv.off;
3557 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003558 }
3559 else
3560#endif
3561 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003562 ++wlv.off;
3563 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003564 }
3565 }
3566#ifdef FEAT_CONCEAL
3567 else if (wp->w_p_cole > 0 && is_concealing)
3568 {
3569 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003570 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003571 if (wlv.n_extra > 0)
3572 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003573 if (wp->w_p_wrap)
3574 {
3575 // Special voodoo required if 'wrap' is on.
3576 //
3577 // Advance the column indicator to force the line
3578 // drawing to wrap early. This will make the line
3579 // take up the same screen space when parts are concealed,
3580 // so that cursor line computations aren't messed up.
3581 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003582 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003583 // trailing junk to be written out of the screen line
3584 // we are building, 'boguscols' keeps track of the number
3585 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003586 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003587 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003588 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003589# ifdef FEAT_RIGHTLEFT
3590 if (wp->w_p_rl)
3591 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003592 wlv.col -= wlv.n_extra;
3593 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003594 }
3595 else
3596# endif
3597 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003598 wlv.col += wlv.n_extra;
3599 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003600 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003601 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003602 n_attr = 0;
3603 }
3604
3605
3606 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3607 {
3608 // Need to fill two screen columns.
3609# ifdef FEAT_RIGHTLEFT
3610 if (wp->w_p_rl)
3611 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003612 --wlv.boguscols;
3613 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003614 }
3615 else
3616# endif
3617 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003618 ++wlv.boguscols;
3619 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003620 }
3621 }
3622
3623# ifdef FEAT_RIGHTLEFT
3624 if (wp->w_p_rl)
3625 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003626 --wlv.boguscols;
3627 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003628 }
3629 else
3630# endif
3631 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003632 ++wlv.boguscols;
3633 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003634 }
3635 }
3636 else
3637 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003638 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003639 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003640 wlv.vcol += wlv.n_extra;
3641 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003642 n_attr = 0;
3643 }
3644 }
3645
3646 }
3647#endif // FEAT_CONCEAL
3648 else
3649 --n_skip;
3650
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003651 // Only advance the "wlv.vcol" when after the 'number' or
3652 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003653 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003654#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003655 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003656#endif
3657 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003658 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003659
3660#ifdef FEAT_SYN_HL
3661 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003662 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003663#endif
3664
3665 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003666 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3667 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003668
3669 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003670 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003671 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003672 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003673 if (n_attr_skip > 0)
3674 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003675
3676 // At end of screen line and there is more to come: Display the line
3677 // so far. If there is no more to display it is caught above.
3678 if ((
3679#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003680 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003681#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003682 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003683 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003684 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003685#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003686 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003687#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003688#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003689 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003690#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003691 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003692 && wlv.p_extra != at_end_str)
3693 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3694 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003695 )
3696 {
3697#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003698 wlv.col += wlv.boguscols;
3699 wlv_screen_line(wp, &wlv, FALSE);
3700 wlv.col -= wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003701 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003702#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003703 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003704#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003705 ++wlv.row;
3706 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003707
3708 // When not wrapping and finished diff lines, or when displayed
3709 // '$' and highlighting until last column, break here.
3710 if ((!wp->w_p_wrap
3711#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003712 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003713#endif
3714#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003715 && !text_prop_above && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003716#endif
3717 ) || lcs_eol_one == -1)
3718 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003719#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003720 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003721 {
3722 // do not output more of the line, only the "below" prop
3723 ptr += STRLEN(ptr);
3724# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003725 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003726# endif
3727 }
3728#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003729
3730 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003731 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003732#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003733 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003734#endif
3735 )
3736 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003737 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3738 draw_vsep_win(wp, wlv.row);
3739 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003740 }
3741
3742 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003743 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003744 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003745 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003746 break;
3747 }
3748
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003749 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003750#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003751 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003752#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003753#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003754 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003755#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003756 && wp->w_width == Columns)
3757 {
3758 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003759 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003760
3761 // Special trick to make copy/paste of wrapped lines work with
3762 // xterm/screen: write an extra character beyond the end of
3763 // the line. This will work with all terminal types
3764 // (regardless of the xn,am settings).
3765 // Only do this on a fast tty.
3766 // Only do this if the cursor is on the current line
3767 // (something has been written in it).
3768 // Don't do this for the GUI.
3769 // Don't do this for double-width characters.
3770 // Don't do this for a window not at the right screen border.
3771 if (p_tf
3772#ifdef FEAT_GUI
3773 && !gui.in_use
3774#endif
3775 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003776 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3777 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003778 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003779 || (*mb_off2cells)(
3780 LineOffset[wlv.screen_row - 1]
3781 + (int)Columns - 2,
3782 LineOffset[wlv.screen_row]
3783 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003784 {
3785 // First make sure we are at the end of the screen line,
3786 // then output the same character again to let the
3787 // terminal know about the wrap. If the terminal doesn't
3788 // auto-wrap, we overwrite the character.
3789 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003790 screen_char(LineOffset[wlv.screen_row - 1]
3791 + (unsigned)Columns - 1,
3792 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003793
3794 // When there is a multi-byte character, just output a
3795 // space to keep it simple.
3796 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003797 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003798 out_char(' ');
3799 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003800 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003801 + (Columns - 1)]);
3802 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003803 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003804 screen_start(); // don't know where cursor is now
3805 }
3806 }
3807
Bram Moolenaar1306b362022-08-06 15:59:06 +01003808 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003809
Bram Moolenaareed9d462021-02-15 20:38:25 +01003810 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003811#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003812 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003813# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003814 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003815# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003816 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003817 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003818#endif
3819#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003820 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003821 // When the filler lines are actually below the last line of the
3822 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003823 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003824 break;
3825#endif
3826 }
3827
3828 } // for every character in the line
3829
3830#ifdef FEAT_SPELL
3831 // After an empty line check first word for capital.
3832 if (*skipwhite(line) == NUL)
3833 {
3834 capcol_lnum = lnum + 1;
3835 cap_col = 0;
3836 }
3837#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003838#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003839 vim_free(text_props);
3840 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003841 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003842#endif
3843
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003844 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003845 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003846}