blob: 18ae4bf768a61df16635a6a3b71dccdd201931de [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
1832 // Repeat for the whole displayed line.
1833 for (;;)
1834 {
1835#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001836 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001837#endif
1838#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001839 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001840#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001841
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001842 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001843 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001844 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001845#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001846 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001847 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001848 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001849 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001850 }
1851#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001852 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001853 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001854 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001855 if (cmdwin_type != 0 && wp == curwin)
1856 {
1857 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001858 wlv.n_extra = 1;
1859 wlv.c_extra = cmdwin_type;
1860 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001861 wlv.char_attr =
1862 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001863 }
1864 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001865#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001866 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001867 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001868 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001869 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001870 }
1871#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001872#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001873 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001874 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001875 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001876 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001877 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001878 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001879 }
1880#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001881 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001882 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001883 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001884 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001885 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001886 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001887#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001888 // Check if 'breakindent' applies and show it.
1889 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1890 if (wlv.n_extra == 0)
1891 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001892#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001893#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001894 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001895 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001896 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001897 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001898 }
1899#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001900 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001901 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001902 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001903 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001904 }
1905 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001906
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001907#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001908 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001909 && wlv.vcol >= left_curline_col
1910 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001911 {
zeertzjqb7acea12022-12-12 13:20:43 +00001912 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001913 }
1914#endif
1915
1916 // When still displaying '$' of change command, stop at cursor.
1917 // When only displaying the (relative) line number and that's done,
1918 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001919 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001920 && lnum == wp->w_cursor.lnum
1921 && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001922 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001923#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001924 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001925#endif
1926 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001927 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001928 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001929 // Pretend we have finished updating the window. Except when
1930 // 'cursorcolumn' is set.
1931#ifdef FEAT_SYN_HL
1932 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001933 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001934 else
1935#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001936 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001937 break;
1938 }
1939
Bram Moolenaar1306b362022-08-06 15:59:06 +01001940 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001941 {
1942 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001943 if (wlv.vcol == wlv.fromcol
1944 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1945 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001946 && (*mb_ptr2cells)(ptr) > 1)
1947 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001948 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001949 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001950 area_attr = vi_attr; // start highlighting
1951 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001952 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001953 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001954 area_attr = 0; // stop highlighting
1955
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001956#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001957 if (text_props != NULL)
1958 {
1959 int pi;
1960 int bcol = (int)(ptr - line);
1961
Bram Moolenaar1306b362022-08-06 15:59:06 +01001962 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001963# ifdef FEAT_LINEBREAK
1964 && !in_linebreak
1965# endif
1966 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001967 --bcol; // still working on the previous char, e.g. Tab
1968
1969 // Check if any active property ends.
1970 for (pi = 0; pi < text_props_active; ++pi)
1971 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001972 int tpi = text_prop_idxs[pi];
1973 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001974
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001975 // An inline property ends when after the start column plus
1976 // length. An "above" property ends when used and n_extra
1977 // is zero.
1978 if ((tp->tp_col != MAXCOL
1979 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001980 {
1981 if (pi + 1 < text_props_active)
1982 mch_memmove(text_prop_idxs + pi,
1983 text_prop_idxs + pi + 1,
1984 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001985 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001986 --text_props_active;
1987 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001988# ifdef FEAT_LINEBREAK
1989 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001990 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001991 syntax_attr = 0;
1992# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001993 }
1994 }
1995
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001996# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001997 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001998 // not on the next char yet, don't start another prop
1999 --bcol;
2000# endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002001 int display_text_first = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002002
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002003 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002004 // With 'nowrap' and not in the first screen line only "below"
2005 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002006 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002007 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002008 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002009 && (wp->w_p_wrap
2010 || wlv.row == startrow
2011 || (text_props[text_prop_next].tp_flags
2012 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002013 || (bcol == 0
2014 && (text_props[text_prop_next].tp_flags
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002015 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002016 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002017 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01002018 if (text_props[text_prop_next].tp_col == MAXCOL
2019 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002020 + text_props[text_prop_next].tp_len)
2021 text_prop_idxs[text_props_active++] = text_prop_next;
2022 ++text_prop_next;
2023 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002024
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002025 if (wlv.n_extra == 0 || !wlv.extra_for_textprop)
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002026 {
2027 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002028 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002029 text_prop_flags = 0;
2030 text_prop_type = NULL;
2031 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002032 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002033 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002034 if (text_props_active > 0 && wlv.n_extra == 0
2035 && !display_text_first)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002036 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01002037 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002038 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002039 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002040
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002041 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002042 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002043
2044 // Sort the properties on priority and/or starting last.
2045 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002046 sort_text_props(wp->w_buffer, text_props,
2047 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002048
2049 for (pi = 0; pi < text_props_active; ++pi)
2050 {
2051 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002052 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002053 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002054 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002055
Bram Moolenaarcd105412022-10-10 19:50:42 +01002056 // Only use a text property that can be displayed.
2057 // Skip "after" properties when wrap is off and at the
2058 // end of the window.
2059 if (pt != NULL
2060 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2061 && tp->tp_id != -MAXCOL
2062 && !(tp->tp_id < 0
2063 && !wp->w_p_wrap
2064 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2065 | TP_FLAG_ALIGN_ABOVE
2066 | TP_FLAG_ALIGN_BELOW)) == 0
2067 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002068 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002069 if (tp->tp_col == MAXCOL
2070 && *ptr == NUL
2071 && ((wp->w_p_list && lcs_eol_one > 0
2072 && (tp->tp_flags
2073 & TP_FLAG_ALIGN_ABOVE) == 0)
2074 || (ptr == line
2075 && !did_line
2076 && (tp->tp_flags
2077 & TP_FLAG_ALIGN_BELOW))))
2078 {
2079 // skip this prop, first display the '$' after
2080 // the line or display an empty line
2081 text_prop_follows = TRUE;
2082 if (used_tpi < 0)
2083 display_text_first = TRUE;
2084 continue;
2085 }
2086
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002087 if (pt->pt_hl_id > 0)
2088 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002089 text_prop_type = pt;
2090 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002091 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002092 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2093 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002094 text_prop_flags = pt->pt_flags;
2095 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002096 used_tpi = tpi;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002097 display_text_first = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002098 }
2099 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002100 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002101 && -text_prop_id
2102 <= wp->w_buffer->b_textprop_text.ga_len)
2103 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002104 textprop_T *tp = &text_props[used_tpi];
2105 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002106 ->b_textprop_text.ga_data)[
2107 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002108 int above = (tp->tp_flags
2109 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002110 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002111
2112 // reset the ID in the copy to avoid it being used
2113 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002114 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002115
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002116 if (p != NULL)
2117 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002118 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002119 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002120 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002121 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002122 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
2123 int padding = tp->tp_col == MAXCOL
2124 && tp->tp_len > 1
2125 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002126
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002127 // Insert virtual text before the current
2128 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002129 wlv.p_extra = p;
2130 wlv.c_extra = NUL;
2131 wlv.c_final = NUL;
2132 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002133 wlv.extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002134 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2135 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002136 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002137 // restore search_attr and area_attr when n_extra
2138 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01002139 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002140 saved_area_attr = area_attr;
2141 search_attr = 0;
2142 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002143 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002144 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002145 if (*ptr == NUL)
2146 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002147 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002148#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002149 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002150 {
2151 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002152 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002153 wlv.need_showbreak = FALSE;
2154 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002155 }
2156#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002157 if ((right || above || below || !wrap
2158 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002159 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002160 char_u *prev_p_extra = wlv.p_extra;
2161 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002162
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002163 // Take care of padding, right-align and
2164 // truncation.
2165 // Shared with win_lbr_chartabsize(), must do
2166 // exactly the same.
2167 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002168 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002169 wlv.col,
2170 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002171 &n_attr, &wlv.n_attr_skip,
2172 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002173 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002174 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002175 // wlv.p_extra was allocated
2176 vim_free(p_extra_free2);
2177 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002178 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002179
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002180 if (above)
2181 wlv.vcol_off_tp = wlv.n_extra;
2182
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002183 if (lcs_eol_one < 0
2184 && wp->w_p_wrap
2185 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002186 + wlv.n_extra - 2 > wp->w_width)
2187 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002188 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002189
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002190 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002191 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002192 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002193 {
2194 draw_screen_line(wp, &wlv);
2195
2196 // When line got too long for screen break
2197 // here.
2198 if (wlv.row == endrow)
2199 {
2200 ++wlv.row;
2201 break;
2202 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002203 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002204 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002205 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002206 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002207 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002208
Bram Moolenaarcd105412022-10-10 19:50:42 +01002209 // If the text didn't reach until the first window
2210 // column we need to skip cells.
2211 if (skip_cells > 0)
2212 {
2213 if (wlv.n_extra > skip_cells)
2214 {
2215 wlv.n_extra -= skip_cells;
2216 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002217 wlv.n_attr_skip -= skip_cells;
2218 if (wlv.n_attr_skip < 0)
2219 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002220 skip_cells = 0;
2221 }
2222 else
2223 {
2224 // the whole text is left of the window, drop
2225 // it and advance to the next one
2226 skip_cells -= wlv.n_extra;
2227 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002228 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002229 bail_out = TRUE;
2230 }
2231 }
2232
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002233 // If another text prop follows the condition below at
2234 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002235 // If this is an "above" text prop and 'nowrap' the we
2236 // must wrap anyway.
2237 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002238 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002239 && (wp->w_p_wrap
2240 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002241 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002242
2243 if (bail_out)
2244 // starting a new line for "below"
2245 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002246 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002247 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002248 else if (text_prop_next < text_prop_count
2249 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002250 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2251 || (!wp->w_p_wrap
2252 && wlv.col == wp->w_width - 1
2253 && (text_props[text_prop_next].tp_flags
2254 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002255 // When at last-but-one character and a text property
2256 // follows after it, we may need to flush the line after
2257 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002258 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002259 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002260 }
2261#endif
2262
zeertzjqe500ae82023-08-17 22:35:26 +02002263#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaare38fc862022-08-11 17:24:50 +01002264 if (wlv.n_extra == 0)
2265 {
2266 // Check for start/end of 'hlsearch' and other matches.
2267 // After end, check for start/end of next match.
2268 // When another match, have to check for start again.
2269 v = (long)(ptr - line);
2270 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2271 &screen_search_hl, &has_match_conc,
2272 &match_conc, did_line_attr, lcs_eol_one,
2273 &on_last_col);
2274 ptr = line + v; // "line" may have been changed
Bram Moolenaare38fc862022-08-11 17:24:50 +01002275
2276 // Do not allow a conceal over EOL otherwise EOL will be missed
2277 // and bad things happen.
2278 if (*ptr == NUL)
2279 has_match_conc = 0;
zeertzjqb25dbb32023-08-13 18:11:05 +02002280 }
zeertzjqe500ae82023-08-17 22:35:26 +02002281#endif
zeertzjqb25dbb32023-08-13 18:11:05 +02002282
Bram Moolenaare38fc862022-08-11 17:24:50 +01002283#ifdef FEAT_DIFF
2284 if (wlv.diff_hlf != (hlf_T)0)
2285 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002286 // When there is extra text (e.g. virtual text) it gets the
2287 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002288 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2289 && wlv.n_extra == 0)
2290 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002291 if (wlv.diff_hlf == HLF_TXD
2292 && ((ptr - line > change_end && wlv.n_extra == 0)
2293 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002294 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002295 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002296 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2297 && wp->w_p_culopt_flags != CULOPT_NBR
2298 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2299 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002300 wlv.line_attr = hl_combine_attr(
2301 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002302 }
2303#endif
2304
Bram Moolenaara74fda62019-10-19 17:38:03 +02002305#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002306 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002307 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002308 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002309# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002310 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002311 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002312# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002313 // Get syntax attribute.
2314 if (has_syntax)
2315 {
2316 // Get the syntax attribute for the character. If there
2317 // is an error, disable syntax highlighting.
2318 save_did_emsg = did_emsg;
2319 did_emsg = FALSE;
2320
2321 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002322 if (v == prev_syntax_col)
2323 // at same column again
2324 syntax_attr = prev_syntax_attr;
2325 else
2326 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002327# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002328 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002329# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002330 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002331# ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01002332 spv->spv_has_spell ? &can_spell :
Bram Moolenaar34390282019-10-16 14:38:26 +02002333# endif
Luuk van Baal30805a12023-05-27 22:22:10 +01002334 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002335 prev_syntax_col = v;
2336 prev_syntax_attr = syntax_attr;
2337 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002338
Bram Moolenaar34390282019-10-16 14:38:26 +02002339 if (did_emsg)
2340 {
2341 wp->w_s->b_syn_error = TRUE;
2342 has_syntax = FALSE;
2343 syntax_attr = 0;
2344 }
2345 else
2346 did_emsg = save_did_emsg;
2347# ifdef SYN_TIME_LIMIT
2348 if (wp->w_s->b_syn_slow)
2349 has_syntax = FALSE;
2350# endif
2351
2352 // Need to get the line again, a multi-line regexp may
2353 // have made it invalid.
2354 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2355 ptr = line + v;
2356# ifdef FEAT_CONCEAL
2357 // no concealing past the end of the line, it interferes
2358 // with line highlighting
2359 if (*ptr == NUL)
2360 syntax_flags = 0;
2361 else
2362 syntax_flags = get_syntax_info(&syntax_seqnr);
2363# endif
2364 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002365 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002366# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002367 // Combine text property highlight into syntax highlight.
2368 if (text_prop_type != NULL)
2369 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002370 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002371 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2372 else
2373 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002374 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002375 }
2376# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002377#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002378
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002379 // Decide which of the highlight attributes to use.
2380 attr_pri = TRUE;
2381#ifdef LINE_ATTR
2382 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002383 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002384 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002385 if (!highlight_match)
2386 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002387 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002388# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002389 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002390# endif
2391 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002392 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002393 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002394 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002395# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002396 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002397# endif
2398 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002399 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002400 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2401 || wlv.vcol < wlv.fromcol
2402 || vcol_prev < fromcol_prev
2403 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002404 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002405 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002406 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002407# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002408 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002409# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002410 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002411# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002412 attr_pri = FALSE;
2413 }
2414#else
2415 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002416 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002417 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002418 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002419#endif
2420 else
2421 {
2422 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002423#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002424 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002425#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002426 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002427#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002428 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002429#ifdef FEAT_PROP_POPUP
2430 // override with text property highlight when "override" is TRUE
2431 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002432 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002433#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002434 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002435
2436 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002437 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002438 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002439 if (wlv.char_attr == 0)
2440 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002441 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002442 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002443 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002444
2445 // Get the next character to put on the screen.
2446
2447 // The "p_extra" points to the extra stuff that is inserted to
2448 // represent special characters (non-printable stuff) and other
2449 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002450 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002451 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2452 // "p_extra[n_extra]".
2453 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002454 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002455 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002456 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002457 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002458 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2459 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002460 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2461 if (enc_utf8 && utf_char2len(c) > 1)
2462 {
2463 mb_utf8 = TRUE;
2464 u8cc[0] = 0;
2465 c = 0xc0;
2466 }
2467 else
2468 mb_utf8 = FALSE;
2469 }
2470 else
2471 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002472 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002473 if (has_mbyte)
2474 {
2475 mb_c = c;
2476 if (enc_utf8)
2477 {
2478 // If the UTF-8 character is more than one byte:
2479 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002480 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002481 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002482 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002483 mb_l = 1;
2484 else if (mb_l > 1)
2485 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002486 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002487 mb_utf8 = TRUE;
2488 c = 0xc0;
2489 }
2490 }
2491 else
2492 {
2493 // if this is a DBCS character, put it in "mb_c"
2494 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002495 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002496 mb_l = 1;
2497 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002498 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002499 }
2500 if (mb_l == 0) // at the NUL at end-of-line
2501 mb_l = 1;
2502
2503 // If a double-width char doesn't fit display a '>' in the
2504 // last column.
2505 if ((
2506# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002507 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002508# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002509 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002510 && (*mb_char2cells)(mb_c) == 2)
2511 {
2512 c = '>';
2513 mb_c = c;
2514 mb_l = 1;
2515 mb_utf8 = FALSE;
2516 multi_attr = HL_ATTR(HLF_AT);
2517#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002518 if (wlv.cul_attr)
2519 multi_attr = hl_combine_attr(
2520 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002521#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002522 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002523
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002524 // put the pointer back to output the double-width
2525 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002526 ++wlv.n_extra;
2527 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002528 }
2529 else
2530 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002531 wlv.n_extra -= mb_l - 1;
2532 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002533 }
2534 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002535 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002536 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002537 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002538#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002539 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002540 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002541 // Only restore search_attr and area_attr after "n_extra" in
2542 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002543 if (wlv.saved_n_extra <= 0)
2544 {
2545 if (search_attr == 0)
2546 search_attr = saved_search_attr;
2547 if (area_attr == 0 && *ptr != NUL)
2548 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002549
2550 if (wlv.extra_for_textprop)
2551 // wlv.extra_attr should be used at this position but
2552 // not any further.
2553 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002554 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002555
2556 wlv.extra_for_textprop = FALSE;
2557 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002558 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002559#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002560 }
2561 else
2562 {
2563#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002564 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002565#endif
zeertzjqe500ae82023-08-17 22:35:26 +02002566#ifdef FEAT_SPELL
2567 char_u *prev_ptr = ptr;
2568#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002569
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002570 // Get a character from the line itself.
2571 c = *ptr;
2572#ifdef FEAT_LINEBREAK
2573 c0 = *ptr;
2574#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002575#ifdef FEAT_PROP_POPUP
2576 if (c == NUL)
2577 // text is finished, may display a "below" virtual text
2578 did_line = TRUE;
2579#endif
2580
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002581 if (has_mbyte)
2582 {
2583 mb_c = c;
2584 if (enc_utf8)
2585 {
2586 // If the UTF-8 character is more than one byte: Decode it
2587 // into "mb_c".
2588 mb_l = utfc_ptr2len(ptr);
2589 mb_utf8 = FALSE;
2590 if (mb_l > 1)
2591 {
2592 mb_c = utfc_ptr2char(ptr, u8cc);
2593 // Overlong encoded ASCII or ASCII with composing char
2594 // is displayed normally, except a NUL.
2595 if (mb_c < 0x80)
2596 {
2597 c = mb_c;
2598#ifdef FEAT_LINEBREAK
2599 c0 = mb_c;
2600#endif
2601 }
2602 mb_utf8 = TRUE;
2603
2604 // At start of the line we can have a composing char.
2605 // Draw it as a space with a composing char.
2606 if (utf_iscomposing(mb_c))
2607 {
2608 int i;
2609
2610 for (i = Screen_mco - 1; i > 0; --i)
2611 u8cc[i] = u8cc[i - 1];
2612 u8cc[0] = mb_c;
2613 mb_c = ' ';
2614 }
2615 }
2616
2617 if ((mb_l == 1 && c >= 0x80)
2618 || (mb_l >= 1 && mb_c == 0)
2619 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2620 {
2621 // Illegal UTF-8 byte: display as <xx>.
2622 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002623 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002624# ifdef FEAT_RIGHTLEFT
2625 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002626 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002627# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002628 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002629 c = *wlv.p_extra;
2630 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002631 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002632 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2633 wlv.c_extra = NUL;
2634 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002635 if (area_attr == 0 && search_attr == 0)
2636 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002637 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002638 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002639 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002640 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002641 }
2642 }
2643 else if (mb_l == 0) // at the NUL at end-of-line
2644 mb_l = 1;
2645#ifdef FEAT_ARABIC
2646 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2647 {
2648 // Do Arabic shaping.
2649 int pc, pc1, nc;
2650 int pcc[MAX_MCO];
2651
2652 // The idea of what is the previous and next
2653 // character depends on 'rightleft'.
2654 if (wp->w_p_rl)
2655 {
2656 pc = prev_c;
2657 pc1 = prev_c1;
2658 nc = utf_ptr2char(ptr + mb_l);
2659 prev_c1 = u8cc[0];
2660 }
2661 else
2662 {
2663 pc = utfc_ptr2char(ptr + mb_l, pcc);
2664 nc = prev_c;
2665 pc1 = pcc[0];
2666 }
2667 prev_c = mb_c;
2668
2669 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2670 }
2671 else
2672 prev_c = mb_c;
2673#endif
2674 }
2675 else // enc_dbcs
2676 {
2677 mb_l = MB_BYTE2LEN(c);
2678 if (mb_l == 0) // at the NUL at end-of-line
2679 mb_l = 1;
2680 else if (mb_l > 1)
2681 {
2682 // We assume a second byte below 32 is illegal.
2683 // Hopefully this is OK for all double-byte encodings!
2684 if (ptr[1] >= 32)
2685 mb_c = (c << 8) + ptr[1];
2686 else
2687 {
2688 if (ptr[1] == NUL)
2689 {
2690 // head byte at end of line
2691 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002692 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002693 }
2694 else
2695 {
2696 // illegal tail byte
2697 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002698 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002699 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002700 wlv.p_extra = wlv.extra;
2701 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002702 wlv.c_extra = NUL;
2703 wlv.c_final = NUL;
2704 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002705 if (area_attr == 0 && search_attr == 0)
2706 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002707 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002708 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002709 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002710 // save current attr
2711 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002712 }
2713 mb_c = c;
2714 }
2715 }
2716 }
2717 // If a double-width char doesn't fit display a '>' in the
2718 // last column; the character is displayed at the start of the
2719 // next line.
2720 if ((
2721# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002722 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002723# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002724 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002725 && (*mb_char2cells)(mb_c) == 2)
2726 {
2727 c = '>';
2728 mb_c = c;
2729 mb_utf8 = FALSE;
2730 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002731 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002732 // Put pointer back so that the character will be
2733 // displayed at the start of the next line.
2734 --ptr;
2735#ifdef FEAT_CONCEAL
2736 did_decrement_ptr = TRUE;
2737#endif
2738 }
2739 else if (*ptr != NUL)
2740 ptr += mb_l - 1;
2741
2742 // If a double-width char doesn't fit at the left side display
2743 // a '<' in the first column. Don't do this for unprintable
2744 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002745 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002746 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002747 wlv.n_extra = 1;
2748 wlv.c_extra = MB_FILLER_CHAR;
2749 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002750 c = ' ';
2751 if (area_attr == 0 && search_attr == 0)
2752 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002753 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002754 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002755 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002756 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002757 }
2758 mb_c = c;
2759 mb_utf8 = FALSE;
2760 mb_l = 1;
2761 }
2762
2763 }
2764 ++ptr;
2765
2766 if (extra_check)
2767 {
2768#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002769 // Check spelling (unless at the end of the line).
2770 // Only do this when there is no syntax highlighting, the
2771 // @Spell cluster is not used or the current syntax item
2772 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002773 v = (long)(ptr - line);
Luuk van Baal30805a12023-05-27 22:22:10 +01002774 if (spv->spv_has_spell && v >= word_end && v > cur_checked_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002775 {
2776 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002777 // do not calculate cap_col at the end of the line or when
2778 // only white space is following
2779 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002780# ifdef FEAT_SYN_HL
2781 !has_syntax ||
2782# endif
2783 can_spell))
2784 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002785 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002786 int len;
2787 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002788
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002789 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002790 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002791
2792 // Use nextline[] if possible, it has the start of the
2793 // next line concatenated.
2794 if ((prev_ptr - line) - nextlinecol >= 0)
2795 p = nextline + (prev_ptr - line) - nextlinecol;
2796 else
2797 p = prev_ptr;
Luuk van Baal30805a12023-05-27 22:22:10 +01002798 spv->spv_cap_col -= (int)(prev_ptr - line);
2799 len = spell_check(wp, p, &spell_hlf, &spv->spv_cap_col,
2800 spv->spv_unchanged);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002801 word_end = v + len;
2802
2803 // In Insert mode only highlight a word that
2804 // doesn't touch the cursor.
2805 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002806 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002807 && wp->w_cursor.lnum == lnum
2808 && wp->w_cursor.col >=
2809 (colnr_T)(prev_ptr - line)
2810 && wp->w_cursor.col < (colnr_T)word_end)
2811 {
2812 spell_hlf = HLF_COUNT;
2813 spell_redraw_lnum = lnum;
2814 }
2815
2816 if (spell_hlf == HLF_COUNT && p != prev_ptr
2817 && (p - nextline) + len > nextline_idx)
2818 {
2819 // Remember that the good word continues at the
2820 // start of the next line.
Luuk van Baal30805a12023-05-27 22:22:10 +01002821 spv->spv_checked_lnum = lnum + 1;
2822 spv->spv_checked_col = (p - nextline) + len
2823 - nextline_idx;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002824 }
2825
2826 // Turn index into actual attributes.
2827 if (spell_hlf != HLF_COUNT)
2828 spell_attr = highlight_attr[spell_hlf];
2829
Luuk van Baal30805a12023-05-27 22:22:10 +01002830 if (spv->spv_cap_col > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002831 {
2832 if (p != prev_ptr
Luuk van Baal30805a12023-05-27 22:22:10 +01002833 && (p - nextline) + spv->spv_cap_col
2834 >= nextline_idx)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002835 {
2836 // Remember that the word in the next line
2837 // must start with a capital.
Luuk van Baal30805a12023-05-27 22:22:10 +01002838 spv->spv_capcol_lnum = lnum + 1;
2839 spv->spv_cap_col = ((p - nextline)
2840 + spv->spv_cap_col - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002841 }
2842 else
2843 // Compute the actual column.
Luuk van Baal30805a12023-05-27 22:22:10 +01002844 spv->spv_cap_col += (prev_ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002845 }
2846 }
2847 }
2848 if (spell_attr != 0)
2849 {
2850 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002851 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2852 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002853 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002854 wlv.char_attr = hl_combine_attr(spell_attr,
2855 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002856 }
2857#endif
2858#ifdef FEAT_LINEBREAK
2859 // Found last space before word: check for line break.
2860 if (wp->w_p_lbr && c0 == c
2861 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2862 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002863 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2864 : 0;
2865 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002866 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002867
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002868 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002869# ifdef FEAT_PROP_POPUP
2870 // do not want virtual text counted here
2871 cts.cts_has_prop_with_text = FALSE;
2872# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002873 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002874 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002875
2876 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002877 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002878 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002879 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002880 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2881 if (wlv.n_extra < 0)
2882 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002883 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002884 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002885 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002886 // line break, but for TABs the highlighting should
2887 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002888 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002889
Bram Moolenaar1306b362022-08-06 15:59:06 +01002890 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002891# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002892 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002893 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002894 wp->w_buffer->b_p_vts_array) - 1;
2895# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002896 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002897 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002898# endif
2899
Bram Moolenaar1306b362022-08-06 15:59:06 +01002900 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2901 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002902# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002903 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002904 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002905# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002906 if (VIM_ISWHITE(c))
2907 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002908# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002909 if (c == TAB)
2910 // See "Tab alignment" below.
2911 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002912# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002913 if (!wp->w_p_list)
2914 c = ' ';
2915 }
2916 }
2917#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002918 in_multispace = c == ' '
2919 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2920 if (!in_multispace)
2921 multispace_pos = 0;
2922
Bram Moolenaareed9d462021-02-15 20:38:25 +01002923 // 'list': Change char 160 to 'nbsp' and space to 'space'
2924 // setting in 'listchars'. But not when the character is
2925 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002926 if (wp->w_p_list
2927 && ((((c == 160 && mb_l == 1)
2928 || (mb_utf8
2929 && ((mb_c == 160 && mb_l == 2)
2930 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002931 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002932 || (c == ' '
2933 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002934 && (wp->w_lcs_chars.space
2935 || (in_multispace
2936 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002937 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002938 && ptr - line <= trailcol)))
2939 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002940 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2941 {
2942 c = wp->w_lcs_chars.multispace[multispace_pos++];
2943 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2944 multispace_pos = 0;
2945 }
2946 else
2947 c = (c == ' ') ? wp->w_lcs_chars.space
2948 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002949 if (area_attr == 0 && search_attr == 0)
2950 {
2951 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002952 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002953 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002954 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002955 }
2956 mb_c = c;
2957 if (enc_utf8 && utf_char2len(c) > 1)
2958 {
2959 mb_utf8 = TRUE;
2960 u8cc[0] = 0;
2961 c = 0xc0;
2962 }
2963 else
2964 mb_utf8 = FALSE;
2965 }
2966
zeertzjq2e7cba32022-06-10 15:30:32 +01002967 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2968 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002969 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002970 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2971 && wp->w_lcs_chars.leadmultispace != NULL)
2972 {
2973 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002974 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2975 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002976 multispace_pos = 0;
2977 }
2978
2979 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2980 c = wp->w_lcs_chars.trail;
2981
2982 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2983 c = wp->w_lcs_chars.lead;
2984
zeertzjq2e7cba32022-06-10 15:30:32 +01002985 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002986 c = wp->w_lcs_chars.space;
2987
2988
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002989 if (!attr_pri)
2990 {
2991 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002992 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002993 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002994 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002995 }
2996 mb_c = c;
2997 if (enc_utf8 && utf_char2len(c) > 1)
2998 {
2999 mb_utf8 = TRUE;
3000 u8cc[0] = 0;
3001 c = 0xc0;
3002 }
3003 else
3004 mb_utf8 = FALSE;
3005 }
3006 }
3007
3008 // Handling of non-printable characters.
3009 if (!vim_isprintc(c))
3010 {
3011 // when getting a character from the file, we may have to
3012 // turn it into something else on the way to putting it
3013 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01003014 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003015 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003016 int tab_len = 0;
3017 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003018#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003019 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01003020
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003021 // only adjust the tab_len, when at the first column
3022 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01003023 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003024 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003025#endif
3026 // tab amount depends on current column
3027#ifdef FEAT_VARTABS
3028 tab_len = tabstop_padding(vcol_adjusted,
3029 wp->w_buffer->b_p_ts,
3030 wp->w_buffer->b_p_vts_array) - 1;
3031#else
3032 tab_len = (int)wp->w_buffer->b_p_ts
3033 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
3034#endif
3035
3036#ifdef FEAT_LINEBREAK
3037 if (!wp->w_p_lbr || !wp->w_p_list)
3038#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003039 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003040 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01003041 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003042 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003043#ifdef FEAT_LINEBREAK
3044 else
3045 {
3046 char_u *p;
3047 int len;
3048 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003049 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003050
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003051# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003052 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003053 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003054 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003055
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003056 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003057 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003058 && old_boguscols > 0
3059 && wlv.n_extra > tab_len)
3060 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003061# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003062 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003063 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003064 // If wlv.n_extra > 0, it gives the number of chars
3065 // to use for a tab, else we need to calculate the
3066 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003067 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3068 len = tab_len * tab2_len;
3069 if (wp->w_lcs_chars.tab3)
3070 len += mb_char2len(wp->w_lcs_chars.tab3)
3071 - tab2_len;
3072 if (wlv.n_extra > 0)
3073 len += wlv.n_extra - tab_len;
3074 c = wp->w_lcs_chars.tab1;
3075 p = alloc(len + 1);
3076 if (p == NULL)
3077 wlv.n_extra = 0;
3078 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003079 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003080 vim_memset(p, ' ', len);
3081 p[len] = NUL;
3082 vim_free(wlv.p_extra_free);
3083 wlv.p_extra_free = p;
3084 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003085 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003086 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003087
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003088 if (*p == NUL)
3089 {
3090 tab_len = i;
3091 break;
3092 }
3093
3094 // if tab3 is given, use it for the last
3095 // char
3096 if (wp->w_lcs_chars.tab3
3097 && i == tab_len - 1)
3098 lcs = wp->w_lcs_chars.tab3;
3099 p += mb_char2bytes(lcs, p);
3100 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003101 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003102 }
3103 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003104# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003105 // n_extra will be increased by
3106 // FIX_FOX_BOGUSCOLS macro below, so need to
3107 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003108 if (wlv.vcol_off_co > 0)
3109 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003110# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003111 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003112 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003113 }
3114#endif
3115#ifdef FEAT_CONCEAL
3116 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003117 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003118
3119 // Tab alignment should be identical regardless of
3120 // 'conceallevel' value. So tab compensates of all
3121 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003122 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003123 // line. Note that the tab can be longer than
3124 // 'tabstop' when there are concealed characters.
3125 FIX_FOR_BOGUSCOLS;
3126
3127 // Make sure, the highlighting for the tab char will be
3128 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003129 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003130 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003131 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003132 tab_len += vc_saved;
3133 }
3134#endif
3135 mb_utf8 = FALSE; // don't draw as UTF-8
3136 if (wp->w_p_list)
3137 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003138 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003139 ? wp->w_lcs_chars.tab3
3140 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003141#ifdef FEAT_LINEBREAK
h-east194555c2023-03-02 18:49:09 +00003142 if (wp->w_p_lbr && wlv.p_extra != NULL
3143 && *wlv.p_extra != NUL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003144 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003145 else
3146#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003147 wlv.c_extra = wp->w_lcs_chars.tab2;
3148 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003149 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003150 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003151 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003152 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003153 mb_c = c;
3154 if (enc_utf8 && utf_char2len(c) > 1)
3155 {
3156 mb_utf8 = TRUE;
3157 u8cc[0] = 0;
3158 c = 0xc0;
3159 }
3160 }
3161 else
3162 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003163 wlv.c_final = NUL;
3164 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003165 c = ' ';
3166 }
3167 }
3168 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003169 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003170 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003171 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3172 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003173 && VIsual_mode != Ctrl_V
3174 && (
3175# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003176 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003177# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003178 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003179 && !(noinvcur
3180 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003181 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003182 && lcs_eol_one > 0)
3183 {
3184 // Display a '$' after the line or highlight an extra
3185 // character if the line break is included.
3186#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3187 // For a diff line the highlighting continues after the
3188 // "$".
3189 if (
3190# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003191 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003192# ifdef LINE_ATTR
3193 &&
3194# endif
3195# endif
3196# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003197 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003198# endif
3199 )
3200#endif
3201 {
3202 // In virtualedit, visual selections may extend
3203 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003204 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003205 && wlv.tocol != MAXCOL
3206 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003207 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003208 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003209 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003210 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3211 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003212 else
3213 c = ' ';
3214 lcs_eol_one = -1;
3215 --ptr; // put it back at the NUL
3216 if (!attr_pri)
3217 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003218 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003219 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003220 n_attr = 1;
3221 }
3222 mb_c = c;
3223 if (enc_utf8 && utf_char2len(c) > 1)
3224 {
3225 mb_utf8 = TRUE;
3226 u8cc[0] = 0;
3227 c = 0xc0;
3228 }
3229 else
3230 mb_utf8 = FALSE; // don't draw as UTF-8
3231 }
3232 else if (c != NUL)
3233 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003234 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3235 if (wlv.n_extra == 0)
3236 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003237#ifdef FEAT_RIGHTLEFT
3238 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003239 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003240#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003241 wlv.c_extra = NUL;
3242 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003243#ifdef FEAT_LINEBREAK
3244 if (wp->w_p_lbr)
3245 {
3246 char_u *p;
3247
Bram Moolenaar1306b362022-08-06 15:59:06 +01003248 c = *wlv.p_extra;
3249 p = alloc(wlv.n_extra + 1);
3250 vim_memset(p, ' ', wlv.n_extra);
3251 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3252 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003253 vim_free(wlv.p_extra_free);
3254 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003255 }
3256 else
3257#endif
3258 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003259 wlv.n_extra = byte2cells(c) - 1;
3260 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003261 }
3262 if (!attr_pri)
3263 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003264 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003265 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003266 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003267 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003268 }
3269 mb_utf8 = FALSE; // don't draw as UTF-8
3270 }
3271 else if (VIsual_active
3272 && (VIsual_mode == Ctrl_V
3273 || VIsual_mode == 'v')
3274 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003275 && wlv.tocol != MAXCOL
3276 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003277 && (
3278#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003279 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003280#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003281 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003282 {
3283 c = ' ';
3284 --ptr; // put it back at the NUL
3285 }
3286#if defined(LINE_ATTR)
3287 else if ((
3288# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003289 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003290# endif
3291# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003292 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003293# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003294 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003295 ) && (
3296# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003297 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003298# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003299 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003300# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003301 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003302# endif
3303 < wp->w_width)))
3304 {
3305 // Highlight until the right side of the window
3306 c = ' ';
3307 --ptr; // put it back at the NUL
3308
3309 // Remember we do the char for line highlighting.
3310 ++did_line_attr;
3311
3312 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003313 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003314 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003315 || (wp->w_p_list &&
3316 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003317 wlv.char_attr = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003318# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003319 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003320 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003321 wlv.diff_hlf = HLF_CHD;
3322 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003323 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003324 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003325 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3326 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003327 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003328 || (wlv.vcol >= left_curline_col
3329 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003330 wlv.char_attr = hl_combine_attr(
3331 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003332 }
3333 }
3334# endif
3335# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003336 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003337 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003338 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003339 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3340 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003341 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003342 if (!wlv.cul_screenline
3343 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003344 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003345 wlv.char_attr = hl_combine_attr(
3346 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003347 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003348 else if (wlv.line_attr)
3349 wlv.char_attr = hl_combine_attr(
3350 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003351 }
3352# endif
3353 }
3354#endif
3355 }
3356
3357#ifdef FEAT_CONCEAL
3358 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003359 && (wp != curwin || lnum != wp->w_cursor.lnum
3360 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003361 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3362 && !(lnum_in_visual_area
3363 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3364 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003365 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003366 if (((prev_syntax_id != syntax_seqnr
3367 && (syntax_flags & HL_CONCEAL) != 0)
3368 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003369 && (syn_get_sub_char() != NUL
3370 || (has_match_conc && match_conc)
3371 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003372 && wp->w_p_cole != 3)
3373 {
3374 // First time at this concealed item: display one
3375 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003376 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003377 c = match_conc;
3378 else if (syn_get_sub_char() != NUL)
3379 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003380 else if (wp->w_lcs_chars.conceal != NUL)
3381 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003382 else
3383 c = ' ';
3384
3385 prev_syntax_id = syntax_seqnr;
3386
Bram Moolenaar1306b362022-08-06 15:59:06 +01003387 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003388 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003389 wlv.vcol += wlv.n_extra;
3390 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003391 {
3392# ifdef FEAT_RIGHTLEFT
3393 if (wp->w_p_rl)
3394 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003395 wlv.col -= wlv.n_extra;
3396 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003397 }
3398 else
3399# endif
3400 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003401 wlv.boguscols += wlv.n_extra;
3402 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003403 }
3404 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003405 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003406 n_attr = 0;
3407 }
3408 else if (n_skip == 0)
3409 {
3410 is_concealing = TRUE;
3411 n_skip = 1;
3412 }
3413 mb_c = c;
3414 if (enc_utf8 && utf_char2len(c) > 1)
3415 {
3416 mb_utf8 = TRUE;
3417 u8cc[0] = 0;
3418 c = 0xc0;
3419 }
3420 else
3421 mb_utf8 = FALSE; // don't draw as UTF-8
3422 }
3423 else
3424 {
3425 prev_syntax_id = 0;
3426 is_concealing = FALSE;
3427 }
3428
3429 if (n_skip > 0 && did_decrement_ptr)
3430 // not showing the '>', put pointer back to avoid getting stuck
3431 ++ptr;
3432
3433#endif // FEAT_CONCEAL
3434 }
3435
3436#ifdef FEAT_CONCEAL
3437 // In the cursor line and we may be concealing characters: correct
3438 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003439 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003440 && wp == curwin && lnum == wp->w_cursor.lnum
3441 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003442 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003443 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003444# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003445 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003446 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003447 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003448# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003449 wp->w_wcol = wlv.col - wlv.boguscols;
3450 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003451 did_wcol = TRUE;
3452 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003453# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003454 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003455# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003456 }
3457#endif
3458
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003459 // Use "wlv.extra_attr", but don't override visual selection
3460 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003461 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3462 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003463 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003464 && (!attr_pri
3465#ifdef FEAT_PROP_POPUP
3466 || (text_prop_flags & PT_FLAG_OVERRIDE)
3467#endif
3468 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003469 {
3470#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003471 if (wlv.line_attr)
3472 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003473 else
3474#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003475 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003476#ifdef FEAT_PROP_POPUP
3477 if (reset_extra_attr)
3478 {
3479 reset_extra_attr = FALSE;
3480 wlv.extra_attr = 0;
3481 }
3482#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003483 }
3484
3485#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3486 // XIM don't send preedit_start and preedit_end, but they send
3487 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3488 // im_is_preediting() here.
3489 if (p_imst == IM_ON_THE_SPOT
3490 && xic != NULL
3491 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003492 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003493 && !p_imdisable
3494 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003495 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003496 {
3497 colnr_T tcol;
3498
3499 if (preedit_end_col == MAXCOL)
3500 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3501 else
3502 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003503 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003504 {
3505 if (feedback_old_attr < 0)
3506 {
3507 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003508 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003509 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003510 wlv.char_attr = im_get_feedback_attr(feedback_col);
3511 if (wlv.char_attr < 0)
3512 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003513 feedback_col++;
3514 }
3515 else if (feedback_old_attr >= 0)
3516 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003517 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003518 feedback_old_attr = -1;
3519 feedback_col = 0;
3520 }
3521 }
3522#endif
3523 // Handle the case where we are in column 0 but not on the first
3524 // character of the line and the user wants us to show us a
3525 // special character (via 'listchars' option "precedes:<char>".
3526 if (lcs_prec_todo != NUL
3527 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003528 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3529 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003530#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003531 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003532#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003533 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003534 && c != NUL)
3535 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003536 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003537 lcs_prec_todo = NUL;
3538 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3539 {
3540 // Double-width character being overwritten by the "precedes"
3541 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003542 wlv.c_extra = MB_FILLER_CHAR;
3543 wlv.c_final = NUL;
3544 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003545 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003546 wlv.extra_attr =
3547 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003548 }
3549 mb_c = c;
3550 if (enc_utf8 && utf_char2len(c) > 1)
3551 {
3552 mb_utf8 = TRUE;
3553 u8cc[0] = 0;
3554 c = 0xc0;
3555 }
3556 else
3557 mb_utf8 = FALSE; // don't draw as UTF-8
3558 if (!attr_pri)
3559 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003560 saved_attr3 = wlv.char_attr; // save current attr
3561 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003562 n_attr3 = 1;
3563 }
3564 }
3565
3566 // At end of the text line or just after the last character.
3567 if ((c == NUL
3568#if defined(LINE_ATTR)
3569 || did_line_attr == 1
3570#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003571 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003572 {
3573#ifdef FEAT_SEARCH_EXTRA
3574 // flag to indicate whether prevcol equals startcol of search_hl or
3575 // one of the matches
3576 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3577 (long)(ptr - line) - (c == NUL));
3578#endif
3579 // Invert at least one char, used for Visual and empty line or
3580 // highlight match at end of line. If it's beyond the last
3581 // char on the screen, just overwrite that one (tricky!) Not
3582 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003583 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003584 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003585 && (VIsual_mode != Ctrl_V
3586 || lnum == VIsual.lnum
3587 || lnum == curwin->w_cursor.lnum)
3588 && c == NUL)
3589#ifdef FEAT_SEARCH_EXTRA
3590 // highlight 'hlsearch' match at end of line
3591 || (prevcol_hl_flag
3592# ifdef FEAT_SYN_HL
3593 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3594 && !(wp == curwin && VIsual_active))
3595# endif
3596# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003597 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003598# endif
3599# if defined(LINE_ATTR)
3600 && did_line_attr <= 1
3601# endif
3602 )
3603#endif
3604 ))
3605 {
3606 int n = 0;
3607
3608#ifdef FEAT_RIGHTLEFT
3609 if (wp->w_p_rl)
3610 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003611 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003612 n = 1;
3613 }
3614 else
3615#endif
3616 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003617 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003618 n = -1;
3619 }
3620 if (n != 0)
3621 {
3622 // At the window boundary, highlight the last character
3623 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003624 wlv.off += n;
3625 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003626 }
3627 else
3628 {
3629 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003630 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003631 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003632 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003633 }
3634#ifdef FEAT_SEARCH_EXTRA
3635 if (area_attr == 0)
3636 {
3637 // Use attributes from match with highest priority among
3638 // 'search_hl' and the match list.
3639 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003640 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003641 }
3642#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003643 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003644 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003645#ifdef FEAT_RIGHTLEFT
3646 if (wp->w_p_rl)
3647 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003648 --wlv.col;
3649 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003650 }
3651 else
3652#endif
3653 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003654 ++wlv.col;
3655 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003656 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003657 ++wlv.vcol;
3658 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003659 }
3660 }
3661
3662 // At end of the text line.
3663 if (c == NUL)
3664 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003665#ifdef FEAT_PROP_POPUP
3666 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003667 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003668 // Put the pointer back to the NUL.
3669 --ptr;
3670 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003671 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003672 else
3673#endif
3674 {
3675 draw_screen_line(wp, &wlv);
3676
3677 // Update w_cline_height and w_cline_folded if the cursor line
3678 // was updated (saves a call to plines() later).
3679 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3680 {
3681 curwin->w_cline_row = startrow;
3682 curwin->w_cline_height = wlv.row - startrow;
3683#ifdef FEAT_FOLDING
3684 curwin->w_cline_folded = FALSE;
3685#endif
3686 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3687 }
3688 break;
3689 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003690 }
3691
3692 // Show "extends" character from 'listchars' if beyond the line end and
3693 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003694 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003695 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003696 && wp->w_p_list
3697 && !wp->w_p_wrap
3698#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003699 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003700#endif
3701 && (
3702#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003703 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003704#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003705 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003706 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003707 || lcs_eol_one > 0
3708 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003709 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003710 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003711 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003712 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003713 mb_c = c;
3714 if (enc_utf8 && utf_char2len(c) > 1)
3715 {
3716 mb_utf8 = TRUE;
3717 u8cc[0] = 0;
3718 c = 0xc0;
3719 }
3720 else
3721 mb_utf8 = FALSE;
3722 }
3723
3724#ifdef FEAT_SYN_HL
3725 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003726 if (wlv.draw_color_col)
3727 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003728
3729 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3730 // highlight the cursor position itself.
3731 // Also highlight the 'colorcolumn' if it is different than
3732 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003733 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3734 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003735 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003736 if (((wlv.draw_state == WL_LINE
3737 || wlv.draw_state == WL_BRI
3738 || wlv.draw_state == WL_SBR)
3739 && !lnum_in_visual_area
3740 && search_attr == 0
3741 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003742# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003743 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003744# endif
3745 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003746 {
3747 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3748 && lnum != wp->w_cursor.lnum)
3749 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003750 vcol_save_attr = wlv.char_attr;
3751 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3752 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003753 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003754 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003755 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003756 vcol_save_attr = wlv.char_attr;
3757 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003758 }
3759 }
3760#endif
3761
3762 // Store character to be displayed.
3763 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003764 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003765 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003766 {
3767 // Store the character.
3768#if defined(FEAT_RIGHTLEFT)
3769 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3770 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003771 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003772 --wlv.off;
3773 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003774 }
3775#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003776 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003777 if (enc_dbcs == DBCS_JPNU)
3778 {
3779 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003780 ScreenLines[wlv.off] = 0x8e;
3781 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003782 }
3783 else if (enc_utf8)
3784 {
3785 if (mb_utf8)
3786 {
3787 int i;
3788
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003789 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003790 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003791 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003792 for (i = 0; i < Screen_mco; ++i)
3793 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003794 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003795 if (u8cc[i] == 0)
3796 break;
3797 }
3798 }
3799 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003800 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003801 }
3802 if (multi_attr)
3803 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003804 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003805 multi_attr = 0;
3806 }
3807 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003808 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003809
zeertzjqe500ae82023-08-17 22:35:26 +02003810 ScreenCols[wlv.off] = wlv.vcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003811
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003812 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3813 {
3814 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003815 ++wlv.off;
3816 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003817 if (enc_utf8)
3818 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003819 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003820 else
3821 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003822 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003823 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003824#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003825 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003826#endif
3827 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003828 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003829 // When "wlv.tocol" is halfway a character, set it to the end
3830 // of the character, otherwise highlighting won't stop.
3831 if (wlv.tocol == wlv.vcol)
3832 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003833
zeertzjqe500ae82023-08-17 22:35:26 +02003834 ScreenCols[wlv.off] = wlv.vcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003835
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003836#ifdef FEAT_RIGHTLEFT
3837 if (wp->w_p_rl)
3838 {
3839 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003840 --wlv.off;
3841 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003842 }
3843#endif
3844 }
3845#ifdef FEAT_RIGHTLEFT
3846 if (wp->w_p_rl)
3847 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003848 --wlv.off;
3849 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003850 }
3851 else
3852#endif
3853 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003854 ++wlv.off;
3855 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003856 }
3857 }
3858#ifdef FEAT_CONCEAL
3859 else if (wp->w_p_cole > 0 && is_concealing)
3860 {
3861 --n_skip;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003862 ++wlv.vcol_off_co;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003863 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003864 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003865 if (wp->w_p_wrap)
3866 {
3867 // Special voodoo required if 'wrap' is on.
3868 //
3869 // Advance the column indicator to force the line
3870 // drawing to wrap early. This will make the line
3871 // take up the same screen space when parts are concealed,
3872 // so that cursor line computations aren't messed up.
3873 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003874 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003875 // trailing junk to be written out of the screen line
3876 // we are building, 'boguscols' keeps track of the number
3877 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003878 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003879 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003880 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003881# ifdef FEAT_RIGHTLEFT
3882 if (wp->w_p_rl)
3883 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003884 wlv.col -= wlv.n_extra;
3885 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003886 }
3887 else
3888# endif
3889 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003890 wlv.col += wlv.n_extra;
3891 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003892 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003893 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003894 n_attr = 0;
3895 }
3896
3897
3898 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3899 {
3900 // Need to fill two screen columns.
3901# ifdef FEAT_RIGHTLEFT
3902 if (wp->w_p_rl)
3903 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003904 --wlv.boguscols;
3905 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003906 }
3907 else
3908# endif
3909 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003910 ++wlv.boguscols;
3911 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003912 }
3913 }
3914
3915# ifdef FEAT_RIGHTLEFT
3916 if (wp->w_p_rl)
3917 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003918 --wlv.boguscols;
3919 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003920 }
3921 else
3922# endif
3923 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003924 ++wlv.boguscols;
3925 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003926 }
3927 }
3928 else
3929 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003930 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003931 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003932 wlv.vcol += wlv.n_extra;
3933 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003934 n_attr = 0;
3935 }
3936 }
3937
3938 }
3939#endif // FEAT_CONCEAL
3940 else
3941 --n_skip;
3942
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003943 // Only advance the "wlv.vcol" when after the 'number' or
3944 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003945 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003946#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003947 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003948#endif
3949 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003950 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003951
3952#ifdef FEAT_SYN_HL
3953 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003954 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003955#endif
3956
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003957 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003958 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3959 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003960
3961 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003962 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003963 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003964 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003965 if (wlv.n_attr_skip > 0)
3966 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003967
3968 // At end of screen line and there is more to come: Display the line
3969 // so far. If there is no more to display it is caught above.
3970 if ((
3971#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003972 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003973#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003974 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003975 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003976 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003977#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003978 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003979#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003980#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003981 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003982#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003983 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003984 && wlv.p_extra != at_end_str)
3985 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3986 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003987 )
3988 {
3989#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003990 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003991 wlv_screen_line(wp, &wlv, FALSE);
3992 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003993 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003994 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003995#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003996 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003997#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003998 ++wlv.row;
3999 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004000
4001 // When not wrapping and finished diff lines, or when displayed
4002 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01004003 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004004#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004005 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004006#endif
4007#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01004008 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004009#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01004010 ) || lcs_eol_one == -1)
4011#ifdef FEAT_PROP_POPUP
4012 && !text_prop_follows
4013#endif
4014 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004015 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004016#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004017 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004018 {
4019 // do not output more of the line, only the "below" prop
4020 ptr += STRLEN(ptr);
4021# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004022 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004023# endif
4024 }
4025#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004026
4027 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004028 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004029#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004030 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004031#endif
4032 )
4033 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004034 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
4035 draw_vsep_win(wp, wlv.row);
4036 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004037 }
4038
4039 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004040 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004041 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004042 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004043 break;
4044 }
4045
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004046 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004047#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004048 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004049#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004050#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004051 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004052#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004053 && wp->w_width == Columns)
4054 {
4055 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004056 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004057
4058 // Special trick to make copy/paste of wrapped lines work with
4059 // xterm/screen: write an extra character beyond the end of
4060 // the line. This will work with all terminal types
4061 // (regardless of the xn,am settings).
4062 // Only do this on a fast tty.
4063 // Only do this if the cursor is on the current line
4064 // (something has been written in it).
4065 // Don't do this for the GUI.
4066 // Don't do this for double-width characters.
4067 // Don't do this for a window not at the right screen border.
4068 if (p_tf
4069#ifdef FEAT_GUI
4070 && !gui.in_use
4071#endif
4072 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004073 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4074 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004075 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004076 || (*mb_off2cells)(
4077 LineOffset[wlv.screen_row - 1]
4078 + (int)Columns - 2,
4079 LineOffset[wlv.screen_row]
4080 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004081 {
4082 // First make sure we are at the end of the screen line,
4083 // then output the same character again to let the
4084 // terminal know about the wrap. If the terminal doesn't
4085 // auto-wrap, we overwrite the character.
4086 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004087 screen_char(LineOffset[wlv.screen_row - 1]
4088 + (unsigned)Columns - 1,
4089 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004090
4091 // When there is a multi-byte character, just output a
4092 // space to keep it simple.
4093 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004094 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004095 out_char(' ');
4096 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004097 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004098 + (Columns - 1)]);
4099 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004100 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004101 screen_start(); // don't know where cursor is now
4102 }
4103 }
4104
Bram Moolenaar1306b362022-08-06 15:59:06 +01004105 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004106
Bram Moolenaareed9d462021-02-15 20:38:25 +01004107 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004108#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004109 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004110# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004111 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004112# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004113 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004114 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004115#endif
4116#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004117 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004118 // When the filler lines are actually below the last line of the
4119 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004120 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004121 break;
4122#endif
4123 }
4124
4125 } // for every character in the line
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004126#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004127 vim_free(text_props);
4128 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004129 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004130#endif
4131
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004132 vim_free(wlv.p_extra_free);
zeertzjq58e1e012023-06-04 18:46:28 +01004133 vim_free(wlv.saved_p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004134 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004135}