blob: 309fcd446930ffc59c6ce16af8bec194171ca7c5 [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
501 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
502# ifdef FEAT_DIFF
503 && wlv->filler_lines == 0
504# endif
505# ifdef FEAT_PROP_POPUP
506 && !wlv->dont_use_showbreak
507# endif
508 )
509 {
510 wlv->char_attr = 0;
511# ifdef FEAT_DIFF
512 if (wlv->diff_hlf != (hlf_T)0)
513 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
514# endif
515 wlv->p_extra = NULL;
516 wlv->c_extra = ' ';
517 wlv->c_final = NUL;
518 wlv->n_extra = get_breakindent_win(wp,
519 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
520 if (wlv->row == wlv->startrow)
521 {
522 wlv->n_extra -= win_col_off2(wp);
523 if (wlv->n_extra < 0)
524 wlv->n_extra = 0;
525 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100526 if (wp->w_skipcol > 0 && wlv->startrow == 0
527 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100528 wlv->need_showbreak = FALSE;
529 // Correct end of highlighted area for 'breakindent',
530 // required when 'linebreak' is also set.
531 if (wlv->tocol == wlv->vcol)
532 wlv->tocol += wlv->n_extra;
533 }
534 }
535}
536#endif
537
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100538#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
539 static void
540handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
541{
542# ifdef FEAT_DIFF
543 if (wlv->filler_todo > 0)
544 {
545 // Draw "deleted" diff line(s).
546 if (char2cells(wp->w_fill_chars.diff) > 1)
547 {
548 wlv->c_extra = '-';
549 wlv->c_final = NUL;
550 }
551 else
552 {
553 wlv->c_extra = wp->w_fill_chars.diff;
554 wlv->c_final = NUL;
555 }
556# ifdef FEAT_RIGHTLEFT
557 if (wp->w_p_rl)
558 wlv->n_extra = wlv->col + 1;
559 else
560# endif
561 wlv->n_extra = wp->w_width - wlv->col;
562 wlv->char_attr = HL_ATTR(HLF_DED);
563 }
564# endif
565
566# ifdef FEAT_LINEBREAK
567 char_u *sbr = get_showbreak_value(wp);
568 if (*sbr != NUL && wlv->need_showbreak)
569 {
570 // Draw 'showbreak' at the start of each broken line.
571 wlv->p_extra = sbr;
572 wlv->c_extra = NUL;
573 wlv->c_final = NUL;
574 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100575 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100576 wlv->need_showbreak = FALSE;
577 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100578
579 // Correct start of highlighted area for 'showbreak'.
580 if (wlv->fromcol >= wlv->vcol && wlv->fromcol < wlv->vcol_sbr)
581 wlv->fromcol = wlv->vcol_sbr;
582
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100583 // Correct end of highlighted area for 'showbreak',
584 // required when 'linebreak' is also set.
585 if (wlv->tocol == wlv->vcol)
586 wlv->tocol += wlv->n_extra;
587 // combine 'showbreak' with 'wincolor'
588 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
589# ifdef FEAT_SYN_HL
590 // combine 'showbreak' with 'cursorline'
591 if (wlv->cul_attr != 0)
592 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
593# endif
594 }
595# endif
596}
597#endif
598
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100599#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100600/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100601 * Return the cell size of virtual text after truncation.
602 */
603 static int
604textprop_size_after_trunc(
605 win_T *wp,
606 int flags, // TP_FLAG_ALIGN_*
607 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100608 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100609 char_u *text,
610 int *n_used_ptr)
611{
612 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100613 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100614 int len = (int)STRLEN(text);
615 int strsize = 0;
616 int n_used;
617
Bram Moolenaar7e017462022-10-11 21:02:09 +0100618 // if the remaining size is to small and 'wrap' is set we wrap anyway and
619 // use the next line
620 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100621 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100622 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100623 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100624 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
625 {
626 int clen = ptr2cells(text + n_used);
627
628 if (strsize + clen > space)
629 break;
630 strsize += clen;
631 }
632 *n_used_ptr = n_used;
633 return strsize;
634}
635
636/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100637 * Take care of padding, right-align and truncation of virtual text after a
638 * line.
639 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
640 * padding, right-align and truncation. Otherwise only the size is computed.
641 * When "n_attr" is NULL returns the number of screen cells used.
642 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100643 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100644 int
645text_prop_position(
646 win_T *wp,
647 textprop_T *tp,
porygonisaduck38854b52022-11-27 20:55:05 +0000648 int vcol, // current text column
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100649 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100650 int *n_extra, // nr of bytes for virtual text
651 char_u **p_extra, // virtual text
652 int *n_attr, // attribute cells, NULL if not used
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000653 int *n_attr_skip, // cells to skip attr, NULL if not used
654 int do_skip) // skip_cells is not zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200655{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100656 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100657 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100658 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
Bram Moolenaar1aeb3eb2023-01-01 14:04:51 +0000659 int wrap = tp->tp_col < MAXCOL || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100660 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
porygonisaduck38854b52022-11-27 20:55:05 +0000661 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100662 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100663 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100664 int before = room; // spaces before the text
665 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100666 int n_used = *n_extra;
667 char_u *l = NULL;
668 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100669 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100670 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200671
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100672 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100673 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100674 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100675
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100676 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100677 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100678 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100679 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar2354b662023-04-23 21:42:25 +0100680 if (after < 0)
681 {
682 // text "above" has too much padding to fit
683 padding += after;
684 after = 0;
685 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100686 }
687 else
688 {
689 // Right-align: fill with before
690 if (right)
691 before -= cells;
porygonisaduck38854b52022-11-27 20:55:05 +0000692
693 // Below-align: empty line add one character
Bram Moolenaar7c02ad92022-11-29 21:37:13 +0000694 if (below && vcol == 0 && col_with_padding == col_off
695 && wp->w_width - col_off == before)
696 col_with_padding += 1;
porygonisaduck38854b52022-11-27 20:55:05 +0000697
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100698 if (before < 0
699 || !(right || below)
porygonisaduck38854b52022-11-27 20:55:05 +0000700 || (below ? (col_with_padding <= col_off || !wp->w_p_wrap)
701 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100702 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100703 if (right && (wrap
704 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100705 {
706 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100707 before = wp->w_width - col_off - strsize + room;
708 if (before < 0)
709 before = 0;
710 else
711 n_used = *n_extra;
712 }
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000713 else if (below && before > vcol && do_skip)
714 before -= vcol;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100715 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100716 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100717 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100718 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100719
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100720 // With 'nowrap' add one to show the "extends" character if needed (it
721 // doesn't show if the text just fits).
722 if (!wp->w_p_wrap
723 && n_used < *n_extra
724 && wp->w_lcs_chars.ext != NUL
725 && wp->w_p_list)
726 ++n_used;
727
728 // add 1 for NUL, 2 for when '…' is used
729 if (n_attr != NULL)
Christian Brabandtf1cc4d52023-08-12 00:14:14 +0200730 l = alloc(n_used + before + after + (padding > 0 ? padding : 0) + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100731 if (n_attr == NULL || l != NULL)
732 {
733 int off = 0;
734
735 if (n_attr != NULL)
736 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100737 vim_memset(l, ' ', before);
738 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100739 if (padding > 0)
740 {
741 vim_memset(l + off, ' ', padding);
742 off += padding;
743 }
744 vim_strncpy(l + off, *p_extra, n_used);
745 off += n_used;
746 }
747 else
748 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100749 off = before + after + padding + n_used;
750 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100751 }
752 if (n_attr != NULL)
753 {
754 if (n_used < *n_extra && wp->w_p_wrap)
755 {
756 char_u *lp = l + off - 1;
757
758 if (has_mbyte)
759 {
h-east4c42c7e2023-04-17 21:44:57 +0100760 char_u buf[MB_MAXBYTES + 1];
761 char_u *cp = buf;
762
763 // change the last character to '…', converted to the
764 // current 'encoding'
765 STRCPY(buf, "…");
766 if (!enc_utf8)
767 {
768 vimconv_T vc;
769
770 vc.vc_type = CONV_NONE;
771 convert_setup(&vc, (char_u *)"utf-8", p_enc);
772 if (vc.vc_type != CONV_NONE)
773 {
774 cp = string_convert(&vc, buf, NULL);
775 if (cp == NULL)
776 {
777 // when conversion fails use '>'
778 cp = buf;
779 STRCPY(buf, ">");
780 }
781 convert_setup(&vc, NULL, NULL);
782 }
783 }
784
785 lp -= (*mb_ptr2cells)(cp) - 1;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100786 lp -= (*mb_head_off)(l, lp);
h-east4c42c7e2023-04-17 21:44:57 +0100787 STRCPY(lp, cp);
Bram Moolenaar13845c42022-10-09 15:26:03 +0100788 n_used = lp - l + 3 - before - padding;
h-east4c42c7e2023-04-17 21:44:57 +0100789 if (cp != buf)
790 vim_free(cp);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100791 }
792 else
793 // change last character to '>'
794 *lp = '>';
795 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100796 else if (after > 0)
797 {
798 vim_memset(l + off, ' ', after);
799 l[off + after] = NUL;
800 }
801
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100802 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100803 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100804 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100805 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100806 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100807
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000808 // n_attr_skip will not be decremented before draw_state is
809 // WL_LINE
Christian Brabandtf1cc4d52023-08-12 00:14:14 +0200810 *n_attr_skip = before + (padding > 0 ? padding : 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100811 }
812 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100813 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100814
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100815 if (n_attr == NULL)
816 return cells;
817 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200818}
819#endif
820
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100821/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100822 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100823 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
824 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100825 */
826 static void
827wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
828{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100829 if (wlv->row == 0 && wp->w_skipcol > 0
830#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100831 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100832 && *get_showbreak_value(wp) == NUL
833#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100834 // do not overwrite the 'listchars' "precedes" text with "<<<"
835 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100836 {
837 int off = (int)(current_ScreenLine - ScreenLines);
zeertzjqecb87dd2023-06-03 19:45:06 +0100838 int max_off = off + screen_Columns;
Bram Moolenaareb4de622022-10-15 13:42:17 +0100839 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100840
Bram Moolenaareb4de622022-10-15 13:42:17 +0100841 if (wp->w_p_nu && wp->w_p_rnu)
842 // Do not overwrite the line number, change "123 text" to
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100843 // "123<<<xt".
Bram Moolenaareb4de622022-10-15 13:42:17 +0100844 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
845 {
846 ++off;
847 ++skip;
848 }
849
850 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100851 {
zeertzjqecb87dd2023-06-03 19:45:06 +0100852 if ((*mb_off2cells)(off, max_off) > 1)
853 // When the first half of a double-width character is
854 // overwritten, change the second half to a space.
855 ScreenLines[off + 1] = ' ';
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100856 ScreenLines[off] = '<';
857 if (enc_utf8)
858 ScreenLinesUC[off] = 0;
859 ScreenAttrs[off] = HL_ATTR(HLF_AT);
860 ++off;
861 }
862 }
863
864 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
865 negative_width ? -wp->w_width : wp->w_width,
866 wlv->screen_line_flags);
867}
868
869/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100870 * Called when finished with the line: draw the screen line and handle any
871 * highlighting until the right of the window.
872 */
873 static void
874draw_screen_line(win_T *wp, winlinevars_T *wlv)
875{
876#ifdef FEAT_SYN_HL
877 long v;
878
879 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
880 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100881 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100882 else
883 v = wp->w_leftcol;
884
885 // check if line ends before left margin
886 if (wlv->vcol < v + wlv->col - win_col_off(wp))
887 wlv->vcol = v + wlv->col - win_col_off(wp);
888# ifdef FEAT_CONCEAL
889 // Get rid of the boguscols now, we want to draw until the right
890 // edge for 'cursorcolumn'.
891 wlv->col -= wlv->boguscols;
892 wlv->boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000893# define VCOL_HLC (wlv->vcol - wlv->vcol_off_co - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100894# else
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000895# define VCOL_HLC (wlv->vcol - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100896# endif
897
898 if (wlv->draw_color_col)
899 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
900
901 if (((wp->w_p_cuc
902 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
903 && (int)wp->w_virtcol <
904 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
905 && wlv->lnum != wp->w_cursor.lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000906 || wlv->draw_color_col
907# ifdef LINE_ATTR
908 || wlv->line_attr != 0
909# endif
910 || wlv->win_attr != 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100911# ifdef FEAT_RIGHTLEFT
912 && !wp->w_p_rl
913# endif
914 )
915 {
916 int rightmost_vcol = 0;
917 int i;
918
919 if (wp->w_p_cuc)
920 rightmost_vcol = wp->w_virtcol;
921 if (wlv->draw_color_col)
922 // determine rightmost colorcolumn to possibly draw
923 for (i = 0; wlv->color_cols[i] >= 0; ++i)
924 if (rightmost_vcol < wlv->color_cols[i])
925 rightmost_vcol = wlv->color_cols[i];
926
927 while (wlv->col < wp->w_width)
928 {
929 ScreenLines[wlv->off] = ' ';
930 if (enc_utf8)
931 ScreenLinesUC[wlv->off] = 0;
932 ScreenCols[wlv->off] = MAXCOL;
933 ++wlv->col;
934 if (wlv->draw_color_col)
935 wlv->draw_color_col = advance_color_col(
936 VCOL_HLC, &wlv->color_cols);
937
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000938 int attr = wlv->win_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100939 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000940 attr = HL_ATTR(HLF_CUC);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100941 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000942 attr = HL_ATTR(HLF_MC);
943# ifdef LINE_ATTR
944 else if (wlv->line_attr != 0)
945 attr = wlv->line_attr;
946# endif
947 ScreenAttrs[wlv->off++] = attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100948
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000949 if (VCOL_HLC >= rightmost_vcol
950# ifdef LINE_ATTR
951 && wlv->line_attr == 0
952# endif
953 && wlv->win_attr == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100954 break;
955
956 ++wlv->vcol;
957 }
958 }
959#endif
960
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100961 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100962 ++wlv->row;
963 ++wlv->screen_row;
964}
965#undef VCOL_HLC
966
967/*
968 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100969 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100970 */
971 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100972win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100973{
974 wlv->col = 0;
975 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
Christian Brabandtdd75fcf2023-10-11 21:51:19 +0200976#ifdef FEAT_LINEBREAK
977 wlv->need_lbr = FALSE;
978#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100979
980#ifdef FEAT_RIGHTLEFT
981 if (wp->w_p_rl)
982 {
983 // Rightleft window: process the text in the normal direction, but put
984 // it in current_ScreenLine[] from right to left. Start at the
985 // rightmost column of the window.
986 wlv->col = wp->w_width - 1;
987 wlv->off += wlv->col;
988 wlv->screen_line_flags |= SLF_RIGHTLEFT;
989 }
990#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100991 if (save_extra)
992 {
993 // reset the drawing state for the start of a wrapped line
994 wlv->draw_state = WL_START;
995 wlv->saved_n_extra = wlv->n_extra;
996 wlv->saved_p_extra = wlv->p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +0100997 vim_free(wlv->saved_p_extra_free);
998 wlv->saved_p_extra_free = wlv->p_extra_free;
999 wlv->p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001000 wlv->saved_extra_attr = wlv->extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001001 wlv->saved_n_attr_skip = wlv->n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001002 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001003 wlv->saved_c_extra = wlv->c_extra;
1004 wlv->saved_c_final = wlv->c_final;
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02001005#ifdef FEAT_LINEBREAK
1006 wlv->need_lbr = TRUE;
1007#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001008#ifdef FEAT_SYN_HL
1009 if (!(wlv->cul_screenline
1010# ifdef FEAT_DIFF
1011 && wlv->diff_hlf == (hlf_T)0
1012# endif
1013 ))
1014 wlv->saved_char_attr = wlv->char_attr;
1015 else
1016#endif
1017 wlv->saved_char_attr = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001018
1019 // these are not used until restored in win_line_continue()
Bram Moolenaar1306b362022-08-06 15:59:06 +01001020 wlv->n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001021 wlv->n_attr_skip = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001022 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001023}
1024
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001025/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001026 * Called when wlv->draw_state is set to WL_LINE.
1027 */
1028 static void
1029win_line_continue(winlinevars_T *wlv)
1030{
1031 if (wlv->saved_n_extra > 0)
1032 {
1033 // Continue item from end of wrapped line.
1034 wlv->n_extra = wlv->saved_n_extra;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001035 wlv->saved_n_extra = 0;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001036 wlv->c_extra = wlv->saved_c_extra;
1037 wlv->c_final = wlv->saved_c_final;
1038 wlv->p_extra = wlv->saved_p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +01001039 vim_free(wlv->p_extra_free);
1040 wlv->p_extra_free = wlv->saved_p_extra_free;
1041 wlv->saved_p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001042 wlv->extra_attr = wlv->saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001043 wlv->n_attr_skip = wlv->saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001044 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001045 wlv->char_attr = wlv->saved_char_attr;
1046 }
1047 else
1048 wlv->char_attr = wlv->win_attr;
1049}
1050
zeertzjqb7acea12022-12-12 13:20:43 +00001051#ifdef FEAT_SYN_HL
1052 static void
1053apply_cursorline_highlight(
1054 winlinevars_T *wlv,
1055 int sign_present UNUSED)
1056{
1057 wlv->cul_attr = HL_ATTR(HLF_CUL);
1058# ifdef FEAT_SIGNS
1059 // Combine the 'cursorline' and sign highlighting, depending on
1060 // the sign priority.
1061 if (sign_present && wlv->sattr.sat_linehl > 0)
1062 {
1063 if (wlv->sattr.sat_priority >= 100)
1064 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1065 else
1066 wlv->line_attr = hl_combine_attr(wlv->line_attr, wlv->cul_attr);
1067 }
1068 else
1069# endif
1070# if defined(FEAT_QUICKFIX)
1071 // let the line attribute overrule 'cursorline', otherwise
1072 // it disappears when both have background set;
1073 // 'cursorline' can use underline or bold to make it show
1074 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1075# else
1076 wlv->line_attr = wlv->cul_attr;
1077# endif
1078}
1079#endif
1080
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001081/*
Luuk van Baal30805a12023-05-27 22:22:10 +01001082 * Display line "lnum" of window "wp" on the screen.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001083 * Start at row "startrow", stop when "endrow" is reached.
Luuk van Baal30805a12023-05-27 22:22:10 +01001084 * When "number_only" is TRUE only update the number column.
1085 * "spv" is used to store information for spell checking, kept between
1086 * sequential calls for the same window.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001087 * wp->w_virtcol needs to be valid.
1088 *
1089 * Return the number of last row the line occupies.
1090 */
1091 int
1092win_line(
1093 win_T *wp,
1094 linenr_T lnum,
1095 int startrow,
1096 int endrow,
Luuk van Baal30805a12023-05-27 22:22:10 +01001097 int number_only,
1098 spellvars_T *spv UNUSED)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001099{
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001100 winlinevars_T wlv; // variables passed between functions
1101
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001102 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001103 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001104 char_u *line; // current line
1105 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001106
Bram Moolenaar1306b362022-08-06 15:59:06 +01001107#ifdef FEAT_PROP_POPUP
1108 char_u *p_extra_free2 = NULL; // another p_extra to be freed
1109#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001110#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001111 int in_linebreak = FALSE; // n_extra set for showing linebreak
1112#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001113 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +01001114 // displaying eol at end-of-line
1115 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001116 int lcs_prec_todo = wp->w_lcs_chars.prec;
1117 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001118
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001119 int n_attr = 0; // chars with special attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001120 int saved_attr2 = 0; // char_attr saved for n_attr
1121 int n_attr3 = 0; // chars with overruling special attr
1122 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001123
zeertzjqb557f482023-08-22 22:07:34 +02001124 int skip_cells = 0; // nr of cells to skip for w_leftcol or
1125 // w_skipcol or concealing
1126 int skipped_cells = 0; // nr of skipped cells for virtual text
1127 // to be added to wlv.vcol later
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001128 int fromcol_prev = -2; // start of inverting after cursor
1129 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001130 int lnum_in_visual_area = FALSE;
1131 pos_T pos;
1132 long v;
1133
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001134 int attr_pri = FALSE; // char_attr has priority
1135 int area_highlighting = FALSE; // Visual or incsearch highlighting
1136 // in this line
1137 int vi_attr = 0; // attributes for Visual and incsearch
1138 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001139 int area_attr = 0; // attributes desired by highlighting
1140 int search_attr = 0; // attributes desired by 'hlsearch'
1141#ifdef FEAT_SYN_HL
1142 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1143 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001144 int prev_syntax_col = -1; // column of prev_syntax_attr
1145 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001146 int has_syntax = FALSE; // this buffer has syntax highl.
1147 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001148#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001149#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001150 int did_line = FALSE; // set to TRUE when line text done
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001151 int text_prop_count;
1152 int text_prop_next = 0; // next text property to use
1153 textprop_T *text_props = NULL;
1154 int *text_prop_idxs = NULL;
1155 int text_props_active = 0;
1156 proptype_T *text_prop_type = NULL;
1157 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001158 int text_prop_attr_comb = 0; // text_prop_attr combined with
1159 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001160 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001161 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001162 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001163 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001164 int saved_search_attr = 0; // search_attr to be used when n_extra
1165 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001166 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001167 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001168#endif
1169#ifdef FEAT_SPELL
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001170 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001171# define SPWORDLEN 150
1172 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1173 int nextlinecol = 0; // column where nextline[] starts
1174 int nextline_idx = 0; // index in nextline[] where next line
1175 // starts
1176 int spell_attr = 0; // attributes desired by spelling
1177 int word_end = 0; // last byte with same spell_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001178 int cur_checked_col = 0; // checked column for current line
1179#endif
1180 int extra_check = 0; // has extra highlighting
1181 int multi_attr = 0; // attributes desired by multibyte
1182 int mb_l = 1; // multi-byte byte length
1183 int mb_c = 0; // decoded multi-byte character
1184 int mb_utf8 = FALSE; // screen char is UTF-8 char
1185 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001186#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001187 int change_start = MAXCOL; // first col of changed area
1188 int change_end = -1; // last col of changed area
1189#endif
1190 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001191 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001192 int in_multispace = FALSE; // in multiple consecutive spaces
1193 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001194#ifdef LINE_ATTR
Bram Moolenaarbf915842022-08-06 22:38:02 +01001195 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001196#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001197 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001198 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001199#ifdef FEAT_ARABIC
1200 int prev_c = 0; // previous Arabic character
1201 int prev_c1 = 0; // first composing char for prev_c
1202#endif
1203#if defined(LINE_ATTR)
1204 int did_line_attr = 0;
1205#endif
1206#ifdef FEAT_TERMINAL
1207 int get_term_attr = FALSE;
1208#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001209
Martin Tournoijba43e762022-10-13 22:12:15 +01001210#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001211 // margin columns for the screen line, needed for when 'cursorlineopt'
1212 // contains "screenline"
1213 int left_curline_col = 0;
1214 int right_curline_col = 0;
1215#endif
1216
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001217#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1218 int feedback_col = 0;
1219 int feedback_old_attr = -1;
1220#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001221
1222#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1223 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001224#endif
1225#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001226 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001227#endif
1228#ifdef FEAT_CONCEAL
1229 int syntax_flags = 0;
1230 int syntax_seqnr = 0;
1231 int prev_syntax_id = 0;
1232 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1233 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001234 int did_wcol = FALSE;
1235 int old_boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001236# define VCOL_HLC (wlv.vcol - wlv.vcol_off_co - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001237# define FIX_FOR_BOGUSCOLS \
1238 { \
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001239 wlv.n_extra += wlv.vcol_off_co; \
1240 wlv.vcol -= wlv.vcol_off_co; \
1241 wlv.vcol_off_co = 0; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001242 wlv.col -= wlv.boguscols; \
1243 old_boguscols = wlv.boguscols; \
1244 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001245 }
1246#else
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001247# define VCOL_HLC (wlv.vcol - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001248#endif
1249
1250 if (startrow > endrow) // past the end already!
1251 return startrow;
1252
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001253 CLEAR_FIELD(wlv);
1254
1255 wlv.lnum = lnum;
1256 wlv.startrow = startrow;
1257 wlv.row = startrow;
1258 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001259 wlv.fromcol = -10;
1260 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001261#ifdef FEAT_LINEBREAK
1262 wlv.vcol_sbr = -1;
1263#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001264
1265 if (!number_only)
1266 {
1267 // To speed up the loop below, set extra_check when there is linebreak,
1268 // trailing white space and/or syntax processing to be done.
1269#ifdef FEAT_LINEBREAK
1270 extra_check = wp->w_p_lbr;
1271#endif
1272#ifdef FEAT_SYN_HL
1273 if (syntax_present(wp) && !wp->w_s->b_syn_error
1274# ifdef SYN_TIME_LIMIT
1275 && !wp->w_s->b_syn_slow
1276# endif
1277 )
1278 {
1279 // Prepare for syntax highlighting in this line. When there is an
1280 // error, stop syntax highlighting.
1281 save_did_emsg = did_emsg;
1282 did_emsg = FALSE;
1283 syntax_start(wp, lnum);
1284 if (did_emsg)
1285 wp->w_s->b_syn_error = TRUE;
1286 else
1287 {
1288 did_emsg = save_did_emsg;
1289#ifdef SYN_TIME_LIMIT
1290 if (!wp->w_s->b_syn_slow)
1291#endif
1292 {
1293 has_syntax = TRUE;
1294 extra_check = TRUE;
1295 }
1296 }
1297 }
1298
1299 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001300 wlv.color_cols = wp->w_p_cc_cols;
1301 if (wlv.color_cols != NULL)
1302 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001303#endif
1304
1305#ifdef FEAT_TERMINAL
1306 if (term_show_buffer(wp->w_buffer))
1307 {
1308 extra_check = TRUE;
1309 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001310 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001311 }
1312#endif
1313
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001314 // handle Visual active in this window
1315 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1316 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001317 pos_T *top, *bot;
1318
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001319 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1320 {
1321 // Visual is after curwin->w_cursor
1322 top = &curwin->w_cursor;
1323 bot = &VIsual;
1324 }
1325 else
1326 {
1327 // Visual is before curwin->w_cursor
1328 top = &VIsual;
1329 bot = &curwin->w_cursor;
1330 }
1331 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1332 if (VIsual_mode == Ctrl_V)
1333 {
1334 // block mode
1335 if (lnum_in_visual_area)
1336 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001337 wlv.fromcol = wp->w_old_cursor_fcol;
1338 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001339 }
1340 }
1341 else
1342 {
1343 // non-block mode
1344 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001345 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001346 else if (lnum == top->lnum)
1347 {
1348 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001349 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001350 else
1351 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001352 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001353 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001354 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001355 }
1356 }
1357 if (VIsual_mode != 'V' && lnum == bot->lnum)
1358 {
1359 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1360 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001361 wlv.fromcol = -10;
1362 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001363 }
1364 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001365 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001366 else
1367 {
1368 pos = *bot;
1369 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001370 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1371 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001372 else
1373 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001374 getvvcol(wp, &pos, NULL, NULL,
1375 (colnr_T *)&wlv.tocol);
1376 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001377 }
1378 }
1379 }
1380 }
1381
1382 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001383 if (!highlight_match && lnum == curwin->w_cursor.lnum
1384 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001385#ifdef FEAT_GUI
1386 && !gui.in_use
1387#endif
1388 )
1389 noinvcur = TRUE;
1390
1391 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001392 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001393 {
1394 area_highlighting = TRUE;
1395 vi_attr = HL_ATTR(HLF_V);
1396#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1397 if ((clip_star.available && !clip_star.owned
1398 && clip_isautosel_star())
1399 || (clip_plus.available && !clip_plus.owned
1400 && clip_isautosel_plus()))
1401 vi_attr = HL_ATTR(HLF_VNC);
1402#endif
1403 }
1404 }
1405
1406 // handle 'incsearch' and ":s///c" highlighting
1407 else if (highlight_match
1408 && wp == curwin
1409 && lnum >= curwin->w_cursor.lnum
1410 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1411 {
1412 if (lnum == curwin->w_cursor.lnum)
1413 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001414 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001415 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001416 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001417 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1418 {
1419 pos.lnum = lnum;
1420 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001421 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001422 }
1423 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001424 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001425 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001426 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1427 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001428 area_highlighting = TRUE;
1429 vi_attr = HL_ATTR(HLF_I);
1430 }
1431 }
1432
1433#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001434 wlv.filler_lines = diff_check(wp, lnum);
1435 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001436 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001437 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001438 {
1439 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001440 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001441 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001442 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001443 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001444 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001445 }
1446 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001447 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001448 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001449 area_highlighting = TRUE;
1450 }
1451 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001452 wlv.filler_lines = wp->w_topfill;
1453 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001454#endif
1455
1456#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001457 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001458 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001459 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001460#endif
1461
1462#ifdef LINE_ATTR
1463# ifdef FEAT_SIGNS
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001464 // If this line has a sign with line highlighting set wlv.line_attr.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001465 if (sign_present)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001466 wlv.line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001467# endif
1468# if defined(FEAT_QUICKFIX)
1469 // Highlight the current line in the quickfix window.
1470 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001471 wlv.line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001472# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001473 if (wlv.line_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001474 area_highlighting = TRUE;
1475#endif
1476
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001477#ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01001478 if (spv->spv_has_spell && !number_only)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001479 {
Luuk van Baal30805a12023-05-27 22:22:10 +01001480 // Prepare for spell checking.
1481 extra_check = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001482
Luuk van Baal30805a12023-05-27 22:22:10 +01001483 // When a word wrapped from the previous line the start of the
1484 // current line is valid.
1485 if (lnum == spv->spv_checked_lnum)
1486 cur_checked_col = spv->spv_checked_col;
Luuk van Baale84c7732023-05-31 18:57:36 +01001487 // Previous line was not spell checked, check for capital. This happens
1488 // for the first line in an updated region or after a closed fold.
1489 if (spv->spv_capcol_lnum == 0 && check_need_cap(wp, lnum, 0))
1490 spv->spv_cap_col = 0;
1491 else if (lnum != spv->spv_capcol_lnum)
Luuk van Baal30805a12023-05-27 22:22:10 +01001492 spv->spv_cap_col = -1;
1493 spv->spv_checked_lnum = 0;
1494
Luuk van Baal30805a12023-05-27 22:22:10 +01001495 // Get the start of the next line, so that words that wrap to the
1496 // next line are found too: "et<line-break>al.".
1497 // Trick: skip a few chars for C/shell/Vim comments
1498 nextline[SPWORDLEN] = NUL;
1499 if (lnum < wp->w_buffer->b_ml.ml_line_count)
Luuk van Baale84c7732023-05-31 18:57:36 +01001500 {
1501 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1502 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1503 }
1504 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1505
1506 // If current line is empty, check first word in next line for capital.
1507 ptr = skipwhite(line);
1508 if (*ptr == NUL)
1509 {
1510 spv->spv_cap_col = 0;
1511 spv->spv_capcol_lnum = lnum + 1;
1512 }
1513 // For checking first word with a capital skip white space.
1514 else if (spv->spv_cap_col == 0)
1515 spv->spv_cap_col = ptr - line;
1516
Luuk van Baal30805a12023-05-27 22:22:10 +01001517 // Copy the end of the current line into nextline[].
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001518 if (nextline[SPWORDLEN] == NUL)
1519 {
1520 // No next line or it is empty.
1521 nextlinecol = MAXCOL;
1522 nextline_idx = 0;
1523 }
1524 else
1525 {
1526 v = (long)STRLEN(line);
1527 if (v < SPWORDLEN)
1528 {
1529 // Short line, use it completely and append the start of the
1530 // next line.
1531 nextlinecol = 0;
1532 mch_memmove(nextline, line, (size_t)v);
1533 STRMOVE(nextline + v, nextline + SPWORDLEN);
1534 nextline_idx = v + 1;
1535 }
1536 else
1537 {
1538 // Long line, use only the last SPWORDLEN bytes.
1539 nextlinecol = v - SPWORDLEN;
1540 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1541 nextline_idx = SPWORDLEN + 1;
1542 }
1543 }
1544 }
1545#endif
1546
Luuk van Baale84c7732023-05-31 18:57:36 +01001547 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1548 ptr = line;
1549
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001550 if (wp->w_p_list)
1551 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001552 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001553 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001554 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001555 || wp->w_lcs_chars.trail
1556 || wp->w_lcs_chars.lead
1557 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001558 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001559
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001560 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001561 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001562 {
1563 trailcol = (colnr_T)STRLEN(ptr);
1564 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1565 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001566 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001567 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001568 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001569 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001570 {
1571 leadcol = 0;
1572 while (VIM_ISWHITE(ptr[leadcol]))
1573 ++leadcol;
1574 if (ptr[leadcol] == NUL)
1575 // in a line full of spaces all of them are treated as trailing
1576 leadcol = (colnr_T)0;
1577 else
1578 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001579 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001580 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001581 }
1582
Bram Moolenaard7657e92022-09-20 18:59:30 +01001583 wlv.wcr_attr = get_wcr_attr(wp);
1584 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001585 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001586 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001587 area_highlighting = TRUE;
1588 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001589
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001590 // When w_skipcol is non-zero and there is virtual text above the actual
1591 // text, then this much of the virtual text is skipped.
1592 int skipcol_in_text_prop_above = 0;
1593
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001594#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001595 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001596 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001597
1598 char_u *prop_start;
1599 text_prop_count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE);
1600 if (text_prop_count > 0)
1601 {
1602 // Make a copy of the properties, so that they are properly
1603 // aligned.
1604 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1605 if (text_props != NULL)
1606 mch_memmove(text_props, prop_start,
1607 text_prop_count * sizeof(textprop_T));
1608
1609 // Allocate an array for the indexes.
1610 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1611 if (text_prop_idxs == NULL)
1612 VIM_CLEAR(text_props);
1613
1614 if (text_props != NULL)
1615 {
1616 area_highlighting = TRUE;
1617 extra_check = TRUE;
1618
1619 // When skipping virtual text the props need to be sorted. The
1620 // order is reversed!
1621 if (lnum == wp->w_topline && wp->w_skipcol > 0)
1622 {
1623 for (int i = 0; i < text_prop_count; ++i)
1624 text_prop_idxs[i] = i;
1625 sort_text_props(wp->w_buffer, text_props,
1626 text_prop_idxs, text_prop_count);
1627 }
1628
1629 // Text props "above" move the line number down to where the text
1630 // is. Only count the ones that are visible, not those that are
1631 // skipped because of w_skipcol.
1632 int text_width = wp->w_width - win_col_off(wp);
1633 for (int i = text_prop_count - 1; i >= 0; --i)
1634 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1635 {
1636 if (lnum == wp->w_topline
1637 && wp->w_skipcol - skipcol_in_text_prop_above
1638 >= text_width)
1639 {
1640 // This virtual text above is skipped, remove it from
1641 // the array.
1642 skipcol_in_text_prop_above += text_width;
1643 for (int j = i + 1; j < text_prop_count; ++j)
1644 text_props[j - 1] = text_props[j];
1645 ++i;
1646 --text_prop_count;
1647 }
1648 else
1649 ++wlv.text_prop_above_count;
1650 }
1651 }
1652 }
Bram Moolenaara572b932023-02-19 14:34:37 +00001653
1654 if (number_only)
1655 {
1656 // skip over rows only used for virtual text above
1657 wlv.row += wlv.text_prop_above_count;
1658 if (wlv.row > endrow)
1659 return wlv.row;
1660 wlv.screen_row += wlv.text_prop_above_count;
1661 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001662#endif
1663
zeertzjqce53e3e2023-09-01 18:49:30 +02001664#if defined(FEAT_LINEBREAK) || defined(FEAT_PROP_POPUP)
1665 colnr_T vcol_first_char = 0;
1666 if (wp->w_p_lbr && !number_only)
1667 {
1668 chartabsize_T cts;
1669 init_chartabsize_arg(&cts, wp, lnum, 0, line, line);
1670 (void)win_lbr_chartabsize(&cts, NULL);
1671 vcol_first_char = cts.cts_first_char;
1672 clear_chartabsize_arg(&cts);
1673 }
1674#endif
1675
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001676 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1677 // first character to be displayed.
1678 if (wp->w_p_wrap)
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001679 v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001680 else
1681 v = wp->w_leftcol;
1682 if (v > 0 && !number_only)
1683 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001684 char_u *prev_ptr = ptr;
1685 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001686 int charsize = 0;
zeertzjqb557f482023-08-22 22:07:34 +02001687 int head = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001688
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001689 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
zeertzjqb557f482023-08-22 22:07:34 +02001690 cts.cts_max_head_vcol = v;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001691 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001692 {
zeertzjqb557f482023-08-22 22:07:34 +02001693 head = 0;
1694 charsize = win_lbr_chartabsize(&cts, &head);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001695 cts.cts_vcol += charsize;
1696 prev_ptr = cts.cts_ptr;
1697 MB_PTR_ADV(cts.cts_ptr);
zeertzjqabc80812023-09-24 23:32:18 +02001698 if (wp->w_p_list)
1699 {
1700 in_multispace = *prev_ptr == ' ' && (*cts.cts_ptr == ' '
1701 || (prev_ptr > line && prev_ptr[-1] == ' '));
1702 if (!in_multispace)
1703 multispace_pos = 0;
1704 else if (cts.cts_ptr >= line + leadcol
1705 && wp->w_lcs_chars.multispace != NULL)
1706 {
1707 ++multispace_pos;
1708 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
1709 multispace_pos = 0;
1710 }
1711 else if (cts.cts_ptr < line + leadcol
1712 && wp->w_lcs_chars.leadmultispace != NULL)
1713 {
1714 ++multispace_pos;
1715 if (wp->w_lcs_chars.leadmultispace[multispace_pos] == NUL)
1716 multispace_pos = 0;
1717 }
1718 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001719 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001720 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001721 ptr = cts.cts_ptr;
1722 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001723
1724 // When:
1725 // - 'cuc' is set, or
1726 // - 'colorcolumn' is set, or
1727 // - 'virtualedit' is set, or
1728 // - the visual mode is active,
1729 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001730 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001731#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001732 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001733#endif
1734 virtual_active() ||
1735 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001736 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001737
1738 // Handle a character that's not completely on the screen: Put ptr at
1739 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001740 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001741 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001742 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001743 ptr = prev_ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001744 }
zeertzjqb557f482023-08-22 22:07:34 +02001745 if (v > wlv.vcol)
1746 skip_cells = v - wlv.vcol - head;
Bram Moolenaarcd105412022-10-10 19:50:42 +01001747
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001748 // Adjust for when the inverted text is before the screen,
1749 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001750 if (wlv.tocol <= wlv.vcol)
1751 wlv.fromcol = 0;
1752 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1753 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001754
1755#ifdef FEAT_LINEBREAK
1756 // When w_skipcol is non-zero, first line needs 'showbreak'
1757 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001758 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001759#endif
1760#ifdef FEAT_SPELL
1761 // When spell checking a word we need to figure out the start of the
1762 // word and if it's badly spelled or not.
Luuk van Baal30805a12023-05-27 22:22:10 +01001763 if (spv->spv_has_spell)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001764 {
1765 int len;
1766 colnr_T linecol = (colnr_T)(ptr - line);
1767 hlf_T spell_hlf = HLF_COUNT;
1768
1769 pos = wp->w_cursor;
1770 wp->w_cursor.lnum = lnum;
1771 wp->w_cursor.col = linecol;
1772 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1773
1774 // spell_move_to() may call ml_get() and make "line" invalid
1775 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1776 ptr = line + linecol;
1777
1778 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1779 {
1780 // no bad word found at line start, don't check until end of a
1781 // word
1782 spell_hlf = HLF_COUNT;
1783 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1784 }
1785 else
1786 {
1787 // bad word found, use attributes until end of word
1788 word_end = wp->w_cursor.col + len + 1;
1789
1790 // Turn index into actual attributes.
1791 if (spell_hlf != HLF_COUNT)
1792 spell_attr = highlight_attr[spell_hlf];
1793 }
1794 wp->w_cursor = pos;
1795
1796# ifdef FEAT_SYN_HL
1797 // Need to restart syntax highlighting for this line.
1798 if (has_syntax)
1799 syntax_start(wp, lnum);
1800# endif
1801 }
1802#endif
1803 }
1804
1805 // Correct highlighting for cursor that can't be disabled.
1806 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001807 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001808 {
1809 if (noinvcur)
1810 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001811 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001812 {
1813 // highlighting starts at cursor, let it start just after the
1814 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001815 fromcol_prev = wlv.fromcol;
1816 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001817 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001818 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001819 // restart highlighting after the cursor
1820 fromcol_prev = wp->w_virtcol;
1821 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001822 if (wlv.fromcol >= wlv.tocol)
1823 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001824 }
1825
1826#ifdef FEAT_SEARCH_EXTRA
1827 if (!number_only)
1828 {
1829 v = (long)(ptr - line);
1830 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1831 &line, &screen_search_hl,
1832 &search_attr);
1833 ptr = line + v; // "line" may have been updated
1834 }
1835#endif
1836
1837#ifdef FEAT_SYN_HL
1838 // Cursor line highlighting for 'cursorline' in the current window.
1839 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1840 {
1841 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001842 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001843 if (!(wp == curwin && VIsual_active)
1844 && wp->w_p_culopt_flags != CULOPT_NBR)
1845 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001846 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001847 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1848
zeertzjqb7acea12022-12-12 13:20:43 +00001849 // Only apply CursorLine highlight here when "screenline" is not
1850 // present in 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001851 if (!wlv.cul_screenline)
zeertzjqb7acea12022-12-12 13:20:43 +00001852 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001853 else
1854 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001855 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001856 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1857 }
1858 area_highlighting = TRUE;
1859 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001860 }
1861#endif
1862
Bram Moolenaar1306b362022-08-06 15:59:06 +01001863 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001864
1865 // Repeat for the whole displayed line.
1866 for (;;)
1867 {
1868#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001869 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001870#endif
1871#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001872 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001873#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001874
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001875 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001876 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001877 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001878#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001879 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001880 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001881 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001882 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001883 }
1884#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001885 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001886 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001887 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001888 if (cmdwin_type != 0 && wp == curwin)
1889 {
1890 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001891 wlv.n_extra = 1;
1892 wlv.c_extra = cmdwin_type;
1893 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001894 wlv.char_attr =
1895 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001896 }
1897 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001898#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001899 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001900 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001901 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001902 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001903 }
1904#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001905#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001906 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001907 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001908 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001909 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001910 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001911 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001912 }
1913#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001914 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001915 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001916 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001917 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001918 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001919 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001920#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001921 // Check if 'breakindent' applies and show it.
1922 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1923 if (wlv.n_extra == 0)
1924 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001925#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001926#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001927 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001928 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001929 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001930 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001931 }
1932#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001933 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001934 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001935 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001936 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001937 }
1938 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001939
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001940#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001941 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001942 && wlv.vcol >= left_curline_col
1943 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001944 {
zeertzjqb7acea12022-12-12 13:20:43 +00001945 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001946 }
1947#endif
1948
1949 // When still displaying '$' of change command, stop at cursor.
1950 // When only displaying the (relative) line number and that's done,
1951 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001952 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001953 && lnum == wp->w_cursor.lnum
1954 && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001955 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001956#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001957 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001958#endif
1959 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001960 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001961 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001962 // Pretend we have finished updating the window. Except when
1963 // 'cursorcolumn' is set.
1964#ifdef FEAT_SYN_HL
1965 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001966 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001967 else
1968#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001969 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001970 break;
1971 }
1972
Bram Moolenaar1306b362022-08-06 15:59:06 +01001973 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001974 {
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001975#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001976 if (text_props != NULL)
1977 {
1978 int pi;
1979 int bcol = (int)(ptr - line);
1980
Bram Moolenaar1306b362022-08-06 15:59:06 +01001981 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001982# ifdef FEAT_LINEBREAK
1983 && !in_linebreak
1984# endif
1985 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001986 --bcol; // still working on the previous char, e.g. Tab
1987
1988 // Check if any active property ends.
1989 for (pi = 0; pi < text_props_active; ++pi)
1990 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001991 int tpi = text_prop_idxs[pi];
1992 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001993
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001994 // An inline property ends when after the start column plus
1995 // length. An "above" property ends when used and n_extra
1996 // is zero.
1997 if ((tp->tp_col != MAXCOL
1998 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001999 {
2000 if (pi + 1 < text_props_active)
2001 mch_memmove(text_prop_idxs + pi,
2002 text_prop_idxs + pi + 1,
2003 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002004 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002005 --text_props_active;
2006 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002007# ifdef FEAT_LINEBREAK
2008 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002009 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002010 syntax_attr = 0;
2011# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002012 }
2013 }
2014
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002015# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01002016 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002017 // not on the next char yet, don't start another prop
2018 --bcol;
2019# endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002020 int display_text_first = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002021
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002022 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002023 // With 'nowrap' and not in the first screen line only "below"
2024 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002025 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002026 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002027 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002028 && (wp->w_p_wrap
2029 || wlv.row == startrow
2030 || (text_props[text_prop_next].tp_flags
2031 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002032 || (bcol == 0
2033 && (text_props[text_prop_next].tp_flags
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002034 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002035 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002036 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01002037 if (text_props[text_prop_next].tp_col == MAXCOL
2038 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002039 + text_props[text_prop_next].tp_len)
2040 text_prop_idxs[text_props_active++] = text_prop_next;
2041 ++text_prop_next;
2042 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002043
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002044 if (wlv.n_extra == 0 ||
2045 (!wlv.extra_for_textprop
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002046 && !(text_prop_type != NULL &&
2047 text_prop_flags & PT_FLAG_OVERRIDE)
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002048 ))
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002049 {
2050 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002051 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002052 text_prop_flags = 0;
2053 text_prop_type = NULL;
2054 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002055 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002056 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002057 if (text_props_active > 0 && wlv.n_extra == 0
2058 && !display_text_first)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002059 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01002060 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002061 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002062 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002063
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002064 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002065 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002066
2067 // Sort the properties on priority and/or starting last.
2068 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002069 sort_text_props(wp->w_buffer, text_props,
2070 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002071
2072 for (pi = 0; pi < text_props_active; ++pi)
2073 {
2074 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002075 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002076 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002077 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002078
Bram Moolenaarcd105412022-10-10 19:50:42 +01002079 // Only use a text property that can be displayed.
2080 // Skip "after" properties when wrap is off and at the
2081 // end of the window.
2082 if (pt != NULL
2083 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2084 && tp->tp_id != -MAXCOL
2085 && !(tp->tp_id < 0
2086 && !wp->w_p_wrap
2087 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2088 | TP_FLAG_ALIGN_ABOVE
2089 | TP_FLAG_ALIGN_BELOW)) == 0
2090 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002091 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002092 if (tp->tp_col == MAXCOL
2093 && *ptr == NUL
2094 && ((wp->w_p_list && lcs_eol_one > 0
2095 && (tp->tp_flags
2096 & TP_FLAG_ALIGN_ABOVE) == 0)
2097 || (ptr == line
2098 && !did_line
2099 && (tp->tp_flags
2100 & TP_FLAG_ALIGN_BELOW))))
2101 {
2102 // skip this prop, first display the '$' after
2103 // the line or display an empty line
2104 text_prop_follows = TRUE;
2105 if (used_tpi < 0)
2106 display_text_first = TRUE;
2107 continue;
2108 }
2109
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002110 if (pt->pt_hl_id > 0)
2111 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002112 text_prop_type = pt;
2113 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002114 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002115 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2116 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002117 text_prop_flags = pt->pt_flags;
2118 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002119 used_tpi = tpi;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002120 display_text_first = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002121 }
2122 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002123 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002124 && -text_prop_id
2125 <= wp->w_buffer->b_textprop_text.ga_len)
2126 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002127 textprop_T *tp = &text_props[used_tpi];
2128 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002129 ->b_textprop_text.ga_data)[
2130 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002131 int above = (tp->tp_flags
2132 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002133 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002134
2135 // reset the ID in the copy to avoid it being used
2136 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002137 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002138
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002139 if (p != NULL)
2140 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002141 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002142 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002143 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002144 & TP_FLAG_ALIGN_BELOW);
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002145 int wrap = tp->tp_col < MAXCOL
2146 || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002147 int padding = tp->tp_col == MAXCOL
2148 && tp->tp_len > 1
2149 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002150
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002151 // Insert virtual text before the current
2152 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002153 wlv.p_extra = p;
2154 wlv.c_extra = NUL;
2155 wlv.c_final = NUL;
2156 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002157 wlv.extra_for_textprop = TRUE;
zeertzjq6e940d92023-08-17 23:21:40 +02002158 wlv.start_extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002159 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2160 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002161 n_attr = mb_charlen(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002162 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002163 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002164 if (*ptr == NUL)
2165 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002166 text_prop_flags &= ~PT_FLAG_COMBINE;
zeertzjq6b9c2022023-09-11 20:01:17 +02002167# ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002168 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002169 {
2170 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002171 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002172 wlv.need_showbreak = FALSE;
2173 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002174 }
zeertzjq6b9c2022023-09-11 20:01:17 +02002175# endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002176 if ((right || above || below || !wrap
2177 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002178 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002179 char_u *prev_p_extra = wlv.p_extra;
2180 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002181
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002182 // Take care of padding, right-align and
2183 // truncation.
2184 // Shared with win_lbr_chartabsize(), must do
2185 // exactly the same.
2186 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002187 wlv.vcol,
zeertzjq6b9c2022023-09-11 20:01:17 +02002188# ifdef FEAT_RIGHTLEFT
2189 wp->w_p_rl
2190 ? wp->w_width - wlv.col - 1
2191 :
2192# endif
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002193 wlv.col,
2194 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002195 &n_attr, &wlv.n_attr_skip,
2196 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002197 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002198 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002199 // wlv.p_extra was allocated
2200 vim_free(p_extra_free2);
2201 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002202 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002203
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002204 if (above)
2205 wlv.vcol_off_tp = wlv.n_extra;
2206
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002207 if (lcs_eol_one < 0
2208 && wp->w_p_wrap
2209 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002210 + wlv.n_extra - 2 > wp->w_width)
2211 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002212 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002213
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002214 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002215 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002216 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002217 {
2218 draw_screen_line(wp, &wlv);
2219
2220 // When line got too long for screen break
2221 // here.
2222 if (wlv.row == endrow)
2223 {
2224 ++wlv.row;
2225 break;
2226 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002227 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002228 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002229 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002230 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002231 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002232
Bram Moolenaarcd105412022-10-10 19:50:42 +01002233 // If the text didn't reach until the first window
2234 // column we need to skip cells.
2235 if (skip_cells > 0)
2236 {
2237 if (wlv.n_extra > skip_cells)
2238 {
2239 wlv.n_extra -= skip_cells;
2240 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002241 wlv.n_attr_skip -= skip_cells;
2242 if (wlv.n_attr_skip < 0)
2243 wlv.n_attr_skip = 0;
zeertzjqb557f482023-08-22 22:07:34 +02002244 skipped_cells += skip_cells;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002245 skip_cells = 0;
2246 }
2247 else
2248 {
2249 // the whole text is left of the window, drop
2250 // it and advance to the next one
2251 skip_cells -= wlv.n_extra;
zeertzjqb557f482023-08-22 22:07:34 +02002252 skipped_cells += wlv.n_extra;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002253 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002254 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002255 bail_out = TRUE;
2256 }
2257 }
2258
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002259 // If another text prop follows the condition below at
2260 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002261 // If this is an "above" text prop and 'nowrap' the we
2262 // must wrap anyway.
2263 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002264 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002265 && (wp->w_p_wrap
2266 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002267 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002268
2269 if (bail_out)
2270 // starting a new line for "below"
2271 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002272 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002273 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002274 else if (text_prop_next < text_prop_count
2275 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002276 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2277 || (!wp->w_p_wrap
2278 && wlv.col == wp->w_width - 1
2279 && (text_props[text_prop_next].tp_flags
2280 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002281 // When at last-but-one character and a text property
2282 // follows after it, we may need to flush the line after
2283 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002284 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002285 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002286 }
zeertzjq6e940d92023-08-17 23:21:40 +02002287
2288 if (wlv.start_extra_for_textprop)
2289 {
2290 wlv.start_extra_for_textprop = FALSE;
2291 // restore search_attr and area_attr when n_extra
2292 // is down to zero
2293 saved_search_attr = search_attr;
2294 saved_area_attr = area_attr;
2295 search_attr = 0;
2296 area_attr = 0;
2297 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002298#endif
2299
zeertzjq6e940d92023-08-17 23:21:40 +02002300 int *area_attr_p =
2301#ifdef FEAT_PROP_POPUP
2302 wlv.extra_for_textprop ? &saved_area_attr :
2303#endif
2304 &area_attr;
2305
2306 // handle Visual or match highlighting in this line
2307 if (wlv.vcol == wlv.fromcol
2308 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
2309 && ((wlv.n_extra == 0 && (*mb_ptr2cells)(ptr) > 1)
2310 || (wlv.n_extra > 0 && wlv.p_extra != NULL
2311 && (*mb_ptr2cells)(wlv.p_extra) > 1)))
2312 || ((int)vcol_prev == fromcol_prev
2313 && vcol_prev < wlv.vcol // not at margin
2314 && wlv.vcol < wlv.tocol))
2315 *area_attr_p = vi_attr; // start highlighting
2316 else if (*area_attr_p != 0
2317 && (wlv.vcol == wlv.tocol
2318 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
2319 *area_attr_p = 0; // stop highlighting
2320
zeertzjqe500ae82023-08-17 22:35:26 +02002321#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaare38fc862022-08-11 17:24:50 +01002322 if (wlv.n_extra == 0)
2323 {
2324 // Check for start/end of 'hlsearch' and other matches.
2325 // After end, check for start/end of next match.
2326 // When another match, have to check for start again.
2327 v = (long)(ptr - line);
2328 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2329 &screen_search_hl, &has_match_conc,
2330 &match_conc, did_line_attr, lcs_eol_one,
2331 &on_last_col);
2332 ptr = line + v; // "line" may have been changed
Bram Moolenaare38fc862022-08-11 17:24:50 +01002333
2334 // Do not allow a conceal over EOL otherwise EOL will be missed
2335 // and bad things happen.
2336 if (*ptr == NUL)
2337 has_match_conc = 0;
zeertzjqb25dbb32023-08-13 18:11:05 +02002338 }
zeertzjqe500ae82023-08-17 22:35:26 +02002339#endif
zeertzjqb25dbb32023-08-13 18:11:05 +02002340
Bram Moolenaare38fc862022-08-11 17:24:50 +01002341#ifdef FEAT_DIFF
2342 if (wlv.diff_hlf != (hlf_T)0)
2343 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002344 // When there is extra text (e.g. virtual text) it gets the
2345 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002346 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2347 && wlv.n_extra == 0)
2348 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002349 if (wlv.diff_hlf == HLF_TXD
2350 && ((ptr - line > change_end && wlv.n_extra == 0)
2351 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002352 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002353 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002354 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2355 && wp->w_p_culopt_flags != CULOPT_NBR
2356 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2357 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002358 wlv.line_attr = hl_combine_attr(
2359 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002360 }
2361#endif
2362
Bram Moolenaara74fda62019-10-19 17:38:03 +02002363#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002364 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002365 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002366 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002367# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002368 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002369 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002370# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002371 // Get syntax attribute.
2372 if (has_syntax)
2373 {
2374 // Get the syntax attribute for the character. If there
2375 // is an error, disable syntax highlighting.
2376 save_did_emsg = did_emsg;
2377 did_emsg = FALSE;
2378
2379 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002380 if (v == prev_syntax_col)
2381 // at same column again
2382 syntax_attr = prev_syntax_attr;
2383 else
2384 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002385# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002386 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002387# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002388 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002389# ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01002390 spv->spv_has_spell ? &can_spell :
Bram Moolenaar34390282019-10-16 14:38:26 +02002391# endif
Luuk van Baal30805a12023-05-27 22:22:10 +01002392 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002393 prev_syntax_col = v;
2394 prev_syntax_attr = syntax_attr;
2395 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002396
Bram Moolenaar34390282019-10-16 14:38:26 +02002397 if (did_emsg)
2398 {
2399 wp->w_s->b_syn_error = TRUE;
2400 has_syntax = FALSE;
2401 syntax_attr = 0;
2402 }
2403 else
2404 did_emsg = save_did_emsg;
2405# ifdef SYN_TIME_LIMIT
2406 if (wp->w_s->b_syn_slow)
2407 has_syntax = FALSE;
2408# endif
2409
2410 // Need to get the line again, a multi-line regexp may
2411 // have made it invalid.
2412 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2413 ptr = line + v;
2414# ifdef FEAT_CONCEAL
2415 // no concealing past the end of the line, it interferes
2416 // with line highlighting
2417 if (*ptr == NUL)
2418 syntax_flags = 0;
2419 else
2420 syntax_flags = get_syntax_info(&syntax_seqnr);
2421# endif
2422 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002423 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002424# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002425 // Combine text property highlight into syntax highlight.
2426 if (text_prop_type != NULL)
2427 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002428 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002429 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2430 else
2431 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002432 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002433 }
2434# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002435#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002436
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002437 // Decide which of the highlight attributes to use.
2438 attr_pri = TRUE;
2439#ifdef LINE_ATTR
2440 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002441 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002442 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002443 if (!highlight_match)
2444 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002445 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002446# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002447 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002448# endif
2449 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002450 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002451 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002452 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002453# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002454 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002455# endif
2456 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002457 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002458 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2459 || wlv.vcol < wlv.fromcol
2460 || vcol_prev < fromcol_prev
2461 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002462 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002463 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002464 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002465# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002466 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002467# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002468 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002469# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002470 attr_pri = FALSE;
2471 }
2472#else
2473 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002474 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002475 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002476 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002477#endif
2478 else
2479 {
2480 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002481#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002482 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002483#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002484 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002485#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002486 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002487#ifdef FEAT_PROP_POPUP
2488 // override with text property highlight when "override" is TRUE
2489 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002490 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002491#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002492 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002493
2494 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002495 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002496 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002497 if (wlv.char_attr == 0)
2498 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002499 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002500 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002501 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002502
2503 // Get the next character to put on the screen.
2504
2505 // The "p_extra" points to the extra stuff that is inserted to
2506 // represent special characters (non-printable stuff) and other
2507 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002508 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002509 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2510 // "p_extra[n_extra]".
2511 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002512 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002513 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002514 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002515 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002516 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2517 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002518 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2519 if (enc_utf8 && utf_char2len(c) > 1)
2520 {
2521 mb_utf8 = TRUE;
2522 u8cc[0] = 0;
2523 c = 0xc0;
2524 }
2525 else
2526 mb_utf8 = FALSE;
2527 }
2528 else
2529 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002530 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002531 if (has_mbyte)
2532 {
2533 mb_c = c;
2534 if (enc_utf8)
2535 {
2536 // If the UTF-8 character is more than one byte:
2537 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002538 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002539 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002540 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002541 mb_l = 1;
2542 else if (mb_l > 1)
2543 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002544 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002545 mb_utf8 = TRUE;
2546 c = 0xc0;
2547 }
2548 }
2549 else
2550 {
2551 // if this is a DBCS character, put it in "mb_c"
2552 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002553 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002554 mb_l = 1;
2555 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002556 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002557 }
2558 if (mb_l == 0) // at the NUL at end-of-line
2559 mb_l = 1;
2560
2561 // If a double-width char doesn't fit display a '>' in the
2562 // last column.
2563 if ((
2564# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002565 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002566# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002567 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002568 && (*mb_char2cells)(mb_c) == 2)
2569 {
2570 c = '>';
2571 mb_c = c;
2572 mb_l = 1;
2573 mb_utf8 = FALSE;
2574 multi_attr = HL_ATTR(HLF_AT);
2575#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002576 if (wlv.cul_attr)
2577 multi_attr = hl_combine_attr(
2578 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002579#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002580 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002581
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002582 // put the pointer back to output the double-width
2583 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002584 ++wlv.n_extra;
2585 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002586 }
2587 else
2588 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002589 wlv.n_extra -= mb_l - 1;
2590 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002591 }
2592 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002593 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002594 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002595 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002596#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002597 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002598 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002599 // Only restore search_attr and area_attr after "n_extra" in
2600 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002601 if (wlv.saved_n_extra <= 0)
2602 {
2603 if (search_attr == 0)
2604 search_attr = saved_search_attr;
2605 if (area_attr == 0 && *ptr != NUL)
2606 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002607
2608 if (wlv.extra_for_textprop)
2609 // wlv.extra_attr should be used at this position but
2610 // not any further.
2611 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002612 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002613
2614 wlv.extra_for_textprop = FALSE;
2615 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002616 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002617#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002618 }
2619 else
2620 {
2621#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002622 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002623#endif
zeertzjqe500ae82023-08-17 22:35:26 +02002624 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002625
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002626 // Get a character from the line itself.
2627 c = *ptr;
2628#ifdef FEAT_LINEBREAK
2629 c0 = *ptr;
2630#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002631 if (c == NUL)
zeertzjqb557f482023-08-22 22:07:34 +02002632 {
2633#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002634 // text is finished, may display a "below" virtual text
2635 did_line = TRUE;
2636#endif
zeertzjqb557f482023-08-22 22:07:34 +02002637 // no more cells to skip
2638 skip_cells = 0;
2639 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002640
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002641 if (has_mbyte)
2642 {
2643 mb_c = c;
2644 if (enc_utf8)
2645 {
2646 // If the UTF-8 character is more than one byte: Decode it
2647 // into "mb_c".
2648 mb_l = utfc_ptr2len(ptr);
2649 mb_utf8 = FALSE;
2650 if (mb_l > 1)
2651 {
2652 mb_c = utfc_ptr2char(ptr, u8cc);
2653 // Overlong encoded ASCII or ASCII with composing char
2654 // is displayed normally, except a NUL.
2655 if (mb_c < 0x80)
2656 {
2657 c = mb_c;
2658#ifdef FEAT_LINEBREAK
2659 c0 = mb_c;
2660#endif
2661 }
2662 mb_utf8 = TRUE;
2663
2664 // At start of the line we can have a composing char.
2665 // Draw it as a space with a composing char.
2666 if (utf_iscomposing(mb_c))
2667 {
2668 int i;
2669
2670 for (i = Screen_mco - 1; i > 0; --i)
2671 u8cc[i] = u8cc[i - 1];
2672 u8cc[0] = mb_c;
2673 mb_c = ' ';
2674 }
2675 }
2676
2677 if ((mb_l == 1 && c >= 0x80)
2678 || (mb_l >= 1 && mb_c == 0)
2679 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2680 {
2681 // Illegal UTF-8 byte: display as <xx>.
2682 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002683 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002684# ifdef FEAT_RIGHTLEFT
2685 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002686 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002687# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002688 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002689 c = *wlv.p_extra;
2690 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002691 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002692 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2693 wlv.c_extra = NUL;
2694 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002695 if (area_attr == 0 && search_attr == 0)
2696 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002697 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002698 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002699 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002700 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002701 }
2702 }
2703 else if (mb_l == 0) // at the NUL at end-of-line
2704 mb_l = 1;
2705#ifdef FEAT_ARABIC
2706 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2707 {
2708 // Do Arabic shaping.
2709 int pc, pc1, nc;
2710 int pcc[MAX_MCO];
2711
2712 // The idea of what is the previous and next
2713 // character depends on 'rightleft'.
2714 if (wp->w_p_rl)
2715 {
2716 pc = prev_c;
2717 pc1 = prev_c1;
2718 nc = utf_ptr2char(ptr + mb_l);
2719 prev_c1 = u8cc[0];
2720 }
2721 else
2722 {
2723 pc = utfc_ptr2char(ptr + mb_l, pcc);
2724 nc = prev_c;
2725 pc1 = pcc[0];
2726 }
2727 prev_c = mb_c;
2728
2729 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2730 }
2731 else
2732 prev_c = mb_c;
2733#endif
2734 }
2735 else // enc_dbcs
2736 {
2737 mb_l = MB_BYTE2LEN(c);
2738 if (mb_l == 0) // at the NUL at end-of-line
2739 mb_l = 1;
2740 else if (mb_l > 1)
2741 {
2742 // We assume a second byte below 32 is illegal.
2743 // Hopefully this is OK for all double-byte encodings!
2744 if (ptr[1] >= 32)
2745 mb_c = (c << 8) + ptr[1];
2746 else
2747 {
2748 if (ptr[1] == NUL)
2749 {
2750 // head byte at end of line
2751 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002752 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002753 }
2754 else
2755 {
2756 // illegal tail byte
2757 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002758 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002759 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002760 wlv.p_extra = wlv.extra;
2761 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002762 wlv.c_extra = NUL;
2763 wlv.c_final = NUL;
2764 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002765 if (area_attr == 0 && search_attr == 0)
2766 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002767 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002768 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002769 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002770 // save current attr
2771 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002772 }
2773 mb_c = c;
2774 }
2775 }
2776 }
2777 // If a double-width char doesn't fit display a '>' in the
2778 // last column; the character is displayed at the start of the
2779 // next line.
2780 if ((
2781# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002782 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002783# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002784 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002785 && (*mb_char2cells)(mb_c) == 2)
2786 {
2787 c = '>';
2788 mb_c = c;
2789 mb_utf8 = FALSE;
2790 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002791 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002792 // Put pointer back so that the character will be
2793 // displayed at the start of the next line.
2794 --ptr;
2795#ifdef FEAT_CONCEAL
2796 did_decrement_ptr = TRUE;
2797#endif
2798 }
2799 else if (*ptr != NUL)
2800 ptr += mb_l - 1;
2801
2802 // If a double-width char doesn't fit at the left side display
2803 // a '<' in the first column. Don't do this for unprintable
2804 // characters.
zeertzjqb557f482023-08-22 22:07:34 +02002805 if (skip_cells > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002806 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002807 wlv.n_extra = 1;
2808 wlv.c_extra = MB_FILLER_CHAR;
2809 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002810 c = ' ';
2811 if (area_attr == 0 && search_attr == 0)
2812 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002813 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002814 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002815 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002816 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002817 }
2818 mb_c = c;
2819 mb_utf8 = FALSE;
2820 mb_l = 1;
2821 }
2822
2823 }
2824 ++ptr;
2825
2826 if (extra_check)
2827 {
2828#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002829 // Check spelling (unless at the end of the line).
2830 // Only do this when there is no syntax highlighting, the
2831 // @Spell cluster is not used or the current syntax item
2832 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002833 v = (long)(ptr - line);
Luuk van Baal30805a12023-05-27 22:22:10 +01002834 if (spv->spv_has_spell && v >= word_end && v > cur_checked_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002835 {
2836 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002837 // do not calculate cap_col at the end of the line or when
2838 // only white space is following
2839 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002840# ifdef FEAT_SYN_HL
2841 !has_syntax ||
2842# endif
2843 can_spell))
2844 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002845 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002846 int len;
2847 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002848
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002849 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002850 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002851
2852 // Use nextline[] if possible, it has the start of the
2853 // next line concatenated.
2854 if ((prev_ptr - line) - nextlinecol >= 0)
2855 p = nextline + (prev_ptr - line) - nextlinecol;
2856 else
2857 p = prev_ptr;
Luuk van Baal30805a12023-05-27 22:22:10 +01002858 spv->spv_cap_col -= (int)(prev_ptr - line);
2859 len = spell_check(wp, p, &spell_hlf, &spv->spv_cap_col,
2860 spv->spv_unchanged);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002861 word_end = v + len;
2862
2863 // In Insert mode only highlight a word that
2864 // doesn't touch the cursor.
2865 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002866 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002867 && wp->w_cursor.lnum == lnum
2868 && wp->w_cursor.col >=
2869 (colnr_T)(prev_ptr - line)
2870 && wp->w_cursor.col < (colnr_T)word_end)
2871 {
2872 spell_hlf = HLF_COUNT;
2873 spell_redraw_lnum = lnum;
2874 }
2875
2876 if (spell_hlf == HLF_COUNT && p != prev_ptr
2877 && (p - nextline) + len > nextline_idx)
2878 {
2879 // Remember that the good word continues at the
2880 // start of the next line.
Luuk van Baal30805a12023-05-27 22:22:10 +01002881 spv->spv_checked_lnum = lnum + 1;
2882 spv->spv_checked_col = (p - nextline) + len
2883 - nextline_idx;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002884 }
2885
2886 // Turn index into actual attributes.
2887 if (spell_hlf != HLF_COUNT)
2888 spell_attr = highlight_attr[spell_hlf];
2889
Luuk van Baal30805a12023-05-27 22:22:10 +01002890 if (spv->spv_cap_col > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002891 {
2892 if (p != prev_ptr
Luuk van Baal30805a12023-05-27 22:22:10 +01002893 && (p - nextline) + spv->spv_cap_col
2894 >= nextline_idx)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002895 {
2896 // Remember that the word in the next line
2897 // must start with a capital.
Luuk van Baal30805a12023-05-27 22:22:10 +01002898 spv->spv_capcol_lnum = lnum + 1;
2899 spv->spv_cap_col = ((p - nextline)
2900 + spv->spv_cap_col - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002901 }
2902 else
2903 // Compute the actual column.
Luuk van Baal30805a12023-05-27 22:22:10 +01002904 spv->spv_cap_col += (prev_ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002905 }
2906 }
2907 }
2908 if (spell_attr != 0)
2909 {
2910 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002911 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2912 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002913 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002914 wlv.char_attr = hl_combine_attr(spell_attr,
2915 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002916 }
2917#endif
2918#ifdef FEAT_LINEBREAK
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02002919 // we don't want linebreak to apply for lines that start with
2920 // leading spaces, followed by long letters (since it would add
2921 // a break at the beginning of a line and this might be unexpected)
2922 //
2923 // So only allow to linebreak, once we have found chars not in
2924 // 'breakat' in the line.
2925 if ( wp->w_p_lbr && !wlv.need_lbr && c != NUL &&
2926 !VIM_ISBREAK((int)*ptr))
2927 wlv.need_lbr = TRUE;
2928#endif
2929#ifdef FEAT_LINEBREAK
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002930 // Found last space before word: check for line break.
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02002931 if (wp->w_p_lbr && c0 == c && wlv.need_lbr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002932 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2933 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002934 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2935 : 0;
2936 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002937 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002938
zeertzjqce53e3e2023-09-01 18:49:30 +02002939 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol
2940# ifdef FEAT_PROP_POPUP
2941 - vcol_first_char,
2942# endif
2943 line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002944# ifdef FEAT_PROP_POPUP
2945 // do not want virtual text counted here
2946 cts.cts_has_prop_with_text = FALSE;
2947# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002948 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002949 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002950
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002951 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002952 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002953 // line break, but for TABs the highlighting should
2954 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002955 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002956
Bram Moolenaar1306b362022-08-06 15:59:06 +01002957 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002958# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002959 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002960 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002961 wp->w_buffer->b_p_vts_array) - 1;
2962# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002963 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002964 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002965# endif
2966
Bram Moolenaar1306b362022-08-06 15:59:06 +01002967 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2968 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002969# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002970 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002971 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002972# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002973 if (VIM_ISWHITE(c))
2974 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002975# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002976 if (c == TAB)
2977 // See "Tab alignment" below.
2978 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002979# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002980 if (!wp->w_p_list)
2981 c = ' ';
2982 }
2983 }
2984#endif
zeertzjqabc80812023-09-24 23:32:18 +02002985 if (wp->w_p_list)
2986 {
2987 in_multispace = c == ' ' && (*ptr == ' '
2988 || (prev_ptr > line && prev_ptr[-1] == ' '));
2989 if (!in_multispace)
2990 multispace_pos = 0;
2991 }
zeertzjqf14b8ba2021-09-10 16:58:30 +02002992
Bram Moolenaareed9d462021-02-15 20:38:25 +01002993 // 'list': Change char 160 to 'nbsp' and space to 'space'
2994 // setting in 'listchars'. But not when the character is
2995 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002996 if (wp->w_p_list
2997 && ((((c == 160 && mb_l == 1)
2998 || (mb_utf8
2999 && ((mb_c == 160 && mb_l == 2)
3000 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01003001 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003002 || (c == ' '
3003 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02003004 && (wp->w_lcs_chars.space
3005 || (in_multispace
3006 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01003007 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003008 && ptr - line <= trailcol)))
3009 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02003010 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
3011 {
3012 c = wp->w_lcs_chars.multispace[multispace_pos++];
3013 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
3014 multispace_pos = 0;
3015 }
3016 else
3017 c = (c == ' ') ? wp->w_lcs_chars.space
3018 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003019 if (area_attr == 0 && search_attr == 0)
3020 {
3021 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003022 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003023 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003024 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003025 }
3026 mb_c = c;
3027 if (enc_utf8 && utf_char2len(c) > 1)
3028 {
3029 mb_utf8 = TRUE;
3030 u8cc[0] = 0;
3031 c = 0xc0;
3032 }
3033 else
3034 mb_utf8 = FALSE;
3035 }
3036
zeertzjq2e7cba32022-06-10 15:30:32 +01003037 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
3038 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003039 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003040 if (leadcol != 0 && in_multispace && ptr < line + leadcol
3041 && wp->w_lcs_chars.leadmultispace != NULL)
3042 {
3043 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01003044 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
3045 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003046 multispace_pos = 0;
3047 }
3048
3049 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
3050 c = wp->w_lcs_chars.trail;
3051
3052 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
3053 c = wp->w_lcs_chars.lead;
3054
zeertzjq2e7cba32022-06-10 15:30:32 +01003055 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003056 c = wp->w_lcs_chars.space;
3057
3058
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003059 if (!attr_pri)
3060 {
3061 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003062 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003063 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003064 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003065 }
3066 mb_c = c;
3067 if (enc_utf8 && utf_char2len(c) > 1)
3068 {
3069 mb_utf8 = TRUE;
3070 u8cc[0] = 0;
3071 c = 0xc0;
3072 }
3073 else
3074 mb_utf8 = FALSE;
3075 }
3076 }
3077
3078 // Handling of non-printable characters.
3079 if (!vim_isprintc(c))
3080 {
3081 // when getting a character from the file, we may have to
3082 // turn it into something else on the way to putting it
3083 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01003084 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003085 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003086 int tab_len = 0;
3087 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003088#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003089 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01003090
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003091 // only adjust the tab_len, when at the first column
3092 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01003093 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003094 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003095#endif
3096 // tab amount depends on current column
3097#ifdef FEAT_VARTABS
3098 tab_len = tabstop_padding(vcol_adjusted,
3099 wp->w_buffer->b_p_ts,
3100 wp->w_buffer->b_p_vts_array) - 1;
3101#else
3102 tab_len = (int)wp->w_buffer->b_p_ts
3103 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
3104#endif
3105
3106#ifdef FEAT_LINEBREAK
3107 if (!wp->w_p_lbr || !wp->w_p_list)
3108#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003109 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003110 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01003111 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003112 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003113#ifdef FEAT_LINEBREAK
3114 else
3115 {
3116 char_u *p;
3117 int len;
3118 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003119 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003120
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003121# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003122 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003123 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003124 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003125
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003126 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003127 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003128 && old_boguscols > 0
3129 && wlv.n_extra > tab_len)
3130 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003131# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003132 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003133 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003134 // If wlv.n_extra > 0, it gives the number of chars
3135 // to use for a tab, else we need to calculate the
3136 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003137 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3138 len = tab_len * tab2_len;
3139 if (wp->w_lcs_chars.tab3)
3140 len += mb_char2len(wp->w_lcs_chars.tab3)
3141 - tab2_len;
3142 if (wlv.n_extra > 0)
3143 len += wlv.n_extra - tab_len;
3144 c = wp->w_lcs_chars.tab1;
3145 p = alloc(len + 1);
3146 if (p == NULL)
3147 wlv.n_extra = 0;
3148 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003149 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003150 vim_memset(p, ' ', len);
3151 p[len] = NUL;
3152 vim_free(wlv.p_extra_free);
3153 wlv.p_extra_free = p;
3154 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003155 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003156 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003157
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003158 if (*p == NUL)
3159 {
3160 tab_len = i;
3161 break;
3162 }
3163
3164 // if tab3 is given, use it for the last
3165 // char
3166 if (wp->w_lcs_chars.tab3
3167 && i == tab_len - 1)
3168 lcs = wp->w_lcs_chars.tab3;
3169 p += mb_char2bytes(lcs, p);
3170 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003171 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003172 }
3173 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003174# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003175 // n_extra will be increased by
3176 // FIX_FOX_BOGUSCOLS macro below, so need to
3177 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003178 if (wlv.vcol_off_co > 0)
3179 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003180# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003181 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003182 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003183 }
3184#endif
3185#ifdef FEAT_CONCEAL
3186 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003187 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003188
3189 // Tab alignment should be identical regardless of
3190 // 'conceallevel' value. So tab compensates of all
3191 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003192 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003193 // line. Note that the tab can be longer than
3194 // 'tabstop' when there are concealed characters.
3195 FIX_FOR_BOGUSCOLS;
3196
3197 // Make sure, the highlighting for the tab char will be
3198 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003199 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003200 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003201 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003202 tab_len += vc_saved;
3203 }
3204#endif
3205 mb_utf8 = FALSE; // don't draw as UTF-8
3206 if (wp->w_p_list)
3207 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003208 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003209 ? wp->w_lcs_chars.tab3
3210 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003211#ifdef FEAT_LINEBREAK
h-east194555c2023-03-02 18:49:09 +00003212 if (wp->w_p_lbr && wlv.p_extra != NULL
3213 && *wlv.p_extra != NUL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003214 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003215 else
3216#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003217 wlv.c_extra = wp->w_lcs_chars.tab2;
3218 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003219 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003220 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003221 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003222 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003223 mb_c = c;
3224 if (enc_utf8 && utf_char2len(c) > 1)
3225 {
3226 mb_utf8 = TRUE;
3227 u8cc[0] = 0;
3228 c = 0xc0;
3229 }
3230 }
3231 else
3232 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003233 wlv.c_final = NUL;
3234 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003235 c = ' ';
3236 }
3237 }
3238 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003239 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003240 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003241 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3242 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003243 && VIsual_mode != Ctrl_V
3244 && (
3245# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003246 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003247# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003248 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003249 && !(noinvcur
3250 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003251 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003252 && lcs_eol_one > 0)
3253 {
3254 // Display a '$' after the line or highlight an extra
3255 // character if the line break is included.
3256#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3257 // For a diff line the highlighting continues after the
3258 // "$".
3259 if (
3260# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003261 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003262# ifdef LINE_ATTR
3263 &&
3264# endif
3265# endif
3266# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003267 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003268# endif
3269 )
3270#endif
3271 {
3272 // In virtualedit, visual selections may extend
3273 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003274 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003275 && wlv.tocol != MAXCOL
3276 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003277 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003278 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003279 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003280 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3281 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003282 else
3283 c = ' ';
3284 lcs_eol_one = -1;
3285 --ptr; // put it back at the NUL
3286 if (!attr_pri)
3287 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003288 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003289 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003290 n_attr = 1;
3291 }
3292 mb_c = c;
3293 if (enc_utf8 && utf_char2len(c) > 1)
3294 {
3295 mb_utf8 = TRUE;
3296 u8cc[0] = 0;
3297 c = 0xc0;
3298 }
3299 else
3300 mb_utf8 = FALSE; // don't draw as UTF-8
3301 }
3302 else if (c != NUL)
3303 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003304 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3305 if (wlv.n_extra == 0)
3306 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003307#ifdef FEAT_RIGHTLEFT
3308 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003309 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003310#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003311 wlv.c_extra = NUL;
3312 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003313#ifdef FEAT_LINEBREAK
3314 if (wp->w_p_lbr)
3315 {
3316 char_u *p;
3317
Bram Moolenaar1306b362022-08-06 15:59:06 +01003318 c = *wlv.p_extra;
3319 p = alloc(wlv.n_extra + 1);
3320 vim_memset(p, ' ', wlv.n_extra);
3321 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3322 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003323 vim_free(wlv.p_extra_free);
3324 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003325 }
3326 else
3327#endif
3328 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003329 wlv.n_extra = byte2cells(c) - 1;
3330 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003331 }
3332 if (!attr_pri)
3333 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003334 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003335 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003336 HL_ATTR(HLF_8));
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003337#ifdef FEAT_PROP_POPUP
3338 if (text_prop_type != NULL &&
3339 text_prop_flags & PT_FLAG_OVERRIDE)
3340 wlv.extra_attr = hl_combine_attr(text_prop_attr, wlv.extra_attr);
3341#endif
3342
Bram Moolenaar1306b362022-08-06 15:59:06 +01003343 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003344 }
3345 mb_utf8 = FALSE; // don't draw as UTF-8
3346 }
3347 else if (VIsual_active
3348 && (VIsual_mode == Ctrl_V
3349 || VIsual_mode == 'v')
3350 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003351 && wlv.tocol != MAXCOL
3352 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003353 && (
3354#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003355 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003356#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003357 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003358 {
3359 c = ' ';
3360 --ptr; // put it back at the NUL
3361 }
3362#if defined(LINE_ATTR)
3363 else if ((
3364# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003365 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003366# endif
3367# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003368 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003369# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003370 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003371 ) && (
3372# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003373 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003374# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003375 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003376# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003377 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003378# endif
3379 < wp->w_width)))
3380 {
3381 // Highlight until the right side of the window
3382 c = ' ';
3383 --ptr; // put it back at the NUL
3384
3385 // Remember we do the char for line highlighting.
3386 ++did_line_attr;
3387
3388 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003389 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003390 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003391 || (wp->w_p_list &&
3392 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003393 wlv.char_attr = wlv.line_attr;
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003394#ifdef FEAT_SIGNS
3395 // At end of line: if Sign is present with line highlight, reset char_attr
Christian Brabandte1eaae22023-08-19 22:36:12 +02003396 // but not when cursorline is active
3397 if (sign_present && wlv.sattr.sat_linehl > 0 && wlv.draw_state == WL_LINE
3398 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum))
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003399 wlv.char_attr = wlv.sattr.sat_linehl;
3400#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003401# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003402 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003403 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003404 wlv.diff_hlf = HLF_CHD;
3405 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003406 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003407 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003408 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3409 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003410 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003411 || (wlv.vcol >= left_curline_col
3412 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003413 wlv.char_attr = hl_combine_attr(
3414 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003415 }
3416 }
3417# endif
3418# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003419 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003420 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003421 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003422 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3423 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003424 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003425 if (!wlv.cul_screenline
3426 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003427 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003428 wlv.char_attr = hl_combine_attr(
3429 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003430 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003431 else if (wlv.line_attr)
3432 wlv.char_attr = hl_combine_attr(
3433 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003434 }
3435# endif
3436 }
3437#endif
3438 }
3439
3440#ifdef FEAT_CONCEAL
3441 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003442 && (wp != curwin || lnum != wp->w_cursor.lnum
3443 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003444 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3445 && !(lnum_in_visual_area
3446 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3447 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003448 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003449 if (((prev_syntax_id != syntax_seqnr
3450 && (syntax_flags & HL_CONCEAL) != 0)
3451 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003452 && (syn_get_sub_char() != NUL
3453 || (has_match_conc && match_conc)
3454 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003455 && wp->w_p_cole != 3)
3456 {
3457 // First time at this concealed item: display one
3458 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003459 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003460 c = match_conc;
3461 else if (syn_get_sub_char() != NUL)
3462 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003463 else if (wp->w_lcs_chars.conceal != NUL)
3464 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003465 else
3466 c = ' ';
3467
3468 prev_syntax_id = syntax_seqnr;
3469
Bram Moolenaar1306b362022-08-06 15:59:06 +01003470 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003471 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003472 wlv.vcol += wlv.n_extra;
3473 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003474 {
3475# ifdef FEAT_RIGHTLEFT
3476 if (wp->w_p_rl)
3477 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003478 wlv.col -= wlv.n_extra;
3479 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003480 }
3481 else
3482# endif
3483 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003484 wlv.boguscols += wlv.n_extra;
3485 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003486 }
3487 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003488 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003489 n_attr = 0;
3490 }
zeertzjqb557f482023-08-22 22:07:34 +02003491 else if (skip_cells == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003492 {
3493 is_concealing = TRUE;
zeertzjqb557f482023-08-22 22:07:34 +02003494 skip_cells = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003495 }
3496 mb_c = c;
3497 if (enc_utf8 && utf_char2len(c) > 1)
3498 {
3499 mb_utf8 = TRUE;
3500 u8cc[0] = 0;
3501 c = 0xc0;
3502 }
3503 else
3504 mb_utf8 = FALSE; // don't draw as UTF-8
3505 }
3506 else
3507 {
3508 prev_syntax_id = 0;
3509 is_concealing = FALSE;
3510 }
3511
zeertzjqb557f482023-08-22 22:07:34 +02003512 if (skip_cells > 0 && did_decrement_ptr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003513 // not showing the '>', put pointer back to avoid getting stuck
3514 ++ptr;
3515
3516#endif // FEAT_CONCEAL
3517 }
3518
3519#ifdef FEAT_CONCEAL
3520 // In the cursor line and we may be concealing characters: correct
3521 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003522 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003523 && wp == curwin && lnum == wp->w_cursor.lnum
3524 && conceal_cursor_line(wp)
zeertzjqb557f482023-08-22 22:07:34 +02003525 && (int)wp->w_virtcol <= wlv.vcol + skip_cells)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003526 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003527# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003528 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003529 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003530 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003531# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003532 wp->w_wcol = wlv.col - wlv.boguscols;
3533 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003534 did_wcol = TRUE;
3535 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003536# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003537 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003538# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003539 }
3540#endif
3541
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003542 // Use "wlv.extra_attr", but don't override visual selection
3543 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003544 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3545 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003546 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003547 && (!attr_pri
3548#ifdef FEAT_PROP_POPUP
3549 || (text_prop_flags & PT_FLAG_OVERRIDE)
3550#endif
3551 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003552 {
3553#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003554 if (wlv.line_attr)
3555 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003556 else
3557#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003558 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003559#ifdef FEAT_PROP_POPUP
3560 if (reset_extra_attr)
3561 {
3562 reset_extra_attr = FALSE;
3563 wlv.extra_attr = 0;
3564 }
3565#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003566 }
3567
3568#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3569 // XIM don't send preedit_start and preedit_end, but they send
3570 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3571 // im_is_preediting() here.
3572 if (p_imst == IM_ON_THE_SPOT
3573 && xic != NULL
3574 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003575 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003576 && !p_imdisable
3577 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003578 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003579 {
3580 colnr_T tcol;
3581
3582 if (preedit_end_col == MAXCOL)
3583 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3584 else
3585 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003586 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003587 {
3588 if (feedback_old_attr < 0)
3589 {
3590 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003591 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003592 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003593 wlv.char_attr = im_get_feedback_attr(feedback_col);
3594 if (wlv.char_attr < 0)
3595 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003596 feedback_col++;
3597 }
3598 else if (feedback_old_attr >= 0)
3599 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003600 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003601 feedback_old_attr = -1;
3602 feedback_col = 0;
3603 }
3604 }
3605#endif
3606 // Handle the case where we are in column 0 but not on the first
3607 // character of the line and the user wants us to show us a
3608 // special character (via 'listchars' option "precedes:<char>".
3609 if (lcs_prec_todo != NUL
3610 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003611 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3612 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003613#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003614 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003615#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003616 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003617 && c != NUL)
3618 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003619 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003620 lcs_prec_todo = NUL;
3621 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3622 {
3623 // Double-width character being overwritten by the "precedes"
3624 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003625 wlv.c_extra = MB_FILLER_CHAR;
3626 wlv.c_final = NUL;
3627 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003628 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003629 wlv.extra_attr =
3630 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003631 }
3632 mb_c = c;
3633 if (enc_utf8 && utf_char2len(c) > 1)
3634 {
3635 mb_utf8 = TRUE;
3636 u8cc[0] = 0;
3637 c = 0xc0;
3638 }
3639 else
3640 mb_utf8 = FALSE; // don't draw as UTF-8
3641 if (!attr_pri)
3642 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003643 saved_attr3 = wlv.char_attr; // save current attr
3644 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003645 n_attr3 = 1;
3646 }
3647 }
3648
3649 // At end of the text line or just after the last character.
3650 if ((c == NUL
3651#if defined(LINE_ATTR)
3652 || did_line_attr == 1
3653#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003654 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003655 {
3656#ifdef FEAT_SEARCH_EXTRA
3657 // flag to indicate whether prevcol equals startcol of search_hl or
3658 // one of the matches
3659 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3660 (long)(ptr - line) - (c == NUL));
3661#endif
3662 // Invert at least one char, used for Visual and empty line or
3663 // highlight match at end of line. If it's beyond the last
3664 // char on the screen, just overwrite that one (tricky!) Not
3665 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003666 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003667 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003668 && (VIsual_mode != Ctrl_V
3669 || lnum == VIsual.lnum
3670 || lnum == curwin->w_cursor.lnum)
3671 && c == NUL)
3672#ifdef FEAT_SEARCH_EXTRA
3673 // highlight 'hlsearch' match at end of line
3674 || (prevcol_hl_flag
3675# ifdef FEAT_SYN_HL
3676 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3677 && !(wp == curwin && VIsual_active))
3678# endif
3679# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003680 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003681# endif
3682# if defined(LINE_ATTR)
3683 && did_line_attr <= 1
3684# endif
3685 )
3686#endif
3687 ))
3688 {
3689 int n = 0;
3690
3691#ifdef FEAT_RIGHTLEFT
3692 if (wp->w_p_rl)
3693 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003694 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003695 n = 1;
3696 }
3697 else
3698#endif
3699 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003700 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003701 n = -1;
3702 }
3703 if (n != 0)
3704 {
3705 // At the window boundary, highlight the last character
3706 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003707 wlv.off += n;
3708 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003709 }
3710 else
3711 {
3712 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003713 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003714 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003715 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003716 }
3717#ifdef FEAT_SEARCH_EXTRA
3718 if (area_attr == 0)
3719 {
3720 // Use attributes from match with highest priority among
3721 // 'search_hl' and the match list.
3722 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003723 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003724 }
3725#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003726 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003727 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003728#ifdef FEAT_RIGHTLEFT
3729 if (wp->w_p_rl)
3730 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003731 --wlv.col;
3732 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003733 }
3734 else
3735#endif
3736 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003737 ++wlv.col;
3738 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003739 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003740 ++wlv.vcol;
3741 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003742 }
3743 }
3744
3745 // At end of the text line.
3746 if (c == NUL)
3747 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003748#ifdef FEAT_PROP_POPUP
3749 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003750 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003751 // Put the pointer back to the NUL.
3752 --ptr;
3753 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003754 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003755 else
3756#endif
3757 {
3758 draw_screen_line(wp, &wlv);
3759
3760 // Update w_cline_height and w_cline_folded if the cursor line
3761 // was updated (saves a call to plines() later).
3762 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3763 {
3764 curwin->w_cline_row = startrow;
3765 curwin->w_cline_height = wlv.row - startrow;
3766#ifdef FEAT_FOLDING
3767 curwin->w_cline_folded = FALSE;
3768#endif
3769 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3770 }
3771 break;
3772 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003773 }
3774
3775 // Show "extends" character from 'listchars' if beyond the line end and
3776 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003777 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003778 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003779 && wp->w_p_list
3780 && !wp->w_p_wrap
3781#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003782 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003783#endif
3784 && (
3785#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003786 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003787#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003788 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003789 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003790 || lcs_eol_one > 0
3791 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
zeertzjq6a389722023-08-27 19:04:14 +02003792 || *wlv.p_extra != NUL))
3793#ifdef FEAT_PROP_POPUP
3794 || text_prop_next < text_prop_count
3795#endif
3796 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003797 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003798 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003799 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003800 mb_c = c;
3801 if (enc_utf8 && utf_char2len(c) > 1)
3802 {
3803 mb_utf8 = TRUE;
3804 u8cc[0] = 0;
3805 c = 0xc0;
3806 }
3807 else
3808 mb_utf8 = FALSE;
3809 }
3810
3811#ifdef FEAT_SYN_HL
3812 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003813 if (wlv.draw_color_col)
3814 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003815
3816 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3817 // highlight the cursor position itself.
3818 // Also highlight the 'colorcolumn' if it is different than
3819 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003820 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3821 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003822 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003823 if (((wlv.draw_state == WL_LINE
3824 || wlv.draw_state == WL_BRI
3825 || wlv.draw_state == WL_SBR)
3826 && !lnum_in_visual_area
3827 && search_attr == 0
3828 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003829# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003830 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003831# endif
3832 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003833 {
3834 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3835 && lnum != wp->w_cursor.lnum)
3836 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003837 vcol_save_attr = wlv.char_attr;
3838 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3839 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003840 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003841 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003842 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003843 vcol_save_attr = wlv.char_attr;
3844 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003845 }
3846 }
3847#endif
3848
zeertzjq8fc6a1d2023-08-20 18:12:54 +02003849 if (wlv.draw_state == WL_LINE)
3850 vcol_prev = wlv.vcol;
3851
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003852 // Store character to be displayed.
3853 // Skip characters that are left of the screen for 'nowrap'.
zeertzjqb557f482023-08-22 22:07:34 +02003854 if (wlv.draw_state < WL_LINE || skip_cells <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003855 {
3856 // Store the character.
3857#if defined(FEAT_RIGHTLEFT)
3858 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3859 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003860 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003861 --wlv.off;
3862 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003863 }
3864#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003865 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003866 if (enc_dbcs == DBCS_JPNU)
3867 {
3868 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003869 ScreenLines[wlv.off] = 0x8e;
3870 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003871 }
3872 else if (enc_utf8)
3873 {
3874 if (mb_utf8)
3875 {
3876 int i;
3877
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003878 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003879 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003880 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003881 for (i = 0; i < Screen_mco; ++i)
3882 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003883 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003884 if (u8cc[i] == 0)
3885 break;
3886 }
3887 }
3888 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003889 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003890 }
3891 if (multi_attr)
3892 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003893 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003894 multi_attr = 0;
3895 }
3896 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003897 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003898
zeertzjqdb54e982023-09-21 16:33:09 +02003899 if (wlv.draw_state > WL_NR
3900#ifdef FEAT_DIFF
3901 && wlv.filler_todo <= 0
3902#endif
3903 )
3904 ScreenCols[wlv.off] = wlv.vcol;
3905 else
3906 ScreenCols[wlv.off] = -1;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003907
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003908 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3909 {
3910 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003911 ++wlv.off;
3912 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003913 if (enc_utf8)
3914 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003915 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003916 else
3917 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003918 ScreenLines[wlv.off] = mb_c & 0xff;
zeertzjqdb54e982023-09-21 16:33:09 +02003919
Bram Moolenaar1306b362022-08-06 15:59:06 +01003920 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003921#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003922 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003923#endif
3924 )
zeertzjqdb54e982023-09-21 16:33:09 +02003925 ScreenCols[wlv.off] = ++wlv.vcol;
3926 else
3927 ScreenCols[wlv.off] = -1;
3928
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003929 // When "wlv.tocol" is halfway a character, set it to the end
3930 // of the character, otherwise highlighting won't stop.
3931 if (wlv.tocol == wlv.vcol)
3932 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003933
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003934#ifdef FEAT_RIGHTLEFT
3935 if (wp->w_p_rl)
3936 {
3937 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003938 --wlv.off;
3939 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003940 }
3941#endif
3942 }
3943#ifdef FEAT_RIGHTLEFT
3944 if (wp->w_p_rl)
3945 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003946 --wlv.off;
3947 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003948 }
3949 else
3950#endif
3951 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003952 ++wlv.off;
3953 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003954 }
3955 }
3956#ifdef FEAT_CONCEAL
3957 else if (wp->w_p_cole > 0 && is_concealing)
3958 {
zeertzjqb557f482023-08-22 22:07:34 +02003959 --skip_cells;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003960 ++wlv.vcol_off_co;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003961 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003962 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003963 if (wp->w_p_wrap)
3964 {
3965 // Special voodoo required if 'wrap' is on.
3966 //
3967 // Advance the column indicator to force the line
3968 // drawing to wrap early. This will make the line
3969 // take up the same screen space when parts are concealed,
3970 // so that cursor line computations aren't messed up.
3971 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003972 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003973 // trailing junk to be written out of the screen line
3974 // we are building, 'boguscols' keeps track of the number
3975 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003976 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003977 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003978 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003979# ifdef FEAT_RIGHTLEFT
3980 if (wp->w_p_rl)
3981 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003982 wlv.col -= wlv.n_extra;
3983 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003984 }
3985 else
3986# endif
3987 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003988 wlv.col += wlv.n_extra;
3989 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003990 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003991 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003992 n_attr = 0;
3993 }
3994
3995
3996 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3997 {
3998 // Need to fill two screen columns.
3999# ifdef FEAT_RIGHTLEFT
4000 if (wp->w_p_rl)
4001 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004002 --wlv.boguscols;
4003 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004004 }
4005 else
4006# endif
4007 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004008 ++wlv.boguscols;
4009 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004010 }
4011 }
4012
4013# ifdef FEAT_RIGHTLEFT
4014 if (wp->w_p_rl)
4015 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004016 --wlv.boguscols;
4017 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004018 }
4019 else
4020# endif
4021 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004022 ++wlv.boguscols;
4023 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004024 }
4025 }
4026 else
4027 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004028 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004029 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004030 wlv.vcol += wlv.n_extra;
4031 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004032 n_attr = 0;
4033 }
4034 }
4035
4036 }
4037#endif // FEAT_CONCEAL
4038 else
zeertzjqb557f482023-08-22 22:07:34 +02004039 --skip_cells;
4040
4041 if (wlv.draw_state > WL_NR && skipped_cells > 0)
4042 {
4043 wlv.vcol += skipped_cells;
4044 skipped_cells = 0;
4045 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004046
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004047 // Only advance the "wlv.vcol" when after the 'number' or
4048 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004049 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004050#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004051 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004052#endif
4053 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004054 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004055
4056#ifdef FEAT_SYN_HL
4057 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004058 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004059#endif
4060
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004061 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01004062 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
4063 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004064
4065 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01004066 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004067 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004068 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004069 if (wlv.n_attr_skip > 0)
4070 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004071
4072 // At end of screen line and there is more to come: Display the line
4073 // so far. If there is no more to display it is caught above.
4074 if ((
4075#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004076 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004077#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004078 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01004079 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02004080 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004081#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004082 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004083#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004084#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004085 || text_prop_above || text_prop_follows
zeertzjq6a389722023-08-27 19:04:14 +02004086 || text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004087#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01004088 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01004089 && wlv.p_extra != at_end_str)
4090 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
4091 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004092 )
4093 {
4094#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01004095 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01004096 wlv_screen_line(wp, &wlv, FALSE);
4097 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004098 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004099 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004100#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01004101 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004102#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004103 ++wlv.row;
4104 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004105
4106 // When not wrapping and finished diff lines, or when displayed
4107 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01004108 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004109#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004110 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004111#endif
4112#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01004113 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004114#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01004115 ) || lcs_eol_one == -1)
4116#ifdef FEAT_PROP_POPUP
4117 && !text_prop_follows
4118#endif
4119 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004120 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004121#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004122 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004123 {
4124 // do not output more of the line, only the "below" prop
4125 ptr += STRLEN(ptr);
4126# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004127 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004128# endif
4129 }
4130#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004131
4132 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004133 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004134#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004135 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004136#endif
4137 )
4138 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004139 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
4140 draw_vsep_win(wp, wlv.row);
4141 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004142 }
4143
4144 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004145 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004146 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004147 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004148 break;
4149 }
4150
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004151 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004152#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004153 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004154#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004155#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004156 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004157#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004158 && wp->w_width == Columns)
4159 {
4160 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004161 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004162
4163 // Special trick to make copy/paste of wrapped lines work with
4164 // xterm/screen: write an extra character beyond the end of
4165 // the line. This will work with all terminal types
4166 // (regardless of the xn,am settings).
4167 // Only do this on a fast tty.
4168 // Only do this if the cursor is on the current line
4169 // (something has been written in it).
4170 // Don't do this for the GUI.
4171 // Don't do this for double-width characters.
4172 // Don't do this for a window not at the right screen border.
4173 if (p_tf
4174#ifdef FEAT_GUI
4175 && !gui.in_use
4176#endif
4177 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004178 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4179 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004180 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004181 || (*mb_off2cells)(
4182 LineOffset[wlv.screen_row - 1]
4183 + (int)Columns - 2,
4184 LineOffset[wlv.screen_row]
4185 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004186 {
4187 // First make sure we are at the end of the screen line,
4188 // then output the same character again to let the
4189 // terminal know about the wrap. If the terminal doesn't
4190 // auto-wrap, we overwrite the character.
4191 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004192 screen_char(LineOffset[wlv.screen_row - 1]
4193 + (unsigned)Columns - 1,
4194 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004195
4196 // When there is a multi-byte character, just output a
4197 // space to keep it simple.
4198 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004199 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004200 out_char(' ');
4201 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004202 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004203 + (Columns - 1)]);
4204 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004205 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004206 screen_start(); // don't know where cursor is now
4207 }
4208 }
4209
Bram Moolenaar1306b362022-08-06 15:59:06 +01004210 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004211
Bram Moolenaareed9d462021-02-15 20:38:25 +01004212 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004213#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004214 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004215# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004216 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004217# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004218 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004219 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004220#endif
4221#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004222 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004223 // When the filler lines are actually below the last line of the
4224 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004225 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004226 break;
4227#endif
4228 }
4229
4230 } // for every character in the line
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004231#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004232 vim_free(text_props);
4233 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004234 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004235#endif
4236
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004237 vim_free(wlv.p_extra_free);
zeertzjq58e1e012023-06-04 18:46:28 +01004238 vim_free(wlv.saved_p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004239 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004240}