blob: f738e76b4e6539094ca334f1072d5623be986e39 [file] [log] [blame]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * drawline.c: Functions for drawing window lines on the screen.
Bram Moolenaare89aeed2022-08-22 13:00:16 +010012 * This is the middle level, drawscreen.c is the higher level and screen.c the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020013 * lower level.
14 */
15
16#include "vim.h"
17
18#ifdef FEAT_SYN_HL
19/*
20 * Advance **color_cols and return TRUE when there are columns to draw.
21 */
22 static int
23advance_color_col(int vcol, int **color_cols)
24{
25 while (**color_cols >= 0 && vcol > **color_cols)
26 ++*color_cols;
27 return (**color_cols >= 0);
28}
29#endif
30
31#ifdef FEAT_SYN_HL
32/*
33 * Used when 'cursorlineopt' contains "screenline": compute the margins between
34 * which the highlighting is used.
35 */
36 static void
37margin_columns_win(win_T *wp, int *left_col, int *right_col)
38{
39 // cache previous calculations depending on w_virtcol
40 static int saved_w_virtcol;
41 static win_T *prev_wp;
42 static int prev_left_col;
43 static int prev_right_col;
44 static int prev_col_off;
45
46 int cur_col_off = win_col_off(wp);
47 int width1;
48 int width2;
49
50 if (saved_w_virtcol == wp->w_virtcol
51 && prev_wp == wp && prev_col_off == cur_col_off)
52 {
53 *right_col = prev_right_col;
54 *left_col = prev_left_col;
55 return;
56 }
57
58 width1 = wp->w_width - cur_col_off;
59 width2 = width1 + win_col_off2(wp);
60
61 *left_col = 0;
62 *right_col = width1;
63
64 if (wp->w_virtcol >= (colnr_T)width1)
65 *right_col = width1 + ((wp->w_virtcol - width1) / width2 + 1) * width2;
66 if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0)
67 *left_col = (wp->w_virtcol - width1) / width2 * width2 + width1;
68
69 // cache values
70 prev_left_col = *left_col;
71 prev_right_col = *right_col;
72 prev_wp = wp;
73 saved_w_virtcol = wp->w_virtcol;
74 prev_col_off = cur_col_off;
75}
76#endif
77
Bram Moolenaar1306b362022-08-06 15:59:06 +010078// structure with variables passed between win_line() and other functions
79typedef struct {
80 int draw_state; // what to draw next
81
82 linenr_T lnum; // line number to be drawn
83
84 int startrow; // first row in the window to be drawn
85 int row; // row in the window, excl w_winrow
86 int screen_row; // row on the screen, incl w_winrow
87
88 long vcol; // virtual column, before wrapping
89 int col; // visual column on screen, after wrapping
90#ifdef FEAT_CONCEAL
91 int boguscols; // nonexistent columns added to "col" to force
92 // wrapping
93 int vcol_off; // offset for concealed characters
94#endif
95#ifdef FEAT_SYN_HL
96 int draw_color_col; // highlight colorcolumn
97 int *color_cols; // pointer to according columns array
98#endif
99 int eol_hl_off; // 1 if highlighted char after EOL
100
101 unsigned off; // offset in ScreenLines/ScreenAttrs
102
103 int win_attr; // background for the whole window, except
104 // margins and "~" lines.
Bram Moolenaard7657e92022-09-20 18:59:30 +0100105 int wcr_attr; // attributes from 'wincolor'
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100106#ifdef FEAT_SYN_HL
107 int cul_attr; // set when 'cursorline' active
108#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100109
110 int screen_line_flags; // flags for screen_line()
111
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100112 int fromcol; // start of inverting
113 int tocol; // end of inverting
114
115#ifdef FEAT_LINEBREAK
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100116 long vcol_sbr; // virtual column after showbreak
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100117 int need_showbreak; // overlong line, skipping first x chars
118 int dont_use_showbreak; // do not use 'showbreak'
119#endif
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100120#ifdef FEAT_PROP_POPUP
121 int text_prop_above_count;
122#endif
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100123
Bram Moolenaar1306b362022-08-06 15:59:06 +0100124 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
125 int cul_screenline;
126
127 int char_attr; // attributes for the next character
128
129 int n_extra; // number of extra bytes
130 char_u *p_extra; // string of extra chars, plus NUL, only used
131 // when c_extra and c_final are NUL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100132 char_u *p_extra_free; // p_extra buffer that needs to be freed
Bram Moolenaar1306b362022-08-06 15:59:06 +0100133 int c_extra; // extra chars, all the same
134 int c_final; // final char, mandatory if set
135
136 // saved "extra" items for when draw_state becomes WL_LINE (again)
137 int saved_n_extra;
138 char_u *saved_p_extra;
139 int saved_c_extra;
140 int saved_c_final;
141 int saved_char_attr;
142
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100143 char_u extra[NUMBUFLEN + MB_MAXBYTES];
144 // "%ld " and 'fdc' must fit in here, as well
145 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100146
Bram Moolenaar1306b362022-08-06 15:59:06 +0100147#ifdef FEAT_DIFF
148 hlf_T diff_hlf; // type of diff highlighting
149#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100150 int filler_lines; // nr of filler lines to be drawn
151 int filler_todo; // nr of filler lines still to do + 1
152#ifdef FEAT_SIGNS
153 sign_attrs_T sattr;
154#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100155} winlinevars_T;
156
157// draw_state values for items that are drawn in sequence:
158#define WL_START 0 // nothing done yet, must be zero
Martin Tournoij7904fa42022-10-04 16:28:45 +0100159#define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar1306b362022-08-06 15:59:06 +0100160#ifdef FEAT_FOLDING
161# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
162#else
163# define WL_FOLD WL_CMDLINE
164#endif
165#ifdef FEAT_SIGNS
166# define WL_SIGN (WL_FOLD + 1) // column for signs
167#else
168# define WL_SIGN WL_FOLD // column for signs
169#endif
170#define WL_NR (WL_SIGN + 1) // line number
171#ifdef FEAT_LINEBREAK
172# define WL_BRI (WL_NR + 1) // 'breakindent'
173#else
174# define WL_BRI WL_NR
175#endif
176#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
177# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
178#else
179# define WL_SBR WL_BRI
180#endif
181#define WL_LINE (WL_SBR + 1) // text in the line
182
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100183#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200184/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000185 * Return TRUE if CursorLineSign highlight is to be used.
186 */
187 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100188use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000189{
190 return wp->w_p_cul
191 && lnum == wp->w_cursor.lnum
192 && (wp->w_p_culopt_flags & CULOPT_NBR);
193}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100194#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000195
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100196
197#ifdef FEAT_FOLDING
198/*
199 * Setup for drawing the 'foldcolumn', if there is one.
200 */
201 static void
202handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
203{
204 int fdc = compute_foldcolumn(wp, 0);
205
206 if (fdc <= 0)
207 return;
208
209 // Allocate a buffer, "wlv->extra[]" may already be in use.
210 vim_free(wlv->p_extra_free);
211 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
212 if (wlv->p_extra_free != NULL)
213 {
214 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
215 wp, FALSE, wlv->lnum);
216 wlv->p_extra_free[wlv->n_extra] = NUL;
217 wlv->p_extra = wlv->p_extra_free;
218 wlv->c_extra = NUL;
219 wlv->c_final = NUL;
220 if (use_cursor_line_highlight(wp, wlv->lnum))
221 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
222 else
223 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
224 }
225}
226#endif
227
228#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000229/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100230 * Get information needed to display the sign in line "wlv->lnum" in window
231 * "wp".
232 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200233 * Otherwise the sign is going to be displayed in the sign column.
234 */
235 static void
236get_sign_display_info(
237 int nrcol,
238 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100239 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200240{
241 int text_sign;
242# ifdef FEAT_SIGN_ICONS
243 int icon_sign;
244# endif
245
246 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100247 wlv->c_extra = ' ';
248 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200249 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100250 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200251 else
252 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100253 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100254 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000255 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100256 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100257 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200258 }
259
Bram Moolenaar1306b362022-08-06 15:59:06 +0100260 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200261#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100262 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200263#endif
264 )
265 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100266 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200267# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100268 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200269 if (gui.in_use && icon_sign != 0)
270 {
271 // Use the image in this position.
272 if (nrcol)
273 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100274 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100275 sprintf((char *)wlv->extra, "%-*c ",
276 number_width(wp), SIGN_BYTE);
277 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100278 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200279 }
280 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100281 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200282# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100283 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
284 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200285 {
286 if (nrcol)
287 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100288 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100289 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200290 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100291 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100292 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200293 }
294 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100295 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200296 }
297# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100298 wlv->c_final = NUL;
299 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200300 }
301 else
302# endif
303 if (text_sign != 0)
304 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100305 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100306 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200307 {
308 if (nrcol)
309 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100310 int width = number_width(wp) - 2;
311 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200312
313 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100314 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100315 vim_snprintf((char *)wlv->extra + n,
316 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100317 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200318 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100319 wlv->c_extra = NUL;
320 wlv->c_final = NUL;
321 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200322 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000323
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100324 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100325 && wlv->sattr.sat_culhl > 0)
326 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000327 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100328 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200329 }
330 }
331}
332#endif
333
Bram Moolenaard7657e92022-09-20 18:59:30 +0100334/*
335 * Display the absolute or relative line number. After the first row fill with
336 * blanks when the 'n' flag isn't in 'cpo'.
337 */
338 static void
339handle_lnum_col(
340 win_T *wp,
341 winlinevars_T *wlv,
342 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100343 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100344{
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100345 int has_cpo_n = vim_strchr(p_cpo, CPO_NUMCOL) != NULL;
346
Bram Moolenaard7657e92022-09-20 18:59:30 +0100347 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100348 && (wlv->row == wlv->startrow + wlv->filler_lines || !has_cpo_n)
Bram Moolenaar37251162022-10-06 20:48:00 +0100349 // there is no line number in a wrapped line when "n" is in
350 // 'cpoptions', but 'breakindent' assumes it anyway.
351 && !((has_cpo_n
352#ifdef FEAT_LINEBREAK
353 && !wp->w_p_bri
354#endif
355 ) && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100356 {
357#ifdef FEAT_SIGNS
358 // If 'signcolumn' is set to 'number' and a sign is present
359 // in 'lnum', then display the sign instead of the line
360 // number.
361 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
362 get_sign_display_info(TRUE, wp, wlv);
363 else
364#endif
365 {
366 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100367 // When there are text properties above the line put the line number
368 // below them.
369 if (wlv->row == wlv->startrow + wlv->filler_lines
370#ifdef FEAT_PROP_POPUP
371 + wlv->text_prop_above_count
Bram Moolenaard7657e92022-09-20 18:59:30 +0100372#endif
Bram Moolenaar06618f92022-10-06 19:21:20 +0100373 && (wp->w_skipcol == 0 || wlv->row > wp->w_winrow))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100374 {
375 long num;
376 char *fmt = "%*ld ";
377
378 if (wp->w_p_nu && !wp->w_p_rnu)
379 // 'number' + 'norelativenumber'
380 num = (long)wlv->lnum;
381 else
382 {
383 // 'relativenumber', don't use negative numbers
384 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
385 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
386 {
387 // 'number' + 'relativenumber'
388 num = wlv->lnum;
389 fmt = "%-*ld ";
390 }
391 }
392
393 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100394 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100395 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
396 ++wlv->p_extra)
397 *wlv->p_extra = '-';
398#ifdef FEAT_RIGHTLEFT
399 if (wp->w_p_rl) // reverse line numbers
400 {
401 char_u *p1, *p2;
402 int t;
403
404 // like rl_mirror(), but keep the space at the end
405 p2 = skipwhite(wlv->extra);
406 p2 = skiptowhite(p2) - 1;
407 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
408 {
409 t = *p1;
410 *p1 = *p2;
411 *p2 = t;
412 }
413 }
414#endif
415 wlv->p_extra = wlv->extra;
416 wlv->c_extra = NUL;
417 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100418 }
419 else
420 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100421 wlv->c_extra = ' ';
422 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100423 }
424 wlv->n_extra = number_width(wp) + 1;
425 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
426#ifdef FEAT_SYN_HL
427 // When 'cursorline' is set highlight the line number of
428 // the current line differently.
429 // When 'cursorlineopt' does not have "line" only
430 // highlight the line number itself.
431 // TODO: Can we use CursorLine instead of CursorLineNr
432 // when CursorLineNr isn't set?
433 if (wp->w_p_cul
434 && wlv->lnum == wp->w_cursor.lnum
435 && (wp->w_p_culopt_flags & CULOPT_NBR)
436 && (wlv->row == wlv->startrow + wlv->filler_lines
437 || (wlv->row > wlv->startrow + wlv->filler_lines
438 && (wp->w_p_culopt_flags & CULOPT_LINE))))
439 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
440#endif
441 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
442 && HL_ATTR(HLF_LNA) != 0)
443 // Use LineNrAbove
444 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
445 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
446 && HL_ATTR(HLF_LNB) != 0)
447 // Use LineNrBelow
448 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
449 }
450#ifdef FEAT_SIGNS
451 if (num_attr)
452 wlv->char_attr = num_attr;
453#endif
454 }
455}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100456
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100457#ifdef FEAT_LINEBREAK
458 static void
459handle_breakindent(win_T *wp, winlinevars_T *wlv)
460{
461 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
462 && *get_showbreak_value(wp) != NUL)
463 // draw indent after showbreak value
464 wlv->draw_state = WL_BRI;
465 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
466 // After the showbreak, draw the breakindent
467 wlv->draw_state = WL_BRI - 1;
468
469 // draw 'breakindent': indent wrapped text accordingly
470 if (wlv->draw_state == WL_BRI - 1)
471 {
472 wlv->draw_state = WL_BRI;
473 // if wlv->need_showbreak is set, breakindent also applies
474 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
475# ifdef FEAT_DIFF
476 && wlv->filler_lines == 0
477# endif
478# ifdef FEAT_PROP_POPUP
479 && !wlv->dont_use_showbreak
480# endif
481 )
482 {
483 wlv->char_attr = 0;
484# ifdef FEAT_DIFF
485 if (wlv->diff_hlf != (hlf_T)0)
486 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
487# endif
488 wlv->p_extra = NULL;
489 wlv->c_extra = ' ';
490 wlv->c_final = NUL;
491 wlv->n_extra = get_breakindent_win(wp,
492 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
493 if (wlv->row == wlv->startrow)
494 {
495 wlv->n_extra -= win_col_off2(wp);
496 if (wlv->n_extra < 0)
497 wlv->n_extra = 0;
498 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100499 if (wp->w_skipcol > 0 && wlv->startrow == 0
500 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100501 wlv->need_showbreak = FALSE;
502 // Correct end of highlighted area for 'breakindent',
503 // required when 'linebreak' is also set.
504 if (wlv->tocol == wlv->vcol)
505 wlv->tocol += wlv->n_extra;
506 }
507 }
508}
509#endif
510
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100511#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
512 static void
513handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
514{
515# ifdef FEAT_DIFF
516 if (wlv->filler_todo > 0)
517 {
518 // Draw "deleted" diff line(s).
519 if (char2cells(wp->w_fill_chars.diff) > 1)
520 {
521 wlv->c_extra = '-';
522 wlv->c_final = NUL;
523 }
524 else
525 {
526 wlv->c_extra = wp->w_fill_chars.diff;
527 wlv->c_final = NUL;
528 }
529# ifdef FEAT_RIGHTLEFT
530 if (wp->w_p_rl)
531 wlv->n_extra = wlv->col + 1;
532 else
533# endif
534 wlv->n_extra = wp->w_width - wlv->col;
535 wlv->char_attr = HL_ATTR(HLF_DED);
536 }
537# endif
538
539# ifdef FEAT_LINEBREAK
540 char_u *sbr = get_showbreak_value(wp);
541 if (*sbr != NUL && wlv->need_showbreak)
542 {
543 // Draw 'showbreak' at the start of each broken line.
544 wlv->p_extra = sbr;
545 wlv->c_extra = NUL;
546 wlv->c_final = NUL;
547 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100548 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100549 wlv->need_showbreak = FALSE;
550 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
551 // Correct end of highlighted area for 'showbreak',
552 // required when 'linebreak' is also set.
553 if (wlv->tocol == wlv->vcol)
554 wlv->tocol += wlv->n_extra;
555 // combine 'showbreak' with 'wincolor'
556 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
557# ifdef FEAT_SYN_HL
558 // combine 'showbreak' with 'cursorline'
559 if (wlv->cul_attr != 0)
560 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
561# endif
562 }
563# endif
564}
565#endif
566
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100567#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100568/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100569 * Return the cell size of virtual text after truncation.
570 */
571 static int
572textprop_size_after_trunc(
573 win_T *wp,
574 int flags, // TP_FLAG_ALIGN_*
575 int added,
576 char_u *text,
577 int *n_used_ptr)
578{
579 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
580 ? wp->w_width : added;
581 int len = (int)STRLEN(text);
582 int strsize = 0;
583 int n_used;
584
585 // if the remaining size is to small wrap anyway and use the next line
586 if (space < PROP_TEXT_MIN_CELLS)
587 space += wp->w_width;
588 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
589 {
590 int clen = ptr2cells(text + n_used);
591
592 if (strsize + clen > space)
593 break;
594 strsize += clen;
595 }
596 *n_used_ptr = n_used;
597 return strsize;
598}
599
600/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100601 * Take care of padding, right-align and truncation of virtual text after a
602 * line.
603 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
604 * padding, right-align and truncation. Otherwise only the size is computed.
605 * When "n_attr" is NULL returns the number of screen cells used.
606 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100607 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100608 int
609text_prop_position(
610 win_T *wp,
611 textprop_T *tp,
612 int vcol, // current screen column
613 int *n_extra, // nr of bytes for virtual text
614 char_u **p_extra, // virtual text
615 int *n_attr, // attribute cells, NULL if not used
616 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200617{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100618 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100619 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100620 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
621 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
622 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
623 ? tp->tp_len - 1 : 0;
624 int col_with_padding = vcol + (below ? 0 : padding);
625 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100626 int before = room; // spaces before the text
627 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100628 int n_used = *n_extra;
629 char_u *l = NULL;
630 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100631 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
632 tp->tp_flags, before, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200633
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100634 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100635 {
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100636 int col_off = win_col_off(wp) + win_col_off2(wp);
637 int skip_add = 0;
638
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100639 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100640 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100641 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100642 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100643 }
644 else
645 {
646 // Right-align: fill with before
647 if (right)
648 before -= cells;
649 if (before < 0
650 || !(right || below)
651 || (below
652 ? (col_with_padding == 0 || !wp->w_p_wrap)
653 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100654 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100655 if (right && (wrap || room < PROP_TEXT_MIN_CELLS))
656 {
657 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100658 before = wp->w_width - col_off - strsize + room;
659 if (before < 0)
660 before = 0;
661 else
662 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100663 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100664 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100665 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100666 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100667 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100668 else if (below && before > 0)
669 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100670 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100671 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100672
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100673 // With 'nowrap' add one to show the "extends" character if needed (it
674 // doesn't show if the text just fits).
675 if (!wp->w_p_wrap
676 && n_used < *n_extra
677 && wp->w_lcs_chars.ext != NUL
678 && wp->w_p_list)
679 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100680 if (!wp->w_p_wrap && below && padding > 0)
681 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100682
683 // add 1 for NUL, 2 for when '…' is used
684 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100685 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100686 if (n_attr == NULL || l != NULL)
687 {
688 int off = 0;
689
690 if (n_attr != NULL)
691 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100692 vim_memset(l, ' ', before);
693 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100694 if (padding > 0)
695 {
696 vim_memset(l + off, ' ', padding);
697 off += padding;
698 }
699 vim_strncpy(l + off, *p_extra, n_used);
700 off += n_used;
701 }
702 else
703 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100704 off = before + after + padding + n_used;
705 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100706 }
707 if (n_attr != NULL)
708 {
709 if (n_used < *n_extra && wp->w_p_wrap)
710 {
711 char_u *lp = l + off - 1;
712
713 if (has_mbyte)
714 {
715 // change last character to '…'
716 lp -= (*mb_head_off)(l, lp);
717 STRCPY(lp, "…");
718 n_used = lp - l + 3 - padding;
719 }
720 else
721 // change last character to '>'
722 *lp = '>';
723 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100724 else if (after > 0)
725 {
726 vim_memset(l + off, ' ', after);
727 l[off + after] = NUL;
728 }
729
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100730 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100731 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100732 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100733 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100734 *n_attr -= padding + after;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100735 *n_attr_skip = before + padding + skip_add;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100736 }
737 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100738 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100739
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100740 if (n_attr == NULL)
741 return cells;
742 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200743}
744#endif
745
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100746/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100747 * Call screen_line() using values from "wlv".
748 * Also takes care of putting "<<<" on the first line for 'smoothscroll'.
749 */
750 static void
751wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
752{
753 if (wlv->row == 0 && wp->w_skipcol > 0)
754 {
755 int off = (int)(current_ScreenLine - ScreenLines);
756
757 for (int i = 0; i < 3; ++i)
758 {
759 ScreenLines[off] = '<';
760 if (enc_utf8)
761 ScreenLinesUC[off] = 0;
762 ScreenAttrs[off] = HL_ATTR(HLF_AT);
763 ++off;
764 }
765 }
766
767 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
768 negative_width ? -wp->w_width : wp->w_width,
769 wlv->screen_line_flags);
770}
771
772/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100773 * Called when finished with the line: draw the screen line and handle any
774 * highlighting until the right of the window.
775 */
776 static void
777draw_screen_line(win_T *wp, winlinevars_T *wlv)
778{
779#ifdef FEAT_SYN_HL
780 long v;
781
782 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
783 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100784 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100785 else
786 v = wp->w_leftcol;
787
788 // check if line ends before left margin
789 if (wlv->vcol < v + wlv->col - win_col_off(wp))
790 wlv->vcol = v + wlv->col - win_col_off(wp);
791# ifdef FEAT_CONCEAL
792 // Get rid of the boguscols now, we want to draw until the right
793 // edge for 'cursorcolumn'.
794 wlv->col -= wlv->boguscols;
795 wlv->boguscols = 0;
796# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
797# else
798# define VCOL_HLC (wlv->vcol)
799# endif
800
801 if (wlv->draw_color_col)
802 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
803
804 if (((wp->w_p_cuc
805 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
806 && (int)wp->w_virtcol <
807 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
808 && wlv->lnum != wp->w_cursor.lnum)
809 || wlv->draw_color_col
810 || wlv->win_attr != 0)
811# ifdef FEAT_RIGHTLEFT
812 && !wp->w_p_rl
813# endif
814 )
815 {
816 int rightmost_vcol = 0;
817 int i;
818
819 if (wp->w_p_cuc)
820 rightmost_vcol = wp->w_virtcol;
821 if (wlv->draw_color_col)
822 // determine rightmost colorcolumn to possibly draw
823 for (i = 0; wlv->color_cols[i] >= 0; ++i)
824 if (rightmost_vcol < wlv->color_cols[i])
825 rightmost_vcol = wlv->color_cols[i];
826
827 while (wlv->col < wp->w_width)
828 {
829 ScreenLines[wlv->off] = ' ';
830 if (enc_utf8)
831 ScreenLinesUC[wlv->off] = 0;
832 ScreenCols[wlv->off] = MAXCOL;
833 ++wlv->col;
834 if (wlv->draw_color_col)
835 wlv->draw_color_col = advance_color_col(
836 VCOL_HLC, &wlv->color_cols);
837
838 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
839 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
840 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
841 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
842 else
843 ScreenAttrs[wlv->off++] = wlv->win_attr;
844
845 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
846 break;
847
848 ++wlv->vcol;
849 }
850 }
851#endif
852
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100853 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100854 ++wlv->row;
855 ++wlv->screen_row;
856}
857#undef VCOL_HLC
858
859/*
860 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100861 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100862 */
863 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100864win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100865{
866 wlv->col = 0;
867 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
868
869#ifdef FEAT_RIGHTLEFT
870 if (wp->w_p_rl)
871 {
872 // Rightleft window: process the text in the normal direction, but put
873 // it in current_ScreenLine[] from right to left. Start at the
874 // rightmost column of the window.
875 wlv->col = wp->w_width - 1;
876 wlv->off += wlv->col;
877 wlv->screen_line_flags |= SLF_RIGHTLEFT;
878 }
879#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100880 if (save_extra)
881 {
882 // reset the drawing state for the start of a wrapped line
883 wlv->draw_state = WL_START;
884 wlv->saved_n_extra = wlv->n_extra;
885 wlv->saved_p_extra = wlv->p_extra;
886 wlv->saved_c_extra = wlv->c_extra;
887 wlv->saved_c_final = wlv->c_final;
888#ifdef FEAT_SYN_HL
889 if (!(wlv->cul_screenline
890# ifdef FEAT_DIFF
891 && wlv->diff_hlf == (hlf_T)0
892# endif
893 ))
894 wlv->saved_char_attr = wlv->char_attr;
895 else
896#endif
897 wlv->saved_char_attr = 0;
898 wlv->n_extra = 0;
899 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100900}
901
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200902/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100903 * Called when wlv->draw_state is set to WL_LINE.
904 */
905 static void
906win_line_continue(winlinevars_T *wlv)
907{
908 if (wlv->saved_n_extra > 0)
909 {
910 // Continue item from end of wrapped line.
911 wlv->n_extra = wlv->saved_n_extra;
912 wlv->c_extra = wlv->saved_c_extra;
913 wlv->c_final = wlv->saved_c_final;
914 wlv->p_extra = wlv->saved_p_extra;
915 wlv->char_attr = wlv->saved_char_attr;
916 }
917 else
918 wlv->char_attr = wlv->win_attr;
919}
920
921/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200922 * Display line "lnum" of window 'wp' on the screen.
923 * Start at row "startrow", stop when "endrow" is reached.
924 * wp->w_virtcol needs to be valid.
925 *
926 * Return the number of last row the line occupies.
927 */
928 int
929win_line(
930 win_T *wp,
931 linenr_T lnum,
932 int startrow,
933 int endrow,
934 int nochange UNUSED, // not updating for changed text
935 int number_only) // only update the number column
936{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100937 winlinevars_T wlv; // variables passed between functions
938
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200939 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100940 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200941 char_u *line; // current line
942 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200943
Bram Moolenaar1306b362022-08-06 15:59:06 +0100944#ifdef FEAT_PROP_POPUP
945 char_u *p_extra_free2 = NULL; // another p_extra to be freed
946#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200947 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000948#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000949 int in_linebreak = FALSE; // n_extra set for showing linebreak
950#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200951 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100952 // displaying eol at end-of-line
953 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000954 int lcs_prec_todo = wp->w_lcs_chars.prec;
955 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200956
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100957 int n_attr = 0; // chars with special attr
958 int n_attr_skip = 0; // chars to skip before using extra_attr
959 int saved_attr2 = 0; // char_attr saved for n_attr
960 int n_attr3 = 0; // chars with overruling special attr
961 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200962
963 int n_skip = 0; // nr of chars to skip for 'nowrap'
964
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200965 int fromcol_prev = -2; // start of inverting after cursor
966 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200967 int lnum_in_visual_area = FALSE;
968 pos_T pos;
969 long v;
970
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200971 int attr_pri = FALSE; // char_attr has priority
972 int area_highlighting = FALSE; // Visual or incsearch highlighting
973 // in this line
974 int vi_attr = 0; // attributes for Visual and incsearch
975 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200976 int area_attr = 0; // attributes desired by highlighting
977 int search_attr = 0; // attributes desired by 'hlsearch'
978#ifdef FEAT_SYN_HL
979 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
980 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200981 int prev_syntax_col = -1; // column of prev_syntax_attr
982 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200983 int has_syntax = FALSE; // this buffer has syntax highl.
984 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200985#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100986#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200987 int text_prop_count;
988 int text_prop_next = 0; // next text property to use
989 textprop_T *text_props = NULL;
990 int *text_prop_idxs = NULL;
991 int text_props_active = 0;
992 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +0100993 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200994 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +0100995 int text_prop_attr_comb = 0; // text_prop_attr combined with
996 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100997 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100998 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +0100999 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001000 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001001 int saved_search_attr = 0; // search_attr to be used when n_extra
1002 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001003 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001004#endif
1005#ifdef FEAT_SPELL
1006 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001007 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001008# define SPWORDLEN 150
1009 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1010 int nextlinecol = 0; // column where nextline[] starts
1011 int nextline_idx = 0; // index in nextline[] where next line
1012 // starts
1013 int spell_attr = 0; // attributes desired by spelling
1014 int word_end = 0; // last byte with same spell_attr
1015 static linenr_T checked_lnum = 0; // line number for "checked_col"
1016 static int checked_col = 0; // column in "checked_lnum" up to which
1017 // there are no spell errors
1018 static int cap_col = -1; // column to check for Cap word
1019 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1020 int cur_checked_col = 0; // checked column for current line
1021#endif
1022 int extra_check = 0; // has extra highlighting
1023 int multi_attr = 0; // attributes desired by multibyte
1024 int mb_l = 1; // multi-byte byte length
1025 int mb_c = 0; // decoded multi-byte character
1026 int mb_utf8 = FALSE; // screen char is UTF-8 char
1027 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001028#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001029 int change_start = MAXCOL; // first col of changed area
1030 int change_end = -1; // last col of changed area
1031#endif
1032 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001033 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001034 int in_multispace = FALSE; // in multiple consecutive spaces
1035 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001036#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
1037 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
1038# define LINE_ATTR
1039 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +01001040 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001041#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001042 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001043 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001044#ifdef FEAT_ARABIC
1045 int prev_c = 0; // previous Arabic character
1046 int prev_c1 = 0; // first composing char for prev_c
1047#endif
1048#if defined(LINE_ATTR)
1049 int did_line_attr = 0;
1050#endif
1051#ifdef FEAT_TERMINAL
1052 int get_term_attr = FALSE;
1053#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001054
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001055#ifdef FEAT_SYN_HL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001056 // margin columns for the screen line, needed for when 'cursorlineopt'
1057 // contains "screenline"
1058 int left_curline_col = 0;
1059 int right_curline_col = 0;
1060#endif
1061
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001062#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1063 int feedback_col = 0;
1064 int feedback_old_attr = -1;
1065#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001066
1067#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1068 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001069 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001070#endif
1071#ifdef FEAT_CONCEAL
1072 int syntax_flags = 0;
1073 int syntax_seqnr = 0;
1074 int prev_syntax_id = 0;
1075 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1076 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001077 int did_wcol = FALSE;
1078 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001079# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001080# define FIX_FOR_BOGUSCOLS \
1081 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001082 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001083 wlv.vcol -= wlv.vcol_off; \
1084 wlv.vcol_off = 0; \
1085 wlv.col -= wlv.boguscols; \
1086 old_boguscols = wlv.boguscols; \
1087 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001088 }
1089#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001090# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001091#endif
1092
1093 if (startrow > endrow) // past the end already!
1094 return startrow;
1095
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001096 CLEAR_FIELD(wlv);
1097
1098 wlv.lnum = lnum;
1099 wlv.startrow = startrow;
1100 wlv.row = startrow;
1101 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001102 wlv.fromcol = -10;
1103 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001104#ifdef FEAT_LINEBREAK
1105 wlv.vcol_sbr = -1;
1106#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001107
1108 if (!number_only)
1109 {
1110 // To speed up the loop below, set extra_check when there is linebreak,
1111 // trailing white space and/or syntax processing to be done.
1112#ifdef FEAT_LINEBREAK
1113 extra_check = wp->w_p_lbr;
1114#endif
1115#ifdef FEAT_SYN_HL
1116 if (syntax_present(wp) && !wp->w_s->b_syn_error
1117# ifdef SYN_TIME_LIMIT
1118 && !wp->w_s->b_syn_slow
1119# endif
1120 )
1121 {
1122 // Prepare for syntax highlighting in this line. When there is an
1123 // error, stop syntax highlighting.
1124 save_did_emsg = did_emsg;
1125 did_emsg = FALSE;
1126 syntax_start(wp, lnum);
1127 if (did_emsg)
1128 wp->w_s->b_syn_error = TRUE;
1129 else
1130 {
1131 did_emsg = save_did_emsg;
1132#ifdef SYN_TIME_LIMIT
1133 if (!wp->w_s->b_syn_slow)
1134#endif
1135 {
1136 has_syntax = TRUE;
1137 extra_check = TRUE;
1138 }
1139 }
1140 }
1141
1142 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001143 wlv.color_cols = wp->w_p_cc_cols;
1144 if (wlv.color_cols != NULL)
1145 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001146#endif
1147
1148#ifdef FEAT_TERMINAL
1149 if (term_show_buffer(wp->w_buffer))
1150 {
1151 extra_check = TRUE;
1152 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001153 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001154 }
1155#endif
1156
1157#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001158 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001159 {
1160 // Prepare for spell checking.
1161 has_spell = TRUE;
1162 extra_check = TRUE;
1163
1164 // Get the start of the next line, so that words that wrap to the
1165 // next line are found too: "et<line-break>al.".
1166 // Trick: skip a few chars for C/shell/Vim comments
1167 nextline[SPWORDLEN] = NUL;
1168 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1169 {
1170 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1171 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1172 }
1173
1174 // When a word wrapped from the previous line the start of the
1175 // current line is valid.
1176 if (lnum == checked_lnum)
1177 cur_checked_col = checked_col;
1178 checked_lnum = 0;
1179
1180 // When there was a sentence end in the previous line may require a
1181 // word starting with capital in this line. In line 1 always check
1182 // the first word.
1183 if (lnum != capcol_lnum)
1184 cap_col = -1;
1185 if (lnum == 1)
1186 cap_col = 0;
1187 capcol_lnum = 0;
1188 }
1189#endif
1190
1191 // handle Visual active in this window
1192 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1193 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001194 pos_T *top, *bot;
1195
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001196 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1197 {
1198 // Visual is after curwin->w_cursor
1199 top = &curwin->w_cursor;
1200 bot = &VIsual;
1201 }
1202 else
1203 {
1204 // Visual is before curwin->w_cursor
1205 top = &VIsual;
1206 bot = &curwin->w_cursor;
1207 }
1208 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1209 if (VIsual_mode == Ctrl_V)
1210 {
1211 // block mode
1212 if (lnum_in_visual_area)
1213 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001214 wlv.fromcol = wp->w_old_cursor_fcol;
1215 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001216 }
1217 }
1218 else
1219 {
1220 // non-block mode
1221 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001222 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001223 else if (lnum == top->lnum)
1224 {
1225 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001226 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001227 else
1228 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001229 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001230 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001231 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001232 }
1233 }
1234 if (VIsual_mode != 'V' && lnum == bot->lnum)
1235 {
1236 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1237 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001238 wlv.fromcol = -10;
1239 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001240 }
1241 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001242 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001243 else
1244 {
1245 pos = *bot;
1246 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001247 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1248 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001249 else
1250 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001251 getvvcol(wp, &pos, NULL, NULL,
1252 (colnr_T *)&wlv.tocol);
1253 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001254 }
1255 }
1256 }
1257 }
1258
1259 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001260 if (!highlight_match && lnum == curwin->w_cursor.lnum
1261 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001262#ifdef FEAT_GUI
1263 && !gui.in_use
1264#endif
1265 )
1266 noinvcur = TRUE;
1267
1268 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001269 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001270 {
1271 area_highlighting = TRUE;
1272 vi_attr = HL_ATTR(HLF_V);
1273#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1274 if ((clip_star.available && !clip_star.owned
1275 && clip_isautosel_star())
1276 || (clip_plus.available && !clip_plus.owned
1277 && clip_isautosel_plus()))
1278 vi_attr = HL_ATTR(HLF_VNC);
1279#endif
1280 }
1281 }
1282
1283 // handle 'incsearch' and ":s///c" highlighting
1284 else if (highlight_match
1285 && wp == curwin
1286 && lnum >= curwin->w_cursor.lnum
1287 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1288 {
1289 if (lnum == curwin->w_cursor.lnum)
1290 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001291 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001292 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001293 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001294 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1295 {
1296 pos.lnum = lnum;
1297 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001298 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001299 }
1300 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001301 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001302 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001303 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1304 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001305 area_highlighting = TRUE;
1306 vi_attr = HL_ATTR(HLF_I);
1307 }
1308 }
1309
1310#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001311 wlv.filler_lines = diff_check(wp, lnum);
1312 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001313 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001314 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001315 {
1316 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001317 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001318 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001319 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001320 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001321 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001322 }
1323 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001324 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001325 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001326 area_highlighting = TRUE;
1327 }
1328 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001329 wlv.filler_lines = wp->w_topfill;
1330 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001331#endif
1332
1333#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001334 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001335 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001336 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001337#endif
1338
1339#ifdef LINE_ATTR
1340# ifdef FEAT_SIGNS
1341 // If this line has a sign with line highlighting set line_attr.
1342 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001343 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001344# endif
1345# if defined(FEAT_QUICKFIX)
1346 // Highlight the current line in the quickfix window.
1347 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1348 line_attr = HL_ATTR(HLF_QFL);
1349# endif
1350 if (line_attr != 0)
1351 area_highlighting = TRUE;
1352#endif
1353
1354 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1355 ptr = line;
1356
1357#ifdef FEAT_SPELL
1358 if (has_spell && !number_only)
1359 {
1360 // For checking first word with a capital skip white space.
1361 if (cap_col == 0)
1362 cap_col = getwhitecols(line);
1363
1364 // To be able to spell-check over line boundaries copy the end of the
1365 // current line into nextline[]. Above the start of the next line was
1366 // copied to nextline[SPWORDLEN].
1367 if (nextline[SPWORDLEN] == NUL)
1368 {
1369 // No next line or it is empty.
1370 nextlinecol = MAXCOL;
1371 nextline_idx = 0;
1372 }
1373 else
1374 {
1375 v = (long)STRLEN(line);
1376 if (v < SPWORDLEN)
1377 {
1378 // Short line, use it completely and append the start of the
1379 // next line.
1380 nextlinecol = 0;
1381 mch_memmove(nextline, line, (size_t)v);
1382 STRMOVE(nextline + v, nextline + SPWORDLEN);
1383 nextline_idx = v + 1;
1384 }
1385 else
1386 {
1387 // Long line, use only the last SPWORDLEN bytes.
1388 nextlinecol = v - SPWORDLEN;
1389 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1390 nextline_idx = SPWORDLEN + 1;
1391 }
1392 }
1393 }
1394#endif
1395
1396 if (wp->w_p_list)
1397 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001398 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001399 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001400 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001401 || wp->w_lcs_chars.trail
1402 || wp->w_lcs_chars.lead
1403 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001404 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001405
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001406 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001407 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001408 {
1409 trailcol = (colnr_T)STRLEN(ptr);
1410 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1411 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001412 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001413 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001414 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001415 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001416 {
1417 leadcol = 0;
1418 while (VIM_ISWHITE(ptr[leadcol]))
1419 ++leadcol;
1420 if (ptr[leadcol] == NUL)
1421 // in a line full of spaces all of them are treated as trailing
1422 leadcol = (colnr_T)0;
1423 else
1424 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001425 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001426 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001427 }
1428
Bram Moolenaard7657e92022-09-20 18:59:30 +01001429 wlv.wcr_attr = get_wcr_attr(wp);
1430 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001431 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001432 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001433 area_highlighting = TRUE;
1434 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001435
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001436#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001437 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001438 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001439#endif
1440
1441 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1442 // first character to be displayed.
1443 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001444 v = startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001445 else
1446 v = wp->w_leftcol;
1447 if (v > 0 && !number_only)
1448 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001449 char_u *prev_ptr = ptr;
1450 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001451 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001452
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001453 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001454 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001455 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001456 charsize = win_lbr_chartabsize(&cts, NULL);
1457 cts.cts_vcol += charsize;
1458 prev_ptr = cts.cts_ptr;
1459 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001460 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001461 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001462 ptr = cts.cts_ptr;
1463 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001464
1465 // When:
1466 // - 'cuc' is set, or
1467 // - 'colorcolumn' is set, or
1468 // - 'virtualedit' is set, or
1469 // - the visual mode is active,
1470 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001471 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001472#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001473 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001474#endif
1475 virtual_active() ||
1476 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001477 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001478
1479 // Handle a character that's not completely on the screen: Put ptr at
1480 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001481 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001482 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001483 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001484 ptr = prev_ptr;
1485 // If the character fits on the screen, don't need to skip it.
1486 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001487 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1488 && wlv.col == 0)
1489 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001490 }
1491
1492 // Adjust for when the inverted text is before the screen,
1493 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001494 if (wlv.tocol <= wlv.vcol)
1495 wlv.fromcol = 0;
1496 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1497 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001498
1499#ifdef FEAT_LINEBREAK
1500 // When w_skipcol is non-zero, first line needs 'showbreak'
1501 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001502 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001503#endif
1504#ifdef FEAT_SPELL
1505 // When spell checking a word we need to figure out the start of the
1506 // word and if it's badly spelled or not.
1507 if (has_spell)
1508 {
1509 int len;
1510 colnr_T linecol = (colnr_T)(ptr - line);
1511 hlf_T spell_hlf = HLF_COUNT;
1512
1513 pos = wp->w_cursor;
1514 wp->w_cursor.lnum = lnum;
1515 wp->w_cursor.col = linecol;
1516 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1517
1518 // spell_move_to() may call ml_get() and make "line" invalid
1519 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1520 ptr = line + linecol;
1521
1522 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1523 {
1524 // no bad word found at line start, don't check until end of a
1525 // word
1526 spell_hlf = HLF_COUNT;
1527 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1528 }
1529 else
1530 {
1531 // bad word found, use attributes until end of word
1532 word_end = wp->w_cursor.col + len + 1;
1533
1534 // Turn index into actual attributes.
1535 if (spell_hlf != HLF_COUNT)
1536 spell_attr = highlight_attr[spell_hlf];
1537 }
1538 wp->w_cursor = pos;
1539
1540# ifdef FEAT_SYN_HL
1541 // Need to restart syntax highlighting for this line.
1542 if (has_syntax)
1543 syntax_start(wp, lnum);
1544# endif
1545 }
1546#endif
1547 }
1548
1549 // Correct highlighting for cursor that can't be disabled.
1550 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001551 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001552 {
1553 if (noinvcur)
1554 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001555 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001556 {
1557 // highlighting starts at cursor, let it start just after the
1558 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001559 fromcol_prev = wlv.fromcol;
1560 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001561 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001562 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001563 // restart highlighting after the cursor
1564 fromcol_prev = wp->w_virtcol;
1565 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001566 if (wlv.fromcol >= wlv.tocol)
1567 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001568 }
1569
1570#ifdef FEAT_SEARCH_EXTRA
1571 if (!number_only)
1572 {
1573 v = (long)(ptr - line);
1574 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1575 &line, &screen_search_hl,
1576 &search_attr);
1577 ptr = line + v; // "line" may have been updated
1578 }
1579#endif
1580
1581#ifdef FEAT_SYN_HL
1582 // Cursor line highlighting for 'cursorline' in the current window.
1583 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1584 {
1585 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001586 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001587 if (!(wp == curwin && VIsual_active)
1588 && wp->w_p_culopt_flags != CULOPT_NBR)
1589 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001590 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001591 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1592
1593 // Only set line_attr here when "screenline" is not present in
1594 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001595 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001596 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001597 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001598# ifdef FEAT_SIGNS
1599 // Combine the 'cursorline' and sign highlighting, depending on
1600 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001601 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001602 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001603 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001604 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001605 else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001606 line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001607 }
1608 else
1609# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001610# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001611 // let the line attribute overrule 'cursorline', otherwise
1612 // it disappears when both have background set;
1613 // 'cursorline' can use underline or bold to make it show
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001614 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001615# else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001616 line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001617# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001618 }
1619 else
1620 {
1621 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001622 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1623 }
1624 area_highlighting = TRUE;
1625 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001626 }
1627#endif
1628
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001629#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001630 {
1631 char_u *prop_start;
1632
1633 text_prop_count = get_text_props(wp->w_buffer, lnum,
1634 &prop_start, FALSE);
1635 if (text_prop_count > 0)
1636 {
1637 // Make a copy of the properties, so that they are properly
1638 // aligned.
1639 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1640 if (text_props != NULL)
1641 mch_memmove(text_props, prop_start,
1642 text_prop_count * sizeof(textprop_T));
1643
1644 // Allocate an array for the indexes.
1645 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001646 if (text_prop_idxs == NULL)
1647 VIM_CLEAR(text_props);
1648
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001649 if (text_props != NULL)
1650 {
1651 area_highlighting = TRUE;
1652 extra_check = TRUE;
1653 for (int i = 0; i < text_prop_count; ++i)
1654 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1655 ++wlv.text_prop_above_count;
1656 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001657 }
1658 }
1659#endif
1660
Bram Moolenaar1306b362022-08-06 15:59:06 +01001661 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001662
1663 // Repeat for the whole displayed line.
1664 for (;;)
1665 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001666 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001667#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001668 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001669#endif
1670#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001671 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001672#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001673
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001674 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001675 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001676 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001677#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001678 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001679 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001680 wlv.cul_attr = 0;
zeertzjq4f33bc22021-08-05 17:57:02 +02001681 line_attr = line_attr_save;
1682 }
1683#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001684 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001685 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001686 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001687 if (cmdwin_type != 0 && wp == curwin)
1688 {
1689 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001690 wlv.n_extra = 1;
1691 wlv.c_extra = cmdwin_type;
1692 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001693 wlv.char_attr =
1694 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001695 }
1696 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001697#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001698 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001699 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001700 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001701 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001702 }
1703#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001704#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001705 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001706 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001707 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001708 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001709 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001710 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001711 }
1712#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001713 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001714 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001715 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001716 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001717 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001718 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001719#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001720 // Check if 'breakindent' applies and show it.
1721 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1722 if (wlv.n_extra == 0)
1723 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001724#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001725#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001726 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001727 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001728 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001729 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001730 }
1731#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001732 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001733 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001734 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001735 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001736 }
1737 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001738
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001739#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001740 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001741 && wlv.vcol >= left_curline_col
1742 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001743 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001744 wlv.cul_attr = HL_ATTR(HLF_CUL);
1745 line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001746 }
1747#endif
1748
1749 // When still displaying '$' of change command, stop at cursor.
1750 // When only displaying the (relative) line number and that's done,
1751 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001752 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001753 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001754 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001755#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001756 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001757#endif
1758 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001759 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001760 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001761 // Pretend we have finished updating the window. Except when
1762 // 'cursorcolumn' is set.
1763#ifdef FEAT_SYN_HL
1764 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001765 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001766 else
1767#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001768 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001769 break;
1770 }
1771
Bram Moolenaar1306b362022-08-06 15:59:06 +01001772 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001773 {
1774 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001775 if (wlv.vcol == wlv.fromcol
1776 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1777 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001778 && (*mb_ptr2cells)(ptr) > 1)
1779 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001780 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001781 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001782 area_attr = vi_attr; // start highlighting
1783 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001784 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001785 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001786 area_attr = 0; // stop highlighting
1787
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001788#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001789 if (text_props != NULL)
1790 {
1791 int pi;
1792 int bcol = (int)(ptr - line);
1793
Bram Moolenaar1306b362022-08-06 15:59:06 +01001794 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001795# ifdef FEAT_LINEBREAK
1796 && !in_linebreak
1797# endif
1798 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001799 --bcol; // still working on the previous char, e.g. Tab
1800
1801 // Check if any active property ends.
1802 for (pi = 0; pi < text_props_active; ++pi)
1803 {
1804 int tpi = text_prop_idxs[pi];
1805
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001806 if (text_props[tpi].tp_col != MAXCOL
1807 && bcol >= text_props[tpi].tp_col - 1
1808 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001809 {
1810 if (pi + 1 < text_props_active)
1811 mch_memmove(text_prop_idxs + pi,
1812 text_prop_idxs + pi + 1,
1813 sizeof(int)
1814 * (text_props_active - (pi + 1)));
1815 --text_props_active;
1816 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001817# ifdef FEAT_LINEBREAK
1818 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001819 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001820 syntax_attr = 0;
1821# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001822 }
1823 }
1824
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001825# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001826 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001827 // not on the next char yet, don't start another prop
1828 --bcol;
1829# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001830 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001831 // With 'nowrap' and not in the first screen line only "below"
1832 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001833 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001834 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001835 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001836 && (wp->w_p_wrap
1837 || wlv.row == startrow
1838 || (text_props[text_prop_next].tp_flags
1839 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001840 || (bcol == 0 &&
1841 (text_props[text_prop_next].tp_flags
1842 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001843 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001844 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001845 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001846 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1847 {
1848 // first display the '$' after the line
1849 text_prop_follows = TRUE;
1850 break;
1851 }
1852 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001853 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001854 + text_props[text_prop_next].tp_len)
1855 text_prop_idxs[text_props_active++] = text_prop_next;
1856 ++text_prop_next;
1857 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001858
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001859 if (wlv.n_extra == 0 || !extra_for_textprop)
1860 {
1861 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001862 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001863 text_prop_flags = 0;
1864 text_prop_type = NULL;
1865 text_prop_id = 0;
1866 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001867 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001868 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001869 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001870 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001871 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001872
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001873 // Sort the properties on priority and/or starting last.
1874 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001875 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001876 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001877 sort_text_props(wp->w_buffer, text_props,
1878 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001879
1880 for (pi = 0; pi < text_props_active; ++pi)
1881 {
1882 int tpi = text_prop_idxs[pi];
1883 proptype_T *pt = text_prop_type_by_id(
1884 wp->w_buffer, text_props[tpi].tp_type);
1885
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001886 if (pt != NULL && (pt->pt_hl_id > 0
1887 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001888 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001889 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001890 if (pt->pt_hl_id > 0)
1891 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001892 text_prop_type = pt;
1893 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001894 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001895 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001896 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001897 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001898 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001899 }
1900 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001901 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001902 && -text_prop_id
1903 <= wp->w_buffer->b_textprop_text.ga_len)
1904 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001905 textprop_T *tp = &text_props[used_tpi];
1906 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001907 ->b_textprop_text.ga_data)[
1908 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001909 int above = (tp->tp_flags
1910 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001911
1912 // reset the ID in the copy to avoid it being used
1913 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001914 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001915
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001916 if (p != NULL)
1917 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001918 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001919 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001920 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001921 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001922 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1923 int padding = tp->tp_col == MAXCOL
1924 && tp->tp_len > 1
1925 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001926
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001927 // Insert virtual text before the current
1928 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001929 wlv.p_extra = p;
1930 wlv.c_extra = NUL;
1931 wlv.c_final = NUL;
1932 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001933 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001934 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001935 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001936 // restore search_attr and area_attr when n_extra
1937 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001938 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001939 saved_area_attr = area_attr;
1940 search_attr = 0;
1941 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001942 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001943 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001944 if (*ptr == NUL)
1945 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001946 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001947#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001948 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001949 {
1950 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001951 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001952 wlv.need_showbreak = FALSE;
1953 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001954 }
1955#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001956 if ((right || above || below || !wrap
1957 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001958 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001959 char_u *prev_p_extra = wlv.p_extra;
1960 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001961
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001962 // Take care of padding, right-align and
1963 // truncation.
1964 // Shared with win_lbr_chartabsize(), must do
1965 // exactly the same.
1966 start_line = text_prop_position(wp, tp,
1967 wlv.col,
1968 &wlv.n_extra, &wlv.p_extra,
1969 &n_attr, &n_attr_skip);
1970 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001971 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001972 // wlv.p_extra was allocated
1973 vim_free(p_extra_free2);
1974 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001975 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001976
Bram Moolenaara4abe512022-09-15 19:44:09 +01001977 if (lcs_eol_one < 0 && wlv.col
1978 + wlv.n_extra - 2 > wp->w_width)
1979 // don't bail out at end of line
1980 lcs_eol_one = 0;
1981
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001982 // When 'wrap' is off then for "below" we need
1983 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001984 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001985 {
1986 draw_screen_line(wp, &wlv);
1987
1988 // When line got too long for screen break
1989 // here.
1990 if (wlv.row == endrow)
1991 {
1992 ++wlv.row;
1993 break;
1994 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001995 win_line_start(wp, &wlv, TRUE);
1996 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001997 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001998 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001999 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002000
2001 // If another text prop follows the condition below at
2002 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002003 // If this is an "above" text prop and 'nowrap' the we
2004 // must wrap anyway.
2005 text_prop_above = above;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002006 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002007 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002008 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002009 else if (text_prop_next < text_prop_count
2010 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002011 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2012 || (!wp->w_p_wrap
2013 && wlv.col == wp->w_width - 1
2014 && (text_props[text_prop_next].tp_flags
2015 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002016 // When at last-but-one character and a text property
2017 // follows after it, we may need to flush the line after
2018 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002019 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002020 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002021 }
2022#endif
2023
Bram Moolenaare38fc862022-08-11 17:24:50 +01002024#ifdef FEAT_SEARCH_EXTRA
2025 if (wlv.n_extra == 0)
2026 {
2027 // Check for start/end of 'hlsearch' and other matches.
2028 // After end, check for start/end of next match.
2029 // When another match, have to check for start again.
2030 v = (long)(ptr - line);
2031 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2032 &screen_search_hl, &has_match_conc,
2033 &match_conc, did_line_attr, lcs_eol_one,
2034 &on_last_col);
2035 ptr = line + v; // "line" may have been changed
2036 prev_ptr = ptr;
2037
2038 // Do not allow a conceal over EOL otherwise EOL will be missed
2039 // and bad things happen.
2040 if (*ptr == NUL)
2041 has_match_conc = 0;
2042 }
2043#endif
2044
2045#ifdef FEAT_DIFF
2046 if (wlv.diff_hlf != (hlf_T)0)
2047 {
2048 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2049 && wlv.n_extra == 0)
2050 wlv.diff_hlf = HLF_TXD; // changed text
2051 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2052 && wlv.n_extra == 0)
2053 wlv.diff_hlf = HLF_CHD; // changed line
2054 line_attr = HL_ATTR(wlv.diff_hlf);
2055 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2056 && wp->w_p_culopt_flags != CULOPT_NBR
2057 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2058 && wlv.vcol <= right_curline_col)))
2059 line_attr = hl_combine_attr(
2060 line_attr, HL_ATTR(HLF_CUL));
2061 }
2062#endif
2063
Bram Moolenaara74fda62019-10-19 17:38:03 +02002064#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002065 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002066 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002067 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002068# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002069 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002070 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002071# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002072 // Get syntax attribute.
2073 if (has_syntax)
2074 {
2075 // Get the syntax attribute for the character. If there
2076 // is an error, disable syntax highlighting.
2077 save_did_emsg = did_emsg;
2078 did_emsg = FALSE;
2079
2080 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002081 if (v == prev_syntax_col)
2082 // at same column again
2083 syntax_attr = prev_syntax_attr;
2084 else
2085 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002086# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002087 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002088# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002089 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002090# ifdef FEAT_SPELL
2091 has_spell ? &can_spell :
2092# endif
2093 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002094 prev_syntax_col = v;
2095 prev_syntax_attr = syntax_attr;
2096 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002097
Bram Moolenaar34390282019-10-16 14:38:26 +02002098 if (did_emsg)
2099 {
2100 wp->w_s->b_syn_error = TRUE;
2101 has_syntax = FALSE;
2102 syntax_attr = 0;
2103 }
2104 else
2105 did_emsg = save_did_emsg;
2106# ifdef SYN_TIME_LIMIT
2107 if (wp->w_s->b_syn_slow)
2108 has_syntax = FALSE;
2109# endif
2110
2111 // Need to get the line again, a multi-line regexp may
2112 // have made it invalid.
2113 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2114 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002115 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002116# ifdef FEAT_CONCEAL
2117 // no concealing past the end of the line, it interferes
2118 // with line highlighting
2119 if (*ptr == NUL)
2120 syntax_flags = 0;
2121 else
2122 syntax_flags = get_syntax_info(&syntax_seqnr);
2123# endif
2124 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002125 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002126# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002127 // Combine text property highlight into syntax highlight.
2128 if (text_prop_type != NULL)
2129 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002130 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002131 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2132 else
2133 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002134 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002135 }
2136# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002137#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002138
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002139 // Decide which of the highlight attributes to use.
2140 attr_pri = TRUE;
2141#ifdef LINE_ATTR
2142 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002143 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002144 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002145 if (!highlight_match)
2146 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002147 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002148# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002149 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002150# endif
2151 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002152 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002153 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002154 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002155# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002156 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002157# endif
2158 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002159 else if (line_attr != 0
2160 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2161 || wlv.vcol < wlv.fromcol
2162 || vcol_prev < fromcol_prev
2163 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002164 {
2165 // Use line_attr when not in the Visual or 'incsearch' area
2166 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002167# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002168 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002169# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002170 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002171# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002172 attr_pri = FALSE;
2173 }
2174#else
2175 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002176 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002177 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002178 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002179#endif
2180 else
2181 {
2182 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002183#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002184 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002185#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002186 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002187#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002188 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002189#ifdef FEAT_PROP_POPUP
2190 // override with text property highlight when "override" is TRUE
2191 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002192 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002193#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002194 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002195
2196 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002197 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002198 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002199 if (wlv.char_attr == 0)
2200 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002201 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002202 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002203 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002204
2205 // Get the next character to put on the screen.
2206
2207 // The "p_extra" points to the extra stuff that is inserted to
2208 // represent special characters (non-printable stuff) and other
2209 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002210 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002211 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2212 // "p_extra[n_extra]".
2213 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002214 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002215 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002216 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002217 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002218 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2219 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002220 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2221 if (enc_utf8 && utf_char2len(c) > 1)
2222 {
2223 mb_utf8 = TRUE;
2224 u8cc[0] = 0;
2225 c = 0xc0;
2226 }
2227 else
2228 mb_utf8 = FALSE;
2229 }
2230 else
2231 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002232 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002233 if (has_mbyte)
2234 {
2235 mb_c = c;
2236 if (enc_utf8)
2237 {
2238 // If the UTF-8 character is more than one byte:
2239 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002240 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002241 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002242 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002243 mb_l = 1;
2244 else if (mb_l > 1)
2245 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002246 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002247 mb_utf8 = TRUE;
2248 c = 0xc0;
2249 }
2250 }
2251 else
2252 {
2253 // if this is a DBCS character, put it in "mb_c"
2254 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002255 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002256 mb_l = 1;
2257 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002258 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002259 }
2260 if (mb_l == 0) // at the NUL at end-of-line
2261 mb_l = 1;
2262
2263 // If a double-width char doesn't fit display a '>' in the
2264 // last column.
2265 if ((
2266# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002267 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002268# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002269 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002270 && (*mb_char2cells)(mb_c) == 2)
2271 {
2272 c = '>';
2273 mb_c = c;
2274 mb_l = 1;
2275 mb_utf8 = FALSE;
2276 multi_attr = HL_ATTR(HLF_AT);
2277#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002278 if (wlv.cul_attr)
2279 multi_attr = hl_combine_attr(
2280 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002281#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002282 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002283
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002284 // put the pointer back to output the double-width
2285 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002286 ++wlv.n_extra;
2287 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002288 }
2289 else
2290 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002291 wlv.n_extra -= mb_l - 1;
2292 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002293 }
2294 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002295 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002296 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002297 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002298#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002299 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002300 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002301 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002302 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002303 if (search_attr == 0)
2304 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002305 if (area_attr == 0 && *ptr != NUL)
2306 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002307 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002308#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002309 }
2310 else
2311 {
2312#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002313 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002314#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002315 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002316
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002317 // Get a character from the line itself.
2318 c = *ptr;
2319#ifdef FEAT_LINEBREAK
2320 c0 = *ptr;
2321#endif
2322 if (has_mbyte)
2323 {
2324 mb_c = c;
2325 if (enc_utf8)
2326 {
2327 // If the UTF-8 character is more than one byte: Decode it
2328 // into "mb_c".
2329 mb_l = utfc_ptr2len(ptr);
2330 mb_utf8 = FALSE;
2331 if (mb_l > 1)
2332 {
2333 mb_c = utfc_ptr2char(ptr, u8cc);
2334 // Overlong encoded ASCII or ASCII with composing char
2335 // is displayed normally, except a NUL.
2336 if (mb_c < 0x80)
2337 {
2338 c = mb_c;
2339#ifdef FEAT_LINEBREAK
2340 c0 = mb_c;
2341#endif
2342 }
2343 mb_utf8 = TRUE;
2344
2345 // At start of the line we can have a composing char.
2346 // Draw it as a space with a composing char.
2347 if (utf_iscomposing(mb_c))
2348 {
2349 int i;
2350
2351 for (i = Screen_mco - 1; i > 0; --i)
2352 u8cc[i] = u8cc[i - 1];
2353 u8cc[0] = mb_c;
2354 mb_c = ' ';
2355 }
2356 }
2357
2358 if ((mb_l == 1 && c >= 0x80)
2359 || (mb_l >= 1 && mb_c == 0)
2360 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2361 {
2362 // Illegal UTF-8 byte: display as <xx>.
2363 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002364 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002365# ifdef FEAT_RIGHTLEFT
2366 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002367 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002368# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002369 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002370 c = *wlv.p_extra;
2371 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002372 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002373 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2374 wlv.c_extra = NUL;
2375 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002376 if (area_attr == 0 && search_attr == 0)
2377 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002378 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002379 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002380 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002381 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002382 }
2383 }
2384 else if (mb_l == 0) // at the NUL at end-of-line
2385 mb_l = 1;
2386#ifdef FEAT_ARABIC
2387 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2388 {
2389 // Do Arabic shaping.
2390 int pc, pc1, nc;
2391 int pcc[MAX_MCO];
2392
2393 // The idea of what is the previous and next
2394 // character depends on 'rightleft'.
2395 if (wp->w_p_rl)
2396 {
2397 pc = prev_c;
2398 pc1 = prev_c1;
2399 nc = utf_ptr2char(ptr + mb_l);
2400 prev_c1 = u8cc[0];
2401 }
2402 else
2403 {
2404 pc = utfc_ptr2char(ptr + mb_l, pcc);
2405 nc = prev_c;
2406 pc1 = pcc[0];
2407 }
2408 prev_c = mb_c;
2409
2410 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2411 }
2412 else
2413 prev_c = mb_c;
2414#endif
2415 }
2416 else // enc_dbcs
2417 {
2418 mb_l = MB_BYTE2LEN(c);
2419 if (mb_l == 0) // at the NUL at end-of-line
2420 mb_l = 1;
2421 else if (mb_l > 1)
2422 {
2423 // We assume a second byte below 32 is illegal.
2424 // Hopefully this is OK for all double-byte encodings!
2425 if (ptr[1] >= 32)
2426 mb_c = (c << 8) + ptr[1];
2427 else
2428 {
2429 if (ptr[1] == NUL)
2430 {
2431 // head byte at end of line
2432 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002433 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002434 }
2435 else
2436 {
2437 // illegal tail byte
2438 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002439 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002440 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002441 wlv.p_extra = wlv.extra;
2442 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002443 wlv.c_extra = NUL;
2444 wlv.c_final = NUL;
2445 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002446 if (area_attr == 0 && search_attr == 0)
2447 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002448 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002449 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002450 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002451 // save current attr
2452 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002453 }
2454 mb_c = c;
2455 }
2456 }
2457 }
2458 // If a double-width char doesn't fit display a '>' in the
2459 // last column; the character is displayed at the start of the
2460 // next line.
2461 if ((
2462# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002463 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002464# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002465 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002466 && (*mb_char2cells)(mb_c) == 2)
2467 {
2468 c = '>';
2469 mb_c = c;
2470 mb_utf8 = FALSE;
2471 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002472 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002473 // Put pointer back so that the character will be
2474 // displayed at the start of the next line.
2475 --ptr;
2476#ifdef FEAT_CONCEAL
2477 did_decrement_ptr = TRUE;
2478#endif
2479 }
2480 else if (*ptr != NUL)
2481 ptr += mb_l - 1;
2482
2483 // If a double-width char doesn't fit at the left side display
2484 // a '<' in the first column. Don't do this for unprintable
2485 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002486 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002487 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002488 wlv.n_extra = 1;
2489 wlv.c_extra = MB_FILLER_CHAR;
2490 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002491 c = ' ';
2492 if (area_attr == 0 && search_attr == 0)
2493 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002494 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002495 extra_attr = hl_combine_attr(
2496 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002497 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002498 }
2499 mb_c = c;
2500 mb_utf8 = FALSE;
2501 mb_l = 1;
2502 }
2503
2504 }
2505 ++ptr;
2506
2507 if (extra_check)
2508 {
2509#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002510 // Check spelling (unless at the end of the line).
2511 // Only do this when there is no syntax highlighting, the
2512 // @Spell cluster is not used or the current syntax item
2513 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002514 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002515 if (has_spell && v >= word_end && v > cur_checked_col)
2516 {
2517 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002518 // do not calculate cap_col at the end of the line or when
2519 // only white space is following
2520 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002521# ifdef FEAT_SYN_HL
2522 !has_syntax ||
2523# endif
2524 can_spell))
2525 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002526 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002527 int len;
2528 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002529
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002530 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002531 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002532
2533 // Use nextline[] if possible, it has the start of the
2534 // next line concatenated.
2535 if ((prev_ptr - line) - nextlinecol >= 0)
2536 p = nextline + (prev_ptr - line) - nextlinecol;
2537 else
2538 p = prev_ptr;
2539 cap_col -= (int)(prev_ptr - line);
2540 len = spell_check(wp, p, &spell_hlf, &cap_col,
2541 nochange);
2542 word_end = v + len;
2543
2544 // In Insert mode only highlight a word that
2545 // doesn't touch the cursor.
2546 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002547 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002548 && wp->w_cursor.lnum == lnum
2549 && wp->w_cursor.col >=
2550 (colnr_T)(prev_ptr - line)
2551 && wp->w_cursor.col < (colnr_T)word_end)
2552 {
2553 spell_hlf = HLF_COUNT;
2554 spell_redraw_lnum = lnum;
2555 }
2556
2557 if (spell_hlf == HLF_COUNT && p != prev_ptr
2558 && (p - nextline) + len > nextline_idx)
2559 {
2560 // Remember that the good word continues at the
2561 // start of the next line.
2562 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002563 checked_col = (int)((p - nextline)
2564 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002565 }
2566
2567 // Turn index into actual attributes.
2568 if (spell_hlf != HLF_COUNT)
2569 spell_attr = highlight_attr[spell_hlf];
2570
2571 if (cap_col > 0)
2572 {
2573 if (p != prev_ptr
2574 && (p - nextline) + cap_col >= nextline_idx)
2575 {
2576 // Remember that the word in the next line
2577 // must start with a capital.
2578 capcol_lnum = lnum + 1;
2579 cap_col = (int)((p - nextline) + cap_col
2580 - nextline_idx);
2581 }
2582 else
2583 // Compute the actual column.
2584 cap_col += (int)(prev_ptr - line);
2585 }
2586 }
2587 }
2588 if (spell_attr != 0)
2589 {
2590 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002591 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2592 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002593 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002594 wlv.char_attr = hl_combine_attr(spell_attr,
2595 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002596 }
2597#endif
2598#ifdef FEAT_LINEBREAK
2599 // Found last space before word: check for line break.
2600 if (wp->w_p_lbr && c0 == c
2601 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2602 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002603 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2604 : 0;
2605 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002606 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002607
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002608 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002609# ifdef FEAT_PROP_POPUP
2610 // do not want virtual text counted here
2611 cts.cts_has_prop_with_text = FALSE;
2612# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002613 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002614 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002615
2616 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002617 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002618 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002619 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002620 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2621 if (wlv.n_extra < 0)
2622 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002623 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002624 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002625 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002626 // line break, but for TABs the highlighting should
2627 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002628 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002629
Bram Moolenaar1306b362022-08-06 15:59:06 +01002630 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002631# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002632 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002633 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002634 wp->w_buffer->b_p_vts_array) - 1;
2635# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002636 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002637 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002638# endif
2639
Bram Moolenaar1306b362022-08-06 15:59:06 +01002640 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2641 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002642# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002643 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002644 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002645# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002646 if (VIM_ISWHITE(c))
2647 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002648# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002649 if (c == TAB)
2650 // See "Tab alignment" below.
2651 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002652# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002653 if (!wp->w_p_list)
2654 c = ' ';
2655 }
2656 }
2657#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002658 in_multispace = c == ' '
2659 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2660 if (!in_multispace)
2661 multispace_pos = 0;
2662
Bram Moolenaareed9d462021-02-15 20:38:25 +01002663 // 'list': Change char 160 to 'nbsp' and space to 'space'
2664 // setting in 'listchars'. But not when the character is
2665 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002666 if (wp->w_p_list
2667 && ((((c == 160 && mb_l == 1)
2668 || (mb_utf8
2669 && ((mb_c == 160 && mb_l == 2)
2670 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002671 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002672 || (c == ' '
2673 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002674 && (wp->w_lcs_chars.space
2675 || (in_multispace
2676 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002677 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002678 && ptr - line <= trailcol)))
2679 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002680 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2681 {
2682 c = wp->w_lcs_chars.multispace[multispace_pos++];
2683 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2684 multispace_pos = 0;
2685 }
2686 else
2687 c = (c == ' ') ? wp->w_lcs_chars.space
2688 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002689 if (area_attr == 0 && search_attr == 0)
2690 {
2691 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002692 extra_attr = hl_combine_attr(wlv.win_attr,
2693 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002694 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002695 }
2696 mb_c = c;
2697 if (enc_utf8 && utf_char2len(c) > 1)
2698 {
2699 mb_utf8 = TRUE;
2700 u8cc[0] = 0;
2701 c = 0xc0;
2702 }
2703 else
2704 mb_utf8 = FALSE;
2705 }
2706
zeertzjq2e7cba32022-06-10 15:30:32 +01002707 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2708 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002709 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002710 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2711 && wp->w_lcs_chars.leadmultispace != NULL)
2712 {
2713 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002714 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2715 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002716 multispace_pos = 0;
2717 }
2718
2719 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2720 c = wp->w_lcs_chars.trail;
2721
2722 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2723 c = wp->w_lcs_chars.lead;
2724
zeertzjq2e7cba32022-06-10 15:30:32 +01002725 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002726 c = wp->w_lcs_chars.space;
2727
2728
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002729 if (!attr_pri)
2730 {
2731 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002732 extra_attr = hl_combine_attr(wlv.win_attr,
2733 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002734 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002735 }
2736 mb_c = c;
2737 if (enc_utf8 && utf_char2len(c) > 1)
2738 {
2739 mb_utf8 = TRUE;
2740 u8cc[0] = 0;
2741 c = 0xc0;
2742 }
2743 else
2744 mb_utf8 = FALSE;
2745 }
2746 }
2747
2748 // Handling of non-printable characters.
2749 if (!vim_isprintc(c))
2750 {
2751 // when getting a character from the file, we may have to
2752 // turn it into something else on the way to putting it
2753 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002754 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002755 {
2756 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002757 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002758#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002759 char_u *sbr = get_showbreak_value(wp);
2760
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002761 // only adjust the tab_len, when at the first column
2762 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002763 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002764 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002765#endif
2766 // tab amount depends on current column
2767#ifdef FEAT_VARTABS
2768 tab_len = tabstop_padding(vcol_adjusted,
2769 wp->w_buffer->b_p_ts,
2770 wp->w_buffer->b_p_vts_array) - 1;
2771#else
2772 tab_len = (int)wp->w_buffer->b_p_ts
2773 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2774#endif
2775
2776#ifdef FEAT_LINEBREAK
2777 if (!wp->w_p_lbr || !wp->w_p_list)
2778#endif
2779 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002780 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002781#ifdef FEAT_LINEBREAK
2782 else
2783 {
2784 char_u *p;
2785 int len;
2786 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002787 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002788
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002789# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002790 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002791 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002792 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002793
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002794 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002795 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002796 && old_boguscols > 0
2797 && wlv.n_extra > tab_len)
2798 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002799# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002800 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002801 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002802 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002803 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002804 if (wp->w_lcs_chars.tab3)
2805 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002806 if (wlv.n_extra > 0)
2807 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002808 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002809 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002810 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002811 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002812 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002813 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002814 vim_memset(p, ' ', len);
2815 p[len] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002816 vim_free(wlv.p_extra_free);
2817 wlv.p_extra_free = p;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002818 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002819 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002820 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002821
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002822 if (*p == NUL)
2823 {
2824 tab_len = i;
2825 break;
2826 }
2827
2828 // if tab3 is given, use it for the last char
2829 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2830 lcs = wp->w_lcs_chars.tab3;
2831 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002832 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002833 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002834 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002835 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002836# ifdef FEAT_CONCEAL
2837 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2838 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002839 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002840 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002841# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002842 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002843 }
2844#endif
2845#ifdef FEAT_CONCEAL
2846 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002847 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002848
2849 // Tab alignment should be identical regardless of
2850 // 'conceallevel' value. So tab compensates of all
2851 // previous concealed characters, and thus resets
2852 // vcol_off and boguscols accumulated so far in the
2853 // line. Note that the tab can be longer than
2854 // 'tabstop' when there are concealed characters.
2855 FIX_FOR_BOGUSCOLS;
2856
2857 // Make sure, the highlighting for the tab char will be
2858 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002859 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002860 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002861 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002862 tab_len += vc_saved;
2863 }
2864#endif
2865 mb_utf8 = FALSE; // don't draw as UTF-8
2866 if (wp->w_p_list)
2867 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002868 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002869 ? wp->w_lcs_chars.tab3
2870 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002871#ifdef FEAT_LINEBREAK
2872 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002873 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002874 else
2875#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002876 wlv.c_extra = wp->w_lcs_chars.tab2;
2877 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002878 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002879 extra_attr = hl_combine_attr(wlv.win_attr,
2880 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002881 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002882 mb_c = c;
2883 if (enc_utf8 && utf_char2len(c) > 1)
2884 {
2885 mb_utf8 = TRUE;
2886 u8cc[0] = 0;
2887 c = 0xc0;
2888 }
2889 }
2890 else
2891 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002892 wlv.c_final = NUL;
2893 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002894 c = ' ';
2895 }
2896 }
2897 else if (c == NUL
2898 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002899 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
2900 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002901 && VIsual_mode != Ctrl_V
2902 && (
2903# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002904 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002905# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002906 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002907 && !(noinvcur
2908 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002909 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002910 && lcs_eol_one > 0)
2911 {
2912 // Display a '$' after the line or highlight an extra
2913 // character if the line break is included.
2914#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2915 // For a diff line the highlighting continues after the
2916 // "$".
2917 if (
2918# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002919 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002920# ifdef LINE_ATTR
2921 &&
2922# endif
2923# endif
2924# ifdef LINE_ATTR
2925 line_attr == 0
2926# endif
2927 )
2928#endif
2929 {
2930 // In virtualedit, visual selections may extend
2931 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002932 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002933 && wlv.tocol != MAXCOL
2934 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002935 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002936 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002937 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002938 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2939 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002940 else
2941 c = ' ';
2942 lcs_eol_one = -1;
2943 --ptr; // put it back at the NUL
2944 if (!attr_pri)
2945 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002946 extra_attr = hl_combine_attr(wlv.win_attr,
2947 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002948 n_attr = 1;
2949 }
2950 mb_c = c;
2951 if (enc_utf8 && utf_char2len(c) > 1)
2952 {
2953 mb_utf8 = TRUE;
2954 u8cc[0] = 0;
2955 c = 0xc0;
2956 }
2957 else
2958 mb_utf8 = FALSE; // don't draw as UTF-8
2959 }
2960 else if (c != NUL)
2961 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002962 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2963 if (wlv.n_extra == 0)
2964 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002965#ifdef FEAT_RIGHTLEFT
2966 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002967 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002968#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002969 wlv.c_extra = NUL;
2970 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002971#ifdef FEAT_LINEBREAK
2972 if (wp->w_p_lbr)
2973 {
2974 char_u *p;
2975
Bram Moolenaar1306b362022-08-06 15:59:06 +01002976 c = *wlv.p_extra;
2977 p = alloc(wlv.n_extra + 1);
2978 vim_memset(p, ' ', wlv.n_extra);
2979 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2980 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002981 vim_free(wlv.p_extra_free);
2982 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002983 }
2984 else
2985#endif
2986 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002987 wlv.n_extra = byte2cells(c) - 1;
2988 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002989 }
2990 if (!attr_pri)
2991 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002992 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002993 extra_attr = hl_combine_attr(wlv.win_attr,
2994 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002995 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002996 }
2997 mb_utf8 = FALSE; // don't draw as UTF-8
2998 }
2999 else if (VIsual_active
3000 && (VIsual_mode == Ctrl_V
3001 || VIsual_mode == 'v')
3002 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003003 && wlv.tocol != MAXCOL
3004 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003005 && (
3006#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003007 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003008#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003009 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003010 {
3011 c = ' ';
3012 --ptr; // put it back at the NUL
3013 }
3014#if defined(LINE_ATTR)
3015 else if ((
3016# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003017 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003018# endif
3019# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003020 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003021# endif
3022 line_attr != 0
3023 ) && (
3024# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003025 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003026# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003027 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003028# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003029 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003030# endif
3031 < wp->w_width)))
3032 {
3033 // Highlight until the right side of the window
3034 c = ' ';
3035 --ptr; // put it back at the NUL
3036
3037 // Remember we do the char for line highlighting.
3038 ++did_line_attr;
3039
3040 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01003041 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003042 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003043 || (wp->w_p_list &&
3044 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003045 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003046# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003047 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003048 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003049 wlv.diff_hlf = HLF_CHD;
3050 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003051 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003052 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003053 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3054 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003055 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003056 || (wlv.vcol >= left_curline_col
3057 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003058 wlv.char_attr = hl_combine_attr(
3059 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003060 }
3061 }
3062# endif
3063# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003064 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003065 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003066 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003067 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3068 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003069 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003070 if (!wlv.cul_screenline
3071 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003072 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003073 wlv.char_attr = hl_combine_attr(
3074 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003075 }
3076 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003077 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3078 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003079 }
3080# endif
3081 }
3082#endif
3083 }
3084
3085#ifdef FEAT_CONCEAL
3086 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003087 && (wp != curwin || lnum != wp->w_cursor.lnum
3088 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003089 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3090 && !(lnum_in_visual_area
3091 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3092 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003093 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003094 if (((prev_syntax_id != syntax_seqnr
3095 && (syntax_flags & HL_CONCEAL) != 0)
3096 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003097 && (syn_get_sub_char() != NUL
3098 || (has_match_conc && match_conc)
3099 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003100 && wp->w_p_cole != 3)
3101 {
3102 // First time at this concealed item: display one
3103 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003104 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003105 c = match_conc;
3106 else if (syn_get_sub_char() != NUL)
3107 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003108 else if (wp->w_lcs_chars.conceal != NUL)
3109 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003110 else
3111 c = ' ';
3112
3113 prev_syntax_id = syntax_seqnr;
3114
Bram Moolenaar1306b362022-08-06 15:59:06 +01003115 if (wlv.n_extra > 0)
3116 wlv.vcol_off += wlv.n_extra;
3117 wlv.vcol += wlv.n_extra;
3118 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003119 {
3120# ifdef FEAT_RIGHTLEFT
3121 if (wp->w_p_rl)
3122 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003123 wlv.col -= wlv.n_extra;
3124 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003125 }
3126 else
3127# endif
3128 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003129 wlv.boguscols += wlv.n_extra;
3130 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003131 }
3132 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003133 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003134 n_attr = 0;
3135 }
3136 else if (n_skip == 0)
3137 {
3138 is_concealing = TRUE;
3139 n_skip = 1;
3140 }
3141 mb_c = c;
3142 if (enc_utf8 && utf_char2len(c) > 1)
3143 {
3144 mb_utf8 = TRUE;
3145 u8cc[0] = 0;
3146 c = 0xc0;
3147 }
3148 else
3149 mb_utf8 = FALSE; // don't draw as UTF-8
3150 }
3151 else
3152 {
3153 prev_syntax_id = 0;
3154 is_concealing = FALSE;
3155 }
3156
3157 if (n_skip > 0 && did_decrement_ptr)
3158 // not showing the '>', put pointer back to avoid getting stuck
3159 ++ptr;
3160
3161#endif // FEAT_CONCEAL
3162 }
3163
3164#ifdef FEAT_CONCEAL
3165 // In the cursor line and we may be concealing characters: correct
3166 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003167 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003168 && wp == curwin && lnum == wp->w_cursor.lnum
3169 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003170 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003171 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003172# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003173 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003174 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003175 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003176# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003177 wp->w_wcol = wlv.col - wlv.boguscols;
3178 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003179 did_wcol = TRUE;
3180 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003181# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003182 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003183# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003184 }
3185#endif
3186
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003187 // Use "extra_attr", but don't override visual selection highlighting,
3188 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003189 // Don't use "extra_attr" until n_attr_skip is zero.
3190 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003191 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003192 && (!attr_pri
3193#ifdef FEAT_PROP_POPUP
3194 || (text_prop_flags & PT_FLAG_OVERRIDE)
3195#endif
3196 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003197 {
3198#ifdef LINE_ATTR
3199 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003200 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003201 else
3202#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003203 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003204 }
3205
3206#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3207 // XIM don't send preedit_start and preedit_end, but they send
3208 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3209 // im_is_preediting() here.
3210 if (p_imst == IM_ON_THE_SPOT
3211 && xic != NULL
3212 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003213 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003214 && !p_imdisable
3215 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003216 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003217 {
3218 colnr_T tcol;
3219
3220 if (preedit_end_col == MAXCOL)
3221 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3222 else
3223 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003224 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003225 {
3226 if (feedback_old_attr < 0)
3227 {
3228 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003229 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003230 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003231 wlv.char_attr = im_get_feedback_attr(feedback_col);
3232 if (wlv.char_attr < 0)
3233 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003234 feedback_col++;
3235 }
3236 else if (feedback_old_attr >= 0)
3237 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003238 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003239 feedback_old_attr = -1;
3240 feedback_col = 0;
3241 }
3242 }
3243#endif
3244 // Handle the case where we are in column 0 but not on the first
3245 // character of the line and the user wants us to show us a
3246 // special character (via 'listchars' option "precedes:<char>".
3247 if (lcs_prec_todo != NUL
3248 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003249 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3250 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003251#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003252 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003253#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003254 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003255 && c != NUL)
3256 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003257 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003258 lcs_prec_todo = NUL;
3259 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3260 {
3261 // Double-width character being overwritten by the "precedes"
3262 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003263 wlv.c_extra = MB_FILLER_CHAR;
3264 wlv.c_final = NUL;
3265 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003266 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003267 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003268 }
3269 mb_c = c;
3270 if (enc_utf8 && utf_char2len(c) > 1)
3271 {
3272 mb_utf8 = TRUE;
3273 u8cc[0] = 0;
3274 c = 0xc0;
3275 }
3276 else
3277 mb_utf8 = FALSE; // don't draw as UTF-8
3278 if (!attr_pri)
3279 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003280 saved_attr3 = wlv.char_attr; // save current attr
3281 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003282 n_attr3 = 1;
3283 }
3284 }
3285
3286 // At end of the text line or just after the last character.
3287 if ((c == NUL
3288#if defined(LINE_ATTR)
3289 || did_line_attr == 1
3290#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003291 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003292 {
3293#ifdef FEAT_SEARCH_EXTRA
3294 // flag to indicate whether prevcol equals startcol of search_hl or
3295 // one of the matches
3296 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3297 (long)(ptr - line) - (c == NUL));
3298#endif
3299 // Invert at least one char, used for Visual and empty line or
3300 // highlight match at end of line. If it's beyond the last
3301 // char on the screen, just overwrite that one (tricky!) Not
3302 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003303 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003304 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003305 && (VIsual_mode != Ctrl_V
3306 || lnum == VIsual.lnum
3307 || lnum == curwin->w_cursor.lnum)
3308 && c == NUL)
3309#ifdef FEAT_SEARCH_EXTRA
3310 // highlight 'hlsearch' match at end of line
3311 || (prevcol_hl_flag
3312# ifdef FEAT_SYN_HL
3313 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3314 && !(wp == curwin && VIsual_active))
3315# endif
3316# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003317 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003318# endif
3319# if defined(LINE_ATTR)
3320 && did_line_attr <= 1
3321# endif
3322 )
3323#endif
3324 ))
3325 {
3326 int n = 0;
3327
3328#ifdef FEAT_RIGHTLEFT
3329 if (wp->w_p_rl)
3330 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003331 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003332 n = 1;
3333 }
3334 else
3335#endif
3336 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003337 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003338 n = -1;
3339 }
3340 if (n != 0)
3341 {
3342 // At the window boundary, highlight the last character
3343 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003344 wlv.off += n;
3345 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003346 }
3347 else
3348 {
3349 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003350 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003351 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003352 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003353 }
3354#ifdef FEAT_SEARCH_EXTRA
3355 if (area_attr == 0)
3356 {
3357 // Use attributes from match with highest priority among
3358 // 'search_hl' and the match list.
3359 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003360 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003361 }
3362#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003363 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003364 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003365#ifdef FEAT_RIGHTLEFT
3366 if (wp->w_p_rl)
3367 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003368 --wlv.col;
3369 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003370 }
3371 else
3372#endif
3373 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003374 ++wlv.col;
3375 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003376 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003377 ++wlv.vcol;
3378 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003379 }
3380 }
3381
3382 // At end of the text line.
3383 if (c == NUL)
3384 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003385 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003386
3387 // Update w_cline_height and w_cline_folded if the cursor line was
3388 // updated (saves a call to plines() later).
3389 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3390 {
3391 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003392 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003393#ifdef FEAT_FOLDING
3394 curwin->w_cline_folded = FALSE;
3395#endif
3396 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3397 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003398 break;
3399 }
3400
3401 // Show "extends" character from 'listchars' if beyond the line end and
3402 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003403 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003404 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003405 && wp->w_p_list
3406 && !wp->w_p_wrap
3407#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003408 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003409#endif
3410 && (
3411#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003412 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003413#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003414 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003415 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003416 || lcs_eol_one > 0
3417 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003418 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003419 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003420 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003421 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003422 mb_c = c;
3423 if (enc_utf8 && utf_char2len(c) > 1)
3424 {
3425 mb_utf8 = TRUE;
3426 u8cc[0] = 0;
3427 c = 0xc0;
3428 }
3429 else
3430 mb_utf8 = FALSE;
3431 }
3432
3433#ifdef FEAT_SYN_HL
3434 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003435 if (wlv.draw_color_col)
3436 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003437
3438 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3439 // highlight the cursor position itself.
3440 // Also highlight the 'colorcolumn' if it is different than
3441 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003442 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3443 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003444 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003445 if (((wlv.draw_state == WL_LINE
3446 || wlv.draw_state == WL_BRI
3447 || wlv.draw_state == WL_SBR)
3448 && !lnum_in_visual_area
3449 && search_attr == 0
3450 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003451# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003452 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003453# endif
3454 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003455 {
3456 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3457 && lnum != wp->w_cursor.lnum)
3458 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003459 vcol_save_attr = wlv.char_attr;
3460 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3461 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003462 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003463 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003464 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003465 vcol_save_attr = wlv.char_attr;
3466 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003467 }
3468 }
3469#endif
3470
3471 // Store character to be displayed.
3472 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003473 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003474 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003475 {
3476 // Store the character.
3477#if defined(FEAT_RIGHTLEFT)
3478 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3479 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003480 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003481 --wlv.off;
3482 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003483 }
3484#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003485 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003486 if (enc_dbcs == DBCS_JPNU)
3487 {
3488 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003489 ScreenLines[wlv.off] = 0x8e;
3490 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003491 }
3492 else if (enc_utf8)
3493 {
3494 if (mb_utf8)
3495 {
3496 int i;
3497
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003498 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003499 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003500 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003501 for (i = 0; i < Screen_mco; ++i)
3502 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003503 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003504 if (u8cc[i] == 0)
3505 break;
3506 }
3507 }
3508 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003509 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003510 }
3511 if (multi_attr)
3512 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003513 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003514 multi_attr = 0;
3515 }
3516 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003517 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003518
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003519 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003520
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003521 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3522 {
3523 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003524 ++wlv.off;
3525 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003526 if (enc_utf8)
3527 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003528 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003529 else
3530 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003531 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003532 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003533#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003534 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003535#endif
3536 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003537 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003538 // When "wlv.tocol" is halfway a character, set it to the end
3539 // of the character, otherwise highlighting won't stop.
3540 if (wlv.tocol == wlv.vcol)
3541 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003542
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003543 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003544
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003545#ifdef FEAT_RIGHTLEFT
3546 if (wp->w_p_rl)
3547 {
3548 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003549 --wlv.off;
3550 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003551 }
3552#endif
3553 }
3554#ifdef FEAT_RIGHTLEFT
3555 if (wp->w_p_rl)
3556 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003557 --wlv.off;
3558 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003559 }
3560 else
3561#endif
3562 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003563 ++wlv.off;
3564 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003565 }
3566 }
3567#ifdef FEAT_CONCEAL
3568 else if (wp->w_p_cole > 0 && is_concealing)
3569 {
3570 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003571 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003572 if (wlv.n_extra > 0)
3573 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003574 if (wp->w_p_wrap)
3575 {
3576 // Special voodoo required if 'wrap' is on.
3577 //
3578 // Advance the column indicator to force the line
3579 // drawing to wrap early. This will make the line
3580 // take up the same screen space when parts are concealed,
3581 // so that cursor line computations aren't messed up.
3582 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003583 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003584 // trailing junk to be written out of the screen line
3585 // we are building, 'boguscols' keeps track of the number
3586 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003587 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003588 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003589 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003590# ifdef FEAT_RIGHTLEFT
3591 if (wp->w_p_rl)
3592 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003593 wlv.col -= wlv.n_extra;
3594 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003595 }
3596 else
3597# endif
3598 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003599 wlv.col += wlv.n_extra;
3600 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003601 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003602 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003603 n_attr = 0;
3604 }
3605
3606
3607 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3608 {
3609 // Need to fill two screen columns.
3610# ifdef FEAT_RIGHTLEFT
3611 if (wp->w_p_rl)
3612 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003613 --wlv.boguscols;
3614 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003615 }
3616 else
3617# endif
3618 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003619 ++wlv.boguscols;
3620 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003621 }
3622 }
3623
3624# ifdef FEAT_RIGHTLEFT
3625 if (wp->w_p_rl)
3626 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003627 --wlv.boguscols;
3628 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003629 }
3630 else
3631# endif
3632 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003633 ++wlv.boguscols;
3634 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003635 }
3636 }
3637 else
3638 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003639 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003640 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003641 wlv.vcol += wlv.n_extra;
3642 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003643 n_attr = 0;
3644 }
3645 }
3646
3647 }
3648#endif // FEAT_CONCEAL
3649 else
3650 --n_skip;
3651
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003652 // Only advance the "wlv.vcol" when after the 'number' or
3653 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003654 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003655#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003656 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003657#endif
3658 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003659 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003660
3661#ifdef FEAT_SYN_HL
3662 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003663 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003664#endif
3665
3666 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003667 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3668 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003669
3670 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003671 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003672 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003673 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003674 if (n_attr_skip > 0)
3675 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003676
3677 // At end of screen line and there is more to come: Display the line
3678 // so far. If there is no more to display it is caught above.
3679 if ((
3680#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003681 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003682#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003683 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003684 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003685 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003686#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003687 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003688#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003689#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003690 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003691#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003692 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003693 && wlv.p_extra != at_end_str)
3694 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3695 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003696 )
3697 {
3698#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003699 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003700 wlv_screen_line(wp, &wlv, FALSE);
3701 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003702 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003703#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003704 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003705#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003706 ++wlv.row;
3707 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003708
3709 // When not wrapping and finished diff lines, or when displayed
3710 // '$' and highlighting until last column, break here.
3711 if ((!wp->w_p_wrap
3712#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003713 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003714#endif
3715#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003716 && !text_prop_above && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003717#endif
3718 ) || lcs_eol_one == -1)
3719 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003720#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003721 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003722 {
3723 // do not output more of the line, only the "below" prop
3724 ptr += STRLEN(ptr);
3725# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003726 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003727# endif
3728 }
3729#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003730
3731 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003732 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003733#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003734 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003735#endif
3736 )
3737 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003738 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3739 draw_vsep_win(wp, wlv.row);
3740 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003741 }
3742
3743 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003744 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003745 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003746 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003747 break;
3748 }
3749
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003750 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003751#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003752 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003753#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003754#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003755 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003756#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003757 && wp->w_width == Columns)
3758 {
3759 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003760 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003761
3762 // Special trick to make copy/paste of wrapped lines work with
3763 // xterm/screen: write an extra character beyond the end of
3764 // the line. This will work with all terminal types
3765 // (regardless of the xn,am settings).
3766 // Only do this on a fast tty.
3767 // Only do this if the cursor is on the current line
3768 // (something has been written in it).
3769 // Don't do this for the GUI.
3770 // Don't do this for double-width characters.
3771 // Don't do this for a window not at the right screen border.
3772 if (p_tf
3773#ifdef FEAT_GUI
3774 && !gui.in_use
3775#endif
3776 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003777 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3778 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003779 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003780 || (*mb_off2cells)(
3781 LineOffset[wlv.screen_row - 1]
3782 + (int)Columns - 2,
3783 LineOffset[wlv.screen_row]
3784 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003785 {
3786 // First make sure we are at the end of the screen line,
3787 // then output the same character again to let the
3788 // terminal know about the wrap. If the terminal doesn't
3789 // auto-wrap, we overwrite the character.
3790 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003791 screen_char(LineOffset[wlv.screen_row - 1]
3792 + (unsigned)Columns - 1,
3793 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003794
3795 // When there is a multi-byte character, just output a
3796 // space to keep it simple.
3797 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003798 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003799 out_char(' ');
3800 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003801 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003802 + (Columns - 1)]);
3803 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003804 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003805 screen_start(); // don't know where cursor is now
3806 }
3807 }
3808
Bram Moolenaar1306b362022-08-06 15:59:06 +01003809 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003810
Bram Moolenaareed9d462021-02-15 20:38:25 +01003811 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003812#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003813 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003814# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003815 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003816# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003817 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003818 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003819#endif
3820#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003821 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003822 // When the filler lines are actually below the last line of the
3823 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003824 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003825 break;
3826#endif
3827 }
3828
3829 } // for every character in the line
3830
3831#ifdef FEAT_SPELL
3832 // After an empty line check first word for capital.
3833 if (*skipwhite(line) == NUL)
3834 {
3835 capcol_lnum = lnum + 1;
3836 cap_col = 0;
3837 }
3838#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003839#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003840 vim_free(text_props);
3841 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003842 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003843#endif
3844
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003845 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003846 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003847}