blob: 9d6ee8d8db2fca032f10405201896a4ab16df9d0 [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 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001835 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001836#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001837 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001838#endif
1839#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001840 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001841#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001842
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001843 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001844 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001845 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001846#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001847 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001848 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001849 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001850 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001851 }
1852#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001853 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001854 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001855 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001856 if (cmdwin_type != 0 && wp == curwin)
1857 {
1858 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001859 wlv.n_extra = 1;
1860 wlv.c_extra = cmdwin_type;
1861 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001862 wlv.char_attr =
1863 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001864 }
1865 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001866#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001867 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001868 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001869 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001870 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001871 }
1872#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001873#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001874 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001875 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001876 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001877 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001878 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001879 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001880 }
1881#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001882 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001883 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001884 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001885 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001886 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001887 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001888#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001889 // Check if 'breakindent' applies and show it.
1890 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1891 if (wlv.n_extra == 0)
1892 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001893#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001894#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001895 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001896 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001897 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001898 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001899 }
1900#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001901 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001902 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001903 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001904 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001905 }
1906 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001907
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001908#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001909 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001910 && wlv.vcol >= left_curline_col
1911 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001912 {
zeertzjqb7acea12022-12-12 13:20:43 +00001913 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001914 }
1915#endif
1916
1917 // When still displaying '$' of change command, stop at cursor.
1918 // When only displaying the (relative) line number and that's done,
1919 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001920 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001921 && lnum == wp->w_cursor.lnum
1922 && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001923 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001924#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001925 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001926#endif
1927 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001928 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001929 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001930 // Pretend we have finished updating the window. Except when
1931 // 'cursorcolumn' is set.
1932#ifdef FEAT_SYN_HL
1933 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001934 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001935 else
1936#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001937 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001938 break;
1939 }
1940
Bram Moolenaar1306b362022-08-06 15:59:06 +01001941 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001942 {
1943 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001944 if (wlv.vcol == wlv.fromcol
1945 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1946 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001947 && (*mb_ptr2cells)(ptr) > 1)
1948 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001949 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001950 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001951 area_attr = vi_attr; // start highlighting
1952 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001953 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001954 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001955 area_attr = 0; // stop highlighting
1956
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001957#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001958 if (text_props != NULL)
1959 {
1960 int pi;
1961 int bcol = (int)(ptr - line);
1962
Bram Moolenaar1306b362022-08-06 15:59:06 +01001963 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001964# ifdef FEAT_LINEBREAK
1965 && !in_linebreak
1966# endif
1967 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001968 --bcol; // still working on the previous char, e.g. Tab
1969
1970 // Check if any active property ends.
1971 for (pi = 0; pi < text_props_active; ++pi)
1972 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001973 int tpi = text_prop_idxs[pi];
1974 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001975
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001976 // An inline property ends when after the start column plus
1977 // length. An "above" property ends when used and n_extra
1978 // is zero.
1979 if ((tp->tp_col != MAXCOL
1980 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001981 {
1982 if (pi + 1 < text_props_active)
1983 mch_memmove(text_prop_idxs + pi,
1984 text_prop_idxs + pi + 1,
1985 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001986 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001987 --text_props_active;
1988 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001989# ifdef FEAT_LINEBREAK
1990 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001991 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001992 syntax_attr = 0;
1993# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001994 }
1995 }
1996
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001997# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001998 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001999 // not on the next char yet, don't start another prop
2000 --bcol;
2001# endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002002 int display_text_first = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002003
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002004 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002005 // With 'nowrap' and not in the first screen line only "below"
2006 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002007 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002008 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002009 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002010 && (wp->w_p_wrap
2011 || wlv.row == startrow
2012 || (text_props[text_prop_next].tp_flags
2013 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002014 || (bcol == 0
2015 && (text_props[text_prop_next].tp_flags
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002016 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002017 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002018 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01002019 if (text_props[text_prop_next].tp_col == MAXCOL
2020 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002021 + text_props[text_prop_next].tp_len)
2022 text_prop_idxs[text_props_active++] = text_prop_next;
2023 ++text_prop_next;
2024 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002025
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002026 if (wlv.n_extra == 0 || !wlv.extra_for_textprop)
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002027 {
2028 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002029 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002030 text_prop_flags = 0;
2031 text_prop_type = NULL;
2032 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002033 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002034 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002035 if (text_props_active > 0 && wlv.n_extra == 0
2036 && !display_text_first)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002037 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01002038 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002039 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002040 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002041
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002042 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002043 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002044
2045 // Sort the properties on priority and/or starting last.
2046 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002047 sort_text_props(wp->w_buffer, text_props,
2048 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002049
2050 for (pi = 0; pi < text_props_active; ++pi)
2051 {
2052 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002053 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002054 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002055 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002056
Bram Moolenaarcd105412022-10-10 19:50:42 +01002057 // Only use a text property that can be displayed.
2058 // Skip "after" properties when wrap is off and at the
2059 // end of the window.
2060 if (pt != NULL
2061 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2062 && tp->tp_id != -MAXCOL
2063 && !(tp->tp_id < 0
2064 && !wp->w_p_wrap
2065 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2066 | TP_FLAG_ALIGN_ABOVE
2067 | TP_FLAG_ALIGN_BELOW)) == 0
2068 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002069 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002070 if (tp->tp_col == MAXCOL
2071 && *ptr == NUL
2072 && ((wp->w_p_list && lcs_eol_one > 0
2073 && (tp->tp_flags
2074 & TP_FLAG_ALIGN_ABOVE) == 0)
2075 || (ptr == line
2076 && !did_line
2077 && (tp->tp_flags
2078 & TP_FLAG_ALIGN_BELOW))))
2079 {
2080 // skip this prop, first display the '$' after
2081 // the line or display an empty line
2082 text_prop_follows = TRUE;
2083 if (used_tpi < 0)
2084 display_text_first = TRUE;
2085 continue;
2086 }
2087
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002088 if (pt->pt_hl_id > 0)
2089 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002090 text_prop_type = pt;
2091 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002092 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002093 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2094 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002095 text_prop_flags = pt->pt_flags;
2096 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002097 used_tpi = tpi;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002098 display_text_first = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002099 }
2100 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002101 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002102 && -text_prop_id
2103 <= wp->w_buffer->b_textprop_text.ga_len)
2104 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002105 textprop_T *tp = &text_props[used_tpi];
2106 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002107 ->b_textprop_text.ga_data)[
2108 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002109 int above = (tp->tp_flags
2110 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002111 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002112
2113 // reset the ID in the copy to avoid it being used
2114 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002115 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002116
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002117 if (p != NULL)
2118 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002119 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002120 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002121 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002122 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002123 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
2124 int padding = tp->tp_col == MAXCOL
2125 && tp->tp_len > 1
2126 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002127
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002128 // Insert virtual text before the current
2129 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002130 wlv.p_extra = p;
2131 wlv.c_extra = NUL;
2132 wlv.c_final = NUL;
2133 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002134 wlv.extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002135 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2136 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002137 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002138 // restore search_attr and area_attr when n_extra
2139 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01002140 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002141 saved_area_attr = area_attr;
2142 search_attr = 0;
2143 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002144 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002145 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002146 if (*ptr == NUL)
2147 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002148 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002149#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002150 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002151 {
2152 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002153 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002154 wlv.need_showbreak = FALSE;
2155 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002156 }
2157#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002158 if ((right || above || below || !wrap
2159 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002160 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002161 char_u *prev_p_extra = wlv.p_extra;
2162 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002163
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002164 // Take care of padding, right-align and
2165 // truncation.
2166 // Shared with win_lbr_chartabsize(), must do
2167 // exactly the same.
2168 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002169 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002170 wlv.col,
2171 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002172 &n_attr, &wlv.n_attr_skip,
2173 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002174 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002175 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002176 // wlv.p_extra was allocated
2177 vim_free(p_extra_free2);
2178 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002179 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002180
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002181 if (above)
2182 wlv.vcol_off_tp = wlv.n_extra;
2183
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002184 if (lcs_eol_one < 0
2185 && wp->w_p_wrap
2186 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002187 + wlv.n_extra - 2 > wp->w_width)
2188 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002189 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002190
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002191 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002192 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002193 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002194 {
2195 draw_screen_line(wp, &wlv);
2196
2197 // When line got too long for screen break
2198 // here.
2199 if (wlv.row == endrow)
2200 {
2201 ++wlv.row;
2202 break;
2203 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002204 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002205 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002206 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002207 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002208 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002209
Bram Moolenaarcd105412022-10-10 19:50:42 +01002210 // If the text didn't reach until the first window
2211 // column we need to skip cells.
2212 if (skip_cells > 0)
2213 {
2214 if (wlv.n_extra > skip_cells)
2215 {
2216 wlv.n_extra -= skip_cells;
2217 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002218 wlv.n_attr_skip -= skip_cells;
2219 if (wlv.n_attr_skip < 0)
2220 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002221 skip_cells = 0;
2222 }
2223 else
2224 {
2225 // the whole text is left of the window, drop
2226 // it and advance to the next one
2227 skip_cells -= wlv.n_extra;
2228 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002229 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002230 bail_out = TRUE;
2231 }
2232 }
2233
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002234 // If another text prop follows the condition below at
2235 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002236 // If this is an "above" text prop and 'nowrap' the we
2237 // must wrap anyway.
2238 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002239 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002240 && (wp->w_p_wrap
2241 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002242 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002243
2244 if (bail_out)
2245 // starting a new line for "below"
2246 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002247 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002248 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002249 else if (text_prop_next < text_prop_count
2250 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002251 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2252 || (!wp->w_p_wrap
2253 && wlv.col == wp->w_width - 1
2254 && (text_props[text_prop_next].tp_flags
2255 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002256 // When at last-but-one character and a text property
2257 // follows after it, we may need to flush the line after
2258 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002259 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002260 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002261 }
2262#endif
2263
Bram Moolenaare38fc862022-08-11 17:24:50 +01002264#ifdef FEAT_SEARCH_EXTRA
2265 if (wlv.n_extra == 0)
2266 {
2267 // Check for start/end of 'hlsearch' and other matches.
2268 // After end, check for start/end of next match.
2269 // When another match, have to check for start again.
2270 v = (long)(ptr - line);
2271 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2272 &screen_search_hl, &has_match_conc,
2273 &match_conc, did_line_attr, lcs_eol_one,
2274 &on_last_col);
2275 ptr = line + v; // "line" may have been changed
2276 prev_ptr = ptr;
2277
2278 // Do not allow a conceal over EOL otherwise EOL will be missed
2279 // and bad things happen.
2280 if (*ptr == NUL)
2281 has_match_conc = 0;
2282 }
2283#endif
2284
2285#ifdef FEAT_DIFF
2286 if (wlv.diff_hlf != (hlf_T)0)
2287 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002288 // When there is extra text (e.g. virtual text) it gets the
2289 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002290 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2291 && wlv.n_extra == 0)
2292 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002293 if (wlv.diff_hlf == HLF_TXD
2294 && ((ptr - line > change_end && wlv.n_extra == 0)
2295 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002296 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002297 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002298 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2299 && wp->w_p_culopt_flags != CULOPT_NBR
2300 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2301 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002302 wlv.line_attr = hl_combine_attr(
2303 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002304 }
2305#endif
2306
Bram Moolenaara74fda62019-10-19 17:38:03 +02002307#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002308 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002309 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002310 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002311# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002312 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002313 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002314# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002315 // Get syntax attribute.
2316 if (has_syntax)
2317 {
2318 // Get the syntax attribute for the character. If there
2319 // is an error, disable syntax highlighting.
2320 save_did_emsg = did_emsg;
2321 did_emsg = FALSE;
2322
2323 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002324 if (v == prev_syntax_col)
2325 // at same column again
2326 syntax_attr = prev_syntax_attr;
2327 else
2328 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002329# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002330 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002331# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002332 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002333# ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01002334 spv->spv_has_spell ? &can_spell :
Bram Moolenaar34390282019-10-16 14:38:26 +02002335# endif
Luuk van Baal30805a12023-05-27 22:22:10 +01002336 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002337 prev_syntax_col = v;
2338 prev_syntax_attr = syntax_attr;
2339 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002340
Bram Moolenaar34390282019-10-16 14:38:26 +02002341 if (did_emsg)
2342 {
2343 wp->w_s->b_syn_error = TRUE;
2344 has_syntax = FALSE;
2345 syntax_attr = 0;
2346 }
2347 else
2348 did_emsg = save_did_emsg;
2349# ifdef SYN_TIME_LIMIT
2350 if (wp->w_s->b_syn_slow)
2351 has_syntax = FALSE;
2352# endif
2353
2354 // Need to get the line again, a multi-line regexp may
2355 // have made it invalid.
2356 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2357 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002358 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002359# ifdef FEAT_CONCEAL
2360 // no concealing past the end of the line, it interferes
2361 // with line highlighting
2362 if (*ptr == NUL)
2363 syntax_flags = 0;
2364 else
2365 syntax_flags = get_syntax_info(&syntax_seqnr);
2366# endif
2367 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002368 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002369# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002370 // Combine text property highlight into syntax highlight.
2371 if (text_prop_type != NULL)
2372 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002373 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002374 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2375 else
2376 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002377 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002378 }
2379# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002380#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002381
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002382 // Decide which of the highlight attributes to use.
2383 attr_pri = TRUE;
2384#ifdef LINE_ATTR
2385 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002386 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002387 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002388 if (!highlight_match)
2389 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002390 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002391# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002392 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002393# endif
2394 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002395 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002396 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002397 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002398# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002399 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002400# endif
2401 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002402 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002403 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2404 || wlv.vcol < wlv.fromcol
2405 || vcol_prev < fromcol_prev
2406 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002407 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002408 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002409 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002410# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002411 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002412# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002413 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002414# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002415 attr_pri = FALSE;
2416 }
2417#else
2418 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002419 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002420 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002421 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002422#endif
2423 else
2424 {
2425 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002426#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002427 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002428#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002429 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002430#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002431 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002432#ifdef FEAT_PROP_POPUP
2433 // override with text property highlight when "override" is TRUE
2434 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002435 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002436#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002437 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002438
2439 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002440 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002441 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002442 if (wlv.char_attr == 0)
2443 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002444 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002445 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002446 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002447
2448 // Get the next character to put on the screen.
2449
2450 // The "p_extra" points to the extra stuff that is inserted to
2451 // represent special characters (non-printable stuff) and other
2452 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002453 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002454 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2455 // "p_extra[n_extra]".
2456 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002457 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002458 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002459 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002460 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002461 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2462 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002463 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2464 if (enc_utf8 && utf_char2len(c) > 1)
2465 {
2466 mb_utf8 = TRUE;
2467 u8cc[0] = 0;
2468 c = 0xc0;
2469 }
2470 else
2471 mb_utf8 = FALSE;
2472 }
2473 else
2474 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002475 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002476 if (has_mbyte)
2477 {
2478 mb_c = c;
2479 if (enc_utf8)
2480 {
2481 // If the UTF-8 character is more than one byte:
2482 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002483 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002484 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002485 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002486 mb_l = 1;
2487 else if (mb_l > 1)
2488 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002489 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002490 mb_utf8 = TRUE;
2491 c = 0xc0;
2492 }
2493 }
2494 else
2495 {
2496 // if this is a DBCS character, put it in "mb_c"
2497 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002498 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002499 mb_l = 1;
2500 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002501 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002502 }
2503 if (mb_l == 0) // at the NUL at end-of-line
2504 mb_l = 1;
2505
2506 // If a double-width char doesn't fit display a '>' in the
2507 // last column.
2508 if ((
2509# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002510 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002511# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002512 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002513 && (*mb_char2cells)(mb_c) == 2)
2514 {
2515 c = '>';
2516 mb_c = c;
2517 mb_l = 1;
2518 mb_utf8 = FALSE;
2519 multi_attr = HL_ATTR(HLF_AT);
2520#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002521 if (wlv.cul_attr)
2522 multi_attr = hl_combine_attr(
2523 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002524#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002525 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002526
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002527 // put the pointer back to output the double-width
2528 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002529 ++wlv.n_extra;
2530 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002531 }
2532 else
2533 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002534 wlv.n_extra -= mb_l - 1;
2535 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002536 }
2537 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002538 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002539 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002540 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002541#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002542 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002543 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002544 // Only restore search_attr and area_attr after "n_extra" in
2545 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002546 if (wlv.saved_n_extra <= 0)
2547 {
2548 if (search_attr == 0)
2549 search_attr = saved_search_attr;
2550 if (area_attr == 0 && *ptr != NUL)
2551 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002552
2553 if (wlv.extra_for_textprop)
2554 // wlv.extra_attr should be used at this position but
2555 // not any further.
2556 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002557 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002558
2559 wlv.extra_for_textprop = FALSE;
2560 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002561 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002562#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002563 }
2564 else
2565 {
2566#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002567 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002568#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002569 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002570
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002571 // Get a character from the line itself.
2572 c = *ptr;
2573#ifdef FEAT_LINEBREAK
2574 c0 = *ptr;
2575#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002576#ifdef FEAT_PROP_POPUP
2577 if (c == NUL)
2578 // text is finished, may display a "below" virtual text
2579 did_line = TRUE;
2580#endif
2581
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002582 if (has_mbyte)
2583 {
2584 mb_c = c;
2585 if (enc_utf8)
2586 {
2587 // If the UTF-8 character is more than one byte: Decode it
2588 // into "mb_c".
2589 mb_l = utfc_ptr2len(ptr);
2590 mb_utf8 = FALSE;
2591 if (mb_l > 1)
2592 {
2593 mb_c = utfc_ptr2char(ptr, u8cc);
2594 // Overlong encoded ASCII or ASCII with composing char
2595 // is displayed normally, except a NUL.
2596 if (mb_c < 0x80)
2597 {
2598 c = mb_c;
2599#ifdef FEAT_LINEBREAK
2600 c0 = mb_c;
2601#endif
2602 }
2603 mb_utf8 = TRUE;
2604
2605 // At start of the line we can have a composing char.
2606 // Draw it as a space with a composing char.
2607 if (utf_iscomposing(mb_c))
2608 {
2609 int i;
2610
2611 for (i = Screen_mco - 1; i > 0; --i)
2612 u8cc[i] = u8cc[i - 1];
2613 u8cc[0] = mb_c;
2614 mb_c = ' ';
2615 }
2616 }
2617
2618 if ((mb_l == 1 && c >= 0x80)
2619 || (mb_l >= 1 && mb_c == 0)
2620 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2621 {
2622 // Illegal UTF-8 byte: display as <xx>.
2623 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002624 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002625# ifdef FEAT_RIGHTLEFT
2626 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002627 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002628# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002629 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002630 c = *wlv.p_extra;
2631 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002632 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002633 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2634 wlv.c_extra = NUL;
2635 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002636 if (area_attr == 0 && search_attr == 0)
2637 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002638 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002639 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002640 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002641 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002642 }
2643 }
2644 else if (mb_l == 0) // at the NUL at end-of-line
2645 mb_l = 1;
2646#ifdef FEAT_ARABIC
2647 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2648 {
2649 // Do Arabic shaping.
2650 int pc, pc1, nc;
2651 int pcc[MAX_MCO];
2652
2653 // The idea of what is the previous and next
2654 // character depends on 'rightleft'.
2655 if (wp->w_p_rl)
2656 {
2657 pc = prev_c;
2658 pc1 = prev_c1;
2659 nc = utf_ptr2char(ptr + mb_l);
2660 prev_c1 = u8cc[0];
2661 }
2662 else
2663 {
2664 pc = utfc_ptr2char(ptr + mb_l, pcc);
2665 nc = prev_c;
2666 pc1 = pcc[0];
2667 }
2668 prev_c = mb_c;
2669
2670 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2671 }
2672 else
2673 prev_c = mb_c;
2674#endif
2675 }
2676 else // enc_dbcs
2677 {
2678 mb_l = MB_BYTE2LEN(c);
2679 if (mb_l == 0) // at the NUL at end-of-line
2680 mb_l = 1;
2681 else if (mb_l > 1)
2682 {
2683 // We assume a second byte below 32 is illegal.
2684 // Hopefully this is OK for all double-byte encodings!
2685 if (ptr[1] >= 32)
2686 mb_c = (c << 8) + ptr[1];
2687 else
2688 {
2689 if (ptr[1] == NUL)
2690 {
2691 // head byte at end of line
2692 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002693 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002694 }
2695 else
2696 {
2697 // illegal tail byte
2698 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002699 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002700 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002701 wlv.p_extra = wlv.extra;
2702 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002703 wlv.c_extra = NUL;
2704 wlv.c_final = NUL;
2705 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002706 if (area_attr == 0 && search_attr == 0)
2707 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002708 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002709 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002710 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002711 // save current attr
2712 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002713 }
2714 mb_c = c;
2715 }
2716 }
2717 }
2718 // If a double-width char doesn't fit display a '>' in the
2719 // last column; the character is displayed at the start of the
2720 // next line.
2721 if ((
2722# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002723 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002724# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002725 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002726 && (*mb_char2cells)(mb_c) == 2)
2727 {
2728 c = '>';
2729 mb_c = c;
2730 mb_utf8 = FALSE;
2731 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002732 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002733 // Put pointer back so that the character will be
2734 // displayed at the start of the next line.
2735 --ptr;
2736#ifdef FEAT_CONCEAL
2737 did_decrement_ptr = TRUE;
2738#endif
2739 }
2740 else if (*ptr != NUL)
2741 ptr += mb_l - 1;
2742
2743 // If a double-width char doesn't fit at the left side display
2744 // a '<' in the first column. Don't do this for unprintable
2745 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002746 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002747 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002748 wlv.n_extra = 1;
2749 wlv.c_extra = MB_FILLER_CHAR;
2750 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002751 c = ' ';
2752 if (area_attr == 0 && search_attr == 0)
2753 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002754 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002755 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002756 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002757 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002758 }
2759 mb_c = c;
2760 mb_utf8 = FALSE;
2761 mb_l = 1;
2762 }
2763
2764 }
2765 ++ptr;
2766
2767 if (extra_check)
2768 {
2769#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002770 // Check spelling (unless at the end of the line).
2771 // Only do this when there is no syntax highlighting, the
2772 // @Spell cluster is not used or the current syntax item
2773 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002774 v = (long)(ptr - line);
Luuk van Baal30805a12023-05-27 22:22:10 +01002775 if (spv->spv_has_spell && v >= word_end && v > cur_checked_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002776 {
2777 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002778 // do not calculate cap_col at the end of the line or when
2779 // only white space is following
2780 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002781# ifdef FEAT_SYN_HL
2782 !has_syntax ||
2783# endif
2784 can_spell))
2785 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002786 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002787 int len;
2788 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002789
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002790 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002791 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002792
2793 // Use nextline[] if possible, it has the start of the
2794 // next line concatenated.
2795 if ((prev_ptr - line) - nextlinecol >= 0)
2796 p = nextline + (prev_ptr - line) - nextlinecol;
2797 else
2798 p = prev_ptr;
Luuk van Baal30805a12023-05-27 22:22:10 +01002799 spv->spv_cap_col -= (int)(prev_ptr - line);
2800 len = spell_check(wp, p, &spell_hlf, &spv->spv_cap_col,
2801 spv->spv_unchanged);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002802 word_end = v + len;
2803
2804 // In Insert mode only highlight a word that
2805 // doesn't touch the cursor.
2806 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002807 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002808 && wp->w_cursor.lnum == lnum
2809 && wp->w_cursor.col >=
2810 (colnr_T)(prev_ptr - line)
2811 && wp->w_cursor.col < (colnr_T)word_end)
2812 {
2813 spell_hlf = HLF_COUNT;
2814 spell_redraw_lnum = lnum;
2815 }
2816
2817 if (spell_hlf == HLF_COUNT && p != prev_ptr
2818 && (p - nextline) + len > nextline_idx)
2819 {
2820 // Remember that the good word continues at the
2821 // start of the next line.
Luuk van Baal30805a12023-05-27 22:22:10 +01002822 spv->spv_checked_lnum = lnum + 1;
2823 spv->spv_checked_col = (p - nextline) + len
2824 - nextline_idx;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002825 }
2826
2827 // Turn index into actual attributes.
2828 if (spell_hlf != HLF_COUNT)
2829 spell_attr = highlight_attr[spell_hlf];
2830
Luuk van Baal30805a12023-05-27 22:22:10 +01002831 if (spv->spv_cap_col > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002832 {
2833 if (p != prev_ptr
Luuk van Baal30805a12023-05-27 22:22:10 +01002834 && (p - nextline) + spv->spv_cap_col
2835 >= nextline_idx)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002836 {
2837 // Remember that the word in the next line
2838 // must start with a capital.
Luuk van Baal30805a12023-05-27 22:22:10 +01002839 spv->spv_capcol_lnum = lnum + 1;
2840 spv->spv_cap_col = ((p - nextline)
2841 + spv->spv_cap_col - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002842 }
2843 else
2844 // Compute the actual column.
Luuk van Baal30805a12023-05-27 22:22:10 +01002845 spv->spv_cap_col += (prev_ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002846 }
2847 }
2848 }
2849 if (spell_attr != 0)
2850 {
2851 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002852 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2853 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002854 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002855 wlv.char_attr = hl_combine_attr(spell_attr,
2856 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002857 }
2858#endif
2859#ifdef FEAT_LINEBREAK
2860 // Found last space before word: check for line break.
2861 if (wp->w_p_lbr && c0 == c
2862 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2863 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002864 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2865 : 0;
2866 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002867 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002868
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002869 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002870# ifdef FEAT_PROP_POPUP
2871 // do not want virtual text counted here
2872 cts.cts_has_prop_with_text = FALSE;
2873# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002874 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002875 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002876
2877 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002878 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002879 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002880 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002881 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2882 if (wlv.n_extra < 0)
2883 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002884 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002885 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002886 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002887 // line break, but for TABs the highlighting should
2888 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002889 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002890
Bram Moolenaar1306b362022-08-06 15:59:06 +01002891 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002892# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002893 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002894 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002895 wp->w_buffer->b_p_vts_array) - 1;
2896# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002897 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002898 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002899# endif
2900
Bram Moolenaar1306b362022-08-06 15:59:06 +01002901 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2902 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002903# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002904 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002905 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002906# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002907 if (VIM_ISWHITE(c))
2908 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002909# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002910 if (c == TAB)
2911 // See "Tab alignment" below.
2912 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002913# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002914 if (!wp->w_p_list)
2915 c = ' ';
2916 }
2917 }
2918#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002919 in_multispace = c == ' '
2920 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2921 if (!in_multispace)
2922 multispace_pos = 0;
2923
Bram Moolenaareed9d462021-02-15 20:38:25 +01002924 // 'list': Change char 160 to 'nbsp' and space to 'space'
2925 // setting in 'listchars'. But not when the character is
2926 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002927 if (wp->w_p_list
2928 && ((((c == 160 && mb_l == 1)
2929 || (mb_utf8
2930 && ((mb_c == 160 && mb_l == 2)
2931 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002932 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002933 || (c == ' '
2934 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002935 && (wp->w_lcs_chars.space
2936 || (in_multispace
2937 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002938 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002939 && ptr - line <= trailcol)))
2940 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002941 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2942 {
2943 c = wp->w_lcs_chars.multispace[multispace_pos++];
2944 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2945 multispace_pos = 0;
2946 }
2947 else
2948 c = (c == ' ') ? wp->w_lcs_chars.space
2949 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002950 if (area_attr == 0 && search_attr == 0)
2951 {
2952 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002953 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002954 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002955 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002956 }
2957 mb_c = c;
2958 if (enc_utf8 && utf_char2len(c) > 1)
2959 {
2960 mb_utf8 = TRUE;
2961 u8cc[0] = 0;
2962 c = 0xc0;
2963 }
2964 else
2965 mb_utf8 = FALSE;
2966 }
2967
zeertzjq2e7cba32022-06-10 15:30:32 +01002968 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2969 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002970 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002971 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2972 && wp->w_lcs_chars.leadmultispace != NULL)
2973 {
2974 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002975 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2976 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002977 multispace_pos = 0;
2978 }
2979
2980 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2981 c = wp->w_lcs_chars.trail;
2982
2983 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2984 c = wp->w_lcs_chars.lead;
2985
zeertzjq2e7cba32022-06-10 15:30:32 +01002986 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002987 c = wp->w_lcs_chars.space;
2988
2989
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002990 if (!attr_pri)
2991 {
2992 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002993 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002994 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002995 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002996 }
2997 mb_c = c;
2998 if (enc_utf8 && utf_char2len(c) > 1)
2999 {
3000 mb_utf8 = TRUE;
3001 u8cc[0] = 0;
3002 c = 0xc0;
3003 }
3004 else
3005 mb_utf8 = FALSE;
3006 }
3007 }
3008
3009 // Handling of non-printable characters.
3010 if (!vim_isprintc(c))
3011 {
3012 // when getting a character from the file, we may have to
3013 // turn it into something else on the way to putting it
3014 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01003015 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003016 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003017 int tab_len = 0;
3018 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003019#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003020 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01003021
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003022 // only adjust the tab_len, when at the first column
3023 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01003024 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003025 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003026#endif
3027 // tab amount depends on current column
3028#ifdef FEAT_VARTABS
3029 tab_len = tabstop_padding(vcol_adjusted,
3030 wp->w_buffer->b_p_ts,
3031 wp->w_buffer->b_p_vts_array) - 1;
3032#else
3033 tab_len = (int)wp->w_buffer->b_p_ts
3034 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
3035#endif
3036
3037#ifdef FEAT_LINEBREAK
3038 if (!wp->w_p_lbr || !wp->w_p_list)
3039#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003040 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003041 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01003042 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003043 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003044#ifdef FEAT_LINEBREAK
3045 else
3046 {
3047 char_u *p;
3048 int len;
3049 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003050 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003051
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003052# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003053 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003054 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003055 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003056
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003057 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003058 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003059 && old_boguscols > 0
3060 && wlv.n_extra > tab_len)
3061 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003062# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003063 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003064 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003065 // If wlv.n_extra > 0, it gives the number of chars
3066 // to use for a tab, else we need to calculate the
3067 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003068 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3069 len = tab_len * tab2_len;
3070 if (wp->w_lcs_chars.tab3)
3071 len += mb_char2len(wp->w_lcs_chars.tab3)
3072 - tab2_len;
3073 if (wlv.n_extra > 0)
3074 len += wlv.n_extra - tab_len;
3075 c = wp->w_lcs_chars.tab1;
3076 p = alloc(len + 1);
3077 if (p == NULL)
3078 wlv.n_extra = 0;
3079 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003080 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003081 vim_memset(p, ' ', len);
3082 p[len] = NUL;
3083 vim_free(wlv.p_extra_free);
3084 wlv.p_extra_free = p;
3085 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003086 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003087 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003088
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003089 if (*p == NUL)
3090 {
3091 tab_len = i;
3092 break;
3093 }
3094
3095 // if tab3 is given, use it for the last
3096 // char
3097 if (wp->w_lcs_chars.tab3
3098 && i == tab_len - 1)
3099 lcs = wp->w_lcs_chars.tab3;
3100 p += mb_char2bytes(lcs, p);
3101 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003102 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003103 }
3104 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003105# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003106 // n_extra will be increased by
3107 // FIX_FOX_BOGUSCOLS macro below, so need to
3108 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003109 if (wlv.vcol_off_co > 0)
3110 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003111# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003112 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003113 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003114 }
3115#endif
3116#ifdef FEAT_CONCEAL
3117 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003118 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003119
3120 // Tab alignment should be identical regardless of
3121 // 'conceallevel' value. So tab compensates of all
3122 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003123 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003124 // line. Note that the tab can be longer than
3125 // 'tabstop' when there are concealed characters.
3126 FIX_FOR_BOGUSCOLS;
3127
3128 // Make sure, the highlighting for the tab char will be
3129 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003130 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003131 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003132 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003133 tab_len += vc_saved;
3134 }
3135#endif
3136 mb_utf8 = FALSE; // don't draw as UTF-8
3137 if (wp->w_p_list)
3138 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003139 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003140 ? wp->w_lcs_chars.tab3
3141 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003142#ifdef FEAT_LINEBREAK
h-east194555c2023-03-02 18:49:09 +00003143 if (wp->w_p_lbr && wlv.p_extra != NULL
3144 && *wlv.p_extra != NUL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003145 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003146 else
3147#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003148 wlv.c_extra = wp->w_lcs_chars.tab2;
3149 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003150 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003151 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003152 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003153 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003154 mb_c = c;
3155 if (enc_utf8 && utf_char2len(c) > 1)
3156 {
3157 mb_utf8 = TRUE;
3158 u8cc[0] = 0;
3159 c = 0xc0;
3160 }
3161 }
3162 else
3163 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003164 wlv.c_final = NUL;
3165 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003166 c = ' ';
3167 }
3168 }
3169 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003170 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003171 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003172 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3173 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003174 && VIsual_mode != Ctrl_V
3175 && (
3176# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003177 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003178# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003179 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003180 && !(noinvcur
3181 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003182 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003183 && lcs_eol_one > 0)
3184 {
3185 // Display a '$' after the line or highlight an extra
3186 // character if the line break is included.
3187#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3188 // For a diff line the highlighting continues after the
3189 // "$".
3190 if (
3191# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003192 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003193# ifdef LINE_ATTR
3194 &&
3195# endif
3196# endif
3197# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003198 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003199# endif
3200 )
3201#endif
3202 {
3203 // In virtualedit, visual selections may extend
3204 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003205 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003206 && wlv.tocol != MAXCOL
3207 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003208 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003209 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003210 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003211 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3212 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003213 else
3214 c = ' ';
3215 lcs_eol_one = -1;
3216 --ptr; // put it back at the NUL
3217 if (!attr_pri)
3218 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003219 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003220 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003221 n_attr = 1;
3222 }
3223 mb_c = c;
3224 if (enc_utf8 && utf_char2len(c) > 1)
3225 {
3226 mb_utf8 = TRUE;
3227 u8cc[0] = 0;
3228 c = 0xc0;
3229 }
3230 else
3231 mb_utf8 = FALSE; // don't draw as UTF-8
3232 }
3233 else if (c != NUL)
3234 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003235 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3236 if (wlv.n_extra == 0)
3237 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003238#ifdef FEAT_RIGHTLEFT
3239 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003240 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003241#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003242 wlv.c_extra = NUL;
3243 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003244#ifdef FEAT_LINEBREAK
3245 if (wp->w_p_lbr)
3246 {
3247 char_u *p;
3248
Bram Moolenaar1306b362022-08-06 15:59:06 +01003249 c = *wlv.p_extra;
3250 p = alloc(wlv.n_extra + 1);
3251 vim_memset(p, ' ', wlv.n_extra);
3252 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3253 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003254 vim_free(wlv.p_extra_free);
3255 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003256 }
3257 else
3258#endif
3259 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003260 wlv.n_extra = byte2cells(c) - 1;
3261 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003262 }
3263 if (!attr_pri)
3264 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003265 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003266 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003267 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003268 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003269 }
3270 mb_utf8 = FALSE; // don't draw as UTF-8
3271 }
3272 else if (VIsual_active
3273 && (VIsual_mode == Ctrl_V
3274 || VIsual_mode == 'v')
3275 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003276 && wlv.tocol != MAXCOL
3277 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003278 && (
3279#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003280 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003281#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003282 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003283 {
3284 c = ' ';
3285 --ptr; // put it back at the NUL
3286 }
3287#if defined(LINE_ATTR)
3288 else if ((
3289# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003290 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003291# endif
3292# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003293 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003294# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003295 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003296 ) && (
3297# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003298 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003299# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003300 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003301# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003302 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003303# endif
3304 < wp->w_width)))
3305 {
3306 // Highlight until the right side of the window
3307 c = ' ';
3308 --ptr; // put it back at the NUL
3309
3310 // Remember we do the char for line highlighting.
3311 ++did_line_attr;
3312
3313 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003314 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003315 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003316 || (wp->w_p_list &&
3317 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003318 wlv.char_attr = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003319# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003320 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003321 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003322 wlv.diff_hlf = HLF_CHD;
3323 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003324 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003325 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003326 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3327 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003328 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003329 || (wlv.vcol >= left_curline_col
3330 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003331 wlv.char_attr = hl_combine_attr(
3332 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003333 }
3334 }
3335# endif
3336# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003337 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003338 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003339 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003340 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3341 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003342 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003343 if (!wlv.cul_screenline
3344 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003345 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003346 wlv.char_attr = hl_combine_attr(
3347 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003348 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003349 else if (wlv.line_attr)
3350 wlv.char_attr = hl_combine_attr(
3351 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003352 }
3353# endif
3354 }
3355#endif
3356 }
3357
3358#ifdef FEAT_CONCEAL
3359 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003360 && (wp != curwin || lnum != wp->w_cursor.lnum
3361 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003362 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3363 && !(lnum_in_visual_area
3364 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3365 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003366 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003367 if (((prev_syntax_id != syntax_seqnr
3368 && (syntax_flags & HL_CONCEAL) != 0)
3369 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003370 && (syn_get_sub_char() != NUL
3371 || (has_match_conc && match_conc)
3372 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003373 && wp->w_p_cole != 3)
3374 {
3375 // First time at this concealed item: display one
3376 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003377 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003378 c = match_conc;
3379 else if (syn_get_sub_char() != NUL)
3380 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003381 else if (wp->w_lcs_chars.conceal != NUL)
3382 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003383 else
3384 c = ' ';
3385
3386 prev_syntax_id = syntax_seqnr;
3387
Bram Moolenaar1306b362022-08-06 15:59:06 +01003388 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003389 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003390 wlv.vcol += wlv.n_extra;
3391 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003392 {
3393# ifdef FEAT_RIGHTLEFT
3394 if (wp->w_p_rl)
3395 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003396 wlv.col -= wlv.n_extra;
3397 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003398 }
3399 else
3400# endif
3401 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003402 wlv.boguscols += wlv.n_extra;
3403 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003404 }
3405 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003406 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003407 n_attr = 0;
3408 }
3409 else if (n_skip == 0)
3410 {
3411 is_concealing = TRUE;
3412 n_skip = 1;
3413 }
3414 mb_c = c;
3415 if (enc_utf8 && utf_char2len(c) > 1)
3416 {
3417 mb_utf8 = TRUE;
3418 u8cc[0] = 0;
3419 c = 0xc0;
3420 }
3421 else
3422 mb_utf8 = FALSE; // don't draw as UTF-8
3423 }
3424 else
3425 {
3426 prev_syntax_id = 0;
3427 is_concealing = FALSE;
3428 }
3429
3430 if (n_skip > 0 && did_decrement_ptr)
3431 // not showing the '>', put pointer back to avoid getting stuck
3432 ++ptr;
3433
3434#endif // FEAT_CONCEAL
3435 }
3436
3437#ifdef FEAT_CONCEAL
3438 // In the cursor line and we may be concealing characters: correct
3439 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003440 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003441 && wp == curwin && lnum == wp->w_cursor.lnum
3442 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003443 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003444 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003445# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003446 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003447 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003448 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003449# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003450 wp->w_wcol = wlv.col - wlv.boguscols;
3451 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003452 did_wcol = TRUE;
3453 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003454# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003455 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003456# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003457 }
3458#endif
3459
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003460 // Use "wlv.extra_attr", but don't override visual selection
3461 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003462 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3463 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003464 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003465 && (!attr_pri
3466#ifdef FEAT_PROP_POPUP
3467 || (text_prop_flags & PT_FLAG_OVERRIDE)
3468#endif
3469 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003470 {
3471#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003472 if (wlv.line_attr)
3473 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003474 else
3475#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003476 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003477#ifdef FEAT_PROP_POPUP
3478 if (reset_extra_attr)
3479 {
3480 reset_extra_attr = FALSE;
3481 wlv.extra_attr = 0;
3482 }
3483#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003484 }
3485
3486#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3487 // XIM don't send preedit_start and preedit_end, but they send
3488 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3489 // im_is_preediting() here.
3490 if (p_imst == IM_ON_THE_SPOT
3491 && xic != NULL
3492 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003493 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003494 && !p_imdisable
3495 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003496 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003497 {
3498 colnr_T tcol;
3499
3500 if (preedit_end_col == MAXCOL)
3501 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3502 else
3503 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003504 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003505 {
3506 if (feedback_old_attr < 0)
3507 {
3508 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003509 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003510 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003511 wlv.char_attr = im_get_feedback_attr(feedback_col);
3512 if (wlv.char_attr < 0)
3513 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003514 feedback_col++;
3515 }
3516 else if (feedback_old_attr >= 0)
3517 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003518 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003519 feedback_old_attr = -1;
3520 feedback_col = 0;
3521 }
3522 }
3523#endif
3524 // Handle the case where we are in column 0 but not on the first
3525 // character of the line and the user wants us to show us a
3526 // special character (via 'listchars' option "precedes:<char>".
3527 if (lcs_prec_todo != NUL
3528 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003529 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3530 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003531#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003532 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003533#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003534 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003535 && c != NUL)
3536 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003537 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003538 lcs_prec_todo = NUL;
3539 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3540 {
3541 // Double-width character being overwritten by the "precedes"
3542 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003543 wlv.c_extra = MB_FILLER_CHAR;
3544 wlv.c_final = NUL;
3545 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003546 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003547 wlv.extra_attr =
3548 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003549 }
3550 mb_c = c;
3551 if (enc_utf8 && utf_char2len(c) > 1)
3552 {
3553 mb_utf8 = TRUE;
3554 u8cc[0] = 0;
3555 c = 0xc0;
3556 }
3557 else
3558 mb_utf8 = FALSE; // don't draw as UTF-8
3559 if (!attr_pri)
3560 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003561 saved_attr3 = wlv.char_attr; // save current attr
3562 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003563 n_attr3 = 1;
3564 }
3565 }
3566
3567 // At end of the text line or just after the last character.
3568 if ((c == NUL
3569#if defined(LINE_ATTR)
3570 || did_line_attr == 1
3571#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003572 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003573 {
3574#ifdef FEAT_SEARCH_EXTRA
3575 // flag to indicate whether prevcol equals startcol of search_hl or
3576 // one of the matches
3577 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3578 (long)(ptr - line) - (c == NUL));
3579#endif
3580 // Invert at least one char, used for Visual and empty line or
3581 // highlight match at end of line. If it's beyond the last
3582 // char on the screen, just overwrite that one (tricky!) Not
3583 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003584 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003585 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003586 && (VIsual_mode != Ctrl_V
3587 || lnum == VIsual.lnum
3588 || lnum == curwin->w_cursor.lnum)
3589 && c == NUL)
3590#ifdef FEAT_SEARCH_EXTRA
3591 // highlight 'hlsearch' match at end of line
3592 || (prevcol_hl_flag
3593# ifdef FEAT_SYN_HL
3594 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3595 && !(wp == curwin && VIsual_active))
3596# endif
3597# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003598 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003599# endif
3600# if defined(LINE_ATTR)
3601 && did_line_attr <= 1
3602# endif
3603 )
3604#endif
3605 ))
3606 {
3607 int n = 0;
3608
3609#ifdef FEAT_RIGHTLEFT
3610 if (wp->w_p_rl)
3611 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003612 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003613 n = 1;
3614 }
3615 else
3616#endif
3617 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003618 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003619 n = -1;
3620 }
3621 if (n != 0)
3622 {
3623 // At the window boundary, highlight the last character
3624 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003625 wlv.off += n;
3626 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003627 }
3628 else
3629 {
3630 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003631 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003632 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003633 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003634 }
3635#ifdef FEAT_SEARCH_EXTRA
3636 if (area_attr == 0)
3637 {
3638 // Use attributes from match with highest priority among
3639 // 'search_hl' and the match list.
3640 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003641 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003642 }
3643#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003644 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003645 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003646#ifdef FEAT_RIGHTLEFT
3647 if (wp->w_p_rl)
3648 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003649 --wlv.col;
3650 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003651 }
3652 else
3653#endif
3654 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003655 ++wlv.col;
3656 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003657 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003658 ++wlv.vcol;
3659 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003660 }
3661 }
3662
3663 // At end of the text line.
3664 if (c == NUL)
3665 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003666#ifdef FEAT_PROP_POPUP
3667 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003668 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003669 // Put the pointer back to the NUL.
3670 --ptr;
3671 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003672 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003673 else
3674#endif
3675 {
3676 draw_screen_line(wp, &wlv);
3677
3678 // Update w_cline_height and w_cline_folded if the cursor line
3679 // was updated (saves a call to plines() later).
3680 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3681 {
3682 curwin->w_cline_row = startrow;
3683 curwin->w_cline_height = wlv.row - startrow;
3684#ifdef FEAT_FOLDING
3685 curwin->w_cline_folded = FALSE;
3686#endif
3687 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3688 }
3689 break;
3690 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003691 }
3692
3693 // Show "extends" character from 'listchars' if beyond the line end and
3694 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003695 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003696 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003697 && wp->w_p_list
3698 && !wp->w_p_wrap
3699#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003700 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003701#endif
3702 && (
3703#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003704 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003705#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003706 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003707 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003708 || lcs_eol_one > 0
3709 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003710 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003711 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003712 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003713 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003714 mb_c = c;
3715 if (enc_utf8 && utf_char2len(c) > 1)
3716 {
3717 mb_utf8 = TRUE;
3718 u8cc[0] = 0;
3719 c = 0xc0;
3720 }
3721 else
3722 mb_utf8 = FALSE;
3723 }
3724
3725#ifdef FEAT_SYN_HL
3726 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003727 if (wlv.draw_color_col)
3728 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003729
3730 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3731 // highlight the cursor position itself.
3732 // Also highlight the 'colorcolumn' if it is different than
3733 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003734 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3735 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003736 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003737 if (((wlv.draw_state == WL_LINE
3738 || wlv.draw_state == WL_BRI
3739 || wlv.draw_state == WL_SBR)
3740 && !lnum_in_visual_area
3741 && search_attr == 0
3742 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003743# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003744 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003745# endif
3746 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003747 {
3748 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3749 && lnum != wp->w_cursor.lnum)
3750 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003751 vcol_save_attr = wlv.char_attr;
3752 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3753 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003754 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003755 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003756 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003757 vcol_save_attr = wlv.char_attr;
3758 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003759 }
3760 }
3761#endif
3762
3763 // Store character to be displayed.
3764 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003765 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003766 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003767 {
3768 // Store the character.
3769#if defined(FEAT_RIGHTLEFT)
3770 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3771 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003772 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003773 --wlv.off;
3774 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003775 }
3776#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003777 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003778 if (enc_dbcs == DBCS_JPNU)
3779 {
3780 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003781 ScreenLines[wlv.off] = 0x8e;
3782 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003783 }
3784 else if (enc_utf8)
3785 {
3786 if (mb_utf8)
3787 {
3788 int i;
3789
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003790 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003791 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003792 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003793 for (i = 0; i < Screen_mco; ++i)
3794 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003795 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003796 if (u8cc[i] == 0)
3797 break;
3798 }
3799 }
3800 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003801 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003802 }
3803 if (multi_attr)
3804 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003805 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003806 multi_attr = 0;
3807 }
3808 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003809 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003810
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003811 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003812
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003813 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3814 {
3815 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003816 ++wlv.off;
3817 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003818 if (enc_utf8)
3819 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003820 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003821 else
3822 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003823 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003824 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003825#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003826 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003827#endif
3828 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003829 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003830 // When "wlv.tocol" is halfway a character, set it to the end
3831 // of the character, otherwise highlighting won't stop.
3832 if (wlv.tocol == wlv.vcol)
3833 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003834
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003835 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003836
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003837#ifdef FEAT_RIGHTLEFT
3838 if (wp->w_p_rl)
3839 {
3840 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003841 --wlv.off;
3842 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003843 }
3844#endif
3845 }
3846#ifdef FEAT_RIGHTLEFT
3847 if (wp->w_p_rl)
3848 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003849 --wlv.off;
3850 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003851 }
3852 else
3853#endif
3854 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003855 ++wlv.off;
3856 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003857 }
3858 }
3859#ifdef FEAT_CONCEAL
3860 else if (wp->w_p_cole > 0 && is_concealing)
3861 {
3862 --n_skip;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003863 ++wlv.vcol_off_co;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003864 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003865 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003866 if (wp->w_p_wrap)
3867 {
3868 // Special voodoo required if 'wrap' is on.
3869 //
3870 // Advance the column indicator to force the line
3871 // drawing to wrap early. This will make the line
3872 // take up the same screen space when parts are concealed,
3873 // so that cursor line computations aren't messed up.
3874 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003875 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003876 // trailing junk to be written out of the screen line
3877 // we are building, 'boguscols' keeps track of the number
3878 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003879 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003880 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003881 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003882# ifdef FEAT_RIGHTLEFT
3883 if (wp->w_p_rl)
3884 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003885 wlv.col -= wlv.n_extra;
3886 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003887 }
3888 else
3889# endif
3890 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003891 wlv.col += wlv.n_extra;
3892 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003893 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003894 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003895 n_attr = 0;
3896 }
3897
3898
3899 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3900 {
3901 // Need to fill two screen columns.
3902# ifdef FEAT_RIGHTLEFT
3903 if (wp->w_p_rl)
3904 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003905 --wlv.boguscols;
3906 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003907 }
3908 else
3909# endif
3910 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003911 ++wlv.boguscols;
3912 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003913 }
3914 }
3915
3916# ifdef FEAT_RIGHTLEFT
3917 if (wp->w_p_rl)
3918 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003919 --wlv.boguscols;
3920 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003921 }
3922 else
3923# endif
3924 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003925 ++wlv.boguscols;
3926 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003927 }
3928 }
3929 else
3930 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003931 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003932 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003933 wlv.vcol += wlv.n_extra;
3934 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003935 n_attr = 0;
3936 }
3937 }
3938
3939 }
3940#endif // FEAT_CONCEAL
3941 else
3942 --n_skip;
3943
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003944 // Only advance the "wlv.vcol" when after the 'number' or
3945 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003946 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003947#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003948 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003949#endif
3950 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003951 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003952
3953#ifdef FEAT_SYN_HL
3954 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003955 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003956#endif
3957
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003958 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003959 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3960 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003961
3962 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003963 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003964 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003965 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003966 if (wlv.n_attr_skip > 0)
3967 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003968
3969 // At end of screen line and there is more to come: Display the line
3970 // so far. If there is no more to display it is caught above.
3971 if ((
3972#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003973 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003974#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003975 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003976 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003977 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003978#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003979 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003980#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003981#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003982 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003983#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003984 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003985 && wlv.p_extra != at_end_str)
3986 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3987 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003988 )
3989 {
3990#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003991 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003992 wlv_screen_line(wp, &wlv, FALSE);
3993 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003994 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003995 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003996#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003997 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003998#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003999 ++wlv.row;
4000 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004001
4002 // When not wrapping and finished diff lines, or when displayed
4003 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01004004 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004005#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004006 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004007#endif
4008#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01004009 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004010#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01004011 ) || lcs_eol_one == -1)
4012#ifdef FEAT_PROP_POPUP
4013 && !text_prop_follows
4014#endif
4015 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004016 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004017#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004018 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004019 {
4020 // do not output more of the line, only the "below" prop
4021 ptr += STRLEN(ptr);
4022# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004023 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004024# endif
4025 }
4026#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004027
4028 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004029 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004030#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004031 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004032#endif
4033 )
4034 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004035 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
4036 draw_vsep_win(wp, wlv.row);
4037 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004038 }
4039
4040 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004041 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004042 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004043 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004044 break;
4045 }
4046
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004047 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004048#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004049 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004050#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004051#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004052 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004053#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004054 && wp->w_width == Columns)
4055 {
4056 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004057 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004058
4059 // Special trick to make copy/paste of wrapped lines work with
4060 // xterm/screen: write an extra character beyond the end of
4061 // the line. This will work with all terminal types
4062 // (regardless of the xn,am settings).
4063 // Only do this on a fast tty.
4064 // Only do this if the cursor is on the current line
4065 // (something has been written in it).
4066 // Don't do this for the GUI.
4067 // Don't do this for double-width characters.
4068 // Don't do this for a window not at the right screen border.
4069 if (p_tf
4070#ifdef FEAT_GUI
4071 && !gui.in_use
4072#endif
4073 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004074 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4075 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004076 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004077 || (*mb_off2cells)(
4078 LineOffset[wlv.screen_row - 1]
4079 + (int)Columns - 2,
4080 LineOffset[wlv.screen_row]
4081 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004082 {
4083 // First make sure we are at the end of the screen line,
4084 // then output the same character again to let the
4085 // terminal know about the wrap. If the terminal doesn't
4086 // auto-wrap, we overwrite the character.
4087 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004088 screen_char(LineOffset[wlv.screen_row - 1]
4089 + (unsigned)Columns - 1,
4090 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004091
4092 // When there is a multi-byte character, just output a
4093 // space to keep it simple.
4094 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004095 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004096 out_char(' ');
4097 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004098 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004099 + (Columns - 1)]);
4100 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004101 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004102 screen_start(); // don't know where cursor is now
4103 }
4104 }
4105
Bram Moolenaar1306b362022-08-06 15:59:06 +01004106 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004107
Bram Moolenaareed9d462021-02-15 20:38:25 +01004108 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004109#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004110 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004111# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004112 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004113# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004114 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004115 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004116#endif
4117#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004118 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004119 // When the filler lines are actually below the last line of the
4120 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004121 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004122 break;
4123#endif
4124 }
4125
4126 } // for every character in the line
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004127#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004128 vim_free(text_props);
4129 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004130 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004131#endif
4132
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004133 vim_free(wlv.p_extra_free);
zeertzjq58e1e012023-06-04 18:46:28 +01004134 vim_free(wlv.saved_p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004135 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004136}