blob: 408f2d5bdb4c2b29cf6f92b24e41fb8b646c9300 [file] [log] [blame]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * drawline.c: Functions for drawing window lines on the screen.
Bram Moolenaare89aeed2022-08-22 13:00:16 +010012 * This is the middle level, drawscreen.c is the higher level and screen.c the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020013 * lower level.
14 */
15
16#include "vim.h"
17
18#ifdef FEAT_SYN_HL
19/*
20 * Advance **color_cols and return TRUE when there are columns to draw.
21 */
22 static int
23advance_color_col(int vcol, int **color_cols)
24{
25 while (**color_cols >= 0 && vcol > **color_cols)
26 ++*color_cols;
27 return (**color_cols >= 0);
28}
29#endif
30
31#ifdef FEAT_SYN_HL
32/*
33 * Used when 'cursorlineopt' contains "screenline": compute the margins between
34 * which the highlighting is used.
35 */
36 static void
37margin_columns_win(win_T *wp, int *left_col, int *right_col)
38{
39 // cache previous calculations depending on w_virtcol
40 static int saved_w_virtcol;
41 static win_T *prev_wp;
42 static int prev_left_col;
43 static int prev_right_col;
44 static int prev_col_off;
45
46 int cur_col_off = win_col_off(wp);
47 int width1;
48 int width2;
49
50 if (saved_w_virtcol == wp->w_virtcol
51 && prev_wp == wp && prev_col_off == cur_col_off)
52 {
53 *right_col = prev_right_col;
54 *left_col = prev_left_col;
55 return;
56 }
57
58 width1 = wp->w_width - cur_col_off;
59 width2 = width1 + win_col_off2(wp);
60
61 *left_col = 0;
62 *right_col = width1;
63
64 if (wp->w_virtcol >= (colnr_T)width1)
65 *right_col = width1 + ((wp->w_virtcol - width1) / width2 + 1) * width2;
66 if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0)
67 *left_col = (wp->w_virtcol - width1) / width2 * width2 + width1;
68
69 // cache values
70 prev_left_col = *left_col;
71 prev_right_col = *right_col;
72 prev_wp = wp;
73 saved_w_virtcol = wp->w_virtcol;
74 prev_col_off = cur_col_off;
75}
76#endif
77
Bram Moolenaar1306b362022-08-06 15:59:06 +010078// structure with variables passed between win_line() and other functions
79typedef struct {
80 int draw_state; // what to draw next
81
82 linenr_T lnum; // line number to be drawn
83
84 int startrow; // first row in the window to be drawn
85 int row; // row in the window, excl w_winrow
86 int screen_row; // row on the screen, incl w_winrow
87
88 long vcol; // virtual column, before wrapping
89 int col; // visual column on screen, after wrapping
90#ifdef FEAT_CONCEAL
91 int boguscols; // nonexistent columns added to "col" to force
92 // wrapping
93 int vcol_off; // offset for concealed characters
94#endif
95#ifdef FEAT_SYN_HL
96 int draw_color_col; // highlight colorcolumn
97 int *color_cols; // pointer to according columns array
98#endif
99 int eol_hl_off; // 1 if highlighted char after EOL
100
101 unsigned off; // offset in ScreenLines/ScreenAttrs
102
103 int win_attr; // background for the whole window, except
104 // margins and "~" lines.
Bram Moolenaard7657e92022-09-20 18:59:30 +0100105 int wcr_attr; // attributes from 'wincolor'
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100106#ifdef FEAT_SYN_HL
107 int cul_attr; // set when 'cursorline' active
108#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100109
110 int screen_line_flags; // flags for screen_line()
111
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100112 int fromcol; // start of inverting
113 int tocol; // end of inverting
114
115#ifdef FEAT_LINEBREAK
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100116 long vcol_sbr; // virtual column after showbreak
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100117 int need_showbreak; // overlong line, skipping first x chars
118 int dont_use_showbreak; // do not use 'showbreak'
119#endif
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100120#ifdef FEAT_PROP_POPUP
121 int text_prop_above_count;
122#endif
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100123
Bram Moolenaar1306b362022-08-06 15:59:06 +0100124 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
125 int cul_screenline;
126
127 int char_attr; // attributes for the next character
128
129 int n_extra; // number of extra bytes
130 char_u *p_extra; // string of extra chars, plus NUL, only used
131 // when c_extra and c_final are NUL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100132 char_u *p_extra_free; // p_extra buffer that needs to be freed
Bram Moolenaaree28c702022-11-17 14:56:00 +0000133 int extra_attr; // attributes for p_extra, should be combined
134 // with win_attr if needed
Bram Moolenaar1306b362022-08-06 15:59:06 +0100135 int c_extra; // extra chars, all the same
136 int c_final; // final char, mandatory if set
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000137 int extra_for_textprop; // wlv.n_extra set for textprop
Bram Moolenaar1306b362022-08-06 15:59:06 +0100138
139 // saved "extra" items for when draw_state becomes WL_LINE (again)
140 int saved_n_extra;
141 char_u *saved_p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000142 int saved_extra_attr;
143 int saved_extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100144 int saved_c_extra;
145 int saved_c_final;
146 int saved_char_attr;
147
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100148 char_u extra[NUMBUFLEN + MB_MAXBYTES];
149 // "%ld " and 'fdc' must fit in here, as well
150 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100151
Bram Moolenaar1306b362022-08-06 15:59:06 +0100152#ifdef FEAT_DIFF
153 hlf_T diff_hlf; // type of diff highlighting
154#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100155 int filler_lines; // nr of filler lines to be drawn
156 int filler_todo; // nr of filler lines still to do + 1
157#ifdef FEAT_SIGNS
158 sign_attrs_T sattr;
159#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100160} winlinevars_T;
161
162// draw_state values for items that are drawn in sequence:
163#define WL_START 0 // nothing done yet, must be zero
Martin Tournoij7904fa42022-10-04 16:28:45 +0100164#define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar1306b362022-08-06 15:59:06 +0100165#ifdef FEAT_FOLDING
166# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
167#else
168# define WL_FOLD WL_CMDLINE
169#endif
170#ifdef FEAT_SIGNS
171# define WL_SIGN (WL_FOLD + 1) // column for signs
172#else
173# define WL_SIGN WL_FOLD // column for signs
174#endif
175#define WL_NR (WL_SIGN + 1) // line number
176#ifdef FEAT_LINEBREAK
177# define WL_BRI (WL_NR + 1) // 'breakindent'
178#else
179# define WL_BRI WL_NR
180#endif
181#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
182# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
183#else
184# define WL_SBR WL_BRI
185#endif
186#define WL_LINE (WL_SBR + 1) // text in the line
187
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100188#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200189/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000190 * Return TRUE if CursorLineSign highlight is to be used.
191 */
192 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100193use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000194{
195 return wp->w_p_cul
196 && lnum == wp->w_cursor.lnum
197 && (wp->w_p_culopt_flags & CULOPT_NBR);
198}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100199#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000200
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100201
202#ifdef FEAT_FOLDING
203/*
204 * Setup for drawing the 'foldcolumn', if there is one.
205 */
206 static void
207handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
208{
209 int fdc = compute_foldcolumn(wp, 0);
210
211 if (fdc <= 0)
212 return;
213
214 // Allocate a buffer, "wlv->extra[]" may already be in use.
215 vim_free(wlv->p_extra_free);
216 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
217 if (wlv->p_extra_free != NULL)
218 {
219 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
220 wp, FALSE, wlv->lnum);
221 wlv->p_extra_free[wlv->n_extra] = NUL;
222 wlv->p_extra = wlv->p_extra_free;
223 wlv->c_extra = NUL;
224 wlv->c_final = NUL;
225 if (use_cursor_line_highlight(wp, wlv->lnum))
226 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
227 else
228 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
229 }
230}
231#endif
232
233#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000234/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100235 * Get information needed to display the sign in line "wlv->lnum" in window
236 * "wp".
237 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200238 * Otherwise the sign is going to be displayed in the sign column.
239 */
240 static void
241get_sign_display_info(
242 int nrcol,
243 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100244 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200245{
246 int text_sign;
247# ifdef FEAT_SIGN_ICONS
248 int icon_sign;
249# endif
250
251 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100252 wlv->c_extra = ' ';
253 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200254 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100255 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200256 else
257 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100258 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100259 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000260 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100261 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100262 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200263 }
264
Bram Moolenaar1306b362022-08-06 15:59:06 +0100265 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200266#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100267 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200268#endif
269 )
270 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100271 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200272# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100273 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200274 if (gui.in_use && icon_sign != 0)
275 {
276 // Use the image in this position.
277 if (nrcol)
278 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100279 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100280 sprintf((char *)wlv->extra, "%-*c ",
281 number_width(wp), SIGN_BYTE);
282 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100283 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200284 }
285 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100286 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200287# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100288 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
289 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200290 {
291 if (nrcol)
292 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100293 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100294 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200295 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100296 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100297 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200298 }
299 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100300 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200301 }
302# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100303 wlv->c_final = NUL;
304 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200305 }
306 else
307# endif
308 if (text_sign != 0)
309 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100310 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100311 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200312 {
313 if (nrcol)
314 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100315 int width = number_width(wp) - 2;
316 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200317
318 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100319 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100320 vim_snprintf((char *)wlv->extra + n,
321 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100322 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200323 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100324 wlv->c_extra = NUL;
325 wlv->c_final = NUL;
326 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200327 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000328
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100329 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100330 && wlv->sattr.sat_culhl > 0)
331 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000332 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100333 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200334 }
335 }
336}
337#endif
338
Bram Moolenaard7657e92022-09-20 18:59:30 +0100339/*
340 * Display the absolute or relative line number. After the first row fill with
341 * blanks when the 'n' flag isn't in 'cpo'.
342 */
343 static void
344handle_lnum_col(
345 win_T *wp,
346 winlinevars_T *wlv,
347 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100348 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100349{
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100350 int has_cpo_n = vim_strchr(p_cpo, CPO_NUMCOL) != NULL;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100351 int lnum_row = wlv->startrow + wlv->filler_lines
352#ifdef FEAT_PROP_POPUP
353 + wlv->text_prop_above_count
354#endif
355 ;
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100356
Bram Moolenaard7657e92022-09-20 18:59:30 +0100357 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100358 && (wlv->row <= lnum_row || !has_cpo_n)
Bram Moolenaar37251162022-10-06 20:48:00 +0100359 // there is no line number in a wrapped line when "n" is in
360 // 'cpoptions', but 'breakindent' assumes it anyway.
361 && !((has_cpo_n
362#ifdef FEAT_LINEBREAK
363 && !wp->w_p_bri
364#endif
365 ) && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100366 {
367#ifdef FEAT_SIGNS
368 // If 'signcolumn' is set to 'number' and a sign is present
369 // in 'lnum', then display the sign instead of the line
370 // number.
371 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
372 get_sign_display_info(TRUE, wp, wlv);
373 else
374#endif
375 {
376 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100377 // When there are text properties above the line put the line number
378 // below them.
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100379 if (wlv->row == lnum_row
Bram Moolenaareb4de622022-10-15 13:42:17 +0100380 && (wp->w_skipcol == 0 || wlv->row > wp->w_winrow
381 || (wp->w_p_nu && wp->w_p_rnu)))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100382 {
383 long num;
384 char *fmt = "%*ld ";
385
386 if (wp->w_p_nu && !wp->w_p_rnu)
387 // 'number' + 'norelativenumber'
388 num = (long)wlv->lnum;
389 else
390 {
391 // 'relativenumber', don't use negative numbers
392 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
393 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
394 {
395 // 'number' + 'relativenumber'
396 num = wlv->lnum;
397 fmt = "%-*ld ";
398 }
399 }
400
401 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100402 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100403 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
404 ++wlv->p_extra)
405 *wlv->p_extra = '-';
406#ifdef FEAT_RIGHTLEFT
407 if (wp->w_p_rl) // reverse line numbers
408 {
409 char_u *p1, *p2;
410 int t;
411
412 // like rl_mirror(), but keep the space at the end
413 p2 = skipwhite(wlv->extra);
414 p2 = skiptowhite(p2) - 1;
415 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
416 {
417 t = *p1;
418 *p1 = *p2;
419 *p2 = t;
420 }
421 }
422#endif
423 wlv->p_extra = wlv->extra;
424 wlv->c_extra = NUL;
425 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100426 }
427 else
428 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100429 wlv->c_extra = ' ';
430 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100431 }
432 wlv->n_extra = number_width(wp) + 1;
433 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
434#ifdef FEAT_SYN_HL
435 // When 'cursorline' is set highlight the line number of
436 // the current line differently.
437 // When 'cursorlineopt' does not have "line" only
438 // highlight the line number itself.
439 // TODO: Can we use CursorLine instead of CursorLineNr
440 // when CursorLineNr isn't set?
441 if (wp->w_p_cul
442 && wlv->lnum == wp->w_cursor.lnum
443 && (wp->w_p_culopt_flags & CULOPT_NBR)
444 && (wlv->row == wlv->startrow + wlv->filler_lines
445 || (wlv->row > wlv->startrow + wlv->filler_lines
446 && (wp->w_p_culopt_flags & CULOPT_LINE))))
447 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
448#endif
449 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
450 && HL_ATTR(HLF_LNA) != 0)
451 // Use LineNrAbove
452 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
453 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
454 && HL_ATTR(HLF_LNB) != 0)
455 // Use LineNrBelow
456 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
457 }
458#ifdef FEAT_SIGNS
459 if (num_attr)
460 wlv->char_attr = num_attr;
461#endif
462 }
463}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100464
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100465#ifdef FEAT_LINEBREAK
466 static void
467handle_breakindent(win_T *wp, winlinevars_T *wlv)
468{
469 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100470 && *get_showbreak_value(wp) != NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100471 // draw indent after showbreak value
472 wlv->draw_state = WL_BRI;
473 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
474 // After the showbreak, draw the breakindent
475 wlv->draw_state = WL_BRI - 1;
476
477 // draw 'breakindent': indent wrapped text accordingly
478 if (wlv->draw_state == WL_BRI - 1)
479 {
480 wlv->draw_state = WL_BRI;
481 // if wlv->need_showbreak is set, breakindent also applies
482 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
483# ifdef FEAT_DIFF
484 && wlv->filler_lines == 0
485# endif
486# ifdef FEAT_PROP_POPUP
487 && !wlv->dont_use_showbreak
488# endif
489 )
490 {
491 wlv->char_attr = 0;
492# ifdef FEAT_DIFF
493 if (wlv->diff_hlf != (hlf_T)0)
494 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
495# endif
496 wlv->p_extra = NULL;
497 wlv->c_extra = ' ';
498 wlv->c_final = NUL;
499 wlv->n_extra = get_breakindent_win(wp,
500 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
501 if (wlv->row == wlv->startrow)
502 {
503 wlv->n_extra -= win_col_off2(wp);
504 if (wlv->n_extra < 0)
505 wlv->n_extra = 0;
506 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100507 if (wp->w_skipcol > 0 && wlv->startrow == 0
508 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100509 wlv->need_showbreak = FALSE;
510 // Correct end of highlighted area for 'breakindent',
511 // required when 'linebreak' is also set.
512 if (wlv->tocol == wlv->vcol)
513 wlv->tocol += wlv->n_extra;
514 }
515 }
516}
517#endif
518
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100519#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
520 static void
521handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
522{
523# ifdef FEAT_DIFF
524 if (wlv->filler_todo > 0)
525 {
526 // Draw "deleted" diff line(s).
527 if (char2cells(wp->w_fill_chars.diff) > 1)
528 {
529 wlv->c_extra = '-';
530 wlv->c_final = NUL;
531 }
532 else
533 {
534 wlv->c_extra = wp->w_fill_chars.diff;
535 wlv->c_final = NUL;
536 }
537# ifdef FEAT_RIGHTLEFT
538 if (wp->w_p_rl)
539 wlv->n_extra = wlv->col + 1;
540 else
541# endif
542 wlv->n_extra = wp->w_width - wlv->col;
543 wlv->char_attr = HL_ATTR(HLF_DED);
544 }
545# endif
546
547# ifdef FEAT_LINEBREAK
548 char_u *sbr = get_showbreak_value(wp);
549 if (*sbr != NUL && wlv->need_showbreak)
550 {
551 // Draw 'showbreak' at the start of each broken line.
552 wlv->p_extra = sbr;
553 wlv->c_extra = NUL;
554 wlv->c_final = NUL;
555 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100556 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100557 wlv->need_showbreak = FALSE;
558 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
559 // Correct end of highlighted area for 'showbreak',
560 // required when 'linebreak' is also set.
561 if (wlv->tocol == wlv->vcol)
562 wlv->tocol += wlv->n_extra;
563 // combine 'showbreak' with 'wincolor'
564 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
565# ifdef FEAT_SYN_HL
566 // combine 'showbreak' with 'cursorline'
567 if (wlv->cul_attr != 0)
568 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
569# endif
570 }
571# endif
572}
573#endif
574
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100575#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100576/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100577 * Return the cell size of virtual text after truncation.
578 */
579 static int
580textprop_size_after_trunc(
581 win_T *wp,
582 int flags, // TP_FLAG_ALIGN_*
583 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100584 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100585 char_u *text,
586 int *n_used_ptr)
587{
588 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100589 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100590 int len = (int)STRLEN(text);
591 int strsize = 0;
592 int n_used;
593
Bram Moolenaar7e017462022-10-11 21:02:09 +0100594 // if the remaining size is to small and 'wrap' is set we wrap anyway and
595 // use the next line
596 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100597 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100598 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100599 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100600 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
601 {
602 int clen = ptr2cells(text + n_used);
603
604 if (strsize + clen > space)
605 break;
606 strsize += clen;
607 }
608 *n_used_ptr = n_used;
609 return strsize;
610}
611
612/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100613 * Take care of padding, right-align and truncation of virtual text after a
614 * line.
615 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
616 * padding, right-align and truncation. Otherwise only the size is computed.
617 * When "n_attr" is NULL returns the number of screen cells used.
618 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100619 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100620 int
621text_prop_position(
622 win_T *wp,
623 textprop_T *tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100624 int vcol UNUSED, // current text column
625 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100626 int *n_extra, // nr of bytes for virtual text
627 char_u **p_extra, // virtual text
628 int *n_attr, // attribute cells, NULL if not used
629 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200630{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100631 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100632 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100633 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
634 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
635 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
636 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100637 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100638 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100639 int before = room; // spaces before the text
640 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100641 int n_used = *n_extra;
642 char_u *l = NULL;
643 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100644 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100645 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar1206c162022-10-10 15:40:04 +0100646 int cont_on_next_line = below && col_with_padding > win_col_off(wp)
647 && !wp->w_p_wrap;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200648
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100649 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100650 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100651 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100652 int skip_add = 0;
653
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100654 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100655 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100656 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100657 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100658 }
659 else
660 {
661 // Right-align: fill with before
662 if (right)
663 before -= cells;
664 if (before < 0
665 || !(right || below)
666 || (below
Bram Moolenaarccf28372022-10-10 21:10:03 +0100667 ? (col_with_padding <= col_off || !wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100668 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100669 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100670 if (right && (wrap
671 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100672 {
673 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100674 before = wp->w_width - col_off - strsize + room;
675 if (before < 0)
676 before = 0;
677 else
678 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100679 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100680 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100681 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100682 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100683 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100684 else if (below && before > 0)
685 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100686 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100687 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100688
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100689 // With 'nowrap' add one to show the "extends" character if needed (it
690 // doesn't show if the text just fits).
691 if (!wp->w_p_wrap
692 && n_used < *n_extra
693 && wp->w_lcs_chars.ext != NUL
694 && wp->w_p_list)
695 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100696 if (!wp->w_p_wrap && below && padding > 0)
697 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100698
699 // add 1 for NUL, 2 for when '…' is used
700 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100701 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100702 if (n_attr == NULL || l != NULL)
703 {
704 int off = 0;
705
706 if (n_attr != NULL)
707 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100708 vim_memset(l, ' ', before);
709 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100710 if (padding > 0)
711 {
712 vim_memset(l + off, ' ', padding);
713 off += padding;
714 }
715 vim_strncpy(l + off, *p_extra, n_used);
716 off += n_used;
717 }
718 else
719 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100720 off = before + after + padding + n_used;
721 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100722 }
723 if (n_attr != NULL)
724 {
725 if (n_used < *n_extra && wp->w_p_wrap)
726 {
727 char_u *lp = l + off - 1;
728
729 if (has_mbyte)
730 {
731 // change last character to '…'
732 lp -= (*mb_head_off)(l, lp);
733 STRCPY(lp, "…");
Bram Moolenaar13845c42022-10-09 15:26:03 +0100734 n_used = lp - l + 3 - before - padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100735 }
736 else
737 // change last character to '>'
738 *lp = '>';
739 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100740 else if (after > 0)
741 {
742 vim_memset(l + off, ' ', after);
743 l[off + after] = NUL;
744 }
745
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100746 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100747 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100748 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100749 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100750 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100751
752 // Add "skip_add" when starting a new line or wrapping,
753 // n_attr_skip will then be decremented in the number column.
754 *n_attr_skip = before + padding
755 + (cont_on_next_line || before > 0 ? skip_add : 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100756 }
757 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100758 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100759
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100760 if (n_attr == NULL)
761 return cells;
762 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200763}
764#endif
765
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100766/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100767 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100768 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
769 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100770 */
771 static void
772wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
773{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100774 if (wlv->row == 0 && wp->w_skipcol > 0
775#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100776 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100777 && *get_showbreak_value(wp) == NUL
778#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100779 // do not overwrite the 'listchars' "precedes" text with "<<<"
780 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100781 {
782 int off = (int)(current_ScreenLine - ScreenLines);
Bram Moolenaareb4de622022-10-15 13:42:17 +0100783 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100784
Bram Moolenaareb4de622022-10-15 13:42:17 +0100785 if (wp->w_p_nu && wp->w_p_rnu)
786 // Do not overwrite the line number, change "123 text" to
787 // "123>>>xt".
788 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
789 {
790 ++off;
791 ++skip;
792 }
793
794 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100795 {
796 ScreenLines[off] = '<';
797 if (enc_utf8)
798 ScreenLinesUC[off] = 0;
799 ScreenAttrs[off] = HL_ATTR(HLF_AT);
800 ++off;
801 }
802 }
803
804 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
805 negative_width ? -wp->w_width : wp->w_width,
806 wlv->screen_line_flags);
807}
808
809/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100810 * Called when finished with the line: draw the screen line and handle any
811 * highlighting until the right of the window.
812 */
813 static void
814draw_screen_line(win_T *wp, winlinevars_T *wlv)
815{
816#ifdef FEAT_SYN_HL
817 long v;
818
819 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
820 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100821 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100822 else
823 v = wp->w_leftcol;
824
825 // check if line ends before left margin
826 if (wlv->vcol < v + wlv->col - win_col_off(wp))
827 wlv->vcol = v + wlv->col - win_col_off(wp);
828# ifdef FEAT_CONCEAL
829 // Get rid of the boguscols now, we want to draw until the right
830 // edge for 'cursorcolumn'.
831 wlv->col -= wlv->boguscols;
832 wlv->boguscols = 0;
833# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
834# else
835# define VCOL_HLC (wlv->vcol)
836# endif
837
838 if (wlv->draw_color_col)
839 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
840
841 if (((wp->w_p_cuc
842 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
843 && (int)wp->w_virtcol <
844 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
845 && wlv->lnum != wp->w_cursor.lnum)
846 || wlv->draw_color_col
847 || wlv->win_attr != 0)
848# ifdef FEAT_RIGHTLEFT
849 && !wp->w_p_rl
850# endif
851 )
852 {
853 int rightmost_vcol = 0;
854 int i;
855
856 if (wp->w_p_cuc)
857 rightmost_vcol = wp->w_virtcol;
858 if (wlv->draw_color_col)
859 // determine rightmost colorcolumn to possibly draw
860 for (i = 0; wlv->color_cols[i] >= 0; ++i)
861 if (rightmost_vcol < wlv->color_cols[i])
862 rightmost_vcol = wlv->color_cols[i];
863
864 while (wlv->col < wp->w_width)
865 {
866 ScreenLines[wlv->off] = ' ';
867 if (enc_utf8)
868 ScreenLinesUC[wlv->off] = 0;
869 ScreenCols[wlv->off] = MAXCOL;
870 ++wlv->col;
871 if (wlv->draw_color_col)
872 wlv->draw_color_col = advance_color_col(
873 VCOL_HLC, &wlv->color_cols);
874
875 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
876 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
877 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
878 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
879 else
880 ScreenAttrs[wlv->off++] = wlv->win_attr;
881
882 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
883 break;
884
885 ++wlv->vcol;
886 }
887 }
888#endif
889
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100890 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100891 ++wlv->row;
892 ++wlv->screen_row;
893}
894#undef VCOL_HLC
895
896/*
897 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100898 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100899 */
900 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100901win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100902{
903 wlv->col = 0;
904 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
905
906#ifdef FEAT_RIGHTLEFT
907 if (wp->w_p_rl)
908 {
909 // Rightleft window: process the text in the normal direction, but put
910 // it in current_ScreenLine[] from right to left. Start at the
911 // rightmost column of the window.
912 wlv->col = wp->w_width - 1;
913 wlv->off += wlv->col;
914 wlv->screen_line_flags |= SLF_RIGHTLEFT;
915 }
916#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100917 if (save_extra)
918 {
919 // reset the drawing state for the start of a wrapped line
920 wlv->draw_state = WL_START;
921 wlv->saved_n_extra = wlv->n_extra;
922 wlv->saved_p_extra = wlv->p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000923 wlv->saved_extra_attr = wlv->extra_attr;
924 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100925 wlv->saved_c_extra = wlv->c_extra;
926 wlv->saved_c_final = wlv->c_final;
927#ifdef FEAT_SYN_HL
928 if (!(wlv->cul_screenline
929# ifdef FEAT_DIFF
930 && wlv->diff_hlf == (hlf_T)0
931# endif
932 ))
933 wlv->saved_char_attr = wlv->char_attr;
934 else
935#endif
936 wlv->saved_char_attr = 0;
937 wlv->n_extra = 0;
938 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100939}
940
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200941/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100942 * Called when wlv->draw_state is set to WL_LINE.
943 */
944 static void
945win_line_continue(winlinevars_T *wlv)
946{
947 if (wlv->saved_n_extra > 0)
948 {
949 // Continue item from end of wrapped line.
950 wlv->n_extra = wlv->saved_n_extra;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +0000951 wlv->saved_n_extra = 0;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100952 wlv->c_extra = wlv->saved_c_extra;
953 wlv->c_final = wlv->saved_c_final;
954 wlv->p_extra = wlv->saved_p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000955 wlv->extra_attr = wlv->saved_extra_attr;
956 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100957 wlv->char_attr = wlv->saved_char_attr;
958 }
959 else
960 wlv->char_attr = wlv->win_attr;
961}
962
963/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200964 * Display line "lnum" of window 'wp' on the screen.
965 * Start at row "startrow", stop when "endrow" is reached.
966 * wp->w_virtcol needs to be valid.
967 *
968 * Return the number of last row the line occupies.
969 */
970 int
971win_line(
972 win_T *wp,
973 linenr_T lnum,
974 int startrow,
975 int endrow,
976 int nochange UNUSED, // not updating for changed text
977 int number_only) // only update the number column
978{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100979 winlinevars_T wlv; // variables passed between functions
980
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200981 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100982 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200983 char_u *line; // current line
984 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200985
Bram Moolenaar1306b362022-08-06 15:59:06 +0100986#ifdef FEAT_PROP_POPUP
987 char_u *p_extra_free2 = NULL; // another p_extra to be freed
988#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000989#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000990 int in_linebreak = FALSE; // n_extra set for showing linebreak
991#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200992 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100993 // displaying eol at end-of-line
994 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000995 int lcs_prec_todo = wp->w_lcs_chars.prec;
996 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200997
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100998 int n_attr = 0; // chars with special attr
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000999 int n_attr_skip = 0; // chars to skip bef. using wlv.extra_attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001000 int saved_attr2 = 0; // char_attr saved for n_attr
1001 int n_attr3 = 0; // chars with overruling special attr
1002 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001003
Bram Moolenaarcd105412022-10-10 19:50:42 +01001004 int n_skip = 0; // nr of cells to skip for 'nowrap' or
1005 // concealing
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001006#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001007 int skip_cells = 0; // nr of cells to skip for virtual text
1008 // after the line, when w_skipcol is
1009 // larger than the text length
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001010#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001011
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001012 int fromcol_prev = -2; // start of inverting after cursor
1013 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001014 int lnum_in_visual_area = FALSE;
1015 pos_T pos;
1016 long v;
1017
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001018 int attr_pri = FALSE; // char_attr has priority
1019 int area_highlighting = FALSE; // Visual or incsearch highlighting
1020 // in this line
1021 int vi_attr = 0; // attributes for Visual and incsearch
1022 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001023 int area_attr = 0; // attributes desired by highlighting
1024 int search_attr = 0; // attributes desired by 'hlsearch'
1025#ifdef FEAT_SYN_HL
1026 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1027 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001028 int prev_syntax_col = -1; // column of prev_syntax_attr
1029 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001030 int has_syntax = FALSE; // this buffer has syntax highl.
1031 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001032#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001033#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001034 int text_prop_count;
1035 int text_prop_next = 0; // next text property to use
1036 textprop_T *text_props = NULL;
1037 int *text_prop_idxs = NULL;
1038 int text_props_active = 0;
1039 proptype_T *text_prop_type = NULL;
1040 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001041 int text_prop_attr_comb = 0; // text_prop_attr combined with
1042 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001043 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001044 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001045 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001046 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001047 int saved_search_attr = 0; // search_attr to be used when n_extra
1048 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001049 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001050 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001051#endif
1052#ifdef FEAT_SPELL
1053 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001054 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001055# define SPWORDLEN 150
1056 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1057 int nextlinecol = 0; // column where nextline[] starts
1058 int nextline_idx = 0; // index in nextline[] where next line
1059 // starts
1060 int spell_attr = 0; // attributes desired by spelling
1061 int word_end = 0; // last byte with same spell_attr
1062 static linenr_T checked_lnum = 0; // line number for "checked_col"
1063 static int checked_col = 0; // column in "checked_lnum" up to which
1064 // there are no spell errors
1065 static int cap_col = -1; // column to check for Cap word
1066 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1067 int cur_checked_col = 0; // checked column for current line
1068#endif
1069 int extra_check = 0; // has extra highlighting
1070 int multi_attr = 0; // attributes desired by multibyte
1071 int mb_l = 1; // multi-byte byte length
1072 int mb_c = 0; // decoded multi-byte character
1073 int mb_utf8 = FALSE; // screen char is UTF-8 char
1074 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001075#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001076 int change_start = MAXCOL; // first col of changed area
1077 int change_end = -1; // last col of changed area
1078#endif
1079 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001080 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001081 int in_multispace = FALSE; // in multiple consecutive spaces
1082 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001083#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
1084 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
1085# define LINE_ATTR
1086 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +01001087 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001088#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001089 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001090 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001091#ifdef FEAT_ARABIC
1092 int prev_c = 0; // previous Arabic character
1093 int prev_c1 = 0; // first composing char for prev_c
1094#endif
1095#if defined(LINE_ATTR)
1096 int did_line_attr = 0;
1097#endif
1098#ifdef FEAT_TERMINAL
1099 int get_term_attr = FALSE;
1100#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001101
Martin Tournoijba43e762022-10-13 22:12:15 +01001102#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001103 // margin columns for the screen line, needed for when 'cursorlineopt'
1104 // contains "screenline"
1105 int left_curline_col = 0;
1106 int right_curline_col = 0;
1107#endif
1108
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001109#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1110 int feedback_col = 0;
1111 int feedback_old_attr = -1;
1112#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001113
1114#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1115 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001116#endif
1117#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001118 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001119#endif
1120#ifdef FEAT_CONCEAL
1121 int syntax_flags = 0;
1122 int syntax_seqnr = 0;
1123 int prev_syntax_id = 0;
1124 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1125 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001126 int did_wcol = FALSE;
1127 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001128# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001129# define FIX_FOR_BOGUSCOLS \
1130 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001131 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001132 wlv.vcol -= wlv.vcol_off; \
1133 wlv.vcol_off = 0; \
1134 wlv.col -= wlv.boguscols; \
1135 old_boguscols = wlv.boguscols; \
1136 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001137 }
1138#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001139# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001140#endif
1141
1142 if (startrow > endrow) // past the end already!
1143 return startrow;
1144
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001145 CLEAR_FIELD(wlv);
1146
1147 wlv.lnum = lnum;
1148 wlv.startrow = startrow;
1149 wlv.row = startrow;
1150 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001151 wlv.fromcol = -10;
1152 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001153#ifdef FEAT_LINEBREAK
1154 wlv.vcol_sbr = -1;
1155#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001156
1157 if (!number_only)
1158 {
1159 // To speed up the loop below, set extra_check when there is linebreak,
1160 // trailing white space and/or syntax processing to be done.
1161#ifdef FEAT_LINEBREAK
1162 extra_check = wp->w_p_lbr;
1163#endif
1164#ifdef FEAT_SYN_HL
1165 if (syntax_present(wp) && !wp->w_s->b_syn_error
1166# ifdef SYN_TIME_LIMIT
1167 && !wp->w_s->b_syn_slow
1168# endif
1169 )
1170 {
1171 // Prepare for syntax highlighting in this line. When there is an
1172 // error, stop syntax highlighting.
1173 save_did_emsg = did_emsg;
1174 did_emsg = FALSE;
1175 syntax_start(wp, lnum);
1176 if (did_emsg)
1177 wp->w_s->b_syn_error = TRUE;
1178 else
1179 {
1180 did_emsg = save_did_emsg;
1181#ifdef SYN_TIME_LIMIT
1182 if (!wp->w_s->b_syn_slow)
1183#endif
1184 {
1185 has_syntax = TRUE;
1186 extra_check = TRUE;
1187 }
1188 }
1189 }
1190
1191 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001192 wlv.color_cols = wp->w_p_cc_cols;
1193 if (wlv.color_cols != NULL)
1194 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001195#endif
1196
1197#ifdef FEAT_TERMINAL
1198 if (term_show_buffer(wp->w_buffer))
1199 {
1200 extra_check = TRUE;
1201 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001202 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001203 }
1204#endif
1205
1206#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001207 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001208 {
1209 // Prepare for spell checking.
1210 has_spell = TRUE;
1211 extra_check = TRUE;
1212
1213 // Get the start of the next line, so that words that wrap to the
1214 // next line are found too: "et<line-break>al.".
1215 // Trick: skip a few chars for C/shell/Vim comments
1216 nextline[SPWORDLEN] = NUL;
1217 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1218 {
1219 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1220 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1221 }
1222
1223 // When a word wrapped from the previous line the start of the
1224 // current line is valid.
1225 if (lnum == checked_lnum)
1226 cur_checked_col = checked_col;
1227 checked_lnum = 0;
1228
1229 // When there was a sentence end in the previous line may require a
1230 // word starting with capital in this line. In line 1 always check
1231 // the first word.
1232 if (lnum != capcol_lnum)
1233 cap_col = -1;
1234 if (lnum == 1)
1235 cap_col = 0;
1236 capcol_lnum = 0;
1237 }
1238#endif
1239
1240 // handle Visual active in this window
1241 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1242 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001243 pos_T *top, *bot;
1244
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001245 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1246 {
1247 // Visual is after curwin->w_cursor
1248 top = &curwin->w_cursor;
1249 bot = &VIsual;
1250 }
1251 else
1252 {
1253 // Visual is before curwin->w_cursor
1254 top = &VIsual;
1255 bot = &curwin->w_cursor;
1256 }
1257 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1258 if (VIsual_mode == Ctrl_V)
1259 {
1260 // block mode
1261 if (lnum_in_visual_area)
1262 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001263 wlv.fromcol = wp->w_old_cursor_fcol;
1264 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001265 }
1266 }
1267 else
1268 {
1269 // non-block mode
1270 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001271 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001272 else if (lnum == top->lnum)
1273 {
1274 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001275 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001276 else
1277 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001278 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001279 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001280 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001281 }
1282 }
1283 if (VIsual_mode != 'V' && lnum == bot->lnum)
1284 {
1285 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1286 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001287 wlv.fromcol = -10;
1288 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001289 }
1290 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001291 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001292 else
1293 {
1294 pos = *bot;
1295 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001296 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1297 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001298 else
1299 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001300 getvvcol(wp, &pos, NULL, NULL,
1301 (colnr_T *)&wlv.tocol);
1302 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001303 }
1304 }
1305 }
1306 }
1307
1308 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001309 if (!highlight_match && lnum == curwin->w_cursor.lnum
1310 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001311#ifdef FEAT_GUI
1312 && !gui.in_use
1313#endif
1314 )
1315 noinvcur = TRUE;
1316
1317 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001318 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001319 {
1320 area_highlighting = TRUE;
1321 vi_attr = HL_ATTR(HLF_V);
1322#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1323 if ((clip_star.available && !clip_star.owned
1324 && clip_isautosel_star())
1325 || (clip_plus.available && !clip_plus.owned
1326 && clip_isautosel_plus()))
1327 vi_attr = HL_ATTR(HLF_VNC);
1328#endif
1329 }
1330 }
1331
1332 // handle 'incsearch' and ":s///c" highlighting
1333 else if (highlight_match
1334 && wp == curwin
1335 && lnum >= curwin->w_cursor.lnum
1336 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1337 {
1338 if (lnum == curwin->w_cursor.lnum)
1339 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001340 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001341 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001342 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001343 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1344 {
1345 pos.lnum = lnum;
1346 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001347 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001348 }
1349 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001350 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001351 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001352 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1353 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001354 area_highlighting = TRUE;
1355 vi_attr = HL_ATTR(HLF_I);
1356 }
1357 }
1358
1359#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001360 wlv.filler_lines = diff_check(wp, lnum);
1361 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001362 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001363 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001364 {
1365 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001366 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001367 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001368 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001369 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001370 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001371 }
1372 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001373 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001374 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001375 area_highlighting = TRUE;
1376 }
1377 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001378 wlv.filler_lines = wp->w_topfill;
1379 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001380#endif
1381
1382#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001383 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001384 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001385 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001386#endif
1387
1388#ifdef LINE_ATTR
1389# ifdef FEAT_SIGNS
1390 // If this line has a sign with line highlighting set line_attr.
1391 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001392 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001393# endif
1394# if defined(FEAT_QUICKFIX)
1395 // Highlight the current line in the quickfix window.
1396 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1397 line_attr = HL_ATTR(HLF_QFL);
1398# endif
1399 if (line_attr != 0)
1400 area_highlighting = TRUE;
1401#endif
1402
1403 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1404 ptr = line;
1405
1406#ifdef FEAT_SPELL
1407 if (has_spell && !number_only)
1408 {
1409 // For checking first word with a capital skip white space.
1410 if (cap_col == 0)
1411 cap_col = getwhitecols(line);
1412
1413 // To be able to spell-check over line boundaries copy the end of the
1414 // current line into nextline[]. Above the start of the next line was
1415 // copied to nextline[SPWORDLEN].
1416 if (nextline[SPWORDLEN] == NUL)
1417 {
1418 // No next line or it is empty.
1419 nextlinecol = MAXCOL;
1420 nextline_idx = 0;
1421 }
1422 else
1423 {
1424 v = (long)STRLEN(line);
1425 if (v < SPWORDLEN)
1426 {
1427 // Short line, use it completely and append the start of the
1428 // next line.
1429 nextlinecol = 0;
1430 mch_memmove(nextline, line, (size_t)v);
1431 STRMOVE(nextline + v, nextline + SPWORDLEN);
1432 nextline_idx = v + 1;
1433 }
1434 else
1435 {
1436 // Long line, use only the last SPWORDLEN bytes.
1437 nextlinecol = v - SPWORDLEN;
1438 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1439 nextline_idx = SPWORDLEN + 1;
1440 }
1441 }
1442 }
1443#endif
1444
1445 if (wp->w_p_list)
1446 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001447 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001448 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001449 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001450 || wp->w_lcs_chars.trail
1451 || wp->w_lcs_chars.lead
1452 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001453 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001454
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001455 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001456 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001457 {
1458 trailcol = (colnr_T)STRLEN(ptr);
1459 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1460 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001461 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001462 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001463 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001464 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001465 {
1466 leadcol = 0;
1467 while (VIM_ISWHITE(ptr[leadcol]))
1468 ++leadcol;
1469 if (ptr[leadcol] == NUL)
1470 // in a line full of spaces all of them are treated as trailing
1471 leadcol = (colnr_T)0;
1472 else
1473 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001474 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001475 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001476 }
1477
Bram Moolenaard7657e92022-09-20 18:59:30 +01001478 wlv.wcr_attr = get_wcr_attr(wp);
1479 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001480 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001481 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001482 area_highlighting = TRUE;
1483 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001484
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001485#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001486 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001487 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001488#endif
1489
1490 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1491 // first character to be displayed.
1492 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001493 v = startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001494 else
1495 v = wp->w_leftcol;
1496 if (v > 0 && !number_only)
1497 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001498 char_u *prev_ptr = ptr;
1499 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001500 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001501
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001502 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001503 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001504 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001505 charsize = win_lbr_chartabsize(&cts, NULL);
1506 cts.cts_vcol += charsize;
1507 prev_ptr = cts.cts_ptr;
1508 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001509 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001510 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001511 ptr = cts.cts_ptr;
1512 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001513
1514 // When:
1515 // - 'cuc' is set, or
1516 // - 'colorcolumn' is set, or
1517 // - 'virtualedit' is set, or
1518 // - the visual mode is active,
1519 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001520 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001521#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001522 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001523#endif
1524 virtual_active() ||
1525 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001526 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001527
1528 // Handle a character that's not completely on the screen: Put ptr at
1529 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001530 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001531 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001532 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001533 ptr = prev_ptr;
1534 // If the character fits on the screen, don't need to skip it.
1535 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001536 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1537 && wlv.col == 0)
1538 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001539 }
1540
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001541#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001542 // If there the text doesn't reach to the desired column, need to skip
1543 // "skip_cells" cells when virtual text follows.
1544 if (!wp->w_p_wrap && v > wlv.vcol)
1545 skip_cells = v - wlv.vcol;
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001546#endif
Bram Moolenaarcd105412022-10-10 19:50:42 +01001547
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001548 // Adjust for when the inverted text is before the screen,
1549 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001550 if (wlv.tocol <= wlv.vcol)
1551 wlv.fromcol = 0;
1552 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1553 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001554
1555#ifdef FEAT_LINEBREAK
1556 // When w_skipcol is non-zero, first line needs 'showbreak'
1557 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001558 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001559#endif
1560#ifdef FEAT_SPELL
1561 // When spell checking a word we need to figure out the start of the
1562 // word and if it's badly spelled or not.
1563 if (has_spell)
1564 {
1565 int len;
1566 colnr_T linecol = (colnr_T)(ptr - line);
1567 hlf_T spell_hlf = HLF_COUNT;
1568
1569 pos = wp->w_cursor;
1570 wp->w_cursor.lnum = lnum;
1571 wp->w_cursor.col = linecol;
1572 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1573
1574 // spell_move_to() may call ml_get() and make "line" invalid
1575 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1576 ptr = line + linecol;
1577
1578 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1579 {
1580 // no bad word found at line start, don't check until end of a
1581 // word
1582 spell_hlf = HLF_COUNT;
1583 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1584 }
1585 else
1586 {
1587 // bad word found, use attributes until end of word
1588 word_end = wp->w_cursor.col + len + 1;
1589
1590 // Turn index into actual attributes.
1591 if (spell_hlf != HLF_COUNT)
1592 spell_attr = highlight_attr[spell_hlf];
1593 }
1594 wp->w_cursor = pos;
1595
1596# ifdef FEAT_SYN_HL
1597 // Need to restart syntax highlighting for this line.
1598 if (has_syntax)
1599 syntax_start(wp, lnum);
1600# endif
1601 }
1602#endif
1603 }
1604
1605 // Correct highlighting for cursor that can't be disabled.
1606 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001607 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001608 {
1609 if (noinvcur)
1610 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001611 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001612 {
1613 // highlighting starts at cursor, let it start just after the
1614 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001615 fromcol_prev = wlv.fromcol;
1616 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001617 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001618 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001619 // restart highlighting after the cursor
1620 fromcol_prev = wp->w_virtcol;
1621 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001622 if (wlv.fromcol >= wlv.tocol)
1623 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001624 }
1625
1626#ifdef FEAT_SEARCH_EXTRA
1627 if (!number_only)
1628 {
1629 v = (long)(ptr - line);
1630 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1631 &line, &screen_search_hl,
1632 &search_attr);
1633 ptr = line + v; // "line" may have been updated
1634 }
1635#endif
1636
1637#ifdef FEAT_SYN_HL
1638 // Cursor line highlighting for 'cursorline' in the current window.
1639 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1640 {
1641 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001642 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001643 if (!(wp == curwin && VIsual_active)
1644 && wp->w_p_culopt_flags != CULOPT_NBR)
1645 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001646 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001647 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1648
1649 // Only set line_attr here when "screenline" is not present in
1650 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001651 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001652 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001653 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001654# ifdef FEAT_SIGNS
1655 // Combine the 'cursorline' and sign highlighting, depending on
1656 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001657 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001658 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001659 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001660 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001661 else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001662 line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001663 }
1664 else
1665# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001666# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001667 // let the line attribute overrule 'cursorline', otherwise
1668 // it disappears when both have background set;
1669 // 'cursorline' can use underline or bold to make it show
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001670 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001671# else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001672 line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001673# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001674 }
1675 else
1676 {
1677 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001678 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1679 }
1680 area_highlighting = TRUE;
1681 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001682 }
1683#endif
1684
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001685#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001686 {
1687 char_u *prop_start;
1688
1689 text_prop_count = get_text_props(wp->w_buffer, lnum,
1690 &prop_start, FALSE);
1691 if (text_prop_count > 0)
1692 {
1693 // Make a copy of the properties, so that they are properly
1694 // aligned.
1695 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1696 if (text_props != NULL)
1697 mch_memmove(text_props, prop_start,
1698 text_prop_count * sizeof(textprop_T));
1699
1700 // Allocate an array for the indexes.
1701 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001702 if (text_prop_idxs == NULL)
1703 VIM_CLEAR(text_props);
1704
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001705 if (text_props != NULL)
1706 {
1707 area_highlighting = TRUE;
1708 extra_check = TRUE;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +01001709 // text props "above" move the line number down to where the
1710 // text is.
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001711 for (int i = 0; i < text_prop_count; ++i)
1712 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1713 ++wlv.text_prop_above_count;
1714 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001715 }
1716 }
1717#endif
1718
Bram Moolenaar1306b362022-08-06 15:59:06 +01001719 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001720
1721 // Repeat for the whole displayed line.
1722 for (;;)
1723 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001724 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001725#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001726 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001727#endif
1728#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001729 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001730#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001731
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001732 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001733 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001734 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001735#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001736 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001737 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001738 wlv.cul_attr = 0;
zeertzjq4f33bc22021-08-05 17:57:02 +02001739 line_attr = line_attr_save;
1740 }
1741#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001742 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001743 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001744 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001745 if (cmdwin_type != 0 && wp == curwin)
1746 {
1747 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001748 wlv.n_extra = 1;
1749 wlv.c_extra = cmdwin_type;
1750 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001751 wlv.char_attr =
1752 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001753 }
1754 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001755#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001756 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001757 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001758 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001759 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001760 }
1761#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001762#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001763 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001764 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001765 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001766 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001767 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001768 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001769 }
1770#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001771 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001772 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001773 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001774 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001775 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001776 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001777#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001778 // Check if 'breakindent' applies and show it.
1779 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1780 if (wlv.n_extra == 0)
1781 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001782#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001783#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001784 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001785 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001786 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001787 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001788 }
1789#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001790 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001791 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001792 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001793 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001794 }
1795 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001796
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001797#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001798 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001799 && wlv.vcol >= left_curline_col
1800 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001801 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001802 wlv.cul_attr = HL_ATTR(HLF_CUL);
1803 line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001804 }
1805#endif
1806
1807 // When still displaying '$' of change command, stop at cursor.
1808 // When only displaying the (relative) line number and that's done,
1809 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001810 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001811 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001812 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001813#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001814 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001815#endif
1816 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001817 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001818 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001819 // Pretend we have finished updating the window. Except when
1820 // 'cursorcolumn' is set.
1821#ifdef FEAT_SYN_HL
1822 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001823 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001824 else
1825#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001826 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001827 break;
1828 }
1829
Bram Moolenaar1306b362022-08-06 15:59:06 +01001830 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001831 {
1832 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001833 if (wlv.vcol == wlv.fromcol
1834 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1835 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001836 && (*mb_ptr2cells)(ptr) > 1)
1837 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001838 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001839 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001840 area_attr = vi_attr; // start highlighting
1841 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001842 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001843 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001844 area_attr = 0; // stop highlighting
1845
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001846#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001847 if (text_props != NULL)
1848 {
1849 int pi;
1850 int bcol = (int)(ptr - line);
1851
Bram Moolenaar1306b362022-08-06 15:59:06 +01001852 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001853# ifdef FEAT_LINEBREAK
1854 && !in_linebreak
1855# endif
1856 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001857 --bcol; // still working on the previous char, e.g. Tab
1858
1859 // Check if any active property ends.
1860 for (pi = 0; pi < text_props_active; ++pi)
1861 {
1862 int tpi = text_prop_idxs[pi];
1863
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001864 if (text_props[tpi].tp_col != MAXCOL
1865 && bcol >= text_props[tpi].tp_col - 1
1866 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001867 {
1868 if (pi + 1 < text_props_active)
1869 mch_memmove(text_prop_idxs + pi,
1870 text_prop_idxs + pi + 1,
1871 sizeof(int)
1872 * (text_props_active - (pi + 1)));
1873 --text_props_active;
1874 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001875# ifdef FEAT_LINEBREAK
1876 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001877 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001878 syntax_attr = 0;
1879# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001880 }
1881 }
1882
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001883# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001884 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001885 // not on the next char yet, don't start another prop
1886 --bcol;
1887# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001888 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001889 // With 'nowrap' and not in the first screen line only "below"
1890 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001891 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001892 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001893 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001894 && (wp->w_p_wrap
1895 || wlv.row == startrow
1896 || (text_props[text_prop_next].tp_flags
1897 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001898 || (bcol == 0 &&
1899 (text_props[text_prop_next].tp_flags
1900 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001901 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001902 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001903 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001904 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1905 {
1906 // first display the '$' after the line
1907 text_prop_follows = TRUE;
1908 break;
1909 }
1910 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001911 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001912 + text_props[text_prop_next].tp_len)
1913 text_prop_idxs[text_props_active++] = text_prop_next;
1914 ++text_prop_next;
1915 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001916
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001917 if (wlv.n_extra == 0 || !wlv.extra_for_textprop)
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001918 {
1919 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001920 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001921 text_prop_flags = 0;
1922 text_prop_type = NULL;
1923 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001924 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001925 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001926 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001927 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001928 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001929 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001930 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001931
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001932 // Sort the properties on priority and/or starting last.
1933 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001934 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001935 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001936 sort_text_props(wp->w_buffer, text_props,
1937 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001938
1939 for (pi = 0; pi < text_props_active; ++pi)
1940 {
1941 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001942 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001943 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01001944 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001945
Bram Moolenaarcd105412022-10-10 19:50:42 +01001946 // Only use a text property that can be displayed.
1947 // Skip "after" properties when wrap is off and at the
1948 // end of the window.
1949 if (pt != NULL
1950 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
1951 && tp->tp_id != -MAXCOL
1952 && !(tp->tp_id < 0
1953 && !wp->w_p_wrap
1954 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
1955 | TP_FLAG_ALIGN_ABOVE
1956 | TP_FLAG_ALIGN_BELOW)) == 0
1957 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001958 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001959 if (pt->pt_hl_id > 0)
1960 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001961 text_prop_type = pt;
1962 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001963 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001964 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001965 text_prop_flags = pt->pt_flags;
1966 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001967 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001968 }
1969 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001970 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001971 && -text_prop_id
1972 <= wp->w_buffer->b_textprop_text.ga_len)
1973 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001974 textprop_T *tp = &text_props[used_tpi];
1975 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001976 ->b_textprop_text.ga_data)[
1977 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001978 int above = (tp->tp_flags
1979 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01001980 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001981
1982 // reset the ID in the copy to avoid it being used
1983 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001984 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001985
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001986 if (p != NULL)
1987 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001988 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001989 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001990 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001991 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001992 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1993 int padding = tp->tp_col == MAXCOL
1994 && tp->tp_len > 1
1995 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001996
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001997 // Insert virtual text before the current
1998 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001999 wlv.p_extra = p;
2000 wlv.c_extra = NUL;
2001 wlv.c_final = NUL;
2002 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002003 wlv.extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002004 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2005 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002006 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002007 // restore search_attr and area_attr when n_extra
2008 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01002009 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002010 saved_area_attr = area_attr;
2011 search_attr = 0;
2012 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002013 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002014 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002015 if (*ptr == NUL)
2016 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002017 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002018#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002019 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002020 {
2021 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002022 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002023 wlv.need_showbreak = FALSE;
2024 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002025 }
2026#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002027 if ((right || above || below || !wrap
2028 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002029 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002030 char_u *prev_p_extra = wlv.p_extra;
2031 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002032
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002033 // Take care of padding, right-align and
2034 // truncation.
2035 // Shared with win_lbr_chartabsize(), must do
2036 // exactly the same.
2037 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002038 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002039 wlv.col,
2040 &wlv.n_extra, &wlv.p_extra,
2041 &n_attr, &n_attr_skip);
2042 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002043 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002044 // wlv.p_extra was allocated
2045 vim_free(p_extra_free2);
2046 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002047 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002048
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002049 if (lcs_eol_one < 0
2050 && wp->w_p_wrap
2051 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002052 + wlv.n_extra - 2 > wp->w_width)
2053 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002054 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002055
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002056 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002057 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002058 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002059 {
2060 draw_screen_line(wp, &wlv);
2061
2062 // When line got too long for screen break
2063 // here.
2064 if (wlv.row == endrow)
2065 {
2066 ++wlv.row;
2067 break;
2068 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002069 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002070 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002071 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002072 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002073 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002074
Bram Moolenaarcd105412022-10-10 19:50:42 +01002075 // If the text didn't reach until the first window
2076 // column we need to skip cells.
2077 if (skip_cells > 0)
2078 {
2079 if (wlv.n_extra > skip_cells)
2080 {
2081 wlv.n_extra -= skip_cells;
2082 wlv.p_extra += skip_cells;
2083 n_attr_skip -= skip_cells;
2084 if (n_attr_skip < 0)
2085 n_attr_skip = 0;
2086 skip_cells = 0;
2087 }
2088 else
2089 {
2090 // the whole text is left of the window, drop
2091 // it and advance to the next one
2092 skip_cells -= wlv.n_extra;
2093 wlv.n_extra = 0;
2094 n_attr_skip = 0;
2095 bail_out = TRUE;
2096 }
2097 }
2098
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002099 // If another text prop follows the condition below at
2100 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002101 // If this is an "above" text prop and 'nowrap' the we
2102 // must wrap anyway.
2103 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002104 text_prop_follows |= other_tpi != -1
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002105 && (wp->w_p_wrap
2106 || (text_props[other_tpi].tp_flags
2107 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002108
2109 if (bail_out)
2110 // starting a new line for "below"
2111 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002112 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002113 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002114 else if (text_prop_next < text_prop_count
2115 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002116 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2117 || (!wp->w_p_wrap
2118 && wlv.col == wp->w_width - 1
2119 && (text_props[text_prop_next].tp_flags
2120 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002121 // When at last-but-one character and a text property
2122 // follows after it, we may need to flush the line after
2123 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002124 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002125 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002126 }
2127#endif
2128
Bram Moolenaare38fc862022-08-11 17:24:50 +01002129#ifdef FEAT_SEARCH_EXTRA
2130 if (wlv.n_extra == 0)
2131 {
2132 // Check for start/end of 'hlsearch' and other matches.
2133 // After end, check for start/end of next match.
2134 // When another match, have to check for start again.
2135 v = (long)(ptr - line);
2136 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2137 &screen_search_hl, &has_match_conc,
2138 &match_conc, did_line_attr, lcs_eol_one,
2139 &on_last_col);
2140 ptr = line + v; // "line" may have been changed
2141 prev_ptr = ptr;
2142
2143 // Do not allow a conceal over EOL otherwise EOL will be missed
2144 // and bad things happen.
2145 if (*ptr == NUL)
2146 has_match_conc = 0;
2147 }
2148#endif
2149
2150#ifdef FEAT_DIFF
2151 if (wlv.diff_hlf != (hlf_T)0)
2152 {
2153 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2154 && wlv.n_extra == 0)
2155 wlv.diff_hlf = HLF_TXD; // changed text
2156 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2157 && wlv.n_extra == 0)
2158 wlv.diff_hlf = HLF_CHD; // changed line
2159 line_attr = HL_ATTR(wlv.diff_hlf);
2160 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2161 && wp->w_p_culopt_flags != CULOPT_NBR
2162 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2163 && wlv.vcol <= right_curline_col)))
2164 line_attr = hl_combine_attr(
2165 line_attr, HL_ATTR(HLF_CUL));
2166 }
2167#endif
2168
Bram Moolenaara74fda62019-10-19 17:38:03 +02002169#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002170 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002171 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002172 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002173# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002174 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002175 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002176# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002177 // Get syntax attribute.
2178 if (has_syntax)
2179 {
2180 // Get the syntax attribute for the character. If there
2181 // is an error, disable syntax highlighting.
2182 save_did_emsg = did_emsg;
2183 did_emsg = FALSE;
2184
2185 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002186 if (v == prev_syntax_col)
2187 // at same column again
2188 syntax_attr = prev_syntax_attr;
2189 else
2190 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002191# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002192 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002193# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002194 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002195# ifdef FEAT_SPELL
2196 has_spell ? &can_spell :
2197# endif
2198 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002199 prev_syntax_col = v;
2200 prev_syntax_attr = syntax_attr;
2201 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002202
Bram Moolenaar34390282019-10-16 14:38:26 +02002203 if (did_emsg)
2204 {
2205 wp->w_s->b_syn_error = TRUE;
2206 has_syntax = FALSE;
2207 syntax_attr = 0;
2208 }
2209 else
2210 did_emsg = save_did_emsg;
2211# ifdef SYN_TIME_LIMIT
2212 if (wp->w_s->b_syn_slow)
2213 has_syntax = FALSE;
2214# endif
2215
2216 // Need to get the line again, a multi-line regexp may
2217 // have made it invalid.
2218 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2219 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002220 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002221# ifdef FEAT_CONCEAL
2222 // no concealing past the end of the line, it interferes
2223 // with line highlighting
2224 if (*ptr == NUL)
2225 syntax_flags = 0;
2226 else
2227 syntax_flags = get_syntax_info(&syntax_seqnr);
2228# endif
2229 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002230 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002231# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002232 // Combine text property highlight into syntax highlight.
2233 if (text_prop_type != NULL)
2234 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002235 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002236 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2237 else
2238 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002239 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002240 }
2241# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002242#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002243
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002244 // Decide which of the highlight attributes to use.
2245 attr_pri = TRUE;
2246#ifdef LINE_ATTR
2247 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002248 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002249 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002250 if (!highlight_match)
2251 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002252 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002253# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002254 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002255# endif
2256 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002257 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002258 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002259 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002260# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002261 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002262# endif
2263 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002264 else if (line_attr != 0
2265 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2266 || wlv.vcol < wlv.fromcol
2267 || vcol_prev < fromcol_prev
2268 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002269 {
2270 // Use line_attr when not in the Visual or 'incsearch' area
2271 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002272# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002273 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002274# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002275 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002276# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002277 attr_pri = FALSE;
2278 }
2279#else
2280 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002281 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002282 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002283 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002284#endif
2285 else
2286 {
2287 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002288#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002289 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002290#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002291 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002292#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002293 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002294#ifdef FEAT_PROP_POPUP
2295 // override with text property highlight when "override" is TRUE
2296 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002297 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002298#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002299 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002300
2301 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002302 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002303 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002304 if (wlv.char_attr == 0)
2305 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002306 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002307 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002308 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002309
2310 // Get the next character to put on the screen.
2311
2312 // The "p_extra" points to the extra stuff that is inserted to
2313 // represent special characters (non-printable stuff) and other
2314 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002315 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002316 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2317 // "p_extra[n_extra]".
2318 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002319 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002320 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002321 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002322 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002323 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2324 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002325 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2326 if (enc_utf8 && utf_char2len(c) > 1)
2327 {
2328 mb_utf8 = TRUE;
2329 u8cc[0] = 0;
2330 c = 0xc0;
2331 }
2332 else
2333 mb_utf8 = FALSE;
2334 }
2335 else
2336 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002337 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002338 if (has_mbyte)
2339 {
2340 mb_c = c;
2341 if (enc_utf8)
2342 {
2343 // If the UTF-8 character is more than one byte:
2344 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002345 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002346 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002347 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002348 mb_l = 1;
2349 else if (mb_l > 1)
2350 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002351 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002352 mb_utf8 = TRUE;
2353 c = 0xc0;
2354 }
2355 }
2356 else
2357 {
2358 // if this is a DBCS character, put it in "mb_c"
2359 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002360 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002361 mb_l = 1;
2362 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002363 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002364 }
2365 if (mb_l == 0) // at the NUL at end-of-line
2366 mb_l = 1;
2367
2368 // If a double-width char doesn't fit display a '>' in the
2369 // last column.
2370 if ((
2371# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002372 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002373# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002374 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002375 && (*mb_char2cells)(mb_c) == 2)
2376 {
2377 c = '>';
2378 mb_c = c;
2379 mb_l = 1;
2380 mb_utf8 = FALSE;
2381 multi_attr = HL_ATTR(HLF_AT);
2382#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002383 if (wlv.cul_attr)
2384 multi_attr = hl_combine_attr(
2385 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002386#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002387 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002388
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002389 // put the pointer back to output the double-width
2390 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002391 ++wlv.n_extra;
2392 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002393 }
2394 else
2395 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002396 wlv.n_extra -= mb_l - 1;
2397 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002398 }
2399 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002400 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002401 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002402 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002403#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002404 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002405 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002406 // Only restore search_attr and area_attr after "n_extra" in
2407 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002408 if (wlv.saved_n_extra <= 0)
2409 {
2410 if (search_attr == 0)
2411 search_attr = saved_search_attr;
2412 if (area_attr == 0 && *ptr != NUL)
2413 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002414
2415 if (wlv.extra_for_textprop)
2416 // wlv.extra_attr should be used at this position but
2417 // not any further.
2418 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002419 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002420
2421 wlv.extra_for_textprop = FALSE;
2422 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002423 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002424#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002425 }
2426 else
2427 {
2428#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002429 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002430#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002431 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002432
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002433 // Get a character from the line itself.
2434 c = *ptr;
2435#ifdef FEAT_LINEBREAK
2436 c0 = *ptr;
2437#endif
2438 if (has_mbyte)
2439 {
2440 mb_c = c;
2441 if (enc_utf8)
2442 {
2443 // If the UTF-8 character is more than one byte: Decode it
2444 // into "mb_c".
2445 mb_l = utfc_ptr2len(ptr);
2446 mb_utf8 = FALSE;
2447 if (mb_l > 1)
2448 {
2449 mb_c = utfc_ptr2char(ptr, u8cc);
2450 // Overlong encoded ASCII or ASCII with composing char
2451 // is displayed normally, except a NUL.
2452 if (mb_c < 0x80)
2453 {
2454 c = mb_c;
2455#ifdef FEAT_LINEBREAK
2456 c0 = mb_c;
2457#endif
2458 }
2459 mb_utf8 = TRUE;
2460
2461 // At start of the line we can have a composing char.
2462 // Draw it as a space with a composing char.
2463 if (utf_iscomposing(mb_c))
2464 {
2465 int i;
2466
2467 for (i = Screen_mco - 1; i > 0; --i)
2468 u8cc[i] = u8cc[i - 1];
2469 u8cc[0] = mb_c;
2470 mb_c = ' ';
2471 }
2472 }
2473
2474 if ((mb_l == 1 && c >= 0x80)
2475 || (mb_l >= 1 && mb_c == 0)
2476 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2477 {
2478 // Illegal UTF-8 byte: display as <xx>.
2479 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002480 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002481# ifdef FEAT_RIGHTLEFT
2482 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002483 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002484# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002485 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002486 c = *wlv.p_extra;
2487 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002488 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002489 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2490 wlv.c_extra = NUL;
2491 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002492 if (area_attr == 0 && search_attr == 0)
2493 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002494 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002495 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002496 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002497 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002498 }
2499 }
2500 else if (mb_l == 0) // at the NUL at end-of-line
2501 mb_l = 1;
2502#ifdef FEAT_ARABIC
2503 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2504 {
2505 // Do Arabic shaping.
2506 int pc, pc1, nc;
2507 int pcc[MAX_MCO];
2508
2509 // The idea of what is the previous and next
2510 // character depends on 'rightleft'.
2511 if (wp->w_p_rl)
2512 {
2513 pc = prev_c;
2514 pc1 = prev_c1;
2515 nc = utf_ptr2char(ptr + mb_l);
2516 prev_c1 = u8cc[0];
2517 }
2518 else
2519 {
2520 pc = utfc_ptr2char(ptr + mb_l, pcc);
2521 nc = prev_c;
2522 pc1 = pcc[0];
2523 }
2524 prev_c = mb_c;
2525
2526 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2527 }
2528 else
2529 prev_c = mb_c;
2530#endif
2531 }
2532 else // enc_dbcs
2533 {
2534 mb_l = MB_BYTE2LEN(c);
2535 if (mb_l == 0) // at the NUL at end-of-line
2536 mb_l = 1;
2537 else if (mb_l > 1)
2538 {
2539 // We assume a second byte below 32 is illegal.
2540 // Hopefully this is OK for all double-byte encodings!
2541 if (ptr[1] >= 32)
2542 mb_c = (c << 8) + ptr[1];
2543 else
2544 {
2545 if (ptr[1] == NUL)
2546 {
2547 // head byte at end of line
2548 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002549 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002550 }
2551 else
2552 {
2553 // illegal tail byte
2554 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002555 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002556 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002557 wlv.p_extra = wlv.extra;
2558 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002559 wlv.c_extra = NUL;
2560 wlv.c_final = NUL;
2561 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002562 if (area_attr == 0 && search_attr == 0)
2563 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002564 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002565 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002566 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002567 // save current attr
2568 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002569 }
2570 mb_c = c;
2571 }
2572 }
2573 }
2574 // If a double-width char doesn't fit display a '>' in the
2575 // last column; the character is displayed at the start of the
2576 // next line.
2577 if ((
2578# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002579 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002580# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002581 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002582 && (*mb_char2cells)(mb_c) == 2)
2583 {
2584 c = '>';
2585 mb_c = c;
2586 mb_utf8 = FALSE;
2587 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002588 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002589 // Put pointer back so that the character will be
2590 // displayed at the start of the next line.
2591 --ptr;
2592#ifdef FEAT_CONCEAL
2593 did_decrement_ptr = TRUE;
2594#endif
2595 }
2596 else if (*ptr != NUL)
2597 ptr += mb_l - 1;
2598
2599 // If a double-width char doesn't fit at the left side display
2600 // a '<' in the first column. Don't do this for unprintable
2601 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002602 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002603 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002604 wlv.n_extra = 1;
2605 wlv.c_extra = MB_FILLER_CHAR;
2606 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002607 c = ' ';
2608 if (area_attr == 0 && search_attr == 0)
2609 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002610 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002611 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002612 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002613 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002614 }
2615 mb_c = c;
2616 mb_utf8 = FALSE;
2617 mb_l = 1;
2618 }
2619
2620 }
2621 ++ptr;
2622
2623 if (extra_check)
2624 {
2625#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002626 // Check spelling (unless at the end of the line).
2627 // Only do this when there is no syntax highlighting, the
2628 // @Spell cluster is not used or the current syntax item
2629 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002630 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002631 if (has_spell && v >= word_end && v > cur_checked_col)
2632 {
2633 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002634 // do not calculate cap_col at the end of the line or when
2635 // only white space is following
2636 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002637# ifdef FEAT_SYN_HL
2638 !has_syntax ||
2639# endif
2640 can_spell))
2641 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002642 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002643 int len;
2644 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002645
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002646 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002647 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002648
2649 // Use nextline[] if possible, it has the start of the
2650 // next line concatenated.
2651 if ((prev_ptr - line) - nextlinecol >= 0)
2652 p = nextline + (prev_ptr - line) - nextlinecol;
2653 else
2654 p = prev_ptr;
2655 cap_col -= (int)(prev_ptr - line);
2656 len = spell_check(wp, p, &spell_hlf, &cap_col,
2657 nochange);
2658 word_end = v + len;
2659
2660 // In Insert mode only highlight a word that
2661 // doesn't touch the cursor.
2662 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002663 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002664 && wp->w_cursor.lnum == lnum
2665 && wp->w_cursor.col >=
2666 (colnr_T)(prev_ptr - line)
2667 && wp->w_cursor.col < (colnr_T)word_end)
2668 {
2669 spell_hlf = HLF_COUNT;
2670 spell_redraw_lnum = lnum;
2671 }
2672
2673 if (spell_hlf == HLF_COUNT && p != prev_ptr
2674 && (p - nextline) + len > nextline_idx)
2675 {
2676 // Remember that the good word continues at the
2677 // start of the next line.
2678 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002679 checked_col = (int)((p - nextline)
2680 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002681 }
2682
2683 // Turn index into actual attributes.
2684 if (spell_hlf != HLF_COUNT)
2685 spell_attr = highlight_attr[spell_hlf];
2686
2687 if (cap_col > 0)
2688 {
2689 if (p != prev_ptr
2690 && (p - nextline) + cap_col >= nextline_idx)
2691 {
2692 // Remember that the word in the next line
2693 // must start with a capital.
2694 capcol_lnum = lnum + 1;
2695 cap_col = (int)((p - nextline) + cap_col
2696 - nextline_idx);
2697 }
2698 else
2699 // Compute the actual column.
2700 cap_col += (int)(prev_ptr - line);
2701 }
2702 }
2703 }
2704 if (spell_attr != 0)
2705 {
2706 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002707 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2708 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002709 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002710 wlv.char_attr = hl_combine_attr(spell_attr,
2711 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002712 }
2713#endif
2714#ifdef FEAT_LINEBREAK
2715 // Found last space before word: check for line break.
2716 if (wp->w_p_lbr && c0 == c
2717 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2718 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002719 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2720 : 0;
2721 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002722 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002723
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002724 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002725# ifdef FEAT_PROP_POPUP
2726 // do not want virtual text counted here
2727 cts.cts_has_prop_with_text = FALSE;
2728# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002729 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002730 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002731
2732 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002733 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002734 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002735 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002736 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2737 if (wlv.n_extra < 0)
2738 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002739 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002740 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002741 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002742 // line break, but for TABs the highlighting should
2743 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002744 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002745
Bram Moolenaar1306b362022-08-06 15:59:06 +01002746 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002747# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002748 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002749 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002750 wp->w_buffer->b_p_vts_array) - 1;
2751# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002752 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002753 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002754# endif
2755
Bram Moolenaar1306b362022-08-06 15:59:06 +01002756 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2757 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002758# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002759 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002760 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002761# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002762 if (VIM_ISWHITE(c))
2763 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002764# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002765 if (c == TAB)
2766 // See "Tab alignment" below.
2767 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002768# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002769 if (!wp->w_p_list)
2770 c = ' ';
2771 }
2772 }
2773#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002774 in_multispace = c == ' '
2775 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2776 if (!in_multispace)
2777 multispace_pos = 0;
2778
Bram Moolenaareed9d462021-02-15 20:38:25 +01002779 // 'list': Change char 160 to 'nbsp' and space to 'space'
2780 // setting in 'listchars'. But not when the character is
2781 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002782 if (wp->w_p_list
2783 && ((((c == 160 && mb_l == 1)
2784 || (mb_utf8
2785 && ((mb_c == 160 && mb_l == 2)
2786 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002787 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002788 || (c == ' '
2789 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002790 && (wp->w_lcs_chars.space
2791 || (in_multispace
2792 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002793 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002794 && ptr - line <= trailcol)))
2795 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002796 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2797 {
2798 c = wp->w_lcs_chars.multispace[multispace_pos++];
2799 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2800 multispace_pos = 0;
2801 }
2802 else
2803 c = (c == ' ') ? wp->w_lcs_chars.space
2804 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002805 if (area_attr == 0 && search_attr == 0)
2806 {
2807 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002808 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002809 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002810 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002811 }
2812 mb_c = c;
2813 if (enc_utf8 && utf_char2len(c) > 1)
2814 {
2815 mb_utf8 = TRUE;
2816 u8cc[0] = 0;
2817 c = 0xc0;
2818 }
2819 else
2820 mb_utf8 = FALSE;
2821 }
2822
zeertzjq2e7cba32022-06-10 15:30:32 +01002823 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2824 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002825 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002826 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2827 && wp->w_lcs_chars.leadmultispace != NULL)
2828 {
2829 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002830 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2831 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002832 multispace_pos = 0;
2833 }
2834
2835 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2836 c = wp->w_lcs_chars.trail;
2837
2838 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2839 c = wp->w_lcs_chars.lead;
2840
zeertzjq2e7cba32022-06-10 15:30:32 +01002841 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002842 c = wp->w_lcs_chars.space;
2843
2844
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002845 if (!attr_pri)
2846 {
2847 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002848 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002849 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002850 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002851 }
2852 mb_c = c;
2853 if (enc_utf8 && utf_char2len(c) > 1)
2854 {
2855 mb_utf8 = TRUE;
2856 u8cc[0] = 0;
2857 c = 0xc0;
2858 }
2859 else
2860 mb_utf8 = FALSE;
2861 }
2862 }
2863
2864 // Handling of non-printable characters.
2865 if (!vim_isprintc(c))
2866 {
2867 // when getting a character from the file, we may have to
2868 // turn it into something else on the way to putting it
2869 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002870 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002871 {
2872 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002873 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002874#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002875 char_u *sbr = get_showbreak_value(wp);
2876
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002877 // only adjust the tab_len, when at the first column
2878 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002879 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002880 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002881#endif
2882 // tab amount depends on current column
2883#ifdef FEAT_VARTABS
2884 tab_len = tabstop_padding(vcol_adjusted,
2885 wp->w_buffer->b_p_ts,
2886 wp->w_buffer->b_p_vts_array) - 1;
2887#else
2888 tab_len = (int)wp->w_buffer->b_p_ts
2889 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2890#endif
2891
2892#ifdef FEAT_LINEBREAK
2893 if (!wp->w_p_lbr || !wp->w_p_list)
2894#endif
2895 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002896 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002897#ifdef FEAT_LINEBREAK
2898 else
2899 {
2900 char_u *p;
2901 int len;
2902 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002903 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002904
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002905# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002906 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002907 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002908 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002909
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002910 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002911 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002912 && old_boguscols > 0
2913 && wlv.n_extra > tab_len)
2914 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002915# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002916 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002917 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002918 // If wlv.n_extra > 0, it gives the number of
2919 // chars, to use for a tab, else we need to
2920 // calculate the width for a tab.
2921 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
2922 len = tab_len * tab2_len;
2923 if (wp->w_lcs_chars.tab3)
2924 len += mb_char2len(wp->w_lcs_chars.tab3)
2925 - tab2_len;
2926 if (wlv.n_extra > 0)
2927 len += wlv.n_extra - tab_len;
2928 c = wp->w_lcs_chars.tab1;
2929 p = alloc(len + 1);
2930 if (p == NULL)
2931 wlv.n_extra = 0;
2932 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002933 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002934 vim_memset(p, ' ', len);
2935 p[len] = NUL;
2936 vim_free(wlv.p_extra_free);
2937 wlv.p_extra_free = p;
2938 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002939 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002940 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002941
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002942 if (*p == NUL)
2943 {
2944 tab_len = i;
2945 break;
2946 }
2947
2948 // if tab3 is given, use it for the last
2949 // char
2950 if (wp->w_lcs_chars.tab3
2951 && i == tab_len - 1)
2952 lcs = wp->w_lcs_chars.tab3;
2953 p += mb_char2bytes(lcs, p);
2954 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002955 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002956 }
2957 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002958# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002959 // n_extra will be increased by
2960 // FIX_FOX_BOGUSCOLS macro below, so need to
2961 // adjust for that here
2962 if (wlv.vcol_off > 0)
2963 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002964# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002965 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002966 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002967 }
2968#endif
2969#ifdef FEAT_CONCEAL
2970 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002971 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002972
2973 // Tab alignment should be identical regardless of
2974 // 'conceallevel' value. So tab compensates of all
2975 // previous concealed characters, and thus resets
2976 // vcol_off and boguscols accumulated so far in the
2977 // line. Note that the tab can be longer than
2978 // 'tabstop' when there are concealed characters.
2979 FIX_FOR_BOGUSCOLS;
2980
2981 // Make sure, the highlighting for the tab char will be
2982 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002983 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002984 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002985 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002986 tab_len += vc_saved;
2987 }
2988#endif
2989 mb_utf8 = FALSE; // don't draw as UTF-8
2990 if (wp->w_p_list)
2991 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002992 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002993 ? wp->w_lcs_chars.tab3
2994 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002995#ifdef FEAT_LINEBREAK
2996 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002997 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002998 else
2999#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003000 wlv.c_extra = wp->w_lcs_chars.tab2;
3001 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003002 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003003 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003004 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003005 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003006 mb_c = c;
3007 if (enc_utf8 && utf_char2len(c) > 1)
3008 {
3009 mb_utf8 = TRUE;
3010 u8cc[0] = 0;
3011 c = 0xc0;
3012 }
3013 }
3014 else
3015 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003016 wlv.c_final = NUL;
3017 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003018 c = ' ';
3019 }
3020 }
3021 else if (c == NUL
3022 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003023 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3024 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003025 && VIsual_mode != Ctrl_V
3026 && (
3027# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003028 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003029# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003030 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003031 && !(noinvcur
3032 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003033 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003034 && lcs_eol_one > 0)
3035 {
3036 // Display a '$' after the line or highlight an extra
3037 // character if the line break is included.
3038#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3039 // For a diff line the highlighting continues after the
3040 // "$".
3041 if (
3042# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003043 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003044# ifdef LINE_ATTR
3045 &&
3046# endif
3047# endif
3048# ifdef LINE_ATTR
3049 line_attr == 0
3050# endif
3051 )
3052#endif
3053 {
3054 // In virtualedit, visual selections may extend
3055 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003056 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003057 && wlv.tocol != MAXCOL
3058 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003059 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003060 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003061 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003062 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3063 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003064 else
3065 c = ' ';
3066 lcs_eol_one = -1;
3067 --ptr; // put it back at the NUL
3068 if (!attr_pri)
3069 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003070 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003071 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003072 n_attr = 1;
3073 }
3074 mb_c = c;
3075 if (enc_utf8 && utf_char2len(c) > 1)
3076 {
3077 mb_utf8 = TRUE;
3078 u8cc[0] = 0;
3079 c = 0xc0;
3080 }
3081 else
3082 mb_utf8 = FALSE; // don't draw as UTF-8
3083 }
3084 else if (c != NUL)
3085 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003086 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3087 if (wlv.n_extra == 0)
3088 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003089#ifdef FEAT_RIGHTLEFT
3090 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003091 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003092#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003093 wlv.c_extra = NUL;
3094 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003095#ifdef FEAT_LINEBREAK
3096 if (wp->w_p_lbr)
3097 {
3098 char_u *p;
3099
Bram Moolenaar1306b362022-08-06 15:59:06 +01003100 c = *wlv.p_extra;
3101 p = alloc(wlv.n_extra + 1);
3102 vim_memset(p, ' ', wlv.n_extra);
3103 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3104 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003105 vim_free(wlv.p_extra_free);
3106 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003107 }
3108 else
3109#endif
3110 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003111 wlv.n_extra = byte2cells(c) - 1;
3112 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003113 }
3114 if (!attr_pri)
3115 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003116 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003117 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003118 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003119 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003120 }
3121 mb_utf8 = FALSE; // don't draw as UTF-8
3122 }
3123 else if (VIsual_active
3124 && (VIsual_mode == Ctrl_V
3125 || VIsual_mode == 'v')
3126 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003127 && wlv.tocol != MAXCOL
3128 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003129 && (
3130#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003131 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003132#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003133 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003134 {
3135 c = ' ';
3136 --ptr; // put it back at the NUL
3137 }
3138#if defined(LINE_ATTR)
3139 else if ((
3140# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003141 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003142# endif
3143# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003144 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003145# endif
3146 line_attr != 0
3147 ) && (
3148# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003149 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003150# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003151 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003152# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003153 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003154# endif
3155 < wp->w_width)))
3156 {
3157 // Highlight until the right side of the window
3158 c = ' ';
3159 --ptr; // put it back at the NUL
3160
3161 // Remember we do the char for line highlighting.
3162 ++did_line_attr;
3163
3164 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01003165 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003166 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003167 || (wp->w_p_list &&
3168 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003169 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003170# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003171 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003172 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003173 wlv.diff_hlf = HLF_CHD;
3174 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003175 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003176 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003177 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3178 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003179 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003180 || (wlv.vcol >= left_curline_col
3181 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003182 wlv.char_attr = hl_combine_attr(
3183 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003184 }
3185 }
3186# endif
3187# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003188 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003189 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003190 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003191 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3192 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003193 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003194 if (!wlv.cul_screenline
3195 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003196 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003197 wlv.char_attr = hl_combine_attr(
3198 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003199 }
3200 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003201 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3202 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003203 }
3204# endif
3205 }
3206#endif
3207 }
3208
3209#ifdef FEAT_CONCEAL
3210 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003211 && (wp != curwin || lnum != wp->w_cursor.lnum
3212 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003213 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3214 && !(lnum_in_visual_area
3215 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3216 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003217 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003218 if (((prev_syntax_id != syntax_seqnr
3219 && (syntax_flags & HL_CONCEAL) != 0)
3220 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003221 && (syn_get_sub_char() != NUL
3222 || (has_match_conc && match_conc)
3223 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003224 && wp->w_p_cole != 3)
3225 {
3226 // First time at this concealed item: display one
3227 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003228 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003229 c = match_conc;
3230 else if (syn_get_sub_char() != NUL)
3231 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003232 else if (wp->w_lcs_chars.conceal != NUL)
3233 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003234 else
3235 c = ' ';
3236
3237 prev_syntax_id = syntax_seqnr;
3238
Bram Moolenaar1306b362022-08-06 15:59:06 +01003239 if (wlv.n_extra > 0)
3240 wlv.vcol_off += wlv.n_extra;
3241 wlv.vcol += wlv.n_extra;
3242 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003243 {
3244# ifdef FEAT_RIGHTLEFT
3245 if (wp->w_p_rl)
3246 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003247 wlv.col -= wlv.n_extra;
3248 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003249 }
3250 else
3251# endif
3252 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003253 wlv.boguscols += wlv.n_extra;
3254 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003255 }
3256 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003257 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003258 n_attr = 0;
3259 }
3260 else if (n_skip == 0)
3261 {
3262 is_concealing = TRUE;
3263 n_skip = 1;
3264 }
3265 mb_c = c;
3266 if (enc_utf8 && utf_char2len(c) > 1)
3267 {
3268 mb_utf8 = TRUE;
3269 u8cc[0] = 0;
3270 c = 0xc0;
3271 }
3272 else
3273 mb_utf8 = FALSE; // don't draw as UTF-8
3274 }
3275 else
3276 {
3277 prev_syntax_id = 0;
3278 is_concealing = FALSE;
3279 }
3280
3281 if (n_skip > 0 && did_decrement_ptr)
3282 // not showing the '>', put pointer back to avoid getting stuck
3283 ++ptr;
3284
3285#endif // FEAT_CONCEAL
3286 }
3287
3288#ifdef FEAT_CONCEAL
3289 // In the cursor line and we may be concealing characters: correct
3290 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003291 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003292 && wp == curwin && lnum == wp->w_cursor.lnum
3293 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003294 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003295 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003296# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003297 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003298 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003299 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003300# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003301 wp->w_wcol = wlv.col - wlv.boguscols;
3302 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003303 did_wcol = TRUE;
3304 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003305# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003306 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003307# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003308 }
3309#endif
3310
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003311 // Use "wlv.extra_attr", but don't override visual selection
3312 // highlighting, unless text property overrides.
3313 // Don't use "wlv.extra_attr" until n_attr_skip is zero.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003314 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003315 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003316 && (!attr_pri
3317#ifdef FEAT_PROP_POPUP
3318 || (text_prop_flags & PT_FLAG_OVERRIDE)
3319#endif
3320 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003321 {
3322#ifdef LINE_ATTR
3323 if (line_attr)
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003324 wlv.char_attr = hl_combine_attr(line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003325 else
3326#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003327 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003328#ifdef FEAT_PROP_POPUP
3329 if (reset_extra_attr)
3330 {
3331 reset_extra_attr = FALSE;
3332 wlv.extra_attr = 0;
3333 }
3334#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003335 }
3336
3337#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3338 // XIM don't send preedit_start and preedit_end, but they send
3339 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3340 // im_is_preediting() here.
3341 if (p_imst == IM_ON_THE_SPOT
3342 && xic != NULL
3343 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003344 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003345 && !p_imdisable
3346 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003347 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003348 {
3349 colnr_T tcol;
3350
3351 if (preedit_end_col == MAXCOL)
3352 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3353 else
3354 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003355 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003356 {
3357 if (feedback_old_attr < 0)
3358 {
3359 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003360 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003361 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003362 wlv.char_attr = im_get_feedback_attr(feedback_col);
3363 if (wlv.char_attr < 0)
3364 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003365 feedback_col++;
3366 }
3367 else if (feedback_old_attr >= 0)
3368 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003369 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003370 feedback_old_attr = -1;
3371 feedback_col = 0;
3372 }
3373 }
3374#endif
3375 // Handle the case where we are in column 0 but not on the first
3376 // character of the line and the user wants us to show us a
3377 // special character (via 'listchars' option "precedes:<char>".
3378 if (lcs_prec_todo != NUL
3379 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003380 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3381 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003382#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003383 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003384#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003385 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003386 && c != NUL)
3387 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003388 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003389 lcs_prec_todo = NUL;
3390 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3391 {
3392 // Double-width character being overwritten by the "precedes"
3393 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003394 wlv.c_extra = MB_FILLER_CHAR;
3395 wlv.c_final = NUL;
3396 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003397 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003398 wlv.extra_attr =
3399 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003400 }
3401 mb_c = c;
3402 if (enc_utf8 && utf_char2len(c) > 1)
3403 {
3404 mb_utf8 = TRUE;
3405 u8cc[0] = 0;
3406 c = 0xc0;
3407 }
3408 else
3409 mb_utf8 = FALSE; // don't draw as UTF-8
3410 if (!attr_pri)
3411 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003412 saved_attr3 = wlv.char_attr; // save current attr
3413 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003414 n_attr3 = 1;
3415 }
3416 }
3417
3418 // At end of the text line or just after the last character.
3419 if ((c == NUL
3420#if defined(LINE_ATTR)
3421 || did_line_attr == 1
3422#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003423 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003424 {
3425#ifdef FEAT_SEARCH_EXTRA
3426 // flag to indicate whether prevcol equals startcol of search_hl or
3427 // one of the matches
3428 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3429 (long)(ptr - line) - (c == NUL));
3430#endif
3431 // Invert at least one char, used for Visual and empty line or
3432 // highlight match at end of line. If it's beyond the last
3433 // char on the screen, just overwrite that one (tricky!) Not
3434 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003435 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003436 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003437 && (VIsual_mode != Ctrl_V
3438 || lnum == VIsual.lnum
3439 || lnum == curwin->w_cursor.lnum)
3440 && c == NUL)
3441#ifdef FEAT_SEARCH_EXTRA
3442 // highlight 'hlsearch' match at end of line
3443 || (prevcol_hl_flag
3444# ifdef FEAT_SYN_HL
3445 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3446 && !(wp == curwin && VIsual_active))
3447# endif
3448# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003449 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003450# endif
3451# if defined(LINE_ATTR)
3452 && did_line_attr <= 1
3453# endif
3454 )
3455#endif
3456 ))
3457 {
3458 int n = 0;
3459
3460#ifdef FEAT_RIGHTLEFT
3461 if (wp->w_p_rl)
3462 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003463 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003464 n = 1;
3465 }
3466 else
3467#endif
3468 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003469 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003470 n = -1;
3471 }
3472 if (n != 0)
3473 {
3474 // At the window boundary, highlight the last character
3475 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003476 wlv.off += n;
3477 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003478 }
3479 else
3480 {
3481 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003482 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003483 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003484 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003485 }
3486#ifdef FEAT_SEARCH_EXTRA
3487 if (area_attr == 0)
3488 {
3489 // Use attributes from match with highest priority among
3490 // 'search_hl' and the match list.
3491 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003492 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003493 }
3494#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003495 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003496 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003497#ifdef FEAT_RIGHTLEFT
3498 if (wp->w_p_rl)
3499 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003500 --wlv.col;
3501 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003502 }
3503 else
3504#endif
3505 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003506 ++wlv.col;
3507 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003508 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003509 ++wlv.vcol;
3510 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003511 }
3512 }
3513
3514 // At end of the text line.
3515 if (c == NUL)
3516 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003517 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003518
3519 // Update w_cline_height and w_cline_folded if the cursor line was
3520 // updated (saves a call to plines() later).
3521 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3522 {
3523 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003524 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003525#ifdef FEAT_FOLDING
3526 curwin->w_cline_folded = FALSE;
3527#endif
3528 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3529 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003530 break;
3531 }
3532
3533 // Show "extends" character from 'listchars' if beyond the line end and
3534 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003535 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003536 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003537 && wp->w_p_list
3538 && !wp->w_p_wrap
3539#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003540 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003541#endif
3542 && (
3543#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003544 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003545#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003546 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003547 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003548 || lcs_eol_one > 0
3549 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003550 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003551 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003552 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003553 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003554 mb_c = c;
3555 if (enc_utf8 && utf_char2len(c) > 1)
3556 {
3557 mb_utf8 = TRUE;
3558 u8cc[0] = 0;
3559 c = 0xc0;
3560 }
3561 else
3562 mb_utf8 = FALSE;
3563 }
3564
3565#ifdef FEAT_SYN_HL
3566 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003567 if (wlv.draw_color_col)
3568 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003569
3570 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3571 // highlight the cursor position itself.
3572 // Also highlight the 'colorcolumn' if it is different than
3573 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003574 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3575 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003576 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003577 if (((wlv.draw_state == WL_LINE
3578 || wlv.draw_state == WL_BRI
3579 || wlv.draw_state == WL_SBR)
3580 && !lnum_in_visual_area
3581 && search_attr == 0
3582 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003583# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003584 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003585# endif
3586 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003587 {
3588 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3589 && lnum != wp->w_cursor.lnum)
3590 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003591 vcol_save_attr = wlv.char_attr;
3592 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3593 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003594 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003595 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003596 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003597 vcol_save_attr = wlv.char_attr;
3598 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003599 }
3600 }
3601#endif
3602
3603 // Store character to be displayed.
3604 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003605 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003606 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003607 {
3608 // Store the character.
3609#if defined(FEAT_RIGHTLEFT)
3610 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3611 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003612 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003613 --wlv.off;
3614 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003615 }
3616#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003617 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003618 if (enc_dbcs == DBCS_JPNU)
3619 {
3620 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003621 ScreenLines[wlv.off] = 0x8e;
3622 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003623 }
3624 else if (enc_utf8)
3625 {
3626 if (mb_utf8)
3627 {
3628 int i;
3629
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003630 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003631 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003632 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003633 for (i = 0; i < Screen_mco; ++i)
3634 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003635 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003636 if (u8cc[i] == 0)
3637 break;
3638 }
3639 }
3640 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003641 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003642 }
3643 if (multi_attr)
3644 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003645 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003646 multi_attr = 0;
3647 }
3648 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003649 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003650
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003651 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003652
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003653 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3654 {
3655 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003656 ++wlv.off;
3657 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003658 if (enc_utf8)
3659 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003660 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003661 else
3662 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003663 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003664 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003665#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003666 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003667#endif
3668 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003669 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003670 // When "wlv.tocol" is halfway a character, set it to the end
3671 // of the character, otherwise highlighting won't stop.
3672 if (wlv.tocol == wlv.vcol)
3673 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003674
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003675 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003676
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003677#ifdef FEAT_RIGHTLEFT
3678 if (wp->w_p_rl)
3679 {
3680 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003681 --wlv.off;
3682 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003683 }
3684#endif
3685 }
3686#ifdef FEAT_RIGHTLEFT
3687 if (wp->w_p_rl)
3688 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003689 --wlv.off;
3690 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003691 }
3692 else
3693#endif
3694 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003695 ++wlv.off;
3696 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003697 }
3698 }
3699#ifdef FEAT_CONCEAL
3700 else if (wp->w_p_cole > 0 && is_concealing)
3701 {
3702 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003703 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003704 if (wlv.n_extra > 0)
3705 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003706 if (wp->w_p_wrap)
3707 {
3708 // Special voodoo required if 'wrap' is on.
3709 //
3710 // Advance the column indicator to force the line
3711 // drawing to wrap early. This will make the line
3712 // take up the same screen space when parts are concealed,
3713 // so that cursor line computations aren't messed up.
3714 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003715 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003716 // trailing junk to be written out of the screen line
3717 // we are building, 'boguscols' keeps track of the number
3718 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003719 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003720 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003721 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003722# ifdef FEAT_RIGHTLEFT
3723 if (wp->w_p_rl)
3724 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003725 wlv.col -= wlv.n_extra;
3726 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003727 }
3728 else
3729# endif
3730 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003731 wlv.col += wlv.n_extra;
3732 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003733 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003734 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003735 n_attr = 0;
3736 }
3737
3738
3739 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3740 {
3741 // Need to fill two screen columns.
3742# ifdef FEAT_RIGHTLEFT
3743 if (wp->w_p_rl)
3744 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003745 --wlv.boguscols;
3746 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003747 }
3748 else
3749# endif
3750 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003751 ++wlv.boguscols;
3752 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003753 }
3754 }
3755
3756# ifdef FEAT_RIGHTLEFT
3757 if (wp->w_p_rl)
3758 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003759 --wlv.boguscols;
3760 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003761 }
3762 else
3763# endif
3764 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003765 ++wlv.boguscols;
3766 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003767 }
3768 }
3769 else
3770 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003771 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003772 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003773 wlv.vcol += wlv.n_extra;
3774 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003775 n_attr = 0;
3776 }
3777 }
3778
3779 }
3780#endif // FEAT_CONCEAL
3781 else
3782 --n_skip;
3783
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003784 // Only advance the "wlv.vcol" when after the 'number' or
3785 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003786 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003787#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003788 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003789#endif
3790 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003791 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003792
3793#ifdef FEAT_SYN_HL
3794 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003795 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003796#endif
3797
3798 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003799 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3800 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003801
3802 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003803 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003804 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003805 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003806 if (n_attr_skip > 0)
3807 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003808
3809 // At end of screen line and there is more to come: Display the line
3810 // so far. If there is no more to display it is caught above.
3811 if ((
3812#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003813 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003814#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003815 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003816 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003817 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003818#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003819 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003820#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003821#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003822 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003823#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003824 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003825 && wlv.p_extra != at_end_str)
3826 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3827 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003828 )
3829 {
3830#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003831 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003832 wlv_screen_line(wp, &wlv, FALSE);
3833 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003834 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003835#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003836 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003837#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003838 ++wlv.row;
3839 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003840
3841 // When not wrapping and finished diff lines, or when displayed
3842 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01003843 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003844#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003845 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003846#endif
3847#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01003848 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003849#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01003850 ) || lcs_eol_one == -1)
3851#ifdef FEAT_PROP_POPUP
3852 && !text_prop_follows
3853#endif
3854 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003855 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003856#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003857 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003858 {
3859 // do not output more of the line, only the "below" prop
3860 ptr += STRLEN(ptr);
3861# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003862 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003863# endif
3864 }
3865#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003866
3867 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003868 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003869#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003870 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003871#endif
3872 )
3873 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003874 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3875 draw_vsep_win(wp, wlv.row);
3876 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003877 }
3878
3879 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003880 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003881 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003882 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003883 break;
3884 }
3885
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003886 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003887#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003888 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003889#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003890#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003891 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003892#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003893 && wp->w_width == Columns)
3894 {
3895 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003896 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003897
3898 // Special trick to make copy/paste of wrapped lines work with
3899 // xterm/screen: write an extra character beyond the end of
3900 // the line. This will work with all terminal types
3901 // (regardless of the xn,am settings).
3902 // Only do this on a fast tty.
3903 // Only do this if the cursor is on the current line
3904 // (something has been written in it).
3905 // Don't do this for the GUI.
3906 // Don't do this for double-width characters.
3907 // Don't do this for a window not at the right screen border.
3908 if (p_tf
3909#ifdef FEAT_GUI
3910 && !gui.in_use
3911#endif
3912 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003913 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3914 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003915 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003916 || (*mb_off2cells)(
3917 LineOffset[wlv.screen_row - 1]
3918 + (int)Columns - 2,
3919 LineOffset[wlv.screen_row]
3920 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003921 {
3922 // First make sure we are at the end of the screen line,
3923 // then output the same character again to let the
3924 // terminal know about the wrap. If the terminal doesn't
3925 // auto-wrap, we overwrite the character.
3926 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003927 screen_char(LineOffset[wlv.screen_row - 1]
3928 + (unsigned)Columns - 1,
3929 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003930
3931 // When there is a multi-byte character, just output a
3932 // space to keep it simple.
3933 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003934 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003935 out_char(' ');
3936 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003937 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003938 + (Columns - 1)]);
3939 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003940 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003941 screen_start(); // don't know where cursor is now
3942 }
3943 }
3944
Bram Moolenaar1306b362022-08-06 15:59:06 +01003945 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003946
Bram Moolenaareed9d462021-02-15 20:38:25 +01003947 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003948#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003949 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003950# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003951 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003952# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003953 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003954 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003955#endif
3956#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003957 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003958 // When the filler lines are actually below the last line of the
3959 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003960 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003961 break;
3962#endif
3963 }
3964
3965 } // for every character in the line
3966
3967#ifdef FEAT_SPELL
3968 // After an empty line check first word for capital.
3969 if (*skipwhite(line) == NUL)
3970 {
3971 capcol_lnum = lnum + 1;
3972 cap_col = 0;
3973 }
3974#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003975#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003976 vim_free(text_props);
3977 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003978 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003979#endif
3980
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003981 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003982 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003983}