blob: 5c647507d83d9ad7f390e66e77bb0edd7304a29b [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 Moolenaara572b932023-02-19 14:34:37 +00001601
1602 if (number_only)
1603 {
1604 // skip over rows only used for virtual text above
1605 wlv.row += wlv.text_prop_above_count;
1606 if (wlv.row > endrow)
1607 return wlv.row;
1608 wlv.screen_row += wlv.text_prop_above_count;
1609 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001610#endif
1611
1612 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1613 // first character to be displayed.
1614 if (wp->w_p_wrap)
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001615 v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001616 else
1617 v = wp->w_leftcol;
1618 if (v > 0 && !number_only)
1619 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001620 char_u *prev_ptr = ptr;
1621 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001622 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001623
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001624 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001625 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001626 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001627 charsize = win_lbr_chartabsize(&cts, NULL);
1628 cts.cts_vcol += charsize;
1629 prev_ptr = cts.cts_ptr;
1630 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001631 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001632 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001633 ptr = cts.cts_ptr;
1634 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001635
1636 // When:
1637 // - 'cuc' is set, or
1638 // - 'colorcolumn' is set, or
1639 // - 'virtualedit' is set, or
1640 // - the visual mode is active,
1641 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001642 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001643#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001644 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001645#endif
1646 virtual_active() ||
1647 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001648 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001649
1650 // Handle a character that's not completely on the screen: Put ptr at
1651 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001652 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001653 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001654 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001655 ptr = prev_ptr;
1656 // If the character fits on the screen, don't need to skip it.
1657 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001658 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1659 && wlv.col == 0)
1660 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001661 }
1662
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001663#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001664 // If there the text doesn't reach to the desired column, need to skip
1665 // "skip_cells" cells when virtual text follows.
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001666 if ((!wp->w_p_wrap || (lnum == wp->w_topline && wp->w_skipcol > 0))
1667 && v > wlv.vcol)
Bram Moolenaarcd105412022-10-10 19:50:42 +01001668 skip_cells = v - wlv.vcol;
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001669#endif
Bram Moolenaarcd105412022-10-10 19:50:42 +01001670
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001671 // Adjust for when the inverted text is before the screen,
1672 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001673 if (wlv.tocol <= wlv.vcol)
1674 wlv.fromcol = 0;
1675 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1676 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001677
1678#ifdef FEAT_LINEBREAK
1679 // When w_skipcol is non-zero, first line needs 'showbreak'
1680 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001681 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001682#endif
1683#ifdef FEAT_SPELL
1684 // When spell checking a word we need to figure out the start of the
1685 // word and if it's badly spelled or not.
1686 if (has_spell)
1687 {
1688 int len;
1689 colnr_T linecol = (colnr_T)(ptr - line);
1690 hlf_T spell_hlf = HLF_COUNT;
1691
1692 pos = wp->w_cursor;
1693 wp->w_cursor.lnum = lnum;
1694 wp->w_cursor.col = linecol;
1695 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1696
1697 // spell_move_to() may call ml_get() and make "line" invalid
1698 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1699 ptr = line + linecol;
1700
1701 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1702 {
1703 // no bad word found at line start, don't check until end of a
1704 // word
1705 spell_hlf = HLF_COUNT;
1706 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1707 }
1708 else
1709 {
1710 // bad word found, use attributes until end of word
1711 word_end = wp->w_cursor.col + len + 1;
1712
1713 // Turn index into actual attributes.
1714 if (spell_hlf != HLF_COUNT)
1715 spell_attr = highlight_attr[spell_hlf];
1716 }
1717 wp->w_cursor = pos;
1718
1719# ifdef FEAT_SYN_HL
1720 // Need to restart syntax highlighting for this line.
1721 if (has_syntax)
1722 syntax_start(wp, lnum);
1723# endif
1724 }
1725#endif
1726 }
1727
1728 // Correct highlighting for cursor that can't be disabled.
1729 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001730 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001731 {
1732 if (noinvcur)
1733 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001734 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001735 {
1736 // highlighting starts at cursor, let it start just after the
1737 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001738 fromcol_prev = wlv.fromcol;
1739 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001740 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001741 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001742 // restart highlighting after the cursor
1743 fromcol_prev = wp->w_virtcol;
1744 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001745 if (wlv.fromcol >= wlv.tocol)
1746 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001747 }
1748
1749#ifdef FEAT_SEARCH_EXTRA
1750 if (!number_only)
1751 {
1752 v = (long)(ptr - line);
1753 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1754 &line, &screen_search_hl,
1755 &search_attr);
1756 ptr = line + v; // "line" may have been updated
1757 }
1758#endif
1759
1760#ifdef FEAT_SYN_HL
1761 // Cursor line highlighting for 'cursorline' in the current window.
1762 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1763 {
1764 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001765 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001766 if (!(wp == curwin && VIsual_active)
1767 && wp->w_p_culopt_flags != CULOPT_NBR)
1768 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001769 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001770 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1771
zeertzjqb7acea12022-12-12 13:20:43 +00001772 // Only apply CursorLine highlight here when "screenline" is not
1773 // present in 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001774 if (!wlv.cul_screenline)
zeertzjqb7acea12022-12-12 13:20:43 +00001775 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001776 else
1777 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001778 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001779 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1780 }
1781 area_highlighting = TRUE;
1782 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001783 }
1784#endif
1785
Bram Moolenaar1306b362022-08-06 15:59:06 +01001786 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001787
1788 // Repeat for the whole displayed line.
1789 for (;;)
1790 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001791 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001792#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001793 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001794#endif
1795#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001796 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001797#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001798
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001799 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001800 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001801 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001802#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001803 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001804 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001805 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001806 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001807 }
1808#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001809 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001810 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001811 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001812 if (cmdwin_type != 0 && wp == curwin)
1813 {
1814 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001815 wlv.n_extra = 1;
1816 wlv.c_extra = cmdwin_type;
1817 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001818 wlv.char_attr =
1819 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001820 }
1821 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001822#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001823 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001824 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001825 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001826 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001827 }
1828#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001829#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001830 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001831 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001832 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001833 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001834 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001835 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001836 }
1837#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001838 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001839 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001840 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001841 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001842 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001843 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001844#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001845 // Check if 'breakindent' applies and show it.
1846 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1847 if (wlv.n_extra == 0)
1848 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001849#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001850#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001851 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001852 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001853 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001854 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001855 }
1856#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001857 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001858 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001859 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001860 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001861 }
1862 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001863
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001864#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001865 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001866 && wlv.vcol >= left_curline_col
1867 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001868 {
zeertzjqb7acea12022-12-12 13:20:43 +00001869 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001870 }
1871#endif
1872
1873 // When still displaying '$' of change command, stop at cursor.
1874 // When only displaying the (relative) line number and that's done,
1875 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001876 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001877 && lnum == wp->w_cursor.lnum
1878 && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001879 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001880#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001881 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001882#endif
1883 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001884 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001885 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001886 // Pretend we have finished updating the window. Except when
1887 // 'cursorcolumn' is set.
1888#ifdef FEAT_SYN_HL
1889 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001890 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001891 else
1892#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001893 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001894 break;
1895 }
1896
Bram Moolenaar1306b362022-08-06 15:59:06 +01001897 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001898 {
1899 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001900 if (wlv.vcol == wlv.fromcol
1901 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1902 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001903 && (*mb_ptr2cells)(ptr) > 1)
1904 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001905 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001906 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001907 area_attr = vi_attr; // start highlighting
1908 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001909 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001910 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001911 area_attr = 0; // stop highlighting
1912
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001913#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001914 if (text_props != NULL)
1915 {
1916 int pi;
1917 int bcol = (int)(ptr - line);
1918
Bram Moolenaar1306b362022-08-06 15:59:06 +01001919 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001920# ifdef FEAT_LINEBREAK
1921 && !in_linebreak
1922# endif
1923 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001924 --bcol; // still working on the previous char, e.g. Tab
1925
1926 // Check if any active property ends.
1927 for (pi = 0; pi < text_props_active; ++pi)
1928 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001929 int tpi = text_prop_idxs[pi];
1930 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001931
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001932 // An inline property ends when after the start column plus
1933 // length. An "above" property ends when used and n_extra
1934 // is zero.
1935 if ((tp->tp_col != MAXCOL
1936 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001937 {
1938 if (pi + 1 < text_props_active)
1939 mch_memmove(text_prop_idxs + pi,
1940 text_prop_idxs + pi + 1,
1941 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001942 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001943 --text_props_active;
1944 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001945# ifdef FEAT_LINEBREAK
1946 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001947 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001948 syntax_attr = 0;
1949# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001950 }
1951 }
1952
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001953# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001954 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001955 // not on the next char yet, don't start another prop
1956 --bcol;
1957# endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001958 int display_text_first = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001959
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001960 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001961 // With 'nowrap' and not in the first screen line only "below"
1962 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001963 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001964 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001965 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001966 && (wp->w_p_wrap
1967 || wlv.row == startrow
1968 || (text_props[text_prop_next].tp_flags
1969 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001970 || (bcol == 0
1971 && (text_props[text_prop_next].tp_flags
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001972 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001973 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001974 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001975 if (text_props[text_prop_next].tp_col == MAXCOL
1976 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001977 + text_props[text_prop_next].tp_len)
1978 text_prop_idxs[text_props_active++] = text_prop_next;
1979 ++text_prop_next;
1980 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001981
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001982 if (wlv.n_extra == 0 || !wlv.extra_for_textprop)
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001983 {
1984 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001985 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001986 text_prop_flags = 0;
1987 text_prop_type = NULL;
1988 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001989 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001990 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001991 if (text_props_active > 0 && wlv.n_extra == 0
1992 && !display_text_first)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001993 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001994 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001995 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001996 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001997
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001998 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001999 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002000
2001 // Sort the properties on priority and/or starting last.
2002 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002003 sort_text_props(wp->w_buffer, text_props,
2004 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002005
2006 for (pi = 0; pi < text_props_active; ++pi)
2007 {
2008 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002009 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002010 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002011 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002012
Bram Moolenaarcd105412022-10-10 19:50:42 +01002013 // Only use a text property that can be displayed.
2014 // Skip "after" properties when wrap is off and at the
2015 // end of the window.
2016 if (pt != NULL
2017 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2018 && tp->tp_id != -MAXCOL
2019 && !(tp->tp_id < 0
2020 && !wp->w_p_wrap
2021 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2022 | TP_FLAG_ALIGN_ABOVE
2023 | TP_FLAG_ALIGN_BELOW)) == 0
2024 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002025 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002026 if (tp->tp_col == MAXCOL
2027 && *ptr == NUL
2028 && ((wp->w_p_list && lcs_eol_one > 0
2029 && (tp->tp_flags
2030 & TP_FLAG_ALIGN_ABOVE) == 0)
2031 || (ptr == line
2032 && !did_line
2033 && (tp->tp_flags
2034 & TP_FLAG_ALIGN_BELOW))))
2035 {
2036 // skip this prop, first display the '$' after
2037 // the line or display an empty line
2038 text_prop_follows = TRUE;
2039 if (used_tpi < 0)
2040 display_text_first = TRUE;
2041 continue;
2042 }
2043
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002044 if (pt->pt_hl_id > 0)
2045 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002046 text_prop_type = pt;
2047 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002048 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002049 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2050 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002051 text_prop_flags = pt->pt_flags;
2052 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002053 used_tpi = tpi;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002054 display_text_first = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002055 }
2056 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002057 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002058 && -text_prop_id
2059 <= wp->w_buffer->b_textprop_text.ga_len)
2060 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002061 textprop_T *tp = &text_props[used_tpi];
2062 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002063 ->b_textprop_text.ga_data)[
2064 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002065 int above = (tp->tp_flags
2066 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002067 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002068
2069 // reset the ID in the copy to avoid it being used
2070 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002071 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002072
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002073 if (p != NULL)
2074 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002075 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002076 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002077 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002078 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002079 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
2080 int padding = tp->tp_col == MAXCOL
2081 && tp->tp_len > 1
2082 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002083
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002084 // Insert virtual text before the current
2085 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002086 wlv.p_extra = p;
2087 wlv.c_extra = NUL;
2088 wlv.c_final = NUL;
2089 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002090 wlv.extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002091 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2092 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002093 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002094 // restore search_attr and area_attr when n_extra
2095 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01002096 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002097 saved_area_attr = area_attr;
2098 search_attr = 0;
2099 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002100 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002101 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002102 if (*ptr == NUL)
2103 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002104 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002105#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002106 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002107 {
2108 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002109 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002110 wlv.need_showbreak = FALSE;
2111 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002112 }
2113#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002114 if ((right || above || below || !wrap
2115 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002116 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002117 char_u *prev_p_extra = wlv.p_extra;
2118 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002119
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002120 // Take care of padding, right-align and
2121 // truncation.
2122 // Shared with win_lbr_chartabsize(), must do
2123 // exactly the same.
2124 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002125 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002126 wlv.col,
2127 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002128 &n_attr, &wlv.n_attr_skip,
2129 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002130 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002131 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002132 // wlv.p_extra was allocated
2133 vim_free(p_extra_free2);
2134 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002135 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002136
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002137 if (above)
2138 wlv.vcol_off_tp = wlv.n_extra;
2139
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002140 if (lcs_eol_one < 0
2141 && wp->w_p_wrap
2142 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002143 + wlv.n_extra - 2 > wp->w_width)
2144 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002145 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002146
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002147 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002148 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002149 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002150 {
2151 draw_screen_line(wp, &wlv);
2152
2153 // When line got too long for screen break
2154 // here.
2155 if (wlv.row == endrow)
2156 {
2157 ++wlv.row;
2158 break;
2159 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002160 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002161 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002162 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002163 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002164 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002165
Bram Moolenaarcd105412022-10-10 19:50:42 +01002166 // If the text didn't reach until the first window
2167 // column we need to skip cells.
2168 if (skip_cells > 0)
2169 {
2170 if (wlv.n_extra > skip_cells)
2171 {
2172 wlv.n_extra -= skip_cells;
2173 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002174 wlv.n_attr_skip -= skip_cells;
2175 if (wlv.n_attr_skip < 0)
2176 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002177 skip_cells = 0;
2178 }
2179 else
2180 {
2181 // the whole text is left of the window, drop
2182 // it and advance to the next one
2183 skip_cells -= wlv.n_extra;
2184 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002185 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002186 bail_out = TRUE;
2187 }
2188 }
2189
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002190 // If another text prop follows the condition below at
2191 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002192 // If this is an "above" text prop and 'nowrap' the we
2193 // must wrap anyway.
2194 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002195 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002196 && (wp->w_p_wrap
2197 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002198 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002199
2200 if (bail_out)
2201 // starting a new line for "below"
2202 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002203 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002204 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002205 else if (text_prop_next < text_prop_count
2206 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002207 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2208 || (!wp->w_p_wrap
2209 && wlv.col == wp->w_width - 1
2210 && (text_props[text_prop_next].tp_flags
2211 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002212 // When at last-but-one character and a text property
2213 // follows after it, we may need to flush the line after
2214 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002215 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002216 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002217 }
2218#endif
2219
Bram Moolenaare38fc862022-08-11 17:24:50 +01002220#ifdef FEAT_SEARCH_EXTRA
2221 if (wlv.n_extra == 0)
2222 {
2223 // Check for start/end of 'hlsearch' and other matches.
2224 // After end, check for start/end of next match.
2225 // When another match, have to check for start again.
2226 v = (long)(ptr - line);
2227 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2228 &screen_search_hl, &has_match_conc,
2229 &match_conc, did_line_attr, lcs_eol_one,
2230 &on_last_col);
2231 ptr = line + v; // "line" may have been changed
2232 prev_ptr = ptr;
2233
2234 // Do not allow a conceal over EOL otherwise EOL will be missed
2235 // and bad things happen.
2236 if (*ptr == NUL)
2237 has_match_conc = 0;
2238 }
2239#endif
2240
2241#ifdef FEAT_DIFF
2242 if (wlv.diff_hlf != (hlf_T)0)
2243 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002244 // When there is extra text (e.g. virtual text) it gets the
2245 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002246 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2247 && wlv.n_extra == 0)
2248 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002249 if (wlv.diff_hlf == HLF_TXD
2250 && ((ptr - line > change_end && wlv.n_extra == 0)
2251 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002252 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002253 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002254 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2255 && wp->w_p_culopt_flags != CULOPT_NBR
2256 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2257 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002258 wlv.line_attr = hl_combine_attr(
2259 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002260 }
2261#endif
2262
Bram Moolenaara74fda62019-10-19 17:38:03 +02002263#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002264 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002265 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002266 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002267# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002268 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002269 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002270# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002271 // Get syntax attribute.
2272 if (has_syntax)
2273 {
2274 // Get the syntax attribute for the character. If there
2275 // is an error, disable syntax highlighting.
2276 save_did_emsg = did_emsg;
2277 did_emsg = FALSE;
2278
2279 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002280 if (v == prev_syntax_col)
2281 // at same column again
2282 syntax_attr = prev_syntax_attr;
2283 else
2284 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002285# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002286 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002287# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002288 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002289# ifdef FEAT_SPELL
2290 has_spell ? &can_spell :
2291# endif
2292 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002293 prev_syntax_col = v;
2294 prev_syntax_attr = syntax_attr;
2295 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002296
Bram Moolenaar34390282019-10-16 14:38:26 +02002297 if (did_emsg)
2298 {
2299 wp->w_s->b_syn_error = TRUE;
2300 has_syntax = FALSE;
2301 syntax_attr = 0;
2302 }
2303 else
2304 did_emsg = save_did_emsg;
2305# ifdef SYN_TIME_LIMIT
2306 if (wp->w_s->b_syn_slow)
2307 has_syntax = FALSE;
2308# endif
2309
2310 // Need to get the line again, a multi-line regexp may
2311 // have made it invalid.
2312 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2313 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002314 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002315# ifdef FEAT_CONCEAL
2316 // no concealing past the end of the line, it interferes
2317 // with line highlighting
2318 if (*ptr == NUL)
2319 syntax_flags = 0;
2320 else
2321 syntax_flags = get_syntax_info(&syntax_seqnr);
2322# endif
2323 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002324 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002325# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002326 // Combine text property highlight into syntax highlight.
2327 if (text_prop_type != NULL)
2328 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002329 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002330 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2331 else
2332 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002333 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002334 }
2335# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002336#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002337
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002338 // Decide which of the highlight attributes to use.
2339 attr_pri = TRUE;
2340#ifdef LINE_ATTR
2341 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002342 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002343 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002344 if (!highlight_match)
2345 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002346 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002347# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002348 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002349# endif
2350 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002351 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002352 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002353 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002354# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002355 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002356# endif
2357 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002358 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002359 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2360 || wlv.vcol < wlv.fromcol
2361 || vcol_prev < fromcol_prev
2362 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002363 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002364 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002365 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002366# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002367 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002368# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002369 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002370# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002371 attr_pri = FALSE;
2372 }
2373#else
2374 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002375 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002376 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002377 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002378#endif
2379 else
2380 {
2381 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002382#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002383 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002384#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002385 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002386#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002387 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002388#ifdef FEAT_PROP_POPUP
2389 // override with text property highlight when "override" is TRUE
2390 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002391 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002392#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002393 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002394
2395 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002396 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002397 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002398 if (wlv.char_attr == 0)
2399 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002400 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002401 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002402 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002403
2404 // Get the next character to put on the screen.
2405
2406 // The "p_extra" points to the extra stuff that is inserted to
2407 // represent special characters (non-printable stuff) and other
2408 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002409 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002410 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2411 // "p_extra[n_extra]".
2412 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002413 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002414 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002415 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002416 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002417 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2418 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002419 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2420 if (enc_utf8 && utf_char2len(c) > 1)
2421 {
2422 mb_utf8 = TRUE;
2423 u8cc[0] = 0;
2424 c = 0xc0;
2425 }
2426 else
2427 mb_utf8 = FALSE;
2428 }
2429 else
2430 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002431 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002432 if (has_mbyte)
2433 {
2434 mb_c = c;
2435 if (enc_utf8)
2436 {
2437 // If the UTF-8 character is more than one byte:
2438 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002439 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002440 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002441 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002442 mb_l = 1;
2443 else if (mb_l > 1)
2444 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002445 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002446 mb_utf8 = TRUE;
2447 c = 0xc0;
2448 }
2449 }
2450 else
2451 {
2452 // if this is a DBCS character, put it in "mb_c"
2453 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002454 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002455 mb_l = 1;
2456 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002457 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002458 }
2459 if (mb_l == 0) // at the NUL at end-of-line
2460 mb_l = 1;
2461
2462 // If a double-width char doesn't fit display a '>' in the
2463 // last column.
2464 if ((
2465# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002466 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002467# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002468 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002469 && (*mb_char2cells)(mb_c) == 2)
2470 {
2471 c = '>';
2472 mb_c = c;
2473 mb_l = 1;
2474 mb_utf8 = FALSE;
2475 multi_attr = HL_ATTR(HLF_AT);
2476#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002477 if (wlv.cul_attr)
2478 multi_attr = hl_combine_attr(
2479 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002480#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002481 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002482
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002483 // put the pointer back to output the double-width
2484 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002485 ++wlv.n_extra;
2486 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002487 }
2488 else
2489 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002490 wlv.n_extra -= mb_l - 1;
2491 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002492 }
2493 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002494 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002495 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002496 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002497#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002498 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002499 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002500 // Only restore search_attr and area_attr after "n_extra" in
2501 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002502 if (wlv.saved_n_extra <= 0)
2503 {
2504 if (search_attr == 0)
2505 search_attr = saved_search_attr;
2506 if (area_attr == 0 && *ptr != NUL)
2507 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002508
2509 if (wlv.extra_for_textprop)
2510 // wlv.extra_attr should be used at this position but
2511 // not any further.
2512 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002513 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002514
2515 wlv.extra_for_textprop = FALSE;
2516 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002517 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002518#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002519 }
2520 else
2521 {
2522#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002523 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002524#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002525 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002526
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002527 // Get a character from the line itself.
2528 c = *ptr;
2529#ifdef FEAT_LINEBREAK
2530 c0 = *ptr;
2531#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002532#ifdef FEAT_PROP_POPUP
2533 if (c == NUL)
2534 // text is finished, may display a "below" virtual text
2535 did_line = TRUE;
2536#endif
2537
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002538 if (has_mbyte)
2539 {
2540 mb_c = c;
2541 if (enc_utf8)
2542 {
2543 // If the UTF-8 character is more than one byte: Decode it
2544 // into "mb_c".
2545 mb_l = utfc_ptr2len(ptr);
2546 mb_utf8 = FALSE;
2547 if (mb_l > 1)
2548 {
2549 mb_c = utfc_ptr2char(ptr, u8cc);
2550 // Overlong encoded ASCII or ASCII with composing char
2551 // is displayed normally, except a NUL.
2552 if (mb_c < 0x80)
2553 {
2554 c = mb_c;
2555#ifdef FEAT_LINEBREAK
2556 c0 = mb_c;
2557#endif
2558 }
2559 mb_utf8 = TRUE;
2560
2561 // At start of the line we can have a composing char.
2562 // Draw it as a space with a composing char.
2563 if (utf_iscomposing(mb_c))
2564 {
2565 int i;
2566
2567 for (i = Screen_mco - 1; i > 0; --i)
2568 u8cc[i] = u8cc[i - 1];
2569 u8cc[0] = mb_c;
2570 mb_c = ' ';
2571 }
2572 }
2573
2574 if ((mb_l == 1 && c >= 0x80)
2575 || (mb_l >= 1 && mb_c == 0)
2576 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2577 {
2578 // Illegal UTF-8 byte: display as <xx>.
2579 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002580 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002581# ifdef FEAT_RIGHTLEFT
2582 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002583 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002584# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002585 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002586 c = *wlv.p_extra;
2587 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002588 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002589 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2590 wlv.c_extra = NUL;
2591 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002592 if (area_attr == 0 && search_attr == 0)
2593 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002594 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002595 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002596 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002597 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002598 }
2599 }
2600 else if (mb_l == 0) // at the NUL at end-of-line
2601 mb_l = 1;
2602#ifdef FEAT_ARABIC
2603 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2604 {
2605 // Do Arabic shaping.
2606 int pc, pc1, nc;
2607 int pcc[MAX_MCO];
2608
2609 // The idea of what is the previous and next
2610 // character depends on 'rightleft'.
2611 if (wp->w_p_rl)
2612 {
2613 pc = prev_c;
2614 pc1 = prev_c1;
2615 nc = utf_ptr2char(ptr + mb_l);
2616 prev_c1 = u8cc[0];
2617 }
2618 else
2619 {
2620 pc = utfc_ptr2char(ptr + mb_l, pcc);
2621 nc = prev_c;
2622 pc1 = pcc[0];
2623 }
2624 prev_c = mb_c;
2625
2626 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2627 }
2628 else
2629 prev_c = mb_c;
2630#endif
2631 }
2632 else // enc_dbcs
2633 {
2634 mb_l = MB_BYTE2LEN(c);
2635 if (mb_l == 0) // at the NUL at end-of-line
2636 mb_l = 1;
2637 else if (mb_l > 1)
2638 {
2639 // We assume a second byte below 32 is illegal.
2640 // Hopefully this is OK for all double-byte encodings!
2641 if (ptr[1] >= 32)
2642 mb_c = (c << 8) + ptr[1];
2643 else
2644 {
2645 if (ptr[1] == NUL)
2646 {
2647 // head byte at end of line
2648 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002649 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002650 }
2651 else
2652 {
2653 // illegal tail byte
2654 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002655 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002656 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002657 wlv.p_extra = wlv.extra;
2658 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002659 wlv.c_extra = NUL;
2660 wlv.c_final = NUL;
2661 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002662 if (area_attr == 0 && search_attr == 0)
2663 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002664 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002665 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002666 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002667 // save current attr
2668 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002669 }
2670 mb_c = c;
2671 }
2672 }
2673 }
2674 // If a double-width char doesn't fit display a '>' in the
2675 // last column; the character is displayed at the start of the
2676 // next line.
2677 if ((
2678# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002679 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002680# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002681 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002682 && (*mb_char2cells)(mb_c) == 2)
2683 {
2684 c = '>';
2685 mb_c = c;
2686 mb_utf8 = FALSE;
2687 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002688 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002689 // Put pointer back so that the character will be
2690 // displayed at the start of the next line.
2691 --ptr;
2692#ifdef FEAT_CONCEAL
2693 did_decrement_ptr = TRUE;
2694#endif
2695 }
2696 else if (*ptr != NUL)
2697 ptr += mb_l - 1;
2698
2699 // If a double-width char doesn't fit at the left side display
2700 // a '<' in the first column. Don't do this for unprintable
2701 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002702 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002703 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002704 wlv.n_extra = 1;
2705 wlv.c_extra = MB_FILLER_CHAR;
2706 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002707 c = ' ';
2708 if (area_attr == 0 && search_attr == 0)
2709 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002710 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002711 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002712 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002713 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002714 }
2715 mb_c = c;
2716 mb_utf8 = FALSE;
2717 mb_l = 1;
2718 }
2719
2720 }
2721 ++ptr;
2722
2723 if (extra_check)
2724 {
2725#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002726 // Check spelling (unless at the end of the line).
2727 // Only do this when there is no syntax highlighting, the
2728 // @Spell cluster is not used or the current syntax item
2729 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002730 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002731 if (has_spell && v >= word_end && v > cur_checked_col)
2732 {
2733 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002734 // do not calculate cap_col at the end of the line or when
2735 // only white space is following
2736 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002737# ifdef FEAT_SYN_HL
2738 !has_syntax ||
2739# endif
2740 can_spell))
2741 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002742 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002743 int len;
2744 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002745
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002746 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002747 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002748
2749 // Use nextline[] if possible, it has the start of the
2750 // next line concatenated.
2751 if ((prev_ptr - line) - nextlinecol >= 0)
2752 p = nextline + (prev_ptr - line) - nextlinecol;
2753 else
2754 p = prev_ptr;
2755 cap_col -= (int)(prev_ptr - line);
2756 len = spell_check(wp, p, &spell_hlf, &cap_col,
2757 nochange);
2758 word_end = v + len;
2759
2760 // In Insert mode only highlight a word that
2761 // doesn't touch the cursor.
2762 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002763 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002764 && wp->w_cursor.lnum == lnum
2765 && wp->w_cursor.col >=
2766 (colnr_T)(prev_ptr - line)
2767 && wp->w_cursor.col < (colnr_T)word_end)
2768 {
2769 spell_hlf = HLF_COUNT;
2770 spell_redraw_lnum = lnum;
2771 }
2772
2773 if (spell_hlf == HLF_COUNT && p != prev_ptr
2774 && (p - nextline) + len > nextline_idx)
2775 {
2776 // Remember that the good word continues at the
2777 // start of the next line.
2778 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002779 checked_col = (int)((p - nextline)
2780 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002781 }
2782
2783 // Turn index into actual attributes.
2784 if (spell_hlf != HLF_COUNT)
2785 spell_attr = highlight_attr[spell_hlf];
2786
2787 if (cap_col > 0)
2788 {
2789 if (p != prev_ptr
2790 && (p - nextline) + cap_col >= nextline_idx)
2791 {
2792 // Remember that the word in the next line
2793 // must start with a capital.
2794 capcol_lnum = lnum + 1;
2795 cap_col = (int)((p - nextline) + cap_col
2796 - nextline_idx);
2797 }
2798 else
2799 // Compute the actual column.
2800 cap_col += (int)(prev_ptr - line);
2801 }
2802 }
2803 }
2804 if (spell_attr != 0)
2805 {
2806 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002807 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2808 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002809 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002810 wlv.char_attr = hl_combine_attr(spell_attr,
2811 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002812 }
2813#endif
2814#ifdef FEAT_LINEBREAK
2815 // Found last space before word: check for line break.
2816 if (wp->w_p_lbr && c0 == c
2817 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2818 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002819 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2820 : 0;
2821 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002822 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002823
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002824 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002825# ifdef FEAT_PROP_POPUP
2826 // do not want virtual text counted here
2827 cts.cts_has_prop_with_text = FALSE;
2828# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002829 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002830 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002831
2832 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002833 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002834 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002835 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002836 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2837 if (wlv.n_extra < 0)
2838 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002839 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002840 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002841 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002842 // line break, but for TABs the highlighting should
2843 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002844 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002845
Bram Moolenaar1306b362022-08-06 15:59:06 +01002846 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002847# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002848 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002849 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002850 wp->w_buffer->b_p_vts_array) - 1;
2851# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002852 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002853 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002854# endif
2855
Bram Moolenaar1306b362022-08-06 15:59:06 +01002856 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2857 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002858# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002859 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002860 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002861# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002862 if (VIM_ISWHITE(c))
2863 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002864# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002865 if (c == TAB)
2866 // See "Tab alignment" below.
2867 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002868# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002869 if (!wp->w_p_list)
2870 c = ' ';
2871 }
2872 }
2873#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002874 in_multispace = c == ' '
2875 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2876 if (!in_multispace)
2877 multispace_pos = 0;
2878
Bram Moolenaareed9d462021-02-15 20:38:25 +01002879 // 'list': Change char 160 to 'nbsp' and space to 'space'
2880 // setting in 'listchars'. But not when the character is
2881 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002882 if (wp->w_p_list
2883 && ((((c == 160 && mb_l == 1)
2884 || (mb_utf8
2885 && ((mb_c == 160 && mb_l == 2)
2886 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002887 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002888 || (c == ' '
2889 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002890 && (wp->w_lcs_chars.space
2891 || (in_multispace
2892 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002893 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002894 && ptr - line <= trailcol)))
2895 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002896 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2897 {
2898 c = wp->w_lcs_chars.multispace[multispace_pos++];
2899 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2900 multispace_pos = 0;
2901 }
2902 else
2903 c = (c == ' ') ? wp->w_lcs_chars.space
2904 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002905 if (area_attr == 0 && search_attr == 0)
2906 {
2907 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002908 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002909 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002910 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002911 }
2912 mb_c = c;
2913 if (enc_utf8 && utf_char2len(c) > 1)
2914 {
2915 mb_utf8 = TRUE;
2916 u8cc[0] = 0;
2917 c = 0xc0;
2918 }
2919 else
2920 mb_utf8 = FALSE;
2921 }
2922
zeertzjq2e7cba32022-06-10 15:30:32 +01002923 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2924 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002925 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002926 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2927 && wp->w_lcs_chars.leadmultispace != NULL)
2928 {
2929 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002930 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2931 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002932 multispace_pos = 0;
2933 }
2934
2935 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2936 c = wp->w_lcs_chars.trail;
2937
2938 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2939 c = wp->w_lcs_chars.lead;
2940
zeertzjq2e7cba32022-06-10 15:30:32 +01002941 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002942 c = wp->w_lcs_chars.space;
2943
2944
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002945 if (!attr_pri)
2946 {
2947 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002948 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002949 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002950 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002951 }
2952 mb_c = c;
2953 if (enc_utf8 && utf_char2len(c) > 1)
2954 {
2955 mb_utf8 = TRUE;
2956 u8cc[0] = 0;
2957 c = 0xc0;
2958 }
2959 else
2960 mb_utf8 = FALSE;
2961 }
2962 }
2963
2964 // Handling of non-printable characters.
2965 if (!vim_isprintc(c))
2966 {
2967 // when getting a character from the file, we may have to
2968 // turn it into something else on the way to putting it
2969 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002970 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002971 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002972 int tab_len = 0;
2973 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002974#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002975 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01002976
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002977 // only adjust the tab_len, when at the first column
2978 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002979 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002980 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002981#endif
2982 // tab amount depends on current column
2983#ifdef FEAT_VARTABS
2984 tab_len = tabstop_padding(vcol_adjusted,
2985 wp->w_buffer->b_p_ts,
2986 wp->w_buffer->b_p_vts_array) - 1;
2987#else
2988 tab_len = (int)wp->w_buffer->b_p_ts
2989 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2990#endif
2991
2992#ifdef FEAT_LINEBREAK
2993 if (!wp->w_p_lbr || !wp->w_p_list)
2994#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002995 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002996 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002997 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002998 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002999#ifdef FEAT_LINEBREAK
3000 else
3001 {
3002 char_u *p;
3003 int len;
3004 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003005 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003006
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003007# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003008 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003009 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003010 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003011
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003012 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003013 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003014 && old_boguscols > 0
3015 && wlv.n_extra > tab_len)
3016 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003017# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003018 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003019 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003020 // If wlv.n_extra > 0, it gives the number of chars
3021 // to use for a tab, else we need to calculate the
3022 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003023 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3024 len = tab_len * tab2_len;
3025 if (wp->w_lcs_chars.tab3)
3026 len += mb_char2len(wp->w_lcs_chars.tab3)
3027 - tab2_len;
3028 if (wlv.n_extra > 0)
3029 len += wlv.n_extra - tab_len;
3030 c = wp->w_lcs_chars.tab1;
3031 p = alloc(len + 1);
3032 if (p == NULL)
3033 wlv.n_extra = 0;
3034 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003035 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003036 vim_memset(p, ' ', len);
3037 p[len] = NUL;
3038 vim_free(wlv.p_extra_free);
3039 wlv.p_extra_free = p;
3040 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003041 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003042 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003043
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003044 if (*p == NUL)
3045 {
3046 tab_len = i;
3047 break;
3048 }
3049
3050 // if tab3 is given, use it for the last
3051 // char
3052 if (wp->w_lcs_chars.tab3
3053 && i == tab_len - 1)
3054 lcs = wp->w_lcs_chars.tab3;
3055 p += mb_char2bytes(lcs, p);
3056 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003057 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003058 }
3059 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003060# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003061 // n_extra will be increased by
3062 // FIX_FOX_BOGUSCOLS macro below, so need to
3063 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003064 if (wlv.vcol_off_co > 0)
3065 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003066# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003067 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003068 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003069 }
3070#endif
3071#ifdef FEAT_CONCEAL
3072 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003073 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003074
3075 // Tab alignment should be identical regardless of
3076 // 'conceallevel' value. So tab compensates of all
3077 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003078 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003079 // line. Note that the tab can be longer than
3080 // 'tabstop' when there are concealed characters.
3081 FIX_FOR_BOGUSCOLS;
3082
3083 // Make sure, the highlighting for the tab char will be
3084 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003085 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003086 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003087 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003088 tab_len += vc_saved;
3089 }
3090#endif
3091 mb_utf8 = FALSE; // don't draw as UTF-8
3092 if (wp->w_p_list)
3093 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003094 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003095 ? wp->w_lcs_chars.tab3
3096 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003097#ifdef FEAT_LINEBREAK
h-east194555c2023-03-02 18:49:09 +00003098 if (wp->w_p_lbr && wlv.p_extra != NULL
3099 && *wlv.p_extra != NUL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003100 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003101 else
3102#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003103 wlv.c_extra = wp->w_lcs_chars.tab2;
3104 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003105 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003106 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003107 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003108 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003109 mb_c = c;
3110 if (enc_utf8 && utf_char2len(c) > 1)
3111 {
3112 mb_utf8 = TRUE;
3113 u8cc[0] = 0;
3114 c = 0xc0;
3115 }
3116 }
3117 else
3118 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003119 wlv.c_final = NUL;
3120 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003121 c = ' ';
3122 }
3123 }
3124 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003125 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003126 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003127 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3128 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003129 && VIsual_mode != Ctrl_V
3130 && (
3131# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003132 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003133# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003134 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003135 && !(noinvcur
3136 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003137 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003138 && lcs_eol_one > 0)
3139 {
3140 // Display a '$' after the line or highlight an extra
3141 // character if the line break is included.
3142#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3143 // For a diff line the highlighting continues after the
3144 // "$".
3145 if (
3146# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003147 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003148# ifdef LINE_ATTR
3149 &&
3150# endif
3151# endif
3152# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003153 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003154# endif
3155 )
3156#endif
3157 {
3158 // In virtualedit, visual selections may extend
3159 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003160 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003161 && wlv.tocol != MAXCOL
3162 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003163 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003164 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003165 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003166 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3167 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003168 else
3169 c = ' ';
3170 lcs_eol_one = -1;
3171 --ptr; // put it back at the NUL
3172 if (!attr_pri)
3173 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003174 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003175 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003176 n_attr = 1;
3177 }
3178 mb_c = c;
3179 if (enc_utf8 && utf_char2len(c) > 1)
3180 {
3181 mb_utf8 = TRUE;
3182 u8cc[0] = 0;
3183 c = 0xc0;
3184 }
3185 else
3186 mb_utf8 = FALSE; // don't draw as UTF-8
3187 }
3188 else if (c != NUL)
3189 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003190 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3191 if (wlv.n_extra == 0)
3192 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003193#ifdef FEAT_RIGHTLEFT
3194 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003195 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003196#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003197 wlv.c_extra = NUL;
3198 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003199#ifdef FEAT_LINEBREAK
3200 if (wp->w_p_lbr)
3201 {
3202 char_u *p;
3203
Bram Moolenaar1306b362022-08-06 15:59:06 +01003204 c = *wlv.p_extra;
3205 p = alloc(wlv.n_extra + 1);
3206 vim_memset(p, ' ', wlv.n_extra);
3207 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3208 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003209 vim_free(wlv.p_extra_free);
3210 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003211 }
3212 else
3213#endif
3214 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003215 wlv.n_extra = byte2cells(c) - 1;
3216 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003217 }
3218 if (!attr_pri)
3219 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003220 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003221 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003222 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003223 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003224 }
3225 mb_utf8 = FALSE; // don't draw as UTF-8
3226 }
3227 else if (VIsual_active
3228 && (VIsual_mode == Ctrl_V
3229 || VIsual_mode == 'v')
3230 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003231 && wlv.tocol != MAXCOL
3232 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003233 && (
3234#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003235 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003236#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003237 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003238 {
3239 c = ' ';
3240 --ptr; // put it back at the NUL
3241 }
3242#if defined(LINE_ATTR)
3243 else if ((
3244# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003245 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003246# endif
3247# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003248 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003249# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003250 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003251 ) && (
3252# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003253 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003254# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003255 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003256# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003257 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003258# endif
3259 < wp->w_width)))
3260 {
3261 // Highlight until the right side of the window
3262 c = ' ';
3263 --ptr; // put it back at the NUL
3264
3265 // Remember we do the char for line highlighting.
3266 ++did_line_attr;
3267
3268 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003269 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003270 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003271 || (wp->w_p_list &&
3272 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003273 wlv.char_attr = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003274# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003275 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003276 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003277 wlv.diff_hlf = HLF_CHD;
3278 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003279 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003280 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003281 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3282 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003283 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003284 || (wlv.vcol >= left_curline_col
3285 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003286 wlv.char_attr = hl_combine_attr(
3287 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003288 }
3289 }
3290# endif
3291# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003292 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003293 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003294 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003295 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3296 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003297 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003298 if (!wlv.cul_screenline
3299 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003300 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003301 wlv.char_attr = hl_combine_attr(
3302 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003303 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003304 else if (wlv.line_attr)
3305 wlv.char_attr = hl_combine_attr(
3306 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003307 }
3308# endif
3309 }
3310#endif
3311 }
3312
3313#ifdef FEAT_CONCEAL
3314 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003315 && (wp != curwin || lnum != wp->w_cursor.lnum
3316 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003317 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3318 && !(lnum_in_visual_area
3319 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3320 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003321 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003322 if (((prev_syntax_id != syntax_seqnr
3323 && (syntax_flags & HL_CONCEAL) != 0)
3324 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003325 && (syn_get_sub_char() != NUL
3326 || (has_match_conc && match_conc)
3327 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003328 && wp->w_p_cole != 3)
3329 {
3330 // First time at this concealed item: display one
3331 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003332 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003333 c = match_conc;
3334 else if (syn_get_sub_char() != NUL)
3335 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003336 else if (wp->w_lcs_chars.conceal != NUL)
3337 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003338 else
3339 c = ' ';
3340
3341 prev_syntax_id = syntax_seqnr;
3342
Bram Moolenaar1306b362022-08-06 15:59:06 +01003343 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003344 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003345 wlv.vcol += wlv.n_extra;
3346 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003347 {
3348# ifdef FEAT_RIGHTLEFT
3349 if (wp->w_p_rl)
3350 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003351 wlv.col -= wlv.n_extra;
3352 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003353 }
3354 else
3355# endif
3356 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003357 wlv.boguscols += wlv.n_extra;
3358 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003359 }
3360 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003361 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003362 n_attr = 0;
3363 }
3364 else if (n_skip == 0)
3365 {
3366 is_concealing = TRUE;
3367 n_skip = 1;
3368 }
3369 mb_c = c;
3370 if (enc_utf8 && utf_char2len(c) > 1)
3371 {
3372 mb_utf8 = TRUE;
3373 u8cc[0] = 0;
3374 c = 0xc0;
3375 }
3376 else
3377 mb_utf8 = FALSE; // don't draw as UTF-8
3378 }
3379 else
3380 {
3381 prev_syntax_id = 0;
3382 is_concealing = FALSE;
3383 }
3384
3385 if (n_skip > 0 && did_decrement_ptr)
3386 // not showing the '>', put pointer back to avoid getting stuck
3387 ++ptr;
3388
3389#endif // FEAT_CONCEAL
3390 }
3391
3392#ifdef FEAT_CONCEAL
3393 // In the cursor line and we may be concealing characters: correct
3394 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003395 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003396 && wp == curwin && lnum == wp->w_cursor.lnum
3397 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003398 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003399 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003400# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003401 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003402 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003403 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003404# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003405 wp->w_wcol = wlv.col - wlv.boguscols;
3406 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003407 did_wcol = TRUE;
3408 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003409# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003410 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003411# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003412 }
3413#endif
3414
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003415 // Use "wlv.extra_attr", but don't override visual selection
3416 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003417 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3418 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003419 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003420 && (!attr_pri
3421#ifdef FEAT_PROP_POPUP
3422 || (text_prop_flags & PT_FLAG_OVERRIDE)
3423#endif
3424 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003425 {
3426#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003427 if (wlv.line_attr)
3428 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003429 else
3430#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003431 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003432#ifdef FEAT_PROP_POPUP
3433 if (reset_extra_attr)
3434 {
3435 reset_extra_attr = FALSE;
3436 wlv.extra_attr = 0;
3437 }
3438#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003439 }
3440
3441#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3442 // XIM don't send preedit_start and preedit_end, but they send
3443 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3444 // im_is_preediting() here.
3445 if (p_imst == IM_ON_THE_SPOT
3446 && xic != NULL
3447 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003448 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003449 && !p_imdisable
3450 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003451 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003452 {
3453 colnr_T tcol;
3454
3455 if (preedit_end_col == MAXCOL)
3456 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3457 else
3458 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003459 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003460 {
3461 if (feedback_old_attr < 0)
3462 {
3463 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003464 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003465 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003466 wlv.char_attr = im_get_feedback_attr(feedback_col);
3467 if (wlv.char_attr < 0)
3468 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003469 feedback_col++;
3470 }
3471 else if (feedback_old_attr >= 0)
3472 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003473 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003474 feedback_old_attr = -1;
3475 feedback_col = 0;
3476 }
3477 }
3478#endif
3479 // Handle the case where we are in column 0 but not on the first
3480 // character of the line and the user wants us to show us a
3481 // special character (via 'listchars' option "precedes:<char>".
3482 if (lcs_prec_todo != NUL
3483 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003484 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3485 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003486#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003487 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003488#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003489 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003490 && c != NUL)
3491 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003492 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003493 lcs_prec_todo = NUL;
3494 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3495 {
3496 // Double-width character being overwritten by the "precedes"
3497 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003498 wlv.c_extra = MB_FILLER_CHAR;
3499 wlv.c_final = NUL;
3500 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003501 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003502 wlv.extra_attr =
3503 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003504 }
3505 mb_c = c;
3506 if (enc_utf8 && utf_char2len(c) > 1)
3507 {
3508 mb_utf8 = TRUE;
3509 u8cc[0] = 0;
3510 c = 0xc0;
3511 }
3512 else
3513 mb_utf8 = FALSE; // don't draw as UTF-8
3514 if (!attr_pri)
3515 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003516 saved_attr3 = wlv.char_attr; // save current attr
3517 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003518 n_attr3 = 1;
3519 }
3520 }
3521
3522 // At end of the text line or just after the last character.
3523 if ((c == NUL
3524#if defined(LINE_ATTR)
3525 || did_line_attr == 1
3526#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003527 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003528 {
3529#ifdef FEAT_SEARCH_EXTRA
3530 // flag to indicate whether prevcol equals startcol of search_hl or
3531 // one of the matches
3532 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3533 (long)(ptr - line) - (c == NUL));
3534#endif
3535 // Invert at least one char, used for Visual and empty line or
3536 // highlight match at end of line. If it's beyond the last
3537 // char on the screen, just overwrite that one (tricky!) Not
3538 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003539 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003540 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003541 && (VIsual_mode != Ctrl_V
3542 || lnum == VIsual.lnum
3543 || lnum == curwin->w_cursor.lnum)
3544 && c == NUL)
3545#ifdef FEAT_SEARCH_EXTRA
3546 // highlight 'hlsearch' match at end of line
3547 || (prevcol_hl_flag
3548# ifdef FEAT_SYN_HL
3549 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3550 && !(wp == curwin && VIsual_active))
3551# endif
3552# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003553 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003554# endif
3555# if defined(LINE_ATTR)
3556 && did_line_attr <= 1
3557# endif
3558 )
3559#endif
3560 ))
3561 {
3562 int n = 0;
3563
3564#ifdef FEAT_RIGHTLEFT
3565 if (wp->w_p_rl)
3566 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003567 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003568 n = 1;
3569 }
3570 else
3571#endif
3572 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003573 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003574 n = -1;
3575 }
3576 if (n != 0)
3577 {
3578 // At the window boundary, highlight the last character
3579 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003580 wlv.off += n;
3581 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003582 }
3583 else
3584 {
3585 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003586 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003587 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003588 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003589 }
3590#ifdef FEAT_SEARCH_EXTRA
3591 if (area_attr == 0)
3592 {
3593 // Use attributes from match with highest priority among
3594 // 'search_hl' and the match list.
3595 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003596 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003597 }
3598#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003599 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003600 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003601#ifdef FEAT_RIGHTLEFT
3602 if (wp->w_p_rl)
3603 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003604 --wlv.col;
3605 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003606 }
3607 else
3608#endif
3609 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003610 ++wlv.col;
3611 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003612 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003613 ++wlv.vcol;
3614 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003615 }
3616 }
3617
3618 // At end of the text line.
3619 if (c == NUL)
3620 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003621#ifdef FEAT_PROP_POPUP
3622 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003623 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003624 // Put the pointer back to the NUL.
3625 --ptr;
3626 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003627 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003628 else
3629#endif
3630 {
3631 draw_screen_line(wp, &wlv);
3632
3633 // Update w_cline_height and w_cline_folded if the cursor line
3634 // was updated (saves a call to plines() later).
3635 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3636 {
3637 curwin->w_cline_row = startrow;
3638 curwin->w_cline_height = wlv.row - startrow;
3639#ifdef FEAT_FOLDING
3640 curwin->w_cline_folded = FALSE;
3641#endif
3642 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3643 }
3644 break;
3645 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003646 }
3647
3648 // Show "extends" character from 'listchars' if beyond the line end and
3649 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003650 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003651 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003652 && wp->w_p_list
3653 && !wp->w_p_wrap
3654#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003655 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003656#endif
3657 && (
3658#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003659 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003660#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003661 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003662 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003663 || lcs_eol_one > 0
3664 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003665 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003666 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003667 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003668 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003669 mb_c = c;
3670 if (enc_utf8 && utf_char2len(c) > 1)
3671 {
3672 mb_utf8 = TRUE;
3673 u8cc[0] = 0;
3674 c = 0xc0;
3675 }
3676 else
3677 mb_utf8 = FALSE;
3678 }
3679
3680#ifdef FEAT_SYN_HL
3681 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003682 if (wlv.draw_color_col)
3683 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003684
3685 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3686 // highlight the cursor position itself.
3687 // Also highlight the 'colorcolumn' if it is different than
3688 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003689 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3690 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003691 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003692 if (((wlv.draw_state == WL_LINE
3693 || wlv.draw_state == WL_BRI
3694 || wlv.draw_state == WL_SBR)
3695 && !lnum_in_visual_area
3696 && search_attr == 0
3697 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003698# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003699 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003700# endif
3701 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003702 {
3703 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3704 && lnum != wp->w_cursor.lnum)
3705 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003706 vcol_save_attr = wlv.char_attr;
3707 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3708 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003709 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003710 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003711 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003712 vcol_save_attr = wlv.char_attr;
3713 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003714 }
3715 }
3716#endif
3717
3718 // Store character to be displayed.
3719 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003720 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003721 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003722 {
3723 // Store the character.
3724#if defined(FEAT_RIGHTLEFT)
3725 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3726 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003727 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003728 --wlv.off;
3729 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003730 }
3731#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003732 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003733 if (enc_dbcs == DBCS_JPNU)
3734 {
3735 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003736 ScreenLines[wlv.off] = 0x8e;
3737 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003738 }
3739 else if (enc_utf8)
3740 {
3741 if (mb_utf8)
3742 {
3743 int i;
3744
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003745 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003746 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003747 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003748 for (i = 0; i < Screen_mco; ++i)
3749 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003750 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003751 if (u8cc[i] == 0)
3752 break;
3753 }
3754 }
3755 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003756 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003757 }
3758 if (multi_attr)
3759 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003760 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003761 multi_attr = 0;
3762 }
3763 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003764 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003765
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003766 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003767
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003768 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3769 {
3770 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003771 ++wlv.off;
3772 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003773 if (enc_utf8)
3774 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003775 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003776 else
3777 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003778 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003779 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003780#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003781 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003782#endif
3783 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003784 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003785 // When "wlv.tocol" is halfway a character, set it to the end
3786 // of the character, otherwise highlighting won't stop.
3787 if (wlv.tocol == wlv.vcol)
3788 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003789
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003790 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003791
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003792#ifdef FEAT_RIGHTLEFT
3793 if (wp->w_p_rl)
3794 {
3795 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003796 --wlv.off;
3797 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003798 }
3799#endif
3800 }
3801#ifdef FEAT_RIGHTLEFT
3802 if (wp->w_p_rl)
3803 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003804 --wlv.off;
3805 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003806 }
3807 else
3808#endif
3809 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003810 ++wlv.off;
3811 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003812 }
3813 }
3814#ifdef FEAT_CONCEAL
3815 else if (wp->w_p_cole > 0 && is_concealing)
3816 {
3817 --n_skip;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003818 ++wlv.vcol_off_co;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003819 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003820 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003821 if (wp->w_p_wrap)
3822 {
3823 // Special voodoo required if 'wrap' is on.
3824 //
3825 // Advance the column indicator to force the line
3826 // drawing to wrap early. This will make the line
3827 // take up the same screen space when parts are concealed,
3828 // so that cursor line computations aren't messed up.
3829 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003830 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003831 // trailing junk to be written out of the screen line
3832 // we are building, 'boguscols' keeps track of the number
3833 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003834 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003835 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003836 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003837# ifdef FEAT_RIGHTLEFT
3838 if (wp->w_p_rl)
3839 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003840 wlv.col -= wlv.n_extra;
3841 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003842 }
3843 else
3844# endif
3845 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003846 wlv.col += wlv.n_extra;
3847 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003848 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003849 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003850 n_attr = 0;
3851 }
3852
3853
3854 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3855 {
3856 // Need to fill two screen columns.
3857# ifdef FEAT_RIGHTLEFT
3858 if (wp->w_p_rl)
3859 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003860 --wlv.boguscols;
3861 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003862 }
3863 else
3864# endif
3865 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003866 ++wlv.boguscols;
3867 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003868 }
3869 }
3870
3871# ifdef FEAT_RIGHTLEFT
3872 if (wp->w_p_rl)
3873 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003874 --wlv.boguscols;
3875 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003876 }
3877 else
3878# endif
3879 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003880 ++wlv.boguscols;
3881 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003882 }
3883 }
3884 else
3885 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003886 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003887 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003888 wlv.vcol += wlv.n_extra;
3889 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003890 n_attr = 0;
3891 }
3892 }
3893
3894 }
3895#endif // FEAT_CONCEAL
3896 else
3897 --n_skip;
3898
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003899 // Only advance the "wlv.vcol" when after the 'number' or
3900 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003901 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003902#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003903 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003904#endif
3905 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003906 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003907
3908#ifdef FEAT_SYN_HL
3909 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003910 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003911#endif
3912
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003913 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003914 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3915 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003916
3917 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003918 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003919 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003920 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003921 if (wlv.n_attr_skip > 0)
3922 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003923
3924 // At end of screen line and there is more to come: Display the line
3925 // so far. If there is no more to display it is caught above.
3926 if ((
3927#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003928 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003929#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003930 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003931 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003932 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003933#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003934 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003935#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003936#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003937 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003938#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003939 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003940 && wlv.p_extra != at_end_str)
3941 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3942 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003943 )
3944 {
3945#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003946 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003947 wlv_screen_line(wp, &wlv, FALSE);
3948 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003949 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003950 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003951#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003952 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003953#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003954 ++wlv.row;
3955 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003956
3957 // When not wrapping and finished diff lines, or when displayed
3958 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01003959 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003960#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003961 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003962#endif
3963#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01003964 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003965#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01003966 ) || lcs_eol_one == -1)
3967#ifdef FEAT_PROP_POPUP
3968 && !text_prop_follows
3969#endif
3970 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003971 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003972#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003973 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003974 {
3975 // do not output more of the line, only the "below" prop
3976 ptr += STRLEN(ptr);
3977# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003978 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003979# endif
3980 }
3981#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003982
3983 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003984 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003985#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003986 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003987#endif
3988 )
3989 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003990 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3991 draw_vsep_win(wp, wlv.row);
3992 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003993 }
3994
3995 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003996 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003997 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003998 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003999 break;
4000 }
4001
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004002 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004003#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004004 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004005#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004006#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004007 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004008#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004009 && wp->w_width == Columns)
4010 {
4011 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004012 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004013
4014 // Special trick to make copy/paste of wrapped lines work with
4015 // xterm/screen: write an extra character beyond the end of
4016 // the line. This will work with all terminal types
4017 // (regardless of the xn,am settings).
4018 // Only do this on a fast tty.
4019 // Only do this if the cursor is on the current line
4020 // (something has been written in it).
4021 // Don't do this for the GUI.
4022 // Don't do this for double-width characters.
4023 // Don't do this for a window not at the right screen border.
4024 if (p_tf
4025#ifdef FEAT_GUI
4026 && !gui.in_use
4027#endif
4028 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004029 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4030 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004031 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004032 || (*mb_off2cells)(
4033 LineOffset[wlv.screen_row - 1]
4034 + (int)Columns - 2,
4035 LineOffset[wlv.screen_row]
4036 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004037 {
4038 // First make sure we are at the end of the screen line,
4039 // then output the same character again to let the
4040 // terminal know about the wrap. If the terminal doesn't
4041 // auto-wrap, we overwrite the character.
4042 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004043 screen_char(LineOffset[wlv.screen_row - 1]
4044 + (unsigned)Columns - 1,
4045 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004046
4047 // When there is a multi-byte character, just output a
4048 // space to keep it simple.
4049 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004050 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004051 out_char(' ');
4052 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004053 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004054 + (Columns - 1)]);
4055 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004056 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004057 screen_start(); // don't know where cursor is now
4058 }
4059 }
4060
Bram Moolenaar1306b362022-08-06 15:59:06 +01004061 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004062
Bram Moolenaareed9d462021-02-15 20:38:25 +01004063 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004064#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004065 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004066# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004067 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004068# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004069 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004070 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004071#endif
4072#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004073 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004074 // When the filler lines are actually below the last line of the
4075 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004076 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004077 break;
4078#endif
4079 }
4080
4081 } // for every character in the line
4082
4083#ifdef FEAT_SPELL
4084 // After an empty line check first word for capital.
4085 if (*skipwhite(line) == NUL)
4086 {
4087 capcol_lnum = lnum + 1;
4088 cap_col = 0;
4089 }
4090#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004091#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004092 vim_free(text_props);
4093 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004094 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004095#endif
4096
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004097 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004098 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004099}