blob: ef9f6637155f6ec9d89db3eb9f52e19562395f3d [file] [log] [blame]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * drawline.c: Functions for drawing window lines on the screen.
Bram Moolenaare89aeed2022-08-22 13:00:16 +010012 * This is the middle level, drawscreen.c is the higher level and screen.c the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020013 * lower level.
14 */
15
16#include "vim.h"
17
18#ifdef FEAT_SYN_HL
19/*
20 * Advance **color_cols and return TRUE when there are columns to draw.
21 */
22 static int
23advance_color_col(int vcol, int **color_cols)
24{
25 while (**color_cols >= 0 && vcol > **color_cols)
26 ++*color_cols;
27 return (**color_cols >= 0);
28}
29#endif
30
31#ifdef FEAT_SYN_HL
32/*
33 * Used when 'cursorlineopt' contains "screenline": compute the margins between
34 * which the highlighting is used.
35 */
36 static void
37margin_columns_win(win_T *wp, int *left_col, int *right_col)
38{
39 // cache previous calculations depending on w_virtcol
40 static int saved_w_virtcol;
41 static win_T *prev_wp;
42 static int prev_left_col;
43 static int prev_right_col;
44 static int prev_col_off;
45
46 int cur_col_off = win_col_off(wp);
47 int width1;
48 int width2;
49
50 if (saved_w_virtcol == wp->w_virtcol
51 && prev_wp == wp && prev_col_off == cur_col_off)
52 {
53 *right_col = prev_right_col;
54 *left_col = prev_left_col;
55 return;
56 }
57
58 width1 = wp->w_width - cur_col_off;
59 width2 = width1 + win_col_off2(wp);
60
61 *left_col = 0;
62 *right_col = width1;
63
64 if (wp->w_virtcol >= (colnr_T)width1)
65 *right_col = width1 + ((wp->w_virtcol - width1) / width2 + 1) * width2;
66 if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0)
67 *left_col = (wp->w_virtcol - width1) / width2 * width2 + width1;
68
69 // cache values
70 prev_left_col = *left_col;
71 prev_right_col = *right_col;
72 prev_wp = wp;
73 saved_w_virtcol = wp->w_virtcol;
74 prev_col_off = cur_col_off;
75}
76#endif
77
Bram Moolenaar45e4eea2022-12-01 18:38:02 +000078#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
79 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
80// using an attribute for the whole line
81# define LINE_ATTR
82#endif
83
Bram Moolenaar1306b362022-08-06 15:59:06 +010084// structure with variables passed between win_line() and other functions
85typedef struct {
86 int draw_state; // what to draw next
87
88 linenr_T lnum; // line number to be drawn
89
90 int startrow; // first row in the window to be drawn
91 int row; // row in the window, excl w_winrow
92 int screen_row; // row on the screen, incl w_winrow
93
94 long vcol; // virtual column, before wrapping
95 int col; // visual column on screen, after wrapping
96#ifdef FEAT_CONCEAL
97 int boguscols; // nonexistent columns added to "col" to force
98 // wrapping
Bram Moolenaarf53e0652023-02-19 14:16:02 +000099 int vcol_off_co; // offset for concealed characters
Bram Moolenaar1306b362022-08-06 15:59:06 +0100100#endif
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000101 int vcol_off_tp; // offset for virtual text
Bram Moolenaar1306b362022-08-06 15:59:06 +0100102#ifdef FEAT_SYN_HL
103 int draw_color_col; // highlight colorcolumn
104 int *color_cols; // pointer to according columns array
105#endif
106 int eol_hl_off; // 1 if highlighted char after EOL
107
108 unsigned off; // offset in ScreenLines/ScreenAttrs
109
110 int win_attr; // background for the whole window, except
111 // margins and "~" lines.
Bram Moolenaard7657e92022-09-20 18:59:30 +0100112 int wcr_attr; // attributes from 'wincolor'
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100113#ifdef FEAT_SYN_HL
114 int cul_attr; // set when 'cursorline' active
115#endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000116#ifdef LINE_ATTR
117 int line_attr; // for the whole line, includes 'cursorline'
118#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100119
120 int screen_line_flags; // flags for screen_line()
121
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100122 int fromcol; // start of inverting
123 int tocol; // end of inverting
124
125#ifdef FEAT_LINEBREAK
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100126 long vcol_sbr; // virtual column after showbreak
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100127 int need_showbreak; // overlong line, skipping first x chars
128 int dont_use_showbreak; // do not use 'showbreak'
129#endif
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100130#ifdef FEAT_PROP_POPUP
131 int text_prop_above_count;
132#endif
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100133
Bram Moolenaar1306b362022-08-06 15:59:06 +0100134 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
135 int cul_screenline;
136
137 int char_attr; // attributes for the next character
138
139 int n_extra; // number of extra bytes
140 char_u *p_extra; // string of extra chars, plus NUL, only used
141 // when c_extra and c_final are NUL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100142 char_u *p_extra_free; // p_extra buffer that needs to be freed
Bram Moolenaaree28c702022-11-17 14:56:00 +0000143 int extra_attr; // attributes for p_extra, should be combined
144 // with win_attr if needed
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000145 int n_attr_skip; // chars to skip before using extra_attr
Bram Moolenaar1306b362022-08-06 15:59:06 +0100146 int c_extra; // extra chars, all the same
147 int c_final; // final char, mandatory if set
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000148 int extra_for_textprop; // wlv.n_extra set for textprop
Bram Moolenaar1306b362022-08-06 15:59:06 +0100149
150 // saved "extra" items for when draw_state becomes WL_LINE (again)
151 int saved_n_extra;
152 char_u *saved_p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +0100153 char_u *saved_p_extra_free;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000154 int saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000155 int saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000156 int saved_extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100157 int saved_c_extra;
158 int saved_c_final;
159 int saved_char_attr;
160
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100161 char_u extra[NUMBUFLEN + MB_MAXBYTES];
162 // "%ld " and 'fdc' must fit in here, as well
163 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100164
Bram Moolenaar1306b362022-08-06 15:59:06 +0100165#ifdef FEAT_DIFF
166 hlf_T diff_hlf; // type of diff highlighting
167#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100168 int filler_lines; // nr of filler lines to be drawn
169 int filler_todo; // nr of filler lines still to do + 1
170#ifdef FEAT_SIGNS
171 sign_attrs_T sattr;
172#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100173} winlinevars_T;
174
175// draw_state values for items that are drawn in sequence:
176#define WL_START 0 // nothing done yet, must be zero
Martin Tournoij7904fa42022-10-04 16:28:45 +0100177#define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar1306b362022-08-06 15:59:06 +0100178#ifdef FEAT_FOLDING
179# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
180#else
181# define WL_FOLD WL_CMDLINE
182#endif
183#ifdef FEAT_SIGNS
184# define WL_SIGN (WL_FOLD + 1) // column for signs
185#else
186# define WL_SIGN WL_FOLD // column for signs
187#endif
188#define WL_NR (WL_SIGN + 1) // line number
189#ifdef FEAT_LINEBREAK
190# define WL_BRI (WL_NR + 1) // 'breakindent'
191#else
192# define WL_BRI WL_NR
193#endif
194#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
195# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
196#else
197# define WL_SBR WL_BRI
198#endif
199#define WL_LINE (WL_SBR + 1) // text in the line
200
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100201#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200202/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000203 * Return TRUE if CursorLineSign highlight is to be used.
204 */
205 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100206use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000207{
208 return wp->w_p_cul
209 && lnum == wp->w_cursor.lnum
210 && (wp->w_p_culopt_flags & CULOPT_NBR);
211}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100212#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000213
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100214
215#ifdef FEAT_FOLDING
216/*
217 * Setup for drawing the 'foldcolumn', if there is one.
218 */
219 static void
220handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
221{
222 int fdc = compute_foldcolumn(wp, 0);
223
224 if (fdc <= 0)
225 return;
226
227 // Allocate a buffer, "wlv->extra[]" may already be in use.
228 vim_free(wlv->p_extra_free);
229 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
Yegappan Lakshmanan465de3a2022-12-26 12:50:04 +0000230 if (wlv->p_extra_free == NULL)
231 return;
232
233 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
zeertzjq58e1e012023-06-04 18:46:28 +0100234 wp, FALSE, wlv->lnum);
Yegappan Lakshmanan465de3a2022-12-26 12:50:04 +0000235 wlv->p_extra_free[wlv->n_extra] = NUL;
236 wlv->p_extra = wlv->p_extra_free;
237 wlv->c_extra = NUL;
238 wlv->c_final = NUL;
239 if (use_cursor_line_highlight(wp, wlv->lnum))
240 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
241 else
242 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100243}
244#endif
245
246#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000247/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100248 * Get information needed to display the sign in line "wlv->lnum" in window
249 * "wp".
250 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200251 * Otherwise the sign is going to be displayed in the sign column.
252 */
253 static void
254get_sign_display_info(
255 int nrcol,
256 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100257 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200258{
259 int text_sign;
260# ifdef FEAT_SIGN_ICONS
261 int icon_sign;
262# endif
263
264 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100265 wlv->c_extra = ' ';
266 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200267 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100268 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200269 else
270 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100271 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100272 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000273 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100274 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100275 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200276 }
277
Bram Moolenaar1306b362022-08-06 15:59:06 +0100278 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200279#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100280 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200281#endif
282 )
283 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100284 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200285# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100286 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200287 if (gui.in_use && icon_sign != 0)
288 {
289 // Use the image in this position.
290 if (nrcol)
291 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100292 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100293 sprintf((char *)wlv->extra, "%-*c ",
294 number_width(wp), SIGN_BYTE);
295 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100296 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200297 }
298 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100299 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200300# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100301 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
302 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200303 {
304 if (nrcol)
305 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100306 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100307 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200308 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100309 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100310 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200311 }
312 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100313 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200314 }
315# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100316 wlv->c_final = NUL;
317 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200318 }
319 else
320# endif
321 if (text_sign != 0)
322 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100323 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100324 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200325 {
326 if (nrcol)
327 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100328 int width = number_width(wp) - 2;
329 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200330
331 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100332 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100333 vim_snprintf((char *)wlv->extra + n,
334 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100335 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200336 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100337 wlv->c_extra = NUL;
338 wlv->c_final = NUL;
339 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200340 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000341
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100342 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100343 && wlv->sattr.sat_culhl > 0)
344 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000345 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100346 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200347 }
348 }
349}
350#endif
351
Bram Moolenaard7657e92022-09-20 18:59:30 +0100352/*
353 * Display the absolute or relative line number. After the first row fill with
354 * blanks when the 'n' flag isn't in 'cpo'.
355 */
356 static void
357handle_lnum_col(
358 win_T *wp,
359 winlinevars_T *wlv,
360 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100361 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100362{
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100363 int has_cpo_n = vim_strchr(p_cpo, CPO_NUMCOL) != NULL;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100364 int lnum_row = wlv->startrow + wlv->filler_lines
365#ifdef FEAT_PROP_POPUP
366 + wlv->text_prop_above_count
367#endif
368 ;
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100369
Bram Moolenaard7657e92022-09-20 18:59:30 +0100370 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100371 && (wlv->row <= lnum_row || !has_cpo_n)
Bram Moolenaar37251162022-10-06 20:48:00 +0100372 // there is no line number in a wrapped line when "n" is in
373 // 'cpoptions', but 'breakindent' assumes it anyway.
374 && !((has_cpo_n
375#ifdef FEAT_LINEBREAK
376 && !wp->w_p_bri
377#endif
378 ) && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100379 {
380#ifdef FEAT_SIGNS
381 // If 'signcolumn' is set to 'number' and a sign is present
382 // in 'lnum', then display the sign instead of the line
383 // number.
384 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
385 get_sign_display_info(TRUE, wp, wlv);
386 else
387#endif
388 {
389 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100390 // When there are text properties above the line put the line number
391 // below them.
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100392 if (wlv->row == lnum_row
zeertzjq88bb3e02023-05-02 20:52:59 +0100393 && (wp->w_skipcol == 0 || wlv->row > 0
Bram Moolenaareb4de622022-10-15 13:42:17 +0100394 || (wp->w_p_nu && wp->w_p_rnu)))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100395 {
396 long num;
397 char *fmt = "%*ld ";
398
399 if (wp->w_p_nu && !wp->w_p_rnu)
400 // 'number' + 'norelativenumber'
401 num = (long)wlv->lnum;
402 else
403 {
404 // 'relativenumber', don't use negative numbers
405 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
406 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
407 {
408 // 'number' + 'relativenumber'
409 num = wlv->lnum;
410 fmt = "%-*ld ";
411 }
412 }
413
414 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100415 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100416 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
417 ++wlv->p_extra)
418 *wlv->p_extra = '-';
419#ifdef FEAT_RIGHTLEFT
420 if (wp->w_p_rl) // reverse line numbers
421 {
422 char_u *p1, *p2;
423 int t;
424
425 // like rl_mirror(), but keep the space at the end
426 p2 = skipwhite(wlv->extra);
427 p2 = skiptowhite(p2) - 1;
428 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
429 {
430 t = *p1;
431 *p1 = *p2;
432 *p2 = t;
433 }
434 }
435#endif
436 wlv->p_extra = wlv->extra;
437 wlv->c_extra = NUL;
438 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100439 }
440 else
441 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100442 wlv->c_extra = ' ';
443 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100444 }
445 wlv->n_extra = number_width(wp) + 1;
446 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
447#ifdef FEAT_SYN_HL
448 // When 'cursorline' is set highlight the line number of
449 // the current line differently.
450 // When 'cursorlineopt' does not have "line" only
451 // highlight the line number itself.
452 // TODO: Can we use CursorLine instead of CursorLineNr
453 // when CursorLineNr isn't set?
454 if (wp->w_p_cul
455 && wlv->lnum == wp->w_cursor.lnum
456 && (wp->w_p_culopt_flags & CULOPT_NBR)
457 && (wlv->row == wlv->startrow + wlv->filler_lines
458 || (wlv->row > wlv->startrow + wlv->filler_lines
459 && (wp->w_p_culopt_flags & CULOPT_LINE))))
460 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
461#endif
462 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
463 && HL_ATTR(HLF_LNA) != 0)
464 // Use LineNrAbove
465 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
466 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
467 && HL_ATTR(HLF_LNB) != 0)
468 // Use LineNrBelow
469 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
470 }
471#ifdef FEAT_SIGNS
472 if (num_attr)
473 wlv->char_attr = num_attr;
474#endif
475 }
476}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100477
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100478#ifdef FEAT_LINEBREAK
479 static void
480handle_breakindent(win_T *wp, winlinevars_T *wlv)
481{
482 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100483 && *get_showbreak_value(wp) != NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100484 // draw indent after showbreak value
485 wlv->draw_state = WL_BRI;
486 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
487 // After the showbreak, draw the breakindent
488 wlv->draw_state = WL_BRI - 1;
489
490 // draw 'breakindent': indent wrapped text accordingly
491 if (wlv->draw_state == WL_BRI - 1)
492 {
493 wlv->draw_state = WL_BRI;
494 // if wlv->need_showbreak is set, breakindent also applies
495 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
496# ifdef FEAT_DIFF
497 && wlv->filler_lines == 0
498# endif
499# ifdef FEAT_PROP_POPUP
500 && !wlv->dont_use_showbreak
501# endif
502 )
503 {
504 wlv->char_attr = 0;
505# ifdef FEAT_DIFF
506 if (wlv->diff_hlf != (hlf_T)0)
507 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
508# endif
509 wlv->p_extra = NULL;
510 wlv->c_extra = ' ';
511 wlv->c_final = NUL;
512 wlv->n_extra = get_breakindent_win(wp,
513 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
514 if (wlv->row == wlv->startrow)
515 {
516 wlv->n_extra -= win_col_off2(wp);
517 if (wlv->n_extra < 0)
518 wlv->n_extra = 0;
519 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100520 if (wp->w_skipcol > 0 && wlv->startrow == 0
521 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100522 wlv->need_showbreak = FALSE;
523 // Correct end of highlighted area for 'breakindent',
524 // required when 'linebreak' is also set.
525 if (wlv->tocol == wlv->vcol)
526 wlv->tocol += wlv->n_extra;
527 }
528 }
529}
530#endif
531
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100532#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
533 static void
534handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
535{
536# ifdef FEAT_DIFF
537 if (wlv->filler_todo > 0)
538 {
539 // Draw "deleted" diff line(s).
540 if (char2cells(wp->w_fill_chars.diff) > 1)
541 {
542 wlv->c_extra = '-';
543 wlv->c_final = NUL;
544 }
545 else
546 {
547 wlv->c_extra = wp->w_fill_chars.diff;
548 wlv->c_final = NUL;
549 }
550# ifdef FEAT_RIGHTLEFT
551 if (wp->w_p_rl)
552 wlv->n_extra = wlv->col + 1;
553 else
554# endif
555 wlv->n_extra = wp->w_width - wlv->col;
556 wlv->char_attr = HL_ATTR(HLF_DED);
557 }
558# endif
559
560# ifdef FEAT_LINEBREAK
561 char_u *sbr = get_showbreak_value(wp);
562 if (*sbr != NUL && wlv->need_showbreak)
563 {
564 // Draw 'showbreak' at the start of each broken line.
565 wlv->p_extra = sbr;
566 wlv->c_extra = NUL;
567 wlv->c_final = NUL;
568 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100569 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100570 wlv->need_showbreak = FALSE;
571 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100572
573 // Correct start of highlighted area for 'showbreak'.
574 if (wlv->fromcol >= wlv->vcol && wlv->fromcol < wlv->vcol_sbr)
575 wlv->fromcol = wlv->vcol_sbr;
576
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100577 // Correct end of highlighted area for 'showbreak',
578 // required when 'linebreak' is also set.
579 if (wlv->tocol == wlv->vcol)
580 wlv->tocol += wlv->n_extra;
581 // combine 'showbreak' with 'wincolor'
582 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
583# ifdef FEAT_SYN_HL
584 // combine 'showbreak' with 'cursorline'
585 if (wlv->cul_attr != 0)
586 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
587# endif
588 }
589# endif
590}
591#endif
592
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100593#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100594/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100595 * Return the cell size of virtual text after truncation.
596 */
597 static int
598textprop_size_after_trunc(
599 win_T *wp,
600 int flags, // TP_FLAG_ALIGN_*
601 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100602 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100603 char_u *text,
604 int *n_used_ptr)
605{
606 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100607 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100608 int len = (int)STRLEN(text);
609 int strsize = 0;
610 int n_used;
611
Bram Moolenaar7e017462022-10-11 21:02:09 +0100612 // if the remaining size is to small and 'wrap' is set we wrap anyway and
613 // use the next line
614 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100615 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100616 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100617 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100618 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
619 {
620 int clen = ptr2cells(text + n_used);
621
622 if (strsize + clen > space)
623 break;
624 strsize += clen;
625 }
626 *n_used_ptr = n_used;
627 return strsize;
628}
629
630/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100631 * Take care of padding, right-align and truncation of virtual text after a
632 * line.
633 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
634 * padding, right-align and truncation. Otherwise only the size is computed.
635 * When "n_attr" is NULL returns the number of screen cells used.
636 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100637 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100638 int
639text_prop_position(
640 win_T *wp,
641 textprop_T *tp,
porygonisaduck38854b52022-11-27 20:55:05 +0000642 int vcol, // current text column
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100643 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100644 int *n_extra, // nr of bytes for virtual text
645 char_u **p_extra, // virtual text
646 int *n_attr, // attribute cells, NULL if not used
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000647 int *n_attr_skip, // cells to skip attr, NULL if not used
648 int do_skip) // skip_cells is not zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200649{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100650 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100651 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100652 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
Bram Moolenaar1aeb3eb2023-01-01 14:04:51 +0000653 int wrap = tp->tp_col < MAXCOL || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100654 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
porygonisaduck38854b52022-11-27 20:55:05 +0000655 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100656 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100657 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100658 int before = room; // spaces before the text
659 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100660 int n_used = *n_extra;
661 char_u *l = NULL;
662 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100663 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100664 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200665
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100666 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100667 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100668 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100669
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100670 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100671 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100672 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100673 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar2354b662023-04-23 21:42:25 +0100674 if (after < 0)
675 {
676 // text "above" has too much padding to fit
677 padding += after;
678 after = 0;
679 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100680 }
681 else
682 {
683 // Right-align: fill with before
684 if (right)
685 before -= cells;
porygonisaduck38854b52022-11-27 20:55:05 +0000686
687 // Below-align: empty line add one character
Bram Moolenaar7c02ad92022-11-29 21:37:13 +0000688 if (below && vcol == 0 && col_with_padding == col_off
689 && wp->w_width - col_off == before)
690 col_with_padding += 1;
porygonisaduck38854b52022-11-27 20:55:05 +0000691
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100692 if (before < 0
693 || !(right || below)
porygonisaduck38854b52022-11-27 20:55:05 +0000694 || (below ? (col_with_padding <= col_off || !wp->w_p_wrap)
695 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100696 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100697 if (right && (wrap
698 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100699 {
700 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100701 before = wp->w_width - col_off - strsize + room;
702 if (before < 0)
703 before = 0;
704 else
705 n_used = *n_extra;
706 }
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000707 else if (below && before > vcol && do_skip)
708 before -= vcol;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100709 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100710 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100711 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100712 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100713
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100714 // With 'nowrap' add one to show the "extends" character if needed (it
715 // doesn't show if the text just fits).
716 if (!wp->w_p_wrap
717 && n_used < *n_extra
718 && wp->w_lcs_chars.ext != NUL
719 && wp->w_p_list)
720 ++n_used;
721
722 // add 1 for NUL, 2 for when '…' is used
723 if (n_attr != NULL)
Christian Brabandtf1cc4d52023-08-12 00:14:14 +0200724 l = alloc(n_used + before + after + (padding > 0 ? padding : 0) + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100725 if (n_attr == NULL || l != NULL)
726 {
727 int off = 0;
728
729 if (n_attr != NULL)
730 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100731 vim_memset(l, ' ', before);
732 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100733 if (padding > 0)
734 {
735 vim_memset(l + off, ' ', padding);
736 off += padding;
737 }
738 vim_strncpy(l + off, *p_extra, n_used);
739 off += n_used;
740 }
741 else
742 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100743 off = before + after + padding + n_used;
744 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100745 }
746 if (n_attr != NULL)
747 {
748 if (n_used < *n_extra && wp->w_p_wrap)
749 {
750 char_u *lp = l + off - 1;
751
752 if (has_mbyte)
753 {
h-east4c42c7e2023-04-17 21:44:57 +0100754 char_u buf[MB_MAXBYTES + 1];
755 char_u *cp = buf;
756
757 // change the last character to '…', converted to the
758 // current 'encoding'
759 STRCPY(buf, "…");
760 if (!enc_utf8)
761 {
762 vimconv_T vc;
763
764 vc.vc_type = CONV_NONE;
765 convert_setup(&vc, (char_u *)"utf-8", p_enc);
766 if (vc.vc_type != CONV_NONE)
767 {
768 cp = string_convert(&vc, buf, NULL);
769 if (cp == NULL)
770 {
771 // when conversion fails use '>'
772 cp = buf;
773 STRCPY(buf, ">");
774 }
775 convert_setup(&vc, NULL, NULL);
776 }
777 }
778
779 lp -= (*mb_ptr2cells)(cp) - 1;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100780 lp -= (*mb_head_off)(l, lp);
h-east4c42c7e2023-04-17 21:44:57 +0100781 STRCPY(lp, cp);
Bram Moolenaar13845c42022-10-09 15:26:03 +0100782 n_used = lp - l + 3 - before - padding;
h-east4c42c7e2023-04-17 21:44:57 +0100783 if (cp != buf)
784 vim_free(cp);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100785 }
786 else
787 // change last character to '>'
788 *lp = '>';
789 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100790 else if (after > 0)
791 {
792 vim_memset(l + off, ' ', after);
793 l[off + after] = NUL;
794 }
795
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100796 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100797 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100798 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100799 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100800 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100801
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000802 // n_attr_skip will not be decremented before draw_state is
803 // WL_LINE
Christian Brabandtf1cc4d52023-08-12 00:14:14 +0200804 *n_attr_skip = before + (padding > 0 ? padding : 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100805 }
806 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100807 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100808
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100809 if (n_attr == NULL)
810 return cells;
811 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200812}
813#endif
814
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100815/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100816 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100817 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
818 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100819 */
820 static void
821wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
822{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100823 if (wlv->row == 0 && wp->w_skipcol > 0
824#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100825 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100826 && *get_showbreak_value(wp) == NUL
827#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100828 // do not overwrite the 'listchars' "precedes" text with "<<<"
829 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100830 {
831 int off = (int)(current_ScreenLine - ScreenLines);
zeertzjqecb87dd2023-06-03 19:45:06 +0100832 int max_off = off + screen_Columns;
Bram Moolenaareb4de622022-10-15 13:42:17 +0100833 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100834
Bram Moolenaareb4de622022-10-15 13:42:17 +0100835 if (wp->w_p_nu && wp->w_p_rnu)
836 // Do not overwrite the line number, change "123 text" to
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100837 // "123<<<xt".
Bram Moolenaareb4de622022-10-15 13:42:17 +0100838 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
839 {
840 ++off;
841 ++skip;
842 }
843
844 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100845 {
zeertzjqecb87dd2023-06-03 19:45:06 +0100846 if ((*mb_off2cells)(off, max_off) > 1)
847 // When the first half of a double-width character is
848 // overwritten, change the second half to a space.
849 ScreenLines[off + 1] = ' ';
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100850 ScreenLines[off] = '<';
851 if (enc_utf8)
852 ScreenLinesUC[off] = 0;
853 ScreenAttrs[off] = HL_ATTR(HLF_AT);
854 ++off;
855 }
856 }
857
858 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
859 negative_width ? -wp->w_width : wp->w_width,
860 wlv->screen_line_flags);
861}
862
863/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100864 * Called when finished with the line: draw the screen line and handle any
865 * highlighting until the right of the window.
866 */
867 static void
868draw_screen_line(win_T *wp, winlinevars_T *wlv)
869{
870#ifdef FEAT_SYN_HL
871 long v;
872
873 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
874 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100875 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100876 else
877 v = wp->w_leftcol;
878
879 // check if line ends before left margin
880 if (wlv->vcol < v + wlv->col - win_col_off(wp))
881 wlv->vcol = v + wlv->col - win_col_off(wp);
882# ifdef FEAT_CONCEAL
883 // Get rid of the boguscols now, we want to draw until the right
884 // edge for 'cursorcolumn'.
885 wlv->col -= wlv->boguscols;
886 wlv->boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000887# define VCOL_HLC (wlv->vcol - wlv->vcol_off_co - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100888# else
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000889# define VCOL_HLC (wlv->vcol - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100890# endif
891
892 if (wlv->draw_color_col)
893 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
894
895 if (((wp->w_p_cuc
896 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
897 && (int)wp->w_virtcol <
898 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
899 && wlv->lnum != wp->w_cursor.lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000900 || wlv->draw_color_col
901# ifdef LINE_ATTR
902 || wlv->line_attr != 0
903# endif
904 || wlv->win_attr != 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100905# ifdef FEAT_RIGHTLEFT
906 && !wp->w_p_rl
907# endif
908 )
909 {
910 int rightmost_vcol = 0;
911 int i;
912
913 if (wp->w_p_cuc)
914 rightmost_vcol = wp->w_virtcol;
915 if (wlv->draw_color_col)
916 // determine rightmost colorcolumn to possibly draw
917 for (i = 0; wlv->color_cols[i] >= 0; ++i)
918 if (rightmost_vcol < wlv->color_cols[i])
919 rightmost_vcol = wlv->color_cols[i];
920
921 while (wlv->col < wp->w_width)
922 {
923 ScreenLines[wlv->off] = ' ';
924 if (enc_utf8)
925 ScreenLinesUC[wlv->off] = 0;
926 ScreenCols[wlv->off] = MAXCOL;
927 ++wlv->col;
928 if (wlv->draw_color_col)
929 wlv->draw_color_col = advance_color_col(
930 VCOL_HLC, &wlv->color_cols);
931
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000932 int attr = wlv->win_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100933 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000934 attr = HL_ATTR(HLF_CUC);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100935 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000936 attr = HL_ATTR(HLF_MC);
937# ifdef LINE_ATTR
938 else if (wlv->line_attr != 0)
939 attr = wlv->line_attr;
940# endif
941 ScreenAttrs[wlv->off++] = attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100942
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000943 if (VCOL_HLC >= rightmost_vcol
944# ifdef LINE_ATTR
945 && wlv->line_attr == 0
946# endif
947 && wlv->win_attr == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100948 break;
949
950 ++wlv->vcol;
951 }
952 }
953#endif
954
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100955 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100956 ++wlv->row;
957 ++wlv->screen_row;
958}
959#undef VCOL_HLC
960
961/*
962 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100963 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100964 */
965 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100966win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100967{
968 wlv->col = 0;
969 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
970
971#ifdef FEAT_RIGHTLEFT
972 if (wp->w_p_rl)
973 {
974 // Rightleft window: process the text in the normal direction, but put
975 // it in current_ScreenLine[] from right to left. Start at the
976 // rightmost column of the window.
977 wlv->col = wp->w_width - 1;
978 wlv->off += wlv->col;
979 wlv->screen_line_flags |= SLF_RIGHTLEFT;
980 }
981#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100982 if (save_extra)
983 {
984 // reset the drawing state for the start of a wrapped line
985 wlv->draw_state = WL_START;
986 wlv->saved_n_extra = wlv->n_extra;
987 wlv->saved_p_extra = wlv->p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +0100988 vim_free(wlv->saved_p_extra_free);
989 wlv->saved_p_extra_free = wlv->p_extra_free;
990 wlv->p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000991 wlv->saved_extra_attr = wlv->extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000992 wlv->saved_n_attr_skip = wlv->n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000993 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100994 wlv->saved_c_extra = wlv->c_extra;
995 wlv->saved_c_final = wlv->c_final;
996#ifdef FEAT_SYN_HL
997 if (!(wlv->cul_screenline
998# ifdef FEAT_DIFF
999 && wlv->diff_hlf == (hlf_T)0
1000# endif
1001 ))
1002 wlv->saved_char_attr = wlv->char_attr;
1003 else
1004#endif
1005 wlv->saved_char_attr = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001006
1007 // these are not used until restored in win_line_continue()
Bram Moolenaar1306b362022-08-06 15:59:06 +01001008 wlv->n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001009 wlv->n_attr_skip = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001010 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001011}
1012
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001013/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001014 * Called when wlv->draw_state is set to WL_LINE.
1015 */
1016 static void
1017win_line_continue(winlinevars_T *wlv)
1018{
1019 if (wlv->saved_n_extra > 0)
1020 {
1021 // Continue item from end of wrapped line.
1022 wlv->n_extra = wlv->saved_n_extra;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001023 wlv->saved_n_extra = 0;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001024 wlv->c_extra = wlv->saved_c_extra;
1025 wlv->c_final = wlv->saved_c_final;
1026 wlv->p_extra = wlv->saved_p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +01001027 vim_free(wlv->p_extra_free);
1028 wlv->p_extra_free = wlv->saved_p_extra_free;
1029 wlv->saved_p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001030 wlv->extra_attr = wlv->saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001031 wlv->n_attr_skip = wlv->saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001032 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001033 wlv->char_attr = wlv->saved_char_attr;
1034 }
1035 else
1036 wlv->char_attr = wlv->win_attr;
1037}
1038
zeertzjqb7acea12022-12-12 13:20:43 +00001039#ifdef FEAT_SYN_HL
1040 static void
1041apply_cursorline_highlight(
1042 winlinevars_T *wlv,
1043 int sign_present UNUSED)
1044{
1045 wlv->cul_attr = HL_ATTR(HLF_CUL);
1046# ifdef FEAT_SIGNS
1047 // Combine the 'cursorline' and sign highlighting, depending on
1048 // the sign priority.
1049 if (sign_present && wlv->sattr.sat_linehl > 0)
1050 {
1051 if (wlv->sattr.sat_priority >= 100)
1052 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1053 else
1054 wlv->line_attr = hl_combine_attr(wlv->line_attr, wlv->cul_attr);
1055 }
1056 else
1057# endif
1058# if defined(FEAT_QUICKFIX)
1059 // let the line attribute overrule 'cursorline', otherwise
1060 // it disappears when both have background set;
1061 // 'cursorline' can use underline or bold to make it show
1062 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1063# else
1064 wlv->line_attr = wlv->cul_attr;
1065# endif
1066}
1067#endif
1068
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001069/*
Luuk van Baal30805a12023-05-27 22:22:10 +01001070 * Display line "lnum" of window "wp" on the screen.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001071 * Start at row "startrow", stop when "endrow" is reached.
Luuk van Baal30805a12023-05-27 22:22:10 +01001072 * When "number_only" is TRUE only update the number column.
1073 * "spv" is used to store information for spell checking, kept between
1074 * sequential calls for the same window.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001075 * wp->w_virtcol needs to be valid.
1076 *
1077 * Return the number of last row the line occupies.
1078 */
1079 int
1080win_line(
1081 win_T *wp,
1082 linenr_T lnum,
1083 int startrow,
1084 int endrow,
Luuk van Baal30805a12023-05-27 22:22:10 +01001085 int number_only,
1086 spellvars_T *spv UNUSED)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001087{
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001088 winlinevars_T wlv; // variables passed between functions
1089
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001090 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001091 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001092 char_u *line; // current line
1093 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001094
Bram Moolenaar1306b362022-08-06 15:59:06 +01001095#ifdef FEAT_PROP_POPUP
1096 char_u *p_extra_free2 = NULL; // another p_extra to be freed
1097#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001098#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001099 int in_linebreak = FALSE; // n_extra set for showing linebreak
1100#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001101 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +01001102 // displaying eol at end-of-line
1103 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001104 int lcs_prec_todo = wp->w_lcs_chars.prec;
1105 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001106
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001107 int n_attr = 0; // chars with special attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001108 int saved_attr2 = 0; // char_attr saved for n_attr
1109 int n_attr3 = 0; // chars with overruling special attr
1110 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001111
Bram Moolenaarcd105412022-10-10 19:50:42 +01001112 int n_skip = 0; // nr of cells to skip for 'nowrap' or
1113 // concealing
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001114#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001115 int skip_cells = 0; // nr of cells to skip for virtual text
1116 // after the line, when w_skipcol is
1117 // larger than the text length
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001118#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001119
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001120 int fromcol_prev = -2; // start of inverting after cursor
1121 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001122 int lnum_in_visual_area = FALSE;
1123 pos_T pos;
1124 long v;
1125
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001126 int attr_pri = FALSE; // char_attr has priority
1127 int area_highlighting = FALSE; // Visual or incsearch highlighting
1128 // in this line
1129 int vi_attr = 0; // attributes for Visual and incsearch
1130 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001131 int area_attr = 0; // attributes desired by highlighting
1132 int search_attr = 0; // attributes desired by 'hlsearch'
1133#ifdef FEAT_SYN_HL
1134 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1135 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001136 int prev_syntax_col = -1; // column of prev_syntax_attr
1137 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001138 int has_syntax = FALSE; // this buffer has syntax highl.
1139 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001140#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001141#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001142 int did_line = FALSE; // set to TRUE when line text done
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001143 int text_prop_count;
1144 int text_prop_next = 0; // next text property to use
1145 textprop_T *text_props = NULL;
1146 int *text_prop_idxs = NULL;
1147 int text_props_active = 0;
1148 proptype_T *text_prop_type = NULL;
1149 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001150 int text_prop_attr_comb = 0; // text_prop_attr combined with
1151 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001152 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001153 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001154 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001155 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001156 int saved_search_attr = 0; // search_attr to be used when n_extra
1157 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001158 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001159 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001160#endif
1161#ifdef FEAT_SPELL
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001162 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001163# define SPWORDLEN 150
1164 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1165 int nextlinecol = 0; // column where nextline[] starts
1166 int nextline_idx = 0; // index in nextline[] where next line
1167 // starts
1168 int spell_attr = 0; // attributes desired by spelling
1169 int word_end = 0; // last byte with same spell_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001170 int cur_checked_col = 0; // checked column for current line
1171#endif
1172 int extra_check = 0; // has extra highlighting
1173 int multi_attr = 0; // attributes desired by multibyte
1174 int mb_l = 1; // multi-byte byte length
1175 int mb_c = 0; // decoded multi-byte character
1176 int mb_utf8 = FALSE; // screen char is UTF-8 char
1177 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001178#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001179 int change_start = MAXCOL; // first col of changed area
1180 int change_end = -1; // last col of changed area
1181#endif
1182 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001183 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001184 int in_multispace = FALSE; // in multiple consecutive spaces
1185 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001186#ifdef LINE_ATTR
Bram Moolenaarbf915842022-08-06 22:38:02 +01001187 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001188#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001189 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001190 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001191#ifdef FEAT_ARABIC
1192 int prev_c = 0; // previous Arabic character
1193 int prev_c1 = 0; // first composing char for prev_c
1194#endif
1195#if defined(LINE_ATTR)
1196 int did_line_attr = 0;
1197#endif
1198#ifdef FEAT_TERMINAL
1199 int get_term_attr = FALSE;
1200#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001201
Martin Tournoijba43e762022-10-13 22:12:15 +01001202#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001203 // margin columns for the screen line, needed for when 'cursorlineopt'
1204 // contains "screenline"
1205 int left_curline_col = 0;
1206 int right_curline_col = 0;
1207#endif
1208
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001209#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1210 int feedback_col = 0;
1211 int feedback_old_attr = -1;
1212#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001213
1214#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1215 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001216#endif
1217#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001218 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001219#endif
1220#ifdef FEAT_CONCEAL
1221 int syntax_flags = 0;
1222 int syntax_seqnr = 0;
1223 int prev_syntax_id = 0;
1224 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1225 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001226 int did_wcol = FALSE;
1227 int old_boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001228# define VCOL_HLC (wlv.vcol - wlv.vcol_off_co - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001229# define FIX_FOR_BOGUSCOLS \
1230 { \
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001231 wlv.n_extra += wlv.vcol_off_co; \
1232 wlv.vcol -= wlv.vcol_off_co; \
1233 wlv.vcol_off_co = 0; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001234 wlv.col -= wlv.boguscols; \
1235 old_boguscols = wlv.boguscols; \
1236 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001237 }
1238#else
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001239# define VCOL_HLC (wlv.vcol - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001240#endif
1241
1242 if (startrow > endrow) // past the end already!
1243 return startrow;
1244
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001245 CLEAR_FIELD(wlv);
1246
1247 wlv.lnum = lnum;
1248 wlv.startrow = startrow;
1249 wlv.row = startrow;
1250 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001251 wlv.fromcol = -10;
1252 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001253#ifdef FEAT_LINEBREAK
1254 wlv.vcol_sbr = -1;
1255#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001256
1257 if (!number_only)
1258 {
1259 // To speed up the loop below, set extra_check when there is linebreak,
1260 // trailing white space and/or syntax processing to be done.
1261#ifdef FEAT_LINEBREAK
1262 extra_check = wp->w_p_lbr;
1263#endif
1264#ifdef FEAT_SYN_HL
1265 if (syntax_present(wp) && !wp->w_s->b_syn_error
1266# ifdef SYN_TIME_LIMIT
1267 && !wp->w_s->b_syn_slow
1268# endif
1269 )
1270 {
1271 // Prepare for syntax highlighting in this line. When there is an
1272 // error, stop syntax highlighting.
1273 save_did_emsg = did_emsg;
1274 did_emsg = FALSE;
1275 syntax_start(wp, lnum);
1276 if (did_emsg)
1277 wp->w_s->b_syn_error = TRUE;
1278 else
1279 {
1280 did_emsg = save_did_emsg;
1281#ifdef SYN_TIME_LIMIT
1282 if (!wp->w_s->b_syn_slow)
1283#endif
1284 {
1285 has_syntax = TRUE;
1286 extra_check = TRUE;
1287 }
1288 }
1289 }
1290
1291 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001292 wlv.color_cols = wp->w_p_cc_cols;
1293 if (wlv.color_cols != NULL)
1294 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001295#endif
1296
1297#ifdef FEAT_TERMINAL
1298 if (term_show_buffer(wp->w_buffer))
1299 {
1300 extra_check = TRUE;
1301 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001302 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001303 }
1304#endif
1305
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001306 // handle Visual active in this window
1307 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1308 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001309 pos_T *top, *bot;
1310
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001311 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1312 {
1313 // Visual is after curwin->w_cursor
1314 top = &curwin->w_cursor;
1315 bot = &VIsual;
1316 }
1317 else
1318 {
1319 // Visual is before curwin->w_cursor
1320 top = &VIsual;
1321 bot = &curwin->w_cursor;
1322 }
1323 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1324 if (VIsual_mode == Ctrl_V)
1325 {
1326 // block mode
1327 if (lnum_in_visual_area)
1328 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001329 wlv.fromcol = wp->w_old_cursor_fcol;
1330 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001331 }
1332 }
1333 else
1334 {
1335 // non-block mode
1336 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001337 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001338 else if (lnum == top->lnum)
1339 {
1340 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001341 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001342 else
1343 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001344 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001345 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001346 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001347 }
1348 }
1349 if (VIsual_mode != 'V' && lnum == bot->lnum)
1350 {
1351 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1352 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001353 wlv.fromcol = -10;
1354 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001355 }
1356 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001357 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001358 else
1359 {
1360 pos = *bot;
1361 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001362 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1363 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001364 else
1365 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001366 getvvcol(wp, &pos, NULL, NULL,
1367 (colnr_T *)&wlv.tocol);
1368 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001369 }
1370 }
1371 }
1372 }
1373
1374 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001375 if (!highlight_match && lnum == curwin->w_cursor.lnum
1376 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001377#ifdef FEAT_GUI
1378 && !gui.in_use
1379#endif
1380 )
1381 noinvcur = TRUE;
1382
1383 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001384 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001385 {
1386 area_highlighting = TRUE;
1387 vi_attr = HL_ATTR(HLF_V);
1388#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1389 if ((clip_star.available && !clip_star.owned
1390 && clip_isautosel_star())
1391 || (clip_plus.available && !clip_plus.owned
1392 && clip_isautosel_plus()))
1393 vi_attr = HL_ATTR(HLF_VNC);
1394#endif
1395 }
1396 }
1397
1398 // handle 'incsearch' and ":s///c" highlighting
1399 else if (highlight_match
1400 && wp == curwin
1401 && lnum >= curwin->w_cursor.lnum
1402 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1403 {
1404 if (lnum == curwin->w_cursor.lnum)
1405 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001406 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001407 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001408 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001409 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1410 {
1411 pos.lnum = lnum;
1412 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001413 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001414 }
1415 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001416 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001417 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001418 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1419 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001420 area_highlighting = TRUE;
1421 vi_attr = HL_ATTR(HLF_I);
1422 }
1423 }
1424
1425#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001426 wlv.filler_lines = diff_check(wp, lnum);
1427 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001428 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001429 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001430 {
1431 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001432 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001433 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001434 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001435 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001436 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001437 }
1438 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001439 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001440 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001441 area_highlighting = TRUE;
1442 }
1443 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001444 wlv.filler_lines = wp->w_topfill;
1445 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001446#endif
1447
1448#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001449 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001450 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001451 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001452#endif
1453
1454#ifdef LINE_ATTR
1455# ifdef FEAT_SIGNS
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001456 // If this line has a sign with line highlighting set wlv.line_attr.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001457 if (sign_present)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001458 wlv.line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001459# endif
1460# if defined(FEAT_QUICKFIX)
1461 // Highlight the current line in the quickfix window.
1462 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001463 wlv.line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001464# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001465 if (wlv.line_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001466 area_highlighting = TRUE;
1467#endif
1468
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001469#ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01001470 if (spv->spv_has_spell && !number_only)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001471 {
Luuk van Baal30805a12023-05-27 22:22:10 +01001472 // Prepare for spell checking.
1473 extra_check = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001474
Luuk van Baal30805a12023-05-27 22:22:10 +01001475 // When a word wrapped from the previous line the start of the
1476 // current line is valid.
1477 if (lnum == spv->spv_checked_lnum)
1478 cur_checked_col = spv->spv_checked_col;
Luuk van Baale84c7732023-05-31 18:57:36 +01001479 // Previous line was not spell checked, check for capital. This happens
1480 // for the first line in an updated region or after a closed fold.
1481 if (spv->spv_capcol_lnum == 0 && check_need_cap(wp, lnum, 0))
1482 spv->spv_cap_col = 0;
1483 else if (lnum != spv->spv_capcol_lnum)
Luuk van Baal30805a12023-05-27 22:22:10 +01001484 spv->spv_cap_col = -1;
1485 spv->spv_checked_lnum = 0;
1486
Luuk van Baal30805a12023-05-27 22:22:10 +01001487 // Get the start of the next line, so that words that wrap to the
1488 // next line are found too: "et<line-break>al.".
1489 // Trick: skip a few chars for C/shell/Vim comments
1490 nextline[SPWORDLEN] = NUL;
1491 if (lnum < wp->w_buffer->b_ml.ml_line_count)
Luuk van Baale84c7732023-05-31 18:57:36 +01001492 {
1493 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1494 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1495 }
1496 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1497
1498 // If current line is empty, check first word in next line for capital.
1499 ptr = skipwhite(line);
1500 if (*ptr == NUL)
1501 {
1502 spv->spv_cap_col = 0;
1503 spv->spv_capcol_lnum = lnum + 1;
1504 }
1505 // For checking first word with a capital skip white space.
1506 else if (spv->spv_cap_col == 0)
1507 spv->spv_cap_col = ptr - line;
1508
Luuk van Baal30805a12023-05-27 22:22:10 +01001509 // Copy the end of the current line into nextline[].
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001510 if (nextline[SPWORDLEN] == NUL)
1511 {
1512 // No next line or it is empty.
1513 nextlinecol = MAXCOL;
1514 nextline_idx = 0;
1515 }
1516 else
1517 {
1518 v = (long)STRLEN(line);
1519 if (v < SPWORDLEN)
1520 {
1521 // Short line, use it completely and append the start of the
1522 // next line.
1523 nextlinecol = 0;
1524 mch_memmove(nextline, line, (size_t)v);
1525 STRMOVE(nextline + v, nextline + SPWORDLEN);
1526 nextline_idx = v + 1;
1527 }
1528 else
1529 {
1530 // Long line, use only the last SPWORDLEN bytes.
1531 nextlinecol = v - SPWORDLEN;
1532 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1533 nextline_idx = SPWORDLEN + 1;
1534 }
1535 }
1536 }
1537#endif
1538
Luuk van Baale84c7732023-05-31 18:57:36 +01001539 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1540 ptr = line;
1541
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001542 if (wp->w_p_list)
1543 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001544 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001545 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001546 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001547 || wp->w_lcs_chars.trail
1548 || wp->w_lcs_chars.lead
1549 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001550 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001551
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001552 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001553 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001554 {
1555 trailcol = (colnr_T)STRLEN(ptr);
1556 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1557 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001558 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001559 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001560 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001561 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001562 {
1563 leadcol = 0;
1564 while (VIM_ISWHITE(ptr[leadcol]))
1565 ++leadcol;
1566 if (ptr[leadcol] == NUL)
1567 // in a line full of spaces all of them are treated as trailing
1568 leadcol = (colnr_T)0;
1569 else
1570 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001571 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001572 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001573 }
1574
Bram Moolenaard7657e92022-09-20 18:59:30 +01001575 wlv.wcr_attr = get_wcr_attr(wp);
1576 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001577 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001578 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001579 area_highlighting = TRUE;
1580 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001581
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001582 // When w_skipcol is non-zero and there is virtual text above the actual
1583 // text, then this much of the virtual text is skipped.
1584 int skipcol_in_text_prop_above = 0;
1585
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001586#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001587 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001588 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001589
1590 char_u *prop_start;
1591 text_prop_count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE);
1592 if (text_prop_count > 0)
1593 {
1594 // Make a copy of the properties, so that they are properly
1595 // aligned.
1596 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1597 if (text_props != NULL)
1598 mch_memmove(text_props, prop_start,
1599 text_prop_count * sizeof(textprop_T));
1600
1601 // Allocate an array for the indexes.
1602 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1603 if (text_prop_idxs == NULL)
1604 VIM_CLEAR(text_props);
1605
1606 if (text_props != NULL)
1607 {
1608 area_highlighting = TRUE;
1609 extra_check = TRUE;
1610
1611 // When skipping virtual text the props need to be sorted. The
1612 // order is reversed!
1613 if (lnum == wp->w_topline && wp->w_skipcol > 0)
1614 {
1615 for (int i = 0; i < text_prop_count; ++i)
1616 text_prop_idxs[i] = i;
1617 sort_text_props(wp->w_buffer, text_props,
1618 text_prop_idxs, text_prop_count);
1619 }
1620
1621 // Text props "above" move the line number down to where the text
1622 // is. Only count the ones that are visible, not those that are
1623 // skipped because of w_skipcol.
1624 int text_width = wp->w_width - win_col_off(wp);
1625 for (int i = text_prop_count - 1; i >= 0; --i)
1626 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1627 {
1628 if (lnum == wp->w_topline
1629 && wp->w_skipcol - skipcol_in_text_prop_above
1630 >= text_width)
1631 {
1632 // This virtual text above is skipped, remove it from
1633 // the array.
1634 skipcol_in_text_prop_above += text_width;
1635 for (int j = i + 1; j < text_prop_count; ++j)
1636 text_props[j - 1] = text_props[j];
1637 ++i;
1638 --text_prop_count;
1639 }
1640 else
1641 ++wlv.text_prop_above_count;
1642 }
1643 }
1644 }
Bram Moolenaara572b932023-02-19 14:34:37 +00001645
1646 if (number_only)
1647 {
1648 // skip over rows only used for virtual text above
1649 wlv.row += wlv.text_prop_above_count;
1650 if (wlv.row > endrow)
1651 return wlv.row;
1652 wlv.screen_row += wlv.text_prop_above_count;
1653 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001654#endif
1655
1656 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1657 // first character to be displayed.
1658 if (wp->w_p_wrap)
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001659 v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001660 else
1661 v = wp->w_leftcol;
1662 if (v > 0 && !number_only)
1663 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001664 char_u *prev_ptr = ptr;
1665 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001666 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001667
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001668 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001669 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001670 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001671 charsize = win_lbr_chartabsize(&cts, NULL);
1672 cts.cts_vcol += charsize;
1673 prev_ptr = cts.cts_ptr;
1674 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001675 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001676 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001677 ptr = cts.cts_ptr;
1678 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001679
1680 // When:
1681 // - 'cuc' is set, or
1682 // - 'colorcolumn' is set, or
1683 // - 'virtualedit' is set, or
1684 // - the visual mode is active,
1685 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001686 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001687#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001688 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001689#endif
1690 virtual_active() ||
1691 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001692 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001693
1694 // Handle a character that's not completely on the screen: Put ptr at
1695 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001696 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001697 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001698 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001699 ptr = prev_ptr;
1700 // If the character fits on the screen, don't need to skip it.
1701 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001702 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1703 && wlv.col == 0)
1704 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001705 }
1706
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001707#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001708 // If there the text doesn't reach to the desired column, need to skip
1709 // "skip_cells" cells when virtual text follows.
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001710 if ((!wp->w_p_wrap || (lnum == wp->w_topline && wp->w_skipcol > 0))
1711 && v > wlv.vcol)
Bram Moolenaarcd105412022-10-10 19:50:42 +01001712 skip_cells = v - wlv.vcol;
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001713#endif
Bram Moolenaarcd105412022-10-10 19:50:42 +01001714
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001715 // Adjust for when the inverted text is before the screen,
1716 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001717 if (wlv.tocol <= wlv.vcol)
1718 wlv.fromcol = 0;
1719 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1720 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001721
1722#ifdef FEAT_LINEBREAK
1723 // When w_skipcol is non-zero, first line needs 'showbreak'
1724 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001725 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001726#endif
1727#ifdef FEAT_SPELL
1728 // When spell checking a word we need to figure out the start of the
1729 // word and if it's badly spelled or not.
Luuk van Baal30805a12023-05-27 22:22:10 +01001730 if (spv->spv_has_spell)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001731 {
1732 int len;
1733 colnr_T linecol = (colnr_T)(ptr - line);
1734 hlf_T spell_hlf = HLF_COUNT;
1735
1736 pos = wp->w_cursor;
1737 wp->w_cursor.lnum = lnum;
1738 wp->w_cursor.col = linecol;
1739 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1740
1741 // spell_move_to() may call ml_get() and make "line" invalid
1742 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1743 ptr = line + linecol;
1744
1745 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1746 {
1747 // no bad word found at line start, don't check until end of a
1748 // word
1749 spell_hlf = HLF_COUNT;
1750 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1751 }
1752 else
1753 {
1754 // bad word found, use attributes until end of word
1755 word_end = wp->w_cursor.col + len + 1;
1756
1757 // Turn index into actual attributes.
1758 if (spell_hlf != HLF_COUNT)
1759 spell_attr = highlight_attr[spell_hlf];
1760 }
1761 wp->w_cursor = pos;
1762
1763# ifdef FEAT_SYN_HL
1764 // Need to restart syntax highlighting for this line.
1765 if (has_syntax)
1766 syntax_start(wp, lnum);
1767# endif
1768 }
1769#endif
1770 }
1771
1772 // Correct highlighting for cursor that can't be disabled.
1773 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001774 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001775 {
1776 if (noinvcur)
1777 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001778 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001779 {
1780 // highlighting starts at cursor, let it start just after the
1781 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001782 fromcol_prev = wlv.fromcol;
1783 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001784 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001785 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001786 // restart highlighting after the cursor
1787 fromcol_prev = wp->w_virtcol;
1788 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001789 if (wlv.fromcol >= wlv.tocol)
1790 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001791 }
1792
1793#ifdef FEAT_SEARCH_EXTRA
1794 if (!number_only)
1795 {
1796 v = (long)(ptr - line);
1797 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1798 &line, &screen_search_hl,
1799 &search_attr);
1800 ptr = line + v; // "line" may have been updated
1801 }
1802#endif
1803
1804#ifdef FEAT_SYN_HL
1805 // Cursor line highlighting for 'cursorline' in the current window.
1806 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1807 {
1808 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001809 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001810 if (!(wp == curwin && VIsual_active)
1811 && wp->w_p_culopt_flags != CULOPT_NBR)
1812 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001813 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001814 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1815
zeertzjqb7acea12022-12-12 13:20:43 +00001816 // Only apply CursorLine highlight here when "screenline" is not
1817 // present in 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001818 if (!wlv.cul_screenline)
zeertzjqb7acea12022-12-12 13:20:43 +00001819 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001820 else
1821 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001822 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001823 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1824 }
1825 area_highlighting = TRUE;
1826 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001827 }
1828#endif
1829
Bram Moolenaar1306b362022-08-06 15:59:06 +01001830 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001831
zeertzjqb25dbb32023-08-13 18:11:05 +02001832 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001833 // Repeat for the whole displayed line.
1834 for (;;)
1835 {
1836#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001837 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001838#endif
1839#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001840 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001841#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001842
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001843 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001844 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001845 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001846#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001847 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001848 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001849 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001850 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001851 }
1852#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001853 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001854 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001855 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001856 if (cmdwin_type != 0 && wp == curwin)
1857 {
1858 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001859 wlv.n_extra = 1;
1860 wlv.c_extra = cmdwin_type;
1861 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001862 wlv.char_attr =
1863 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001864 }
1865 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001866#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001867 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001868 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001869 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001870 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001871 }
1872#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001873#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001874 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001875 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001876 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001877 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001878 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001879 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001880 }
1881#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001882 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001883 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001884 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001885 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001886 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001887 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001888#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001889 // Check if 'breakindent' applies and show it.
1890 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1891 if (wlv.n_extra == 0)
1892 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001893#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001894#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001895 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001896 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001897 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001898 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001899 }
1900#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001901 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001902 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001903 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001904 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001905 }
1906 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001907
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001908#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001909 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001910 && wlv.vcol >= left_curline_col
1911 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001912 {
zeertzjqb7acea12022-12-12 13:20:43 +00001913 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001914 }
1915#endif
1916
1917 // When still displaying '$' of change command, stop at cursor.
1918 // When only displaying the (relative) line number and that's done,
1919 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001920 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001921 && lnum == wp->w_cursor.lnum
1922 && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001923 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001924#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001925 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001926#endif
1927 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001928 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001929 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001930 // Pretend we have finished updating the window. Except when
1931 // 'cursorcolumn' is set.
1932#ifdef FEAT_SYN_HL
1933 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001934 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001935 else
1936#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001937 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001938 break;
1939 }
1940
Bram Moolenaar1306b362022-08-06 15:59:06 +01001941 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001942 {
1943 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001944 if (wlv.vcol == wlv.fromcol
1945 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1946 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001947 && (*mb_ptr2cells)(ptr) > 1)
1948 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001949 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001950 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001951 area_attr = vi_attr; // start highlighting
1952 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001953 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001954 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001955 area_attr = 0; // stop highlighting
1956
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001957#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001958 if (text_props != NULL)
1959 {
1960 int pi;
1961 int bcol = (int)(ptr - line);
1962
Bram Moolenaar1306b362022-08-06 15:59:06 +01001963 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001964# ifdef FEAT_LINEBREAK
1965 && !in_linebreak
1966# endif
1967 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001968 --bcol; // still working on the previous char, e.g. Tab
1969
1970 // Check if any active property ends.
1971 for (pi = 0; pi < text_props_active; ++pi)
1972 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001973 int tpi = text_prop_idxs[pi];
1974 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001975
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001976 // An inline property ends when after the start column plus
1977 // length. An "above" property ends when used and n_extra
1978 // is zero.
1979 if ((tp->tp_col != MAXCOL
1980 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001981 {
1982 if (pi + 1 < text_props_active)
1983 mch_memmove(text_prop_idxs + pi,
1984 text_prop_idxs + pi + 1,
1985 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001986 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001987 --text_props_active;
1988 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001989# ifdef FEAT_LINEBREAK
1990 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001991 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001992 syntax_attr = 0;
1993# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001994 }
1995 }
1996
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001997# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001998 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001999 // not on the next char yet, don't start another prop
2000 --bcol;
2001# endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002002 int display_text_first = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002003
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002004 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002005 // With 'nowrap' and not in the first screen line only "below"
2006 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002007 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002008 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002009 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002010 && (wp->w_p_wrap
2011 || wlv.row == startrow
2012 || (text_props[text_prop_next].tp_flags
2013 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002014 || (bcol == 0
2015 && (text_props[text_prop_next].tp_flags
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002016 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002017 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002018 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01002019 if (text_props[text_prop_next].tp_col == MAXCOL
2020 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002021 + text_props[text_prop_next].tp_len)
2022 text_prop_idxs[text_props_active++] = text_prop_next;
2023 ++text_prop_next;
2024 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002025
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002026 if (wlv.n_extra == 0 || !wlv.extra_for_textprop)
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002027 {
2028 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002029 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002030 text_prop_flags = 0;
2031 text_prop_type = NULL;
2032 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002033 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002034 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002035 if (text_props_active > 0 && wlv.n_extra == 0
2036 && !display_text_first)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002037 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01002038 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002039 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002040 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002041
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002042 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002043 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002044
2045 // Sort the properties on priority and/or starting last.
2046 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002047 sort_text_props(wp->w_buffer, text_props,
2048 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002049
2050 for (pi = 0; pi < text_props_active; ++pi)
2051 {
2052 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002053 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002054 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002055 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002056
Bram Moolenaarcd105412022-10-10 19:50:42 +01002057 // Only use a text property that can be displayed.
2058 // Skip "after" properties when wrap is off and at the
2059 // end of the window.
2060 if (pt != NULL
2061 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2062 && tp->tp_id != -MAXCOL
2063 && !(tp->tp_id < 0
2064 && !wp->w_p_wrap
2065 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2066 | TP_FLAG_ALIGN_ABOVE
2067 | TP_FLAG_ALIGN_BELOW)) == 0
2068 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002069 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002070 if (tp->tp_col == MAXCOL
2071 && *ptr == NUL
2072 && ((wp->w_p_list && lcs_eol_one > 0
2073 && (tp->tp_flags
2074 & TP_FLAG_ALIGN_ABOVE) == 0)
2075 || (ptr == line
2076 && !did_line
2077 && (tp->tp_flags
2078 & TP_FLAG_ALIGN_BELOW))))
2079 {
2080 // skip this prop, first display the '$' after
2081 // the line or display an empty line
2082 text_prop_follows = TRUE;
2083 if (used_tpi < 0)
2084 display_text_first = TRUE;
2085 continue;
2086 }
2087
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002088 if (pt->pt_hl_id > 0)
2089 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002090 text_prop_type = pt;
2091 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002092 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002093 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2094 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002095 text_prop_flags = pt->pt_flags;
2096 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002097 used_tpi = tpi;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002098 display_text_first = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002099 }
2100 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002101 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002102 && -text_prop_id
2103 <= wp->w_buffer->b_textprop_text.ga_len)
2104 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002105 textprop_T *tp = &text_props[used_tpi];
2106 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002107 ->b_textprop_text.ga_data)[
2108 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002109 int above = (tp->tp_flags
2110 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002111 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002112
2113 // reset the ID in the copy to avoid it being used
2114 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002115 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002116
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002117 if (p != NULL)
2118 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002119 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002120 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002121 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002122 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002123 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
2124 int padding = tp->tp_col == MAXCOL
2125 && tp->tp_len > 1
2126 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002127
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002128 // Insert virtual text before the current
2129 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002130 wlv.p_extra = p;
2131 wlv.c_extra = NUL;
2132 wlv.c_final = NUL;
2133 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002134 wlv.extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002135 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2136 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002137 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002138 // restore search_attr and area_attr when n_extra
2139 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01002140 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002141 saved_area_attr = area_attr;
2142 search_attr = 0;
2143 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002144 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002145 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002146 if (*ptr == NUL)
2147 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002148 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002149#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002150 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002151 {
2152 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002153 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002154 wlv.need_showbreak = FALSE;
2155 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002156 }
2157#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002158 if ((right || above || below || !wrap
2159 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002160 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002161 char_u *prev_p_extra = wlv.p_extra;
2162 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002163
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002164 // Take care of padding, right-align and
2165 // truncation.
2166 // Shared with win_lbr_chartabsize(), must do
2167 // exactly the same.
2168 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002169 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002170 wlv.col,
2171 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002172 &n_attr, &wlv.n_attr_skip,
2173 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002174 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002175 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002176 // wlv.p_extra was allocated
2177 vim_free(p_extra_free2);
2178 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002179 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002180
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002181 if (above)
2182 wlv.vcol_off_tp = wlv.n_extra;
2183
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002184 if (lcs_eol_one < 0
2185 && wp->w_p_wrap
2186 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002187 + wlv.n_extra - 2 > wp->w_width)
2188 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002189 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002190
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002191 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002192 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002193 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002194 {
2195 draw_screen_line(wp, &wlv);
2196
2197 // When line got too long for screen break
2198 // here.
2199 if (wlv.row == endrow)
2200 {
2201 ++wlv.row;
2202 break;
2203 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002204 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002205 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002206 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002207 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002208 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002209
Bram Moolenaarcd105412022-10-10 19:50:42 +01002210 // If the text didn't reach until the first window
2211 // column we need to skip cells.
2212 if (skip_cells > 0)
2213 {
2214 if (wlv.n_extra > skip_cells)
2215 {
2216 wlv.n_extra -= skip_cells;
2217 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002218 wlv.n_attr_skip -= skip_cells;
2219 if (wlv.n_attr_skip < 0)
2220 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002221 skip_cells = 0;
2222 }
2223 else
2224 {
2225 // the whole text is left of the window, drop
2226 // it and advance to the next one
2227 skip_cells -= wlv.n_extra;
2228 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002229 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002230 bail_out = TRUE;
2231 }
2232 }
2233
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002234 // If another text prop follows the condition below at
2235 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002236 // If this is an "above" text prop and 'nowrap' the we
2237 // must wrap anyway.
2238 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002239 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002240 && (wp->w_p_wrap
2241 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002242 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002243
2244 if (bail_out)
2245 // starting a new line for "below"
2246 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002247 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002248 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002249 else if (text_prop_next < text_prop_count
2250 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002251 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2252 || (!wp->w_p_wrap
2253 && wlv.col == wp->w_width - 1
2254 && (text_props[text_prop_next].tp_flags
2255 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002256 // When at last-but-one character and a text property
2257 // follows after it, we may need to flush the line after
2258 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002259 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002260 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002261 }
2262#endif
2263
Bram Moolenaare38fc862022-08-11 17:24:50 +01002264 if (wlv.n_extra == 0)
2265 {
zeertzjqb25dbb32023-08-13 18:11:05 +02002266#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaare38fc862022-08-11 17:24:50 +01002267 // Check for start/end of 'hlsearch' and other matches.
2268 // After end, check for start/end of next match.
2269 // When another match, have to check for start again.
2270 v = (long)(ptr - line);
2271 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2272 &screen_search_hl, &has_match_conc,
2273 &match_conc, did_line_attr, lcs_eol_one,
2274 &on_last_col);
2275 ptr = line + v; // "line" may have been changed
Bram Moolenaare38fc862022-08-11 17:24:50 +01002276
2277 // Do not allow a conceal over EOL otherwise EOL will be missed
2278 // and bad things happen.
2279 if (*ptr == NUL)
2280 has_match_conc = 0;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002281#endif
2282
zeertzjqb25dbb32023-08-13 18:11:05 +02002283 prev_ptr = ptr;
2284 }
2285
Bram Moolenaare38fc862022-08-11 17:24:50 +01002286#ifdef FEAT_DIFF
2287 if (wlv.diff_hlf != (hlf_T)0)
2288 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002289 // When there is extra text (e.g. virtual text) it gets the
2290 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002291 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2292 && wlv.n_extra == 0)
2293 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002294 if (wlv.diff_hlf == HLF_TXD
2295 && ((ptr - line > change_end && wlv.n_extra == 0)
2296 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002297 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002298 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002299 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2300 && wp->w_p_culopt_flags != CULOPT_NBR
2301 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2302 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002303 wlv.line_attr = hl_combine_attr(
2304 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002305 }
2306#endif
2307
Bram Moolenaara74fda62019-10-19 17:38:03 +02002308#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002309 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002310 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002311 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002312# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002313 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002314 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002315# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002316 // Get syntax attribute.
2317 if (has_syntax)
2318 {
2319 // Get the syntax attribute for the character. If there
2320 // is an error, disable syntax highlighting.
2321 save_did_emsg = did_emsg;
2322 did_emsg = FALSE;
2323
2324 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002325 if (v == prev_syntax_col)
2326 // at same column again
2327 syntax_attr = prev_syntax_attr;
2328 else
2329 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002330# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002331 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002332# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002333 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002334# ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01002335 spv->spv_has_spell ? &can_spell :
Bram Moolenaar34390282019-10-16 14:38:26 +02002336# endif
Luuk van Baal30805a12023-05-27 22:22:10 +01002337 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002338 prev_syntax_col = v;
2339 prev_syntax_attr = syntax_attr;
2340 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002341
Bram Moolenaar34390282019-10-16 14:38:26 +02002342 if (did_emsg)
2343 {
2344 wp->w_s->b_syn_error = TRUE;
2345 has_syntax = FALSE;
2346 syntax_attr = 0;
2347 }
2348 else
2349 did_emsg = save_did_emsg;
2350# ifdef SYN_TIME_LIMIT
2351 if (wp->w_s->b_syn_slow)
2352 has_syntax = FALSE;
2353# endif
2354
2355 // Need to get the line again, a multi-line regexp may
2356 // have made it invalid.
2357 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2358 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002359 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002360# ifdef FEAT_CONCEAL
2361 // no concealing past the end of the line, it interferes
2362 // with line highlighting
2363 if (*ptr == NUL)
2364 syntax_flags = 0;
2365 else
2366 syntax_flags = get_syntax_info(&syntax_seqnr);
2367# endif
2368 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002369 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002370# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002371 // Combine text property highlight into syntax highlight.
2372 if (text_prop_type != NULL)
2373 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002374 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002375 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2376 else
2377 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002378 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002379 }
2380# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002381#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002382
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002383 // Decide which of the highlight attributes to use.
2384 attr_pri = TRUE;
2385#ifdef LINE_ATTR
2386 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002387 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002388 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002389 if (!highlight_match)
2390 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002391 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002392# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002393 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002394# endif
2395 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002396 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002397 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002398 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002399# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002400 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002401# endif
2402 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002403 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002404 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2405 || wlv.vcol < wlv.fromcol
2406 || vcol_prev < fromcol_prev
2407 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002408 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002409 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002410 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002411# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002412 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002413# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002414 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002415# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002416 attr_pri = FALSE;
2417 }
2418#else
2419 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002420 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002421 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002422 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002423#endif
2424 else
2425 {
2426 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002427#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002428 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002429#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002430 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002431#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002432 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002433#ifdef FEAT_PROP_POPUP
2434 // override with text property highlight when "override" is TRUE
2435 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002436 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002437#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002438 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002439
2440 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002441 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002442 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002443 if (wlv.char_attr == 0)
2444 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002445 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002446 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002447 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002448
2449 // Get the next character to put on the screen.
2450
2451 // The "p_extra" points to the extra stuff that is inserted to
2452 // represent special characters (non-printable stuff) and other
2453 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002454 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002455 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2456 // "p_extra[n_extra]".
2457 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002458 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002459 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002460 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002461 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002462 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2463 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002464 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2465 if (enc_utf8 && utf_char2len(c) > 1)
2466 {
2467 mb_utf8 = TRUE;
2468 u8cc[0] = 0;
2469 c = 0xc0;
2470 }
2471 else
2472 mb_utf8 = FALSE;
2473 }
2474 else
2475 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002476 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002477 if (has_mbyte)
2478 {
2479 mb_c = c;
2480 if (enc_utf8)
2481 {
2482 // If the UTF-8 character is more than one byte:
2483 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002484 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002485 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002486 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002487 mb_l = 1;
2488 else if (mb_l > 1)
2489 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002490 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002491 mb_utf8 = TRUE;
2492 c = 0xc0;
2493 }
2494 }
2495 else
2496 {
2497 // if this is a DBCS character, put it in "mb_c"
2498 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002499 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002500 mb_l = 1;
2501 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002502 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002503 }
2504 if (mb_l == 0) // at the NUL at end-of-line
2505 mb_l = 1;
2506
2507 // If a double-width char doesn't fit display a '>' in the
2508 // last column.
2509 if ((
2510# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002511 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002512# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002513 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002514 && (*mb_char2cells)(mb_c) == 2)
2515 {
2516 c = '>';
2517 mb_c = c;
2518 mb_l = 1;
2519 mb_utf8 = FALSE;
2520 multi_attr = HL_ATTR(HLF_AT);
2521#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002522 if (wlv.cul_attr)
2523 multi_attr = hl_combine_attr(
2524 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002525#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002526 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002527
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002528 // put the pointer back to output the double-width
2529 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002530 ++wlv.n_extra;
2531 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002532 }
2533 else
2534 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002535 wlv.n_extra -= mb_l - 1;
2536 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002537 }
2538 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002539 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002540 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002541 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002542#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002543 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002544 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002545 // Only restore search_attr and area_attr after "n_extra" in
2546 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002547 if (wlv.saved_n_extra <= 0)
2548 {
2549 if (search_attr == 0)
2550 search_attr = saved_search_attr;
2551 if (area_attr == 0 && *ptr != NUL)
2552 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002553
2554 if (wlv.extra_for_textprop)
2555 // wlv.extra_attr should be used at this position but
2556 // not any further.
2557 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002558 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002559
2560 wlv.extra_for_textprop = FALSE;
2561 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002562 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002563#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002564 }
2565 else
2566 {
2567#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002568 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002569#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002570 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002571
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002572 // Get a character from the line itself.
2573 c = *ptr;
2574#ifdef FEAT_LINEBREAK
2575 c0 = *ptr;
2576#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002577#ifdef FEAT_PROP_POPUP
2578 if (c == NUL)
2579 // text is finished, may display a "below" virtual text
2580 did_line = TRUE;
2581#endif
2582
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002583 if (has_mbyte)
2584 {
2585 mb_c = c;
2586 if (enc_utf8)
2587 {
2588 // If the UTF-8 character is more than one byte: Decode it
2589 // into "mb_c".
2590 mb_l = utfc_ptr2len(ptr);
2591 mb_utf8 = FALSE;
2592 if (mb_l > 1)
2593 {
2594 mb_c = utfc_ptr2char(ptr, u8cc);
2595 // Overlong encoded ASCII or ASCII with composing char
2596 // is displayed normally, except a NUL.
2597 if (mb_c < 0x80)
2598 {
2599 c = mb_c;
2600#ifdef FEAT_LINEBREAK
2601 c0 = mb_c;
2602#endif
2603 }
2604 mb_utf8 = TRUE;
2605
2606 // At start of the line we can have a composing char.
2607 // Draw it as a space with a composing char.
2608 if (utf_iscomposing(mb_c))
2609 {
2610 int i;
2611
2612 for (i = Screen_mco - 1; i > 0; --i)
2613 u8cc[i] = u8cc[i - 1];
2614 u8cc[0] = mb_c;
2615 mb_c = ' ';
2616 }
2617 }
2618
2619 if ((mb_l == 1 && c >= 0x80)
2620 || (mb_l >= 1 && mb_c == 0)
2621 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2622 {
2623 // Illegal UTF-8 byte: display as <xx>.
2624 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002625 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002626# ifdef FEAT_RIGHTLEFT
2627 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002628 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002629# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002630 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002631 c = *wlv.p_extra;
2632 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002633 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002634 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2635 wlv.c_extra = NUL;
2636 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002637 if (area_attr == 0 && search_attr == 0)
2638 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002639 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002640 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002641 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002642 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002643 }
2644 }
2645 else if (mb_l == 0) // at the NUL at end-of-line
2646 mb_l = 1;
2647#ifdef FEAT_ARABIC
2648 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2649 {
2650 // Do Arabic shaping.
2651 int pc, pc1, nc;
2652 int pcc[MAX_MCO];
2653
2654 // The idea of what is the previous and next
2655 // character depends on 'rightleft'.
2656 if (wp->w_p_rl)
2657 {
2658 pc = prev_c;
2659 pc1 = prev_c1;
2660 nc = utf_ptr2char(ptr + mb_l);
2661 prev_c1 = u8cc[0];
2662 }
2663 else
2664 {
2665 pc = utfc_ptr2char(ptr + mb_l, pcc);
2666 nc = prev_c;
2667 pc1 = pcc[0];
2668 }
2669 prev_c = mb_c;
2670
2671 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2672 }
2673 else
2674 prev_c = mb_c;
2675#endif
2676 }
2677 else // enc_dbcs
2678 {
2679 mb_l = MB_BYTE2LEN(c);
2680 if (mb_l == 0) // at the NUL at end-of-line
2681 mb_l = 1;
2682 else if (mb_l > 1)
2683 {
2684 // We assume a second byte below 32 is illegal.
2685 // Hopefully this is OK for all double-byte encodings!
2686 if (ptr[1] >= 32)
2687 mb_c = (c << 8) + ptr[1];
2688 else
2689 {
2690 if (ptr[1] == NUL)
2691 {
2692 // head byte at end of line
2693 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002694 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002695 }
2696 else
2697 {
2698 // illegal tail byte
2699 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002700 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002701 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002702 wlv.p_extra = wlv.extra;
2703 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002704 wlv.c_extra = NUL;
2705 wlv.c_final = NUL;
2706 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002707 if (area_attr == 0 && search_attr == 0)
2708 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002709 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002710 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002711 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002712 // save current attr
2713 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002714 }
2715 mb_c = c;
2716 }
2717 }
2718 }
2719 // If a double-width char doesn't fit display a '>' in the
2720 // last column; the character is displayed at the start of the
2721 // next line.
2722 if ((
2723# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002724 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002725# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002726 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002727 && (*mb_char2cells)(mb_c) == 2)
2728 {
2729 c = '>';
2730 mb_c = c;
2731 mb_utf8 = FALSE;
2732 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002733 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002734 // Put pointer back so that the character will be
2735 // displayed at the start of the next line.
2736 --ptr;
2737#ifdef FEAT_CONCEAL
2738 did_decrement_ptr = TRUE;
2739#endif
2740 }
2741 else if (*ptr != NUL)
2742 ptr += mb_l - 1;
2743
2744 // If a double-width char doesn't fit at the left side display
2745 // a '<' in the first column. Don't do this for unprintable
2746 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002747 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002748 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002749 wlv.n_extra = 1;
2750 wlv.c_extra = MB_FILLER_CHAR;
2751 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002752 c = ' ';
2753 if (area_attr == 0 && search_attr == 0)
2754 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002755 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002756 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002757 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002758 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002759 }
2760 mb_c = c;
2761 mb_utf8 = FALSE;
2762 mb_l = 1;
2763 }
2764
2765 }
2766 ++ptr;
2767
2768 if (extra_check)
2769 {
2770#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002771 // Check spelling (unless at the end of the line).
2772 // Only do this when there is no syntax highlighting, the
2773 // @Spell cluster is not used or the current syntax item
2774 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002775 v = (long)(ptr - line);
Luuk van Baal30805a12023-05-27 22:22:10 +01002776 if (spv->spv_has_spell && v >= word_end && v > cur_checked_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002777 {
2778 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002779 // do not calculate cap_col at the end of the line or when
2780 // only white space is following
2781 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002782# ifdef FEAT_SYN_HL
2783 !has_syntax ||
2784# endif
2785 can_spell))
2786 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002787 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002788 int len;
2789 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002790
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002791 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002792 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002793
2794 // Use nextline[] if possible, it has the start of the
2795 // next line concatenated.
2796 if ((prev_ptr - line) - nextlinecol >= 0)
2797 p = nextline + (prev_ptr - line) - nextlinecol;
2798 else
2799 p = prev_ptr;
Luuk van Baal30805a12023-05-27 22:22:10 +01002800 spv->spv_cap_col -= (int)(prev_ptr - line);
2801 len = spell_check(wp, p, &spell_hlf, &spv->spv_cap_col,
2802 spv->spv_unchanged);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002803 word_end = v + len;
2804
2805 // In Insert mode only highlight a word that
2806 // doesn't touch the cursor.
2807 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002808 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002809 && wp->w_cursor.lnum == lnum
2810 && wp->w_cursor.col >=
2811 (colnr_T)(prev_ptr - line)
2812 && wp->w_cursor.col < (colnr_T)word_end)
2813 {
2814 spell_hlf = HLF_COUNT;
2815 spell_redraw_lnum = lnum;
2816 }
2817
2818 if (spell_hlf == HLF_COUNT && p != prev_ptr
2819 && (p - nextline) + len > nextline_idx)
2820 {
2821 // Remember that the good word continues at the
2822 // start of the next line.
Luuk van Baal30805a12023-05-27 22:22:10 +01002823 spv->spv_checked_lnum = lnum + 1;
2824 spv->spv_checked_col = (p - nextline) + len
2825 - nextline_idx;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002826 }
2827
2828 // Turn index into actual attributes.
2829 if (spell_hlf != HLF_COUNT)
2830 spell_attr = highlight_attr[spell_hlf];
2831
Luuk van Baal30805a12023-05-27 22:22:10 +01002832 if (spv->spv_cap_col > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002833 {
2834 if (p != prev_ptr
Luuk van Baal30805a12023-05-27 22:22:10 +01002835 && (p - nextline) + spv->spv_cap_col
2836 >= nextline_idx)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002837 {
2838 // Remember that the word in the next line
2839 // must start with a capital.
Luuk van Baal30805a12023-05-27 22:22:10 +01002840 spv->spv_capcol_lnum = lnum + 1;
2841 spv->spv_cap_col = ((p - nextline)
2842 + spv->spv_cap_col - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002843 }
2844 else
2845 // Compute the actual column.
Luuk van Baal30805a12023-05-27 22:22:10 +01002846 spv->spv_cap_col += (prev_ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002847 }
2848 }
2849 }
2850 if (spell_attr != 0)
2851 {
2852 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002853 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2854 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002855 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002856 wlv.char_attr = hl_combine_attr(spell_attr,
2857 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002858 }
2859#endif
2860#ifdef FEAT_LINEBREAK
2861 // Found last space before word: check for line break.
2862 if (wp->w_p_lbr && c0 == c
2863 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2864 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002865 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2866 : 0;
2867 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002868 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002869
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002870 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002871# ifdef FEAT_PROP_POPUP
2872 // do not want virtual text counted here
2873 cts.cts_has_prop_with_text = FALSE;
2874# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002875 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002876 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002877
2878 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002879 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002880 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002881 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002882 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2883 if (wlv.n_extra < 0)
2884 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002885 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002886 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002887 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002888 // line break, but for TABs the highlighting should
2889 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002890 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002891
Bram Moolenaar1306b362022-08-06 15:59:06 +01002892 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002893# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002894 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002895 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002896 wp->w_buffer->b_p_vts_array) - 1;
2897# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002898 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002899 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002900# endif
2901
Bram Moolenaar1306b362022-08-06 15:59:06 +01002902 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2903 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002904# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002905 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002906 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002907# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002908 if (VIM_ISWHITE(c))
2909 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002910# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002911 if (c == TAB)
2912 // See "Tab alignment" below.
2913 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002914# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002915 if (!wp->w_p_list)
2916 c = ' ';
2917 }
2918 }
2919#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002920 in_multispace = c == ' '
2921 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2922 if (!in_multispace)
2923 multispace_pos = 0;
2924
Bram Moolenaareed9d462021-02-15 20:38:25 +01002925 // 'list': Change char 160 to 'nbsp' and space to 'space'
2926 // setting in 'listchars'. But not when the character is
2927 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002928 if (wp->w_p_list
2929 && ((((c == 160 && mb_l == 1)
2930 || (mb_utf8
2931 && ((mb_c == 160 && mb_l == 2)
2932 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002933 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002934 || (c == ' '
2935 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002936 && (wp->w_lcs_chars.space
2937 || (in_multispace
2938 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002939 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002940 && ptr - line <= trailcol)))
2941 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002942 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2943 {
2944 c = wp->w_lcs_chars.multispace[multispace_pos++];
2945 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2946 multispace_pos = 0;
2947 }
2948 else
2949 c = (c == ' ') ? wp->w_lcs_chars.space
2950 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002951 if (area_attr == 0 && search_attr == 0)
2952 {
2953 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002954 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002955 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002956 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002957 }
2958 mb_c = c;
2959 if (enc_utf8 && utf_char2len(c) > 1)
2960 {
2961 mb_utf8 = TRUE;
2962 u8cc[0] = 0;
2963 c = 0xc0;
2964 }
2965 else
2966 mb_utf8 = FALSE;
2967 }
2968
zeertzjq2e7cba32022-06-10 15:30:32 +01002969 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2970 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002971 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002972 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2973 && wp->w_lcs_chars.leadmultispace != NULL)
2974 {
2975 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002976 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2977 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002978 multispace_pos = 0;
2979 }
2980
2981 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2982 c = wp->w_lcs_chars.trail;
2983
2984 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2985 c = wp->w_lcs_chars.lead;
2986
zeertzjq2e7cba32022-06-10 15:30:32 +01002987 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002988 c = wp->w_lcs_chars.space;
2989
2990
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002991 if (!attr_pri)
2992 {
2993 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002994 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002995 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002996 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002997 }
2998 mb_c = c;
2999 if (enc_utf8 && utf_char2len(c) > 1)
3000 {
3001 mb_utf8 = TRUE;
3002 u8cc[0] = 0;
3003 c = 0xc0;
3004 }
3005 else
3006 mb_utf8 = FALSE;
3007 }
3008 }
3009
3010 // Handling of non-printable characters.
3011 if (!vim_isprintc(c))
3012 {
3013 // when getting a character from the file, we may have to
3014 // turn it into something else on the way to putting it
3015 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01003016 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003017 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003018 int tab_len = 0;
3019 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003020#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003021 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01003022
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003023 // only adjust the tab_len, when at the first column
3024 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01003025 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003026 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003027#endif
3028 // tab amount depends on current column
3029#ifdef FEAT_VARTABS
3030 tab_len = tabstop_padding(vcol_adjusted,
3031 wp->w_buffer->b_p_ts,
3032 wp->w_buffer->b_p_vts_array) - 1;
3033#else
3034 tab_len = (int)wp->w_buffer->b_p_ts
3035 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
3036#endif
3037
3038#ifdef FEAT_LINEBREAK
3039 if (!wp->w_p_lbr || !wp->w_p_list)
3040#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003041 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003042 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01003043 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003044 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003045#ifdef FEAT_LINEBREAK
3046 else
3047 {
3048 char_u *p;
3049 int len;
3050 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003051 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003052
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003053# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003054 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003055 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003056 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003057
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003058 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003059 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003060 && old_boguscols > 0
3061 && wlv.n_extra > tab_len)
3062 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003063# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003064 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003065 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003066 // If wlv.n_extra > 0, it gives the number of chars
3067 // to use for a tab, else we need to calculate the
3068 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003069 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3070 len = tab_len * tab2_len;
3071 if (wp->w_lcs_chars.tab3)
3072 len += mb_char2len(wp->w_lcs_chars.tab3)
3073 - tab2_len;
3074 if (wlv.n_extra > 0)
3075 len += wlv.n_extra - tab_len;
3076 c = wp->w_lcs_chars.tab1;
3077 p = alloc(len + 1);
3078 if (p == NULL)
3079 wlv.n_extra = 0;
3080 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003081 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003082 vim_memset(p, ' ', len);
3083 p[len] = NUL;
3084 vim_free(wlv.p_extra_free);
3085 wlv.p_extra_free = p;
3086 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003087 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003088 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003089
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003090 if (*p == NUL)
3091 {
3092 tab_len = i;
3093 break;
3094 }
3095
3096 // if tab3 is given, use it for the last
3097 // char
3098 if (wp->w_lcs_chars.tab3
3099 && i == tab_len - 1)
3100 lcs = wp->w_lcs_chars.tab3;
3101 p += mb_char2bytes(lcs, p);
3102 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003103 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003104 }
3105 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003106# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003107 // n_extra will be increased by
3108 // FIX_FOX_BOGUSCOLS macro below, so need to
3109 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003110 if (wlv.vcol_off_co > 0)
3111 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003112# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003113 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003114 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003115 }
3116#endif
3117#ifdef FEAT_CONCEAL
3118 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003119 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003120
3121 // Tab alignment should be identical regardless of
3122 // 'conceallevel' value. So tab compensates of all
3123 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003124 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003125 // line. Note that the tab can be longer than
3126 // 'tabstop' when there are concealed characters.
3127 FIX_FOR_BOGUSCOLS;
3128
3129 // Make sure, the highlighting for the tab char will be
3130 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003131 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003132 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003133 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003134 tab_len += vc_saved;
3135 }
3136#endif
3137 mb_utf8 = FALSE; // don't draw as UTF-8
3138 if (wp->w_p_list)
3139 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003140 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003141 ? wp->w_lcs_chars.tab3
3142 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003143#ifdef FEAT_LINEBREAK
h-east194555c2023-03-02 18:49:09 +00003144 if (wp->w_p_lbr && wlv.p_extra != NULL
3145 && *wlv.p_extra != NUL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003146 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003147 else
3148#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003149 wlv.c_extra = wp->w_lcs_chars.tab2;
3150 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003151 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003152 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003153 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003154 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003155 mb_c = c;
3156 if (enc_utf8 && utf_char2len(c) > 1)
3157 {
3158 mb_utf8 = TRUE;
3159 u8cc[0] = 0;
3160 c = 0xc0;
3161 }
3162 }
3163 else
3164 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003165 wlv.c_final = NUL;
3166 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003167 c = ' ';
3168 }
3169 }
3170 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003171 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003172 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003173 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3174 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003175 && VIsual_mode != Ctrl_V
3176 && (
3177# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003178 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003179# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003180 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003181 && !(noinvcur
3182 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003183 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003184 && lcs_eol_one > 0)
3185 {
3186 // Display a '$' after the line or highlight an extra
3187 // character if the line break is included.
3188#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3189 // For a diff line the highlighting continues after the
3190 // "$".
3191 if (
3192# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003193 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003194# ifdef LINE_ATTR
3195 &&
3196# endif
3197# endif
3198# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003199 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003200# endif
3201 )
3202#endif
3203 {
3204 // In virtualedit, visual selections may extend
3205 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003206 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003207 && wlv.tocol != MAXCOL
3208 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003209 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003210 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003211 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003212 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3213 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003214 else
3215 c = ' ';
3216 lcs_eol_one = -1;
3217 --ptr; // put it back at the NUL
3218 if (!attr_pri)
3219 {
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_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003222 n_attr = 1;
3223 }
3224 mb_c = c;
3225 if (enc_utf8 && utf_char2len(c) > 1)
3226 {
3227 mb_utf8 = TRUE;
3228 u8cc[0] = 0;
3229 c = 0xc0;
3230 }
3231 else
3232 mb_utf8 = FALSE; // don't draw as UTF-8
3233 }
3234 else if (c != NUL)
3235 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003236 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3237 if (wlv.n_extra == 0)
3238 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003239#ifdef FEAT_RIGHTLEFT
3240 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003241 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003242#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003243 wlv.c_extra = NUL;
3244 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003245#ifdef FEAT_LINEBREAK
3246 if (wp->w_p_lbr)
3247 {
3248 char_u *p;
3249
Bram Moolenaar1306b362022-08-06 15:59:06 +01003250 c = *wlv.p_extra;
3251 p = alloc(wlv.n_extra + 1);
3252 vim_memset(p, ' ', wlv.n_extra);
3253 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3254 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003255 vim_free(wlv.p_extra_free);
3256 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003257 }
3258 else
3259#endif
3260 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003261 wlv.n_extra = byte2cells(c) - 1;
3262 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003263 }
3264 if (!attr_pri)
3265 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003266 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003267 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003268 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003269 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003270 }
3271 mb_utf8 = FALSE; // don't draw as UTF-8
3272 }
3273 else if (VIsual_active
3274 && (VIsual_mode == Ctrl_V
3275 || VIsual_mode == 'v')
3276 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003277 && wlv.tocol != MAXCOL
3278 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003279 && (
3280#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003281 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003282#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003283 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003284 {
3285 c = ' ';
3286 --ptr; // put it back at the NUL
3287 }
3288#if defined(LINE_ATTR)
3289 else if ((
3290# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003291 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003292# endif
3293# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003294 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003295# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003296 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003297 ) && (
3298# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003299 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003300# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003301 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003302# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003303 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003304# endif
3305 < wp->w_width)))
3306 {
3307 // Highlight until the right side of the window
3308 c = ' ';
3309 --ptr; // put it back at the NUL
3310
3311 // Remember we do the char for line highlighting.
3312 ++did_line_attr;
3313
3314 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003315 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003316 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003317 || (wp->w_p_list &&
3318 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003319 wlv.char_attr = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003320# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003321 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003322 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003323 wlv.diff_hlf = HLF_CHD;
3324 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003325 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003326 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003327 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3328 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003329 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003330 || (wlv.vcol >= left_curline_col
3331 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003332 wlv.char_attr = hl_combine_attr(
3333 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003334 }
3335 }
3336# endif
3337# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003338 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003339 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003340 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003341 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3342 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003343 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003344 if (!wlv.cul_screenline
3345 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003346 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003347 wlv.char_attr = hl_combine_attr(
3348 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003349 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003350 else if (wlv.line_attr)
3351 wlv.char_attr = hl_combine_attr(
3352 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003353 }
3354# endif
3355 }
3356#endif
3357 }
3358
3359#ifdef FEAT_CONCEAL
3360 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003361 && (wp != curwin || lnum != wp->w_cursor.lnum
3362 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003363 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3364 && !(lnum_in_visual_area
3365 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3366 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003367 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003368 if (((prev_syntax_id != syntax_seqnr
3369 && (syntax_flags & HL_CONCEAL) != 0)
3370 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003371 && (syn_get_sub_char() != NUL
3372 || (has_match_conc && match_conc)
3373 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003374 && wp->w_p_cole != 3)
3375 {
3376 // First time at this concealed item: display one
3377 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003378 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003379 c = match_conc;
3380 else if (syn_get_sub_char() != NUL)
3381 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003382 else if (wp->w_lcs_chars.conceal != NUL)
3383 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003384 else
3385 c = ' ';
3386
3387 prev_syntax_id = syntax_seqnr;
3388
Bram Moolenaar1306b362022-08-06 15:59:06 +01003389 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003390 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003391 wlv.vcol += wlv.n_extra;
3392 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003393 {
3394# ifdef FEAT_RIGHTLEFT
3395 if (wp->w_p_rl)
3396 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003397 wlv.col -= wlv.n_extra;
3398 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003399 }
3400 else
3401# endif
3402 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003403 wlv.boguscols += wlv.n_extra;
3404 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003405 }
3406 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003407 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003408 n_attr = 0;
3409 }
3410 else if (n_skip == 0)
3411 {
3412 is_concealing = TRUE;
3413 n_skip = 1;
3414 }
3415 mb_c = c;
3416 if (enc_utf8 && utf_char2len(c) > 1)
3417 {
3418 mb_utf8 = TRUE;
3419 u8cc[0] = 0;
3420 c = 0xc0;
3421 }
3422 else
3423 mb_utf8 = FALSE; // don't draw as UTF-8
3424 }
3425 else
3426 {
3427 prev_syntax_id = 0;
3428 is_concealing = FALSE;
3429 }
3430
3431 if (n_skip > 0 && did_decrement_ptr)
3432 // not showing the '>', put pointer back to avoid getting stuck
3433 ++ptr;
3434
3435#endif // FEAT_CONCEAL
3436 }
3437
3438#ifdef FEAT_CONCEAL
3439 // In the cursor line and we may be concealing characters: correct
3440 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003441 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003442 && wp == curwin && lnum == wp->w_cursor.lnum
3443 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003444 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003445 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003446# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003447 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003448 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003449 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003450# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003451 wp->w_wcol = wlv.col - wlv.boguscols;
3452 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003453 did_wcol = TRUE;
3454 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003455# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003456 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003457# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003458 }
3459#endif
3460
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003461 // Use "wlv.extra_attr", but don't override visual selection
3462 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003463 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3464 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003465 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003466 && (!attr_pri
3467#ifdef FEAT_PROP_POPUP
3468 || (text_prop_flags & PT_FLAG_OVERRIDE)
3469#endif
3470 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003471 {
3472#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003473 if (wlv.line_attr)
3474 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003475 else
3476#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003477 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003478#ifdef FEAT_PROP_POPUP
3479 if (reset_extra_attr)
3480 {
3481 reset_extra_attr = FALSE;
3482 wlv.extra_attr = 0;
3483 }
3484#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003485 }
3486
3487#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3488 // XIM don't send preedit_start and preedit_end, but they send
3489 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3490 // im_is_preediting() here.
3491 if (p_imst == IM_ON_THE_SPOT
3492 && xic != NULL
3493 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003494 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003495 && !p_imdisable
3496 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003497 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003498 {
3499 colnr_T tcol;
3500
3501 if (preedit_end_col == MAXCOL)
3502 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3503 else
3504 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003505 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003506 {
3507 if (feedback_old_attr < 0)
3508 {
3509 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003510 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003511 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003512 wlv.char_attr = im_get_feedback_attr(feedback_col);
3513 if (wlv.char_attr < 0)
3514 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003515 feedback_col++;
3516 }
3517 else if (feedback_old_attr >= 0)
3518 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003519 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003520 feedback_old_attr = -1;
3521 feedback_col = 0;
3522 }
3523 }
3524#endif
3525 // Handle the case where we are in column 0 but not on the first
3526 // character of the line and the user wants us to show us a
3527 // special character (via 'listchars' option "precedes:<char>".
3528 if (lcs_prec_todo != NUL
3529 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003530 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3531 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003532#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003533 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003534#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003535 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003536 && c != NUL)
3537 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003538 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003539 lcs_prec_todo = NUL;
3540 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3541 {
3542 // Double-width character being overwritten by the "precedes"
3543 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003544 wlv.c_extra = MB_FILLER_CHAR;
3545 wlv.c_final = NUL;
3546 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003547 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003548 wlv.extra_attr =
3549 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003550 }
3551 mb_c = c;
3552 if (enc_utf8 && utf_char2len(c) > 1)
3553 {
3554 mb_utf8 = TRUE;
3555 u8cc[0] = 0;
3556 c = 0xc0;
3557 }
3558 else
3559 mb_utf8 = FALSE; // don't draw as UTF-8
3560 if (!attr_pri)
3561 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003562 saved_attr3 = wlv.char_attr; // save current attr
3563 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003564 n_attr3 = 1;
3565 }
3566 }
3567
3568 // At end of the text line or just after the last character.
3569 if ((c == NUL
3570#if defined(LINE_ATTR)
3571 || did_line_attr == 1
3572#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003573 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003574 {
3575#ifdef FEAT_SEARCH_EXTRA
3576 // flag to indicate whether prevcol equals startcol of search_hl or
3577 // one of the matches
3578 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3579 (long)(ptr - line) - (c == NUL));
3580#endif
3581 // Invert at least one char, used for Visual and empty line or
3582 // highlight match at end of line. If it's beyond the last
3583 // char on the screen, just overwrite that one (tricky!) Not
3584 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003585 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003586 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003587 && (VIsual_mode != Ctrl_V
3588 || lnum == VIsual.lnum
3589 || lnum == curwin->w_cursor.lnum)
3590 && c == NUL)
3591#ifdef FEAT_SEARCH_EXTRA
3592 // highlight 'hlsearch' match at end of line
3593 || (prevcol_hl_flag
3594# ifdef FEAT_SYN_HL
3595 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3596 && !(wp == curwin && VIsual_active))
3597# endif
3598# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003599 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003600# endif
3601# if defined(LINE_ATTR)
3602 && did_line_attr <= 1
3603# endif
3604 )
3605#endif
3606 ))
3607 {
3608 int n = 0;
3609
3610#ifdef FEAT_RIGHTLEFT
3611 if (wp->w_p_rl)
3612 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003613 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003614 n = 1;
3615 }
3616 else
3617#endif
3618 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003619 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003620 n = -1;
3621 }
3622 if (n != 0)
3623 {
3624 // At the window boundary, highlight the last character
3625 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003626 wlv.off += n;
3627 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003628 }
3629 else
3630 {
3631 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003632 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003633 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003634 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003635 }
3636#ifdef FEAT_SEARCH_EXTRA
3637 if (area_attr == 0)
3638 {
3639 // Use attributes from match with highest priority among
3640 // 'search_hl' and the match list.
3641 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003642 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003643 }
3644#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003645 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003646 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003647#ifdef FEAT_RIGHTLEFT
3648 if (wp->w_p_rl)
3649 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003650 --wlv.col;
3651 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003652 }
3653 else
3654#endif
3655 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003656 ++wlv.col;
3657 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003658 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003659 ++wlv.vcol;
3660 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003661 }
3662 }
3663
3664 // At end of the text line.
3665 if (c == NUL)
3666 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003667#ifdef FEAT_PROP_POPUP
3668 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003669 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003670 // Put the pointer back to the NUL.
3671 --ptr;
3672 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003673 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003674 else
3675#endif
3676 {
3677 draw_screen_line(wp, &wlv);
3678
3679 // Update w_cline_height and w_cline_folded if the cursor line
3680 // was updated (saves a call to plines() later).
3681 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3682 {
3683 curwin->w_cline_row = startrow;
3684 curwin->w_cline_height = wlv.row - startrow;
3685#ifdef FEAT_FOLDING
3686 curwin->w_cline_folded = FALSE;
3687#endif
3688 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3689 }
3690 break;
3691 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003692 }
3693
3694 // Show "extends" character from 'listchars' if beyond the line end and
3695 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003696 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003697 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003698 && wp->w_p_list
3699 && !wp->w_p_wrap
3700#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003701 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003702#endif
3703 && (
3704#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003705 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003706#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003707 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003708 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003709 || lcs_eol_one > 0
3710 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003711 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003712 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003713 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003714 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003715 mb_c = c;
3716 if (enc_utf8 && utf_char2len(c) > 1)
3717 {
3718 mb_utf8 = TRUE;
3719 u8cc[0] = 0;
3720 c = 0xc0;
3721 }
3722 else
3723 mb_utf8 = FALSE;
3724 }
3725
3726#ifdef FEAT_SYN_HL
3727 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003728 if (wlv.draw_color_col)
3729 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003730
3731 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3732 // highlight the cursor position itself.
3733 // Also highlight the 'colorcolumn' if it is different than
3734 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003735 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3736 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003737 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003738 if (((wlv.draw_state == WL_LINE
3739 || wlv.draw_state == WL_BRI
3740 || wlv.draw_state == WL_SBR)
3741 && !lnum_in_visual_area
3742 && search_attr == 0
3743 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003744# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003745 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003746# endif
3747 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003748 {
3749 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3750 && lnum != wp->w_cursor.lnum)
3751 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003752 vcol_save_attr = wlv.char_attr;
3753 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3754 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003755 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003756 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003757 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003758 vcol_save_attr = wlv.char_attr;
3759 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003760 }
3761 }
3762#endif
3763
3764 // Store character to be displayed.
3765 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003766 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003767 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003768 {
3769 // Store the character.
3770#if defined(FEAT_RIGHTLEFT)
3771 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3772 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003773 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003774 --wlv.off;
3775 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003776 }
3777#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003778 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003779 if (enc_dbcs == DBCS_JPNU)
3780 {
3781 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003782 ScreenLines[wlv.off] = 0x8e;
3783 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003784 }
3785 else if (enc_utf8)
3786 {
3787 if (mb_utf8)
3788 {
3789 int i;
3790
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003791 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003792 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003793 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003794 for (i = 0; i < Screen_mco; ++i)
3795 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003796 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003797 if (u8cc[i] == 0)
3798 break;
3799 }
3800 }
3801 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003802 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003803 }
3804 if (multi_attr)
3805 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003806 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003807 multi_attr = 0;
3808 }
3809 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003810 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003811
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003812 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003813
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003814 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3815 {
3816 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003817 ++wlv.off;
3818 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003819 if (enc_utf8)
3820 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003821 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003822 else
3823 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003824 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003825 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003826#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003827 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003828#endif
3829 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003830 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003831 // When "wlv.tocol" is halfway a character, set it to the end
3832 // of the character, otherwise highlighting won't stop.
3833 if (wlv.tocol == wlv.vcol)
3834 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003835
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003836 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003837
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003838#ifdef FEAT_RIGHTLEFT
3839 if (wp->w_p_rl)
3840 {
3841 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003842 --wlv.off;
3843 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003844 }
3845#endif
3846 }
3847#ifdef FEAT_RIGHTLEFT
3848 if (wp->w_p_rl)
3849 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003850 --wlv.off;
3851 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003852 }
3853 else
3854#endif
3855 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003856 ++wlv.off;
3857 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003858 }
3859 }
3860#ifdef FEAT_CONCEAL
3861 else if (wp->w_p_cole > 0 && is_concealing)
3862 {
3863 --n_skip;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003864 ++wlv.vcol_off_co;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003865 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003866 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003867 if (wp->w_p_wrap)
3868 {
3869 // Special voodoo required if 'wrap' is on.
3870 //
3871 // Advance the column indicator to force the line
3872 // drawing to wrap early. This will make the line
3873 // take up the same screen space when parts are concealed,
3874 // so that cursor line computations aren't messed up.
3875 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003876 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003877 // trailing junk to be written out of the screen line
3878 // we are building, 'boguscols' keeps track of the number
3879 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003880 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003881 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003882 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003883# ifdef FEAT_RIGHTLEFT
3884 if (wp->w_p_rl)
3885 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003886 wlv.col -= wlv.n_extra;
3887 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003888 }
3889 else
3890# endif
3891 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003892 wlv.col += wlv.n_extra;
3893 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003894 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003895 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003896 n_attr = 0;
3897 }
3898
3899
3900 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3901 {
3902 // Need to fill two screen columns.
3903# ifdef FEAT_RIGHTLEFT
3904 if (wp->w_p_rl)
3905 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003906 --wlv.boguscols;
3907 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003908 }
3909 else
3910# endif
3911 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003912 ++wlv.boguscols;
3913 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003914 }
3915 }
3916
3917# ifdef FEAT_RIGHTLEFT
3918 if (wp->w_p_rl)
3919 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003920 --wlv.boguscols;
3921 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003922 }
3923 else
3924# endif
3925 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003926 ++wlv.boguscols;
3927 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003928 }
3929 }
3930 else
3931 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003932 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003933 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003934 wlv.vcol += wlv.n_extra;
3935 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003936 n_attr = 0;
3937 }
3938 }
3939
3940 }
3941#endif // FEAT_CONCEAL
3942 else
3943 --n_skip;
3944
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003945 // Only advance the "wlv.vcol" when after the 'number' or
3946 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003947 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003948#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003949 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003950#endif
3951 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003952 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003953
3954#ifdef FEAT_SYN_HL
3955 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003956 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003957#endif
3958
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003959 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003960 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3961 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003962
3963 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003964 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003965 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003966 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003967 if (wlv.n_attr_skip > 0)
3968 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003969
3970 // At end of screen line and there is more to come: Display the line
3971 // so far. If there is no more to display it is caught above.
3972 if ((
3973#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003974 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003975#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003976 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003977 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003978 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003979#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003980 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003981#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003982#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003983 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003984#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003985 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003986 && wlv.p_extra != at_end_str)
3987 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3988 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003989 )
3990 {
3991#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003992 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003993 wlv_screen_line(wp, &wlv, FALSE);
3994 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003995 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003996 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003997#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003998 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003999#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004000 ++wlv.row;
4001 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004002
4003 // When not wrapping and finished diff lines, or when displayed
4004 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01004005 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004006#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004007 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004008#endif
4009#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01004010 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004011#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01004012 ) || lcs_eol_one == -1)
4013#ifdef FEAT_PROP_POPUP
4014 && !text_prop_follows
4015#endif
4016 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004017 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004018#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004019 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004020 {
4021 // do not output more of the line, only the "below" prop
4022 ptr += STRLEN(ptr);
4023# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004024 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004025# endif
4026 }
4027#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004028
4029 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004030 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004031#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004032 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004033#endif
4034 )
4035 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004036 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
4037 draw_vsep_win(wp, wlv.row);
4038 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004039 }
4040
4041 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004042 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004043 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004044 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004045 break;
4046 }
4047
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004048 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004049#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004050 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004051#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004052#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004053 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004054#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004055 && wp->w_width == Columns)
4056 {
4057 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004058 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004059
4060 // Special trick to make copy/paste of wrapped lines work with
4061 // xterm/screen: write an extra character beyond the end of
4062 // the line. This will work with all terminal types
4063 // (regardless of the xn,am settings).
4064 // Only do this on a fast tty.
4065 // Only do this if the cursor is on the current line
4066 // (something has been written in it).
4067 // Don't do this for the GUI.
4068 // Don't do this for double-width characters.
4069 // Don't do this for a window not at the right screen border.
4070 if (p_tf
4071#ifdef FEAT_GUI
4072 && !gui.in_use
4073#endif
4074 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004075 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4076 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004077 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004078 || (*mb_off2cells)(
4079 LineOffset[wlv.screen_row - 1]
4080 + (int)Columns - 2,
4081 LineOffset[wlv.screen_row]
4082 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004083 {
4084 // First make sure we are at the end of the screen line,
4085 // then output the same character again to let the
4086 // terminal know about the wrap. If the terminal doesn't
4087 // auto-wrap, we overwrite the character.
4088 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004089 screen_char(LineOffset[wlv.screen_row - 1]
4090 + (unsigned)Columns - 1,
4091 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004092
4093 // When there is a multi-byte character, just output a
4094 // space to keep it simple.
4095 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004096 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004097 out_char(' ');
4098 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004099 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004100 + (Columns - 1)]);
4101 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004102 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004103 screen_start(); // don't know where cursor is now
4104 }
4105 }
4106
Bram Moolenaar1306b362022-08-06 15:59:06 +01004107 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004108
Bram Moolenaareed9d462021-02-15 20:38:25 +01004109 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004110#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004111 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004112# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004113 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004114# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004115 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004116 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004117#endif
4118#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004119 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004120 // When the filler lines are actually below the last line of the
4121 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004122 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004123 break;
4124#endif
4125 }
4126
4127 } // for every character in the line
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004128#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004129 vim_free(text_props);
4130 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004131 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004132#endif
4133
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004134 vim_free(wlv.p_extra_free);
zeertzjq58e1e012023-06-04 18:46:28 +01004135 vim_free(wlv.saved_p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004136 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004137}