blob: 4bda102baecef93c857580cde36e445350b2c17e [file] [log] [blame]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * drawline.c: Functions for drawing window lines on the screen.
Bram Moolenaare89aeed2022-08-22 13:00:16 +010012 * This is the middle level, drawscreen.c is the higher level and screen.c the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020013 * lower level.
14 */
15
16#include "vim.h"
17
18#ifdef FEAT_SYN_HL
19/*
20 * Advance **color_cols and return TRUE when there are columns to draw.
21 */
22 static int
23advance_color_col(int vcol, int **color_cols)
24{
25 while (**color_cols >= 0 && vcol > **color_cols)
26 ++*color_cols;
27 return (**color_cols >= 0);
28}
29#endif
30
31#ifdef FEAT_SYN_HL
32/*
33 * Used when 'cursorlineopt' contains "screenline": compute the margins between
34 * which the highlighting is used.
35 */
36 static void
37margin_columns_win(win_T *wp, int *left_col, int *right_col)
38{
39 // cache previous calculations depending on w_virtcol
40 static int saved_w_virtcol;
41 static win_T *prev_wp;
42 static int prev_left_col;
43 static int prev_right_col;
44 static int prev_col_off;
45
46 int cur_col_off = win_col_off(wp);
47 int width1;
48 int width2;
49
50 if (saved_w_virtcol == wp->w_virtcol
51 && prev_wp == wp && prev_col_off == cur_col_off)
52 {
53 *right_col = prev_right_col;
54 *left_col = prev_left_col;
55 return;
56 }
57
58 width1 = wp->w_width - cur_col_off;
59 width2 = width1 + win_col_off2(wp);
60
61 *left_col = 0;
62 *right_col = width1;
63
64 if (wp->w_virtcol >= (colnr_T)width1)
65 *right_col = width1 + ((wp->w_virtcol - width1) / width2 + 1) * width2;
66 if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0)
67 *left_col = (wp->w_virtcol - width1) / width2 * width2 + width1;
68
69 // cache values
70 prev_left_col = *left_col;
71 prev_right_col = *right_col;
72 prev_wp = wp;
73 saved_w_virtcol = wp->w_virtcol;
74 prev_col_off = cur_col_off;
75}
76#endif
77
Bram Moolenaar1306b362022-08-06 15:59:06 +010078// structure with variables passed between win_line() and other functions
79typedef struct {
80 int draw_state; // what to draw next
81
82 linenr_T lnum; // line number to be drawn
83
84 int startrow; // first row in the window to be drawn
85 int row; // row in the window, excl w_winrow
86 int screen_row; // row on the screen, incl w_winrow
87
88 long vcol; // virtual column, before wrapping
89 int col; // visual column on screen, after wrapping
90#ifdef FEAT_CONCEAL
91 int boguscols; // nonexistent columns added to "col" to force
92 // wrapping
93 int vcol_off; // offset for concealed characters
94#endif
95#ifdef FEAT_SYN_HL
96 int draw_color_col; // highlight colorcolumn
97 int *color_cols; // pointer to according columns array
98#endif
99 int eol_hl_off; // 1 if highlighted char after EOL
100
101 unsigned off; // offset in ScreenLines/ScreenAttrs
102
103 int win_attr; // background for the whole window, except
104 // margins and "~" lines.
Bram Moolenaard7657e92022-09-20 18:59:30 +0100105 int wcr_attr; // attributes from 'wincolor'
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100106#ifdef FEAT_SYN_HL
107 int cul_attr; // set when 'cursorline' active
108#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100109
110 int screen_line_flags; // flags for screen_line()
111
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100112 int fromcol; // start of inverting
113 int tocol; // end of inverting
114
115#ifdef FEAT_LINEBREAK
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100116 long vcol_sbr; // virtual column after showbreak
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100117 int need_showbreak; // overlong line, skipping first x chars
118 int dont_use_showbreak; // do not use 'showbreak'
119#endif
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100120#ifdef FEAT_PROP_POPUP
121 int text_prop_above_count;
122#endif
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100123
Bram Moolenaar1306b362022-08-06 15:59:06 +0100124 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
125 int cul_screenline;
126
127 int char_attr; // attributes for the next character
128
129 int n_extra; // number of extra bytes
130 char_u *p_extra; // string of extra chars, plus NUL, only used
131 // when c_extra and c_final are NUL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100132 char_u *p_extra_free; // p_extra buffer that needs to be freed
Bram Moolenaar1306b362022-08-06 15:59:06 +0100133 int c_extra; // extra chars, all the same
134 int c_final; // final char, mandatory if set
135
136 // saved "extra" items for when draw_state becomes WL_LINE (again)
137 int saved_n_extra;
138 char_u *saved_p_extra;
139 int saved_c_extra;
140 int saved_c_final;
141 int saved_char_attr;
142
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100143 char_u extra[NUMBUFLEN + MB_MAXBYTES];
144 // "%ld " and 'fdc' must fit in here, as well
145 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100146
Bram Moolenaar1306b362022-08-06 15:59:06 +0100147#ifdef FEAT_DIFF
148 hlf_T diff_hlf; // type of diff highlighting
149#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100150 int filler_lines; // nr of filler lines to be drawn
151 int filler_todo; // nr of filler lines still to do + 1
152#ifdef FEAT_SIGNS
153 sign_attrs_T sattr;
154#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100155} winlinevars_T;
156
157// draw_state values for items that are drawn in sequence:
158#define WL_START 0 // nothing done yet, must be zero
Martin Tournoij7904fa42022-10-04 16:28:45 +0100159#define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar1306b362022-08-06 15:59:06 +0100160#ifdef FEAT_FOLDING
161# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
162#else
163# define WL_FOLD WL_CMDLINE
164#endif
165#ifdef FEAT_SIGNS
166# define WL_SIGN (WL_FOLD + 1) // column for signs
167#else
168# define WL_SIGN WL_FOLD // column for signs
169#endif
170#define WL_NR (WL_SIGN + 1) // line number
171#ifdef FEAT_LINEBREAK
172# define WL_BRI (WL_NR + 1) // 'breakindent'
173#else
174# define WL_BRI WL_NR
175#endif
176#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
177# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
178#else
179# define WL_SBR WL_BRI
180#endif
181#define WL_LINE (WL_SBR + 1) // text in the line
182
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100183#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200184/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000185 * Return TRUE if CursorLineSign highlight is to be used.
186 */
187 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100188use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000189{
190 return wp->w_p_cul
191 && lnum == wp->w_cursor.lnum
192 && (wp->w_p_culopt_flags & CULOPT_NBR);
193}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100194#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000195
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100196
197#ifdef FEAT_FOLDING
198/*
199 * Setup for drawing the 'foldcolumn', if there is one.
200 */
201 static void
202handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
203{
204 int fdc = compute_foldcolumn(wp, 0);
205
206 if (fdc <= 0)
207 return;
208
209 // Allocate a buffer, "wlv->extra[]" may already be in use.
210 vim_free(wlv->p_extra_free);
211 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
212 if (wlv->p_extra_free != NULL)
213 {
214 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
215 wp, FALSE, wlv->lnum);
216 wlv->p_extra_free[wlv->n_extra] = NUL;
217 wlv->p_extra = wlv->p_extra_free;
218 wlv->c_extra = NUL;
219 wlv->c_final = NUL;
220 if (use_cursor_line_highlight(wp, wlv->lnum))
221 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
222 else
223 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
224 }
225}
226#endif
227
228#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000229/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100230 * Get information needed to display the sign in line "wlv->lnum" in window
231 * "wp".
232 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200233 * Otherwise the sign is going to be displayed in the sign column.
234 */
235 static void
236get_sign_display_info(
237 int nrcol,
238 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100239 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200240{
241 int text_sign;
242# ifdef FEAT_SIGN_ICONS
243 int icon_sign;
244# endif
245
246 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100247 wlv->c_extra = ' ';
248 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200249 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100250 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200251 else
252 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100253 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100254 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000255 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100256 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100257 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200258 }
259
Bram Moolenaar1306b362022-08-06 15:59:06 +0100260 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200261#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100262 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200263#endif
264 )
265 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100266 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200267# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100268 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200269 if (gui.in_use && icon_sign != 0)
270 {
271 // Use the image in this position.
272 if (nrcol)
273 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100274 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100275 sprintf((char *)wlv->extra, "%-*c ",
276 number_width(wp), SIGN_BYTE);
277 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100278 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200279 }
280 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100281 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200282# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100283 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
284 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200285 {
286 if (nrcol)
287 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100288 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100289 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200290 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100291 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100292 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200293 }
294 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100295 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200296 }
297# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100298 wlv->c_final = NUL;
299 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200300 }
301 else
302# endif
303 if (text_sign != 0)
304 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100305 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100306 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200307 {
308 if (nrcol)
309 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100310 int width = number_width(wp) - 2;
311 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200312
313 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100314 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100315 vim_snprintf((char *)wlv->extra + n,
316 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100317 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200318 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100319 wlv->c_extra = NUL;
320 wlv->c_final = NUL;
321 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200322 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000323
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100324 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100325 && wlv->sattr.sat_culhl > 0)
326 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000327 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100328 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200329 }
330 }
331}
332#endif
333
Bram Moolenaard7657e92022-09-20 18:59:30 +0100334/*
335 * Display the absolute or relative line number. After the first row fill with
336 * blanks when the 'n' flag isn't in 'cpo'.
337 */
338 static void
339handle_lnum_col(
340 win_T *wp,
341 winlinevars_T *wlv,
342 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100343 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100344{
345 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar06618f92022-10-06 19:21:20 +0100346 && (wlv->row == wlv->startrow + wlv->filler_lines
347 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100348 {
349#ifdef FEAT_SIGNS
350 // If 'signcolumn' is set to 'number' and a sign is present
351 // in 'lnum', then display the sign instead of the line
352 // number.
353 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
354 get_sign_display_info(TRUE, wp, wlv);
355 else
356#endif
357 {
358 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100359 // When there are text properties above the line put the line number
360 // below them.
361 if (wlv->row == wlv->startrow + wlv->filler_lines
362#ifdef FEAT_PROP_POPUP
363 + wlv->text_prop_above_count
Bram Moolenaard7657e92022-09-20 18:59:30 +0100364#endif
Bram Moolenaar06618f92022-10-06 19:21:20 +0100365 && (wp->w_skipcol == 0 || wlv->row > wp->w_winrow))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100366 {
367 long num;
368 char *fmt = "%*ld ";
369
370 if (wp->w_p_nu && !wp->w_p_rnu)
371 // 'number' + 'norelativenumber'
372 num = (long)wlv->lnum;
373 else
374 {
375 // 'relativenumber', don't use negative numbers
376 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
377 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
378 {
379 // 'number' + 'relativenumber'
380 num = wlv->lnum;
381 fmt = "%-*ld ";
382 }
383 }
384
385 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100386 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100387 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
388 ++wlv->p_extra)
389 *wlv->p_extra = '-';
390#ifdef FEAT_RIGHTLEFT
391 if (wp->w_p_rl) // reverse line numbers
392 {
393 char_u *p1, *p2;
394 int t;
395
396 // like rl_mirror(), but keep the space at the end
397 p2 = skipwhite(wlv->extra);
398 p2 = skiptowhite(p2) - 1;
399 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
400 {
401 t = *p1;
402 *p1 = *p2;
403 *p2 = t;
404 }
405 }
406#endif
407 wlv->p_extra = wlv->extra;
408 wlv->c_extra = NUL;
409 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100410 }
411 else
412 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100413 wlv->c_extra = ' ';
414 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100415 }
416 wlv->n_extra = number_width(wp) + 1;
417 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
418#ifdef FEAT_SYN_HL
419 // When 'cursorline' is set highlight the line number of
420 // the current line differently.
421 // When 'cursorlineopt' does not have "line" only
422 // highlight the line number itself.
423 // TODO: Can we use CursorLine instead of CursorLineNr
424 // when CursorLineNr isn't set?
425 if (wp->w_p_cul
426 && wlv->lnum == wp->w_cursor.lnum
427 && (wp->w_p_culopt_flags & CULOPT_NBR)
428 && (wlv->row == wlv->startrow + wlv->filler_lines
429 || (wlv->row > wlv->startrow + wlv->filler_lines
430 && (wp->w_p_culopt_flags & CULOPT_LINE))))
431 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
432#endif
433 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
434 && HL_ATTR(HLF_LNA) != 0)
435 // Use LineNrAbove
436 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
437 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
438 && HL_ATTR(HLF_LNB) != 0)
439 // Use LineNrBelow
440 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
441 }
442#ifdef FEAT_SIGNS
443 if (num_attr)
444 wlv->char_attr = num_attr;
445#endif
446 }
447}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100448
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100449#ifdef FEAT_LINEBREAK
450 static void
451handle_breakindent(win_T *wp, winlinevars_T *wlv)
452{
453 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
454 && *get_showbreak_value(wp) != NUL)
455 // draw indent after showbreak value
456 wlv->draw_state = WL_BRI;
457 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
458 // After the showbreak, draw the breakindent
459 wlv->draw_state = WL_BRI - 1;
460
461 // draw 'breakindent': indent wrapped text accordingly
462 if (wlv->draw_state == WL_BRI - 1)
463 {
464 wlv->draw_state = WL_BRI;
465 // if wlv->need_showbreak is set, breakindent also applies
466 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
467# ifdef FEAT_DIFF
468 && wlv->filler_lines == 0
469# endif
470# ifdef FEAT_PROP_POPUP
471 && !wlv->dont_use_showbreak
472# endif
473 )
474 {
475 wlv->char_attr = 0;
476# ifdef FEAT_DIFF
477 if (wlv->diff_hlf != (hlf_T)0)
478 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
479# endif
480 wlv->p_extra = NULL;
481 wlv->c_extra = ' ';
482 wlv->c_final = NUL;
483 wlv->n_extra = get_breakindent_win(wp,
484 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
485 if (wlv->row == wlv->startrow)
486 {
487 wlv->n_extra -= win_col_off2(wp);
488 if (wlv->n_extra < 0)
489 wlv->n_extra = 0;
490 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100491 if (wp->w_skipcol > 0 && wlv->startrow == 0
492 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100493 wlv->need_showbreak = FALSE;
494 // Correct end of highlighted area for 'breakindent',
495 // required when 'linebreak' is also set.
496 if (wlv->tocol == wlv->vcol)
497 wlv->tocol += wlv->n_extra;
498 }
499 }
500}
501#endif
502
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100503#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
504 static void
505handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
506{
507# ifdef FEAT_DIFF
508 if (wlv->filler_todo > 0)
509 {
510 // Draw "deleted" diff line(s).
511 if (char2cells(wp->w_fill_chars.diff) > 1)
512 {
513 wlv->c_extra = '-';
514 wlv->c_final = NUL;
515 }
516 else
517 {
518 wlv->c_extra = wp->w_fill_chars.diff;
519 wlv->c_final = NUL;
520 }
521# ifdef FEAT_RIGHTLEFT
522 if (wp->w_p_rl)
523 wlv->n_extra = wlv->col + 1;
524 else
525# endif
526 wlv->n_extra = wp->w_width - wlv->col;
527 wlv->char_attr = HL_ATTR(HLF_DED);
528 }
529# endif
530
531# ifdef FEAT_LINEBREAK
532 char_u *sbr = get_showbreak_value(wp);
533 if (*sbr != NUL && wlv->need_showbreak)
534 {
535 // Draw 'showbreak' at the start of each broken line.
536 wlv->p_extra = sbr;
537 wlv->c_extra = NUL;
538 wlv->c_final = NUL;
539 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100540 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100541 wlv->need_showbreak = FALSE;
542 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
543 // Correct end of highlighted area for 'showbreak',
544 // required when 'linebreak' is also set.
545 if (wlv->tocol == wlv->vcol)
546 wlv->tocol += wlv->n_extra;
547 // combine 'showbreak' with 'wincolor'
548 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
549# ifdef FEAT_SYN_HL
550 // combine 'showbreak' with 'cursorline'
551 if (wlv->cul_attr != 0)
552 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
553# endif
554 }
555# endif
556}
557#endif
558
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100559#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100560/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100561 * Return the cell size of virtual text after truncation.
562 */
563 static int
564textprop_size_after_trunc(
565 win_T *wp,
566 int flags, // TP_FLAG_ALIGN_*
567 int added,
568 char_u *text,
569 int *n_used_ptr)
570{
571 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
572 ? wp->w_width : added;
573 int len = (int)STRLEN(text);
574 int strsize = 0;
575 int n_used;
576
577 // if the remaining size is to small wrap anyway and use the next line
578 if (space < PROP_TEXT_MIN_CELLS)
579 space += wp->w_width;
580 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
581 {
582 int clen = ptr2cells(text + n_used);
583
584 if (strsize + clen > space)
585 break;
586 strsize += clen;
587 }
588 *n_used_ptr = n_used;
589 return strsize;
590}
591
592/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100593 * Take care of padding, right-align and truncation of virtual text after a
594 * line.
595 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
596 * padding, right-align and truncation. Otherwise only the size is computed.
597 * When "n_attr" is NULL returns the number of screen cells used.
598 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100599 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100600 int
601text_prop_position(
602 win_T *wp,
603 textprop_T *tp,
604 int vcol, // current screen column
605 int *n_extra, // nr of bytes for virtual text
606 char_u **p_extra, // virtual text
607 int *n_attr, // attribute cells, NULL if not used
608 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200609{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100610 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100611 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100612 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
613 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
614 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
615 ? tp->tp_len - 1 : 0;
616 int col_with_padding = vcol + (below ? 0 : padding);
617 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100618 int before = room; // spaces before the text
619 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100620 int n_used = *n_extra;
621 char_u *l = NULL;
622 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100623 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
624 tp->tp_flags, before, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200625
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100626 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100627 {
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100628 int col_off = win_col_off(wp) + win_col_off2(wp);
629 int skip_add = 0;
630
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100631 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100632 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100633 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100634 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100635 }
636 else
637 {
638 // Right-align: fill with before
639 if (right)
640 before -= cells;
641 if (before < 0
642 || !(right || below)
643 || (below
644 ? (col_with_padding == 0 || !wp->w_p_wrap)
645 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100646 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100647 if (right && (wrap || room < PROP_TEXT_MIN_CELLS))
648 {
649 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100650 before = wp->w_width - col_off - strsize + room;
651 if (before < 0)
652 before = 0;
653 else
654 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100655 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100656 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100657 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100658 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100659 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100660 else if (below && before > 0)
661 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100662 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100663 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100664
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100665 // With 'nowrap' add one to show the "extends" character if needed (it
666 // doesn't show if the text just fits).
667 if (!wp->w_p_wrap
668 && n_used < *n_extra
669 && wp->w_lcs_chars.ext != NUL
670 && wp->w_p_list)
671 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100672 if (!wp->w_p_wrap && below && padding > 0)
673 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100674
675 // add 1 for NUL, 2 for when '…' is used
676 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100677 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100678 if (n_attr == NULL || l != NULL)
679 {
680 int off = 0;
681
682 if (n_attr != NULL)
683 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100684 vim_memset(l, ' ', before);
685 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100686 if (padding > 0)
687 {
688 vim_memset(l + off, ' ', padding);
689 off += padding;
690 }
691 vim_strncpy(l + off, *p_extra, n_used);
692 off += n_used;
693 }
694 else
695 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100696 off = before + after + padding + n_used;
697 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100698 }
699 if (n_attr != NULL)
700 {
701 if (n_used < *n_extra && wp->w_p_wrap)
702 {
703 char_u *lp = l + off - 1;
704
705 if (has_mbyte)
706 {
707 // change last character to '…'
708 lp -= (*mb_head_off)(l, lp);
709 STRCPY(lp, "…");
710 n_used = lp - l + 3 - padding;
711 }
712 else
713 // change last character to '>'
714 *lp = '>';
715 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100716 else if (after > 0)
717 {
718 vim_memset(l + off, ' ', after);
719 l[off + after] = NUL;
720 }
721
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100722 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100723 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100724 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100725 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100726 *n_attr -= padding + after;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100727 *n_attr_skip = before + padding + skip_add;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100728 }
729 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100730 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100731
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100732 if (n_attr == NULL)
733 return cells;
734 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200735}
736#endif
737
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100738/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100739 * Call screen_line() using values from "wlv".
740 * Also takes care of putting "<<<" on the first line for 'smoothscroll'.
741 */
742 static void
743wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
744{
745 if (wlv->row == 0 && wp->w_skipcol > 0)
746 {
747 int off = (int)(current_ScreenLine - ScreenLines);
748
749 for (int i = 0; i < 3; ++i)
750 {
751 ScreenLines[off] = '<';
752 if (enc_utf8)
753 ScreenLinesUC[off] = 0;
754 ScreenAttrs[off] = HL_ATTR(HLF_AT);
755 ++off;
756 }
757 }
758
759 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
760 negative_width ? -wp->w_width : wp->w_width,
761 wlv->screen_line_flags);
762}
763
764/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100765 * Called when finished with the line: draw the screen line and handle any
766 * highlighting until the right of the window.
767 */
768 static void
769draw_screen_line(win_T *wp, winlinevars_T *wlv)
770{
771#ifdef FEAT_SYN_HL
772 long v;
773
774 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
775 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100776 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100777 else
778 v = wp->w_leftcol;
779
780 // check if line ends before left margin
781 if (wlv->vcol < v + wlv->col - win_col_off(wp))
782 wlv->vcol = v + wlv->col - win_col_off(wp);
783# ifdef FEAT_CONCEAL
784 // Get rid of the boguscols now, we want to draw until the right
785 // edge for 'cursorcolumn'.
786 wlv->col -= wlv->boguscols;
787 wlv->boguscols = 0;
788# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
789# else
790# define VCOL_HLC (wlv->vcol)
791# endif
792
793 if (wlv->draw_color_col)
794 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
795
796 if (((wp->w_p_cuc
797 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
798 && (int)wp->w_virtcol <
799 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
800 && wlv->lnum != wp->w_cursor.lnum)
801 || wlv->draw_color_col
802 || wlv->win_attr != 0)
803# ifdef FEAT_RIGHTLEFT
804 && !wp->w_p_rl
805# endif
806 )
807 {
808 int rightmost_vcol = 0;
809 int i;
810
811 if (wp->w_p_cuc)
812 rightmost_vcol = wp->w_virtcol;
813 if (wlv->draw_color_col)
814 // determine rightmost colorcolumn to possibly draw
815 for (i = 0; wlv->color_cols[i] >= 0; ++i)
816 if (rightmost_vcol < wlv->color_cols[i])
817 rightmost_vcol = wlv->color_cols[i];
818
819 while (wlv->col < wp->w_width)
820 {
821 ScreenLines[wlv->off] = ' ';
822 if (enc_utf8)
823 ScreenLinesUC[wlv->off] = 0;
824 ScreenCols[wlv->off] = MAXCOL;
825 ++wlv->col;
826 if (wlv->draw_color_col)
827 wlv->draw_color_col = advance_color_col(
828 VCOL_HLC, &wlv->color_cols);
829
830 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
831 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
832 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
833 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
834 else
835 ScreenAttrs[wlv->off++] = wlv->win_attr;
836
837 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
838 break;
839
840 ++wlv->vcol;
841 }
842 }
843#endif
844
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100845 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100846 ++wlv->row;
847 ++wlv->screen_row;
848}
849#undef VCOL_HLC
850
851/*
852 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100853 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100854 */
855 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100856win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100857{
858 wlv->col = 0;
859 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
860
861#ifdef FEAT_RIGHTLEFT
862 if (wp->w_p_rl)
863 {
864 // Rightleft window: process the text in the normal direction, but put
865 // it in current_ScreenLine[] from right to left. Start at the
866 // rightmost column of the window.
867 wlv->col = wp->w_width - 1;
868 wlv->off += wlv->col;
869 wlv->screen_line_flags |= SLF_RIGHTLEFT;
870 }
871#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100872 if (save_extra)
873 {
874 // reset the drawing state for the start of a wrapped line
875 wlv->draw_state = WL_START;
876 wlv->saved_n_extra = wlv->n_extra;
877 wlv->saved_p_extra = wlv->p_extra;
878 wlv->saved_c_extra = wlv->c_extra;
879 wlv->saved_c_final = wlv->c_final;
880#ifdef FEAT_SYN_HL
881 if (!(wlv->cul_screenline
882# ifdef FEAT_DIFF
883 && wlv->diff_hlf == (hlf_T)0
884# endif
885 ))
886 wlv->saved_char_attr = wlv->char_attr;
887 else
888#endif
889 wlv->saved_char_attr = 0;
890 wlv->n_extra = 0;
891 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100892}
893
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200894/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100895 * Called when wlv->draw_state is set to WL_LINE.
896 */
897 static void
898win_line_continue(winlinevars_T *wlv)
899{
900 if (wlv->saved_n_extra > 0)
901 {
902 // Continue item from end of wrapped line.
903 wlv->n_extra = wlv->saved_n_extra;
904 wlv->c_extra = wlv->saved_c_extra;
905 wlv->c_final = wlv->saved_c_final;
906 wlv->p_extra = wlv->saved_p_extra;
907 wlv->char_attr = wlv->saved_char_attr;
908 }
909 else
910 wlv->char_attr = wlv->win_attr;
911}
912
913/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200914 * Display line "lnum" of window 'wp' on the screen.
915 * Start at row "startrow", stop when "endrow" is reached.
916 * wp->w_virtcol needs to be valid.
917 *
918 * Return the number of last row the line occupies.
919 */
920 int
921win_line(
922 win_T *wp,
923 linenr_T lnum,
924 int startrow,
925 int endrow,
926 int nochange UNUSED, // not updating for changed text
927 int number_only) // only update the number column
928{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100929 winlinevars_T wlv; // variables passed between functions
930
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200931 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100932 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200933 char_u *line; // current line
934 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200935
Bram Moolenaar1306b362022-08-06 15:59:06 +0100936#ifdef FEAT_PROP_POPUP
937 char_u *p_extra_free2 = NULL; // another p_extra to be freed
938#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200939 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000940#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000941 int in_linebreak = FALSE; // n_extra set for showing linebreak
942#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200943 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100944 // displaying eol at end-of-line
945 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000946 int lcs_prec_todo = wp->w_lcs_chars.prec;
947 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200948
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100949 int n_attr = 0; // chars with special attr
950 int n_attr_skip = 0; // chars to skip before using extra_attr
951 int saved_attr2 = 0; // char_attr saved for n_attr
952 int n_attr3 = 0; // chars with overruling special attr
953 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200954
955 int n_skip = 0; // nr of chars to skip for 'nowrap'
956
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200957 int fromcol_prev = -2; // start of inverting after cursor
958 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200959 int lnum_in_visual_area = FALSE;
960 pos_T pos;
961 long v;
962
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200963 int attr_pri = FALSE; // char_attr has priority
964 int area_highlighting = FALSE; // Visual or incsearch highlighting
965 // in this line
966 int vi_attr = 0; // attributes for Visual and incsearch
967 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200968 int area_attr = 0; // attributes desired by highlighting
969 int search_attr = 0; // attributes desired by 'hlsearch'
970#ifdef FEAT_SYN_HL
971 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
972 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200973 int prev_syntax_col = -1; // column of prev_syntax_attr
974 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200975 int has_syntax = FALSE; // this buffer has syntax highl.
976 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200977#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100978#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200979 int text_prop_count;
980 int text_prop_next = 0; // next text property to use
981 textprop_T *text_props = NULL;
982 int *text_prop_idxs = NULL;
983 int text_props_active = 0;
984 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +0100985 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200986 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +0100987 int text_prop_attr_comb = 0; // text_prop_attr combined with
988 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100989 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100990 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +0100991 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100992 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +0100993 int saved_search_attr = 0; // search_attr to be used when n_extra
994 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +0100995 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200996#endif
997#ifdef FEAT_SPELL
998 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000999 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001000# define SPWORDLEN 150
1001 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1002 int nextlinecol = 0; // column where nextline[] starts
1003 int nextline_idx = 0; // index in nextline[] where next line
1004 // starts
1005 int spell_attr = 0; // attributes desired by spelling
1006 int word_end = 0; // last byte with same spell_attr
1007 static linenr_T checked_lnum = 0; // line number for "checked_col"
1008 static int checked_col = 0; // column in "checked_lnum" up to which
1009 // there are no spell errors
1010 static int cap_col = -1; // column to check for Cap word
1011 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1012 int cur_checked_col = 0; // checked column for current line
1013#endif
1014 int extra_check = 0; // has extra highlighting
1015 int multi_attr = 0; // attributes desired by multibyte
1016 int mb_l = 1; // multi-byte byte length
1017 int mb_c = 0; // decoded multi-byte character
1018 int mb_utf8 = FALSE; // screen char is UTF-8 char
1019 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001020#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001021 int change_start = MAXCOL; // first col of changed area
1022 int change_end = -1; // last col of changed area
1023#endif
1024 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001025 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001026 int in_multispace = FALSE; // in multiple consecutive spaces
1027 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001028#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
1029 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
1030# define LINE_ATTR
1031 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +01001032 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001033#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001034 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001035 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001036#ifdef FEAT_ARABIC
1037 int prev_c = 0; // previous Arabic character
1038 int prev_c1 = 0; // first composing char for prev_c
1039#endif
1040#if defined(LINE_ATTR)
1041 int did_line_attr = 0;
1042#endif
1043#ifdef FEAT_TERMINAL
1044 int get_term_attr = FALSE;
1045#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001046
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001047#ifdef FEAT_SYN_HL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001048 // margin columns for the screen line, needed for when 'cursorlineopt'
1049 // contains "screenline"
1050 int left_curline_col = 0;
1051 int right_curline_col = 0;
1052#endif
1053
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001054#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1055 int feedback_col = 0;
1056 int feedback_old_attr = -1;
1057#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001058
1059#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1060 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001061 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001062#endif
1063#ifdef FEAT_CONCEAL
1064 int syntax_flags = 0;
1065 int syntax_seqnr = 0;
1066 int prev_syntax_id = 0;
1067 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1068 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001069 int did_wcol = FALSE;
1070 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001071# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001072# define FIX_FOR_BOGUSCOLS \
1073 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001074 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001075 wlv.vcol -= wlv.vcol_off; \
1076 wlv.vcol_off = 0; \
1077 wlv.col -= wlv.boguscols; \
1078 old_boguscols = wlv.boguscols; \
1079 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001080 }
1081#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001082# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001083#endif
1084
1085 if (startrow > endrow) // past the end already!
1086 return startrow;
1087
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001088 CLEAR_FIELD(wlv);
1089
1090 wlv.lnum = lnum;
1091 wlv.startrow = startrow;
1092 wlv.row = startrow;
1093 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001094 wlv.fromcol = -10;
1095 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001096#ifdef FEAT_LINEBREAK
1097 wlv.vcol_sbr = -1;
1098#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001099
1100 if (!number_only)
1101 {
1102 // To speed up the loop below, set extra_check when there is linebreak,
1103 // trailing white space and/or syntax processing to be done.
1104#ifdef FEAT_LINEBREAK
1105 extra_check = wp->w_p_lbr;
1106#endif
1107#ifdef FEAT_SYN_HL
1108 if (syntax_present(wp) && !wp->w_s->b_syn_error
1109# ifdef SYN_TIME_LIMIT
1110 && !wp->w_s->b_syn_slow
1111# endif
1112 )
1113 {
1114 // Prepare for syntax highlighting in this line. When there is an
1115 // error, stop syntax highlighting.
1116 save_did_emsg = did_emsg;
1117 did_emsg = FALSE;
1118 syntax_start(wp, lnum);
1119 if (did_emsg)
1120 wp->w_s->b_syn_error = TRUE;
1121 else
1122 {
1123 did_emsg = save_did_emsg;
1124#ifdef SYN_TIME_LIMIT
1125 if (!wp->w_s->b_syn_slow)
1126#endif
1127 {
1128 has_syntax = TRUE;
1129 extra_check = TRUE;
1130 }
1131 }
1132 }
1133
1134 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001135 wlv.color_cols = wp->w_p_cc_cols;
1136 if (wlv.color_cols != NULL)
1137 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001138#endif
1139
1140#ifdef FEAT_TERMINAL
1141 if (term_show_buffer(wp->w_buffer))
1142 {
1143 extra_check = TRUE;
1144 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001145 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001146 }
1147#endif
1148
1149#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001150 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001151 {
1152 // Prepare for spell checking.
1153 has_spell = TRUE;
1154 extra_check = TRUE;
1155
1156 // Get the start of the next line, so that words that wrap to the
1157 // next line are found too: "et<line-break>al.".
1158 // Trick: skip a few chars for C/shell/Vim comments
1159 nextline[SPWORDLEN] = NUL;
1160 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1161 {
1162 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1163 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1164 }
1165
1166 // When a word wrapped from the previous line the start of the
1167 // current line is valid.
1168 if (lnum == checked_lnum)
1169 cur_checked_col = checked_col;
1170 checked_lnum = 0;
1171
1172 // When there was a sentence end in the previous line may require a
1173 // word starting with capital in this line. In line 1 always check
1174 // the first word.
1175 if (lnum != capcol_lnum)
1176 cap_col = -1;
1177 if (lnum == 1)
1178 cap_col = 0;
1179 capcol_lnum = 0;
1180 }
1181#endif
1182
1183 // handle Visual active in this window
1184 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1185 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001186 pos_T *top, *bot;
1187
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001188 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1189 {
1190 // Visual is after curwin->w_cursor
1191 top = &curwin->w_cursor;
1192 bot = &VIsual;
1193 }
1194 else
1195 {
1196 // Visual is before curwin->w_cursor
1197 top = &VIsual;
1198 bot = &curwin->w_cursor;
1199 }
1200 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1201 if (VIsual_mode == Ctrl_V)
1202 {
1203 // block mode
1204 if (lnum_in_visual_area)
1205 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001206 wlv.fromcol = wp->w_old_cursor_fcol;
1207 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001208 }
1209 }
1210 else
1211 {
1212 // non-block mode
1213 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001214 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001215 else if (lnum == top->lnum)
1216 {
1217 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001218 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001219 else
1220 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001221 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001222 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001223 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001224 }
1225 }
1226 if (VIsual_mode != 'V' && lnum == bot->lnum)
1227 {
1228 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1229 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001230 wlv.fromcol = -10;
1231 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001232 }
1233 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001234 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001235 else
1236 {
1237 pos = *bot;
1238 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001239 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1240 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001241 else
1242 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001243 getvvcol(wp, &pos, NULL, NULL,
1244 (colnr_T *)&wlv.tocol);
1245 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001246 }
1247 }
1248 }
1249 }
1250
1251 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001252 if (!highlight_match && lnum == curwin->w_cursor.lnum
1253 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001254#ifdef FEAT_GUI
1255 && !gui.in_use
1256#endif
1257 )
1258 noinvcur = TRUE;
1259
1260 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001261 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001262 {
1263 area_highlighting = TRUE;
1264 vi_attr = HL_ATTR(HLF_V);
1265#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1266 if ((clip_star.available && !clip_star.owned
1267 && clip_isautosel_star())
1268 || (clip_plus.available && !clip_plus.owned
1269 && clip_isautosel_plus()))
1270 vi_attr = HL_ATTR(HLF_VNC);
1271#endif
1272 }
1273 }
1274
1275 // handle 'incsearch' and ":s///c" highlighting
1276 else if (highlight_match
1277 && wp == curwin
1278 && lnum >= curwin->w_cursor.lnum
1279 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1280 {
1281 if (lnum == curwin->w_cursor.lnum)
1282 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001283 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001284 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001285 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001286 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1287 {
1288 pos.lnum = lnum;
1289 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001290 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001291 }
1292 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001293 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001294 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001295 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1296 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001297 area_highlighting = TRUE;
1298 vi_attr = HL_ATTR(HLF_I);
1299 }
1300 }
1301
1302#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001303 wlv.filler_lines = diff_check(wp, lnum);
1304 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001305 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001306 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001307 {
1308 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001309 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001310 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001311 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001312 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001313 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001314 }
1315 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001316 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001317 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001318 area_highlighting = TRUE;
1319 }
1320 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001321 wlv.filler_lines = wp->w_topfill;
1322 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001323#endif
1324
1325#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001326 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001327 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001328 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001329#endif
1330
1331#ifdef LINE_ATTR
1332# ifdef FEAT_SIGNS
1333 // If this line has a sign with line highlighting set line_attr.
1334 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001335 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001336# endif
1337# if defined(FEAT_QUICKFIX)
1338 // Highlight the current line in the quickfix window.
1339 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1340 line_attr = HL_ATTR(HLF_QFL);
1341# endif
1342 if (line_attr != 0)
1343 area_highlighting = TRUE;
1344#endif
1345
1346 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1347 ptr = line;
1348
1349#ifdef FEAT_SPELL
1350 if (has_spell && !number_only)
1351 {
1352 // For checking first word with a capital skip white space.
1353 if (cap_col == 0)
1354 cap_col = getwhitecols(line);
1355
1356 // To be able to spell-check over line boundaries copy the end of the
1357 // current line into nextline[]. Above the start of the next line was
1358 // copied to nextline[SPWORDLEN].
1359 if (nextline[SPWORDLEN] == NUL)
1360 {
1361 // No next line or it is empty.
1362 nextlinecol = MAXCOL;
1363 nextline_idx = 0;
1364 }
1365 else
1366 {
1367 v = (long)STRLEN(line);
1368 if (v < SPWORDLEN)
1369 {
1370 // Short line, use it completely and append the start of the
1371 // next line.
1372 nextlinecol = 0;
1373 mch_memmove(nextline, line, (size_t)v);
1374 STRMOVE(nextline + v, nextline + SPWORDLEN);
1375 nextline_idx = v + 1;
1376 }
1377 else
1378 {
1379 // Long line, use only the last SPWORDLEN bytes.
1380 nextlinecol = v - SPWORDLEN;
1381 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1382 nextline_idx = SPWORDLEN + 1;
1383 }
1384 }
1385 }
1386#endif
1387
1388 if (wp->w_p_list)
1389 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001390 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001391 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001392 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001393 || wp->w_lcs_chars.trail
1394 || wp->w_lcs_chars.lead
1395 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001396 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001397
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001398 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001399 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001400 {
1401 trailcol = (colnr_T)STRLEN(ptr);
1402 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1403 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001404 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001405 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001406 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001407 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001408 {
1409 leadcol = 0;
1410 while (VIM_ISWHITE(ptr[leadcol]))
1411 ++leadcol;
1412 if (ptr[leadcol] == NUL)
1413 // in a line full of spaces all of them are treated as trailing
1414 leadcol = (colnr_T)0;
1415 else
1416 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001417 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001418 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001419 }
1420
Bram Moolenaard7657e92022-09-20 18:59:30 +01001421 wlv.wcr_attr = get_wcr_attr(wp);
1422 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001423 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001424 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001425 area_highlighting = TRUE;
1426 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001427
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001428#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001429 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001430 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001431#endif
1432
1433 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1434 // first character to be displayed.
1435 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001436 v = startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001437 else
1438 v = wp->w_leftcol;
1439 if (v > 0 && !number_only)
1440 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001441 char_u *prev_ptr = ptr;
1442 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001443 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001444
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001445 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001446 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001447 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001448 charsize = win_lbr_chartabsize(&cts, NULL);
1449 cts.cts_vcol += charsize;
1450 prev_ptr = cts.cts_ptr;
1451 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001452 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001453 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001454 ptr = cts.cts_ptr;
1455 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001456
1457 // When:
1458 // - 'cuc' is set, or
1459 // - 'colorcolumn' is set, or
1460 // - 'virtualedit' is set, or
1461 // - the visual mode is active,
1462 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001463 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001464#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001465 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001466#endif
1467 virtual_active() ||
1468 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001469 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001470
1471 // Handle a character that's not completely on the screen: Put ptr at
1472 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001473 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001474 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001475 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001476 ptr = prev_ptr;
1477 // If the character fits on the screen, don't need to skip it.
1478 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001479 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1480 && wlv.col == 0)
1481 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001482 }
1483
1484 // Adjust for when the inverted text is before the screen,
1485 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001486 if (wlv.tocol <= wlv.vcol)
1487 wlv.fromcol = 0;
1488 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1489 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001490
1491#ifdef FEAT_LINEBREAK
1492 // When w_skipcol is non-zero, first line needs 'showbreak'
1493 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001494 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001495#endif
1496#ifdef FEAT_SPELL
1497 // When spell checking a word we need to figure out the start of the
1498 // word and if it's badly spelled or not.
1499 if (has_spell)
1500 {
1501 int len;
1502 colnr_T linecol = (colnr_T)(ptr - line);
1503 hlf_T spell_hlf = HLF_COUNT;
1504
1505 pos = wp->w_cursor;
1506 wp->w_cursor.lnum = lnum;
1507 wp->w_cursor.col = linecol;
1508 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1509
1510 // spell_move_to() may call ml_get() and make "line" invalid
1511 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1512 ptr = line + linecol;
1513
1514 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1515 {
1516 // no bad word found at line start, don't check until end of a
1517 // word
1518 spell_hlf = HLF_COUNT;
1519 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1520 }
1521 else
1522 {
1523 // bad word found, use attributes until end of word
1524 word_end = wp->w_cursor.col + len + 1;
1525
1526 // Turn index into actual attributes.
1527 if (spell_hlf != HLF_COUNT)
1528 spell_attr = highlight_attr[spell_hlf];
1529 }
1530 wp->w_cursor = pos;
1531
1532# ifdef FEAT_SYN_HL
1533 // Need to restart syntax highlighting for this line.
1534 if (has_syntax)
1535 syntax_start(wp, lnum);
1536# endif
1537 }
1538#endif
1539 }
1540
1541 // Correct highlighting for cursor that can't be disabled.
1542 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001543 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001544 {
1545 if (noinvcur)
1546 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001547 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001548 {
1549 // highlighting starts at cursor, let it start just after the
1550 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001551 fromcol_prev = wlv.fromcol;
1552 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001553 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001554 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001555 // restart highlighting after the cursor
1556 fromcol_prev = wp->w_virtcol;
1557 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001558 if (wlv.fromcol >= wlv.tocol)
1559 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001560 }
1561
1562#ifdef FEAT_SEARCH_EXTRA
1563 if (!number_only)
1564 {
1565 v = (long)(ptr - line);
1566 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1567 &line, &screen_search_hl,
1568 &search_attr);
1569 ptr = line + v; // "line" may have been updated
1570 }
1571#endif
1572
1573#ifdef FEAT_SYN_HL
1574 // Cursor line highlighting for 'cursorline' in the current window.
1575 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1576 {
1577 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001578 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001579 if (!(wp == curwin && VIsual_active)
1580 && wp->w_p_culopt_flags != CULOPT_NBR)
1581 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001582 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001583 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1584
1585 // Only set line_attr here when "screenline" is not present in
1586 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001587 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001588 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001589 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001590# ifdef FEAT_SIGNS
1591 // Combine the 'cursorline' and sign highlighting, depending on
1592 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001593 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001594 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001595 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001596 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001597 else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001598 line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001599 }
1600 else
1601# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001602# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001603 // let the line attribute overrule 'cursorline', otherwise
1604 // it disappears when both have background set;
1605 // 'cursorline' can use underline or bold to make it show
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001606 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001607# else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001608 line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001609# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001610 }
1611 else
1612 {
1613 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001614 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1615 }
1616 area_highlighting = TRUE;
1617 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001618 }
1619#endif
1620
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001621#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001622 {
1623 char_u *prop_start;
1624
1625 text_prop_count = get_text_props(wp->w_buffer, lnum,
1626 &prop_start, FALSE);
1627 if (text_prop_count > 0)
1628 {
1629 // Make a copy of the properties, so that they are properly
1630 // aligned.
1631 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1632 if (text_props != NULL)
1633 mch_memmove(text_props, prop_start,
1634 text_prop_count * sizeof(textprop_T));
1635
1636 // Allocate an array for the indexes.
1637 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001638 if (text_prop_idxs == NULL)
1639 VIM_CLEAR(text_props);
1640
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001641 if (text_props != NULL)
1642 {
1643 area_highlighting = TRUE;
1644 extra_check = TRUE;
1645 for (int i = 0; i < text_prop_count; ++i)
1646 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1647 ++wlv.text_prop_above_count;
1648 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001649 }
1650 }
1651#endif
1652
Bram Moolenaar1306b362022-08-06 15:59:06 +01001653 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001654
1655 // Repeat for the whole displayed line.
1656 for (;;)
1657 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001658 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001659#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001660 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001661#endif
1662#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001663 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001664#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001665
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001666 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001667 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001668 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001669#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001670 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001671 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001672 wlv.cul_attr = 0;
zeertzjq4f33bc22021-08-05 17:57:02 +02001673 line_attr = line_attr_save;
1674 }
1675#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001676 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001677 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001678 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001679 if (cmdwin_type != 0 && wp == curwin)
1680 {
1681 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001682 wlv.n_extra = 1;
1683 wlv.c_extra = cmdwin_type;
1684 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001685 wlv.char_attr =
1686 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001687 }
1688 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001689#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001690 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001691 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001692 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001693 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001694 }
1695#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001696#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001697 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001698 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001699 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001700 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001701 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001702 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001703 }
1704#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001705 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001706 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001707 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001708 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001709 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001710 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001711#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001712 // Check if 'breakindent' applies and show it.
1713 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1714 if (wlv.n_extra == 0)
1715 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001716#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001717#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001718 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001719 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001720 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001721 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001722 }
1723#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001724 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001725 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001726 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001727 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001728 }
1729 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001730
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001731#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001732 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001733 && wlv.vcol >= left_curline_col
1734 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001735 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001736 wlv.cul_attr = HL_ATTR(HLF_CUL);
1737 line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001738 }
1739#endif
1740
1741 // When still displaying '$' of change command, stop at cursor.
1742 // When only displaying the (relative) line number and that's done,
1743 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001744 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001745 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001746 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001747#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001748 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001749#endif
1750 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001751 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001752 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001753 // Pretend we have finished updating the window. Except when
1754 // 'cursorcolumn' is set.
1755#ifdef FEAT_SYN_HL
1756 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001757 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001758 else
1759#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001760 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001761 break;
1762 }
1763
Bram Moolenaar1306b362022-08-06 15:59:06 +01001764 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001765 {
1766 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001767 if (wlv.vcol == wlv.fromcol
1768 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1769 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001770 && (*mb_ptr2cells)(ptr) > 1)
1771 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001772 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001773 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001774 area_attr = vi_attr; // start highlighting
1775 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001776 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001777 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001778 area_attr = 0; // stop highlighting
1779
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001780#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001781 if (text_props != NULL)
1782 {
1783 int pi;
1784 int bcol = (int)(ptr - line);
1785
Bram Moolenaar1306b362022-08-06 15:59:06 +01001786 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001787# ifdef FEAT_LINEBREAK
1788 && !in_linebreak
1789# endif
1790 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001791 --bcol; // still working on the previous char, e.g. Tab
1792
1793 // Check if any active property ends.
1794 for (pi = 0; pi < text_props_active; ++pi)
1795 {
1796 int tpi = text_prop_idxs[pi];
1797
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001798 if (text_props[tpi].tp_col != MAXCOL
1799 && bcol >= text_props[tpi].tp_col - 1
1800 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001801 {
1802 if (pi + 1 < text_props_active)
1803 mch_memmove(text_prop_idxs + pi,
1804 text_prop_idxs + pi + 1,
1805 sizeof(int)
1806 * (text_props_active - (pi + 1)));
1807 --text_props_active;
1808 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001809# ifdef FEAT_LINEBREAK
1810 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001811 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001812 syntax_attr = 0;
1813# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001814 }
1815 }
1816
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001817# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001818 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001819 // not on the next char yet, don't start another prop
1820 --bcol;
1821# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001822 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001823 // With 'nowrap' and not in the first screen line only "below"
1824 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001825 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001826 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001827 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001828 && (wp->w_p_wrap
1829 || wlv.row == startrow
1830 || (text_props[text_prop_next].tp_flags
1831 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001832 || (bcol == 0 &&
1833 (text_props[text_prop_next].tp_flags
1834 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001835 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001836 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001837 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001838 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1839 {
1840 // first display the '$' after the line
1841 text_prop_follows = TRUE;
1842 break;
1843 }
1844 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001845 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001846 + text_props[text_prop_next].tp_len)
1847 text_prop_idxs[text_props_active++] = text_prop_next;
1848 ++text_prop_next;
1849 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001850
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001851 if (wlv.n_extra == 0 || !extra_for_textprop)
1852 {
1853 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001854 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001855 text_prop_flags = 0;
1856 text_prop_type = NULL;
1857 text_prop_id = 0;
1858 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001859 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001860 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001861 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001862 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001863 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001864
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001865 // Sort the properties on priority and/or starting last.
1866 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001867 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001868 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001869 sort_text_props(wp->w_buffer, text_props,
1870 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001871
1872 for (pi = 0; pi < text_props_active; ++pi)
1873 {
1874 int tpi = text_prop_idxs[pi];
1875 proptype_T *pt = text_prop_type_by_id(
1876 wp->w_buffer, text_props[tpi].tp_type);
1877
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001878 if (pt != NULL && (pt->pt_hl_id > 0
1879 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001880 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001881 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001882 if (pt->pt_hl_id > 0)
1883 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001884 text_prop_type = pt;
1885 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001886 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001887 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001888 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001889 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001890 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001891 }
1892 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001893 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001894 && -text_prop_id
1895 <= wp->w_buffer->b_textprop_text.ga_len)
1896 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001897 textprop_T *tp = &text_props[used_tpi];
1898 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001899 ->b_textprop_text.ga_data)[
1900 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001901 int above = (tp->tp_flags
1902 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001903
1904 // reset the ID in the copy to avoid it being used
1905 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001906 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001907
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001908 if (p != NULL)
1909 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001910 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001911 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001912 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001913 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001914 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1915 int padding = tp->tp_col == MAXCOL
1916 && tp->tp_len > 1
1917 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001918
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001919 // Insert virtual text before the current
1920 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001921 wlv.p_extra = p;
1922 wlv.c_extra = NUL;
1923 wlv.c_final = NUL;
1924 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001925 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001926 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001927 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001928 // restore search_attr and area_attr when n_extra
1929 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001930 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001931 saved_area_attr = area_attr;
1932 search_attr = 0;
1933 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001934 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001935 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001936 if (*ptr == NUL)
1937 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001938 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001939#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001940 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001941 {
1942 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001943 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001944 wlv.need_showbreak = FALSE;
1945 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001946 }
1947#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001948 if ((right || above || below || !wrap
1949 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001950 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001951 char_u *prev_p_extra = wlv.p_extra;
1952 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001953
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001954 // Take care of padding, right-align and
1955 // truncation.
1956 // Shared with win_lbr_chartabsize(), must do
1957 // exactly the same.
1958 start_line = text_prop_position(wp, tp,
1959 wlv.col,
1960 &wlv.n_extra, &wlv.p_extra,
1961 &n_attr, &n_attr_skip);
1962 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001963 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001964 // wlv.p_extra was allocated
1965 vim_free(p_extra_free2);
1966 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001967 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001968
Bram Moolenaara4abe512022-09-15 19:44:09 +01001969 if (lcs_eol_one < 0 && wlv.col
1970 + wlv.n_extra - 2 > wp->w_width)
1971 // don't bail out at end of line
1972 lcs_eol_one = 0;
1973
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001974 // When 'wrap' is off then for "below" we need
1975 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001976 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001977 {
1978 draw_screen_line(wp, &wlv);
1979
1980 // When line got too long for screen break
1981 // here.
1982 if (wlv.row == endrow)
1983 {
1984 ++wlv.row;
1985 break;
1986 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001987 win_line_start(wp, &wlv, TRUE);
1988 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001989 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001990 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001991 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001992
1993 // If another text prop follows the condition below at
1994 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001995 // If this is an "above" text prop and 'nowrap' the we
1996 // must wrap anyway.
1997 text_prop_above = above;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001998 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001999 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002000 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002001 else if (text_prop_next < text_prop_count
2002 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002003 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2004 || (!wp->w_p_wrap
2005 && wlv.col == wp->w_width - 1
2006 && (text_props[text_prop_next].tp_flags
2007 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002008 // When at last-but-one character and a text property
2009 // follows after it, we may need to flush the line after
2010 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002011 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002012 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002013 }
2014#endif
2015
Bram Moolenaare38fc862022-08-11 17:24:50 +01002016#ifdef FEAT_SEARCH_EXTRA
2017 if (wlv.n_extra == 0)
2018 {
2019 // Check for start/end of 'hlsearch' and other matches.
2020 // After end, check for start/end of next match.
2021 // When another match, have to check for start again.
2022 v = (long)(ptr - line);
2023 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2024 &screen_search_hl, &has_match_conc,
2025 &match_conc, did_line_attr, lcs_eol_one,
2026 &on_last_col);
2027 ptr = line + v; // "line" may have been changed
2028 prev_ptr = ptr;
2029
2030 // Do not allow a conceal over EOL otherwise EOL will be missed
2031 // and bad things happen.
2032 if (*ptr == NUL)
2033 has_match_conc = 0;
2034 }
2035#endif
2036
2037#ifdef FEAT_DIFF
2038 if (wlv.diff_hlf != (hlf_T)0)
2039 {
2040 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2041 && wlv.n_extra == 0)
2042 wlv.diff_hlf = HLF_TXD; // changed text
2043 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2044 && wlv.n_extra == 0)
2045 wlv.diff_hlf = HLF_CHD; // changed line
2046 line_attr = HL_ATTR(wlv.diff_hlf);
2047 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2048 && wp->w_p_culopt_flags != CULOPT_NBR
2049 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2050 && wlv.vcol <= right_curline_col)))
2051 line_attr = hl_combine_attr(
2052 line_attr, HL_ATTR(HLF_CUL));
2053 }
2054#endif
2055
Bram Moolenaara74fda62019-10-19 17:38:03 +02002056#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002057 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002058 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002059 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002060# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002061 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002062 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002063# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002064 // Get syntax attribute.
2065 if (has_syntax)
2066 {
2067 // Get the syntax attribute for the character. If there
2068 // is an error, disable syntax highlighting.
2069 save_did_emsg = did_emsg;
2070 did_emsg = FALSE;
2071
2072 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002073 if (v == prev_syntax_col)
2074 // at same column again
2075 syntax_attr = prev_syntax_attr;
2076 else
2077 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002078# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002079 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002080# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002081 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002082# ifdef FEAT_SPELL
2083 has_spell ? &can_spell :
2084# endif
2085 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002086 prev_syntax_col = v;
2087 prev_syntax_attr = syntax_attr;
2088 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002089
Bram Moolenaar34390282019-10-16 14:38:26 +02002090 if (did_emsg)
2091 {
2092 wp->w_s->b_syn_error = TRUE;
2093 has_syntax = FALSE;
2094 syntax_attr = 0;
2095 }
2096 else
2097 did_emsg = save_did_emsg;
2098# ifdef SYN_TIME_LIMIT
2099 if (wp->w_s->b_syn_slow)
2100 has_syntax = FALSE;
2101# endif
2102
2103 // Need to get the line again, a multi-line regexp may
2104 // have made it invalid.
2105 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2106 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002107 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002108# ifdef FEAT_CONCEAL
2109 // no concealing past the end of the line, it interferes
2110 // with line highlighting
2111 if (*ptr == NUL)
2112 syntax_flags = 0;
2113 else
2114 syntax_flags = get_syntax_info(&syntax_seqnr);
2115# endif
2116 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002117 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002118# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002119 // Combine text property highlight into syntax highlight.
2120 if (text_prop_type != NULL)
2121 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002122 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002123 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2124 else
2125 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002126 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002127 }
2128# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002129#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002130
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002131 // Decide which of the highlight attributes to use.
2132 attr_pri = TRUE;
2133#ifdef LINE_ATTR
2134 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002135 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002136 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002137 if (!highlight_match)
2138 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002139 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002140# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002141 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002142# endif
2143 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002144 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002145 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002146 wlv.char_attr = hl_combine_attr(line_attr, search_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 Moolenaarc20a4192022-09-21 14:34:28 +01002151 else if (line_attr != 0
2152 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2153 || wlv.vcol < wlv.fromcol
2154 || vcol_prev < fromcol_prev
2155 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002156 {
2157 // Use line_attr when not in the Visual or 'incsearch' area
2158 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002159# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002160 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002161# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002162 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002163# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002164 attr_pri = FALSE;
2165 }
2166#else
2167 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002168 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002169 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002170 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002171#endif
2172 else
2173 {
2174 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002175#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002176 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002177#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002178 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002179#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002180 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002181#ifdef FEAT_PROP_POPUP
2182 // override with text property highlight when "override" is TRUE
2183 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002184 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002185#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002186 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002187
2188 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002189 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002190 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002191 if (wlv.char_attr == 0)
2192 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002193 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002194 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002195 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002196
2197 // Get the next character to put on the screen.
2198
2199 // The "p_extra" points to the extra stuff that is inserted to
2200 // represent special characters (non-printable stuff) and other
2201 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002202 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002203 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2204 // "p_extra[n_extra]".
2205 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002206 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002207 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002208 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002209 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002210 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2211 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002212 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2213 if (enc_utf8 && utf_char2len(c) > 1)
2214 {
2215 mb_utf8 = TRUE;
2216 u8cc[0] = 0;
2217 c = 0xc0;
2218 }
2219 else
2220 mb_utf8 = FALSE;
2221 }
2222 else
2223 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002224 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002225 if (has_mbyte)
2226 {
2227 mb_c = c;
2228 if (enc_utf8)
2229 {
2230 // If the UTF-8 character is more than one byte:
2231 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002232 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002233 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002234 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002235 mb_l = 1;
2236 else if (mb_l > 1)
2237 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002238 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002239 mb_utf8 = TRUE;
2240 c = 0xc0;
2241 }
2242 }
2243 else
2244 {
2245 // if this is a DBCS character, put it in "mb_c"
2246 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002247 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002248 mb_l = 1;
2249 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002250 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002251 }
2252 if (mb_l == 0) // at the NUL at end-of-line
2253 mb_l = 1;
2254
2255 // If a double-width char doesn't fit display a '>' in the
2256 // last column.
2257 if ((
2258# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002259 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002260# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002261 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002262 && (*mb_char2cells)(mb_c) == 2)
2263 {
2264 c = '>';
2265 mb_c = c;
2266 mb_l = 1;
2267 mb_utf8 = FALSE;
2268 multi_attr = HL_ATTR(HLF_AT);
2269#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002270 if (wlv.cul_attr)
2271 multi_attr = hl_combine_attr(
2272 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002273#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002274 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002275
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002276 // put the pointer back to output the double-width
2277 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002278 ++wlv.n_extra;
2279 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002280 }
2281 else
2282 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002283 wlv.n_extra -= mb_l - 1;
2284 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002285 }
2286 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002287 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002288 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002289 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002290#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002291 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002292 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002293 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002294 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002295 if (search_attr == 0)
2296 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002297 if (area_attr == 0 && *ptr != NUL)
2298 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002299 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002300#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002301 }
2302 else
2303 {
2304#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002305 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002306#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002307 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002308
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002309 // Get a character from the line itself.
2310 c = *ptr;
2311#ifdef FEAT_LINEBREAK
2312 c0 = *ptr;
2313#endif
2314 if (has_mbyte)
2315 {
2316 mb_c = c;
2317 if (enc_utf8)
2318 {
2319 // If the UTF-8 character is more than one byte: Decode it
2320 // into "mb_c".
2321 mb_l = utfc_ptr2len(ptr);
2322 mb_utf8 = FALSE;
2323 if (mb_l > 1)
2324 {
2325 mb_c = utfc_ptr2char(ptr, u8cc);
2326 // Overlong encoded ASCII or ASCII with composing char
2327 // is displayed normally, except a NUL.
2328 if (mb_c < 0x80)
2329 {
2330 c = mb_c;
2331#ifdef FEAT_LINEBREAK
2332 c0 = mb_c;
2333#endif
2334 }
2335 mb_utf8 = TRUE;
2336
2337 // At start of the line we can have a composing char.
2338 // Draw it as a space with a composing char.
2339 if (utf_iscomposing(mb_c))
2340 {
2341 int i;
2342
2343 for (i = Screen_mco - 1; i > 0; --i)
2344 u8cc[i] = u8cc[i - 1];
2345 u8cc[0] = mb_c;
2346 mb_c = ' ';
2347 }
2348 }
2349
2350 if ((mb_l == 1 && c >= 0x80)
2351 || (mb_l >= 1 && mb_c == 0)
2352 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2353 {
2354 // Illegal UTF-8 byte: display as <xx>.
2355 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002356 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002357# ifdef FEAT_RIGHTLEFT
2358 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002359 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002360# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002361 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002362 c = *wlv.p_extra;
2363 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002364 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002365 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2366 wlv.c_extra = NUL;
2367 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002368 if (area_attr == 0 && search_attr == 0)
2369 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002370 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002371 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002372 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002373 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002374 }
2375 }
2376 else if (mb_l == 0) // at the NUL at end-of-line
2377 mb_l = 1;
2378#ifdef FEAT_ARABIC
2379 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2380 {
2381 // Do Arabic shaping.
2382 int pc, pc1, nc;
2383 int pcc[MAX_MCO];
2384
2385 // The idea of what is the previous and next
2386 // character depends on 'rightleft'.
2387 if (wp->w_p_rl)
2388 {
2389 pc = prev_c;
2390 pc1 = prev_c1;
2391 nc = utf_ptr2char(ptr + mb_l);
2392 prev_c1 = u8cc[0];
2393 }
2394 else
2395 {
2396 pc = utfc_ptr2char(ptr + mb_l, pcc);
2397 nc = prev_c;
2398 pc1 = pcc[0];
2399 }
2400 prev_c = mb_c;
2401
2402 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2403 }
2404 else
2405 prev_c = mb_c;
2406#endif
2407 }
2408 else // enc_dbcs
2409 {
2410 mb_l = MB_BYTE2LEN(c);
2411 if (mb_l == 0) // at the NUL at end-of-line
2412 mb_l = 1;
2413 else if (mb_l > 1)
2414 {
2415 // We assume a second byte below 32 is illegal.
2416 // Hopefully this is OK for all double-byte encodings!
2417 if (ptr[1] >= 32)
2418 mb_c = (c << 8) + ptr[1];
2419 else
2420 {
2421 if (ptr[1] == NUL)
2422 {
2423 // head byte at end of line
2424 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002425 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002426 }
2427 else
2428 {
2429 // illegal tail byte
2430 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002431 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002432 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002433 wlv.p_extra = wlv.extra;
2434 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002435 wlv.c_extra = NUL;
2436 wlv.c_final = NUL;
2437 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002438 if (area_attr == 0 && search_attr == 0)
2439 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002440 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002441 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002442 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002443 // save current attr
2444 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002445 }
2446 mb_c = c;
2447 }
2448 }
2449 }
2450 // If a double-width char doesn't fit display a '>' in the
2451 // last column; the character is displayed at the start of the
2452 // next line.
2453 if ((
2454# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002455 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002456# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002457 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002458 && (*mb_char2cells)(mb_c) == 2)
2459 {
2460 c = '>';
2461 mb_c = c;
2462 mb_utf8 = FALSE;
2463 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002464 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002465 // Put pointer back so that the character will be
2466 // displayed at the start of the next line.
2467 --ptr;
2468#ifdef FEAT_CONCEAL
2469 did_decrement_ptr = TRUE;
2470#endif
2471 }
2472 else if (*ptr != NUL)
2473 ptr += mb_l - 1;
2474
2475 // If a double-width char doesn't fit at the left side display
2476 // a '<' in the first column. Don't do this for unprintable
2477 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002478 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002479 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002480 wlv.n_extra = 1;
2481 wlv.c_extra = MB_FILLER_CHAR;
2482 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002483 c = ' ';
2484 if (area_attr == 0 && search_attr == 0)
2485 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002486 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002487 extra_attr = hl_combine_attr(
2488 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002489 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002490 }
2491 mb_c = c;
2492 mb_utf8 = FALSE;
2493 mb_l = 1;
2494 }
2495
2496 }
2497 ++ptr;
2498
2499 if (extra_check)
2500 {
2501#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002502 // Check spelling (unless at the end of the line).
2503 // Only do this when there is no syntax highlighting, the
2504 // @Spell cluster is not used or the current syntax item
2505 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002506 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002507 if (has_spell && v >= word_end && v > cur_checked_col)
2508 {
2509 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002510 // do not calculate cap_col at the end of the line or when
2511 // only white space is following
2512 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002513# ifdef FEAT_SYN_HL
2514 !has_syntax ||
2515# endif
2516 can_spell))
2517 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002518 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002519 int len;
2520 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002521
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002522 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002523 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002524
2525 // Use nextline[] if possible, it has the start of the
2526 // next line concatenated.
2527 if ((prev_ptr - line) - nextlinecol >= 0)
2528 p = nextline + (prev_ptr - line) - nextlinecol;
2529 else
2530 p = prev_ptr;
2531 cap_col -= (int)(prev_ptr - line);
2532 len = spell_check(wp, p, &spell_hlf, &cap_col,
2533 nochange);
2534 word_end = v + len;
2535
2536 // In Insert mode only highlight a word that
2537 // doesn't touch the cursor.
2538 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002539 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002540 && wp->w_cursor.lnum == lnum
2541 && wp->w_cursor.col >=
2542 (colnr_T)(prev_ptr - line)
2543 && wp->w_cursor.col < (colnr_T)word_end)
2544 {
2545 spell_hlf = HLF_COUNT;
2546 spell_redraw_lnum = lnum;
2547 }
2548
2549 if (spell_hlf == HLF_COUNT && p != prev_ptr
2550 && (p - nextline) + len > nextline_idx)
2551 {
2552 // Remember that the good word continues at the
2553 // start of the next line.
2554 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002555 checked_col = (int)((p - nextline)
2556 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002557 }
2558
2559 // Turn index into actual attributes.
2560 if (spell_hlf != HLF_COUNT)
2561 spell_attr = highlight_attr[spell_hlf];
2562
2563 if (cap_col > 0)
2564 {
2565 if (p != prev_ptr
2566 && (p - nextline) + cap_col >= nextline_idx)
2567 {
2568 // Remember that the word in the next line
2569 // must start with a capital.
2570 capcol_lnum = lnum + 1;
2571 cap_col = (int)((p - nextline) + cap_col
2572 - nextline_idx);
2573 }
2574 else
2575 // Compute the actual column.
2576 cap_col += (int)(prev_ptr - line);
2577 }
2578 }
2579 }
2580 if (spell_attr != 0)
2581 {
2582 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002583 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2584 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002585 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002586 wlv.char_attr = hl_combine_attr(spell_attr,
2587 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002588 }
2589#endif
2590#ifdef FEAT_LINEBREAK
2591 // Found last space before word: check for line break.
2592 if (wp->w_p_lbr && c0 == c
2593 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2594 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002595 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2596 : 0;
2597 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002598 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002599
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002600 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002601# ifdef FEAT_PROP_POPUP
2602 // do not want virtual text counted here
2603 cts.cts_has_prop_with_text = FALSE;
2604# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002605 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002606 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002607
2608 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002609 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002610 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002611 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002612 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2613 if (wlv.n_extra < 0)
2614 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002615 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002616 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002617 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002618 // line break, but for TABs the highlighting should
2619 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002620 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002621
Bram Moolenaar1306b362022-08-06 15:59:06 +01002622 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002623# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002624 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002625 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002626 wp->w_buffer->b_p_vts_array) - 1;
2627# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002628 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002629 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002630# endif
2631
Bram Moolenaar1306b362022-08-06 15:59:06 +01002632 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2633 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002634# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002635 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002636 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002637# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002638 if (VIM_ISWHITE(c))
2639 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002640# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002641 if (c == TAB)
2642 // See "Tab alignment" below.
2643 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002644# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002645 if (!wp->w_p_list)
2646 c = ' ';
2647 }
2648 }
2649#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002650 in_multispace = c == ' '
2651 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2652 if (!in_multispace)
2653 multispace_pos = 0;
2654
Bram Moolenaareed9d462021-02-15 20:38:25 +01002655 // 'list': Change char 160 to 'nbsp' and space to 'space'
2656 // setting in 'listchars'. But not when the character is
2657 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002658 if (wp->w_p_list
2659 && ((((c == 160 && mb_l == 1)
2660 || (mb_utf8
2661 && ((mb_c == 160 && mb_l == 2)
2662 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002663 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002664 || (c == ' '
2665 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002666 && (wp->w_lcs_chars.space
2667 || (in_multispace
2668 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002669 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002670 && ptr - line <= trailcol)))
2671 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002672 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2673 {
2674 c = wp->w_lcs_chars.multispace[multispace_pos++];
2675 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2676 multispace_pos = 0;
2677 }
2678 else
2679 c = (c == ' ') ? wp->w_lcs_chars.space
2680 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002681 if (area_attr == 0 && search_attr == 0)
2682 {
2683 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002684 extra_attr = hl_combine_attr(wlv.win_attr,
2685 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002686 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002687 }
2688 mb_c = c;
2689 if (enc_utf8 && utf_char2len(c) > 1)
2690 {
2691 mb_utf8 = TRUE;
2692 u8cc[0] = 0;
2693 c = 0xc0;
2694 }
2695 else
2696 mb_utf8 = FALSE;
2697 }
2698
zeertzjq2e7cba32022-06-10 15:30:32 +01002699 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2700 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002701 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002702 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2703 && wp->w_lcs_chars.leadmultispace != NULL)
2704 {
2705 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002706 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2707 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002708 multispace_pos = 0;
2709 }
2710
2711 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2712 c = wp->w_lcs_chars.trail;
2713
2714 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2715 c = wp->w_lcs_chars.lead;
2716
zeertzjq2e7cba32022-06-10 15:30:32 +01002717 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002718 c = wp->w_lcs_chars.space;
2719
2720
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002721 if (!attr_pri)
2722 {
2723 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002724 extra_attr = hl_combine_attr(wlv.win_attr,
2725 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002726 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002727 }
2728 mb_c = c;
2729 if (enc_utf8 && utf_char2len(c) > 1)
2730 {
2731 mb_utf8 = TRUE;
2732 u8cc[0] = 0;
2733 c = 0xc0;
2734 }
2735 else
2736 mb_utf8 = FALSE;
2737 }
2738 }
2739
2740 // Handling of non-printable characters.
2741 if (!vim_isprintc(c))
2742 {
2743 // when getting a character from the file, we may have to
2744 // turn it into something else on the way to putting it
2745 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002746 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002747 {
2748 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002749 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002750#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002751 char_u *sbr = get_showbreak_value(wp);
2752
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002753 // only adjust the tab_len, when at the first column
2754 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002755 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002756 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002757#endif
2758 // tab amount depends on current column
2759#ifdef FEAT_VARTABS
2760 tab_len = tabstop_padding(vcol_adjusted,
2761 wp->w_buffer->b_p_ts,
2762 wp->w_buffer->b_p_vts_array) - 1;
2763#else
2764 tab_len = (int)wp->w_buffer->b_p_ts
2765 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2766#endif
2767
2768#ifdef FEAT_LINEBREAK
2769 if (!wp->w_p_lbr || !wp->w_p_list)
2770#endif
2771 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002772 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002773#ifdef FEAT_LINEBREAK
2774 else
2775 {
2776 char_u *p;
2777 int len;
2778 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002779 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002780
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002781# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002782 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002783 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002784 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002785
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002786 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002787 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002788 && old_boguscols > 0
2789 && wlv.n_extra > tab_len)
2790 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002791# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002792 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002793 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002794 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002795 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002796 if (wp->w_lcs_chars.tab3)
2797 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002798 if (wlv.n_extra > 0)
2799 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002800 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002801 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002802 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002803 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002804 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002805 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002806 vim_memset(p, ' ', len);
2807 p[len] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002808 vim_free(wlv.p_extra_free);
2809 wlv.p_extra_free = p;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002810 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002811 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002812 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002813
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002814 if (*p == NUL)
2815 {
2816 tab_len = i;
2817 break;
2818 }
2819
2820 // if tab3 is given, use it for the last char
2821 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2822 lcs = wp->w_lcs_chars.tab3;
2823 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002824 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002825 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002826 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002827 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002828# ifdef FEAT_CONCEAL
2829 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2830 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002831 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002832 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002833# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002834 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002835 }
2836#endif
2837#ifdef FEAT_CONCEAL
2838 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002839 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002840
2841 // Tab alignment should be identical regardless of
2842 // 'conceallevel' value. So tab compensates of all
2843 // previous concealed characters, and thus resets
2844 // vcol_off and boguscols accumulated so far in the
2845 // line. Note that the tab can be longer than
2846 // 'tabstop' when there are concealed characters.
2847 FIX_FOR_BOGUSCOLS;
2848
2849 // Make sure, the highlighting for the tab char will be
2850 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002851 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002852 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002853 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002854 tab_len += vc_saved;
2855 }
2856#endif
2857 mb_utf8 = FALSE; // don't draw as UTF-8
2858 if (wp->w_p_list)
2859 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002860 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002861 ? wp->w_lcs_chars.tab3
2862 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002863#ifdef FEAT_LINEBREAK
2864 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002865 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002866 else
2867#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002868 wlv.c_extra = wp->w_lcs_chars.tab2;
2869 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002870 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002871 extra_attr = hl_combine_attr(wlv.win_attr,
2872 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002873 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002874 mb_c = c;
2875 if (enc_utf8 && utf_char2len(c) > 1)
2876 {
2877 mb_utf8 = TRUE;
2878 u8cc[0] = 0;
2879 c = 0xc0;
2880 }
2881 }
2882 else
2883 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002884 wlv.c_final = NUL;
2885 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002886 c = ' ';
2887 }
2888 }
2889 else if (c == NUL
2890 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002891 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
2892 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002893 && VIsual_mode != Ctrl_V
2894 && (
2895# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002896 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002897# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002898 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002899 && !(noinvcur
2900 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002901 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002902 && lcs_eol_one > 0)
2903 {
2904 // Display a '$' after the line or highlight an extra
2905 // character if the line break is included.
2906#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2907 // For a diff line the highlighting continues after the
2908 // "$".
2909 if (
2910# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002911 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002912# ifdef LINE_ATTR
2913 &&
2914# endif
2915# endif
2916# ifdef LINE_ATTR
2917 line_attr == 0
2918# endif
2919 )
2920#endif
2921 {
2922 // In virtualedit, visual selections may extend
2923 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002924 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002925 && wlv.tocol != MAXCOL
2926 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002927 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002928 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002929 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002930 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2931 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002932 else
2933 c = ' ';
2934 lcs_eol_one = -1;
2935 --ptr; // put it back at the NUL
2936 if (!attr_pri)
2937 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002938 extra_attr = hl_combine_attr(wlv.win_attr,
2939 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002940 n_attr = 1;
2941 }
2942 mb_c = c;
2943 if (enc_utf8 && utf_char2len(c) > 1)
2944 {
2945 mb_utf8 = TRUE;
2946 u8cc[0] = 0;
2947 c = 0xc0;
2948 }
2949 else
2950 mb_utf8 = FALSE; // don't draw as UTF-8
2951 }
2952 else if (c != NUL)
2953 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002954 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2955 if (wlv.n_extra == 0)
2956 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002957#ifdef FEAT_RIGHTLEFT
2958 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002959 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002960#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002961 wlv.c_extra = NUL;
2962 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002963#ifdef FEAT_LINEBREAK
2964 if (wp->w_p_lbr)
2965 {
2966 char_u *p;
2967
Bram Moolenaar1306b362022-08-06 15:59:06 +01002968 c = *wlv.p_extra;
2969 p = alloc(wlv.n_extra + 1);
2970 vim_memset(p, ' ', wlv.n_extra);
2971 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2972 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002973 vim_free(wlv.p_extra_free);
2974 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002975 }
2976 else
2977#endif
2978 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002979 wlv.n_extra = byte2cells(c) - 1;
2980 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002981 }
2982 if (!attr_pri)
2983 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002984 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002985 extra_attr = hl_combine_attr(wlv.win_attr,
2986 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002987 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002988 }
2989 mb_utf8 = FALSE; // don't draw as UTF-8
2990 }
2991 else if (VIsual_active
2992 && (VIsual_mode == Ctrl_V
2993 || VIsual_mode == 'v')
2994 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002995 && wlv.tocol != MAXCOL
2996 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002997 && (
2998#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002999 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003000#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003001 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003002 {
3003 c = ' ';
3004 --ptr; // put it back at the NUL
3005 }
3006#if defined(LINE_ATTR)
3007 else if ((
3008# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003009 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003010# endif
3011# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003012 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003013# endif
3014 line_attr != 0
3015 ) && (
3016# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003017 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003018# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003019 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003020# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003021 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003022# endif
3023 < wp->w_width)))
3024 {
3025 // Highlight until the right side of the window
3026 c = ' ';
3027 --ptr; // put it back at the NUL
3028
3029 // Remember we do the char for line highlighting.
3030 ++did_line_attr;
3031
3032 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01003033 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003034 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003035 || (wp->w_p_list &&
3036 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003037 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003038# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003039 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003040 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003041 wlv.diff_hlf = HLF_CHD;
3042 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003043 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003044 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003045 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3046 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003047 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003048 || (wlv.vcol >= left_curline_col
3049 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003050 wlv.char_attr = hl_combine_attr(
3051 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003052 }
3053 }
3054# endif
3055# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003056 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003057 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003058 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003059 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3060 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003061 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003062 if (!wlv.cul_screenline
3063 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003064 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003065 wlv.char_attr = hl_combine_attr(
3066 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003067 }
3068 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003069 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3070 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003071 }
3072# endif
3073 }
3074#endif
3075 }
3076
3077#ifdef FEAT_CONCEAL
3078 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003079 && (wp != curwin || lnum != wp->w_cursor.lnum
3080 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003081 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3082 && !(lnum_in_visual_area
3083 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3084 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003085 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003086 if (((prev_syntax_id != syntax_seqnr
3087 && (syntax_flags & HL_CONCEAL) != 0)
3088 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003089 && (syn_get_sub_char() != NUL
3090 || (has_match_conc && match_conc)
3091 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003092 && wp->w_p_cole != 3)
3093 {
3094 // First time at this concealed item: display one
3095 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003096 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003097 c = match_conc;
3098 else if (syn_get_sub_char() != NUL)
3099 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003100 else if (wp->w_lcs_chars.conceal != NUL)
3101 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003102 else
3103 c = ' ';
3104
3105 prev_syntax_id = syntax_seqnr;
3106
Bram Moolenaar1306b362022-08-06 15:59:06 +01003107 if (wlv.n_extra > 0)
3108 wlv.vcol_off += wlv.n_extra;
3109 wlv.vcol += wlv.n_extra;
3110 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003111 {
3112# ifdef FEAT_RIGHTLEFT
3113 if (wp->w_p_rl)
3114 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003115 wlv.col -= wlv.n_extra;
3116 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003117 }
3118 else
3119# endif
3120 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003121 wlv.boguscols += wlv.n_extra;
3122 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003123 }
3124 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003125 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003126 n_attr = 0;
3127 }
3128 else if (n_skip == 0)
3129 {
3130 is_concealing = TRUE;
3131 n_skip = 1;
3132 }
3133 mb_c = c;
3134 if (enc_utf8 && utf_char2len(c) > 1)
3135 {
3136 mb_utf8 = TRUE;
3137 u8cc[0] = 0;
3138 c = 0xc0;
3139 }
3140 else
3141 mb_utf8 = FALSE; // don't draw as UTF-8
3142 }
3143 else
3144 {
3145 prev_syntax_id = 0;
3146 is_concealing = FALSE;
3147 }
3148
3149 if (n_skip > 0 && did_decrement_ptr)
3150 // not showing the '>', put pointer back to avoid getting stuck
3151 ++ptr;
3152
3153#endif // FEAT_CONCEAL
3154 }
3155
3156#ifdef FEAT_CONCEAL
3157 // In the cursor line and we may be concealing characters: correct
3158 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003159 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003160 && wp == curwin && lnum == wp->w_cursor.lnum
3161 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003162 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003163 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003164# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003165 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003166 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003167 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003168# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003169 wp->w_wcol = wlv.col - wlv.boguscols;
3170 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003171 did_wcol = TRUE;
3172 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003173# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003174 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003175# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003176 }
3177#endif
3178
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003179 // Use "extra_attr", but don't override visual selection highlighting,
3180 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003181 // Don't use "extra_attr" until n_attr_skip is zero.
3182 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003183 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003184 && (!attr_pri
3185#ifdef FEAT_PROP_POPUP
3186 || (text_prop_flags & PT_FLAG_OVERRIDE)
3187#endif
3188 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003189 {
3190#ifdef LINE_ATTR
3191 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003192 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003193 else
3194#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003195 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003196 }
3197
3198#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3199 // XIM don't send preedit_start and preedit_end, but they send
3200 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3201 // im_is_preediting() here.
3202 if (p_imst == IM_ON_THE_SPOT
3203 && xic != NULL
3204 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003205 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003206 && !p_imdisable
3207 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003208 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003209 {
3210 colnr_T tcol;
3211
3212 if (preedit_end_col == MAXCOL)
3213 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3214 else
3215 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003216 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003217 {
3218 if (feedback_old_attr < 0)
3219 {
3220 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003221 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003222 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003223 wlv.char_attr = im_get_feedback_attr(feedback_col);
3224 if (wlv.char_attr < 0)
3225 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003226 feedback_col++;
3227 }
3228 else if (feedback_old_attr >= 0)
3229 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003230 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003231 feedback_old_attr = -1;
3232 feedback_col = 0;
3233 }
3234 }
3235#endif
3236 // Handle the case where we are in column 0 but not on the first
3237 // character of the line and the user wants us to show us a
3238 // special character (via 'listchars' option "precedes:<char>".
3239 if (lcs_prec_todo != NUL
3240 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003241 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3242 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003243#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003244 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003245#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003246 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003247 && c != NUL)
3248 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003249 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003250 lcs_prec_todo = NUL;
3251 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3252 {
3253 // Double-width character being overwritten by the "precedes"
3254 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003255 wlv.c_extra = MB_FILLER_CHAR;
3256 wlv.c_final = NUL;
3257 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003258 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003259 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003260 }
3261 mb_c = c;
3262 if (enc_utf8 && utf_char2len(c) > 1)
3263 {
3264 mb_utf8 = TRUE;
3265 u8cc[0] = 0;
3266 c = 0xc0;
3267 }
3268 else
3269 mb_utf8 = FALSE; // don't draw as UTF-8
3270 if (!attr_pri)
3271 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003272 saved_attr3 = wlv.char_attr; // save current attr
3273 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003274 n_attr3 = 1;
3275 }
3276 }
3277
3278 // At end of the text line or just after the last character.
3279 if ((c == NUL
3280#if defined(LINE_ATTR)
3281 || did_line_attr == 1
3282#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003283 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003284 {
3285#ifdef FEAT_SEARCH_EXTRA
3286 // flag to indicate whether prevcol equals startcol of search_hl or
3287 // one of the matches
3288 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3289 (long)(ptr - line) - (c == NUL));
3290#endif
3291 // Invert at least one char, used for Visual and empty line or
3292 // highlight match at end of line. If it's beyond the last
3293 // char on the screen, just overwrite that one (tricky!) Not
3294 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003295 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003296 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003297 && (VIsual_mode != Ctrl_V
3298 || lnum == VIsual.lnum
3299 || lnum == curwin->w_cursor.lnum)
3300 && c == NUL)
3301#ifdef FEAT_SEARCH_EXTRA
3302 // highlight 'hlsearch' match at end of line
3303 || (prevcol_hl_flag
3304# ifdef FEAT_SYN_HL
3305 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3306 && !(wp == curwin && VIsual_active))
3307# endif
3308# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003309 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003310# endif
3311# if defined(LINE_ATTR)
3312 && did_line_attr <= 1
3313# endif
3314 )
3315#endif
3316 ))
3317 {
3318 int n = 0;
3319
3320#ifdef FEAT_RIGHTLEFT
3321 if (wp->w_p_rl)
3322 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003323 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003324 n = 1;
3325 }
3326 else
3327#endif
3328 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003329 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003330 n = -1;
3331 }
3332 if (n != 0)
3333 {
3334 // At the window boundary, highlight the last character
3335 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003336 wlv.off += n;
3337 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003338 }
3339 else
3340 {
3341 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003342 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003343 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003344 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003345 }
3346#ifdef FEAT_SEARCH_EXTRA
3347 if (area_attr == 0)
3348 {
3349 // Use attributes from match with highest priority among
3350 // 'search_hl' and the match list.
3351 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003352 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003353 }
3354#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003355 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003356 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003357#ifdef FEAT_RIGHTLEFT
3358 if (wp->w_p_rl)
3359 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003360 --wlv.col;
3361 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003362 }
3363 else
3364#endif
3365 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003366 ++wlv.col;
3367 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003368 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003369 ++wlv.vcol;
3370 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003371 }
3372 }
3373
3374 // At end of the text line.
3375 if (c == NUL)
3376 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003377 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003378
3379 // Update w_cline_height and w_cline_folded if the cursor line was
3380 // updated (saves a call to plines() later).
3381 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3382 {
3383 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003384 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003385#ifdef FEAT_FOLDING
3386 curwin->w_cline_folded = FALSE;
3387#endif
3388 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3389 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003390 break;
3391 }
3392
3393 // Show "extends" character from 'listchars' if beyond the line end and
3394 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003395 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003396 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003397 && wp->w_p_list
3398 && !wp->w_p_wrap
3399#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003400 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003401#endif
3402 && (
3403#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003404 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003405#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003406 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003407 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003408 || lcs_eol_one > 0
3409 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003410 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003411 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003412 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003413 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003414 mb_c = c;
3415 if (enc_utf8 && utf_char2len(c) > 1)
3416 {
3417 mb_utf8 = TRUE;
3418 u8cc[0] = 0;
3419 c = 0xc0;
3420 }
3421 else
3422 mb_utf8 = FALSE;
3423 }
3424
3425#ifdef FEAT_SYN_HL
3426 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003427 if (wlv.draw_color_col)
3428 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003429
3430 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3431 // highlight the cursor position itself.
3432 // Also highlight the 'colorcolumn' if it is different than
3433 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003434 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3435 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003436 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003437 if (((wlv.draw_state == WL_LINE
3438 || wlv.draw_state == WL_BRI
3439 || wlv.draw_state == WL_SBR)
3440 && !lnum_in_visual_area
3441 && search_attr == 0
3442 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003443# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003444 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003445# endif
3446 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003447 {
3448 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3449 && lnum != wp->w_cursor.lnum)
3450 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003451 vcol_save_attr = wlv.char_attr;
3452 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3453 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003454 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003455 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003456 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003457 vcol_save_attr = wlv.char_attr;
3458 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003459 }
3460 }
3461#endif
3462
3463 // Store character to be displayed.
3464 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003465 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003466 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003467 {
3468 // Store the character.
3469#if defined(FEAT_RIGHTLEFT)
3470 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3471 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003472 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003473 --wlv.off;
3474 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003475 }
3476#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003477 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003478 if (enc_dbcs == DBCS_JPNU)
3479 {
3480 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003481 ScreenLines[wlv.off] = 0x8e;
3482 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003483 }
3484 else if (enc_utf8)
3485 {
3486 if (mb_utf8)
3487 {
3488 int i;
3489
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003490 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003491 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003492 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003493 for (i = 0; i < Screen_mco; ++i)
3494 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003495 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003496 if (u8cc[i] == 0)
3497 break;
3498 }
3499 }
3500 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003501 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003502 }
3503 if (multi_attr)
3504 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003505 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003506 multi_attr = 0;
3507 }
3508 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003509 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003510
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003511 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003512
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003513 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3514 {
3515 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003516 ++wlv.off;
3517 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003518 if (enc_utf8)
3519 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003520 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003521 else
3522 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003523 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003524 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003525#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003526 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003527#endif
3528 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003529 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003530 // When "wlv.tocol" is halfway a character, set it to the end
3531 // of the character, otherwise highlighting won't stop.
3532 if (wlv.tocol == wlv.vcol)
3533 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003534
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003535 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003536
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003537#ifdef FEAT_RIGHTLEFT
3538 if (wp->w_p_rl)
3539 {
3540 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003541 --wlv.off;
3542 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003543 }
3544#endif
3545 }
3546#ifdef FEAT_RIGHTLEFT
3547 if (wp->w_p_rl)
3548 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003549 --wlv.off;
3550 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003551 }
3552 else
3553#endif
3554 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003555 ++wlv.off;
3556 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003557 }
3558 }
3559#ifdef FEAT_CONCEAL
3560 else if (wp->w_p_cole > 0 && is_concealing)
3561 {
3562 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003563 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003564 if (wlv.n_extra > 0)
3565 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003566 if (wp->w_p_wrap)
3567 {
3568 // Special voodoo required if 'wrap' is on.
3569 //
3570 // Advance the column indicator to force the line
3571 // drawing to wrap early. This will make the line
3572 // take up the same screen space when parts are concealed,
3573 // so that cursor line computations aren't messed up.
3574 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003575 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003576 // trailing junk to be written out of the screen line
3577 // we are building, 'boguscols' keeps track of the number
3578 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003579 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003580 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003581 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003582# ifdef FEAT_RIGHTLEFT
3583 if (wp->w_p_rl)
3584 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003585 wlv.col -= wlv.n_extra;
3586 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003587 }
3588 else
3589# endif
3590 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003591 wlv.col += wlv.n_extra;
3592 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003593 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003594 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003595 n_attr = 0;
3596 }
3597
3598
3599 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3600 {
3601 // Need to fill two screen columns.
3602# ifdef FEAT_RIGHTLEFT
3603 if (wp->w_p_rl)
3604 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003605 --wlv.boguscols;
3606 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003607 }
3608 else
3609# endif
3610 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003611 ++wlv.boguscols;
3612 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003613 }
3614 }
3615
3616# ifdef FEAT_RIGHTLEFT
3617 if (wp->w_p_rl)
3618 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003619 --wlv.boguscols;
3620 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003621 }
3622 else
3623# endif
3624 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003625 ++wlv.boguscols;
3626 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003627 }
3628 }
3629 else
3630 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003631 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003632 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003633 wlv.vcol += wlv.n_extra;
3634 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003635 n_attr = 0;
3636 }
3637 }
3638
3639 }
3640#endif // FEAT_CONCEAL
3641 else
3642 --n_skip;
3643
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003644 // Only advance the "wlv.vcol" when after the 'number' or
3645 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003646 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003647#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003648 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003649#endif
3650 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003651 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003652
3653#ifdef FEAT_SYN_HL
3654 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003655 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003656#endif
3657
3658 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003659 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3660 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003661
3662 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003663 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003664 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003665 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003666 if (n_attr_skip > 0)
3667 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003668
3669 // At end of screen line and there is more to come: Display the line
3670 // so far. If there is no more to display it is caught above.
3671 if ((
3672#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003673 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003674#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003675 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003676 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003677 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003678#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003679 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003680#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003681#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003682 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003683#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003684 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003685 && wlv.p_extra != at_end_str)
3686 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3687 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003688 )
3689 {
3690#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003691 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003692 wlv_screen_line(wp, &wlv, FALSE);
3693 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003694 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003695#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003696 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003697#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003698 ++wlv.row;
3699 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003700
3701 // When not wrapping and finished diff lines, or when displayed
3702 // '$' and highlighting until last column, break here.
3703 if ((!wp->w_p_wrap
3704#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003705 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003706#endif
3707#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003708 && !text_prop_above && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003709#endif
3710 ) || lcs_eol_one == -1)
3711 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003712#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003713 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003714 {
3715 // do not output more of the line, only the "below" prop
3716 ptr += STRLEN(ptr);
3717# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003718 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003719# endif
3720 }
3721#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003722
3723 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003724 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003725#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003726 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003727#endif
3728 )
3729 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003730 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3731 draw_vsep_win(wp, wlv.row);
3732 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003733 }
3734
3735 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003736 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003737 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003738 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003739 break;
3740 }
3741
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003742 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003743#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003744 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003745#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003746#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003747 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003748#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003749 && wp->w_width == Columns)
3750 {
3751 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003752 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003753
3754 // Special trick to make copy/paste of wrapped lines work with
3755 // xterm/screen: write an extra character beyond the end of
3756 // the line. This will work with all terminal types
3757 // (regardless of the xn,am settings).
3758 // Only do this on a fast tty.
3759 // Only do this if the cursor is on the current line
3760 // (something has been written in it).
3761 // Don't do this for the GUI.
3762 // Don't do this for double-width characters.
3763 // Don't do this for a window not at the right screen border.
3764 if (p_tf
3765#ifdef FEAT_GUI
3766 && !gui.in_use
3767#endif
3768 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003769 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3770 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003771 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003772 || (*mb_off2cells)(
3773 LineOffset[wlv.screen_row - 1]
3774 + (int)Columns - 2,
3775 LineOffset[wlv.screen_row]
3776 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003777 {
3778 // First make sure we are at the end of the screen line,
3779 // then output the same character again to let the
3780 // terminal know about the wrap. If the terminal doesn't
3781 // auto-wrap, we overwrite the character.
3782 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003783 screen_char(LineOffset[wlv.screen_row - 1]
3784 + (unsigned)Columns - 1,
3785 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003786
3787 // When there is a multi-byte character, just output a
3788 // space to keep it simple.
3789 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003790 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003791 out_char(' ');
3792 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003793 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003794 + (Columns - 1)]);
3795 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003796 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003797 screen_start(); // don't know where cursor is now
3798 }
3799 }
3800
Bram Moolenaar1306b362022-08-06 15:59:06 +01003801 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003802
Bram Moolenaareed9d462021-02-15 20:38:25 +01003803 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003804#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003805 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003806# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003807 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003808# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003809 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003810 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003811#endif
3812#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003813 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003814 // When the filler lines are actually below the last line of the
3815 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003816 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003817 break;
3818#endif
3819 }
3820
3821 } // for every character in the line
3822
3823#ifdef FEAT_SPELL
3824 // After an empty line check first word for capital.
3825 if (*skipwhite(line) == NUL)
3826 {
3827 capcol_lnum = lnum + 1;
3828 cap_col = 0;
3829 }
3830#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003831#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003832 vim_free(text_props);
3833 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003834 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003835#endif
3836
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003837 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003838 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003839}