blob: 74c736c24dd98ebe395b621a6f97ff53b28d759c [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 Moolenaar45e4eea2022-12-01 18:38:02 +000078#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
79 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
80// using an attribute for the whole line
81# define LINE_ATTR
82#endif
83
Bram Moolenaar1306b362022-08-06 15:59:06 +010084// structure with variables passed between win_line() and other functions
85typedef struct {
86 int draw_state; // what to draw next
87
88 linenr_T lnum; // line number to be drawn
89
90 int startrow; // first row in the window to be drawn
91 int row; // row in the window, excl w_winrow
92 int screen_row; // row on the screen, incl w_winrow
93
94 long vcol; // virtual column, before wrapping
95 int col; // visual column on screen, after wrapping
96#ifdef FEAT_CONCEAL
97 int boguscols; // nonexistent columns added to "col" to force
98 // wrapping
Bram Moolenaarf53e0652023-02-19 14:16:02 +000099 int vcol_off_co; // offset for concealed characters
Bram Moolenaar1306b362022-08-06 15:59:06 +0100100#endif
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000101 int vcol_off_tp; // offset for virtual text
Bram Moolenaar1306b362022-08-06 15:59:06 +0100102#ifdef FEAT_SYN_HL
103 int draw_color_col; // highlight colorcolumn
104 int *color_cols; // pointer to according columns array
105#endif
106 int eol_hl_off; // 1 if highlighted char after EOL
107
108 unsigned off; // offset in ScreenLines/ScreenAttrs
109
110 int win_attr; // background for the whole window, except
111 // margins and "~" lines.
Bram Moolenaard7657e92022-09-20 18:59:30 +0100112 int wcr_attr; // attributes from 'wincolor'
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100113#ifdef FEAT_SYN_HL
114 int cul_attr; // set when 'cursorline' active
115#endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000116#ifdef LINE_ATTR
117 int line_attr; // for the whole line, includes 'cursorline'
118#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100119
120 int screen_line_flags; // flags for screen_line()
121
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100122 int fromcol; // start of inverting
123 int tocol; // end of inverting
124
125#ifdef FEAT_LINEBREAK
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100126 long vcol_sbr; // virtual column after showbreak
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100127 int need_showbreak; // overlong line, skipping first x chars
128 int dont_use_showbreak; // do not use 'showbreak'
129#endif
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100130#ifdef FEAT_PROP_POPUP
131 int text_prop_above_count;
132#endif
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100133
Bram Moolenaar1306b362022-08-06 15:59:06 +0100134 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
135 int cul_screenline;
136
137 int char_attr; // attributes for the next character
138
139 int n_extra; // number of extra bytes
140 char_u *p_extra; // string of extra chars, plus NUL, only used
141 // when c_extra and c_final are NUL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100142 char_u *p_extra_free; // p_extra buffer that needs to be freed
Bram Moolenaaree28c702022-11-17 14:56:00 +0000143 int extra_attr; // attributes for p_extra, should be combined
144 // with win_attr if needed
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000145 int n_attr_skip; // chars to skip before using extra_attr
Bram Moolenaar1306b362022-08-06 15:59:06 +0100146 int c_extra; // extra chars, all the same
147 int c_final; // final char, mandatory if set
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000148 int extra_for_textprop; // wlv.n_extra set for textprop
Bram Moolenaar1306b362022-08-06 15:59:06 +0100149
150 // saved "extra" items for when draw_state becomes WL_LINE (again)
151 int saved_n_extra;
152 char_u *saved_p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000153 int saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000154 int saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000155 int saved_extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100156 int saved_c_extra;
157 int saved_c_final;
158 int saved_char_attr;
159
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100160 char_u extra[NUMBUFLEN + MB_MAXBYTES];
161 // "%ld " and 'fdc' must fit in here, as well
162 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100163
Bram Moolenaar1306b362022-08-06 15:59:06 +0100164#ifdef FEAT_DIFF
165 hlf_T diff_hlf; // type of diff highlighting
166#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100167 int filler_lines; // nr of filler lines to be drawn
168 int filler_todo; // nr of filler lines still to do + 1
169#ifdef FEAT_SIGNS
170 sign_attrs_T sattr;
171#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100172} winlinevars_T;
173
174// draw_state values for items that are drawn in sequence:
175#define WL_START 0 // nothing done yet, must be zero
Martin Tournoij7904fa42022-10-04 16:28:45 +0100176#define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar1306b362022-08-06 15:59:06 +0100177#ifdef FEAT_FOLDING
178# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
179#else
180# define WL_FOLD WL_CMDLINE
181#endif
182#ifdef FEAT_SIGNS
183# define WL_SIGN (WL_FOLD + 1) // column for signs
184#else
185# define WL_SIGN WL_FOLD // column for signs
186#endif
187#define WL_NR (WL_SIGN + 1) // line number
188#ifdef FEAT_LINEBREAK
189# define WL_BRI (WL_NR + 1) // 'breakindent'
190#else
191# define WL_BRI WL_NR
192#endif
193#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
194# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
195#else
196# define WL_SBR WL_BRI
197#endif
198#define WL_LINE (WL_SBR + 1) // text in the line
199
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100200#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200201/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000202 * Return TRUE if CursorLineSign highlight is to be used.
203 */
204 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100205use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000206{
207 return wp->w_p_cul
208 && lnum == wp->w_cursor.lnum
209 && (wp->w_p_culopt_flags & CULOPT_NBR);
210}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100211#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000212
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100213
214#ifdef FEAT_FOLDING
215/*
216 * Setup for drawing the 'foldcolumn', if there is one.
217 */
218 static void
219handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
220{
221 int fdc = compute_foldcolumn(wp, 0);
222
223 if (fdc <= 0)
224 return;
225
226 // Allocate a buffer, "wlv->extra[]" may already be in use.
227 vim_free(wlv->p_extra_free);
228 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
Yegappan Lakshmanan465de3a2022-12-26 12:50:04 +0000229 if (wlv->p_extra_free == NULL)
230 return;
231
232 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
233 wp, FALSE, wlv->lnum);
234 wlv->p_extra_free[wlv->n_extra] = NUL;
235 wlv->p_extra = wlv->p_extra_free;
236 wlv->c_extra = NUL;
237 wlv->c_final = NUL;
238 if (use_cursor_line_highlight(wp, wlv->lnum))
239 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
240 else
241 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100242}
243#endif
244
245#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000246/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100247 * Get information needed to display the sign in line "wlv->lnum" in window
248 * "wp".
249 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200250 * Otherwise the sign is going to be displayed in the sign column.
251 */
252 static void
253get_sign_display_info(
254 int nrcol,
255 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100256 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200257{
258 int text_sign;
259# ifdef FEAT_SIGN_ICONS
260 int icon_sign;
261# endif
262
263 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100264 wlv->c_extra = ' ';
265 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200266 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100267 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200268 else
269 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100270 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100271 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000272 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100273 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100274 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200275 }
276
Bram Moolenaar1306b362022-08-06 15:59:06 +0100277 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200278#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100279 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200280#endif
281 )
282 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100283 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200284# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100285 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200286 if (gui.in_use && icon_sign != 0)
287 {
288 // Use the image in this position.
289 if (nrcol)
290 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100291 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100292 sprintf((char *)wlv->extra, "%-*c ",
293 number_width(wp), SIGN_BYTE);
294 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100295 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200296 }
297 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100298 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200299# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100300 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
301 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200302 {
303 if (nrcol)
304 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100305 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100306 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200307 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100308 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100309 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200310 }
311 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100312 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200313 }
314# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100315 wlv->c_final = NUL;
316 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200317 }
318 else
319# endif
320 if (text_sign != 0)
321 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100322 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100323 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200324 {
325 if (nrcol)
326 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100327 int width = number_width(wp) - 2;
328 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200329
330 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100331 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100332 vim_snprintf((char *)wlv->extra + n,
333 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100334 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200335 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100336 wlv->c_extra = NUL;
337 wlv->c_final = NUL;
338 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200339 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000340
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100341 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100342 && wlv->sattr.sat_culhl > 0)
343 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000344 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100345 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200346 }
347 }
348}
349#endif
350
Bram Moolenaard7657e92022-09-20 18:59:30 +0100351/*
352 * Display the absolute or relative line number. After the first row fill with
353 * blanks when the 'n' flag isn't in 'cpo'.
354 */
355 static void
356handle_lnum_col(
357 win_T *wp,
358 winlinevars_T *wlv,
359 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100360 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100361{
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100362 int has_cpo_n = vim_strchr(p_cpo, CPO_NUMCOL) != NULL;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100363 int lnum_row = wlv->startrow + wlv->filler_lines
364#ifdef FEAT_PROP_POPUP
365 + wlv->text_prop_above_count
366#endif
367 ;
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100368
Bram Moolenaard7657e92022-09-20 18:59:30 +0100369 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100370 && (wlv->row <= lnum_row || !has_cpo_n)
Bram Moolenaar37251162022-10-06 20:48:00 +0100371 // there is no line number in a wrapped line when "n" is in
372 // 'cpoptions', but 'breakindent' assumes it anyway.
373 && !((has_cpo_n
374#ifdef FEAT_LINEBREAK
375 && !wp->w_p_bri
376#endif
377 ) && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100378 {
379#ifdef FEAT_SIGNS
380 // If 'signcolumn' is set to 'number' and a sign is present
381 // in 'lnum', then display the sign instead of the line
382 // number.
383 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
384 get_sign_display_info(TRUE, wp, wlv);
385 else
386#endif
387 {
388 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100389 // When there are text properties above the line put the line number
390 // below them.
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100391 if (wlv->row == lnum_row
Bram Moolenaareb4de622022-10-15 13:42:17 +0100392 && (wp->w_skipcol == 0 || wlv->row > wp->w_winrow
393 || (wp->w_p_nu && wp->w_p_rnu)))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100394 {
395 long num;
396 char *fmt = "%*ld ";
397
398 if (wp->w_p_nu && !wp->w_p_rnu)
399 // 'number' + 'norelativenumber'
400 num = (long)wlv->lnum;
401 else
402 {
403 // 'relativenumber', don't use negative numbers
404 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
405 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
406 {
407 // 'number' + 'relativenumber'
408 num = wlv->lnum;
409 fmt = "%-*ld ";
410 }
411 }
412
413 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100414 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100415 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
416 ++wlv->p_extra)
417 *wlv->p_extra = '-';
418#ifdef FEAT_RIGHTLEFT
419 if (wp->w_p_rl) // reverse line numbers
420 {
421 char_u *p1, *p2;
422 int t;
423
424 // like rl_mirror(), but keep the space at the end
425 p2 = skipwhite(wlv->extra);
426 p2 = skiptowhite(p2) - 1;
427 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
428 {
429 t = *p1;
430 *p1 = *p2;
431 *p2 = t;
432 }
433 }
434#endif
435 wlv->p_extra = wlv->extra;
436 wlv->c_extra = NUL;
437 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100438 }
439 else
440 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100441 wlv->c_extra = ' ';
442 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100443 }
444 wlv->n_extra = number_width(wp) + 1;
445 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
446#ifdef FEAT_SYN_HL
447 // When 'cursorline' is set highlight the line number of
448 // the current line differently.
449 // When 'cursorlineopt' does not have "line" only
450 // highlight the line number itself.
451 // TODO: Can we use CursorLine instead of CursorLineNr
452 // when CursorLineNr isn't set?
453 if (wp->w_p_cul
454 && wlv->lnum == wp->w_cursor.lnum
455 && (wp->w_p_culopt_flags & CULOPT_NBR)
456 && (wlv->row == wlv->startrow + wlv->filler_lines
457 || (wlv->row > wlv->startrow + wlv->filler_lines
458 && (wp->w_p_culopt_flags & CULOPT_LINE))))
459 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
460#endif
461 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
462 && HL_ATTR(HLF_LNA) != 0)
463 // Use LineNrAbove
464 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
465 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
466 && HL_ATTR(HLF_LNB) != 0)
467 // Use LineNrBelow
468 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
469 }
470#ifdef FEAT_SIGNS
471 if (num_attr)
472 wlv->char_attr = num_attr;
473#endif
474 }
475}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100476
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100477#ifdef FEAT_LINEBREAK
478 static void
479handle_breakindent(win_T *wp, winlinevars_T *wlv)
480{
481 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100482 && *get_showbreak_value(wp) != NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100483 // draw indent after showbreak value
484 wlv->draw_state = WL_BRI;
485 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
486 // After the showbreak, draw the breakindent
487 wlv->draw_state = WL_BRI - 1;
488
489 // draw 'breakindent': indent wrapped text accordingly
490 if (wlv->draw_state == WL_BRI - 1)
491 {
492 wlv->draw_state = WL_BRI;
493 // if wlv->need_showbreak is set, breakindent also applies
494 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
495# ifdef FEAT_DIFF
496 && wlv->filler_lines == 0
497# endif
498# ifdef FEAT_PROP_POPUP
499 && !wlv->dont_use_showbreak
500# endif
501 )
502 {
503 wlv->char_attr = 0;
504# ifdef FEAT_DIFF
505 if (wlv->diff_hlf != (hlf_T)0)
506 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
507# endif
508 wlv->p_extra = NULL;
509 wlv->c_extra = ' ';
510 wlv->c_final = NUL;
511 wlv->n_extra = get_breakindent_win(wp,
512 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
513 if (wlv->row == wlv->startrow)
514 {
515 wlv->n_extra -= win_col_off2(wp);
516 if (wlv->n_extra < 0)
517 wlv->n_extra = 0;
518 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100519 if (wp->w_skipcol > 0 && wlv->startrow == 0
520 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100521 wlv->need_showbreak = FALSE;
522 // Correct end of highlighted area for 'breakindent',
523 // required when 'linebreak' is also set.
524 if (wlv->tocol == wlv->vcol)
525 wlv->tocol += wlv->n_extra;
526 }
527 }
528}
529#endif
530
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100531#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
532 static void
533handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
534{
535# ifdef FEAT_DIFF
536 if (wlv->filler_todo > 0)
537 {
538 // Draw "deleted" diff line(s).
539 if (char2cells(wp->w_fill_chars.diff) > 1)
540 {
541 wlv->c_extra = '-';
542 wlv->c_final = NUL;
543 }
544 else
545 {
546 wlv->c_extra = wp->w_fill_chars.diff;
547 wlv->c_final = NUL;
548 }
549# ifdef FEAT_RIGHTLEFT
550 if (wp->w_p_rl)
551 wlv->n_extra = wlv->col + 1;
552 else
553# endif
554 wlv->n_extra = wp->w_width - wlv->col;
555 wlv->char_attr = HL_ATTR(HLF_DED);
556 }
557# endif
558
559# ifdef FEAT_LINEBREAK
560 char_u *sbr = get_showbreak_value(wp);
561 if (*sbr != NUL && wlv->need_showbreak)
562 {
563 // Draw 'showbreak' at the start of each broken line.
564 wlv->p_extra = sbr;
565 wlv->c_extra = NUL;
566 wlv->c_final = NUL;
567 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100568 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100569 wlv->need_showbreak = FALSE;
570 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
571 // Correct end of highlighted area for 'showbreak',
572 // required when 'linebreak' is also set.
573 if (wlv->tocol == wlv->vcol)
574 wlv->tocol += wlv->n_extra;
575 // combine 'showbreak' with 'wincolor'
576 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
577# ifdef FEAT_SYN_HL
578 // combine 'showbreak' with 'cursorline'
579 if (wlv->cul_attr != 0)
580 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
581# endif
582 }
583# endif
584}
585#endif
586
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100587#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100588/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100589 * Return the cell size of virtual text after truncation.
590 */
591 static int
592textprop_size_after_trunc(
593 win_T *wp,
594 int flags, // TP_FLAG_ALIGN_*
595 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100596 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100597 char_u *text,
598 int *n_used_ptr)
599{
600 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100601 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100602 int len = (int)STRLEN(text);
603 int strsize = 0;
604 int n_used;
605
Bram Moolenaar7e017462022-10-11 21:02:09 +0100606 // if the remaining size is to small and 'wrap' is set we wrap anyway and
607 // use the next line
608 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100609 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100610 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100611 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100612 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
613 {
614 int clen = ptr2cells(text + n_used);
615
616 if (strsize + clen > space)
617 break;
618 strsize += clen;
619 }
620 *n_used_ptr = n_used;
621 return strsize;
622}
623
624/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100625 * Take care of padding, right-align and truncation of virtual text after a
626 * line.
627 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
628 * padding, right-align and truncation. Otherwise only the size is computed.
629 * When "n_attr" is NULL returns the number of screen cells used.
630 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100631 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100632 int
633text_prop_position(
634 win_T *wp,
635 textprop_T *tp,
porygonisaduck38854b52022-11-27 20:55:05 +0000636 int vcol, // current text column
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100637 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100638 int *n_extra, // nr of bytes for virtual text
639 char_u **p_extra, // virtual text
640 int *n_attr, // attribute cells, NULL if not used
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000641 int *n_attr_skip, // cells to skip attr, NULL if not used
642 int do_skip) // skip_cells is not zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200643{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100644 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100645 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100646 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
Bram Moolenaar1aeb3eb2023-01-01 14:04:51 +0000647 int wrap = tp->tp_col < MAXCOL || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100648 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
porygonisaduck38854b52022-11-27 20:55:05 +0000649 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100650 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100651 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100652 int before = room; // spaces before the text
653 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100654 int n_used = *n_extra;
655 char_u *l = NULL;
656 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100657 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100658 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200659
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100660 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100661 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100662 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100663
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100664 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100665 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100666 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100667 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100668 }
669 else
670 {
671 // Right-align: fill with before
672 if (right)
673 before -= cells;
porygonisaduck38854b52022-11-27 20:55:05 +0000674
675 // Below-align: empty line add one character
Bram Moolenaar7c02ad92022-11-29 21:37:13 +0000676 if (below && vcol == 0 && col_with_padding == col_off
677 && wp->w_width - col_off == before)
678 col_with_padding += 1;
porygonisaduck38854b52022-11-27 20:55:05 +0000679
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100680 if (before < 0
681 || !(right || below)
porygonisaduck38854b52022-11-27 20:55:05 +0000682 || (below ? (col_with_padding <= col_off || !wp->w_p_wrap)
683 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100684 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100685 if (right && (wrap
686 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100687 {
688 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100689 before = wp->w_width - col_off - strsize + room;
690 if (before < 0)
691 before = 0;
692 else
693 n_used = *n_extra;
694 }
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000695 else if (below && before > vcol && do_skip)
696 before -= vcol;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100697 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100698 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100699 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100700 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100701
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100702 // With 'nowrap' add one to show the "extends" character if needed (it
703 // doesn't show if the text just fits).
704 if (!wp->w_p_wrap
705 && n_used < *n_extra
706 && wp->w_lcs_chars.ext != NUL
707 && wp->w_p_list)
708 ++n_used;
709
710 // add 1 for NUL, 2 for when '…' is used
711 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100712 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100713 if (n_attr == NULL || l != NULL)
714 {
715 int off = 0;
716
717 if (n_attr != NULL)
718 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100719 vim_memset(l, ' ', before);
720 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100721 if (padding > 0)
722 {
723 vim_memset(l + off, ' ', padding);
724 off += padding;
725 }
726 vim_strncpy(l + off, *p_extra, n_used);
727 off += n_used;
728 }
729 else
730 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100731 off = before + after + padding + n_used;
732 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100733 }
734 if (n_attr != NULL)
735 {
736 if (n_used < *n_extra && wp->w_p_wrap)
737 {
738 char_u *lp = l + off - 1;
739
740 if (has_mbyte)
741 {
742 // change last character to '…'
743 lp -= (*mb_head_off)(l, lp);
744 STRCPY(lp, "…");
Bram Moolenaar13845c42022-10-09 15:26:03 +0100745 n_used = lp - l + 3 - before - padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100746 }
747 else
748 // change last character to '>'
749 *lp = '>';
750 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100751 else if (after > 0)
752 {
753 vim_memset(l + off, ' ', after);
754 l[off + after] = NUL;
755 }
756
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100757 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100758 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100759 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100760 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100761 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100762
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000763 // n_attr_skip will not be decremented before draw_state is
764 // WL_LINE
765 *n_attr_skip = before + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100766 }
767 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100768 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100769
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100770 if (n_attr == NULL)
771 return cells;
772 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200773}
774#endif
775
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100776/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100777 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100778 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
779 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100780 */
781 static void
782wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
783{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100784 if (wlv->row == 0 && wp->w_skipcol > 0
785#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100786 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100787 && *get_showbreak_value(wp) == NUL
788#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100789 // do not overwrite the 'listchars' "precedes" text with "<<<"
790 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100791 {
792 int off = (int)(current_ScreenLine - ScreenLines);
Bram Moolenaareb4de622022-10-15 13:42:17 +0100793 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100794
Bram Moolenaareb4de622022-10-15 13:42:17 +0100795 if (wp->w_p_nu && wp->w_p_rnu)
796 // Do not overwrite the line number, change "123 text" to
797 // "123>>>xt".
798 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
799 {
800 ++off;
801 ++skip;
802 }
803
804 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100805 {
806 ScreenLines[off] = '<';
807 if (enc_utf8)
808 ScreenLinesUC[off] = 0;
809 ScreenAttrs[off] = HL_ATTR(HLF_AT);
810 ++off;
811 }
812 }
813
814 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
815 negative_width ? -wp->w_width : wp->w_width,
816 wlv->screen_line_flags);
817}
818
819/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100820 * Called when finished with the line: draw the screen line and handle any
821 * highlighting until the right of the window.
822 */
823 static void
824draw_screen_line(win_T *wp, winlinevars_T *wlv)
825{
826#ifdef FEAT_SYN_HL
827 long v;
828
829 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
830 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100831 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100832 else
833 v = wp->w_leftcol;
834
835 // check if line ends before left margin
836 if (wlv->vcol < v + wlv->col - win_col_off(wp))
837 wlv->vcol = v + wlv->col - win_col_off(wp);
838# ifdef FEAT_CONCEAL
839 // Get rid of the boguscols now, we want to draw until the right
840 // edge for 'cursorcolumn'.
841 wlv->col -= wlv->boguscols;
842 wlv->boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000843# define VCOL_HLC (wlv->vcol - wlv->vcol_off_co - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100844# else
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000845# define VCOL_HLC (wlv->vcol - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100846# endif
847
848 if (wlv->draw_color_col)
849 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
850
851 if (((wp->w_p_cuc
852 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
853 && (int)wp->w_virtcol <
854 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
855 && wlv->lnum != wp->w_cursor.lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000856 || wlv->draw_color_col
857# ifdef LINE_ATTR
858 || wlv->line_attr != 0
859# endif
860 || wlv->win_attr != 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100861# ifdef FEAT_RIGHTLEFT
862 && !wp->w_p_rl
863# endif
864 )
865 {
866 int rightmost_vcol = 0;
867 int i;
868
869 if (wp->w_p_cuc)
870 rightmost_vcol = wp->w_virtcol;
871 if (wlv->draw_color_col)
872 // determine rightmost colorcolumn to possibly draw
873 for (i = 0; wlv->color_cols[i] >= 0; ++i)
874 if (rightmost_vcol < wlv->color_cols[i])
875 rightmost_vcol = wlv->color_cols[i];
876
877 while (wlv->col < wp->w_width)
878 {
879 ScreenLines[wlv->off] = ' ';
880 if (enc_utf8)
881 ScreenLinesUC[wlv->off] = 0;
882 ScreenCols[wlv->off] = MAXCOL;
883 ++wlv->col;
884 if (wlv->draw_color_col)
885 wlv->draw_color_col = advance_color_col(
886 VCOL_HLC, &wlv->color_cols);
887
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000888 int attr = wlv->win_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100889 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000890 attr = HL_ATTR(HLF_CUC);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100891 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000892 attr = HL_ATTR(HLF_MC);
893# ifdef LINE_ATTR
894 else if (wlv->line_attr != 0)
895 attr = wlv->line_attr;
896# endif
897 ScreenAttrs[wlv->off++] = attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100898
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000899 if (VCOL_HLC >= rightmost_vcol
900# ifdef LINE_ATTR
901 && wlv->line_attr == 0
902# endif
903 && wlv->win_attr == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100904 break;
905
906 ++wlv->vcol;
907 }
908 }
909#endif
910
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100911 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100912 ++wlv->row;
913 ++wlv->screen_row;
914}
915#undef VCOL_HLC
916
917/*
918 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100919 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100920 */
921 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100922win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100923{
924 wlv->col = 0;
925 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
926
927#ifdef FEAT_RIGHTLEFT
928 if (wp->w_p_rl)
929 {
930 // Rightleft window: process the text in the normal direction, but put
931 // it in current_ScreenLine[] from right to left. Start at the
932 // rightmost column of the window.
933 wlv->col = wp->w_width - 1;
934 wlv->off += wlv->col;
935 wlv->screen_line_flags |= SLF_RIGHTLEFT;
936 }
937#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100938 if (save_extra)
939 {
940 // reset the drawing state for the start of a wrapped line
941 wlv->draw_state = WL_START;
942 wlv->saved_n_extra = wlv->n_extra;
943 wlv->saved_p_extra = wlv->p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000944 wlv->saved_extra_attr = wlv->extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000945 wlv->saved_n_attr_skip = wlv->n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000946 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100947 wlv->saved_c_extra = wlv->c_extra;
948 wlv->saved_c_final = wlv->c_final;
949#ifdef FEAT_SYN_HL
950 if (!(wlv->cul_screenline
951# ifdef FEAT_DIFF
952 && wlv->diff_hlf == (hlf_T)0
953# endif
954 ))
955 wlv->saved_char_attr = wlv->char_attr;
956 else
957#endif
958 wlv->saved_char_attr = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000959
960 // these are not used until restored in win_line_continue()
Bram Moolenaar1306b362022-08-06 15:59:06 +0100961 wlv->n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000962 wlv->n_attr_skip = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100963 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100964}
965
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200966/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100967 * Called when wlv->draw_state is set to WL_LINE.
968 */
969 static void
970win_line_continue(winlinevars_T *wlv)
971{
972 if (wlv->saved_n_extra > 0)
973 {
974 // Continue item from end of wrapped line.
975 wlv->n_extra = wlv->saved_n_extra;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +0000976 wlv->saved_n_extra = 0;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100977 wlv->c_extra = wlv->saved_c_extra;
978 wlv->c_final = wlv->saved_c_final;
979 wlv->p_extra = wlv->saved_p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000980 wlv->extra_attr = wlv->saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000981 wlv->n_attr_skip = wlv->saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000982 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100983 wlv->char_attr = wlv->saved_char_attr;
984 }
985 else
986 wlv->char_attr = wlv->win_attr;
987}
988
zeertzjqb7acea12022-12-12 13:20:43 +0000989#ifdef FEAT_SYN_HL
990 static void
991apply_cursorline_highlight(
992 winlinevars_T *wlv,
993 int sign_present UNUSED)
994{
995 wlv->cul_attr = HL_ATTR(HLF_CUL);
996# ifdef FEAT_SIGNS
997 // Combine the 'cursorline' and sign highlighting, depending on
998 // the sign priority.
999 if (sign_present && wlv->sattr.sat_linehl > 0)
1000 {
1001 if (wlv->sattr.sat_priority >= 100)
1002 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1003 else
1004 wlv->line_attr = hl_combine_attr(wlv->line_attr, wlv->cul_attr);
1005 }
1006 else
1007# endif
1008# if defined(FEAT_QUICKFIX)
1009 // let the line attribute overrule 'cursorline', otherwise
1010 // it disappears when both have background set;
1011 // 'cursorline' can use underline or bold to make it show
1012 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1013# else
1014 wlv->line_attr = wlv->cul_attr;
1015# endif
1016}
1017#endif
1018
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001019/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001020 * Display line "lnum" of window 'wp' on the screen.
1021 * Start at row "startrow", stop when "endrow" is reached.
1022 * wp->w_virtcol needs to be valid.
1023 *
1024 * Return the number of last row the line occupies.
1025 */
1026 int
1027win_line(
1028 win_T *wp,
1029 linenr_T lnum,
1030 int startrow,
1031 int endrow,
1032 int nochange UNUSED, // not updating for changed text
1033 int number_only) // only update the number column
1034{
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001035 winlinevars_T wlv; // variables passed between functions
1036
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001037 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001038 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001039 char_u *line; // current line
1040 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001041
Bram Moolenaar1306b362022-08-06 15:59:06 +01001042#ifdef FEAT_PROP_POPUP
1043 char_u *p_extra_free2 = NULL; // another p_extra to be freed
1044#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001045#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001046 int in_linebreak = FALSE; // n_extra set for showing linebreak
1047#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001048 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +01001049 // displaying eol at end-of-line
1050 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001051 int lcs_prec_todo = wp->w_lcs_chars.prec;
1052 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001053
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001054 int n_attr = 0; // chars with special attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001055 int saved_attr2 = 0; // char_attr saved for n_attr
1056 int n_attr3 = 0; // chars with overruling special attr
1057 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001058
Bram Moolenaarcd105412022-10-10 19:50:42 +01001059 int n_skip = 0; // nr of cells to skip for 'nowrap' or
1060 // concealing
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001061#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001062 int skip_cells = 0; // nr of cells to skip for virtual text
1063 // after the line, when w_skipcol is
1064 // larger than the text length
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001065#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001066
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001067 int fromcol_prev = -2; // start of inverting after cursor
1068 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001069 int lnum_in_visual_area = FALSE;
1070 pos_T pos;
1071 long v;
1072
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001073 int attr_pri = FALSE; // char_attr has priority
1074 int area_highlighting = FALSE; // Visual or incsearch highlighting
1075 // in this line
1076 int vi_attr = 0; // attributes for Visual and incsearch
1077 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001078 int area_attr = 0; // attributes desired by highlighting
1079 int search_attr = 0; // attributes desired by 'hlsearch'
1080#ifdef FEAT_SYN_HL
1081 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1082 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001083 int prev_syntax_col = -1; // column of prev_syntax_attr
1084 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001085 int has_syntax = FALSE; // this buffer has syntax highl.
1086 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001087#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001088#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001089 int did_line = FALSE; // set to TRUE when line text done
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001090 int text_prop_count;
1091 int text_prop_next = 0; // next text property to use
1092 textprop_T *text_props = NULL;
1093 int *text_prop_idxs = NULL;
1094 int text_props_active = 0;
1095 proptype_T *text_prop_type = NULL;
1096 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001097 int text_prop_attr_comb = 0; // text_prop_attr combined with
1098 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001099 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001100 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001101 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001102 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001103 int saved_search_attr = 0; // search_attr to be used when n_extra
1104 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001105 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001106 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001107#endif
1108#ifdef FEAT_SPELL
1109 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001110 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001111# define SPWORDLEN 150
1112 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1113 int nextlinecol = 0; // column where nextline[] starts
1114 int nextline_idx = 0; // index in nextline[] where next line
1115 // starts
1116 int spell_attr = 0; // attributes desired by spelling
1117 int word_end = 0; // last byte with same spell_attr
1118 static linenr_T checked_lnum = 0; // line number for "checked_col"
1119 static int checked_col = 0; // column in "checked_lnum" up to which
1120 // there are no spell errors
1121 static int cap_col = -1; // column to check for Cap word
1122 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1123 int cur_checked_col = 0; // checked column for current line
1124#endif
1125 int extra_check = 0; // has extra highlighting
1126 int multi_attr = 0; // attributes desired by multibyte
1127 int mb_l = 1; // multi-byte byte length
1128 int mb_c = 0; // decoded multi-byte character
1129 int mb_utf8 = FALSE; // screen char is UTF-8 char
1130 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001131#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001132 int change_start = MAXCOL; // first col of changed area
1133 int change_end = -1; // last col of changed area
1134#endif
1135 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001136 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001137 int in_multispace = FALSE; // in multiple consecutive spaces
1138 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001139#ifdef LINE_ATTR
Bram Moolenaarbf915842022-08-06 22:38:02 +01001140 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001141#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001142 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001143 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001144#ifdef FEAT_ARABIC
1145 int prev_c = 0; // previous Arabic character
1146 int prev_c1 = 0; // first composing char for prev_c
1147#endif
1148#if defined(LINE_ATTR)
1149 int did_line_attr = 0;
1150#endif
1151#ifdef FEAT_TERMINAL
1152 int get_term_attr = FALSE;
1153#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001154
Martin Tournoijba43e762022-10-13 22:12:15 +01001155#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001156 // margin columns for the screen line, needed for when 'cursorlineopt'
1157 // contains "screenline"
1158 int left_curline_col = 0;
1159 int right_curline_col = 0;
1160#endif
1161
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001162#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1163 int feedback_col = 0;
1164 int feedback_old_attr = -1;
1165#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001166
1167#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1168 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001169#endif
1170#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001171 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001172#endif
1173#ifdef FEAT_CONCEAL
1174 int syntax_flags = 0;
1175 int syntax_seqnr = 0;
1176 int prev_syntax_id = 0;
1177 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1178 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001179 int did_wcol = FALSE;
1180 int old_boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001181# define VCOL_HLC (wlv.vcol - wlv.vcol_off_co - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001182# define FIX_FOR_BOGUSCOLS \
1183 { \
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001184 wlv.n_extra += wlv.vcol_off_co; \
1185 wlv.vcol -= wlv.vcol_off_co; \
1186 wlv.vcol_off_co = 0; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001187 wlv.col -= wlv.boguscols; \
1188 old_boguscols = wlv.boguscols; \
1189 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001190 }
1191#else
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001192# define VCOL_HLC (wlv.vcol - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001193#endif
1194
1195 if (startrow > endrow) // past the end already!
1196 return startrow;
1197
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001198 CLEAR_FIELD(wlv);
1199
1200 wlv.lnum = lnum;
1201 wlv.startrow = startrow;
1202 wlv.row = startrow;
1203 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001204 wlv.fromcol = -10;
1205 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001206#ifdef FEAT_LINEBREAK
1207 wlv.vcol_sbr = -1;
1208#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001209
1210 if (!number_only)
1211 {
1212 // To speed up the loop below, set extra_check when there is linebreak,
1213 // trailing white space and/or syntax processing to be done.
1214#ifdef FEAT_LINEBREAK
1215 extra_check = wp->w_p_lbr;
1216#endif
1217#ifdef FEAT_SYN_HL
1218 if (syntax_present(wp) && !wp->w_s->b_syn_error
1219# ifdef SYN_TIME_LIMIT
1220 && !wp->w_s->b_syn_slow
1221# endif
1222 )
1223 {
1224 // Prepare for syntax highlighting in this line. When there is an
1225 // error, stop syntax highlighting.
1226 save_did_emsg = did_emsg;
1227 did_emsg = FALSE;
1228 syntax_start(wp, lnum);
1229 if (did_emsg)
1230 wp->w_s->b_syn_error = TRUE;
1231 else
1232 {
1233 did_emsg = save_did_emsg;
1234#ifdef SYN_TIME_LIMIT
1235 if (!wp->w_s->b_syn_slow)
1236#endif
1237 {
1238 has_syntax = TRUE;
1239 extra_check = TRUE;
1240 }
1241 }
1242 }
1243
1244 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001245 wlv.color_cols = wp->w_p_cc_cols;
1246 if (wlv.color_cols != NULL)
1247 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001248#endif
1249
1250#ifdef FEAT_TERMINAL
1251 if (term_show_buffer(wp->w_buffer))
1252 {
1253 extra_check = TRUE;
1254 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001255 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001256 }
1257#endif
1258
1259#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001260 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001261 {
1262 // Prepare for spell checking.
1263 has_spell = TRUE;
1264 extra_check = TRUE;
1265
1266 // Get the start of the next line, so that words that wrap to the
1267 // next line are found too: "et<line-break>al.".
1268 // Trick: skip a few chars for C/shell/Vim comments
1269 nextline[SPWORDLEN] = NUL;
1270 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1271 {
1272 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1273 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1274 }
1275
1276 // When a word wrapped from the previous line the start of the
1277 // current line is valid.
1278 if (lnum == checked_lnum)
1279 cur_checked_col = checked_col;
1280 checked_lnum = 0;
1281
1282 // When there was a sentence end in the previous line may require a
1283 // word starting with capital in this line. In line 1 always check
1284 // the first word.
1285 if (lnum != capcol_lnum)
1286 cap_col = -1;
1287 if (lnum == 1)
1288 cap_col = 0;
1289 capcol_lnum = 0;
1290 }
1291#endif
1292
1293 // handle Visual active in this window
1294 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1295 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001296 pos_T *top, *bot;
1297
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001298 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1299 {
1300 // Visual is after curwin->w_cursor
1301 top = &curwin->w_cursor;
1302 bot = &VIsual;
1303 }
1304 else
1305 {
1306 // Visual is before curwin->w_cursor
1307 top = &VIsual;
1308 bot = &curwin->w_cursor;
1309 }
1310 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1311 if (VIsual_mode == Ctrl_V)
1312 {
1313 // block mode
1314 if (lnum_in_visual_area)
1315 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001316 wlv.fromcol = wp->w_old_cursor_fcol;
1317 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001318 }
1319 }
1320 else
1321 {
1322 // non-block mode
1323 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001324 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001325 else if (lnum == top->lnum)
1326 {
1327 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001328 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001329 else
1330 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001331 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001332 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001333 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001334 }
1335 }
1336 if (VIsual_mode != 'V' && lnum == bot->lnum)
1337 {
1338 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1339 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001340 wlv.fromcol = -10;
1341 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001342 }
1343 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001344 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001345 else
1346 {
1347 pos = *bot;
1348 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001349 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1350 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001351 else
1352 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001353 getvvcol(wp, &pos, NULL, NULL,
1354 (colnr_T *)&wlv.tocol);
1355 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001356 }
1357 }
1358 }
1359 }
1360
1361 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001362 if (!highlight_match && lnum == curwin->w_cursor.lnum
1363 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001364#ifdef FEAT_GUI
1365 && !gui.in_use
1366#endif
1367 )
1368 noinvcur = TRUE;
1369
1370 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001371 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001372 {
1373 area_highlighting = TRUE;
1374 vi_attr = HL_ATTR(HLF_V);
1375#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1376 if ((clip_star.available && !clip_star.owned
1377 && clip_isautosel_star())
1378 || (clip_plus.available && !clip_plus.owned
1379 && clip_isautosel_plus()))
1380 vi_attr = HL_ATTR(HLF_VNC);
1381#endif
1382 }
1383 }
1384
1385 // handle 'incsearch' and ":s///c" highlighting
1386 else if (highlight_match
1387 && wp == curwin
1388 && lnum >= curwin->w_cursor.lnum
1389 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1390 {
1391 if (lnum == curwin->w_cursor.lnum)
1392 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001393 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001394 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001395 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001396 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1397 {
1398 pos.lnum = lnum;
1399 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001400 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001401 }
1402 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001403 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001404 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001405 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1406 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001407 area_highlighting = TRUE;
1408 vi_attr = HL_ATTR(HLF_I);
1409 }
1410 }
1411
1412#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001413 wlv.filler_lines = diff_check(wp, lnum);
1414 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001415 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001416 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001417 {
1418 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001419 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001420 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001421 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001422 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001423 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001424 }
1425 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001426 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001427 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001428 area_highlighting = TRUE;
1429 }
1430 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001431 wlv.filler_lines = wp->w_topfill;
1432 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001433#endif
1434
1435#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001436 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001437 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001438 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001439#endif
1440
1441#ifdef LINE_ATTR
1442# ifdef FEAT_SIGNS
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001443 // If this line has a sign with line highlighting set wlv.line_attr.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001444 if (sign_present)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001445 wlv.line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001446# endif
1447# if defined(FEAT_QUICKFIX)
1448 // Highlight the current line in the quickfix window.
1449 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001450 wlv.line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001451# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001452 if (wlv.line_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001453 area_highlighting = TRUE;
1454#endif
1455
1456 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1457 ptr = line;
1458
1459#ifdef FEAT_SPELL
1460 if (has_spell && !number_only)
1461 {
1462 // For checking first word with a capital skip white space.
1463 if (cap_col == 0)
1464 cap_col = getwhitecols(line);
1465
1466 // To be able to spell-check over line boundaries copy the end of the
1467 // current line into nextline[]. Above the start of the next line was
1468 // copied to nextline[SPWORDLEN].
1469 if (nextline[SPWORDLEN] == NUL)
1470 {
1471 // No next line or it is empty.
1472 nextlinecol = MAXCOL;
1473 nextline_idx = 0;
1474 }
1475 else
1476 {
1477 v = (long)STRLEN(line);
1478 if (v < SPWORDLEN)
1479 {
1480 // Short line, use it completely and append the start of the
1481 // next line.
1482 nextlinecol = 0;
1483 mch_memmove(nextline, line, (size_t)v);
1484 STRMOVE(nextline + v, nextline + SPWORDLEN);
1485 nextline_idx = v + 1;
1486 }
1487 else
1488 {
1489 // Long line, use only the last SPWORDLEN bytes.
1490 nextlinecol = v - SPWORDLEN;
1491 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1492 nextline_idx = SPWORDLEN + 1;
1493 }
1494 }
1495 }
1496#endif
1497
1498 if (wp->w_p_list)
1499 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001500 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001501 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001502 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001503 || wp->w_lcs_chars.trail
1504 || wp->w_lcs_chars.lead
1505 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001506 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001507
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001508 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001509 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001510 {
1511 trailcol = (colnr_T)STRLEN(ptr);
1512 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1513 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001514 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001515 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001516 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001517 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001518 {
1519 leadcol = 0;
1520 while (VIM_ISWHITE(ptr[leadcol]))
1521 ++leadcol;
1522 if (ptr[leadcol] == NUL)
1523 // in a line full of spaces all of them are treated as trailing
1524 leadcol = (colnr_T)0;
1525 else
1526 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001527 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001528 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001529 }
1530
Bram Moolenaard7657e92022-09-20 18:59:30 +01001531 wlv.wcr_attr = get_wcr_attr(wp);
1532 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001533 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001534 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001535 area_highlighting = TRUE;
1536 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001537
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001538 // When w_skipcol is non-zero and there is virtual text above the actual
1539 // text, then this much of the virtual text is skipped.
1540 int skipcol_in_text_prop_above = 0;
1541
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001542#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001543 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001544 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001545
1546 char_u *prop_start;
1547 text_prop_count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE);
1548 if (text_prop_count > 0)
1549 {
1550 // Make a copy of the properties, so that they are properly
1551 // aligned.
1552 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1553 if (text_props != NULL)
1554 mch_memmove(text_props, prop_start,
1555 text_prop_count * sizeof(textprop_T));
1556
1557 // Allocate an array for the indexes.
1558 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1559 if (text_prop_idxs == NULL)
1560 VIM_CLEAR(text_props);
1561
1562 if (text_props != NULL)
1563 {
1564 area_highlighting = TRUE;
1565 extra_check = TRUE;
1566
1567 // When skipping virtual text the props need to be sorted. The
1568 // order is reversed!
1569 if (lnum == wp->w_topline && wp->w_skipcol > 0)
1570 {
1571 for (int i = 0; i < text_prop_count; ++i)
1572 text_prop_idxs[i] = i;
1573 sort_text_props(wp->w_buffer, text_props,
1574 text_prop_idxs, text_prop_count);
1575 }
1576
1577 // Text props "above" move the line number down to where the text
1578 // is. Only count the ones that are visible, not those that are
1579 // skipped because of w_skipcol.
1580 int text_width = wp->w_width - win_col_off(wp);
1581 for (int i = text_prop_count - 1; i >= 0; --i)
1582 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1583 {
1584 if (lnum == wp->w_topline
1585 && wp->w_skipcol - skipcol_in_text_prop_above
1586 >= text_width)
1587 {
1588 // This virtual text above is skipped, remove it from
1589 // the array.
1590 skipcol_in_text_prop_above += text_width;
1591 for (int j = i + 1; j < text_prop_count; ++j)
1592 text_props[j - 1] = text_props[j];
1593 ++i;
1594 --text_prop_count;
1595 }
1596 else
1597 ++wlv.text_prop_above_count;
1598 }
1599 }
1600 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001601#endif
1602
1603 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1604 // first character to be displayed.
1605 if (wp->w_p_wrap)
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001606 v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001607 else
1608 v = wp->w_leftcol;
1609 if (v > 0 && !number_only)
1610 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001611 char_u *prev_ptr = ptr;
1612 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001613 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001614
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001615 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001616 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001617 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001618 charsize = win_lbr_chartabsize(&cts, NULL);
1619 cts.cts_vcol += charsize;
1620 prev_ptr = cts.cts_ptr;
1621 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001622 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001623 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001624 ptr = cts.cts_ptr;
1625 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001626
1627 // When:
1628 // - 'cuc' is set, or
1629 // - 'colorcolumn' is set, or
1630 // - 'virtualedit' is set, or
1631 // - the visual mode is active,
1632 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001633 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001634#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001635 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001636#endif
1637 virtual_active() ||
1638 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001639 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001640
1641 // Handle a character that's not completely on the screen: Put ptr at
1642 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001643 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001644 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001645 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001646 ptr = prev_ptr;
1647 // If the character fits on the screen, don't need to skip it.
1648 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001649 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1650 && wlv.col == 0)
1651 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001652 }
1653
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001654#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001655 // If there the text doesn't reach to the desired column, need to skip
1656 // "skip_cells" cells when virtual text follows.
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001657 if ((!wp->w_p_wrap || (lnum == wp->w_topline && wp->w_skipcol > 0))
1658 && v > wlv.vcol)
Bram Moolenaarcd105412022-10-10 19:50:42 +01001659 skip_cells = v - wlv.vcol;
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001660#endif
Bram Moolenaarcd105412022-10-10 19:50:42 +01001661
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001662 // Adjust for when the inverted text is before the screen,
1663 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001664 if (wlv.tocol <= wlv.vcol)
1665 wlv.fromcol = 0;
1666 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1667 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001668
1669#ifdef FEAT_LINEBREAK
1670 // When w_skipcol is non-zero, first line needs 'showbreak'
1671 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001672 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001673#endif
1674#ifdef FEAT_SPELL
1675 // When spell checking a word we need to figure out the start of the
1676 // word and if it's badly spelled or not.
1677 if (has_spell)
1678 {
1679 int len;
1680 colnr_T linecol = (colnr_T)(ptr - line);
1681 hlf_T spell_hlf = HLF_COUNT;
1682
1683 pos = wp->w_cursor;
1684 wp->w_cursor.lnum = lnum;
1685 wp->w_cursor.col = linecol;
1686 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1687
1688 // spell_move_to() may call ml_get() and make "line" invalid
1689 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1690 ptr = line + linecol;
1691
1692 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1693 {
1694 // no bad word found at line start, don't check until end of a
1695 // word
1696 spell_hlf = HLF_COUNT;
1697 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1698 }
1699 else
1700 {
1701 // bad word found, use attributes until end of word
1702 word_end = wp->w_cursor.col + len + 1;
1703
1704 // Turn index into actual attributes.
1705 if (spell_hlf != HLF_COUNT)
1706 spell_attr = highlight_attr[spell_hlf];
1707 }
1708 wp->w_cursor = pos;
1709
1710# ifdef FEAT_SYN_HL
1711 // Need to restart syntax highlighting for this line.
1712 if (has_syntax)
1713 syntax_start(wp, lnum);
1714# endif
1715 }
1716#endif
1717 }
1718
1719 // Correct highlighting for cursor that can't be disabled.
1720 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001721 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001722 {
1723 if (noinvcur)
1724 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001725 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001726 {
1727 // highlighting starts at cursor, let it start just after the
1728 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001729 fromcol_prev = wlv.fromcol;
1730 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001731 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001732 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001733 // restart highlighting after the cursor
1734 fromcol_prev = wp->w_virtcol;
1735 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001736 if (wlv.fromcol >= wlv.tocol)
1737 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001738 }
1739
1740#ifdef FEAT_SEARCH_EXTRA
1741 if (!number_only)
1742 {
1743 v = (long)(ptr - line);
1744 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1745 &line, &screen_search_hl,
1746 &search_attr);
1747 ptr = line + v; // "line" may have been updated
1748 }
1749#endif
1750
1751#ifdef FEAT_SYN_HL
1752 // Cursor line highlighting for 'cursorline' in the current window.
1753 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1754 {
1755 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001756 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001757 if (!(wp == curwin && VIsual_active)
1758 && wp->w_p_culopt_flags != CULOPT_NBR)
1759 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001760 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001761 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1762
zeertzjqb7acea12022-12-12 13:20:43 +00001763 // Only apply CursorLine highlight here when "screenline" is not
1764 // present in 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001765 if (!wlv.cul_screenline)
zeertzjqb7acea12022-12-12 13:20:43 +00001766 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001767 else
1768 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001769 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001770 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1771 }
1772 area_highlighting = TRUE;
1773 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001774 }
1775#endif
1776
Bram Moolenaar1306b362022-08-06 15:59:06 +01001777 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001778
1779 // Repeat for the whole displayed line.
1780 for (;;)
1781 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001782 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001783#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001784 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001785#endif
1786#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001787 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001788#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001789
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001790 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001791 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001792 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001793#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001794 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001795 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001796 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001797 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001798 }
1799#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001800 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001801 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001802 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001803 if (cmdwin_type != 0 && wp == curwin)
1804 {
1805 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001806 wlv.n_extra = 1;
1807 wlv.c_extra = cmdwin_type;
1808 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001809 wlv.char_attr =
1810 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001811 }
1812 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001813#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001814 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001815 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001816 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001817 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001818 }
1819#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001820#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001821 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001822 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001823 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001824 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001825 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001826 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001827 }
1828#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001829 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001830 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001831 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001832 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001833 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001834 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001835#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001836 // Check if 'breakindent' applies and show it.
1837 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1838 if (wlv.n_extra == 0)
1839 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001840#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001841#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001842 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001843 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001844 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001845 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001846 }
1847#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001848 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001849 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001850 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001851 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001852 }
1853 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001854
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001855#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001856 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001857 && wlv.vcol >= left_curline_col
1858 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001859 {
zeertzjqb7acea12022-12-12 13:20:43 +00001860 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001861 }
1862#endif
1863
1864 // When still displaying '$' of change command, stop at cursor.
1865 // When only displaying the (relative) line number and that's done,
1866 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001867 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001868 && lnum == wp->w_cursor.lnum
1869 && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001870 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001871#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001872 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001873#endif
1874 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001875 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001876 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001877 // Pretend we have finished updating the window. Except when
1878 // 'cursorcolumn' is set.
1879#ifdef FEAT_SYN_HL
1880 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001881 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001882 else
1883#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001884 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001885 break;
1886 }
1887
Bram Moolenaar1306b362022-08-06 15:59:06 +01001888 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001889 {
1890 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001891 if (wlv.vcol == wlv.fromcol
1892 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1893 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001894 && (*mb_ptr2cells)(ptr) > 1)
1895 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001896 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001897 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001898 area_attr = vi_attr; // start highlighting
1899 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001900 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001901 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001902 area_attr = 0; // stop highlighting
1903
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001904#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001905 if (text_props != NULL)
1906 {
1907 int pi;
1908 int bcol = (int)(ptr - line);
1909
Bram Moolenaar1306b362022-08-06 15:59:06 +01001910 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001911# ifdef FEAT_LINEBREAK
1912 && !in_linebreak
1913# endif
1914 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001915 --bcol; // still working on the previous char, e.g. Tab
1916
1917 // Check if any active property ends.
1918 for (pi = 0; pi < text_props_active; ++pi)
1919 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001920 int tpi = text_prop_idxs[pi];
1921 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001922
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001923 // An inline property ends when after the start column plus
1924 // length. An "above" property ends when used and n_extra
1925 // is zero.
1926 if ((tp->tp_col != MAXCOL
1927 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001928 {
1929 if (pi + 1 < text_props_active)
1930 mch_memmove(text_prop_idxs + pi,
1931 text_prop_idxs + pi + 1,
1932 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001933 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001934 --text_props_active;
1935 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001936# ifdef FEAT_LINEBREAK
1937 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001938 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001939 syntax_attr = 0;
1940# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001941 }
1942 }
1943
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001944# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001945 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001946 // not on the next char yet, don't start another prop
1947 --bcol;
1948# endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001949 int display_text_first = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001950
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001951 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001952 // With 'nowrap' and not in the first screen line only "below"
1953 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001954 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001955 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001956 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001957 && (wp->w_p_wrap
1958 || wlv.row == startrow
1959 || (text_props[text_prop_next].tp_flags
1960 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001961 || (bcol == 0
1962 && (text_props[text_prop_next].tp_flags
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001963 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001964 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001965 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001966 if (text_props[text_prop_next].tp_col == MAXCOL
1967 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001968 + text_props[text_prop_next].tp_len)
1969 text_prop_idxs[text_props_active++] = text_prop_next;
1970 ++text_prop_next;
1971 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001972
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001973 if (wlv.n_extra == 0 || !wlv.extra_for_textprop)
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001974 {
1975 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001976 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001977 text_prop_flags = 0;
1978 text_prop_type = NULL;
1979 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001980 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001981 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001982 if (text_props_active > 0 && wlv.n_extra == 0
1983 && !display_text_first)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001984 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001985 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001986 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001987 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001988
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001989 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001990 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001991
1992 // Sort the properties on priority and/or starting last.
1993 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001994 sort_text_props(wp->w_buffer, text_props,
1995 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001996
1997 for (pi = 0; pi < text_props_active; ++pi)
1998 {
1999 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002000 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002001 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002002 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002003
Bram Moolenaarcd105412022-10-10 19:50:42 +01002004 // Only use a text property that can be displayed.
2005 // Skip "after" properties when wrap is off and at the
2006 // end of the window.
2007 if (pt != NULL
2008 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2009 && tp->tp_id != -MAXCOL
2010 && !(tp->tp_id < 0
2011 && !wp->w_p_wrap
2012 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2013 | TP_FLAG_ALIGN_ABOVE
2014 | TP_FLAG_ALIGN_BELOW)) == 0
2015 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002016 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002017 if (tp->tp_col == MAXCOL
2018 && *ptr == NUL
2019 && ((wp->w_p_list && lcs_eol_one > 0
2020 && (tp->tp_flags
2021 & TP_FLAG_ALIGN_ABOVE) == 0)
2022 || (ptr == line
2023 && !did_line
2024 && (tp->tp_flags
2025 & TP_FLAG_ALIGN_BELOW))))
2026 {
2027 // skip this prop, first display the '$' after
2028 // the line or display an empty line
2029 text_prop_follows = TRUE;
2030 if (used_tpi < 0)
2031 display_text_first = TRUE;
2032 continue;
2033 }
2034
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002035 if (pt->pt_hl_id > 0)
2036 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002037 text_prop_type = pt;
2038 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002039 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002040 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2041 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002042 text_prop_flags = pt->pt_flags;
2043 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002044 used_tpi = tpi;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002045 display_text_first = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002046 }
2047 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002048 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002049 && -text_prop_id
2050 <= wp->w_buffer->b_textprop_text.ga_len)
2051 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002052 textprop_T *tp = &text_props[used_tpi];
2053 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002054 ->b_textprop_text.ga_data)[
2055 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002056 int above = (tp->tp_flags
2057 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002058 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002059
2060 // reset the ID in the copy to avoid it being used
2061 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002062 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002063
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002064 if (p != NULL)
2065 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002066 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002067 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002068 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002069 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002070 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
2071 int padding = tp->tp_col == MAXCOL
2072 && tp->tp_len > 1
2073 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002074
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002075 // Insert virtual text before the current
2076 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002077 wlv.p_extra = p;
2078 wlv.c_extra = NUL;
2079 wlv.c_final = NUL;
2080 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002081 wlv.extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002082 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2083 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002084 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002085 // restore search_attr and area_attr when n_extra
2086 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01002087 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002088 saved_area_attr = area_attr;
2089 search_attr = 0;
2090 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002091 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002092 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002093 if (*ptr == NUL)
2094 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002095 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002096#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002097 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002098 {
2099 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002100 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002101 wlv.need_showbreak = FALSE;
2102 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002103 }
2104#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002105 if ((right || above || below || !wrap
2106 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002107 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002108 char_u *prev_p_extra = wlv.p_extra;
2109 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002110
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002111 // Take care of padding, right-align and
2112 // truncation.
2113 // Shared with win_lbr_chartabsize(), must do
2114 // exactly the same.
2115 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002116 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002117 wlv.col,
2118 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002119 &n_attr, &wlv.n_attr_skip,
2120 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002121 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002122 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002123 // wlv.p_extra was allocated
2124 vim_free(p_extra_free2);
2125 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002126 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002127
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002128 if (above)
2129 wlv.vcol_off_tp = wlv.n_extra;
2130
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002131 if (lcs_eol_one < 0
2132 && wp->w_p_wrap
2133 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002134 + wlv.n_extra - 2 > wp->w_width)
2135 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002136 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002137
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002138 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002139 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002140 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002141 {
2142 draw_screen_line(wp, &wlv);
2143
2144 // When line got too long for screen break
2145 // here.
2146 if (wlv.row == endrow)
2147 {
2148 ++wlv.row;
2149 break;
2150 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002151 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002152 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002153 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002154 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002155 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002156
Bram Moolenaarcd105412022-10-10 19:50:42 +01002157 // If the text didn't reach until the first window
2158 // column we need to skip cells.
2159 if (skip_cells > 0)
2160 {
2161 if (wlv.n_extra > skip_cells)
2162 {
2163 wlv.n_extra -= skip_cells;
2164 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002165 wlv.n_attr_skip -= skip_cells;
2166 if (wlv.n_attr_skip < 0)
2167 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002168 skip_cells = 0;
2169 }
2170 else
2171 {
2172 // the whole text is left of the window, drop
2173 // it and advance to the next one
2174 skip_cells -= wlv.n_extra;
2175 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002176 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002177 bail_out = TRUE;
2178 }
2179 }
2180
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002181 // If another text prop follows the condition below at
2182 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002183 // If this is an "above" text prop and 'nowrap' the we
2184 // must wrap anyway.
2185 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002186 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002187 && (wp->w_p_wrap
2188 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002189 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002190
2191 if (bail_out)
2192 // starting a new line for "below"
2193 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002194 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002195 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002196 else if (text_prop_next < text_prop_count
2197 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002198 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2199 || (!wp->w_p_wrap
2200 && wlv.col == wp->w_width - 1
2201 && (text_props[text_prop_next].tp_flags
2202 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002203 // When at last-but-one character and a text property
2204 // follows after it, we may need to flush the line after
2205 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002206 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002207 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002208 }
2209#endif
2210
Bram Moolenaare38fc862022-08-11 17:24:50 +01002211#ifdef FEAT_SEARCH_EXTRA
2212 if (wlv.n_extra == 0)
2213 {
2214 // Check for start/end of 'hlsearch' and other matches.
2215 // After end, check for start/end of next match.
2216 // When another match, have to check for start again.
2217 v = (long)(ptr - line);
2218 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2219 &screen_search_hl, &has_match_conc,
2220 &match_conc, did_line_attr, lcs_eol_one,
2221 &on_last_col);
2222 ptr = line + v; // "line" may have been changed
2223 prev_ptr = ptr;
2224
2225 // Do not allow a conceal over EOL otherwise EOL will be missed
2226 // and bad things happen.
2227 if (*ptr == NUL)
2228 has_match_conc = 0;
2229 }
2230#endif
2231
2232#ifdef FEAT_DIFF
2233 if (wlv.diff_hlf != (hlf_T)0)
2234 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002235 // When there is extra text (e.g. virtual text) it gets the
2236 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002237 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2238 && wlv.n_extra == 0)
2239 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002240 if (wlv.diff_hlf == HLF_TXD
2241 && ((ptr - line > change_end && wlv.n_extra == 0)
2242 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002243 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002244 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002245 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2246 && wp->w_p_culopt_flags != CULOPT_NBR
2247 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2248 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002249 wlv.line_attr = hl_combine_attr(
2250 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002251 }
2252#endif
2253
Bram Moolenaara74fda62019-10-19 17:38:03 +02002254#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002255 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002256 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002257 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002258# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002259 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002260 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002261# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002262 // Get syntax attribute.
2263 if (has_syntax)
2264 {
2265 // Get the syntax attribute for the character. If there
2266 // is an error, disable syntax highlighting.
2267 save_did_emsg = did_emsg;
2268 did_emsg = FALSE;
2269
2270 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002271 if (v == prev_syntax_col)
2272 // at same column again
2273 syntax_attr = prev_syntax_attr;
2274 else
2275 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002276# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002277 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002278# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002279 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002280# ifdef FEAT_SPELL
2281 has_spell ? &can_spell :
2282# endif
2283 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002284 prev_syntax_col = v;
2285 prev_syntax_attr = syntax_attr;
2286 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002287
Bram Moolenaar34390282019-10-16 14:38:26 +02002288 if (did_emsg)
2289 {
2290 wp->w_s->b_syn_error = TRUE;
2291 has_syntax = FALSE;
2292 syntax_attr = 0;
2293 }
2294 else
2295 did_emsg = save_did_emsg;
2296# ifdef SYN_TIME_LIMIT
2297 if (wp->w_s->b_syn_slow)
2298 has_syntax = FALSE;
2299# endif
2300
2301 // Need to get the line again, a multi-line regexp may
2302 // have made it invalid.
2303 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2304 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002305 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002306# ifdef FEAT_CONCEAL
2307 // no concealing past the end of the line, it interferes
2308 // with line highlighting
2309 if (*ptr == NUL)
2310 syntax_flags = 0;
2311 else
2312 syntax_flags = get_syntax_info(&syntax_seqnr);
2313# endif
2314 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002315 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002316# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002317 // Combine text property highlight into syntax highlight.
2318 if (text_prop_type != NULL)
2319 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002320 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002321 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2322 else
2323 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002324 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002325 }
2326# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002327#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002328
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002329 // Decide which of the highlight attributes to use.
2330 attr_pri = TRUE;
2331#ifdef LINE_ATTR
2332 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002333 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002334 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002335 if (!highlight_match)
2336 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002337 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002338# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002339 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002340# endif
2341 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002342 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002343 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002344 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002345# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002346 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002347# endif
2348 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002349 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002350 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2351 || wlv.vcol < wlv.fromcol
2352 || vcol_prev < fromcol_prev
2353 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002354 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002355 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002356 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002357# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002358 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002359# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002360 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002361# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002362 attr_pri = FALSE;
2363 }
2364#else
2365 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002366 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002367 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002368 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002369#endif
2370 else
2371 {
2372 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002373#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002374 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002375#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002376 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002377#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002378 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002379#ifdef FEAT_PROP_POPUP
2380 // override with text property highlight when "override" is TRUE
2381 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002382 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002383#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002384 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002385
2386 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002387 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002388 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002389 if (wlv.char_attr == 0)
2390 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002391 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002392 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002393 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002394
2395 // Get the next character to put on the screen.
2396
2397 // The "p_extra" points to the extra stuff that is inserted to
2398 // represent special characters (non-printable stuff) and other
2399 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002400 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002401 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2402 // "p_extra[n_extra]".
2403 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002404 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002405 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002406 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002407 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002408 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2409 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002410 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2411 if (enc_utf8 && utf_char2len(c) > 1)
2412 {
2413 mb_utf8 = TRUE;
2414 u8cc[0] = 0;
2415 c = 0xc0;
2416 }
2417 else
2418 mb_utf8 = FALSE;
2419 }
2420 else
2421 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002422 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002423 if (has_mbyte)
2424 {
2425 mb_c = c;
2426 if (enc_utf8)
2427 {
2428 // If the UTF-8 character is more than one byte:
2429 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002430 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002431 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002432 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002433 mb_l = 1;
2434 else if (mb_l > 1)
2435 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002436 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002437 mb_utf8 = TRUE;
2438 c = 0xc0;
2439 }
2440 }
2441 else
2442 {
2443 // if this is a DBCS character, put it in "mb_c"
2444 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002445 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002446 mb_l = 1;
2447 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002448 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002449 }
2450 if (mb_l == 0) // at the NUL at end-of-line
2451 mb_l = 1;
2452
2453 // If a double-width char doesn't fit display a '>' in the
2454 // last column.
2455 if ((
2456# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002457 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002458# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002459 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002460 && (*mb_char2cells)(mb_c) == 2)
2461 {
2462 c = '>';
2463 mb_c = c;
2464 mb_l = 1;
2465 mb_utf8 = FALSE;
2466 multi_attr = HL_ATTR(HLF_AT);
2467#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002468 if (wlv.cul_attr)
2469 multi_attr = hl_combine_attr(
2470 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002471#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002472 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002473
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002474 // put the pointer back to output the double-width
2475 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002476 ++wlv.n_extra;
2477 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002478 }
2479 else
2480 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002481 wlv.n_extra -= mb_l - 1;
2482 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002483 }
2484 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002485 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002486 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002487 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002488#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002489 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002490 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002491 // Only restore search_attr and area_attr after "n_extra" in
2492 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002493 if (wlv.saved_n_extra <= 0)
2494 {
2495 if (search_attr == 0)
2496 search_attr = saved_search_attr;
2497 if (area_attr == 0 && *ptr != NUL)
2498 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002499
2500 if (wlv.extra_for_textprop)
2501 // wlv.extra_attr should be used at this position but
2502 // not any further.
2503 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002504 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002505
2506 wlv.extra_for_textprop = FALSE;
2507 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002508 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002509#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002510 }
2511 else
2512 {
2513#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002514 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002515#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002516 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002517
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002518 // Get a character from the line itself.
2519 c = *ptr;
2520#ifdef FEAT_LINEBREAK
2521 c0 = *ptr;
2522#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002523#ifdef FEAT_PROP_POPUP
2524 if (c == NUL)
2525 // text is finished, may display a "below" virtual text
2526 did_line = TRUE;
2527#endif
2528
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002529 if (has_mbyte)
2530 {
2531 mb_c = c;
2532 if (enc_utf8)
2533 {
2534 // If the UTF-8 character is more than one byte: Decode it
2535 // into "mb_c".
2536 mb_l = utfc_ptr2len(ptr);
2537 mb_utf8 = FALSE;
2538 if (mb_l > 1)
2539 {
2540 mb_c = utfc_ptr2char(ptr, u8cc);
2541 // Overlong encoded ASCII or ASCII with composing char
2542 // is displayed normally, except a NUL.
2543 if (mb_c < 0x80)
2544 {
2545 c = mb_c;
2546#ifdef FEAT_LINEBREAK
2547 c0 = mb_c;
2548#endif
2549 }
2550 mb_utf8 = TRUE;
2551
2552 // At start of the line we can have a composing char.
2553 // Draw it as a space with a composing char.
2554 if (utf_iscomposing(mb_c))
2555 {
2556 int i;
2557
2558 for (i = Screen_mco - 1; i > 0; --i)
2559 u8cc[i] = u8cc[i - 1];
2560 u8cc[0] = mb_c;
2561 mb_c = ' ';
2562 }
2563 }
2564
2565 if ((mb_l == 1 && c >= 0x80)
2566 || (mb_l >= 1 && mb_c == 0)
2567 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2568 {
2569 // Illegal UTF-8 byte: display as <xx>.
2570 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002571 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002572# ifdef FEAT_RIGHTLEFT
2573 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002574 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002575# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002576 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002577 c = *wlv.p_extra;
2578 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002579 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002580 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2581 wlv.c_extra = NUL;
2582 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002583 if (area_attr == 0 && search_attr == 0)
2584 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002585 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002586 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002587 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002588 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002589 }
2590 }
2591 else if (mb_l == 0) // at the NUL at end-of-line
2592 mb_l = 1;
2593#ifdef FEAT_ARABIC
2594 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2595 {
2596 // Do Arabic shaping.
2597 int pc, pc1, nc;
2598 int pcc[MAX_MCO];
2599
2600 // The idea of what is the previous and next
2601 // character depends on 'rightleft'.
2602 if (wp->w_p_rl)
2603 {
2604 pc = prev_c;
2605 pc1 = prev_c1;
2606 nc = utf_ptr2char(ptr + mb_l);
2607 prev_c1 = u8cc[0];
2608 }
2609 else
2610 {
2611 pc = utfc_ptr2char(ptr + mb_l, pcc);
2612 nc = prev_c;
2613 pc1 = pcc[0];
2614 }
2615 prev_c = mb_c;
2616
2617 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2618 }
2619 else
2620 prev_c = mb_c;
2621#endif
2622 }
2623 else // enc_dbcs
2624 {
2625 mb_l = MB_BYTE2LEN(c);
2626 if (mb_l == 0) // at the NUL at end-of-line
2627 mb_l = 1;
2628 else if (mb_l > 1)
2629 {
2630 // We assume a second byte below 32 is illegal.
2631 // Hopefully this is OK for all double-byte encodings!
2632 if (ptr[1] >= 32)
2633 mb_c = (c << 8) + ptr[1];
2634 else
2635 {
2636 if (ptr[1] == NUL)
2637 {
2638 // head byte at end of line
2639 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002640 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002641 }
2642 else
2643 {
2644 // illegal tail byte
2645 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002646 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002647 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002648 wlv.p_extra = wlv.extra;
2649 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002650 wlv.c_extra = NUL;
2651 wlv.c_final = NUL;
2652 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002653 if (area_attr == 0 && search_attr == 0)
2654 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002655 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002656 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002657 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002658 // save current attr
2659 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002660 }
2661 mb_c = c;
2662 }
2663 }
2664 }
2665 // If a double-width char doesn't fit display a '>' in the
2666 // last column; the character is displayed at the start of the
2667 // next line.
2668 if ((
2669# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002670 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002671# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002672 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002673 && (*mb_char2cells)(mb_c) == 2)
2674 {
2675 c = '>';
2676 mb_c = c;
2677 mb_utf8 = FALSE;
2678 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002679 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002680 // Put pointer back so that the character will be
2681 // displayed at the start of the next line.
2682 --ptr;
2683#ifdef FEAT_CONCEAL
2684 did_decrement_ptr = TRUE;
2685#endif
2686 }
2687 else if (*ptr != NUL)
2688 ptr += mb_l - 1;
2689
2690 // If a double-width char doesn't fit at the left side display
2691 // a '<' in the first column. Don't do this for unprintable
2692 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002693 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002694 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002695 wlv.n_extra = 1;
2696 wlv.c_extra = MB_FILLER_CHAR;
2697 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002698 c = ' ';
2699 if (area_attr == 0 && search_attr == 0)
2700 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002701 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002702 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002703 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002704 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002705 }
2706 mb_c = c;
2707 mb_utf8 = FALSE;
2708 mb_l = 1;
2709 }
2710
2711 }
2712 ++ptr;
2713
2714 if (extra_check)
2715 {
2716#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002717 // Check spelling (unless at the end of the line).
2718 // Only do this when there is no syntax highlighting, the
2719 // @Spell cluster is not used or the current syntax item
2720 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002721 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002722 if (has_spell && v >= word_end && v > cur_checked_col)
2723 {
2724 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002725 // do not calculate cap_col at the end of the line or when
2726 // only white space is following
2727 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002728# ifdef FEAT_SYN_HL
2729 !has_syntax ||
2730# endif
2731 can_spell))
2732 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002733 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002734 int len;
2735 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002736
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002737 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002738 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002739
2740 // Use nextline[] if possible, it has the start of the
2741 // next line concatenated.
2742 if ((prev_ptr - line) - nextlinecol >= 0)
2743 p = nextline + (prev_ptr - line) - nextlinecol;
2744 else
2745 p = prev_ptr;
2746 cap_col -= (int)(prev_ptr - line);
2747 len = spell_check(wp, p, &spell_hlf, &cap_col,
2748 nochange);
2749 word_end = v + len;
2750
2751 // In Insert mode only highlight a word that
2752 // doesn't touch the cursor.
2753 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002754 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002755 && wp->w_cursor.lnum == lnum
2756 && wp->w_cursor.col >=
2757 (colnr_T)(prev_ptr - line)
2758 && wp->w_cursor.col < (colnr_T)word_end)
2759 {
2760 spell_hlf = HLF_COUNT;
2761 spell_redraw_lnum = lnum;
2762 }
2763
2764 if (spell_hlf == HLF_COUNT && p != prev_ptr
2765 && (p - nextline) + len > nextline_idx)
2766 {
2767 // Remember that the good word continues at the
2768 // start of the next line.
2769 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002770 checked_col = (int)((p - nextline)
2771 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002772 }
2773
2774 // Turn index into actual attributes.
2775 if (spell_hlf != HLF_COUNT)
2776 spell_attr = highlight_attr[spell_hlf];
2777
2778 if (cap_col > 0)
2779 {
2780 if (p != prev_ptr
2781 && (p - nextline) + cap_col >= nextline_idx)
2782 {
2783 // Remember that the word in the next line
2784 // must start with a capital.
2785 capcol_lnum = lnum + 1;
2786 cap_col = (int)((p - nextline) + cap_col
2787 - nextline_idx);
2788 }
2789 else
2790 // Compute the actual column.
2791 cap_col += (int)(prev_ptr - line);
2792 }
2793 }
2794 }
2795 if (spell_attr != 0)
2796 {
2797 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002798 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2799 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002800 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002801 wlv.char_attr = hl_combine_attr(spell_attr,
2802 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002803 }
2804#endif
2805#ifdef FEAT_LINEBREAK
2806 // Found last space before word: check for line break.
2807 if (wp->w_p_lbr && c0 == c
2808 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2809 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002810 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2811 : 0;
2812 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002813 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002814
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002815 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002816# ifdef FEAT_PROP_POPUP
2817 // do not want virtual text counted here
2818 cts.cts_has_prop_with_text = FALSE;
2819# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002820 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002821 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002822
2823 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002824 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002825 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002826 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002827 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2828 if (wlv.n_extra < 0)
2829 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002830 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002831 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002832 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002833 // line break, but for TABs the highlighting should
2834 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002835 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002836
Bram Moolenaar1306b362022-08-06 15:59:06 +01002837 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002838# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002839 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002840 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002841 wp->w_buffer->b_p_vts_array) - 1;
2842# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002843 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002844 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002845# endif
2846
Bram Moolenaar1306b362022-08-06 15:59:06 +01002847 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2848 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002849# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002850 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002851 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002852# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002853 if (VIM_ISWHITE(c))
2854 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002855# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002856 if (c == TAB)
2857 // See "Tab alignment" below.
2858 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002859# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002860 if (!wp->w_p_list)
2861 c = ' ';
2862 }
2863 }
2864#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002865 in_multispace = c == ' '
2866 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2867 if (!in_multispace)
2868 multispace_pos = 0;
2869
Bram Moolenaareed9d462021-02-15 20:38:25 +01002870 // 'list': Change char 160 to 'nbsp' and space to 'space'
2871 // setting in 'listchars'. But not when the character is
2872 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002873 if (wp->w_p_list
2874 && ((((c == 160 && mb_l == 1)
2875 || (mb_utf8
2876 && ((mb_c == 160 && mb_l == 2)
2877 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002878 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002879 || (c == ' '
2880 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002881 && (wp->w_lcs_chars.space
2882 || (in_multispace
2883 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002884 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002885 && ptr - line <= trailcol)))
2886 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002887 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2888 {
2889 c = wp->w_lcs_chars.multispace[multispace_pos++];
2890 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2891 multispace_pos = 0;
2892 }
2893 else
2894 c = (c == ' ') ? wp->w_lcs_chars.space
2895 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002896 if (area_attr == 0 && search_attr == 0)
2897 {
2898 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002899 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002900 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002901 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002902 }
2903 mb_c = c;
2904 if (enc_utf8 && utf_char2len(c) > 1)
2905 {
2906 mb_utf8 = TRUE;
2907 u8cc[0] = 0;
2908 c = 0xc0;
2909 }
2910 else
2911 mb_utf8 = FALSE;
2912 }
2913
zeertzjq2e7cba32022-06-10 15:30:32 +01002914 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2915 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002916 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002917 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2918 && wp->w_lcs_chars.leadmultispace != NULL)
2919 {
2920 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002921 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2922 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002923 multispace_pos = 0;
2924 }
2925
2926 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2927 c = wp->w_lcs_chars.trail;
2928
2929 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2930 c = wp->w_lcs_chars.lead;
2931
zeertzjq2e7cba32022-06-10 15:30:32 +01002932 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002933 c = wp->w_lcs_chars.space;
2934
2935
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002936 if (!attr_pri)
2937 {
2938 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002939 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002940 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002941 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002942 }
2943 mb_c = c;
2944 if (enc_utf8 && utf_char2len(c) > 1)
2945 {
2946 mb_utf8 = TRUE;
2947 u8cc[0] = 0;
2948 c = 0xc0;
2949 }
2950 else
2951 mb_utf8 = FALSE;
2952 }
2953 }
2954
2955 // Handling of non-printable characters.
2956 if (!vim_isprintc(c))
2957 {
2958 // when getting a character from the file, we may have to
2959 // turn it into something else on the way to putting it
2960 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002961 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002962 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002963 int tab_len = 0;
2964 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002965#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002966 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01002967
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002968 // only adjust the tab_len, when at the first column
2969 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002970 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002971 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002972#endif
2973 // tab amount depends on current column
2974#ifdef FEAT_VARTABS
2975 tab_len = tabstop_padding(vcol_adjusted,
2976 wp->w_buffer->b_p_ts,
2977 wp->w_buffer->b_p_vts_array) - 1;
2978#else
2979 tab_len = (int)wp->w_buffer->b_p_ts
2980 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2981#endif
2982
2983#ifdef FEAT_LINEBREAK
2984 if (!wp->w_p_lbr || !wp->w_p_list)
2985#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002986 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002987 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002988 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002989 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002990#ifdef FEAT_LINEBREAK
2991 else
2992 {
2993 char_u *p;
2994 int len;
2995 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002996 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002997
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002998# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002999 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003000 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003001 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003002
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003003 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003004 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003005 && old_boguscols > 0
3006 && wlv.n_extra > tab_len)
3007 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003008# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003009 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003010 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003011 // If wlv.n_extra > 0, it gives the number of chars
3012 // to use for a tab, else we need to calculate the
3013 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003014 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3015 len = tab_len * tab2_len;
3016 if (wp->w_lcs_chars.tab3)
3017 len += mb_char2len(wp->w_lcs_chars.tab3)
3018 - tab2_len;
3019 if (wlv.n_extra > 0)
3020 len += wlv.n_extra - tab_len;
3021 c = wp->w_lcs_chars.tab1;
3022 p = alloc(len + 1);
3023 if (p == NULL)
3024 wlv.n_extra = 0;
3025 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003026 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003027 vim_memset(p, ' ', len);
3028 p[len] = NUL;
3029 vim_free(wlv.p_extra_free);
3030 wlv.p_extra_free = p;
3031 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003032 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003033 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003034
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003035 if (*p == NUL)
3036 {
3037 tab_len = i;
3038 break;
3039 }
3040
3041 // if tab3 is given, use it for the last
3042 // char
3043 if (wp->w_lcs_chars.tab3
3044 && i == tab_len - 1)
3045 lcs = wp->w_lcs_chars.tab3;
3046 p += mb_char2bytes(lcs, p);
3047 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003048 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003049 }
3050 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003051# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003052 // n_extra will be increased by
3053 // FIX_FOX_BOGUSCOLS macro below, so need to
3054 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003055 if (wlv.vcol_off_co > 0)
3056 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003057# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003058 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003059 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003060 }
3061#endif
3062#ifdef FEAT_CONCEAL
3063 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003064 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003065
3066 // Tab alignment should be identical regardless of
3067 // 'conceallevel' value. So tab compensates of all
3068 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003069 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003070 // line. Note that the tab can be longer than
3071 // 'tabstop' when there are concealed characters.
3072 FIX_FOR_BOGUSCOLS;
3073
3074 // Make sure, the highlighting for the tab char will be
3075 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003076 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003077 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003078 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003079 tab_len += vc_saved;
3080 }
3081#endif
3082 mb_utf8 = FALSE; // don't draw as UTF-8
3083 if (wp->w_p_list)
3084 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003085 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003086 ? wp->w_lcs_chars.tab3
3087 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003088#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003089 if (wp->w_p_lbr && wlv.p_extra != NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003090 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003091 else
3092#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003093 wlv.c_extra = wp->w_lcs_chars.tab2;
3094 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003095 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003096 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003097 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003098 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003099 mb_c = c;
3100 if (enc_utf8 && utf_char2len(c) > 1)
3101 {
3102 mb_utf8 = TRUE;
3103 u8cc[0] = 0;
3104 c = 0xc0;
3105 }
3106 }
3107 else
3108 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003109 wlv.c_final = NUL;
3110 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003111 c = ' ';
3112 }
3113 }
3114 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003115 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003116 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003117 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3118 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003119 && VIsual_mode != Ctrl_V
3120 && (
3121# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003122 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003123# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003124 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003125 && !(noinvcur
3126 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003127 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003128 && lcs_eol_one > 0)
3129 {
3130 // Display a '$' after the line or highlight an extra
3131 // character if the line break is included.
3132#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3133 // For a diff line the highlighting continues after the
3134 // "$".
3135 if (
3136# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003137 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003138# ifdef LINE_ATTR
3139 &&
3140# endif
3141# endif
3142# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003143 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003144# endif
3145 )
3146#endif
3147 {
3148 // In virtualedit, visual selections may extend
3149 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003150 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003151 && wlv.tocol != MAXCOL
3152 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003153 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003154 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003155 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003156 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3157 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003158 else
3159 c = ' ';
3160 lcs_eol_one = -1;
3161 --ptr; // put it back at the NUL
3162 if (!attr_pri)
3163 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003164 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003165 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003166 n_attr = 1;
3167 }
3168 mb_c = c;
3169 if (enc_utf8 && utf_char2len(c) > 1)
3170 {
3171 mb_utf8 = TRUE;
3172 u8cc[0] = 0;
3173 c = 0xc0;
3174 }
3175 else
3176 mb_utf8 = FALSE; // don't draw as UTF-8
3177 }
3178 else if (c != NUL)
3179 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003180 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3181 if (wlv.n_extra == 0)
3182 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003183#ifdef FEAT_RIGHTLEFT
3184 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003185 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003186#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003187 wlv.c_extra = NUL;
3188 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003189#ifdef FEAT_LINEBREAK
3190 if (wp->w_p_lbr)
3191 {
3192 char_u *p;
3193
Bram Moolenaar1306b362022-08-06 15:59:06 +01003194 c = *wlv.p_extra;
3195 p = alloc(wlv.n_extra + 1);
3196 vim_memset(p, ' ', wlv.n_extra);
3197 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3198 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003199 vim_free(wlv.p_extra_free);
3200 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003201 }
3202 else
3203#endif
3204 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003205 wlv.n_extra = byte2cells(c) - 1;
3206 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003207 }
3208 if (!attr_pri)
3209 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003210 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003211 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003212 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003213 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003214 }
3215 mb_utf8 = FALSE; // don't draw as UTF-8
3216 }
3217 else if (VIsual_active
3218 && (VIsual_mode == Ctrl_V
3219 || VIsual_mode == 'v')
3220 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003221 && wlv.tocol != MAXCOL
3222 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003223 && (
3224#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003225 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003226#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003227 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003228 {
3229 c = ' ';
3230 --ptr; // put it back at the NUL
3231 }
3232#if defined(LINE_ATTR)
3233 else if ((
3234# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003235 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003236# endif
3237# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003238 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003239# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003240 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003241 ) && (
3242# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003243 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003244# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003245 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003246# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003247 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003248# endif
3249 < wp->w_width)))
3250 {
3251 // Highlight until the right side of the window
3252 c = ' ';
3253 --ptr; // put it back at the NUL
3254
3255 // Remember we do the char for line highlighting.
3256 ++did_line_attr;
3257
3258 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003259 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003260 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003261 || (wp->w_p_list &&
3262 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003263 wlv.char_attr = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003264# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003265 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003266 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003267 wlv.diff_hlf = HLF_CHD;
3268 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003269 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003270 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003271 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3272 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003273 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003274 || (wlv.vcol >= left_curline_col
3275 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003276 wlv.char_attr = hl_combine_attr(
3277 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003278 }
3279 }
3280# endif
3281# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003282 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003283 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003284 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003285 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3286 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003287 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003288 if (!wlv.cul_screenline
3289 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003290 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003291 wlv.char_attr = hl_combine_attr(
3292 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003293 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003294 else if (wlv.line_attr)
3295 wlv.char_attr = hl_combine_attr(
3296 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003297 }
3298# endif
3299 }
3300#endif
3301 }
3302
3303#ifdef FEAT_CONCEAL
3304 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003305 && (wp != curwin || lnum != wp->w_cursor.lnum
3306 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003307 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3308 && !(lnum_in_visual_area
3309 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3310 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003311 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003312 if (((prev_syntax_id != syntax_seqnr
3313 && (syntax_flags & HL_CONCEAL) != 0)
3314 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003315 && (syn_get_sub_char() != NUL
3316 || (has_match_conc && match_conc)
3317 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003318 && wp->w_p_cole != 3)
3319 {
3320 // First time at this concealed item: display one
3321 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003322 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003323 c = match_conc;
3324 else if (syn_get_sub_char() != NUL)
3325 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003326 else if (wp->w_lcs_chars.conceal != NUL)
3327 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003328 else
3329 c = ' ';
3330
3331 prev_syntax_id = syntax_seqnr;
3332
Bram Moolenaar1306b362022-08-06 15:59:06 +01003333 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003334 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003335 wlv.vcol += wlv.n_extra;
3336 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003337 {
3338# ifdef FEAT_RIGHTLEFT
3339 if (wp->w_p_rl)
3340 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003341 wlv.col -= wlv.n_extra;
3342 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003343 }
3344 else
3345# endif
3346 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003347 wlv.boguscols += wlv.n_extra;
3348 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003349 }
3350 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003351 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003352 n_attr = 0;
3353 }
3354 else if (n_skip == 0)
3355 {
3356 is_concealing = TRUE;
3357 n_skip = 1;
3358 }
3359 mb_c = c;
3360 if (enc_utf8 && utf_char2len(c) > 1)
3361 {
3362 mb_utf8 = TRUE;
3363 u8cc[0] = 0;
3364 c = 0xc0;
3365 }
3366 else
3367 mb_utf8 = FALSE; // don't draw as UTF-8
3368 }
3369 else
3370 {
3371 prev_syntax_id = 0;
3372 is_concealing = FALSE;
3373 }
3374
3375 if (n_skip > 0 && did_decrement_ptr)
3376 // not showing the '>', put pointer back to avoid getting stuck
3377 ++ptr;
3378
3379#endif // FEAT_CONCEAL
3380 }
3381
3382#ifdef FEAT_CONCEAL
3383 // In the cursor line and we may be concealing characters: correct
3384 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003385 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003386 && wp == curwin && lnum == wp->w_cursor.lnum
3387 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003388 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003389 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003390# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003391 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003392 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003393 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003394# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003395 wp->w_wcol = wlv.col - wlv.boguscols;
3396 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003397 did_wcol = TRUE;
3398 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003399# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003400 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003401# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003402 }
3403#endif
3404
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003405 // Use "wlv.extra_attr", but don't override visual selection
3406 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003407 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3408 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003409 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003410 && (!attr_pri
3411#ifdef FEAT_PROP_POPUP
3412 || (text_prop_flags & PT_FLAG_OVERRIDE)
3413#endif
3414 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003415 {
3416#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003417 if (wlv.line_attr)
3418 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003419 else
3420#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003421 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003422#ifdef FEAT_PROP_POPUP
3423 if (reset_extra_attr)
3424 {
3425 reset_extra_attr = FALSE;
3426 wlv.extra_attr = 0;
3427 }
3428#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003429 }
3430
3431#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3432 // XIM don't send preedit_start and preedit_end, but they send
3433 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3434 // im_is_preediting() here.
3435 if (p_imst == IM_ON_THE_SPOT
3436 && xic != NULL
3437 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003438 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003439 && !p_imdisable
3440 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003441 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003442 {
3443 colnr_T tcol;
3444
3445 if (preedit_end_col == MAXCOL)
3446 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3447 else
3448 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003449 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003450 {
3451 if (feedback_old_attr < 0)
3452 {
3453 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003454 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003455 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003456 wlv.char_attr = im_get_feedback_attr(feedback_col);
3457 if (wlv.char_attr < 0)
3458 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003459 feedback_col++;
3460 }
3461 else if (feedback_old_attr >= 0)
3462 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003463 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003464 feedback_old_attr = -1;
3465 feedback_col = 0;
3466 }
3467 }
3468#endif
3469 // Handle the case where we are in column 0 but not on the first
3470 // character of the line and the user wants us to show us a
3471 // special character (via 'listchars' option "precedes:<char>".
3472 if (lcs_prec_todo != NUL
3473 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003474 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3475 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003476#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003477 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003478#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003479 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003480 && c != NUL)
3481 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003482 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003483 lcs_prec_todo = NUL;
3484 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3485 {
3486 // Double-width character being overwritten by the "precedes"
3487 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003488 wlv.c_extra = MB_FILLER_CHAR;
3489 wlv.c_final = NUL;
3490 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003491 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003492 wlv.extra_attr =
3493 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003494 }
3495 mb_c = c;
3496 if (enc_utf8 && utf_char2len(c) > 1)
3497 {
3498 mb_utf8 = TRUE;
3499 u8cc[0] = 0;
3500 c = 0xc0;
3501 }
3502 else
3503 mb_utf8 = FALSE; // don't draw as UTF-8
3504 if (!attr_pri)
3505 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003506 saved_attr3 = wlv.char_attr; // save current attr
3507 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003508 n_attr3 = 1;
3509 }
3510 }
3511
3512 // At end of the text line or just after the last character.
3513 if ((c == NUL
3514#if defined(LINE_ATTR)
3515 || did_line_attr == 1
3516#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003517 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003518 {
3519#ifdef FEAT_SEARCH_EXTRA
3520 // flag to indicate whether prevcol equals startcol of search_hl or
3521 // one of the matches
3522 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3523 (long)(ptr - line) - (c == NUL));
3524#endif
3525 // Invert at least one char, used for Visual and empty line or
3526 // highlight match at end of line. If it's beyond the last
3527 // char on the screen, just overwrite that one (tricky!) Not
3528 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003529 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003530 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003531 && (VIsual_mode != Ctrl_V
3532 || lnum == VIsual.lnum
3533 || lnum == curwin->w_cursor.lnum)
3534 && c == NUL)
3535#ifdef FEAT_SEARCH_EXTRA
3536 // highlight 'hlsearch' match at end of line
3537 || (prevcol_hl_flag
3538# ifdef FEAT_SYN_HL
3539 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3540 && !(wp == curwin && VIsual_active))
3541# endif
3542# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003543 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003544# endif
3545# if defined(LINE_ATTR)
3546 && did_line_attr <= 1
3547# endif
3548 )
3549#endif
3550 ))
3551 {
3552 int n = 0;
3553
3554#ifdef FEAT_RIGHTLEFT
3555 if (wp->w_p_rl)
3556 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003557 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003558 n = 1;
3559 }
3560 else
3561#endif
3562 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003563 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003564 n = -1;
3565 }
3566 if (n != 0)
3567 {
3568 // At the window boundary, highlight the last character
3569 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003570 wlv.off += n;
3571 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003572 }
3573 else
3574 {
3575 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003576 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003577 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003578 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003579 }
3580#ifdef FEAT_SEARCH_EXTRA
3581 if (area_attr == 0)
3582 {
3583 // Use attributes from match with highest priority among
3584 // 'search_hl' and the match list.
3585 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003586 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003587 }
3588#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003589 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003590 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003591#ifdef FEAT_RIGHTLEFT
3592 if (wp->w_p_rl)
3593 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003594 --wlv.col;
3595 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003596 }
3597 else
3598#endif
3599 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003600 ++wlv.col;
3601 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003602 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003603 ++wlv.vcol;
3604 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003605 }
3606 }
3607
3608 // At end of the text line.
3609 if (c == NUL)
3610 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003611#ifdef FEAT_PROP_POPUP
3612 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003613 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003614 // Put the pointer back to the NUL.
3615 --ptr;
3616 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003617 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003618 else
3619#endif
3620 {
3621 draw_screen_line(wp, &wlv);
3622
3623 // Update w_cline_height and w_cline_folded if the cursor line
3624 // was updated (saves a call to plines() later).
3625 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3626 {
3627 curwin->w_cline_row = startrow;
3628 curwin->w_cline_height = wlv.row - startrow;
3629#ifdef FEAT_FOLDING
3630 curwin->w_cline_folded = FALSE;
3631#endif
3632 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3633 }
3634 break;
3635 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003636 }
3637
3638 // Show "extends" character from 'listchars' if beyond the line end and
3639 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003640 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003641 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003642 && wp->w_p_list
3643 && !wp->w_p_wrap
3644#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003645 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003646#endif
3647 && (
3648#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003649 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003650#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003651 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003652 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003653 || lcs_eol_one > 0
3654 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003655 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003656 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003657 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003658 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003659 mb_c = c;
3660 if (enc_utf8 && utf_char2len(c) > 1)
3661 {
3662 mb_utf8 = TRUE;
3663 u8cc[0] = 0;
3664 c = 0xc0;
3665 }
3666 else
3667 mb_utf8 = FALSE;
3668 }
3669
3670#ifdef FEAT_SYN_HL
3671 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003672 if (wlv.draw_color_col)
3673 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003674
3675 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3676 // highlight the cursor position itself.
3677 // Also highlight the 'colorcolumn' if it is different than
3678 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003679 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3680 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003681 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003682 if (((wlv.draw_state == WL_LINE
3683 || wlv.draw_state == WL_BRI
3684 || wlv.draw_state == WL_SBR)
3685 && !lnum_in_visual_area
3686 && search_attr == 0
3687 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003688# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003689 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003690# endif
3691 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003692 {
3693 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3694 && lnum != wp->w_cursor.lnum)
3695 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003696 vcol_save_attr = wlv.char_attr;
3697 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3698 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003699 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003700 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003701 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003702 vcol_save_attr = wlv.char_attr;
3703 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003704 }
3705 }
3706#endif
3707
3708 // Store character to be displayed.
3709 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003710 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003711 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003712 {
3713 // Store the character.
3714#if defined(FEAT_RIGHTLEFT)
3715 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3716 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003717 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003718 --wlv.off;
3719 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003720 }
3721#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003722 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003723 if (enc_dbcs == DBCS_JPNU)
3724 {
3725 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003726 ScreenLines[wlv.off] = 0x8e;
3727 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003728 }
3729 else if (enc_utf8)
3730 {
3731 if (mb_utf8)
3732 {
3733 int i;
3734
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003735 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003736 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003737 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003738 for (i = 0; i < Screen_mco; ++i)
3739 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003740 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003741 if (u8cc[i] == 0)
3742 break;
3743 }
3744 }
3745 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003746 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003747 }
3748 if (multi_attr)
3749 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003750 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003751 multi_attr = 0;
3752 }
3753 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003754 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003755
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003756 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003757
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003758 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3759 {
3760 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003761 ++wlv.off;
3762 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003763 if (enc_utf8)
3764 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003765 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003766 else
3767 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003768 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003769 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003770#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003771 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003772#endif
3773 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003774 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003775 // When "wlv.tocol" is halfway a character, set it to the end
3776 // of the character, otherwise highlighting won't stop.
3777 if (wlv.tocol == wlv.vcol)
3778 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003779
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003780 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003781
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003782#ifdef FEAT_RIGHTLEFT
3783 if (wp->w_p_rl)
3784 {
3785 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003786 --wlv.off;
3787 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003788 }
3789#endif
3790 }
3791#ifdef FEAT_RIGHTLEFT
3792 if (wp->w_p_rl)
3793 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003794 --wlv.off;
3795 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003796 }
3797 else
3798#endif
3799 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003800 ++wlv.off;
3801 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003802 }
3803 }
3804#ifdef FEAT_CONCEAL
3805 else if (wp->w_p_cole > 0 && is_concealing)
3806 {
3807 --n_skip;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003808 ++wlv.vcol_off_co;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003809 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003810 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003811 if (wp->w_p_wrap)
3812 {
3813 // Special voodoo required if 'wrap' is on.
3814 //
3815 // Advance the column indicator to force the line
3816 // drawing to wrap early. This will make the line
3817 // take up the same screen space when parts are concealed,
3818 // so that cursor line computations aren't messed up.
3819 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003820 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003821 // trailing junk to be written out of the screen line
3822 // we are building, 'boguscols' keeps track of the number
3823 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003824 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003825 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003826 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003827# ifdef FEAT_RIGHTLEFT
3828 if (wp->w_p_rl)
3829 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003830 wlv.col -= wlv.n_extra;
3831 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003832 }
3833 else
3834# endif
3835 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003836 wlv.col += wlv.n_extra;
3837 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003838 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003839 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003840 n_attr = 0;
3841 }
3842
3843
3844 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3845 {
3846 // Need to fill two screen columns.
3847# ifdef FEAT_RIGHTLEFT
3848 if (wp->w_p_rl)
3849 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003850 --wlv.boguscols;
3851 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003852 }
3853 else
3854# endif
3855 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003856 ++wlv.boguscols;
3857 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003858 }
3859 }
3860
3861# ifdef FEAT_RIGHTLEFT
3862 if (wp->w_p_rl)
3863 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003864 --wlv.boguscols;
3865 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003866 }
3867 else
3868# endif
3869 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003870 ++wlv.boguscols;
3871 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003872 }
3873 }
3874 else
3875 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003876 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003877 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003878 wlv.vcol += wlv.n_extra;
3879 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003880 n_attr = 0;
3881 }
3882 }
3883
3884 }
3885#endif // FEAT_CONCEAL
3886 else
3887 --n_skip;
3888
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003889 // Only advance the "wlv.vcol" when after the 'number' or
3890 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003891 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003892#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003893 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003894#endif
3895 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003896 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003897
3898#ifdef FEAT_SYN_HL
3899 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003900 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003901#endif
3902
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003903 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003904 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3905 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003906
3907 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003908 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003909 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003910 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003911 if (wlv.n_attr_skip > 0)
3912 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003913
3914 // At end of screen line and there is more to come: Display the line
3915 // so far. If there is no more to display it is caught above.
3916 if ((
3917#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003918 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003919#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003920 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003921 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003922 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003923#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003924 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003925#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003926#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003927 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003928#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003929 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003930 && wlv.p_extra != at_end_str)
3931 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3932 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003933 )
3934 {
3935#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003936 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003937 wlv_screen_line(wp, &wlv, FALSE);
3938 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003939 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003940 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003941#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003942 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003943#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003944 ++wlv.row;
3945 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003946
3947 // When not wrapping and finished diff lines, or when displayed
3948 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01003949 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003950#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003951 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003952#endif
3953#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01003954 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003955#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01003956 ) || lcs_eol_one == -1)
3957#ifdef FEAT_PROP_POPUP
3958 && !text_prop_follows
3959#endif
3960 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003961 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003962#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003963 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003964 {
3965 // do not output more of the line, only the "below" prop
3966 ptr += STRLEN(ptr);
3967# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003968 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003969# endif
3970 }
3971#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003972
3973 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003974 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003975#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003976 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003977#endif
3978 )
3979 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003980 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3981 draw_vsep_win(wp, wlv.row);
3982 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003983 }
3984
3985 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003986 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003987 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003988 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003989 break;
3990 }
3991
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003992 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003993#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003994 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003995#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003996#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003997 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003998#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003999 && wp->w_width == Columns)
4000 {
4001 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004002 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004003
4004 // Special trick to make copy/paste of wrapped lines work with
4005 // xterm/screen: write an extra character beyond the end of
4006 // the line. This will work with all terminal types
4007 // (regardless of the xn,am settings).
4008 // Only do this on a fast tty.
4009 // Only do this if the cursor is on the current line
4010 // (something has been written in it).
4011 // Don't do this for the GUI.
4012 // Don't do this for double-width characters.
4013 // Don't do this for a window not at the right screen border.
4014 if (p_tf
4015#ifdef FEAT_GUI
4016 && !gui.in_use
4017#endif
4018 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004019 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4020 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004021 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004022 || (*mb_off2cells)(
4023 LineOffset[wlv.screen_row - 1]
4024 + (int)Columns - 2,
4025 LineOffset[wlv.screen_row]
4026 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004027 {
4028 // First make sure we are at the end of the screen line,
4029 // then output the same character again to let the
4030 // terminal know about the wrap. If the terminal doesn't
4031 // auto-wrap, we overwrite the character.
4032 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004033 screen_char(LineOffset[wlv.screen_row - 1]
4034 + (unsigned)Columns - 1,
4035 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004036
4037 // When there is a multi-byte character, just output a
4038 // space to keep it simple.
4039 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004040 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004041 out_char(' ');
4042 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004043 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004044 + (Columns - 1)]);
4045 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004046 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004047 screen_start(); // don't know where cursor is now
4048 }
4049 }
4050
Bram Moolenaar1306b362022-08-06 15:59:06 +01004051 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004052
Bram Moolenaareed9d462021-02-15 20:38:25 +01004053 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004054#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004055 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004056# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004057 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004058# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004059 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004060 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004061#endif
4062#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004063 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004064 // When the filler lines are actually below the last line of the
4065 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004066 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004067 break;
4068#endif
4069 }
4070
4071 } // for every character in the line
4072
4073#ifdef FEAT_SPELL
4074 // After an empty line check first word for capital.
4075 if (*skipwhite(line) == NUL)
4076 {
4077 capcol_lnum = lnum + 1;
4078 cap_col = 0;
4079 }
4080#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004081#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004082 vim_free(text_props);
4083 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004084 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004085#endif
4086
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004087 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004088 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004089}