blob: 629d66f1c20e50039717536b16a94f45d0ec0cb4 [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 Moolenaareed9d462021-02-15 20:38:25 +01001124 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001125 int lcs_prec_todo = wp->w_lcs_chars.prec;
1126 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001127
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001128 int n_attr = 0; // chars with special attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001129 int saved_attr2 = 0; // char_attr saved for n_attr
1130 int n_attr3 = 0; // chars with overruling special attr
1131 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001132
zeertzjqb557f482023-08-22 22:07:34 +02001133 int skip_cells = 0; // nr of cells to skip for w_leftcol or
1134 // w_skipcol or concealing
1135 int skipped_cells = 0; // nr of skipped cells for virtual text
1136 // to be added to wlv.vcol later
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001137 int fromcol_prev = -2; // start of inverting after cursor
1138 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001139 int lnum_in_visual_area = FALSE;
1140 pos_T pos;
1141 long v;
1142
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001143 int attr_pri = FALSE; // char_attr has priority
1144 int area_highlighting = FALSE; // Visual or incsearch highlighting
1145 // in this line
1146 int vi_attr = 0; // attributes for Visual and incsearch
1147 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001148 int area_attr = 0; // attributes desired by highlighting
1149 int search_attr = 0; // attributes desired by 'hlsearch'
1150#ifdef FEAT_SYN_HL
1151 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1152 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001153 int prev_syntax_col = -1; // column of prev_syntax_attr
1154 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001155 int has_syntax = FALSE; // this buffer has syntax highl.
1156 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001157#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001158#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001159 int did_line = FALSE; // set to TRUE when line text done
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001160 int text_prop_count;
zeertzjq4e26a9a2023-12-03 17:50:47 +01001161 int last_textprop_text_idx = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001162 int text_prop_next = 0; // next text property to use
1163 textprop_T *text_props = NULL;
1164 int *text_prop_idxs = NULL;
1165 int text_props_active = 0;
1166 proptype_T *text_prop_type = NULL;
1167 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001168 int text_prop_attr_comb = 0; // text_prop_attr combined with
1169 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001170 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001171 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001172 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001173 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001174 int saved_search_attr = 0; // search_attr to be used when n_extra
1175 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001176 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001177 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001178#endif
1179#ifdef FEAT_SPELL
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001180 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001181# define SPWORDLEN 150
1182 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1183 int nextlinecol = 0; // column where nextline[] starts
1184 int nextline_idx = 0; // index in nextline[] where next line
1185 // starts
1186 int spell_attr = 0; // attributes desired by spelling
1187 int word_end = 0; // last byte with same spell_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001188 int cur_checked_col = 0; // checked column for current line
1189#endif
1190 int extra_check = 0; // has extra highlighting
1191 int multi_attr = 0; // attributes desired by multibyte
1192 int mb_l = 1; // multi-byte byte length
1193 int mb_c = 0; // decoded multi-byte character
1194 int mb_utf8 = FALSE; // screen char is UTF-8 char
1195 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001196#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001197 int change_start = MAXCOL; // first col of changed area
1198 int change_end = -1; // last col of changed area
1199#endif
1200 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001201 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001202 int in_multispace = FALSE; // in multiple consecutive spaces
1203 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001204#ifdef LINE_ATTR
Bram Moolenaarbf915842022-08-06 22:38:02 +01001205 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001206#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001207 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001208 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001209#ifdef FEAT_ARABIC
1210 int prev_c = 0; // previous Arabic character
1211 int prev_c1 = 0; // first composing char for prev_c
1212#endif
1213#if defined(LINE_ATTR)
1214 int did_line_attr = 0;
1215#endif
1216#ifdef FEAT_TERMINAL
1217 int get_term_attr = FALSE;
1218#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001219
Martin Tournoijba43e762022-10-13 22:12:15 +01001220#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001221 // margin columns for the screen line, needed for when 'cursorlineopt'
1222 // contains "screenline"
1223 int left_curline_col = 0;
1224 int right_curline_col = 0;
1225#endif
1226
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001227#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1228 int feedback_col = 0;
1229 int feedback_old_attr = -1;
1230#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001231
1232#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1233 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001234#endif
1235#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001236 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001237#endif
1238#ifdef FEAT_CONCEAL
1239 int syntax_flags = 0;
1240 int syntax_seqnr = 0;
1241 int prev_syntax_id = 0;
1242 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1243 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001244 int did_wcol = FALSE;
1245 int old_boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001246# define VCOL_HLC (wlv.vcol - wlv.vcol_off_co - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001247# define FIX_FOR_BOGUSCOLS \
1248 { \
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001249 wlv.n_extra += wlv.vcol_off_co; \
1250 wlv.vcol -= wlv.vcol_off_co; \
1251 wlv.vcol_off_co = 0; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001252 wlv.col -= wlv.boguscols; \
1253 old_boguscols = wlv.boguscols; \
1254 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001255 }
1256#else
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001257# define VCOL_HLC (wlv.vcol - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001258#endif
1259
1260 if (startrow > endrow) // past the end already!
1261 return startrow;
1262
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001263 CLEAR_FIELD(wlv);
1264
1265 wlv.lnum = lnum;
1266 wlv.startrow = startrow;
1267 wlv.row = startrow;
1268 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001269 wlv.fromcol = -10;
1270 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001271#ifdef FEAT_LINEBREAK
1272 wlv.vcol_sbr = -1;
1273#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001274
zeertzjqebfd8562024-02-06 10:59:03 +01001275 if (number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001276 {
1277 // To speed up the loop below, set extra_check when there is linebreak,
1278 // trailing white space and/or syntax processing to be done.
1279#ifdef FEAT_LINEBREAK
1280 extra_check = wp->w_p_lbr;
1281#endif
1282#ifdef FEAT_SYN_HL
1283 if (syntax_present(wp) && !wp->w_s->b_syn_error
1284# ifdef SYN_TIME_LIMIT
1285 && !wp->w_s->b_syn_slow
1286# endif
1287 )
1288 {
1289 // Prepare for syntax highlighting in this line. When there is an
1290 // error, stop syntax highlighting.
1291 save_did_emsg = did_emsg;
1292 did_emsg = FALSE;
1293 syntax_start(wp, lnum);
1294 if (did_emsg)
1295 wp->w_s->b_syn_error = TRUE;
1296 else
1297 {
1298 did_emsg = save_did_emsg;
1299#ifdef SYN_TIME_LIMIT
1300 if (!wp->w_s->b_syn_slow)
1301#endif
1302 {
1303 has_syntax = TRUE;
1304 extra_check = TRUE;
1305 }
1306 }
1307 }
1308
1309 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001310 wlv.color_cols = wp->w_p_cc_cols;
1311 if (wlv.color_cols != NULL)
1312 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001313#endif
1314
1315#ifdef FEAT_TERMINAL
1316 if (term_show_buffer(wp->w_buffer))
1317 {
1318 extra_check = TRUE;
1319 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001320 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001321 }
1322#endif
1323
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001324 // handle Visual active in this window
1325 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1326 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001327 pos_T *top, *bot;
1328
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001329 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1330 {
1331 // Visual is after curwin->w_cursor
1332 top = &curwin->w_cursor;
1333 bot = &VIsual;
1334 }
1335 else
1336 {
1337 // Visual is before curwin->w_cursor
1338 top = &VIsual;
1339 bot = &curwin->w_cursor;
1340 }
1341 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1342 if (VIsual_mode == Ctrl_V)
1343 {
1344 // block mode
1345 if (lnum_in_visual_area)
1346 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001347 wlv.fromcol = wp->w_old_cursor_fcol;
1348 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001349 }
1350 }
1351 else
1352 {
1353 // non-block mode
1354 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001355 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001356 else if (lnum == top->lnum)
1357 {
1358 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001359 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001360 else
1361 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001362 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001363 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001364 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001365 }
1366 }
1367 if (VIsual_mode != 'V' && lnum == bot->lnum)
1368 {
1369 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1370 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001371 wlv.fromcol = -10;
1372 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001373 }
1374 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001375 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001376 else
1377 {
1378 pos = *bot;
1379 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001380 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1381 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001382 else
1383 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001384 getvvcol(wp, &pos, NULL, NULL,
1385 (colnr_T *)&wlv.tocol);
1386 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001387 }
1388 }
1389 }
1390 }
1391
1392 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001393 if (!highlight_match && lnum == curwin->w_cursor.lnum
1394 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001395#ifdef FEAT_GUI
1396 && !gui.in_use
1397#endif
1398 )
1399 noinvcur = TRUE;
1400
1401 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001402 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001403 {
1404 area_highlighting = TRUE;
1405 vi_attr = HL_ATTR(HLF_V);
1406#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1407 if ((clip_star.available && !clip_star.owned
1408 && clip_isautosel_star())
1409 || (clip_plus.available && !clip_plus.owned
1410 && clip_isautosel_plus()))
1411 vi_attr = HL_ATTR(HLF_VNC);
1412#endif
1413 }
1414 }
1415
1416 // handle 'incsearch' and ":s///c" highlighting
1417 else if (highlight_match
1418 && wp == curwin
1419 && lnum >= curwin->w_cursor.lnum
1420 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1421 {
1422 if (lnum == curwin->w_cursor.lnum)
1423 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001424 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001425 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001426 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001427 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1428 {
1429 pos.lnum = lnum;
1430 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001431 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001432 }
1433 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001434 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001435 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001436 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1437 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001438 area_highlighting = TRUE;
1439 vi_attr = HL_ATTR(HLF_I);
1440 }
1441 }
1442
1443#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001444 wlv.filler_lines = diff_check(wp, lnum);
1445 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001446 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001447 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001448 {
1449 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001450 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001451 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001452 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001453 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001454 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001455 }
1456 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001457 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001458 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001459 area_highlighting = TRUE;
1460 }
1461 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001462 wlv.filler_lines = wp->w_topfill;
1463 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001464#endif
1465
1466#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001467 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001468 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001469 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001470#endif
1471
1472#ifdef LINE_ATTR
1473# ifdef FEAT_SIGNS
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001474 // If this line has a sign with line highlighting set wlv.line_attr.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001475 if (sign_present)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001476 wlv.line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001477# endif
1478# if defined(FEAT_QUICKFIX)
1479 // Highlight the current line in the quickfix window.
1480 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001481 wlv.line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001482# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001483 if (wlv.line_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001484 area_highlighting = TRUE;
1485#endif
1486
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001487#ifdef FEAT_SPELL
zeertzjqebfd8562024-02-06 10:59:03 +01001488 if (spv->spv_has_spell && number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001489 {
Luuk van Baal30805a12023-05-27 22:22:10 +01001490 // Prepare for spell checking.
1491 extra_check = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001492
Luuk van Baal30805a12023-05-27 22:22:10 +01001493 // When a word wrapped from the previous line the start of the
1494 // current line is valid.
1495 if (lnum == spv->spv_checked_lnum)
1496 cur_checked_col = spv->spv_checked_col;
Luuk van Baale84c7732023-05-31 18:57:36 +01001497 // Previous line was not spell checked, check for capital. This happens
1498 // for the first line in an updated region or after a closed fold.
1499 if (spv->spv_capcol_lnum == 0 && check_need_cap(wp, lnum, 0))
1500 spv->spv_cap_col = 0;
1501 else if (lnum != spv->spv_capcol_lnum)
Luuk van Baal30805a12023-05-27 22:22:10 +01001502 spv->spv_cap_col = -1;
1503 spv->spv_checked_lnum = 0;
1504
Luuk van Baal30805a12023-05-27 22:22:10 +01001505 // Get the start of the next line, so that words that wrap to the
1506 // next line are found too: "et<line-break>al.".
1507 // Trick: skip a few chars for C/shell/Vim comments
1508 nextline[SPWORDLEN] = NUL;
1509 if (lnum < wp->w_buffer->b_ml.ml_line_count)
Luuk van Baale84c7732023-05-31 18:57:36 +01001510 {
1511 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1512 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1513 }
1514 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1515
1516 // If current line is empty, check first word in next line for capital.
1517 ptr = skipwhite(line);
1518 if (*ptr == NUL)
1519 {
1520 spv->spv_cap_col = 0;
1521 spv->spv_capcol_lnum = lnum + 1;
1522 }
1523 // For checking first word with a capital skip white space.
1524 else if (spv->spv_cap_col == 0)
1525 spv->spv_cap_col = ptr - line;
1526
Luuk van Baal30805a12023-05-27 22:22:10 +01001527 // Copy the end of the current line into nextline[].
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001528 if (nextline[SPWORDLEN] == NUL)
1529 {
1530 // No next line or it is empty.
1531 nextlinecol = MAXCOL;
1532 nextline_idx = 0;
1533 }
1534 else
1535 {
zeertzjq94b7c322024-03-12 21:50:32 +01001536 v = ml_get_buf_len(wp->w_buffer, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001537 if (v < SPWORDLEN)
1538 {
1539 // Short line, use it completely and append the start of the
1540 // next line.
1541 nextlinecol = 0;
1542 mch_memmove(nextline, line, (size_t)v);
1543 STRMOVE(nextline + v, nextline + SPWORDLEN);
1544 nextline_idx = v + 1;
1545 }
1546 else
1547 {
1548 // Long line, use only the last SPWORDLEN bytes.
1549 nextlinecol = v - SPWORDLEN;
1550 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1551 nextline_idx = SPWORDLEN + 1;
1552 }
1553 }
1554 }
1555#endif
1556
Luuk van Baale84c7732023-05-31 18:57:36 +01001557 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1558 ptr = line;
1559
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001560 if (wp->w_p_list)
1561 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001562 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001563 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001564 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001565 || wp->w_lcs_chars.trail
1566 || wp->w_lcs_chars.lead
1567 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001568 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001569
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001570 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001571 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001572 {
zeertzjq94b7c322024-03-12 21:50:32 +01001573 trailcol = ml_get_buf_len(wp->w_buffer, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001574 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1575 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001576 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001577 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001578 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001579 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001580 {
1581 leadcol = 0;
1582 while (VIM_ISWHITE(ptr[leadcol]))
1583 ++leadcol;
1584 if (ptr[leadcol] == NUL)
1585 // in a line full of spaces all of them are treated as trailing
1586 leadcol = (colnr_T)0;
1587 else
1588 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001589 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001590 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001591 }
1592
Bram Moolenaard7657e92022-09-20 18:59:30 +01001593 wlv.wcr_attr = get_wcr_attr(wp);
1594 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001595 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001596 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001597 area_highlighting = TRUE;
1598 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001599
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001600 // When w_skipcol is non-zero and there is virtual text above the actual
1601 // text, then this much of the virtual text is skipped.
1602 int skipcol_in_text_prop_above = 0;
1603
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001604#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001605 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001606 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001607
1608 char_u *prop_start;
1609 text_prop_count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE);
1610 if (text_prop_count > 0)
1611 {
1612 // Make a copy of the properties, so that they are properly
1613 // aligned.
1614 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1615 if (text_props != NULL)
1616 mch_memmove(text_props, prop_start,
1617 text_prop_count * sizeof(textprop_T));
1618
1619 // Allocate an array for the indexes.
1620 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1621 if (text_prop_idxs == NULL)
1622 VIM_CLEAR(text_props);
1623
1624 if (text_props != NULL)
1625 {
1626 area_highlighting = TRUE;
1627 extra_check = TRUE;
1628
zeertzjq4e26a9a2023-12-03 17:50:47 +01001629 /* Find the last text property that inserts text. */
1630 for (int i = 0; i < text_prop_count; ++i)
1631 if (text_props[i].tp_id < 0)
1632 last_textprop_text_idx = i;
1633
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001634 // Text props "above" move the line number down to where the text
1635 // is. Only count the ones that are visible, not those that are
1636 // skipped because of w_skipcol.
1637 int text_width = wp->w_width - win_col_off(wp);
1638 for (int i = text_prop_count - 1; i >= 0; --i)
1639 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1640 {
1641 if (lnum == wp->w_topline
1642 && wp->w_skipcol - skipcol_in_text_prop_above
1643 >= text_width)
1644 {
1645 // This virtual text above is skipped, remove it from
1646 // the array.
1647 skipcol_in_text_prop_above += text_width;
1648 for (int j = i + 1; j < text_prop_count; ++j)
1649 text_props[j - 1] = text_props[j];
1650 ++i;
1651 --text_prop_count;
1652 }
1653 else
1654 ++wlv.text_prop_above_count;
1655 }
1656 }
1657 }
Bram Moolenaara572b932023-02-19 14:34:37 +00001658
zeertzjqebfd8562024-02-06 10:59:03 +01001659 if (number_only > 0)
Bram Moolenaara572b932023-02-19 14:34:37 +00001660 {
1661 // skip over rows only used for virtual text above
1662 wlv.row += wlv.text_prop_above_count;
1663 if (wlv.row > endrow)
1664 return wlv.row;
1665 wlv.screen_row += wlv.text_prop_above_count;
1666 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001667#endif
1668
zeertzjqce53e3e2023-09-01 18:49:30 +02001669#if defined(FEAT_LINEBREAK) || defined(FEAT_PROP_POPUP)
1670 colnr_T vcol_first_char = 0;
zeertzjqebfd8562024-02-06 10:59:03 +01001671 if (wp->w_p_lbr && number_only == 0)
zeertzjqce53e3e2023-09-01 18:49:30 +02001672 {
1673 chartabsize_T cts;
1674 init_chartabsize_arg(&cts, wp, lnum, 0, line, line);
1675 (void)win_lbr_chartabsize(&cts, NULL);
1676 vcol_first_char = cts.cts_first_char;
1677 clear_chartabsize_arg(&cts);
1678 }
1679#endif
1680
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001681 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1682 // first character to be displayed.
1683 if (wp->w_p_wrap)
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001684 v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001685 else
1686 v = wp->w_leftcol;
zeertzjqebfd8562024-02-06 10:59:03 +01001687 if (v > 0 && number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001688 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001689 char_u *prev_ptr = ptr;
1690 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001691 int charsize = 0;
zeertzjqb557f482023-08-22 22:07:34 +02001692 int head = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001693
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001694 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
zeertzjqb557f482023-08-22 22:07:34 +02001695 cts.cts_max_head_vcol = v;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001696 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001697 {
zeertzjqb557f482023-08-22 22:07:34 +02001698 head = 0;
1699 charsize = win_lbr_chartabsize(&cts, &head);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001700 cts.cts_vcol += charsize;
1701 prev_ptr = cts.cts_ptr;
1702 MB_PTR_ADV(cts.cts_ptr);
zeertzjqabc80812023-09-24 23:32:18 +02001703 if (wp->w_p_list)
1704 {
1705 in_multispace = *prev_ptr == ' ' && (*cts.cts_ptr == ' '
1706 || (prev_ptr > line && prev_ptr[-1] == ' '));
1707 if (!in_multispace)
1708 multispace_pos = 0;
1709 else if (cts.cts_ptr >= line + leadcol
1710 && wp->w_lcs_chars.multispace != NULL)
1711 {
1712 ++multispace_pos;
1713 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
1714 multispace_pos = 0;
1715 }
1716 else if (cts.cts_ptr < line + leadcol
1717 && wp->w_lcs_chars.leadmultispace != NULL)
1718 {
1719 ++multispace_pos;
1720 if (wp->w_lcs_chars.leadmultispace[multispace_pos] == NUL)
1721 multispace_pos = 0;
1722 }
1723 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001724 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001725 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001726 ptr = cts.cts_ptr;
1727 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001728
1729 // When:
1730 // - 'cuc' is set, or
1731 // - 'colorcolumn' is set, or
1732 // - 'virtualedit' is set, or
1733 // - the visual mode is active,
1734 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001735 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001736#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001737 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001738#endif
1739 virtual_active() ||
1740 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001741 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001742
1743 // Handle a character that's not completely on the screen: Put ptr at
1744 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001745 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001746 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001747 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001748 ptr = prev_ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001749 }
zeertzjqb557f482023-08-22 22:07:34 +02001750 if (v > wlv.vcol)
1751 skip_cells = v - wlv.vcol - head;
Bram Moolenaarcd105412022-10-10 19:50:42 +01001752
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001753 // Adjust for when the inverted text is before the screen,
1754 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001755 if (wlv.tocol <= wlv.vcol)
1756 wlv.fromcol = 0;
1757 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1758 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001759
1760#ifdef FEAT_LINEBREAK
1761 // When w_skipcol is non-zero, first line needs 'showbreak'
1762 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001763 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001764#endif
1765#ifdef FEAT_SPELL
1766 // When spell checking a word we need to figure out the start of the
1767 // word and if it's badly spelled or not.
Luuk van Baal30805a12023-05-27 22:22:10 +01001768 if (spv->spv_has_spell)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001769 {
1770 int len;
1771 colnr_T linecol = (colnr_T)(ptr - line);
1772 hlf_T spell_hlf = HLF_COUNT;
1773
1774 pos = wp->w_cursor;
1775 wp->w_cursor.lnum = lnum;
1776 wp->w_cursor.col = linecol;
1777 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1778
1779 // spell_move_to() may call ml_get() and make "line" invalid
1780 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1781 ptr = line + linecol;
1782
1783 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1784 {
1785 // no bad word found at line start, don't check until end of a
1786 // word
1787 spell_hlf = HLF_COUNT;
1788 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1789 }
1790 else
1791 {
1792 // bad word found, use attributes until end of word
1793 word_end = wp->w_cursor.col + len + 1;
1794
1795 // Turn index into actual attributes.
1796 if (spell_hlf != HLF_COUNT)
1797 spell_attr = highlight_attr[spell_hlf];
1798 }
1799 wp->w_cursor = pos;
1800
1801# ifdef FEAT_SYN_HL
1802 // Need to restart syntax highlighting for this line.
1803 if (has_syntax)
1804 syntax_start(wp, lnum);
1805# endif
1806 }
1807#endif
1808 }
1809
1810 // Correct highlighting for cursor that can't be disabled.
1811 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001812 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001813 {
1814 if (noinvcur)
1815 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001816 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001817 {
1818 // highlighting starts at cursor, let it start just after the
1819 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001820 fromcol_prev = wlv.fromcol;
1821 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001822 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001823 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001824 // restart highlighting after the cursor
1825 fromcol_prev = wp->w_virtcol;
1826 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001827 if (wlv.fromcol >= wlv.tocol)
1828 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001829 }
1830
1831#ifdef FEAT_SEARCH_EXTRA
zeertzjqebfd8562024-02-06 10:59:03 +01001832 if (number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001833 {
1834 v = (long)(ptr - line);
1835 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1836 &line, &screen_search_hl,
1837 &search_attr);
1838 ptr = line + v; // "line" may have been updated
1839 }
1840#endif
1841
1842#ifdef FEAT_SYN_HL
1843 // Cursor line highlighting for 'cursorline' in the current window.
1844 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1845 {
1846 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001847 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001848 if (!(wp == curwin && VIsual_active)
1849 && wp->w_p_culopt_flags != CULOPT_NBR)
1850 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001851 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001852 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1853
zeertzjqb7acea12022-12-12 13:20:43 +00001854 // Only apply CursorLine highlight here when "screenline" is not
1855 // present in 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001856 if (!wlv.cul_screenline)
zeertzjqb7acea12022-12-12 13:20:43 +00001857 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001858 else
1859 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001860 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001861 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1862 }
1863 area_highlighting = TRUE;
1864 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001865 }
1866#endif
1867
Bram Moolenaar1306b362022-08-06 15:59:06 +01001868 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001869
1870 // Repeat for the whole displayed line.
1871 for (;;)
1872 {
1873#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001874 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001875#endif
1876#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001877 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001878#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001879
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001880 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001881 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001882 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001883#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001884 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001885 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001886 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001887 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001888 }
1889#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001890 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001891 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001892 wlv.draw_state = WL_CMDLINE;
Sean Dewar988f7432023-08-16 14:17:36 +01001893 if (wp == cmdwin_win)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001894 {
1895 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001896 wlv.n_extra = 1;
1897 wlv.c_extra = cmdwin_type;
1898 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001899 wlv.char_attr =
1900 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001901 }
1902 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001903#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001904 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001905 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001906 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001907 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001908 }
1909#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001910#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001911 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001912 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001913 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001914 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001915 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001916 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001917 }
1918#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001919 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001920 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001921 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001922 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001923 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001924 }
zeertzjqebfd8562024-02-06 10:59:03 +01001925
1926 // When only displaying the (relative) line number and that's done,
1927 // stop here.
1928 if (number_only > 0 && wlv.draw_state == WL_NR && wlv.n_extra == 0)
1929 {
1930 wlv_screen_line(wp, &wlv, TRUE);
1931 // Need to update more screen lines if:
1932 // - LineNrAbove or LineNrBelow is used, or
1933 // - still drawing filler lines.
1934 if ((wlv.row + 1 - wlv.startrow < number_only
1935 && (HL_ATTR(HLF_LNA) != 0 || HL_ATTR(HLF_LNB) != 0))
1936#ifdef FEAT_DIFF
1937 || wlv.filler_todo > 0
1938#endif
1939 )
1940 {
1941 ++wlv.row;
1942 ++wlv.screen_row;
1943 if (wlv.row == endrow)
1944 break;
1945#ifdef FEAT_DIFF
1946 --wlv.filler_todo;
1947 if (wlv.filler_todo == 0 && wp->w_botfill)
1948 break;
1949#endif
1950 win_line_start(wp, &wlv, TRUE);
1951 continue;
1952 }
1953 else
1954 break;
1955 }
1956
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001957#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001958 // Check if 'breakindent' applies and show it.
1959 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1960 if (wlv.n_extra == 0)
1961 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001962#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001963#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001964 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001965 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001966 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001967 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001968 }
1969#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001970 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001971 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001972 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001973 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001974 }
1975 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001976
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001977#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001978 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001979 && wlv.vcol >= left_curline_col
1980 && wlv.vcol < right_curline_col)
zeertzjqb7acea12022-12-12 13:20:43 +00001981 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001982#endif
1983
1984 // When still displaying '$' of change command, stop at cursor.
zeertzjqebfd8562024-02-06 10:59:03 +01001985 if (dollar_vcol >= 0 && wp == curwin
1986 && lnum == wp->w_cursor.lnum
1987 && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001988 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001989 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001990 // Pretend we have finished updating the window. Except when
1991 // 'cursorcolumn' is set.
1992#ifdef FEAT_SYN_HL
1993 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001994 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001995 else
1996#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001997 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001998 break;
1999 }
2000
Bram Moolenaar1306b362022-08-06 15:59:06 +01002001 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002002 {
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002003#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002004 if (text_props != NULL)
2005 {
2006 int pi;
2007 int bcol = (int)(ptr - line);
2008
Bram Moolenaar1306b362022-08-06 15:59:06 +01002009 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002010# ifdef FEAT_LINEBREAK
2011 && !in_linebreak
2012# endif
2013 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002014 --bcol; // still working on the previous char, e.g. Tab
2015
2016 // Check if any active property ends.
2017 for (pi = 0; pi < text_props_active; ++pi)
2018 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002019 int tpi = text_prop_idxs[pi];
2020 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002021
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002022 // An inline property ends when after the start column plus
2023 // length. An "above" property ends when used and n_extra
2024 // is zero.
2025 if ((tp->tp_col != MAXCOL
2026 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002027 {
2028 if (pi + 1 < text_props_active)
2029 mch_memmove(text_prop_idxs + pi,
2030 text_prop_idxs + pi + 1,
2031 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002032 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002033 --text_props_active;
2034 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002035# ifdef FEAT_LINEBREAK
2036 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002037 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002038 syntax_attr = 0;
2039# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002040 }
2041 }
2042
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002043# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01002044 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002045 // not on the next char yet, don't start another prop
2046 --bcol;
2047# endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002048 int display_text_first = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002049
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002050 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002051 // With 'nowrap' and not in the first screen line only "below"
2052 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002053 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002054 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002055 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002056 && (wp->w_p_wrap
2057 || wlv.row == startrow
2058 || (text_props[text_prop_next].tp_flags
2059 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002060 || (bcol == 0
2061 && (text_props[text_prop_next].tp_flags
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002062 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002063 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002064 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01002065 if (text_props[text_prop_next].tp_col == MAXCOL
2066 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002067 + text_props[text_prop_next].tp_len)
2068 text_prop_idxs[text_props_active++] = text_prop_next;
2069 ++text_prop_next;
2070 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002071
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002072 if (wlv.n_extra == 0 ||
2073 (!wlv.extra_for_textprop
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002074 && !(text_prop_type != NULL &&
2075 text_prop_flags & PT_FLAG_OVERRIDE)
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002076 ))
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002077 {
2078 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002079 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002080 text_prop_flags = 0;
2081 text_prop_type = NULL;
2082 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002083 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002084 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002085 if (text_props_active > 0 && wlv.n_extra == 0
2086 && !display_text_first)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002087 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01002088 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002089 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002090 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002091
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002092 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002093 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002094
2095 // Sort the properties on priority and/or starting last.
2096 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002097 sort_text_props(wp->w_buffer, text_props,
2098 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002099
2100 for (pi = 0; pi < text_props_active; ++pi)
2101 {
2102 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002103 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002104 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002105 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002106
Bram Moolenaarcd105412022-10-10 19:50:42 +01002107 // Only use a text property that can be displayed.
2108 // Skip "after" properties when wrap is off and at the
2109 // end of the window.
2110 if (pt != NULL
2111 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2112 && tp->tp_id != -MAXCOL
2113 && !(tp->tp_id < 0
2114 && !wp->w_p_wrap
2115 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2116 | TP_FLAG_ALIGN_ABOVE
2117 | TP_FLAG_ALIGN_BELOW)) == 0
2118 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002119 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002120 if (tp->tp_col == MAXCOL
2121 && *ptr == NUL
2122 && ((wp->w_p_list && lcs_eol_one > 0
2123 && (tp->tp_flags
2124 & TP_FLAG_ALIGN_ABOVE) == 0)
2125 || (ptr == line
2126 && !did_line
2127 && (tp->tp_flags
2128 & TP_FLAG_ALIGN_BELOW))))
2129 {
2130 // skip this prop, first display the '$' after
2131 // the line or display an empty line
2132 text_prop_follows = TRUE;
2133 if (used_tpi < 0)
2134 display_text_first = TRUE;
2135 continue;
2136 }
2137
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002138 if (pt->pt_hl_id > 0)
2139 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002140 text_prop_type = pt;
2141 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002142 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002143 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2144 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002145 text_prop_flags = pt->pt_flags;
2146 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002147 used_tpi = tpi;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002148 display_text_first = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002149 }
2150 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002151 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002152 && -text_prop_id
2153 <= wp->w_buffer->b_textprop_text.ga_len)
2154 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002155 textprop_T *tp = &text_props[used_tpi];
2156 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002157 ->b_textprop_text.ga_data)[
2158 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002159 int above = (tp->tp_flags
2160 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002161 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002162
2163 // reset the ID in the copy to avoid it being used
2164 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002165 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002166
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002167 if (p != NULL)
2168 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002169 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002170 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002171 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002172 & TP_FLAG_ALIGN_BELOW);
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002173 int wrap = tp->tp_col < MAXCOL
2174 || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002175 int padding = tp->tp_col == MAXCOL
2176 && tp->tp_len > 1
2177 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002178
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002179 // Insert virtual text before the current
2180 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002181 wlv.p_extra = p;
2182 wlv.c_extra = NUL;
2183 wlv.c_final = NUL;
2184 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002185 wlv.extra_for_textprop = TRUE;
zeertzjq6e940d92023-08-17 23:21:40 +02002186 wlv.start_extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002187 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2188 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002189 n_attr = mb_charlen(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002190 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002191 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002192 if (*ptr == NUL)
2193 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002194 text_prop_flags &= ~PT_FLAG_COMBINE;
zeertzjq6b9c2022023-09-11 20:01:17 +02002195# ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002196 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002197 {
2198 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002199 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002200 wlv.need_showbreak = FALSE;
2201 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002202 }
zeertzjq6b9c2022023-09-11 20:01:17 +02002203# endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002204 if ((right || above || below || !wrap
2205 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002206 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002207 char_u *prev_p_extra = wlv.p_extra;
2208 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002209
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002210 // Take care of padding, right-align and
2211 // truncation.
2212 // Shared with win_lbr_chartabsize(), must do
2213 // exactly the same.
2214 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002215 wlv.vcol,
zeertzjq6b9c2022023-09-11 20:01:17 +02002216# ifdef FEAT_RIGHTLEFT
2217 wp->w_p_rl
2218 ? wp->w_width - wlv.col - 1
2219 :
2220# endif
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002221 wlv.col,
2222 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002223 &n_attr, &wlv.n_attr_skip,
2224 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002225 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002226 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002227 // wlv.p_extra was allocated
2228 vim_free(p_extra_free2);
2229 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002230 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002231
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002232 if (above)
2233 wlv.vcol_off_tp = wlv.n_extra;
2234
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002235 if (lcs_eol_one < 0
2236 && wp->w_p_wrap
2237 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002238 + wlv.n_extra - 2 > wp->w_width)
2239 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002240 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002241
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002242 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002243 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002244 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002245 {
2246 draw_screen_line(wp, &wlv);
2247
2248 // When line got too long for screen break
2249 // here.
2250 if (wlv.row == endrow)
2251 {
2252 ++wlv.row;
2253 break;
2254 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002255 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002256 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002257 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002258 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002259 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002260
Bram Moolenaarcd105412022-10-10 19:50:42 +01002261 // If the text didn't reach until the first window
2262 // column we need to skip cells.
2263 if (skip_cells > 0)
2264 {
2265 if (wlv.n_extra > skip_cells)
2266 {
2267 wlv.n_extra -= skip_cells;
2268 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002269 wlv.n_attr_skip -= skip_cells;
2270 if (wlv.n_attr_skip < 0)
2271 wlv.n_attr_skip = 0;
zeertzjqb557f482023-08-22 22:07:34 +02002272 skipped_cells += skip_cells;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002273 skip_cells = 0;
2274 }
2275 else
2276 {
2277 // the whole text is left of the window, drop
2278 // it and advance to the next one
2279 skip_cells -= wlv.n_extra;
zeertzjqb557f482023-08-22 22:07:34 +02002280 skipped_cells += wlv.n_extra;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002281 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002282 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002283 bail_out = TRUE;
2284 }
2285 }
2286
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002287 // If another text prop follows the condition below at
2288 // the last window column must know.
Dylan Thacker-Smith83925be2024-02-21 21:03:10 +01002289 // If this is an "above" text prop and 'nowrap' then we
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002290 // must wrap anyway.
2291 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002292 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002293 && (wp->w_p_wrap
2294 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002295 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002296
2297 if (bail_out)
2298 // starting a new line for "below"
2299 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002300 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002301 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002302 else if (text_prop_next < text_prop_count
2303 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002304 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2305 || (!wp->w_p_wrap
2306 && wlv.col == wp->w_width - 1
2307 && (text_props[text_prop_next].tp_flags
2308 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002309 // When at last-but-one character and a text property
2310 // follows after it, we may need to flush the line after
2311 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002312 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002313 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002314 }
zeertzjq6e940d92023-08-17 23:21:40 +02002315
2316 if (wlv.start_extra_for_textprop)
2317 {
2318 wlv.start_extra_for_textprop = FALSE;
2319 // restore search_attr and area_attr when n_extra
2320 // is down to zero
2321 saved_search_attr = search_attr;
2322 saved_area_attr = area_attr;
2323 search_attr = 0;
2324 area_attr = 0;
2325 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002326#endif
2327
zeertzjq6e940d92023-08-17 23:21:40 +02002328 int *area_attr_p =
2329#ifdef FEAT_PROP_POPUP
2330 wlv.extra_for_textprop ? &saved_area_attr :
2331#endif
2332 &area_attr;
2333
2334 // handle Visual or match highlighting in this line
2335 if (wlv.vcol == wlv.fromcol
2336 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
2337 && ((wlv.n_extra == 0 && (*mb_ptr2cells)(ptr) > 1)
2338 || (wlv.n_extra > 0 && wlv.p_extra != NULL
2339 && (*mb_ptr2cells)(wlv.p_extra) > 1)))
2340 || ((int)vcol_prev == fromcol_prev
2341 && vcol_prev < wlv.vcol // not at margin
2342 && wlv.vcol < wlv.tocol))
2343 *area_attr_p = vi_attr; // start highlighting
2344 else if (*area_attr_p != 0
2345 && (wlv.vcol == wlv.tocol
2346 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
2347 *area_attr_p = 0; // stop highlighting
2348
zeertzjqe500ae82023-08-17 22:35:26 +02002349#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaare38fc862022-08-11 17:24:50 +01002350 if (wlv.n_extra == 0)
2351 {
2352 // Check for start/end of 'hlsearch' and other matches.
2353 // After end, check for start/end of next match.
2354 // When another match, have to check for start again.
2355 v = (long)(ptr - line);
2356 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2357 &screen_search_hl, &has_match_conc,
2358 &match_conc, did_line_attr, lcs_eol_one,
2359 &on_last_col);
2360 ptr = line + v; // "line" may have been changed
Bram Moolenaare38fc862022-08-11 17:24:50 +01002361
2362 // Do not allow a conceal over EOL otherwise EOL will be missed
2363 // and bad things happen.
2364 if (*ptr == NUL)
2365 has_match_conc = 0;
zeertzjqb25dbb32023-08-13 18:11:05 +02002366 }
zeertzjqe500ae82023-08-17 22:35:26 +02002367#endif
zeertzjqb25dbb32023-08-13 18:11:05 +02002368
Bram Moolenaare38fc862022-08-11 17:24:50 +01002369#ifdef FEAT_DIFF
2370 if (wlv.diff_hlf != (hlf_T)0)
2371 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002372 // When there is extra text (e.g. virtual text) it gets the
2373 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002374 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2375 && wlv.n_extra == 0)
2376 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002377 if (wlv.diff_hlf == HLF_TXD
2378 && ((ptr - line > change_end && wlv.n_extra == 0)
2379 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002380 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002381 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002382 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2383 && wp->w_p_culopt_flags != CULOPT_NBR
2384 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2385 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002386 wlv.line_attr = hl_combine_attr(
2387 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002388 }
2389#endif
2390
Bram Moolenaara74fda62019-10-19 17:38:03 +02002391#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002392 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002393 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002394 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002395# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002396 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002397 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002398# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002399 // Get syntax attribute.
2400 if (has_syntax)
2401 {
2402 // Get the syntax attribute for the character. If there
2403 // is an error, disable syntax highlighting.
2404 save_did_emsg = did_emsg;
2405 did_emsg = FALSE;
2406
2407 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002408 if (v == prev_syntax_col)
2409 // at same column again
2410 syntax_attr = prev_syntax_attr;
2411 else
2412 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002413# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002414 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002415# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002416 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002417# ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01002418 spv->spv_has_spell ? &can_spell :
Bram Moolenaar34390282019-10-16 14:38:26 +02002419# endif
Luuk van Baal30805a12023-05-27 22:22:10 +01002420 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002421 prev_syntax_col = v;
2422 prev_syntax_attr = syntax_attr;
2423 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002424
Bram Moolenaar34390282019-10-16 14:38:26 +02002425 if (did_emsg)
2426 {
2427 wp->w_s->b_syn_error = TRUE;
2428 has_syntax = FALSE;
2429 syntax_attr = 0;
2430 }
2431 else
2432 did_emsg = save_did_emsg;
2433# ifdef SYN_TIME_LIMIT
2434 if (wp->w_s->b_syn_slow)
2435 has_syntax = FALSE;
2436# endif
2437
2438 // Need to get the line again, a multi-line regexp may
2439 // have made it invalid.
2440 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2441 ptr = line + v;
2442# ifdef FEAT_CONCEAL
2443 // no concealing past the end of the line, it interferes
2444 // with line highlighting
2445 if (*ptr == NUL)
2446 syntax_flags = 0;
2447 else
2448 syntax_flags = get_syntax_info(&syntax_seqnr);
2449# endif
2450 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002451 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002452# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002453 // Combine text property highlight into syntax highlight.
2454 if (text_prop_type != NULL)
2455 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002456 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002457 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2458 else
2459 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002460 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002461 }
2462# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002463#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002464
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002465 // Decide which of the highlight attributes to use.
2466 attr_pri = TRUE;
2467#ifdef LINE_ATTR
2468 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002469 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002470 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002471 if (!highlight_match)
2472 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002473 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002474# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002475 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002476# endif
2477 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002478 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002479 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002480 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002481# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002482 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002483# endif
2484 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002485 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002486 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2487 || wlv.vcol < wlv.fromcol
2488 || vcol_prev < fromcol_prev
2489 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002490 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002491 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002492 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002493# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002494 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002495# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002496 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002497# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002498 attr_pri = FALSE;
2499 }
2500#else
2501 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002502 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002503 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002504 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002505#endif
2506 else
2507 {
2508 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002509#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002510 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002511#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002512 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002513#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002514 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002515#ifdef FEAT_PROP_POPUP
2516 // override with text property highlight when "override" is TRUE
2517 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002518 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002519#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002520 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002521
2522 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002523 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002524 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002525 if (wlv.char_attr == 0)
2526 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002527 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002528 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002529 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002530
2531 // Get the next character to put on the screen.
2532
2533 // The "p_extra" points to the extra stuff that is inserted to
2534 // represent special characters (non-printable stuff) and other
2535 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002536 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002537 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2538 // "p_extra[n_extra]".
2539 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002540 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002541 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002542 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002543 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002544 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2545 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002546 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2547 if (enc_utf8 && utf_char2len(c) > 1)
2548 {
2549 mb_utf8 = TRUE;
2550 u8cc[0] = 0;
2551 c = 0xc0;
2552 }
2553 else
2554 mb_utf8 = FALSE;
2555 }
2556 else
2557 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002558 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002559 if (has_mbyte)
2560 {
2561 mb_c = c;
2562 if (enc_utf8)
2563 {
2564 // If the UTF-8 character is more than one byte:
2565 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002566 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002567 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002568 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002569 mb_l = 1;
2570 else if (mb_l > 1)
2571 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002572 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002573 mb_utf8 = TRUE;
2574 c = 0xc0;
2575 }
2576 }
2577 else
2578 {
2579 // if this is a DBCS character, put it in "mb_c"
2580 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002581 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002582 mb_l = 1;
2583 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002584 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002585 }
2586 if (mb_l == 0) // at the NUL at end-of-line
2587 mb_l = 1;
2588
2589 // If a double-width char doesn't fit display a '>' in the
2590 // last column.
2591 if ((
2592# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002593 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002594# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002595 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002596 && (*mb_char2cells)(mb_c) == 2)
2597 {
2598 c = '>';
2599 mb_c = c;
2600 mb_l = 1;
2601 mb_utf8 = FALSE;
2602 multi_attr = HL_ATTR(HLF_AT);
2603#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002604 if (wlv.cul_attr)
2605 multi_attr = hl_combine_attr(
2606 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002607#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002608 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002609
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002610 // put the pointer back to output the double-width
2611 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002612 ++wlv.n_extra;
2613 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002614 }
2615 else
2616 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002617 wlv.n_extra -= mb_l - 1;
2618 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002619 }
2620 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002621 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002622 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002623 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002624#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002625 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002626 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002627 // Only restore search_attr and area_attr after "n_extra" in
2628 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002629 if (wlv.saved_n_extra <= 0)
2630 {
2631 if (search_attr == 0)
2632 search_attr = saved_search_attr;
2633 if (area_attr == 0 && *ptr != NUL)
2634 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002635
2636 if (wlv.extra_for_textprop)
2637 // wlv.extra_attr should be used at this position but
2638 // not any further.
2639 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002640 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002641
2642 wlv.extra_for_textprop = FALSE;
2643 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002644 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002645#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002646 }
2647 else
2648 {
2649#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002650 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002651#endif
zeertzjqe500ae82023-08-17 22:35:26 +02002652 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002653
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002654 // Get a character from the line itself.
2655 c = *ptr;
2656#ifdef FEAT_LINEBREAK
2657 c0 = *ptr;
2658#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002659 if (c == NUL)
zeertzjqb557f482023-08-22 22:07:34 +02002660 {
2661#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002662 // text is finished, may display a "below" virtual text
2663 did_line = TRUE;
2664#endif
zeertzjqb557f482023-08-22 22:07:34 +02002665 // no more cells to skip
2666 skip_cells = 0;
2667 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002668
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002669 if (has_mbyte)
2670 {
2671 mb_c = c;
2672 if (enc_utf8)
2673 {
2674 // If the UTF-8 character is more than one byte: Decode it
2675 // into "mb_c".
2676 mb_l = utfc_ptr2len(ptr);
2677 mb_utf8 = FALSE;
2678 if (mb_l > 1)
2679 {
2680 mb_c = utfc_ptr2char(ptr, u8cc);
2681 // Overlong encoded ASCII or ASCII with composing char
2682 // is displayed normally, except a NUL.
2683 if (mb_c < 0x80)
2684 {
2685 c = mb_c;
2686#ifdef FEAT_LINEBREAK
2687 c0 = mb_c;
2688#endif
2689 }
2690 mb_utf8 = TRUE;
2691
2692 // At start of the line we can have a composing char.
2693 // Draw it as a space with a composing char.
2694 if (utf_iscomposing(mb_c))
2695 {
2696 int i;
2697
2698 for (i = Screen_mco - 1; i > 0; --i)
2699 u8cc[i] = u8cc[i - 1];
2700 u8cc[0] = mb_c;
2701 mb_c = ' ';
2702 }
2703 }
2704
2705 if ((mb_l == 1 && c >= 0x80)
2706 || (mb_l >= 1 && mb_c == 0)
2707 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2708 {
2709 // Illegal UTF-8 byte: display as <xx>.
2710 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002711 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002712# ifdef FEAT_RIGHTLEFT
2713 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002714 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002715# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002716 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002717 c = *wlv.p_extra;
2718 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002719 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002720 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2721 wlv.c_extra = NUL;
2722 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002723 if (area_attr == 0 && search_attr == 0)
2724 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002725 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002726 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002727 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002728 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002729 }
2730 }
2731 else if (mb_l == 0) // at the NUL at end-of-line
2732 mb_l = 1;
2733#ifdef FEAT_ARABIC
2734 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2735 {
2736 // Do Arabic shaping.
2737 int pc, pc1, nc;
2738 int pcc[MAX_MCO];
2739
2740 // The idea of what is the previous and next
2741 // character depends on 'rightleft'.
2742 if (wp->w_p_rl)
2743 {
2744 pc = prev_c;
2745 pc1 = prev_c1;
2746 nc = utf_ptr2char(ptr + mb_l);
2747 prev_c1 = u8cc[0];
2748 }
2749 else
2750 {
2751 pc = utfc_ptr2char(ptr + mb_l, pcc);
2752 nc = prev_c;
2753 pc1 = pcc[0];
2754 }
2755 prev_c = mb_c;
2756
2757 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2758 }
2759 else
2760 prev_c = mb_c;
2761#endif
2762 }
2763 else // enc_dbcs
2764 {
2765 mb_l = MB_BYTE2LEN(c);
2766 if (mb_l == 0) // at the NUL at end-of-line
2767 mb_l = 1;
2768 else if (mb_l > 1)
2769 {
2770 // We assume a second byte below 32 is illegal.
2771 // Hopefully this is OK for all double-byte encodings!
2772 if (ptr[1] >= 32)
2773 mb_c = (c << 8) + ptr[1];
2774 else
2775 {
2776 if (ptr[1] == NUL)
2777 {
2778 // head byte at end of line
2779 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002780 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002781 }
2782 else
2783 {
2784 // illegal tail byte
2785 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002786 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002787 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002788 wlv.p_extra = wlv.extra;
2789 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002790 wlv.c_extra = NUL;
2791 wlv.c_final = NUL;
2792 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002793 if (area_attr == 0 && search_attr == 0)
2794 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002795 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002796 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002797 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002798 // save current attr
2799 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002800 }
2801 mb_c = c;
2802 }
2803 }
2804 }
2805 // If a double-width char doesn't fit display a '>' in the
2806 // last column; the character is displayed at the start of the
2807 // next line.
2808 if ((
2809# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002810 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002811# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002812 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002813 && (*mb_char2cells)(mb_c) == 2)
2814 {
2815 c = '>';
2816 mb_c = c;
2817 mb_utf8 = FALSE;
2818 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002819 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002820 // Put pointer back so that the character will be
2821 // displayed at the start of the next line.
2822 --ptr;
2823#ifdef FEAT_CONCEAL
2824 did_decrement_ptr = TRUE;
2825#endif
2826 }
2827 else if (*ptr != NUL)
2828 ptr += mb_l - 1;
2829
2830 // If a double-width char doesn't fit at the left side display
2831 // a '<' in the first column. Don't do this for unprintable
2832 // characters.
zeertzjqb557f482023-08-22 22:07:34 +02002833 if (skip_cells > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002834 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002835 wlv.n_extra = 1;
2836 wlv.c_extra = MB_FILLER_CHAR;
2837 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002838 c = ' ';
2839 if (area_attr == 0 && search_attr == 0)
2840 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002841 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002842 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002843 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002844 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002845 }
2846 mb_c = c;
2847 mb_utf8 = FALSE;
2848 mb_l = 1;
2849 }
2850
2851 }
2852 ++ptr;
2853
2854 if (extra_check)
2855 {
2856#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002857 // Check spelling (unless at the end of the line).
2858 // Only do this when there is no syntax highlighting, the
2859 // @Spell cluster is not used or the current syntax item
2860 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002861 v = (long)(ptr - line);
Luuk van Baal30805a12023-05-27 22:22:10 +01002862 if (spv->spv_has_spell && v >= word_end && v > cur_checked_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002863 {
2864 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002865 // do not calculate cap_col at the end of the line or when
2866 // only white space is following
2867 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002868# ifdef FEAT_SYN_HL
2869 !has_syntax ||
2870# endif
2871 can_spell))
2872 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002873 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002874 int len;
2875 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002876
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002877 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002878 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002879
2880 // Use nextline[] if possible, it has the start of the
2881 // next line concatenated.
2882 if ((prev_ptr - line) - nextlinecol >= 0)
2883 p = nextline + (prev_ptr - line) - nextlinecol;
2884 else
2885 p = prev_ptr;
Luuk van Baal30805a12023-05-27 22:22:10 +01002886 spv->spv_cap_col -= (int)(prev_ptr - line);
2887 len = spell_check(wp, p, &spell_hlf, &spv->spv_cap_col,
2888 spv->spv_unchanged);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002889 word_end = v + len;
2890
2891 // In Insert mode only highlight a word that
2892 // doesn't touch the cursor.
2893 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002894 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002895 && wp->w_cursor.lnum == lnum
2896 && wp->w_cursor.col >=
2897 (colnr_T)(prev_ptr - line)
2898 && wp->w_cursor.col < (colnr_T)word_end)
2899 {
2900 spell_hlf = HLF_COUNT;
2901 spell_redraw_lnum = lnum;
2902 }
2903
2904 if (spell_hlf == HLF_COUNT && p != prev_ptr
2905 && (p - nextline) + len > nextline_idx)
2906 {
2907 // Remember that the good word continues at the
2908 // start of the next line.
Luuk van Baal30805a12023-05-27 22:22:10 +01002909 spv->spv_checked_lnum = lnum + 1;
2910 spv->spv_checked_col = (p - nextline) + len
2911 - nextline_idx;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002912 }
2913
2914 // Turn index into actual attributes.
2915 if (spell_hlf != HLF_COUNT)
2916 spell_attr = highlight_attr[spell_hlf];
2917
Luuk van Baal30805a12023-05-27 22:22:10 +01002918 if (spv->spv_cap_col > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002919 {
2920 if (p != prev_ptr
Luuk van Baal30805a12023-05-27 22:22:10 +01002921 && (p - nextline) + spv->spv_cap_col
2922 >= nextline_idx)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002923 {
2924 // Remember that the word in the next line
2925 // must start with a capital.
Luuk van Baal30805a12023-05-27 22:22:10 +01002926 spv->spv_capcol_lnum = lnum + 1;
2927 spv->spv_cap_col = ((p - nextline)
2928 + spv->spv_cap_col - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002929 }
2930 else
2931 // Compute the actual column.
Luuk van Baal30805a12023-05-27 22:22:10 +01002932 spv->spv_cap_col += (prev_ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002933 }
2934 }
2935 }
2936 if (spell_attr != 0)
2937 {
2938 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002939 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2940 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002941 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002942 wlv.char_attr = hl_combine_attr(spell_attr,
2943 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002944 }
2945#endif
2946#ifdef FEAT_LINEBREAK
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02002947 // we don't want linebreak to apply for lines that start with
2948 // leading spaces, followed by long letters (since it would add
2949 // a break at the beginning of a line and this might be unexpected)
2950 //
2951 // So only allow to linebreak, once we have found chars not in
2952 // 'breakat' in the line.
2953 if ( wp->w_p_lbr && !wlv.need_lbr && c != NUL &&
2954 !VIM_ISBREAK((int)*ptr))
2955 wlv.need_lbr = TRUE;
2956#endif
2957#ifdef FEAT_LINEBREAK
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002958 // Found last space before word: check for line break.
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02002959 if (wp->w_p_lbr && c0 == c && wlv.need_lbr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002960 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2961 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002962 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2963 : 0;
2964 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002965 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002966
zeertzjqce53e3e2023-09-01 18:49:30 +02002967 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol
2968# ifdef FEAT_PROP_POPUP
2969 - vcol_first_char,
2970# endif
2971 line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002972# ifdef FEAT_PROP_POPUP
2973 // do not want virtual text counted here
2974 cts.cts_has_prop_with_text = FALSE;
2975# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002976 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002977 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002978
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002979 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002980 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002981 // line break, but for TABs the highlighting should
2982 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002983 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002984
Bram Moolenaar1306b362022-08-06 15:59:06 +01002985 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002986# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002987 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002988 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002989 wp->w_buffer->b_p_vts_array) - 1;
2990# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002991 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002992 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002993# endif
2994
Bram Moolenaar1306b362022-08-06 15:59:06 +01002995 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2996 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002997# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002998 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002999 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00003000# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003001 if (VIM_ISWHITE(c))
3002 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01003003# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003004 if (c == TAB)
3005 // See "Tab alignment" below.
3006 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01003007# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003008 if (!wp->w_p_list)
3009 c = ' ';
3010 }
3011 }
3012#endif
zeertzjqabc80812023-09-24 23:32:18 +02003013 if (wp->w_p_list)
3014 {
3015 in_multispace = c == ' ' && (*ptr == ' '
3016 || (prev_ptr > line && prev_ptr[-1] == ' '));
3017 if (!in_multispace)
3018 multispace_pos = 0;
3019 }
zeertzjqf14b8ba2021-09-10 16:58:30 +02003020
Bram Moolenaareed9d462021-02-15 20:38:25 +01003021 // 'list': Change char 160 to 'nbsp' and space to 'space'
3022 // setting in 'listchars'. But not when the character is
3023 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003024 if (wp->w_p_list
3025 && ((((c == 160 && mb_l == 1)
3026 || (mb_utf8
3027 && ((mb_c == 160 && mb_l == 2)
3028 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01003029 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003030 || (c == ' '
3031 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02003032 && (wp->w_lcs_chars.space
3033 || (in_multispace
3034 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01003035 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003036 && ptr - line <= trailcol)))
3037 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02003038 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
3039 {
3040 c = wp->w_lcs_chars.multispace[multispace_pos++];
3041 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
3042 multispace_pos = 0;
3043 }
3044 else
3045 c = (c == ' ') ? wp->w_lcs_chars.space
3046 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003047 if (area_attr == 0 && search_attr == 0)
3048 {
3049 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003050 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003051 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003052 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003053 }
3054 mb_c = c;
3055 if (enc_utf8 && utf_char2len(c) > 1)
3056 {
3057 mb_utf8 = TRUE;
3058 u8cc[0] = 0;
3059 c = 0xc0;
3060 }
3061 else
3062 mb_utf8 = FALSE;
3063 }
3064
zeertzjq2e7cba32022-06-10 15:30:32 +01003065 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
3066 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003067 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003068 if (leadcol != 0 && in_multispace && ptr < line + leadcol
3069 && wp->w_lcs_chars.leadmultispace != NULL)
3070 {
3071 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01003072 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
3073 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003074 multispace_pos = 0;
3075 }
3076
3077 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
3078 c = wp->w_lcs_chars.trail;
3079
3080 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
3081 c = wp->w_lcs_chars.lead;
3082
zeertzjq2e7cba32022-06-10 15:30:32 +01003083 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003084 c = wp->w_lcs_chars.space;
3085
3086
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003087 if (!attr_pri)
3088 {
3089 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003090 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003091 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003092 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003093 }
3094 mb_c = c;
3095 if (enc_utf8 && utf_char2len(c) > 1)
3096 {
3097 mb_utf8 = TRUE;
3098 u8cc[0] = 0;
3099 c = 0xc0;
3100 }
3101 else
3102 mb_utf8 = FALSE;
3103 }
3104 }
3105
3106 // Handling of non-printable characters.
3107 if (!vim_isprintc(c))
3108 {
3109 // when getting a character from the file, we may have to
3110 // turn it into something else on the way to putting it
3111 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01003112 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003113 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003114 int tab_len = 0;
3115 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003116#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003117 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01003118
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003119 // only adjust the tab_len, when at the first column
3120 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01003121 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003122 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003123#endif
3124 // tab amount depends on current column
3125#ifdef FEAT_VARTABS
3126 tab_len = tabstop_padding(vcol_adjusted,
3127 wp->w_buffer->b_p_ts,
3128 wp->w_buffer->b_p_vts_array) - 1;
3129#else
3130 tab_len = (int)wp->w_buffer->b_p_ts
3131 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
3132#endif
3133
3134#ifdef FEAT_LINEBREAK
3135 if (!wp->w_p_lbr || !wp->w_p_list)
3136#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003137 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003138 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01003139 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003140 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003141#ifdef FEAT_LINEBREAK
3142 else
3143 {
3144 char_u *p;
3145 int len;
3146 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003147 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003148
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003149# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003150 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003151 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003152 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003153
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003154 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003155 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003156 && old_boguscols > 0
3157 && wlv.n_extra > tab_len)
3158 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003159# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003160 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003161 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003162 // If wlv.n_extra > 0, it gives the number of chars
3163 // to use for a tab, else we need to calculate the
3164 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003165 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3166 len = tab_len * tab2_len;
3167 if (wp->w_lcs_chars.tab3)
3168 len += mb_char2len(wp->w_lcs_chars.tab3)
3169 - tab2_len;
3170 if (wlv.n_extra > 0)
3171 len += wlv.n_extra - tab_len;
3172 c = wp->w_lcs_chars.tab1;
3173 p = alloc(len + 1);
3174 if (p == NULL)
3175 wlv.n_extra = 0;
3176 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003177 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003178 vim_memset(p, ' ', len);
3179 p[len] = NUL;
3180 vim_free(wlv.p_extra_free);
3181 wlv.p_extra_free = p;
3182 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003183 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003184 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003185
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003186 if (*p == NUL)
3187 {
3188 tab_len = i;
3189 break;
3190 }
3191
3192 // if tab3 is given, use it for the last
3193 // char
3194 if (wp->w_lcs_chars.tab3
3195 && i == tab_len - 1)
3196 lcs = wp->w_lcs_chars.tab3;
3197 p += mb_char2bytes(lcs, p);
3198 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003199 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003200 }
3201 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003202# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003203 // n_extra will be increased by
3204 // FIX_FOX_BOGUSCOLS macro below, so need to
3205 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003206 if (wlv.vcol_off_co > 0)
3207 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003208# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003209 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003210 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003211 }
3212#endif
3213#ifdef FEAT_CONCEAL
3214 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003215 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003216
3217 // Tab alignment should be identical regardless of
3218 // 'conceallevel' value. So tab compensates of all
3219 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003220 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003221 // line. Note that the tab can be longer than
3222 // 'tabstop' when there are concealed characters.
3223 FIX_FOR_BOGUSCOLS;
3224
3225 // Make sure, the highlighting for the tab char will be
3226 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003227 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003228 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003229 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003230 tab_len += vc_saved;
3231 }
3232#endif
3233 mb_utf8 = FALSE; // don't draw as UTF-8
3234 if (wp->w_p_list)
3235 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003236 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003237 ? wp->w_lcs_chars.tab3
3238 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003239#ifdef FEAT_LINEBREAK
h-east194555c2023-03-02 18:49:09 +00003240 if (wp->w_p_lbr && wlv.p_extra != NULL
3241 && *wlv.p_extra != NUL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003242 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003243 else
3244#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003245 wlv.c_extra = wp->w_lcs_chars.tab2;
3246 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003247 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003248 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003249 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003250 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003251 mb_c = c;
3252 if (enc_utf8 && utf_char2len(c) > 1)
3253 {
3254 mb_utf8 = TRUE;
3255 u8cc[0] = 0;
3256 c = 0xc0;
3257 }
3258 }
3259 else
3260 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003261 wlv.c_final = NUL;
3262 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003263 c = ' ';
3264 }
3265 }
3266 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003267 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003268 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003269 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3270 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003271 && VIsual_mode != Ctrl_V
3272 && (
3273# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003274 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003275# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003276 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003277 && !(noinvcur
3278 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003279 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003280 && lcs_eol_one > 0)
3281 {
3282 // Display a '$' after the line or highlight an extra
3283 // character if the line break is included.
3284#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3285 // For a diff line the highlighting continues after the
3286 // "$".
3287 if (
3288# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003289 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003290# ifdef LINE_ATTR
3291 &&
3292# endif
3293# endif
3294# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003295 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003296# endif
3297 )
3298#endif
3299 {
3300 // In virtualedit, visual selections may extend
3301 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003302 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003303 && wlv.tocol != MAXCOL
3304 && wlv.vcol < wlv.tocol))
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01003305 wlv.p_extra = (char_u *)"";
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003306 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003307 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003308 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3309 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003310 else
3311 c = ' ';
3312 lcs_eol_one = -1;
3313 --ptr; // put it back at the NUL
3314 if (!attr_pri)
3315 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003316 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003317 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003318 n_attr = 1;
3319 }
3320 mb_c = c;
3321 if (enc_utf8 && utf_char2len(c) > 1)
3322 {
3323 mb_utf8 = TRUE;
3324 u8cc[0] = 0;
3325 c = 0xc0;
3326 }
3327 else
3328 mb_utf8 = FALSE; // don't draw as UTF-8
3329 }
3330 else if (c != NUL)
3331 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003332 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3333 if (wlv.n_extra == 0)
3334 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003335#ifdef FEAT_RIGHTLEFT
3336 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003337 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003338#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003339 wlv.c_extra = NUL;
3340 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003341#ifdef FEAT_LINEBREAK
3342 if (wp->w_p_lbr)
3343 {
3344 char_u *p;
3345
Bram Moolenaar1306b362022-08-06 15:59:06 +01003346 c = *wlv.p_extra;
3347 p = alloc(wlv.n_extra + 1);
3348 vim_memset(p, ' ', wlv.n_extra);
3349 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3350 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003351 vim_free(wlv.p_extra_free);
3352 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003353 }
3354 else
3355#endif
3356 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003357 wlv.n_extra = byte2cells(c) - 1;
3358 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003359 }
3360 if (!attr_pri)
3361 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003362 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003363 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003364 HL_ATTR(HLF_8));
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003365#ifdef FEAT_PROP_POPUP
3366 if (text_prop_type != NULL &&
3367 text_prop_flags & PT_FLAG_OVERRIDE)
3368 wlv.extra_attr = hl_combine_attr(text_prop_attr, wlv.extra_attr);
3369#endif
3370
Bram Moolenaar1306b362022-08-06 15:59:06 +01003371 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003372 }
3373 mb_utf8 = FALSE; // don't draw as UTF-8
3374 }
3375 else if (VIsual_active
3376 && (VIsual_mode == Ctrl_V
3377 || VIsual_mode == 'v')
3378 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003379 && wlv.tocol != MAXCOL
3380 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003381 && (
3382#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003383 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003384#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003385 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003386 {
3387 c = ' ';
3388 --ptr; // put it back at the NUL
3389 }
3390#if defined(LINE_ATTR)
3391 else if ((
3392# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003393 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003394# endif
3395# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003396 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003397# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003398 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003399 ) && (
3400# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003401 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003402# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003403 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003404# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003405 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003406# endif
3407 < wp->w_width)))
3408 {
3409 // Highlight until the right side of the window
3410 c = ' ';
3411 --ptr; // put it back at the NUL
3412
3413 // Remember we do the char for line highlighting.
3414 ++did_line_attr;
3415
3416 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003417 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003418 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003419 || (wp->w_p_list &&
3420 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003421 wlv.char_attr = wlv.line_attr;
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003422#ifdef FEAT_SIGNS
3423 // At end of line: if Sign is present with line highlight, reset char_attr
Christian Brabandte1eaae22023-08-19 22:36:12 +02003424 // but not when cursorline is active
3425 if (sign_present && wlv.sattr.sat_linehl > 0 && wlv.draw_state == WL_LINE
3426 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum))
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003427 wlv.char_attr = wlv.sattr.sat_linehl;
3428#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003429# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003430 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003431 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003432 wlv.diff_hlf = HLF_CHD;
3433 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003434 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003435 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003436 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3437 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003438 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003439 || (wlv.vcol >= left_curline_col
3440 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003441 wlv.char_attr = hl_combine_attr(
3442 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003443 }
3444 }
3445# endif
3446# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003447 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003448 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003449 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003450 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3451 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003452 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003453 if (!wlv.cul_screenline
3454 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003455 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003456 wlv.char_attr = hl_combine_attr(
3457 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003458 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003459 else if (wlv.line_attr)
3460 wlv.char_attr = hl_combine_attr(
3461 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003462 }
3463# endif
3464 }
3465#endif
3466 }
3467
3468#ifdef FEAT_CONCEAL
3469 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003470 && (wp != curwin || lnum != wp->w_cursor.lnum
3471 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003472 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3473 && !(lnum_in_visual_area
3474 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3475 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003476 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003477 if (((prev_syntax_id != syntax_seqnr
3478 && (syntax_flags & HL_CONCEAL) != 0)
3479 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003480 && (syn_get_sub_char() != NUL
3481 || (has_match_conc && match_conc)
3482 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003483 && wp->w_p_cole != 3)
3484 {
3485 // First time at this concealed item: display one
3486 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003487 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003488 c = match_conc;
3489 else if (syn_get_sub_char() != NUL)
3490 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003491 else if (wp->w_lcs_chars.conceal != NUL)
3492 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003493 else
3494 c = ' ';
3495
3496 prev_syntax_id = syntax_seqnr;
3497
Bram Moolenaar1306b362022-08-06 15:59:06 +01003498 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003499 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003500 wlv.vcol += wlv.n_extra;
3501 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003502 {
3503# ifdef FEAT_RIGHTLEFT
3504 if (wp->w_p_rl)
3505 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003506 wlv.col -= wlv.n_extra;
3507 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003508 }
3509 else
3510# endif
3511 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003512 wlv.boguscols += wlv.n_extra;
3513 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003514 }
3515 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003516 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003517 n_attr = 0;
3518 }
zeertzjqb557f482023-08-22 22:07:34 +02003519 else if (skip_cells == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003520 {
3521 is_concealing = TRUE;
zeertzjqb557f482023-08-22 22:07:34 +02003522 skip_cells = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003523 }
3524 mb_c = c;
3525 if (enc_utf8 && utf_char2len(c) > 1)
3526 {
3527 mb_utf8 = TRUE;
3528 u8cc[0] = 0;
3529 c = 0xc0;
3530 }
3531 else
3532 mb_utf8 = FALSE; // don't draw as UTF-8
3533 }
3534 else
3535 {
3536 prev_syntax_id = 0;
3537 is_concealing = FALSE;
3538 }
3539
zeertzjqb557f482023-08-22 22:07:34 +02003540 if (skip_cells > 0 && did_decrement_ptr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003541 // not showing the '>', put pointer back to avoid getting stuck
3542 ++ptr;
3543
3544#endif // FEAT_CONCEAL
3545 }
3546
3547#ifdef FEAT_CONCEAL
3548 // In the cursor line and we may be concealing characters: correct
3549 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003550 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003551 && wp == curwin && lnum == wp->w_cursor.lnum
3552 && conceal_cursor_line(wp)
zeertzjqb557f482023-08-22 22:07:34 +02003553 && (int)wp->w_virtcol <= wlv.vcol + skip_cells)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003554 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003555# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003556 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003557 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003558 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003559# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003560 wp->w_wcol = wlv.col - wlv.boguscols;
3561 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003562 did_wcol = TRUE;
3563 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003564# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003565 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003566# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003567 }
3568#endif
3569
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003570 // Use "wlv.extra_attr", but don't override visual selection
3571 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003572 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3573 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003574 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003575 && (!attr_pri
3576#ifdef FEAT_PROP_POPUP
3577 || (text_prop_flags & PT_FLAG_OVERRIDE)
3578#endif
3579 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003580 {
3581#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003582 if (wlv.line_attr)
3583 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003584 else
3585#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003586 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003587#ifdef FEAT_PROP_POPUP
3588 if (reset_extra_attr)
3589 {
3590 reset_extra_attr = FALSE;
3591 wlv.extra_attr = 0;
3592 }
3593#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003594 }
3595
3596#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3597 // XIM don't send preedit_start and preedit_end, but they send
3598 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3599 // im_is_preediting() here.
3600 if (p_imst == IM_ON_THE_SPOT
3601 && xic != NULL
3602 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003603 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003604 && !p_imdisable
3605 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003606 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003607 {
3608 colnr_T tcol;
3609
3610 if (preedit_end_col == MAXCOL)
3611 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3612 else
3613 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003614 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003615 {
3616 if (feedback_old_attr < 0)
3617 {
3618 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003619 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003620 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003621 wlv.char_attr = im_get_feedback_attr(feedback_col);
3622 if (wlv.char_attr < 0)
3623 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003624 feedback_col++;
3625 }
3626 else if (feedback_old_attr >= 0)
3627 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003628 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003629 feedback_old_attr = -1;
3630 feedback_col = 0;
3631 }
3632 }
3633#endif
3634 // Handle the case where we are in column 0 but not on the first
3635 // character of the line and the user wants us to show us a
3636 // special character (via 'listchars' option "precedes:<char>".
3637 if (lcs_prec_todo != NUL
3638 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003639 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3640 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003641#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003642 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003643#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003644 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003645 && c != NUL)
3646 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003647 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003648 lcs_prec_todo = NUL;
3649 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3650 {
3651 // Double-width character being overwritten by the "precedes"
3652 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003653 wlv.c_extra = MB_FILLER_CHAR;
3654 wlv.c_final = NUL;
3655 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003656 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003657 wlv.extra_attr =
3658 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003659 }
3660 mb_c = c;
3661 if (enc_utf8 && utf_char2len(c) > 1)
3662 {
3663 mb_utf8 = TRUE;
3664 u8cc[0] = 0;
3665 c = 0xc0;
3666 }
3667 else
3668 mb_utf8 = FALSE; // don't draw as UTF-8
3669 if (!attr_pri)
3670 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003671 saved_attr3 = wlv.char_attr; // save current attr
3672 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003673 n_attr3 = 1;
3674 }
3675 }
3676
3677 // At end of the text line or just after the last character.
3678 if ((c == NUL
3679#if defined(LINE_ATTR)
3680 || did_line_attr == 1
3681#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003682 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003683 {
3684#ifdef FEAT_SEARCH_EXTRA
3685 // flag to indicate whether prevcol equals startcol of search_hl or
3686 // one of the matches
3687 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3688 (long)(ptr - line) - (c == NUL));
3689#endif
3690 // Invert at least one char, used for Visual and empty line or
3691 // highlight match at end of line. If it's beyond the last
3692 // char on the screen, just overwrite that one (tricky!) Not
3693 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003694 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003695 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003696 && (VIsual_mode != Ctrl_V
3697 || lnum == VIsual.lnum
3698 || lnum == curwin->w_cursor.lnum)
3699 && c == NUL)
3700#ifdef FEAT_SEARCH_EXTRA
3701 // highlight 'hlsearch' match at end of line
3702 || (prevcol_hl_flag
3703# ifdef FEAT_SYN_HL
3704 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3705 && !(wp == curwin && VIsual_active))
3706# endif
3707# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003708 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003709# endif
3710# if defined(LINE_ATTR)
3711 && did_line_attr <= 1
3712# endif
3713 )
3714#endif
3715 ))
3716 {
3717 int n = 0;
3718
3719#ifdef FEAT_RIGHTLEFT
3720 if (wp->w_p_rl)
3721 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003722 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003723 n = 1;
3724 }
3725 else
3726#endif
3727 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003728 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003729 n = -1;
3730 }
3731 if (n != 0)
3732 {
3733 // At the window boundary, highlight the last character
3734 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003735 wlv.off += n;
3736 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003737 }
3738 else
3739 {
3740 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003741 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003742 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003743 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003744 }
3745#ifdef FEAT_SEARCH_EXTRA
3746 if (area_attr == 0)
3747 {
3748 // Use attributes from match with highest priority among
3749 // 'search_hl' and the match list.
3750 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003751 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003752 }
3753#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003754 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003755 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003756#ifdef FEAT_RIGHTLEFT
3757 if (wp->w_p_rl)
3758 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003759 --wlv.col;
3760 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003761 }
3762 else
3763#endif
3764 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003765 ++wlv.col;
3766 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003767 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003768 ++wlv.vcol;
3769 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003770 }
3771 }
3772
3773 // At end of the text line.
3774 if (c == NUL)
3775 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003776#ifdef FEAT_PROP_POPUP
3777 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003778 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003779 // Put the pointer back to the NUL.
3780 --ptr;
3781 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003782 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003783 else
3784#endif
3785 {
3786 draw_screen_line(wp, &wlv);
3787
3788 // Update w_cline_height and w_cline_folded if the cursor line
3789 // was updated (saves a call to plines() later).
3790 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3791 {
3792 curwin->w_cline_row = startrow;
3793 curwin->w_cline_height = wlv.row - startrow;
3794#ifdef FEAT_FOLDING
3795 curwin->w_cline_folded = FALSE;
3796#endif
3797 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3798 }
3799 break;
3800 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003801 }
3802
3803 // Show "extends" character from 'listchars' if beyond the line end and
3804 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003805 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003806 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003807 && wp->w_p_list
3808 && !wp->w_p_wrap
3809#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003810 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003811#endif
3812 && (
3813#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003814 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003815#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003816 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003817 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003818 || lcs_eol_one > 0
3819 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
zeertzjq6a389722023-08-27 19:04:14 +02003820 || *wlv.p_extra != NUL))
3821#ifdef FEAT_PROP_POPUP
zeertzjq4e26a9a2023-12-03 17:50:47 +01003822 || text_prop_next <= last_textprop_text_idx
zeertzjq6a389722023-08-27 19:04:14 +02003823#endif
3824 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003825 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003826 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003827 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003828 mb_c = c;
3829 if (enc_utf8 && utf_char2len(c) > 1)
3830 {
3831 mb_utf8 = TRUE;
3832 u8cc[0] = 0;
3833 c = 0xc0;
3834 }
3835 else
3836 mb_utf8 = FALSE;
3837 }
3838
3839#ifdef FEAT_SYN_HL
3840 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003841 if (wlv.draw_color_col)
3842 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003843
3844 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3845 // highlight the cursor position itself.
3846 // Also highlight the 'colorcolumn' if it is different than
3847 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003848 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3849 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003850 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003851 if (((wlv.draw_state == WL_LINE
3852 || wlv.draw_state == WL_BRI
3853 || wlv.draw_state == WL_SBR)
3854 && !lnum_in_visual_area
3855 && search_attr == 0
3856 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003857# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003858 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003859# endif
3860 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003861 {
3862 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3863 && lnum != wp->w_cursor.lnum)
3864 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003865 vcol_save_attr = wlv.char_attr;
3866 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3867 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003868 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003869 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003870 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003871 vcol_save_attr = wlv.char_attr;
3872 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003873 }
3874 }
3875#endif
3876
zeertzjq8fc6a1d2023-08-20 18:12:54 +02003877 if (wlv.draw_state == WL_LINE)
3878 vcol_prev = wlv.vcol;
3879
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003880 // Store character to be displayed.
3881 // Skip characters that are left of the screen for 'nowrap'.
zeertzjqb557f482023-08-22 22:07:34 +02003882 if (wlv.draw_state < WL_LINE || skip_cells <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003883 {
3884 // Store the character.
3885#if defined(FEAT_RIGHTLEFT)
3886 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3887 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003888 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003889 --wlv.off;
3890 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003891 }
3892#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003893 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003894 if (enc_dbcs == DBCS_JPNU)
3895 {
3896 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003897 ScreenLines[wlv.off] = 0x8e;
3898 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003899 }
3900 else if (enc_utf8)
3901 {
3902 if (mb_utf8)
3903 {
3904 int i;
3905
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003906 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003907 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003908 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003909 for (i = 0; i < Screen_mco; ++i)
3910 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003911 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003912 if (u8cc[i] == 0)
3913 break;
3914 }
3915 }
3916 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003917 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003918 }
3919 if (multi_attr)
3920 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003921 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003922 multi_attr = 0;
3923 }
3924 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003925 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003926
zeertzjqdb54e982023-09-21 16:33:09 +02003927 if (wlv.draw_state > WL_NR
3928#ifdef FEAT_DIFF
3929 && wlv.filler_todo <= 0
3930#endif
3931 )
3932 ScreenCols[wlv.off] = wlv.vcol;
3933 else
3934 ScreenCols[wlv.off] = -1;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003935
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003936 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3937 {
3938 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003939 ++wlv.off;
3940 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003941 if (enc_utf8)
3942 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003943 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003944 else
3945 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003946 ScreenLines[wlv.off] = mb_c & 0xff;
zeertzjqdb54e982023-09-21 16:33:09 +02003947
Bram Moolenaar1306b362022-08-06 15:59:06 +01003948 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003949#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003950 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003951#endif
3952 )
zeertzjqdb54e982023-09-21 16:33:09 +02003953 ScreenCols[wlv.off] = ++wlv.vcol;
3954 else
3955 ScreenCols[wlv.off] = -1;
3956
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003957 // When "wlv.tocol" is halfway a character, set it to the end
3958 // of the character, otherwise highlighting won't stop.
3959 if (wlv.tocol == wlv.vcol)
3960 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003961
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003962#ifdef FEAT_RIGHTLEFT
3963 if (wp->w_p_rl)
3964 {
3965 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003966 --wlv.off;
3967 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003968 }
3969#endif
3970 }
3971#ifdef FEAT_RIGHTLEFT
3972 if (wp->w_p_rl)
3973 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003974 --wlv.off;
3975 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003976 }
3977 else
3978#endif
3979 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003980 ++wlv.off;
3981 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003982 }
3983 }
3984#ifdef FEAT_CONCEAL
3985 else if (wp->w_p_cole > 0 && is_concealing)
3986 {
zeertzjqb557f482023-08-22 22:07:34 +02003987 --skip_cells;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003988 ++wlv.vcol_off_co;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003989 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003990 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003991 if (wp->w_p_wrap)
3992 {
3993 // Special voodoo required if 'wrap' is on.
3994 //
3995 // Advance the column indicator to force the line
3996 // drawing to wrap early. This will make the line
3997 // take up the same screen space when parts are concealed,
3998 // so that cursor line computations aren't messed up.
3999 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004000 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004001 // trailing junk to be written out of the screen line
4002 // we are building, 'boguscols' keeps track of the number
4003 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004004 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004005 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004006 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004007# ifdef FEAT_RIGHTLEFT
4008 if (wp->w_p_rl)
4009 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004010 wlv.col -= wlv.n_extra;
4011 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004012 }
4013 else
4014# endif
4015 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004016 wlv.col += wlv.n_extra;
4017 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004018 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01004019 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004020 n_attr = 0;
4021 }
4022
4023
4024 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
4025 {
4026 // Need to fill two screen columns.
4027# ifdef FEAT_RIGHTLEFT
4028 if (wp->w_p_rl)
4029 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004030 --wlv.boguscols;
4031 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004032 }
4033 else
4034# endif
4035 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004036 ++wlv.boguscols;
4037 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004038 }
4039 }
4040
4041# ifdef FEAT_RIGHTLEFT
4042 if (wp->w_p_rl)
4043 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004044 --wlv.boguscols;
4045 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004046 }
4047 else
4048# endif
4049 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004050 ++wlv.boguscols;
4051 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004052 }
4053 }
4054 else
4055 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004056 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004057 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004058 wlv.vcol += wlv.n_extra;
4059 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004060 n_attr = 0;
4061 }
4062 }
4063
4064 }
4065#endif // FEAT_CONCEAL
4066 else
zeertzjqb557f482023-08-22 22:07:34 +02004067 --skip_cells;
4068
4069 if (wlv.draw_state > WL_NR && skipped_cells > 0)
4070 {
4071 wlv.vcol += skipped_cells;
4072 skipped_cells = 0;
4073 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004074
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004075 // Only advance the "wlv.vcol" when after the 'number' or
4076 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004077 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004078#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004079 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004080#endif
4081 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004082 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004083
4084#ifdef FEAT_SYN_HL
4085 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004086 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004087#endif
4088
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004089 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01004090 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
4091 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004092
4093 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01004094 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004095 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004096 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004097 if (wlv.n_attr_skip > 0)
4098 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004099
4100 // At end of screen line and there is more to come: Display the line
4101 // so far. If there is no more to display it is caught above.
4102 if ((
4103#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004104 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004105#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004106 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01004107 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02004108 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004109#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004110 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004111#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004112#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004113 || text_prop_above || text_prop_follows
zeertzjq4e26a9a2023-12-03 17:50:47 +01004114 || text_prop_next <= last_textprop_text_idx
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004115#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01004116 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01004117 && lcs_eol_one != -1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004118 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
4119 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004120 )
4121 {
4122#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01004123 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01004124 wlv_screen_line(wp, &wlv, FALSE);
4125 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004126 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004127 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004128#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01004129 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004130#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004131 ++wlv.row;
4132 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004133
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01004134 // When not wrapping and finished diff lines, break here.
4135 if (!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004136#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004137 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004138#endif
4139#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01004140 && !text_prop_above
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01004141 && !text_prop_follows
Bram Moolenaar877151b2022-10-11 15:29:50 +01004142#endif
4143 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004144 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004145#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004146 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004147 {
4148 // do not output more of the line, only the "below" prop
4149 ptr += STRLEN(ptr);
4150# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004151 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004152# endif
4153 }
4154#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004155
4156 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004157 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004158#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004159 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004160#endif
4161 )
4162 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004163 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
4164 draw_vsep_win(wp, wlv.row);
4165 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004166 }
4167
4168 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004169 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004170 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004171 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004172 break;
4173 }
4174
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004175 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004176#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004177 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004178#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004179#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004180 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004181#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004182 && wp->w_width == Columns)
4183 {
4184 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004185 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004186
4187 // Special trick to make copy/paste of wrapped lines work with
4188 // xterm/screen: write an extra character beyond the end of
4189 // the line. This will work with all terminal types
4190 // (regardless of the xn,am settings).
4191 // Only do this on a fast tty.
4192 // Only do this if the cursor is on the current line
4193 // (something has been written in it).
4194 // Don't do this for the GUI.
4195 // Don't do this for double-width characters.
4196 // Don't do this for a window not at the right screen border.
4197 if (p_tf
4198#ifdef FEAT_GUI
4199 && !gui.in_use
4200#endif
4201 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004202 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4203 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004204 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004205 || (*mb_off2cells)(
4206 LineOffset[wlv.screen_row - 1]
4207 + (int)Columns - 2,
4208 LineOffset[wlv.screen_row]
4209 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004210 {
4211 // First make sure we are at the end of the screen line,
4212 // then output the same character again to let the
4213 // terminal know about the wrap. If the terminal doesn't
4214 // auto-wrap, we overwrite the character.
4215 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004216 screen_char(LineOffset[wlv.screen_row - 1]
4217 + (unsigned)Columns - 1,
4218 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004219
4220 // When there is a multi-byte character, just output a
4221 // space to keep it simple.
4222 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004223 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004224 out_char(' ');
4225 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004226 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004227 + (Columns - 1)]);
4228 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004229 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004230 screen_start(); // don't know where cursor is now
4231 }
4232 }
4233
Bram Moolenaar1306b362022-08-06 15:59:06 +01004234 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004235
Bram Moolenaareed9d462021-02-15 20:38:25 +01004236 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004237#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004238 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004239# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004240 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004241# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004242 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004243 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004244#endif
4245#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004246 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004247 // When the filler lines are actually below the last line of the
4248 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004249 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004250 break;
4251#endif
4252 }
4253
4254 } // for every character in the line
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004255#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004256 vim_free(text_props);
4257 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004258 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004259#endif
4260
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004261 vim_free(wlv.p_extra_free);
zeertzjq58e1e012023-06-04 18:46:28 +01004262 vim_free(wlv.saved_p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004263 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004264}