blob: 3499d39e77c959c78ebc27f35317ac5a7482b747 [file] [log] [blame]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * drawline.c: Functions for drawing window lines on the screen.
Bram Moolenaare89aeed2022-08-22 13:00:16 +010012 * This is the middle level, drawscreen.c is the higher level and screen.c the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020013 * lower level.
14 */
15
16#include "vim.h"
17
18#ifdef FEAT_SYN_HL
19/*
20 * Advance **color_cols and return TRUE when there are columns to draw.
21 */
22 static int
23advance_color_col(int vcol, int **color_cols)
24{
25 while (**color_cols >= 0 && vcol > **color_cols)
26 ++*color_cols;
27 return (**color_cols >= 0);
28}
29#endif
30
31#ifdef FEAT_SYN_HL
32/*
33 * Used when 'cursorlineopt' contains "screenline": compute the margins between
34 * which the highlighting is used.
35 */
36 static void
37margin_columns_win(win_T *wp, int *left_col, int *right_col)
38{
39 // cache previous calculations depending on w_virtcol
40 static int saved_w_virtcol;
41 static win_T *prev_wp;
42 static int prev_left_col;
43 static int prev_right_col;
44 static int prev_col_off;
45
46 int cur_col_off = win_col_off(wp);
47 int width1;
48 int width2;
49
50 if (saved_w_virtcol == wp->w_virtcol
51 && prev_wp == wp && prev_col_off == cur_col_off)
52 {
53 *right_col = prev_right_col;
54 *left_col = prev_left_col;
55 return;
56 }
57
58 width1 = wp->w_width - cur_col_off;
59 width2 = width1 + win_col_off2(wp);
60
61 *left_col = 0;
62 *right_col = width1;
63
64 if (wp->w_virtcol >= (colnr_T)width1)
65 *right_col = width1 + ((wp->w_virtcol - width1) / width2 + 1) * width2;
66 if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0)
67 *left_col = (wp->w_virtcol - width1) / width2 * width2 + width1;
68
69 // cache values
70 prev_left_col = *left_col;
71 prev_right_col = *right_col;
72 prev_wp = wp;
73 saved_w_virtcol = wp->w_virtcol;
74 prev_col_off = cur_col_off;
75}
76#endif
77
Bram Moolenaar45e4eea2022-12-01 18:38:02 +000078#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
79 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
80// using an attribute for the whole line
81# define LINE_ATTR
82#endif
83
Bram Moolenaar1306b362022-08-06 15:59:06 +010084// structure with variables passed between win_line() and other functions
85typedef struct {
86 int draw_state; // what to draw next
87
88 linenr_T lnum; // line number to be drawn
89
90 int startrow; // first row in the window to be drawn
91 int row; // row in the window, excl w_winrow
92 int screen_row; // row on the screen, incl w_winrow
93
94 long vcol; // virtual column, before wrapping
95 int col; // visual column on screen, after wrapping
96#ifdef FEAT_CONCEAL
97 int boguscols; // nonexistent columns added to "col" to force
98 // wrapping
Bram Moolenaarf53e0652023-02-19 14:16:02 +000099 int vcol_off_co; // offset for concealed characters
Bram Moolenaar1306b362022-08-06 15:59:06 +0100100#endif
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000101 int vcol_off_tp; // offset for virtual text
Bram Moolenaar1306b362022-08-06 15:59:06 +0100102#ifdef FEAT_SYN_HL
103 int draw_color_col; // highlight colorcolumn
104 int *color_cols; // pointer to according columns array
105#endif
106 int eol_hl_off; // 1 if highlighted char after EOL
107
108 unsigned off; // offset in ScreenLines/ScreenAttrs
109
110 int win_attr; // background for the whole window, except
111 // margins and "~" lines.
Bram Moolenaard7657e92022-09-20 18:59:30 +0100112 int wcr_attr; // attributes from 'wincolor'
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100113#ifdef FEAT_SYN_HL
114 int cul_attr; // set when 'cursorline' active
115#endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000116#ifdef LINE_ATTR
117 int line_attr; // for the whole line, includes 'cursorline'
118#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100119
120 int screen_line_flags; // flags for screen_line()
121
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100122 int fromcol; // start of inverting
123 int tocol; // end of inverting
124
125#ifdef FEAT_LINEBREAK
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100126 long vcol_sbr; // virtual column after showbreak
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100127 int need_showbreak; // overlong line, skipping first x chars
128 int dont_use_showbreak; // do not use 'showbreak'
129#endif
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100130#ifdef FEAT_PROP_POPUP
131 int text_prop_above_count;
132#endif
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100133
Bram Moolenaar1306b362022-08-06 15:59:06 +0100134 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
135 int cul_screenline;
136
137 int char_attr; // attributes for the next character
138
139 int n_extra; // number of extra bytes
140 char_u *p_extra; // string of extra chars, plus NUL, only used
141 // when c_extra and c_final are NUL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100142 char_u *p_extra_free; // p_extra buffer that needs to be freed
Bram Moolenaaree28c702022-11-17 14:56:00 +0000143 int extra_attr; // attributes for p_extra, should be combined
144 // with win_attr if needed
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000145 int n_attr_skip; // chars to skip before using extra_attr
Bram Moolenaar1306b362022-08-06 15:59:06 +0100146 int c_extra; // extra chars, all the same
147 int c_final; // final char, mandatory if set
zeertzjq6e940d92023-08-17 23:21:40 +0200148 int extra_for_textprop; // n_extra set for textprop
149 int start_extra_for_textprop; // extra_for_textprop was just set
Bram Moolenaar1306b362022-08-06 15:59:06 +0100150
151 // saved "extra" items for when draw_state becomes WL_LINE (again)
152 int saved_n_extra;
153 char_u *saved_p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +0100154 char_u *saved_p_extra_free;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000155 int saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000156 int saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000157 int saved_extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100158 int saved_c_extra;
159 int saved_c_final;
160 int saved_char_attr;
161
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100162 char_u extra[NUMBUFLEN + MB_MAXBYTES];
163 // "%ld " and 'fdc' must fit in here, as well
164 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100165
Bram Moolenaar1306b362022-08-06 15:59:06 +0100166#ifdef FEAT_DIFF
167 hlf_T diff_hlf; // type of diff highlighting
168#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100169 int filler_lines; // nr of filler lines to be drawn
170 int filler_todo; // nr of filler lines still to do + 1
171#ifdef FEAT_SIGNS
172 sign_attrs_T sattr;
173#endif
Christian Brabandtdd75fcf2023-10-11 21:51:19 +0200174#ifdef FEAT_LINEBREAK
175 // do consider wrapping in linebreak mode only after encountering
176 // a non whitespace char
177 int need_lbr;
178#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100179} winlinevars_T;
180
181// draw_state values for items that are drawn in sequence:
182#define WL_START 0 // nothing done yet, must be zero
Martin Tournoij7904fa42022-10-04 16:28:45 +0100183#define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar1306b362022-08-06 15:59:06 +0100184#ifdef FEAT_FOLDING
185# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
186#else
187# define WL_FOLD WL_CMDLINE
188#endif
189#ifdef FEAT_SIGNS
190# define WL_SIGN (WL_FOLD + 1) // column for signs
191#else
192# define WL_SIGN WL_FOLD // column for signs
193#endif
194#define WL_NR (WL_SIGN + 1) // line number
195#ifdef FEAT_LINEBREAK
196# define WL_BRI (WL_NR + 1) // 'breakindent'
197#else
198# define WL_BRI WL_NR
199#endif
200#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
201# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
202#else
203# define WL_SBR WL_BRI
204#endif
205#define WL_LINE (WL_SBR + 1) // text in the line
206
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100207#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200208/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000209 * Return TRUE if CursorLineSign highlight is to be used.
210 */
211 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100212use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000213{
214 return wp->w_p_cul
215 && lnum == wp->w_cursor.lnum
216 && (wp->w_p_culopt_flags & CULOPT_NBR);
217}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100218#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000219
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100220
221#ifdef FEAT_FOLDING
222/*
223 * Setup for drawing the 'foldcolumn', if there is one.
224 */
225 static void
226handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
227{
228 int fdc = compute_foldcolumn(wp, 0);
229
230 if (fdc <= 0)
231 return;
232
233 // Allocate a buffer, "wlv->extra[]" may already be in use.
234 vim_free(wlv->p_extra_free);
235 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
Yegappan Lakshmanan465de3a2022-12-26 12:50:04 +0000236 if (wlv->p_extra_free == NULL)
237 return;
238
239 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
zeertzjq58e1e012023-06-04 18:46:28 +0100240 wp, FALSE, wlv->lnum);
Yegappan Lakshmanan465de3a2022-12-26 12:50:04 +0000241 wlv->p_extra_free[wlv->n_extra] = NUL;
242 wlv->p_extra = wlv->p_extra_free;
243 wlv->c_extra = NUL;
244 wlv->c_final = NUL;
245 if (use_cursor_line_highlight(wp, wlv->lnum))
246 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
247 else
248 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100249}
250#endif
251
252#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000253/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100254 * Get information needed to display the sign in line "wlv->lnum" in window
255 * "wp".
256 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200257 * Otherwise the sign is going to be displayed in the sign column.
258 */
259 static void
260get_sign_display_info(
261 int nrcol,
262 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100263 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200264{
265 int text_sign;
266# ifdef FEAT_SIGN_ICONS
267 int icon_sign;
268# endif
269
270 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100271 wlv->c_extra = ' ';
272 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200273 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100274 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200275 else
276 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100277 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100278 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000279 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100280 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100281 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200282 }
283
Bram Moolenaar1306b362022-08-06 15:59:06 +0100284 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200285#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100286 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200287#endif
288 )
289 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100290 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200291# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100292 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200293 if (gui.in_use && icon_sign != 0)
294 {
295 // Use the image in this position.
296 if (nrcol)
297 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100298 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100299 sprintf((char *)wlv->extra, "%-*c ",
300 number_width(wp), SIGN_BYTE);
301 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100302 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200303 }
304 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100305 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200306# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100307 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
308 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200309 {
310 if (nrcol)
311 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100312 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100313 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200314 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100315 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100316 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200317 }
318 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100319 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200320 }
321# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100322 wlv->c_final = NUL;
323 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200324 }
325 else
326# endif
327 if (text_sign != 0)
328 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100329 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100330 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200331 {
332 if (nrcol)
333 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100334 int width = number_width(wp) - 2;
335 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200336
337 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100338 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100339 vim_snprintf((char *)wlv->extra + n,
340 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100341 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200342 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100343 wlv->c_extra = NUL;
344 wlv->c_final = NUL;
345 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200346 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000347
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100348 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100349 && wlv->sattr.sat_culhl > 0)
350 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000351 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100352 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200353 }
354 }
355}
356#endif
357
Bram Moolenaard7657e92022-09-20 18:59:30 +0100358/*
359 * Display the absolute or relative line number. After the first row fill with
360 * blanks when the 'n' flag isn't in 'cpo'.
361 */
362 static void
363handle_lnum_col(
364 win_T *wp,
365 winlinevars_T *wlv,
366 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100367 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100368{
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100369 int has_cpo_n = vim_strchr(p_cpo, CPO_NUMCOL) != NULL;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100370 int lnum_row = wlv->startrow + wlv->filler_lines
371#ifdef FEAT_PROP_POPUP
372 + wlv->text_prop_above_count
373#endif
374 ;
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100375
Bram Moolenaard7657e92022-09-20 18:59:30 +0100376 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100377 && (wlv->row <= lnum_row || !has_cpo_n)
Bram Moolenaar37251162022-10-06 20:48:00 +0100378 // there is no line number in a wrapped line when "n" is in
379 // 'cpoptions', but 'breakindent' assumes it anyway.
380 && !((has_cpo_n
381#ifdef FEAT_LINEBREAK
382 && !wp->w_p_bri
383#endif
384 ) && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100385 {
386#ifdef FEAT_SIGNS
387 // If 'signcolumn' is set to 'number' and a sign is present
388 // in 'lnum', then display the sign instead of the line
389 // number.
390 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
391 get_sign_display_info(TRUE, wp, wlv);
392 else
393#endif
394 {
395 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100396 // When there are text properties above the line put the line number
397 // below them.
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100398 if (wlv->row == lnum_row
zeertzjq88bb3e02023-05-02 20:52:59 +0100399 && (wp->w_skipcol == 0 || wlv->row > 0
Bram Moolenaareb4de622022-10-15 13:42:17 +0100400 || (wp->w_p_nu && wp->w_p_rnu)))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100401 {
402 long num;
403 char *fmt = "%*ld ";
404
405 if (wp->w_p_nu && !wp->w_p_rnu)
406 // 'number' + 'norelativenumber'
407 num = (long)wlv->lnum;
408 else
409 {
410 // 'relativenumber', don't use negative numbers
411 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
412 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
413 {
414 // 'number' + 'relativenumber'
415 num = wlv->lnum;
416 fmt = "%-*ld ";
417 }
418 }
419
420 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100421 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100422 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
423 ++wlv->p_extra)
424 *wlv->p_extra = '-';
425#ifdef FEAT_RIGHTLEFT
426 if (wp->w_p_rl) // reverse line numbers
427 {
428 char_u *p1, *p2;
429 int t;
430
431 // like rl_mirror(), but keep the space at the end
432 p2 = skipwhite(wlv->extra);
433 p2 = skiptowhite(p2) - 1;
434 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
435 {
436 t = *p1;
437 *p1 = *p2;
438 *p2 = t;
439 }
440 }
441#endif
442 wlv->p_extra = wlv->extra;
443 wlv->c_extra = NUL;
444 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100445 }
446 else
447 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100448 wlv->c_extra = ' ';
449 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100450 }
451 wlv->n_extra = number_width(wp) + 1;
452 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
453#ifdef FEAT_SYN_HL
454 // When 'cursorline' is set highlight the line number of
455 // the current line differently.
456 // When 'cursorlineopt' does not have "line" only
457 // highlight the line number itself.
458 // TODO: Can we use CursorLine instead of CursorLineNr
459 // when CursorLineNr isn't set?
460 if (wp->w_p_cul
461 && wlv->lnum == wp->w_cursor.lnum
462 && (wp->w_p_culopt_flags & CULOPT_NBR)
463 && (wlv->row == wlv->startrow + wlv->filler_lines
464 || (wlv->row > wlv->startrow + wlv->filler_lines
465 && (wp->w_p_culopt_flags & CULOPT_LINE))))
466 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
467#endif
468 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
469 && HL_ATTR(HLF_LNA) != 0)
470 // Use LineNrAbove
471 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
472 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
473 && HL_ATTR(HLF_LNB) != 0)
474 // Use LineNrBelow
475 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
476 }
477#ifdef FEAT_SIGNS
478 if (num_attr)
479 wlv->char_attr = num_attr;
480#endif
481 }
482}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100483
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100484#ifdef FEAT_LINEBREAK
485 static void
486handle_breakindent(win_T *wp, winlinevars_T *wlv)
487{
488 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100489 && *get_showbreak_value(wp) != NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100490 // draw indent after showbreak value
491 wlv->draw_state = WL_BRI;
492 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
493 // After the showbreak, draw the breakindent
494 wlv->draw_state = WL_BRI - 1;
495
496 // draw 'breakindent': indent wrapped text accordingly
497 if (wlv->draw_state == WL_BRI - 1)
498 {
499 wlv->draw_state = WL_BRI;
500 // if wlv->need_showbreak is set, breakindent also applies
zeertzjq588f20d2023-12-05 15:47:09 +0100501 if (wp->w_p_bri && (wlv->row > wlv->startrow
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100502# ifdef FEAT_DIFF
zeertzjq588f20d2023-12-05 15:47:09 +0100503 + wlv->filler_lines
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100504# endif
zeertzjq588f20d2023-12-05 15:47:09 +0100505 || wlv->need_showbreak)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100506# ifdef FEAT_PROP_POPUP
507 && !wlv->dont_use_showbreak
508# endif
509 )
510 {
511 wlv->char_attr = 0;
512# ifdef FEAT_DIFF
513 if (wlv->diff_hlf != (hlf_T)0)
514 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
515# endif
516 wlv->p_extra = NULL;
517 wlv->c_extra = ' ';
518 wlv->c_final = NUL;
519 wlv->n_extra = get_breakindent_win(wp,
520 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
521 if (wlv->row == wlv->startrow)
522 {
523 wlv->n_extra -= win_col_off2(wp);
524 if (wlv->n_extra < 0)
525 wlv->n_extra = 0;
526 }
zeertzjq23627722023-12-27 19:08:53 +0100527
528 // Correct start of highlighted area for 'breakindent',
529 if (wlv->fromcol >= wlv->vcol
530 && wlv->fromcol < wlv->vcol + wlv->n_extra)
531 wlv->fromcol = wlv->vcol + wlv->n_extra;
532
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100533 // Correct end of highlighted area for 'breakindent',
534 // required when 'linebreak' is also set.
535 if (wlv->tocol == wlv->vcol)
536 wlv->tocol += wlv->n_extra;
537 }
zeertzjq7e4f62a2023-12-28 23:19:52 +0100538
539 if (wp->w_skipcol > 0 && wlv->startrow == 0 && wp->w_p_wrap
540 && wp->w_briopt_sbr)
541 wlv->need_showbreak = FALSE;
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100542 }
543}
544#endif
545
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100546#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
547 static void
548handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
549{
550# ifdef FEAT_DIFF
551 if (wlv->filler_todo > 0)
552 {
553 // Draw "deleted" diff line(s).
554 if (char2cells(wp->w_fill_chars.diff) > 1)
555 {
556 wlv->c_extra = '-';
557 wlv->c_final = NUL;
558 }
559 else
560 {
561 wlv->c_extra = wp->w_fill_chars.diff;
562 wlv->c_final = NUL;
563 }
564# ifdef FEAT_RIGHTLEFT
565 if (wp->w_p_rl)
566 wlv->n_extra = wlv->col + 1;
567 else
568# endif
569 wlv->n_extra = wp->w_width - wlv->col;
570 wlv->char_attr = HL_ATTR(HLF_DED);
571 }
572# endif
573
574# ifdef FEAT_LINEBREAK
575 char_u *sbr = get_showbreak_value(wp);
576 if (*sbr != NUL && wlv->need_showbreak)
577 {
578 // Draw 'showbreak' at the start of each broken line.
579 wlv->p_extra = sbr;
580 wlv->c_extra = NUL;
581 wlv->c_final = NUL;
582 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100583 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100584
585 // Correct start of highlighted area for 'showbreak'.
586 if (wlv->fromcol >= wlv->vcol && wlv->fromcol < wlv->vcol_sbr)
587 wlv->fromcol = wlv->vcol_sbr;
588
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100589 // Correct end of highlighted area for 'showbreak',
590 // required when 'linebreak' is also set.
591 if (wlv->tocol == wlv->vcol)
zeertzjqdf23d7f2024-02-09 18:14:12 +0100592 wlv->tocol = wlv->vcol_sbr;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100593 // combine 'showbreak' with 'wincolor'
594 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
595# ifdef FEAT_SYN_HL
596 // combine 'showbreak' with 'cursorline'
597 if (wlv->cul_attr != 0)
598 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
599# endif
600 }
zeertzjq7e4f62a2023-12-28 23:19:52 +0100601
602 if (wp->w_skipcol == 0 || wlv->startrow > 0 || !wp->w_p_wrap
603 || !wp->w_briopt_sbr)
604 wlv->need_showbreak = FALSE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100605# endif
606}
607#endif
608
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100609#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100610/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100611 * Return the cell size of virtual text after truncation.
612 */
613 static int
614textprop_size_after_trunc(
615 win_T *wp,
616 int flags, // TP_FLAG_ALIGN_*
617 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100618 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100619 char_u *text,
620 int *n_used_ptr)
621{
622 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100623 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100624 int len = (int)STRLEN(text);
625 int strsize = 0;
626 int n_used;
627
Bram Moolenaar7e017462022-10-11 21:02:09 +0100628 // if the remaining size is to small and 'wrap' is set we wrap anyway and
629 // use the next line
630 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100631 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100632 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100633 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100634 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
635 {
636 int clen = ptr2cells(text + n_used);
637
638 if (strsize + clen > space)
639 break;
640 strsize += clen;
641 }
642 *n_used_ptr = n_used;
643 return strsize;
644}
645
646/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100647 * Take care of padding, right-align and truncation of virtual text after a
648 * line.
649 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
650 * padding, right-align and truncation. Otherwise only the size is computed.
651 * When "n_attr" is NULL returns the number of screen cells used.
652 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100653 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100654 int
655text_prop_position(
656 win_T *wp,
657 textprop_T *tp,
porygonisaduck38854b52022-11-27 20:55:05 +0000658 int vcol, // current text column
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100659 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100660 int *n_extra, // nr of bytes for virtual text
661 char_u **p_extra, // virtual text
662 int *n_attr, // attribute cells, NULL if not used
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000663 int *n_attr_skip, // cells to skip attr, NULL if not used
664 int do_skip) // skip_cells is not zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200665{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100666 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100667 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100668 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
Bram Moolenaar1aeb3eb2023-01-01 14:04:51 +0000669 int wrap = tp->tp_col < MAXCOL || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100670 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
porygonisaduck38854b52022-11-27 20:55:05 +0000671 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100672 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100673 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100674 int before = room; // spaces before the text
675 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100676 int n_used = *n_extra;
677 char_u *l = NULL;
678 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100679 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100680 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200681
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100682 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100683 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100684 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100685
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100686 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100687 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100688 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100689 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar2354b662023-04-23 21:42:25 +0100690 if (after < 0)
691 {
692 // text "above" has too much padding to fit
693 padding += after;
694 after = 0;
695 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100696 }
697 else
698 {
699 // Right-align: fill with before
700 if (right)
701 before -= cells;
porygonisaduck38854b52022-11-27 20:55:05 +0000702
703 // Below-align: empty line add one character
Bram Moolenaar7c02ad92022-11-29 21:37:13 +0000704 if (below && vcol == 0 && col_with_padding == col_off
705 && wp->w_width - col_off == before)
706 col_with_padding += 1;
porygonisaduck38854b52022-11-27 20:55:05 +0000707
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100708 if (before < 0
709 || !(right || below)
porygonisaduck38854b52022-11-27 20:55:05 +0000710 || (below ? (col_with_padding <= col_off || !wp->w_p_wrap)
711 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100712 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100713 if (right && (wrap
714 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100715 {
716 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100717 before = wp->w_width - col_off - strsize + room;
718 if (before < 0)
719 before = 0;
720 else
721 n_used = *n_extra;
722 }
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000723 else if (below && before > vcol && do_skip)
724 before -= vcol;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100725 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100726 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100727 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100728 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100729
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100730 // With 'nowrap' add one to show the "extends" character if needed (it
731 // doesn't show if the text just fits).
732 if (!wp->w_p_wrap
733 && n_used < *n_extra
734 && wp->w_lcs_chars.ext != NUL
735 && wp->w_p_list)
736 ++n_used;
737
738 // add 1 for NUL, 2 for when '…' is used
739 if (n_attr != NULL)
Christian Brabandtf1cc4d52023-08-12 00:14:14 +0200740 l = alloc(n_used + before + after + (padding > 0 ? padding : 0) + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100741 if (n_attr == NULL || l != NULL)
742 {
743 int off = 0;
744
745 if (n_attr != NULL)
746 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100747 vim_memset(l, ' ', before);
748 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100749 if (padding > 0)
750 {
751 vim_memset(l + off, ' ', padding);
752 off += padding;
753 }
754 vim_strncpy(l + off, *p_extra, n_used);
755 off += n_used;
756 }
757 else
758 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100759 off = before + after + padding + n_used;
760 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100761 }
762 if (n_attr != NULL)
763 {
764 if (n_used < *n_extra && wp->w_p_wrap)
765 {
766 char_u *lp = l + off - 1;
767
768 if (has_mbyte)
769 {
h-east4c42c7e2023-04-17 21:44:57 +0100770 char_u buf[MB_MAXBYTES + 1];
771 char_u *cp = buf;
772
773 // change the last character to '…', converted to the
774 // current 'encoding'
775 STRCPY(buf, "…");
776 if (!enc_utf8)
777 {
778 vimconv_T vc;
779
780 vc.vc_type = CONV_NONE;
781 convert_setup(&vc, (char_u *)"utf-8", p_enc);
782 if (vc.vc_type != CONV_NONE)
783 {
784 cp = string_convert(&vc, buf, NULL);
785 if (cp == NULL)
786 {
787 // when conversion fails use '>'
788 cp = buf;
789 STRCPY(buf, ">");
790 }
791 convert_setup(&vc, NULL, NULL);
792 }
793 }
794
795 lp -= (*mb_ptr2cells)(cp) - 1;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100796 lp -= (*mb_head_off)(l, lp);
h-east4c42c7e2023-04-17 21:44:57 +0100797 STRCPY(lp, cp);
Bram Moolenaar13845c42022-10-09 15:26:03 +0100798 n_used = lp - l + 3 - before - padding;
h-east4c42c7e2023-04-17 21:44:57 +0100799 if (cp != buf)
800 vim_free(cp);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100801 }
802 else
803 // change last character to '>'
804 *lp = '>';
805 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100806 else if (after > 0)
807 {
808 vim_memset(l + off, ' ', after);
809 l[off + after] = NUL;
810 }
811
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100812 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100813 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100814 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100815 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100816 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100817
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000818 // n_attr_skip will not be decremented before draw_state is
819 // WL_LINE
Christian Brabandtf1cc4d52023-08-12 00:14:14 +0200820 *n_attr_skip = before + (padding > 0 ? padding : 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100821 }
822 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100823 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100824
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100825 if (n_attr == NULL)
826 return cells;
827 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200828}
829#endif
830
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100831/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100832 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100833 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
834 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100835 */
836 static void
837wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
838{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100839 if (wlv->row == 0 && wp->w_skipcol > 0
840#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100841 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100842 && *get_showbreak_value(wp) == NUL
843#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100844 // do not overwrite the 'listchars' "precedes" text with "<<<"
845 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100846 {
847 int off = (int)(current_ScreenLine - ScreenLines);
zeertzjqecb87dd2023-06-03 19:45:06 +0100848 int max_off = off + screen_Columns;
Bram Moolenaareb4de622022-10-15 13:42:17 +0100849 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100850
Bram Moolenaareb4de622022-10-15 13:42:17 +0100851 if (wp->w_p_nu && wp->w_p_rnu)
852 // Do not overwrite the line number, change "123 text" to
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100853 // "123<<<xt".
Bram Moolenaareb4de622022-10-15 13:42:17 +0100854 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
855 {
856 ++off;
857 ++skip;
858 }
859
860 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100861 {
zeertzjqecb87dd2023-06-03 19:45:06 +0100862 if ((*mb_off2cells)(off, max_off) > 1)
863 // When the first half of a double-width character is
864 // overwritten, change the second half to a space.
865 ScreenLines[off + 1] = ' ';
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100866 ScreenLines[off] = '<';
867 if (enc_utf8)
868 ScreenLinesUC[off] = 0;
869 ScreenAttrs[off] = HL_ATTR(HLF_AT);
870 ++off;
871 }
872 }
873
874 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
875 negative_width ? -wp->w_width : wp->w_width,
876 wlv->screen_line_flags);
877}
878
879/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100880 * Called when finished with the line: draw the screen line and handle any
881 * highlighting until the right of the window.
882 */
883 static void
884draw_screen_line(win_T *wp, winlinevars_T *wlv)
885{
886#ifdef FEAT_SYN_HL
887 long v;
888
889 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
890 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100891 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100892 else
893 v = wp->w_leftcol;
894
895 // check if line ends before left margin
896 if (wlv->vcol < v + wlv->col - win_col_off(wp))
897 wlv->vcol = v + wlv->col - win_col_off(wp);
898# ifdef FEAT_CONCEAL
899 // Get rid of the boguscols now, we want to draw until the right
900 // edge for 'cursorcolumn'.
901 wlv->col -= wlv->boguscols;
902 wlv->boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000903# define VCOL_HLC (wlv->vcol - wlv->vcol_off_co - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100904# else
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000905# define VCOL_HLC (wlv->vcol - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100906# endif
907
908 if (wlv->draw_color_col)
909 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
910
911 if (((wp->w_p_cuc
912 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
913 && (int)wp->w_virtcol <
914 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
915 && wlv->lnum != wp->w_cursor.lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000916 || wlv->draw_color_col
917# ifdef LINE_ATTR
918 || wlv->line_attr != 0
919# endif
920 || wlv->win_attr != 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100921# ifdef FEAT_RIGHTLEFT
922 && !wp->w_p_rl
923# endif
924 )
925 {
926 int rightmost_vcol = 0;
927 int i;
928
929 if (wp->w_p_cuc)
930 rightmost_vcol = wp->w_virtcol;
931 if (wlv->draw_color_col)
932 // determine rightmost colorcolumn to possibly draw
933 for (i = 0; wlv->color_cols[i] >= 0; ++i)
934 if (rightmost_vcol < wlv->color_cols[i])
935 rightmost_vcol = wlv->color_cols[i];
936
937 while (wlv->col < wp->w_width)
938 {
939 ScreenLines[wlv->off] = ' ';
940 if (enc_utf8)
941 ScreenLinesUC[wlv->off] = 0;
942 ScreenCols[wlv->off] = MAXCOL;
943 ++wlv->col;
944 if (wlv->draw_color_col)
945 wlv->draw_color_col = advance_color_col(
946 VCOL_HLC, &wlv->color_cols);
947
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000948 int attr = wlv->win_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100949 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000950 attr = HL_ATTR(HLF_CUC);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100951 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000952 attr = HL_ATTR(HLF_MC);
953# ifdef LINE_ATTR
954 else if (wlv->line_attr != 0)
955 attr = wlv->line_attr;
956# endif
957 ScreenAttrs[wlv->off++] = attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100958
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000959 if (VCOL_HLC >= rightmost_vcol
960# ifdef LINE_ATTR
961 && wlv->line_attr == 0
962# endif
963 && wlv->win_attr == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100964 break;
965
966 ++wlv->vcol;
967 }
968 }
969#endif
970
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100971 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100972 ++wlv->row;
973 ++wlv->screen_row;
974}
975#undef VCOL_HLC
976
977/*
978 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100979 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100980 */
981 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100982win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100983{
984 wlv->col = 0;
985 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
Christian Brabandtdd75fcf2023-10-11 21:51:19 +0200986#ifdef FEAT_LINEBREAK
987 wlv->need_lbr = FALSE;
988#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100989
990#ifdef FEAT_RIGHTLEFT
991 if (wp->w_p_rl)
992 {
993 // Rightleft window: process the text in the normal direction, but put
994 // it in current_ScreenLine[] from right to left. Start at the
995 // rightmost column of the window.
996 wlv->col = wp->w_width - 1;
997 wlv->off += wlv->col;
998 wlv->screen_line_flags |= SLF_RIGHTLEFT;
999 }
1000#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001001 if (save_extra)
1002 {
1003 // reset the drawing state for the start of a wrapped line
1004 wlv->draw_state = WL_START;
1005 wlv->saved_n_extra = wlv->n_extra;
1006 wlv->saved_p_extra = wlv->p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +01001007 vim_free(wlv->saved_p_extra_free);
1008 wlv->saved_p_extra_free = wlv->p_extra_free;
1009 wlv->p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001010 wlv->saved_extra_attr = wlv->extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001011 wlv->saved_n_attr_skip = wlv->n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001012 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001013 wlv->saved_c_extra = wlv->c_extra;
1014 wlv->saved_c_final = wlv->c_final;
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02001015#ifdef FEAT_LINEBREAK
1016 wlv->need_lbr = TRUE;
1017#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001018#ifdef FEAT_SYN_HL
1019 if (!(wlv->cul_screenline
1020# ifdef FEAT_DIFF
1021 && wlv->diff_hlf == (hlf_T)0
1022# endif
1023 ))
1024 wlv->saved_char_attr = wlv->char_attr;
1025 else
1026#endif
1027 wlv->saved_char_attr = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001028
1029 // these are not used until restored in win_line_continue()
Bram Moolenaar1306b362022-08-06 15:59:06 +01001030 wlv->n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001031 wlv->n_attr_skip = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001032 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001033}
1034
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001035/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001036 * Called when wlv->draw_state is set to WL_LINE.
1037 */
1038 static void
1039win_line_continue(winlinevars_T *wlv)
1040{
1041 if (wlv->saved_n_extra > 0)
1042 {
1043 // Continue item from end of wrapped line.
1044 wlv->n_extra = wlv->saved_n_extra;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001045 wlv->saved_n_extra = 0;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001046 wlv->c_extra = wlv->saved_c_extra;
1047 wlv->c_final = wlv->saved_c_final;
1048 wlv->p_extra = wlv->saved_p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +01001049 vim_free(wlv->p_extra_free);
1050 wlv->p_extra_free = wlv->saved_p_extra_free;
1051 wlv->saved_p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001052 wlv->extra_attr = wlv->saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001053 wlv->n_attr_skip = wlv->saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001054 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001055 wlv->char_attr = wlv->saved_char_attr;
1056 }
1057 else
1058 wlv->char_attr = wlv->win_attr;
1059}
1060
zeertzjqb7acea12022-12-12 13:20:43 +00001061#ifdef FEAT_SYN_HL
1062 static void
1063apply_cursorline_highlight(
1064 winlinevars_T *wlv,
1065 int sign_present UNUSED)
1066{
1067 wlv->cul_attr = HL_ATTR(HLF_CUL);
1068# ifdef FEAT_SIGNS
1069 // Combine the 'cursorline' and sign highlighting, depending on
1070 // the sign priority.
1071 if (sign_present && wlv->sattr.sat_linehl > 0)
1072 {
1073 if (wlv->sattr.sat_priority >= 100)
1074 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1075 else
1076 wlv->line_attr = hl_combine_attr(wlv->line_attr, wlv->cul_attr);
1077 }
1078 else
1079# endif
1080# if defined(FEAT_QUICKFIX)
1081 // let the line attribute overrule 'cursorline', otherwise
1082 // it disappears when both have background set;
1083 // 'cursorline' can use underline or bold to make it show
1084 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1085# else
1086 wlv->line_attr = wlv->cul_attr;
1087# endif
1088}
1089#endif
1090
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001091/*
Luuk van Baal30805a12023-05-27 22:22:10 +01001092 * Display line "lnum" of window "wp" on the screen.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001093 * Start at row "startrow", stop when "endrow" is reached.
zeertzjqebfd8562024-02-06 10:59:03 +01001094 * When only updating the number column, "number_only" is set to the height of
1095 * the line, otherwise it is set to 0.
Luuk van Baal30805a12023-05-27 22:22:10 +01001096 * "spv" is used to store information for spell checking, kept between
1097 * sequential calls for the same window.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001098 * wp->w_virtcol needs to be valid.
1099 *
1100 * Return the number of last row the line occupies.
1101 */
1102 int
1103win_line(
1104 win_T *wp,
1105 linenr_T lnum,
1106 int startrow,
1107 int endrow,
Luuk van Baal30805a12023-05-27 22:22:10 +01001108 int number_only,
1109 spellvars_T *spv UNUSED)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001110{
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001111 winlinevars_T wlv; // variables passed between functions
1112
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001113 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001114 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001115 char_u *line; // current line
1116 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001117
Bram Moolenaar1306b362022-08-06 15:59:06 +01001118#ifdef FEAT_PROP_POPUP
1119 char_u *p_extra_free2 = NULL; // another p_extra to be freed
1120#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001121#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001122 int in_linebreak = FALSE; // n_extra set for showing linebreak
1123#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001124 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +01001125 // displaying eol at end-of-line
1126 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001127 int lcs_prec_todo = wp->w_lcs_chars.prec;
1128 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001129
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001130 int n_attr = 0; // chars with special attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001131 int saved_attr2 = 0; // char_attr saved for n_attr
1132 int n_attr3 = 0; // chars with overruling special attr
1133 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001134
zeertzjqb557f482023-08-22 22:07:34 +02001135 int skip_cells = 0; // nr of cells to skip for w_leftcol or
1136 // w_skipcol or concealing
1137 int skipped_cells = 0; // nr of skipped cells for virtual text
1138 // to be added to wlv.vcol later
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001139 int fromcol_prev = -2; // start of inverting after cursor
1140 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001141 int lnum_in_visual_area = FALSE;
1142 pos_T pos;
1143 long v;
1144
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001145 int attr_pri = FALSE; // char_attr has priority
1146 int area_highlighting = FALSE; // Visual or incsearch highlighting
1147 // in this line
1148 int vi_attr = 0; // attributes for Visual and incsearch
1149 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001150 int area_attr = 0; // attributes desired by highlighting
1151 int search_attr = 0; // attributes desired by 'hlsearch'
1152#ifdef FEAT_SYN_HL
1153 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1154 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001155 int prev_syntax_col = -1; // column of prev_syntax_attr
1156 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001157 int has_syntax = FALSE; // this buffer has syntax highl.
1158 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001159#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001160#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001161 int did_line = FALSE; // set to TRUE when line text done
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001162 int text_prop_count;
zeertzjq4e26a9a2023-12-03 17:50:47 +01001163 int last_textprop_text_idx = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001164 int text_prop_next = 0; // next text property to use
1165 textprop_T *text_props = NULL;
1166 int *text_prop_idxs = NULL;
1167 int text_props_active = 0;
1168 proptype_T *text_prop_type = NULL;
1169 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001170 int text_prop_attr_comb = 0; // text_prop_attr combined with
1171 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001172 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001173 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001174 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001175 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001176 int saved_search_attr = 0; // search_attr to be used when n_extra
1177 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001178 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001179 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001180#endif
1181#ifdef FEAT_SPELL
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001182 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001183# define SPWORDLEN 150
1184 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1185 int nextlinecol = 0; // column where nextline[] starts
1186 int nextline_idx = 0; // index in nextline[] where next line
1187 // starts
1188 int spell_attr = 0; // attributes desired by spelling
1189 int word_end = 0; // last byte with same spell_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001190 int cur_checked_col = 0; // checked column for current line
1191#endif
1192 int extra_check = 0; // has extra highlighting
1193 int multi_attr = 0; // attributes desired by multibyte
1194 int mb_l = 1; // multi-byte byte length
1195 int mb_c = 0; // decoded multi-byte character
1196 int mb_utf8 = FALSE; // screen char is UTF-8 char
1197 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001198#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001199 int change_start = MAXCOL; // first col of changed area
1200 int change_end = -1; // last col of changed area
1201#endif
1202 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001203 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001204 int in_multispace = FALSE; // in multiple consecutive spaces
1205 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001206#ifdef LINE_ATTR
Bram Moolenaarbf915842022-08-06 22:38:02 +01001207 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001208#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001209 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001210 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001211#ifdef FEAT_ARABIC
1212 int prev_c = 0; // previous Arabic character
1213 int prev_c1 = 0; // first composing char for prev_c
1214#endif
1215#if defined(LINE_ATTR)
1216 int did_line_attr = 0;
1217#endif
1218#ifdef FEAT_TERMINAL
1219 int get_term_attr = FALSE;
1220#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001221
Martin Tournoijba43e762022-10-13 22:12:15 +01001222#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001223 // margin columns for the screen line, needed for when 'cursorlineopt'
1224 // contains "screenline"
1225 int left_curline_col = 0;
1226 int right_curline_col = 0;
1227#endif
1228
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001229#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1230 int feedback_col = 0;
1231 int feedback_old_attr = -1;
1232#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001233
1234#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1235 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001236#endif
1237#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001238 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001239#endif
1240#ifdef FEAT_CONCEAL
1241 int syntax_flags = 0;
1242 int syntax_seqnr = 0;
1243 int prev_syntax_id = 0;
1244 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1245 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001246 int did_wcol = FALSE;
1247 int old_boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001248# define VCOL_HLC (wlv.vcol - wlv.vcol_off_co - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001249# define FIX_FOR_BOGUSCOLS \
1250 { \
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001251 wlv.n_extra += wlv.vcol_off_co; \
1252 wlv.vcol -= wlv.vcol_off_co; \
1253 wlv.vcol_off_co = 0; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001254 wlv.col -= wlv.boguscols; \
1255 old_boguscols = wlv.boguscols; \
1256 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001257 }
1258#else
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001259# define VCOL_HLC (wlv.vcol - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001260#endif
1261
1262 if (startrow > endrow) // past the end already!
1263 return startrow;
1264
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001265 CLEAR_FIELD(wlv);
1266
1267 wlv.lnum = lnum;
1268 wlv.startrow = startrow;
1269 wlv.row = startrow;
1270 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001271 wlv.fromcol = -10;
1272 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001273#ifdef FEAT_LINEBREAK
1274 wlv.vcol_sbr = -1;
1275#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001276
zeertzjqebfd8562024-02-06 10:59:03 +01001277 if (number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001278 {
1279 // To speed up the loop below, set extra_check when there is linebreak,
1280 // trailing white space and/or syntax processing to be done.
1281#ifdef FEAT_LINEBREAK
1282 extra_check = wp->w_p_lbr;
1283#endif
1284#ifdef FEAT_SYN_HL
1285 if (syntax_present(wp) && !wp->w_s->b_syn_error
1286# ifdef SYN_TIME_LIMIT
1287 && !wp->w_s->b_syn_slow
1288# endif
1289 )
1290 {
1291 // Prepare for syntax highlighting in this line. When there is an
1292 // error, stop syntax highlighting.
1293 save_did_emsg = did_emsg;
1294 did_emsg = FALSE;
1295 syntax_start(wp, lnum);
1296 if (did_emsg)
1297 wp->w_s->b_syn_error = TRUE;
1298 else
1299 {
1300 did_emsg = save_did_emsg;
1301#ifdef SYN_TIME_LIMIT
1302 if (!wp->w_s->b_syn_slow)
1303#endif
1304 {
1305 has_syntax = TRUE;
1306 extra_check = TRUE;
1307 }
1308 }
1309 }
1310
1311 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001312 wlv.color_cols = wp->w_p_cc_cols;
1313 if (wlv.color_cols != NULL)
1314 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001315#endif
1316
1317#ifdef FEAT_TERMINAL
1318 if (term_show_buffer(wp->w_buffer))
1319 {
1320 extra_check = TRUE;
1321 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001322 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001323 }
1324#endif
1325
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001326 // handle Visual active in this window
1327 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1328 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001329 pos_T *top, *bot;
1330
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001331 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1332 {
1333 // Visual is after curwin->w_cursor
1334 top = &curwin->w_cursor;
1335 bot = &VIsual;
1336 }
1337 else
1338 {
1339 // Visual is before curwin->w_cursor
1340 top = &VIsual;
1341 bot = &curwin->w_cursor;
1342 }
1343 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1344 if (VIsual_mode == Ctrl_V)
1345 {
1346 // block mode
1347 if (lnum_in_visual_area)
1348 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001349 wlv.fromcol = wp->w_old_cursor_fcol;
1350 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001351 }
1352 }
1353 else
1354 {
1355 // non-block mode
1356 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001357 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001358 else if (lnum == top->lnum)
1359 {
1360 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001361 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001362 else
1363 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001364 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001365 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001366 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001367 }
1368 }
1369 if (VIsual_mode != 'V' && lnum == bot->lnum)
1370 {
1371 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1372 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001373 wlv.fromcol = -10;
1374 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001375 }
1376 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001377 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001378 else
1379 {
1380 pos = *bot;
1381 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001382 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1383 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001384 else
1385 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001386 getvvcol(wp, &pos, NULL, NULL,
1387 (colnr_T *)&wlv.tocol);
1388 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001389 }
1390 }
1391 }
1392 }
1393
1394 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001395 if (!highlight_match && lnum == curwin->w_cursor.lnum
1396 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001397#ifdef FEAT_GUI
1398 && !gui.in_use
1399#endif
1400 )
1401 noinvcur = TRUE;
1402
1403 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001404 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001405 {
1406 area_highlighting = TRUE;
1407 vi_attr = HL_ATTR(HLF_V);
1408#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1409 if ((clip_star.available && !clip_star.owned
1410 && clip_isautosel_star())
1411 || (clip_plus.available && !clip_plus.owned
1412 && clip_isautosel_plus()))
1413 vi_attr = HL_ATTR(HLF_VNC);
1414#endif
1415 }
1416 }
1417
1418 // handle 'incsearch' and ":s///c" highlighting
1419 else if (highlight_match
1420 && wp == curwin
1421 && lnum >= curwin->w_cursor.lnum
1422 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1423 {
1424 if (lnum == curwin->w_cursor.lnum)
1425 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001426 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001427 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001428 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001429 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1430 {
1431 pos.lnum = lnum;
1432 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001433 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001434 }
1435 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001436 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001437 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001438 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1439 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001440 area_highlighting = TRUE;
1441 vi_attr = HL_ATTR(HLF_I);
1442 }
1443 }
1444
1445#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001446 wlv.filler_lines = diff_check(wp, lnum);
1447 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001448 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001449 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001450 {
1451 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001452 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001453 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001454 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001455 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001456 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001457 }
1458 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001459 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001460 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001461 area_highlighting = TRUE;
1462 }
1463 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001464 wlv.filler_lines = wp->w_topfill;
1465 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001466#endif
1467
1468#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001469 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001470 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001471 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001472#endif
1473
1474#ifdef LINE_ATTR
1475# ifdef FEAT_SIGNS
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001476 // If this line has a sign with line highlighting set wlv.line_attr.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001477 if (sign_present)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001478 wlv.line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001479# endif
1480# if defined(FEAT_QUICKFIX)
1481 // Highlight the current line in the quickfix window.
1482 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001483 wlv.line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001484# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001485 if (wlv.line_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001486 area_highlighting = TRUE;
1487#endif
1488
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001489#ifdef FEAT_SPELL
zeertzjqebfd8562024-02-06 10:59:03 +01001490 if (spv->spv_has_spell && number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001491 {
Luuk van Baal30805a12023-05-27 22:22:10 +01001492 // Prepare for spell checking.
1493 extra_check = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001494
Luuk van Baal30805a12023-05-27 22:22:10 +01001495 // When a word wrapped from the previous line the start of the
1496 // current line is valid.
1497 if (lnum == spv->spv_checked_lnum)
1498 cur_checked_col = spv->spv_checked_col;
Luuk van Baale84c7732023-05-31 18:57:36 +01001499 // Previous line was not spell checked, check for capital. This happens
1500 // for the first line in an updated region or after a closed fold.
1501 if (spv->spv_capcol_lnum == 0 && check_need_cap(wp, lnum, 0))
1502 spv->spv_cap_col = 0;
1503 else if (lnum != spv->spv_capcol_lnum)
Luuk van Baal30805a12023-05-27 22:22:10 +01001504 spv->spv_cap_col = -1;
1505 spv->spv_checked_lnum = 0;
1506
Luuk van Baal30805a12023-05-27 22:22:10 +01001507 // Get the start of the next line, so that words that wrap to the
1508 // next line are found too: "et<line-break>al.".
1509 // Trick: skip a few chars for C/shell/Vim comments
1510 nextline[SPWORDLEN] = NUL;
1511 if (lnum < wp->w_buffer->b_ml.ml_line_count)
Luuk van Baale84c7732023-05-31 18:57:36 +01001512 {
1513 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1514 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1515 }
1516 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1517
1518 // If current line is empty, check first word in next line for capital.
1519 ptr = skipwhite(line);
1520 if (*ptr == NUL)
1521 {
1522 spv->spv_cap_col = 0;
1523 spv->spv_capcol_lnum = lnum + 1;
1524 }
1525 // For checking first word with a capital skip white space.
1526 else if (spv->spv_cap_col == 0)
1527 spv->spv_cap_col = ptr - line;
1528
Luuk van Baal30805a12023-05-27 22:22:10 +01001529 // Copy the end of the current line into nextline[].
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001530 if (nextline[SPWORDLEN] == NUL)
1531 {
1532 // No next line or it is empty.
1533 nextlinecol = MAXCOL;
1534 nextline_idx = 0;
1535 }
1536 else
1537 {
1538 v = (long)STRLEN(line);
1539 if (v < SPWORDLEN)
1540 {
1541 // Short line, use it completely and append the start of the
1542 // next line.
1543 nextlinecol = 0;
1544 mch_memmove(nextline, line, (size_t)v);
1545 STRMOVE(nextline + v, nextline + SPWORDLEN);
1546 nextline_idx = v + 1;
1547 }
1548 else
1549 {
1550 // Long line, use only the last SPWORDLEN bytes.
1551 nextlinecol = v - SPWORDLEN;
1552 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1553 nextline_idx = SPWORDLEN + 1;
1554 }
1555 }
1556 }
1557#endif
1558
Luuk van Baale84c7732023-05-31 18:57:36 +01001559 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1560 ptr = line;
1561
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001562 if (wp->w_p_list)
1563 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001564 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001565 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001566 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001567 || wp->w_lcs_chars.trail
1568 || wp->w_lcs_chars.lead
1569 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001570 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001571
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001572 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001573 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001574 {
1575 trailcol = (colnr_T)STRLEN(ptr);
1576 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1577 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001578 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001579 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001580 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001581 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001582 {
1583 leadcol = 0;
1584 while (VIM_ISWHITE(ptr[leadcol]))
1585 ++leadcol;
1586 if (ptr[leadcol] == NUL)
1587 // in a line full of spaces all of them are treated as trailing
1588 leadcol = (colnr_T)0;
1589 else
1590 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001591 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001592 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001593 }
1594
Bram Moolenaard7657e92022-09-20 18:59:30 +01001595 wlv.wcr_attr = get_wcr_attr(wp);
1596 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001597 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001598 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001599 area_highlighting = TRUE;
1600 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001601
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001602 // When w_skipcol is non-zero and there is virtual text above the actual
1603 // text, then this much of the virtual text is skipped.
1604 int skipcol_in_text_prop_above = 0;
1605
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001606#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001607 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001608 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001609
1610 char_u *prop_start;
1611 text_prop_count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE);
1612 if (text_prop_count > 0)
1613 {
1614 // Make a copy of the properties, so that they are properly
1615 // aligned.
1616 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1617 if (text_props != NULL)
1618 mch_memmove(text_props, prop_start,
1619 text_prop_count * sizeof(textprop_T));
1620
1621 // Allocate an array for the indexes.
1622 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1623 if (text_prop_idxs == NULL)
1624 VIM_CLEAR(text_props);
1625
1626 if (text_props != NULL)
1627 {
1628 area_highlighting = TRUE;
1629 extra_check = TRUE;
1630
zeertzjq4e26a9a2023-12-03 17:50:47 +01001631 /* Find the last text property that inserts text. */
1632 for (int i = 0; i < text_prop_count; ++i)
1633 if (text_props[i].tp_id < 0)
1634 last_textprop_text_idx = i;
1635
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001636 // Text props "above" move the line number down to where the text
1637 // is. Only count the ones that are visible, not those that are
1638 // skipped because of w_skipcol.
1639 int text_width = wp->w_width - win_col_off(wp);
1640 for (int i = text_prop_count - 1; i >= 0; --i)
1641 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1642 {
1643 if (lnum == wp->w_topline
1644 && wp->w_skipcol - skipcol_in_text_prop_above
1645 >= text_width)
1646 {
1647 // This virtual text above is skipped, remove it from
1648 // the array.
1649 skipcol_in_text_prop_above += text_width;
1650 for (int j = i + 1; j < text_prop_count; ++j)
1651 text_props[j - 1] = text_props[j];
1652 ++i;
1653 --text_prop_count;
1654 }
1655 else
1656 ++wlv.text_prop_above_count;
1657 }
1658 }
1659 }
Bram Moolenaara572b932023-02-19 14:34:37 +00001660
zeertzjqebfd8562024-02-06 10:59:03 +01001661 if (number_only > 0)
Bram Moolenaara572b932023-02-19 14:34:37 +00001662 {
1663 // skip over rows only used for virtual text above
1664 wlv.row += wlv.text_prop_above_count;
1665 if (wlv.row > endrow)
1666 return wlv.row;
1667 wlv.screen_row += wlv.text_prop_above_count;
1668 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001669#endif
1670
zeertzjqce53e3e2023-09-01 18:49:30 +02001671#if defined(FEAT_LINEBREAK) || defined(FEAT_PROP_POPUP)
1672 colnr_T vcol_first_char = 0;
zeertzjqebfd8562024-02-06 10:59:03 +01001673 if (wp->w_p_lbr && number_only == 0)
zeertzjqce53e3e2023-09-01 18:49:30 +02001674 {
1675 chartabsize_T cts;
1676 init_chartabsize_arg(&cts, wp, lnum, 0, line, line);
1677 (void)win_lbr_chartabsize(&cts, NULL);
1678 vcol_first_char = cts.cts_first_char;
1679 clear_chartabsize_arg(&cts);
1680 }
1681#endif
1682
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001683 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1684 // first character to be displayed.
1685 if (wp->w_p_wrap)
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001686 v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001687 else
1688 v = wp->w_leftcol;
zeertzjqebfd8562024-02-06 10:59:03 +01001689 if (v > 0 && number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001690 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001691 char_u *prev_ptr = ptr;
1692 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001693 int charsize = 0;
zeertzjqb557f482023-08-22 22:07:34 +02001694 int head = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001695
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001696 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
zeertzjqb557f482023-08-22 22:07:34 +02001697 cts.cts_max_head_vcol = v;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001698 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001699 {
zeertzjqb557f482023-08-22 22:07:34 +02001700 head = 0;
1701 charsize = win_lbr_chartabsize(&cts, &head);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001702 cts.cts_vcol += charsize;
1703 prev_ptr = cts.cts_ptr;
1704 MB_PTR_ADV(cts.cts_ptr);
zeertzjqabc80812023-09-24 23:32:18 +02001705 if (wp->w_p_list)
1706 {
1707 in_multispace = *prev_ptr == ' ' && (*cts.cts_ptr == ' '
1708 || (prev_ptr > line && prev_ptr[-1] == ' '));
1709 if (!in_multispace)
1710 multispace_pos = 0;
1711 else if (cts.cts_ptr >= line + leadcol
1712 && wp->w_lcs_chars.multispace != NULL)
1713 {
1714 ++multispace_pos;
1715 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
1716 multispace_pos = 0;
1717 }
1718 else if (cts.cts_ptr < line + leadcol
1719 && wp->w_lcs_chars.leadmultispace != NULL)
1720 {
1721 ++multispace_pos;
1722 if (wp->w_lcs_chars.leadmultispace[multispace_pos] == NUL)
1723 multispace_pos = 0;
1724 }
1725 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001726 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001727 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001728 ptr = cts.cts_ptr;
1729 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001730
1731 // When:
1732 // - 'cuc' is set, or
1733 // - 'colorcolumn' is set, or
1734 // - 'virtualedit' is set, or
1735 // - the visual mode is active,
1736 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001737 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001738#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001739 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001740#endif
1741 virtual_active() ||
1742 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001743 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001744
1745 // Handle a character that's not completely on the screen: Put ptr at
1746 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001747 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001748 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001749 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001750 ptr = prev_ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001751 }
zeertzjqb557f482023-08-22 22:07:34 +02001752 if (v > wlv.vcol)
1753 skip_cells = v - wlv.vcol - head;
Bram Moolenaarcd105412022-10-10 19:50:42 +01001754
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001755 // Adjust for when the inverted text is before the screen,
1756 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001757 if (wlv.tocol <= wlv.vcol)
1758 wlv.fromcol = 0;
1759 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1760 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001761
1762#ifdef FEAT_LINEBREAK
1763 // When w_skipcol is non-zero, first line needs 'showbreak'
1764 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001765 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001766#endif
1767#ifdef FEAT_SPELL
1768 // When spell checking a word we need to figure out the start of the
1769 // word and if it's badly spelled or not.
Luuk van Baal30805a12023-05-27 22:22:10 +01001770 if (spv->spv_has_spell)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001771 {
1772 int len;
1773 colnr_T linecol = (colnr_T)(ptr - line);
1774 hlf_T spell_hlf = HLF_COUNT;
1775
1776 pos = wp->w_cursor;
1777 wp->w_cursor.lnum = lnum;
1778 wp->w_cursor.col = linecol;
1779 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1780
1781 // spell_move_to() may call ml_get() and make "line" invalid
1782 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1783 ptr = line + linecol;
1784
1785 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1786 {
1787 // no bad word found at line start, don't check until end of a
1788 // word
1789 spell_hlf = HLF_COUNT;
1790 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1791 }
1792 else
1793 {
1794 // bad word found, use attributes until end of word
1795 word_end = wp->w_cursor.col + len + 1;
1796
1797 // Turn index into actual attributes.
1798 if (spell_hlf != HLF_COUNT)
1799 spell_attr = highlight_attr[spell_hlf];
1800 }
1801 wp->w_cursor = pos;
1802
1803# ifdef FEAT_SYN_HL
1804 // Need to restart syntax highlighting for this line.
1805 if (has_syntax)
1806 syntax_start(wp, lnum);
1807# endif
1808 }
1809#endif
1810 }
1811
1812 // Correct highlighting for cursor that can't be disabled.
1813 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001814 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001815 {
1816 if (noinvcur)
1817 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001818 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001819 {
1820 // highlighting starts at cursor, let it start just after the
1821 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001822 fromcol_prev = wlv.fromcol;
1823 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001824 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001825 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001826 // restart highlighting after the cursor
1827 fromcol_prev = wp->w_virtcol;
1828 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001829 if (wlv.fromcol >= wlv.tocol)
1830 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001831 }
1832
1833#ifdef FEAT_SEARCH_EXTRA
zeertzjqebfd8562024-02-06 10:59:03 +01001834 if (number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001835 {
1836 v = (long)(ptr - line);
1837 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1838 &line, &screen_search_hl,
1839 &search_attr);
1840 ptr = line + v; // "line" may have been updated
1841 }
1842#endif
1843
1844#ifdef FEAT_SYN_HL
1845 // Cursor line highlighting for 'cursorline' in the current window.
1846 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1847 {
1848 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001849 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001850 if (!(wp == curwin && VIsual_active)
1851 && wp->w_p_culopt_flags != CULOPT_NBR)
1852 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001853 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001854 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1855
zeertzjqb7acea12022-12-12 13:20:43 +00001856 // Only apply CursorLine highlight here when "screenline" is not
1857 // present in 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001858 if (!wlv.cul_screenline)
zeertzjqb7acea12022-12-12 13:20:43 +00001859 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001860 else
1861 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001862 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001863 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1864 }
1865 area_highlighting = TRUE;
1866 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001867 }
1868#endif
1869
Bram Moolenaar1306b362022-08-06 15:59:06 +01001870 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001871
1872 // Repeat for the whole displayed line.
1873 for (;;)
1874 {
1875#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001876 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001877#endif
1878#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001879 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001880#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001881
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001882 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001883 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001884 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001885#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001886 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001887 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001888 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001889 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001890 }
1891#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001892 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001893 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001894 wlv.draw_state = WL_CMDLINE;
Sean Dewar988f7432023-08-16 14:17:36 +01001895 if (wp == cmdwin_win)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001896 {
1897 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001898 wlv.n_extra = 1;
1899 wlv.c_extra = cmdwin_type;
1900 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001901 wlv.char_attr =
1902 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001903 }
1904 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001905#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001906 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001907 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001908 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001909 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001910 }
1911#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001912#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001913 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001914 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001915 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001916 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001917 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001918 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001919 }
1920#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001921 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001922 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001923 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001924 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001925 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001926 }
zeertzjqebfd8562024-02-06 10:59:03 +01001927
1928 // When only displaying the (relative) line number and that's done,
1929 // stop here.
1930 if (number_only > 0 && wlv.draw_state == WL_NR && wlv.n_extra == 0)
1931 {
1932 wlv_screen_line(wp, &wlv, TRUE);
1933 // Need to update more screen lines if:
1934 // - LineNrAbove or LineNrBelow is used, or
1935 // - still drawing filler lines.
1936 if ((wlv.row + 1 - wlv.startrow < number_only
1937 && (HL_ATTR(HLF_LNA) != 0 || HL_ATTR(HLF_LNB) != 0))
1938#ifdef FEAT_DIFF
1939 || wlv.filler_todo > 0
1940#endif
1941 )
1942 {
1943 ++wlv.row;
1944 ++wlv.screen_row;
1945 if (wlv.row == endrow)
1946 break;
1947#ifdef FEAT_DIFF
1948 --wlv.filler_todo;
1949 if (wlv.filler_todo == 0 && wp->w_botfill)
1950 break;
1951#endif
1952 win_line_start(wp, &wlv, TRUE);
1953 continue;
1954 }
1955 else
1956 break;
1957 }
1958
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001959#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001960 // Check if 'breakindent' applies and show it.
1961 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1962 if (wlv.n_extra == 0)
1963 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001964#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001965#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001966 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001967 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001968 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001969 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001970 }
1971#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001972 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001973 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001974 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001975 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001976 }
1977 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001978
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001979#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001980 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001981 && wlv.vcol >= left_curline_col
1982 && wlv.vcol < right_curline_col)
zeertzjqb7acea12022-12-12 13:20:43 +00001983 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001984#endif
1985
1986 // When still displaying '$' of change command, stop at cursor.
zeertzjqebfd8562024-02-06 10:59:03 +01001987 if (dollar_vcol >= 0 && wp == curwin
1988 && lnum == wp->w_cursor.lnum
1989 && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001990 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001991 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001992 // Pretend we have finished updating the window. Except when
1993 // 'cursorcolumn' is set.
1994#ifdef FEAT_SYN_HL
1995 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001996 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001997 else
1998#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001999 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002000 break;
2001 }
2002
Bram Moolenaar1306b362022-08-06 15:59:06 +01002003 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002004 {
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002005#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002006 if (text_props != NULL)
2007 {
2008 int pi;
2009 int bcol = (int)(ptr - line);
2010
Bram Moolenaar1306b362022-08-06 15:59:06 +01002011 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002012# ifdef FEAT_LINEBREAK
2013 && !in_linebreak
2014# endif
2015 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002016 --bcol; // still working on the previous char, e.g. Tab
2017
2018 // Check if any active property ends.
2019 for (pi = 0; pi < text_props_active; ++pi)
2020 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002021 int tpi = text_prop_idxs[pi];
2022 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002023
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002024 // An inline property ends when after the start column plus
2025 // length. An "above" property ends when used and n_extra
2026 // is zero.
2027 if ((tp->tp_col != MAXCOL
2028 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002029 {
2030 if (pi + 1 < text_props_active)
2031 mch_memmove(text_prop_idxs + pi,
2032 text_prop_idxs + pi + 1,
2033 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002034 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002035 --text_props_active;
2036 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002037# ifdef FEAT_LINEBREAK
2038 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002039 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002040 syntax_attr = 0;
2041# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002042 }
2043 }
2044
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002045# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01002046 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002047 // not on the next char yet, don't start another prop
2048 --bcol;
2049# endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002050 int display_text_first = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002051
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002052 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002053 // With 'nowrap' and not in the first screen line only "below"
2054 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002055 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002056 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002057 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002058 && (wp->w_p_wrap
2059 || wlv.row == startrow
2060 || (text_props[text_prop_next].tp_flags
2061 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002062 || (bcol == 0
2063 && (text_props[text_prop_next].tp_flags
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002064 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002065 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002066 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01002067 if (text_props[text_prop_next].tp_col == MAXCOL
2068 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002069 + text_props[text_prop_next].tp_len)
2070 text_prop_idxs[text_props_active++] = text_prop_next;
2071 ++text_prop_next;
2072 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002073
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002074 if (wlv.n_extra == 0 ||
2075 (!wlv.extra_for_textprop
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002076 && !(text_prop_type != NULL &&
2077 text_prop_flags & PT_FLAG_OVERRIDE)
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002078 ))
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002079 {
2080 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002081 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002082 text_prop_flags = 0;
2083 text_prop_type = NULL;
2084 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002085 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002086 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002087 if (text_props_active > 0 && wlv.n_extra == 0
2088 && !display_text_first)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002089 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01002090 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002091 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002092 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002093
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002094 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002095 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002096
2097 // Sort the properties on priority and/or starting last.
2098 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002099 sort_text_props(wp->w_buffer, text_props,
2100 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002101
2102 for (pi = 0; pi < text_props_active; ++pi)
2103 {
2104 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002105 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002106 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002107 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002108
Bram Moolenaarcd105412022-10-10 19:50:42 +01002109 // Only use a text property that can be displayed.
2110 // Skip "after" properties when wrap is off and at the
2111 // end of the window.
2112 if (pt != NULL
2113 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2114 && tp->tp_id != -MAXCOL
2115 && !(tp->tp_id < 0
2116 && !wp->w_p_wrap
2117 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2118 | TP_FLAG_ALIGN_ABOVE
2119 | TP_FLAG_ALIGN_BELOW)) == 0
2120 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002121 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002122 if (tp->tp_col == MAXCOL
2123 && *ptr == NUL
2124 && ((wp->w_p_list && lcs_eol_one > 0
2125 && (tp->tp_flags
2126 & TP_FLAG_ALIGN_ABOVE) == 0)
2127 || (ptr == line
2128 && !did_line
2129 && (tp->tp_flags
2130 & TP_FLAG_ALIGN_BELOW))))
2131 {
2132 // skip this prop, first display the '$' after
2133 // the line or display an empty line
2134 text_prop_follows = TRUE;
2135 if (used_tpi < 0)
2136 display_text_first = TRUE;
2137 continue;
2138 }
2139
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002140 if (pt->pt_hl_id > 0)
2141 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002142 text_prop_type = pt;
2143 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002144 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002145 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2146 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002147 text_prop_flags = pt->pt_flags;
2148 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002149 used_tpi = tpi;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002150 display_text_first = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002151 }
2152 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002153 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002154 && -text_prop_id
2155 <= wp->w_buffer->b_textprop_text.ga_len)
2156 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002157 textprop_T *tp = &text_props[used_tpi];
2158 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002159 ->b_textprop_text.ga_data)[
2160 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002161 int above = (tp->tp_flags
2162 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002163 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002164
2165 // reset the ID in the copy to avoid it being used
2166 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002167 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002168
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002169 if (p != NULL)
2170 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002171 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002172 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002173 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002174 & TP_FLAG_ALIGN_BELOW);
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002175 int wrap = tp->tp_col < MAXCOL
2176 || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002177 int padding = tp->tp_col == MAXCOL
2178 && tp->tp_len > 1
2179 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002180
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002181 // Insert virtual text before the current
2182 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002183 wlv.p_extra = p;
2184 wlv.c_extra = NUL;
2185 wlv.c_final = NUL;
2186 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002187 wlv.extra_for_textprop = TRUE;
zeertzjq6e940d92023-08-17 23:21:40 +02002188 wlv.start_extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002189 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2190 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002191 n_attr = mb_charlen(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002192 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002193 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002194 if (*ptr == NUL)
2195 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002196 text_prop_flags &= ~PT_FLAG_COMBINE;
zeertzjq6b9c2022023-09-11 20:01:17 +02002197# ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002198 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002199 {
2200 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002201 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002202 wlv.need_showbreak = FALSE;
2203 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002204 }
zeertzjq6b9c2022023-09-11 20:01:17 +02002205# endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002206 if ((right || above || below || !wrap
2207 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002208 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002209 char_u *prev_p_extra = wlv.p_extra;
2210 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002211
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002212 // Take care of padding, right-align and
2213 // truncation.
2214 // Shared with win_lbr_chartabsize(), must do
2215 // exactly the same.
2216 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002217 wlv.vcol,
zeertzjq6b9c2022023-09-11 20:01:17 +02002218# ifdef FEAT_RIGHTLEFT
2219 wp->w_p_rl
2220 ? wp->w_width - wlv.col - 1
2221 :
2222# endif
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002223 wlv.col,
2224 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002225 &n_attr, &wlv.n_attr_skip,
2226 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002227 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002228 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002229 // wlv.p_extra was allocated
2230 vim_free(p_extra_free2);
2231 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002232 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002233
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002234 if (above)
2235 wlv.vcol_off_tp = wlv.n_extra;
2236
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002237 if (lcs_eol_one < 0
2238 && wp->w_p_wrap
2239 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002240 + wlv.n_extra - 2 > wp->w_width)
2241 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002242 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002243
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002244 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002245 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002246 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002247 {
2248 draw_screen_line(wp, &wlv);
2249
2250 // When line got too long for screen break
2251 // here.
2252 if (wlv.row == endrow)
2253 {
2254 ++wlv.row;
2255 break;
2256 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002257 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002258 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002259 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002260 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002261 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002262
Bram Moolenaarcd105412022-10-10 19:50:42 +01002263 // If the text didn't reach until the first window
2264 // column we need to skip cells.
2265 if (skip_cells > 0)
2266 {
2267 if (wlv.n_extra > skip_cells)
2268 {
2269 wlv.n_extra -= skip_cells;
2270 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002271 wlv.n_attr_skip -= skip_cells;
2272 if (wlv.n_attr_skip < 0)
2273 wlv.n_attr_skip = 0;
zeertzjqb557f482023-08-22 22:07:34 +02002274 skipped_cells += skip_cells;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002275 skip_cells = 0;
2276 }
2277 else
2278 {
2279 // the whole text is left of the window, drop
2280 // it and advance to the next one
2281 skip_cells -= wlv.n_extra;
zeertzjqb557f482023-08-22 22:07:34 +02002282 skipped_cells += wlv.n_extra;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002283 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002284 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002285 bail_out = TRUE;
2286 }
2287 }
2288
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002289 // If another text prop follows the condition below at
2290 // the last window column must know.
Dylan Thacker-Smith83925be2024-02-21 21:03:10 +01002291 // If this is an "above" text prop and 'nowrap' then we
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002292 // must wrap anyway.
2293 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002294 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002295 && (wp->w_p_wrap
2296 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002297 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002298
2299 if (bail_out)
2300 // starting a new line for "below"
2301 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002302 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002303 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002304 else if (text_prop_next < text_prop_count
2305 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002306 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2307 || (!wp->w_p_wrap
2308 && wlv.col == wp->w_width - 1
2309 && (text_props[text_prop_next].tp_flags
2310 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002311 // When at last-but-one character and a text property
2312 // follows after it, we may need to flush the line after
2313 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002314 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002315 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002316 }
zeertzjq6e940d92023-08-17 23:21:40 +02002317
2318 if (wlv.start_extra_for_textprop)
2319 {
2320 wlv.start_extra_for_textprop = FALSE;
2321 // restore search_attr and area_attr when n_extra
2322 // is down to zero
2323 saved_search_attr = search_attr;
2324 saved_area_attr = area_attr;
2325 search_attr = 0;
2326 area_attr = 0;
2327 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002328#endif
2329
zeertzjq6e940d92023-08-17 23:21:40 +02002330 int *area_attr_p =
2331#ifdef FEAT_PROP_POPUP
2332 wlv.extra_for_textprop ? &saved_area_attr :
2333#endif
2334 &area_attr;
2335
2336 // handle Visual or match highlighting in this line
2337 if (wlv.vcol == wlv.fromcol
2338 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
2339 && ((wlv.n_extra == 0 && (*mb_ptr2cells)(ptr) > 1)
2340 || (wlv.n_extra > 0 && wlv.p_extra != NULL
2341 && (*mb_ptr2cells)(wlv.p_extra) > 1)))
2342 || ((int)vcol_prev == fromcol_prev
2343 && vcol_prev < wlv.vcol // not at margin
2344 && wlv.vcol < wlv.tocol))
2345 *area_attr_p = vi_attr; // start highlighting
2346 else if (*area_attr_p != 0
2347 && (wlv.vcol == wlv.tocol
2348 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
2349 *area_attr_p = 0; // stop highlighting
2350
zeertzjqe500ae82023-08-17 22:35:26 +02002351#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaare38fc862022-08-11 17:24:50 +01002352 if (wlv.n_extra == 0)
2353 {
2354 // Check for start/end of 'hlsearch' and other matches.
2355 // After end, check for start/end of next match.
2356 // When another match, have to check for start again.
2357 v = (long)(ptr - line);
2358 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2359 &screen_search_hl, &has_match_conc,
2360 &match_conc, did_line_attr, lcs_eol_one,
2361 &on_last_col);
2362 ptr = line + v; // "line" may have been changed
Bram Moolenaare38fc862022-08-11 17:24:50 +01002363
2364 // Do not allow a conceal over EOL otherwise EOL will be missed
2365 // and bad things happen.
2366 if (*ptr == NUL)
2367 has_match_conc = 0;
zeertzjqb25dbb32023-08-13 18:11:05 +02002368 }
zeertzjqe500ae82023-08-17 22:35:26 +02002369#endif
zeertzjqb25dbb32023-08-13 18:11:05 +02002370
Bram Moolenaare38fc862022-08-11 17:24:50 +01002371#ifdef FEAT_DIFF
2372 if (wlv.diff_hlf != (hlf_T)0)
2373 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002374 // When there is extra text (e.g. virtual text) it gets the
2375 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002376 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2377 && wlv.n_extra == 0)
2378 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002379 if (wlv.diff_hlf == HLF_TXD
2380 && ((ptr - line > change_end && wlv.n_extra == 0)
2381 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002382 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002383 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002384 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2385 && wp->w_p_culopt_flags != CULOPT_NBR
2386 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2387 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002388 wlv.line_attr = hl_combine_attr(
2389 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002390 }
2391#endif
2392
Bram Moolenaara74fda62019-10-19 17:38:03 +02002393#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002394 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002395 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002396 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002397# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002398 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002399 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002400# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002401 // Get syntax attribute.
2402 if (has_syntax)
2403 {
2404 // Get the syntax attribute for the character. If there
2405 // is an error, disable syntax highlighting.
2406 save_did_emsg = did_emsg;
2407 did_emsg = FALSE;
2408
2409 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002410 if (v == prev_syntax_col)
2411 // at same column again
2412 syntax_attr = prev_syntax_attr;
2413 else
2414 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002415# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002416 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002417# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002418 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002419# ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01002420 spv->spv_has_spell ? &can_spell :
Bram Moolenaar34390282019-10-16 14:38:26 +02002421# endif
Luuk van Baal30805a12023-05-27 22:22:10 +01002422 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002423 prev_syntax_col = v;
2424 prev_syntax_attr = syntax_attr;
2425 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002426
Bram Moolenaar34390282019-10-16 14:38:26 +02002427 if (did_emsg)
2428 {
2429 wp->w_s->b_syn_error = TRUE;
2430 has_syntax = FALSE;
2431 syntax_attr = 0;
2432 }
2433 else
2434 did_emsg = save_did_emsg;
2435# ifdef SYN_TIME_LIMIT
2436 if (wp->w_s->b_syn_slow)
2437 has_syntax = FALSE;
2438# endif
2439
2440 // Need to get the line again, a multi-line regexp may
2441 // have made it invalid.
2442 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2443 ptr = line + v;
2444# ifdef FEAT_CONCEAL
2445 // no concealing past the end of the line, it interferes
2446 // with line highlighting
2447 if (*ptr == NUL)
2448 syntax_flags = 0;
2449 else
2450 syntax_flags = get_syntax_info(&syntax_seqnr);
2451# endif
2452 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002453 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002454# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002455 // Combine text property highlight into syntax highlight.
2456 if (text_prop_type != NULL)
2457 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002458 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002459 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2460 else
2461 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002462 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002463 }
2464# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002465#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002466
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002467 // Decide which of the highlight attributes to use.
2468 attr_pri = TRUE;
2469#ifdef LINE_ATTR
2470 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002471 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002472 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002473 if (!highlight_match)
2474 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002475 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002476# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002477 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002478# endif
2479 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002480 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002481 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002482 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002483# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002484 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002485# endif
2486 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002487 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002488 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2489 || wlv.vcol < wlv.fromcol
2490 || vcol_prev < fromcol_prev
2491 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002492 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002493 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002494 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002495# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002496 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002497# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002498 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002499# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002500 attr_pri = FALSE;
2501 }
2502#else
2503 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002504 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002505 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002506 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002507#endif
2508 else
2509 {
2510 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002511#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002512 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002513#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002514 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002515#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002516 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002517#ifdef FEAT_PROP_POPUP
2518 // override with text property highlight when "override" is TRUE
2519 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002520 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002521#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002522 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002523
2524 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002525 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002526 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002527 if (wlv.char_attr == 0)
2528 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002529 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002530 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002531 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002532
2533 // Get the next character to put on the screen.
2534
2535 // The "p_extra" points to the extra stuff that is inserted to
2536 // represent special characters (non-printable stuff) and other
2537 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002538 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002539 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2540 // "p_extra[n_extra]".
2541 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002542 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002543 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002544 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002545 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002546 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2547 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002548 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2549 if (enc_utf8 && utf_char2len(c) > 1)
2550 {
2551 mb_utf8 = TRUE;
2552 u8cc[0] = 0;
2553 c = 0xc0;
2554 }
2555 else
2556 mb_utf8 = FALSE;
2557 }
2558 else
2559 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002560 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002561 if (has_mbyte)
2562 {
2563 mb_c = c;
2564 if (enc_utf8)
2565 {
2566 // If the UTF-8 character is more than one byte:
2567 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002568 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002569 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002570 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002571 mb_l = 1;
2572 else if (mb_l > 1)
2573 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002574 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002575 mb_utf8 = TRUE;
2576 c = 0xc0;
2577 }
2578 }
2579 else
2580 {
2581 // if this is a DBCS character, put it in "mb_c"
2582 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002583 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002584 mb_l = 1;
2585 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002586 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002587 }
2588 if (mb_l == 0) // at the NUL at end-of-line
2589 mb_l = 1;
2590
2591 // If a double-width char doesn't fit display a '>' in the
2592 // last column.
2593 if ((
2594# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002595 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002596# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002597 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002598 && (*mb_char2cells)(mb_c) == 2)
2599 {
2600 c = '>';
2601 mb_c = c;
2602 mb_l = 1;
2603 mb_utf8 = FALSE;
2604 multi_attr = HL_ATTR(HLF_AT);
2605#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002606 if (wlv.cul_attr)
2607 multi_attr = hl_combine_attr(
2608 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002609#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002610 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002611
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002612 // put the pointer back to output the double-width
2613 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002614 ++wlv.n_extra;
2615 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002616 }
2617 else
2618 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002619 wlv.n_extra -= mb_l - 1;
2620 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002621 }
2622 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002623 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002624 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002625 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002626#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002627 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002628 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002629 // Only restore search_attr and area_attr after "n_extra" in
2630 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002631 if (wlv.saved_n_extra <= 0)
2632 {
2633 if (search_attr == 0)
2634 search_attr = saved_search_attr;
2635 if (area_attr == 0 && *ptr != NUL)
2636 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002637
2638 if (wlv.extra_for_textprop)
2639 // wlv.extra_attr should be used at this position but
2640 // not any further.
2641 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002642 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002643
2644 wlv.extra_for_textprop = FALSE;
2645 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002646 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002647#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002648 }
2649 else
2650 {
2651#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002652 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002653#endif
zeertzjqe500ae82023-08-17 22:35:26 +02002654 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002655
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002656 // Get a character from the line itself.
2657 c = *ptr;
2658#ifdef FEAT_LINEBREAK
2659 c0 = *ptr;
2660#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002661 if (c == NUL)
zeertzjqb557f482023-08-22 22:07:34 +02002662 {
2663#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002664 // text is finished, may display a "below" virtual text
2665 did_line = TRUE;
2666#endif
zeertzjqb557f482023-08-22 22:07:34 +02002667 // no more cells to skip
2668 skip_cells = 0;
2669 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002670
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002671 if (has_mbyte)
2672 {
2673 mb_c = c;
2674 if (enc_utf8)
2675 {
2676 // If the UTF-8 character is more than one byte: Decode it
2677 // into "mb_c".
2678 mb_l = utfc_ptr2len(ptr);
2679 mb_utf8 = FALSE;
2680 if (mb_l > 1)
2681 {
2682 mb_c = utfc_ptr2char(ptr, u8cc);
2683 // Overlong encoded ASCII or ASCII with composing char
2684 // is displayed normally, except a NUL.
2685 if (mb_c < 0x80)
2686 {
2687 c = mb_c;
2688#ifdef FEAT_LINEBREAK
2689 c0 = mb_c;
2690#endif
2691 }
2692 mb_utf8 = TRUE;
2693
2694 // At start of the line we can have a composing char.
2695 // Draw it as a space with a composing char.
2696 if (utf_iscomposing(mb_c))
2697 {
2698 int i;
2699
2700 for (i = Screen_mco - 1; i > 0; --i)
2701 u8cc[i] = u8cc[i - 1];
2702 u8cc[0] = mb_c;
2703 mb_c = ' ';
2704 }
2705 }
2706
2707 if ((mb_l == 1 && c >= 0x80)
2708 || (mb_l >= 1 && mb_c == 0)
2709 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2710 {
2711 // Illegal UTF-8 byte: display as <xx>.
2712 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002713 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002714# ifdef FEAT_RIGHTLEFT
2715 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002716 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002717# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002718 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002719 c = *wlv.p_extra;
2720 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002721 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002722 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2723 wlv.c_extra = NUL;
2724 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002725 if (area_attr == 0 && search_attr == 0)
2726 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002727 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002728 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002729 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002730 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002731 }
2732 }
2733 else if (mb_l == 0) // at the NUL at end-of-line
2734 mb_l = 1;
2735#ifdef FEAT_ARABIC
2736 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2737 {
2738 // Do Arabic shaping.
2739 int pc, pc1, nc;
2740 int pcc[MAX_MCO];
2741
2742 // The idea of what is the previous and next
2743 // character depends on 'rightleft'.
2744 if (wp->w_p_rl)
2745 {
2746 pc = prev_c;
2747 pc1 = prev_c1;
2748 nc = utf_ptr2char(ptr + mb_l);
2749 prev_c1 = u8cc[0];
2750 }
2751 else
2752 {
2753 pc = utfc_ptr2char(ptr + mb_l, pcc);
2754 nc = prev_c;
2755 pc1 = pcc[0];
2756 }
2757 prev_c = mb_c;
2758
2759 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2760 }
2761 else
2762 prev_c = mb_c;
2763#endif
2764 }
2765 else // enc_dbcs
2766 {
2767 mb_l = MB_BYTE2LEN(c);
2768 if (mb_l == 0) // at the NUL at end-of-line
2769 mb_l = 1;
2770 else if (mb_l > 1)
2771 {
2772 // We assume a second byte below 32 is illegal.
2773 // Hopefully this is OK for all double-byte encodings!
2774 if (ptr[1] >= 32)
2775 mb_c = (c << 8) + ptr[1];
2776 else
2777 {
2778 if (ptr[1] == NUL)
2779 {
2780 // head byte at end of line
2781 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002782 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002783 }
2784 else
2785 {
2786 // illegal tail byte
2787 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002788 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002789 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002790 wlv.p_extra = wlv.extra;
2791 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002792 wlv.c_extra = NUL;
2793 wlv.c_final = NUL;
2794 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002795 if (area_attr == 0 && search_attr == 0)
2796 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002797 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002798 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002799 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002800 // save current attr
2801 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002802 }
2803 mb_c = c;
2804 }
2805 }
2806 }
2807 // If a double-width char doesn't fit display a '>' in the
2808 // last column; the character is displayed at the start of the
2809 // next line.
2810 if ((
2811# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002812 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002813# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002814 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002815 && (*mb_char2cells)(mb_c) == 2)
2816 {
2817 c = '>';
2818 mb_c = c;
2819 mb_utf8 = FALSE;
2820 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002821 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002822 // Put pointer back so that the character will be
2823 // displayed at the start of the next line.
2824 --ptr;
2825#ifdef FEAT_CONCEAL
2826 did_decrement_ptr = TRUE;
2827#endif
2828 }
2829 else if (*ptr != NUL)
2830 ptr += mb_l - 1;
2831
2832 // If a double-width char doesn't fit at the left side display
2833 // a '<' in the first column. Don't do this for unprintable
2834 // characters.
zeertzjqb557f482023-08-22 22:07:34 +02002835 if (skip_cells > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002836 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002837 wlv.n_extra = 1;
2838 wlv.c_extra = MB_FILLER_CHAR;
2839 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002840 c = ' ';
2841 if (area_attr == 0 && search_attr == 0)
2842 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002843 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002844 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002845 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002846 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002847 }
2848 mb_c = c;
2849 mb_utf8 = FALSE;
2850 mb_l = 1;
2851 }
2852
2853 }
2854 ++ptr;
2855
2856 if (extra_check)
2857 {
2858#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002859 // Check spelling (unless at the end of the line).
2860 // Only do this when there is no syntax highlighting, the
2861 // @Spell cluster is not used or the current syntax item
2862 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002863 v = (long)(ptr - line);
Luuk van Baal30805a12023-05-27 22:22:10 +01002864 if (spv->spv_has_spell && v >= word_end && v > cur_checked_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002865 {
2866 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002867 // do not calculate cap_col at the end of the line or when
2868 // only white space is following
2869 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002870# ifdef FEAT_SYN_HL
2871 !has_syntax ||
2872# endif
2873 can_spell))
2874 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002875 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002876 int len;
2877 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002878
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002879 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002880 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002881
2882 // Use nextline[] if possible, it has the start of the
2883 // next line concatenated.
2884 if ((prev_ptr - line) - nextlinecol >= 0)
2885 p = nextline + (prev_ptr - line) - nextlinecol;
2886 else
2887 p = prev_ptr;
Luuk van Baal30805a12023-05-27 22:22:10 +01002888 spv->spv_cap_col -= (int)(prev_ptr - line);
2889 len = spell_check(wp, p, &spell_hlf, &spv->spv_cap_col,
2890 spv->spv_unchanged);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002891 word_end = v + len;
2892
2893 // In Insert mode only highlight a word that
2894 // doesn't touch the cursor.
2895 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002896 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002897 && wp->w_cursor.lnum == lnum
2898 && wp->w_cursor.col >=
2899 (colnr_T)(prev_ptr - line)
2900 && wp->w_cursor.col < (colnr_T)word_end)
2901 {
2902 spell_hlf = HLF_COUNT;
2903 spell_redraw_lnum = lnum;
2904 }
2905
2906 if (spell_hlf == HLF_COUNT && p != prev_ptr
2907 && (p - nextline) + len > nextline_idx)
2908 {
2909 // Remember that the good word continues at the
2910 // start of the next line.
Luuk van Baal30805a12023-05-27 22:22:10 +01002911 spv->spv_checked_lnum = lnum + 1;
2912 spv->spv_checked_col = (p - nextline) + len
2913 - nextline_idx;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002914 }
2915
2916 // Turn index into actual attributes.
2917 if (spell_hlf != HLF_COUNT)
2918 spell_attr = highlight_attr[spell_hlf];
2919
Luuk van Baal30805a12023-05-27 22:22:10 +01002920 if (spv->spv_cap_col > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002921 {
2922 if (p != prev_ptr
Luuk van Baal30805a12023-05-27 22:22:10 +01002923 && (p - nextline) + spv->spv_cap_col
2924 >= nextline_idx)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002925 {
2926 // Remember that the word in the next line
2927 // must start with a capital.
Luuk van Baal30805a12023-05-27 22:22:10 +01002928 spv->spv_capcol_lnum = lnum + 1;
2929 spv->spv_cap_col = ((p - nextline)
2930 + spv->spv_cap_col - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002931 }
2932 else
2933 // Compute the actual column.
Luuk van Baal30805a12023-05-27 22:22:10 +01002934 spv->spv_cap_col += (prev_ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002935 }
2936 }
2937 }
2938 if (spell_attr != 0)
2939 {
2940 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002941 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2942 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002943 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002944 wlv.char_attr = hl_combine_attr(spell_attr,
2945 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002946 }
2947#endif
2948#ifdef FEAT_LINEBREAK
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02002949 // we don't want linebreak to apply for lines that start with
2950 // leading spaces, followed by long letters (since it would add
2951 // a break at the beginning of a line and this might be unexpected)
2952 //
2953 // So only allow to linebreak, once we have found chars not in
2954 // 'breakat' in the line.
2955 if ( wp->w_p_lbr && !wlv.need_lbr && c != NUL &&
2956 !VIM_ISBREAK((int)*ptr))
2957 wlv.need_lbr = TRUE;
2958#endif
2959#ifdef FEAT_LINEBREAK
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002960 // Found last space before word: check for line break.
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02002961 if (wp->w_p_lbr && c0 == c && wlv.need_lbr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002962 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2963 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002964 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2965 : 0;
2966 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002967 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002968
zeertzjqce53e3e2023-09-01 18:49:30 +02002969 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol
2970# ifdef FEAT_PROP_POPUP
2971 - vcol_first_char,
2972# endif
2973 line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002974# ifdef FEAT_PROP_POPUP
2975 // do not want virtual text counted here
2976 cts.cts_has_prop_with_text = FALSE;
2977# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002978 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002979 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002980
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002981 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002982 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002983 // line break, but for TABs the highlighting should
2984 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002985 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002986
Bram Moolenaar1306b362022-08-06 15:59:06 +01002987 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002988# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002989 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002990 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002991 wp->w_buffer->b_p_vts_array) - 1;
2992# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002993 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002994 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002995# endif
2996
Bram Moolenaar1306b362022-08-06 15:59:06 +01002997 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2998 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002999# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01003000 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00003001 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00003002# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003003 if (VIM_ISWHITE(c))
3004 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01003005# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003006 if (c == TAB)
3007 // See "Tab alignment" below.
3008 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01003009# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003010 if (!wp->w_p_list)
3011 c = ' ';
3012 }
3013 }
3014#endif
zeertzjqabc80812023-09-24 23:32:18 +02003015 if (wp->w_p_list)
3016 {
3017 in_multispace = c == ' ' && (*ptr == ' '
3018 || (prev_ptr > line && prev_ptr[-1] == ' '));
3019 if (!in_multispace)
3020 multispace_pos = 0;
3021 }
zeertzjqf14b8ba2021-09-10 16:58:30 +02003022
Bram Moolenaareed9d462021-02-15 20:38:25 +01003023 // 'list': Change char 160 to 'nbsp' and space to 'space'
3024 // setting in 'listchars'. But not when the character is
3025 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003026 if (wp->w_p_list
3027 && ((((c == 160 && mb_l == 1)
3028 || (mb_utf8
3029 && ((mb_c == 160 && mb_l == 2)
3030 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01003031 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003032 || (c == ' '
3033 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02003034 && (wp->w_lcs_chars.space
3035 || (in_multispace
3036 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01003037 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003038 && ptr - line <= trailcol)))
3039 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02003040 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
3041 {
3042 c = wp->w_lcs_chars.multispace[multispace_pos++];
3043 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
3044 multispace_pos = 0;
3045 }
3046 else
3047 c = (c == ' ') ? wp->w_lcs_chars.space
3048 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003049 if (area_attr == 0 && search_attr == 0)
3050 {
3051 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003052 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003053 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003054 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003055 }
3056 mb_c = c;
3057 if (enc_utf8 && utf_char2len(c) > 1)
3058 {
3059 mb_utf8 = TRUE;
3060 u8cc[0] = 0;
3061 c = 0xc0;
3062 }
3063 else
3064 mb_utf8 = FALSE;
3065 }
3066
zeertzjq2e7cba32022-06-10 15:30:32 +01003067 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
3068 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003069 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003070 if (leadcol != 0 && in_multispace && ptr < line + leadcol
3071 && wp->w_lcs_chars.leadmultispace != NULL)
3072 {
3073 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01003074 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
3075 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003076 multispace_pos = 0;
3077 }
3078
3079 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
3080 c = wp->w_lcs_chars.trail;
3081
3082 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
3083 c = wp->w_lcs_chars.lead;
3084
zeertzjq2e7cba32022-06-10 15:30:32 +01003085 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003086 c = wp->w_lcs_chars.space;
3087
3088
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003089 if (!attr_pri)
3090 {
3091 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003092 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003093 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003094 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003095 }
3096 mb_c = c;
3097 if (enc_utf8 && utf_char2len(c) > 1)
3098 {
3099 mb_utf8 = TRUE;
3100 u8cc[0] = 0;
3101 c = 0xc0;
3102 }
3103 else
3104 mb_utf8 = FALSE;
3105 }
3106 }
3107
3108 // Handling of non-printable characters.
3109 if (!vim_isprintc(c))
3110 {
3111 // when getting a character from the file, we may have to
3112 // turn it into something else on the way to putting it
3113 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01003114 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003115 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003116 int tab_len = 0;
3117 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003118#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003119 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01003120
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003121 // only adjust the tab_len, when at the first column
3122 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01003123 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003124 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003125#endif
3126 // tab amount depends on current column
3127#ifdef FEAT_VARTABS
3128 tab_len = tabstop_padding(vcol_adjusted,
3129 wp->w_buffer->b_p_ts,
3130 wp->w_buffer->b_p_vts_array) - 1;
3131#else
3132 tab_len = (int)wp->w_buffer->b_p_ts
3133 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
3134#endif
3135
3136#ifdef FEAT_LINEBREAK
3137 if (!wp->w_p_lbr || !wp->w_p_list)
3138#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003139 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003140 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01003141 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003142 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003143#ifdef FEAT_LINEBREAK
3144 else
3145 {
3146 char_u *p;
3147 int len;
3148 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003149 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003150
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003151# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003152 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003153 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003154 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003155
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003156 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003157 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003158 && old_boguscols > 0
3159 && wlv.n_extra > tab_len)
3160 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003161# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003162 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003163 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003164 // If wlv.n_extra > 0, it gives the number of chars
3165 // to use for a tab, else we need to calculate the
3166 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003167 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3168 len = tab_len * tab2_len;
3169 if (wp->w_lcs_chars.tab3)
3170 len += mb_char2len(wp->w_lcs_chars.tab3)
3171 - tab2_len;
3172 if (wlv.n_extra > 0)
3173 len += wlv.n_extra - tab_len;
3174 c = wp->w_lcs_chars.tab1;
3175 p = alloc(len + 1);
3176 if (p == NULL)
3177 wlv.n_extra = 0;
3178 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003179 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003180 vim_memset(p, ' ', len);
3181 p[len] = NUL;
3182 vim_free(wlv.p_extra_free);
3183 wlv.p_extra_free = p;
3184 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003185 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003186 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003187
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003188 if (*p == NUL)
3189 {
3190 tab_len = i;
3191 break;
3192 }
3193
3194 // if tab3 is given, use it for the last
3195 // char
3196 if (wp->w_lcs_chars.tab3
3197 && i == tab_len - 1)
3198 lcs = wp->w_lcs_chars.tab3;
3199 p += mb_char2bytes(lcs, p);
3200 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003201 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003202 }
3203 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003204# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003205 // n_extra will be increased by
3206 // FIX_FOX_BOGUSCOLS macro below, so need to
3207 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003208 if (wlv.vcol_off_co > 0)
3209 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003210# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003211 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003212 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003213 }
3214#endif
3215#ifdef FEAT_CONCEAL
3216 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003217 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003218
3219 // Tab alignment should be identical regardless of
3220 // 'conceallevel' value. So tab compensates of all
3221 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003222 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003223 // line. Note that the tab can be longer than
3224 // 'tabstop' when there are concealed characters.
3225 FIX_FOR_BOGUSCOLS;
3226
3227 // Make sure, the highlighting for the tab char will be
3228 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003229 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003230 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003231 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003232 tab_len += vc_saved;
3233 }
3234#endif
3235 mb_utf8 = FALSE; // don't draw as UTF-8
3236 if (wp->w_p_list)
3237 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003238 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003239 ? wp->w_lcs_chars.tab3
3240 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003241#ifdef FEAT_LINEBREAK
h-east194555c2023-03-02 18:49:09 +00003242 if (wp->w_p_lbr && wlv.p_extra != NULL
3243 && *wlv.p_extra != NUL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003244 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003245 else
3246#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003247 wlv.c_extra = wp->w_lcs_chars.tab2;
3248 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003249 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003250 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003251 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003252 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003253 mb_c = c;
3254 if (enc_utf8 && utf_char2len(c) > 1)
3255 {
3256 mb_utf8 = TRUE;
3257 u8cc[0] = 0;
3258 c = 0xc0;
3259 }
3260 }
3261 else
3262 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003263 wlv.c_final = NUL;
3264 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003265 c = ' ';
3266 }
3267 }
3268 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003269 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003270 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003271 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3272 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003273 && VIsual_mode != Ctrl_V
3274 && (
3275# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003276 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003277# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003278 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003279 && !(noinvcur
3280 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003281 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003282 && lcs_eol_one > 0)
3283 {
3284 // Display a '$' after the line or highlight an extra
3285 // character if the line break is included.
3286#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3287 // For a diff line the highlighting continues after the
3288 // "$".
3289 if (
3290# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003291 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003292# ifdef LINE_ATTR
3293 &&
3294# endif
3295# endif
3296# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003297 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003298# endif
3299 )
3300#endif
3301 {
3302 // In virtualedit, visual selections may extend
3303 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003304 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003305 && wlv.tocol != MAXCOL
3306 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003307 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003308 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003309 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003310 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3311 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003312 else
3313 c = ' ';
3314 lcs_eol_one = -1;
3315 --ptr; // put it back at the NUL
3316 if (!attr_pri)
3317 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003318 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003319 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003320 n_attr = 1;
3321 }
3322 mb_c = c;
3323 if (enc_utf8 && utf_char2len(c) > 1)
3324 {
3325 mb_utf8 = TRUE;
3326 u8cc[0] = 0;
3327 c = 0xc0;
3328 }
3329 else
3330 mb_utf8 = FALSE; // don't draw as UTF-8
3331 }
3332 else if (c != NUL)
3333 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003334 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3335 if (wlv.n_extra == 0)
3336 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003337#ifdef FEAT_RIGHTLEFT
3338 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003339 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003340#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003341 wlv.c_extra = NUL;
3342 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003343#ifdef FEAT_LINEBREAK
3344 if (wp->w_p_lbr)
3345 {
3346 char_u *p;
3347
Bram Moolenaar1306b362022-08-06 15:59:06 +01003348 c = *wlv.p_extra;
3349 p = alloc(wlv.n_extra + 1);
3350 vim_memset(p, ' ', wlv.n_extra);
3351 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3352 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003353 vim_free(wlv.p_extra_free);
3354 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003355 }
3356 else
3357#endif
3358 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003359 wlv.n_extra = byte2cells(c) - 1;
3360 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003361 }
3362 if (!attr_pri)
3363 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003364 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003365 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003366 HL_ATTR(HLF_8));
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003367#ifdef FEAT_PROP_POPUP
3368 if (text_prop_type != NULL &&
3369 text_prop_flags & PT_FLAG_OVERRIDE)
3370 wlv.extra_attr = hl_combine_attr(text_prop_attr, wlv.extra_attr);
3371#endif
3372
Bram Moolenaar1306b362022-08-06 15:59:06 +01003373 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003374 }
3375 mb_utf8 = FALSE; // don't draw as UTF-8
3376 }
3377 else if (VIsual_active
3378 && (VIsual_mode == Ctrl_V
3379 || VIsual_mode == 'v')
3380 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003381 && wlv.tocol != MAXCOL
3382 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003383 && (
3384#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003385 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003386#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003387 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003388 {
3389 c = ' ';
3390 --ptr; // put it back at the NUL
3391 }
3392#if defined(LINE_ATTR)
3393 else if ((
3394# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003395 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003396# endif
3397# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003398 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003399# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003400 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003401 ) && (
3402# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003403 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003404# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003405 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003406# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003407 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003408# endif
3409 < wp->w_width)))
3410 {
3411 // Highlight until the right side of the window
3412 c = ' ';
3413 --ptr; // put it back at the NUL
3414
3415 // Remember we do the char for line highlighting.
3416 ++did_line_attr;
3417
3418 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003419 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003420 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003421 || (wp->w_p_list &&
3422 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003423 wlv.char_attr = wlv.line_attr;
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003424#ifdef FEAT_SIGNS
3425 // At end of line: if Sign is present with line highlight, reset char_attr
Christian Brabandte1eaae22023-08-19 22:36:12 +02003426 // but not when cursorline is active
3427 if (sign_present && wlv.sattr.sat_linehl > 0 && wlv.draw_state == WL_LINE
3428 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum))
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003429 wlv.char_attr = wlv.sattr.sat_linehl;
3430#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003431# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003432 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003433 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003434 wlv.diff_hlf = HLF_CHD;
3435 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003436 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003437 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003438 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3439 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003440 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003441 || (wlv.vcol >= left_curline_col
3442 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003443 wlv.char_attr = hl_combine_attr(
3444 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003445 }
3446 }
3447# endif
3448# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003449 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003450 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003451 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003452 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3453 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003454 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003455 if (!wlv.cul_screenline
3456 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003457 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003458 wlv.char_attr = hl_combine_attr(
3459 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003460 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003461 else if (wlv.line_attr)
3462 wlv.char_attr = hl_combine_attr(
3463 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003464 }
3465# endif
3466 }
3467#endif
3468 }
3469
3470#ifdef FEAT_CONCEAL
3471 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003472 && (wp != curwin || lnum != wp->w_cursor.lnum
3473 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003474 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3475 && !(lnum_in_visual_area
3476 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3477 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003478 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003479 if (((prev_syntax_id != syntax_seqnr
3480 && (syntax_flags & HL_CONCEAL) != 0)
3481 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003482 && (syn_get_sub_char() != NUL
3483 || (has_match_conc && match_conc)
3484 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003485 && wp->w_p_cole != 3)
3486 {
3487 // First time at this concealed item: display one
3488 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003489 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003490 c = match_conc;
3491 else if (syn_get_sub_char() != NUL)
3492 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003493 else if (wp->w_lcs_chars.conceal != NUL)
3494 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003495 else
3496 c = ' ';
3497
3498 prev_syntax_id = syntax_seqnr;
3499
Bram Moolenaar1306b362022-08-06 15:59:06 +01003500 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003501 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003502 wlv.vcol += wlv.n_extra;
3503 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003504 {
3505# ifdef FEAT_RIGHTLEFT
3506 if (wp->w_p_rl)
3507 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003508 wlv.col -= wlv.n_extra;
3509 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003510 }
3511 else
3512# endif
3513 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003514 wlv.boguscols += wlv.n_extra;
3515 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003516 }
3517 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003518 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003519 n_attr = 0;
3520 }
zeertzjqb557f482023-08-22 22:07:34 +02003521 else if (skip_cells == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003522 {
3523 is_concealing = TRUE;
zeertzjqb557f482023-08-22 22:07:34 +02003524 skip_cells = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003525 }
3526 mb_c = c;
3527 if (enc_utf8 && utf_char2len(c) > 1)
3528 {
3529 mb_utf8 = TRUE;
3530 u8cc[0] = 0;
3531 c = 0xc0;
3532 }
3533 else
3534 mb_utf8 = FALSE; // don't draw as UTF-8
3535 }
3536 else
3537 {
3538 prev_syntax_id = 0;
3539 is_concealing = FALSE;
3540 }
3541
zeertzjqb557f482023-08-22 22:07:34 +02003542 if (skip_cells > 0 && did_decrement_ptr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003543 // not showing the '>', put pointer back to avoid getting stuck
3544 ++ptr;
3545
3546#endif // FEAT_CONCEAL
3547 }
3548
3549#ifdef FEAT_CONCEAL
3550 // In the cursor line and we may be concealing characters: correct
3551 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003552 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003553 && wp == curwin && lnum == wp->w_cursor.lnum
3554 && conceal_cursor_line(wp)
zeertzjqb557f482023-08-22 22:07:34 +02003555 && (int)wp->w_virtcol <= wlv.vcol + skip_cells)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003556 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003557# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003558 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003559 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003560 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003561# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003562 wp->w_wcol = wlv.col - wlv.boguscols;
3563 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003564 did_wcol = TRUE;
3565 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003566# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003567 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003568# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003569 }
3570#endif
3571
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003572 // Use "wlv.extra_attr", but don't override visual selection
3573 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003574 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3575 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003576 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003577 && (!attr_pri
3578#ifdef FEAT_PROP_POPUP
3579 || (text_prop_flags & PT_FLAG_OVERRIDE)
3580#endif
3581 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003582 {
3583#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003584 if (wlv.line_attr)
3585 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003586 else
3587#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003588 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003589#ifdef FEAT_PROP_POPUP
3590 if (reset_extra_attr)
3591 {
3592 reset_extra_attr = FALSE;
3593 wlv.extra_attr = 0;
3594 }
3595#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003596 }
3597
3598#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3599 // XIM don't send preedit_start and preedit_end, but they send
3600 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3601 // im_is_preediting() here.
3602 if (p_imst == IM_ON_THE_SPOT
3603 && xic != NULL
3604 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003605 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003606 && !p_imdisable
3607 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003608 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003609 {
3610 colnr_T tcol;
3611
3612 if (preedit_end_col == MAXCOL)
3613 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3614 else
3615 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003616 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003617 {
3618 if (feedback_old_attr < 0)
3619 {
3620 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003621 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003622 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003623 wlv.char_attr = im_get_feedback_attr(feedback_col);
3624 if (wlv.char_attr < 0)
3625 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003626 feedback_col++;
3627 }
3628 else if (feedback_old_attr >= 0)
3629 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003630 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003631 feedback_old_attr = -1;
3632 feedback_col = 0;
3633 }
3634 }
3635#endif
3636 // Handle the case where we are in column 0 but not on the first
3637 // character of the line and the user wants us to show us a
3638 // special character (via 'listchars' option "precedes:<char>".
3639 if (lcs_prec_todo != NUL
3640 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003641 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3642 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003643#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003644 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003645#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003646 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003647 && c != NUL)
3648 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003649 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003650 lcs_prec_todo = NUL;
3651 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3652 {
3653 // Double-width character being overwritten by the "precedes"
3654 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003655 wlv.c_extra = MB_FILLER_CHAR;
3656 wlv.c_final = NUL;
3657 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003658 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003659 wlv.extra_attr =
3660 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003661 }
3662 mb_c = c;
3663 if (enc_utf8 && utf_char2len(c) > 1)
3664 {
3665 mb_utf8 = TRUE;
3666 u8cc[0] = 0;
3667 c = 0xc0;
3668 }
3669 else
3670 mb_utf8 = FALSE; // don't draw as UTF-8
3671 if (!attr_pri)
3672 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003673 saved_attr3 = wlv.char_attr; // save current attr
3674 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003675 n_attr3 = 1;
3676 }
3677 }
3678
3679 // At end of the text line or just after the last character.
3680 if ((c == NUL
3681#if defined(LINE_ATTR)
3682 || did_line_attr == 1
3683#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003684 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003685 {
3686#ifdef FEAT_SEARCH_EXTRA
3687 // flag to indicate whether prevcol equals startcol of search_hl or
3688 // one of the matches
3689 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3690 (long)(ptr - line) - (c == NUL));
3691#endif
3692 // Invert at least one char, used for Visual and empty line or
3693 // highlight match at end of line. If it's beyond the last
3694 // char on the screen, just overwrite that one (tricky!) Not
3695 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003696 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003697 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003698 && (VIsual_mode != Ctrl_V
3699 || lnum == VIsual.lnum
3700 || lnum == curwin->w_cursor.lnum)
3701 && c == NUL)
3702#ifdef FEAT_SEARCH_EXTRA
3703 // highlight 'hlsearch' match at end of line
3704 || (prevcol_hl_flag
3705# ifdef FEAT_SYN_HL
3706 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3707 && !(wp == curwin && VIsual_active))
3708# endif
3709# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003710 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003711# endif
3712# if defined(LINE_ATTR)
3713 && did_line_attr <= 1
3714# endif
3715 )
3716#endif
3717 ))
3718 {
3719 int n = 0;
3720
3721#ifdef FEAT_RIGHTLEFT
3722 if (wp->w_p_rl)
3723 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003724 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003725 n = 1;
3726 }
3727 else
3728#endif
3729 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003730 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003731 n = -1;
3732 }
3733 if (n != 0)
3734 {
3735 // At the window boundary, highlight the last character
3736 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003737 wlv.off += n;
3738 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003739 }
3740 else
3741 {
3742 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003743 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003744 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003745 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003746 }
3747#ifdef FEAT_SEARCH_EXTRA
3748 if (area_attr == 0)
3749 {
3750 // Use attributes from match with highest priority among
3751 // 'search_hl' and the match list.
3752 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003753 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003754 }
3755#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003756 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003757 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003758#ifdef FEAT_RIGHTLEFT
3759 if (wp->w_p_rl)
3760 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003761 --wlv.col;
3762 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003763 }
3764 else
3765#endif
3766 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003767 ++wlv.col;
3768 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003769 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003770 ++wlv.vcol;
3771 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003772 }
3773 }
3774
3775 // At end of the text line.
3776 if (c == NUL)
3777 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003778#ifdef FEAT_PROP_POPUP
3779 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003780 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003781 // Put the pointer back to the NUL.
3782 --ptr;
3783 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003784 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003785 else
3786#endif
3787 {
3788 draw_screen_line(wp, &wlv);
3789
3790 // Update w_cline_height and w_cline_folded if the cursor line
3791 // was updated (saves a call to plines() later).
3792 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3793 {
3794 curwin->w_cline_row = startrow;
3795 curwin->w_cline_height = wlv.row - startrow;
3796#ifdef FEAT_FOLDING
3797 curwin->w_cline_folded = FALSE;
3798#endif
3799 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3800 }
3801 break;
3802 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003803 }
3804
3805 // Show "extends" character from 'listchars' if beyond the line end and
3806 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003807 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003808 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003809 && wp->w_p_list
3810 && !wp->w_p_wrap
3811#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003812 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003813#endif
3814 && (
3815#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003816 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003817#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003818 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003819 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003820 || lcs_eol_one > 0
3821 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
zeertzjq6a389722023-08-27 19:04:14 +02003822 || *wlv.p_extra != NUL))
3823#ifdef FEAT_PROP_POPUP
zeertzjq4e26a9a2023-12-03 17:50:47 +01003824 || text_prop_next <= last_textprop_text_idx
zeertzjq6a389722023-08-27 19:04:14 +02003825#endif
3826 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003827 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003828 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003829 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003830 mb_c = c;
3831 if (enc_utf8 && utf_char2len(c) > 1)
3832 {
3833 mb_utf8 = TRUE;
3834 u8cc[0] = 0;
3835 c = 0xc0;
3836 }
3837 else
3838 mb_utf8 = FALSE;
3839 }
3840
3841#ifdef FEAT_SYN_HL
3842 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003843 if (wlv.draw_color_col)
3844 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003845
3846 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3847 // highlight the cursor position itself.
3848 // Also highlight the 'colorcolumn' if it is different than
3849 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003850 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3851 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003852 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003853 if (((wlv.draw_state == WL_LINE
3854 || wlv.draw_state == WL_BRI
3855 || wlv.draw_state == WL_SBR)
3856 && !lnum_in_visual_area
3857 && search_attr == 0
3858 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003859# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003860 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003861# endif
3862 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003863 {
3864 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3865 && lnum != wp->w_cursor.lnum)
3866 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003867 vcol_save_attr = wlv.char_attr;
3868 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3869 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003870 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003871 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003872 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003873 vcol_save_attr = wlv.char_attr;
3874 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003875 }
3876 }
3877#endif
3878
zeertzjq8fc6a1d2023-08-20 18:12:54 +02003879 if (wlv.draw_state == WL_LINE)
3880 vcol_prev = wlv.vcol;
3881
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003882 // Store character to be displayed.
3883 // Skip characters that are left of the screen for 'nowrap'.
zeertzjqb557f482023-08-22 22:07:34 +02003884 if (wlv.draw_state < WL_LINE || skip_cells <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003885 {
3886 // Store the character.
3887#if defined(FEAT_RIGHTLEFT)
3888 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3889 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003890 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003891 --wlv.off;
3892 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003893 }
3894#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003895 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003896 if (enc_dbcs == DBCS_JPNU)
3897 {
3898 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003899 ScreenLines[wlv.off] = 0x8e;
3900 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003901 }
3902 else if (enc_utf8)
3903 {
3904 if (mb_utf8)
3905 {
3906 int i;
3907
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003908 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003909 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003910 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003911 for (i = 0; i < Screen_mco; ++i)
3912 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003913 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003914 if (u8cc[i] == 0)
3915 break;
3916 }
3917 }
3918 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003919 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003920 }
3921 if (multi_attr)
3922 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003923 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003924 multi_attr = 0;
3925 }
3926 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003927 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003928
zeertzjqdb54e982023-09-21 16:33:09 +02003929 if (wlv.draw_state > WL_NR
3930#ifdef FEAT_DIFF
3931 && wlv.filler_todo <= 0
3932#endif
3933 )
3934 ScreenCols[wlv.off] = wlv.vcol;
3935 else
3936 ScreenCols[wlv.off] = -1;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003937
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003938 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3939 {
3940 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003941 ++wlv.off;
3942 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003943 if (enc_utf8)
3944 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003945 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003946 else
3947 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003948 ScreenLines[wlv.off] = mb_c & 0xff;
zeertzjqdb54e982023-09-21 16:33:09 +02003949
Bram Moolenaar1306b362022-08-06 15:59:06 +01003950 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003951#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003952 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003953#endif
3954 )
zeertzjqdb54e982023-09-21 16:33:09 +02003955 ScreenCols[wlv.off] = ++wlv.vcol;
3956 else
3957 ScreenCols[wlv.off] = -1;
3958
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003959 // When "wlv.tocol" is halfway a character, set it to the end
3960 // of the character, otherwise highlighting won't stop.
3961 if (wlv.tocol == wlv.vcol)
3962 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003963
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003964#ifdef FEAT_RIGHTLEFT
3965 if (wp->w_p_rl)
3966 {
3967 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003968 --wlv.off;
3969 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003970 }
3971#endif
3972 }
3973#ifdef FEAT_RIGHTLEFT
3974 if (wp->w_p_rl)
3975 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003976 --wlv.off;
3977 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003978 }
3979 else
3980#endif
3981 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003982 ++wlv.off;
3983 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003984 }
3985 }
3986#ifdef FEAT_CONCEAL
3987 else if (wp->w_p_cole > 0 && is_concealing)
3988 {
zeertzjqb557f482023-08-22 22:07:34 +02003989 --skip_cells;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003990 ++wlv.vcol_off_co;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003991 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003992 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003993 if (wp->w_p_wrap)
3994 {
3995 // Special voodoo required if 'wrap' is on.
3996 //
3997 // Advance the column indicator to force the line
3998 // drawing to wrap early. This will make the line
3999 // take up the same screen space when parts are concealed,
4000 // so that cursor line computations aren't messed up.
4001 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004002 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004003 // trailing junk to be written out of the screen line
4004 // we are building, 'boguscols' keeps track of the number
4005 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004006 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004007 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004008 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004009# ifdef FEAT_RIGHTLEFT
4010 if (wp->w_p_rl)
4011 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004012 wlv.col -= wlv.n_extra;
4013 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004014 }
4015 else
4016# endif
4017 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004018 wlv.col += wlv.n_extra;
4019 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004020 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01004021 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004022 n_attr = 0;
4023 }
4024
4025
4026 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
4027 {
4028 // Need to fill two screen columns.
4029# ifdef FEAT_RIGHTLEFT
4030 if (wp->w_p_rl)
4031 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004032 --wlv.boguscols;
4033 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004034 }
4035 else
4036# endif
4037 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004038 ++wlv.boguscols;
4039 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004040 }
4041 }
4042
4043# ifdef FEAT_RIGHTLEFT
4044 if (wp->w_p_rl)
4045 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004046 --wlv.boguscols;
4047 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004048 }
4049 else
4050# endif
4051 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004052 ++wlv.boguscols;
4053 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004054 }
4055 }
4056 else
4057 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004058 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004059 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004060 wlv.vcol += wlv.n_extra;
4061 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004062 n_attr = 0;
4063 }
4064 }
4065
4066 }
4067#endif // FEAT_CONCEAL
4068 else
zeertzjqb557f482023-08-22 22:07:34 +02004069 --skip_cells;
4070
4071 if (wlv.draw_state > WL_NR && skipped_cells > 0)
4072 {
4073 wlv.vcol += skipped_cells;
4074 skipped_cells = 0;
4075 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004076
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004077 // Only advance the "wlv.vcol" when after the 'number' or
4078 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004079 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004080#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004081 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004082#endif
4083 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004084 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004085
4086#ifdef FEAT_SYN_HL
4087 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004088 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004089#endif
4090
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004091 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01004092 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
4093 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004094
4095 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01004096 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004097 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004098 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004099 if (wlv.n_attr_skip > 0)
4100 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004101
4102 // At end of screen line and there is more to come: Display the line
4103 // so far. If there is no more to display it is caught above.
4104 if ((
4105#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004106 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004107#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004108 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01004109 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02004110 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004111#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004112 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004113#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004114#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004115 || text_prop_above || text_prop_follows
zeertzjq4e26a9a2023-12-03 17:50:47 +01004116 || text_prop_next <= last_textprop_text_idx
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004117#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01004118 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01004119 && wlv.p_extra != at_end_str)
4120 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
4121 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004122 )
4123 {
4124#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01004125 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01004126 wlv_screen_line(wp, &wlv, FALSE);
4127 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004128 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004129 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004130#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01004131 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004132#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004133 ++wlv.row;
4134 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004135
4136 // When not wrapping and finished diff lines, or when displayed
4137 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01004138 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004139#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004140 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004141#endif
4142#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01004143 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004144#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01004145 ) || lcs_eol_one == -1)
4146#ifdef FEAT_PROP_POPUP
4147 && !text_prop_follows
4148#endif
4149 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004150 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004151#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004152 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004153 {
4154 // do not output more of the line, only the "below" prop
4155 ptr += STRLEN(ptr);
4156# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004157 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004158# endif
4159 }
4160#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004161
4162 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004163 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004164#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004165 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004166#endif
4167 )
4168 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004169 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
4170 draw_vsep_win(wp, wlv.row);
4171 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004172 }
4173
4174 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004175 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004176 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004177 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004178 break;
4179 }
4180
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004181 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004182#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004183 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004184#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004185#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004186 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004187#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004188 && wp->w_width == Columns)
4189 {
4190 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004191 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004192
4193 // Special trick to make copy/paste of wrapped lines work with
4194 // xterm/screen: write an extra character beyond the end of
4195 // the line. This will work with all terminal types
4196 // (regardless of the xn,am settings).
4197 // Only do this on a fast tty.
4198 // Only do this if the cursor is on the current line
4199 // (something has been written in it).
4200 // Don't do this for the GUI.
4201 // Don't do this for double-width characters.
4202 // Don't do this for a window not at the right screen border.
4203 if (p_tf
4204#ifdef FEAT_GUI
4205 && !gui.in_use
4206#endif
4207 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004208 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4209 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004210 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004211 || (*mb_off2cells)(
4212 LineOffset[wlv.screen_row - 1]
4213 + (int)Columns - 2,
4214 LineOffset[wlv.screen_row]
4215 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004216 {
4217 // First make sure we are at the end of the screen line,
4218 // then output the same character again to let the
4219 // terminal know about the wrap. If the terminal doesn't
4220 // auto-wrap, we overwrite the character.
4221 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004222 screen_char(LineOffset[wlv.screen_row - 1]
4223 + (unsigned)Columns - 1,
4224 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004225
4226 // When there is a multi-byte character, just output a
4227 // space to keep it simple.
4228 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004229 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004230 out_char(' ');
4231 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004232 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004233 + (Columns - 1)]);
4234 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004235 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004236 screen_start(); // don't know where cursor is now
4237 }
4238 }
4239
Bram Moolenaar1306b362022-08-06 15:59:06 +01004240 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004241
Bram Moolenaareed9d462021-02-15 20:38:25 +01004242 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004243#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004244 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004245# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004246 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004247# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004248 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004249 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004250#endif
4251#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004252 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004253 // When the filler lines are actually below the last line of the
4254 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004255 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004256 break;
4257#endif
4258 }
4259
4260 } // for every character in the line
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004261#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004262 vim_free(text_props);
4263 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004264 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004265#endif
4266
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004267 vim_free(wlv.p_extra_free);
zeertzjq58e1e012023-06-04 18:46:28 +01004268 vim_free(wlv.saved_p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004269 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004270}