blob: 99994d64c0c6158629c49b60b4395a3e584b3872 [file] [log] [blame]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * drawline.c: Functions for drawing window lines on the screen.
Bram Moolenaare89aeed2022-08-22 13:00:16 +010012 * This is the middle level, drawscreen.c is the higher level and screen.c the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020013 * lower level.
14 */
15
16#include "vim.h"
17
18#ifdef FEAT_SYN_HL
19/*
20 * Advance **color_cols and return TRUE when there are columns to draw.
21 */
22 static int
23advance_color_col(int vcol, int **color_cols)
24{
25 while (**color_cols >= 0 && vcol > **color_cols)
26 ++*color_cols;
27 return (**color_cols >= 0);
28}
29#endif
30
31#ifdef FEAT_SYN_HL
32/*
33 * Used when 'cursorlineopt' contains "screenline": compute the margins between
34 * which the highlighting is used.
35 */
36 static void
37margin_columns_win(win_T *wp, int *left_col, int *right_col)
38{
39 // cache previous calculations depending on w_virtcol
40 static int saved_w_virtcol;
41 static win_T *prev_wp;
42 static int prev_left_col;
43 static int prev_right_col;
44 static int prev_col_off;
45
46 int cur_col_off = win_col_off(wp);
47 int width1;
48 int width2;
49
50 if (saved_w_virtcol == wp->w_virtcol
51 && prev_wp == wp && prev_col_off == cur_col_off)
52 {
53 *right_col = prev_right_col;
54 *left_col = prev_left_col;
55 return;
56 }
57
58 width1 = wp->w_width - cur_col_off;
59 width2 = width1 + win_col_off2(wp);
60
61 *left_col = 0;
62 *right_col = width1;
63
64 if (wp->w_virtcol >= (colnr_T)width1)
65 *right_col = width1 + ((wp->w_virtcol - width1) / width2 + 1) * width2;
66 if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0)
67 *left_col = (wp->w_virtcol - width1) / width2 * width2 + width1;
68
69 // cache values
70 prev_left_col = *left_col;
71 prev_right_col = *right_col;
72 prev_wp = wp;
73 saved_w_virtcol = wp->w_virtcol;
74 prev_col_off = cur_col_off;
75}
76#endif
77
Bram Moolenaar45e4eea2022-12-01 18:38:02 +000078#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
79 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
80// using an attribute for the whole line
81# define LINE_ATTR
82#endif
83
Bram Moolenaar1306b362022-08-06 15:59:06 +010084// structure with variables passed between win_line() and other functions
85typedef struct {
86 int draw_state; // what to draw next
87
88 linenr_T lnum; // line number to be drawn
89
90 int startrow; // first row in the window to be drawn
91 int row; // row in the window, excl w_winrow
92 int screen_row; // row on the screen, incl w_winrow
93
94 long vcol; // virtual column, before wrapping
95 int col; // visual column on screen, after wrapping
96#ifdef FEAT_CONCEAL
97 int boguscols; // nonexistent columns added to "col" to force
98 // wrapping
Bram Moolenaarf53e0652023-02-19 14:16:02 +000099 int vcol_off_co; // offset for concealed characters
Bram Moolenaar1306b362022-08-06 15:59:06 +0100100#endif
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000101 int vcol_off_tp; // offset for virtual text
Bram Moolenaar1306b362022-08-06 15:59:06 +0100102#ifdef FEAT_SYN_HL
103 int draw_color_col; // highlight colorcolumn
104 int *color_cols; // pointer to according columns array
105#endif
106 int eol_hl_off; // 1 if highlighted char after EOL
107
108 unsigned off; // offset in ScreenLines/ScreenAttrs
109
110 int win_attr; // background for the whole window, except
111 // margins and "~" lines.
Bram Moolenaard7657e92022-09-20 18:59:30 +0100112 int wcr_attr; // attributes from 'wincolor'
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100113#ifdef FEAT_SYN_HL
114 int cul_attr; // set when 'cursorline' active
115#endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000116#ifdef LINE_ATTR
117 int line_attr; // for the whole line, includes 'cursorline'
118#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100119
120 int screen_line_flags; // flags for screen_line()
121
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100122 int fromcol; // start of inverting
123 int tocol; // end of inverting
124
125#ifdef FEAT_LINEBREAK
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100126 long vcol_sbr; // virtual column after showbreak
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100127 int need_showbreak; // overlong line, skipping first x chars
128 int dont_use_showbreak; // do not use 'showbreak'
129#endif
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100130#ifdef FEAT_PROP_POPUP
131 int text_prop_above_count;
132#endif
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100133
Bram Moolenaar1306b362022-08-06 15:59:06 +0100134 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
135 int cul_screenline;
136
137 int char_attr; // attributes for the next character
138
139 int n_extra; // number of extra bytes
140 char_u *p_extra; // string of extra chars, plus NUL, only used
141 // when c_extra and c_final are NUL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100142 char_u *p_extra_free; // p_extra buffer that needs to be freed
Bram Moolenaaree28c702022-11-17 14:56:00 +0000143 int extra_attr; // attributes for p_extra, should be combined
144 // with win_attr if needed
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000145 int n_attr_skip; // chars to skip before using extra_attr
Bram Moolenaar1306b362022-08-06 15:59:06 +0100146 int c_extra; // extra chars, all the same
147 int c_final; // final char, mandatory if set
zeertzjq6e940d92023-08-17 23:21:40 +0200148 int extra_for_textprop; // n_extra set for textprop
149 int start_extra_for_textprop; // extra_for_textprop was just set
Bram Moolenaar1306b362022-08-06 15:59:06 +0100150
151 // saved "extra" items for when draw_state becomes WL_LINE (again)
152 int saved_n_extra;
153 char_u *saved_p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +0100154 char_u *saved_p_extra_free;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000155 int saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000156 int saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000157 int saved_extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100158 int saved_c_extra;
159 int saved_c_final;
160 int saved_char_attr;
161
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100162 char_u extra[NUMBUFLEN + MB_MAXBYTES];
163 // "%ld " and 'fdc' must fit in here, as well
164 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100165
Bram Moolenaar1306b362022-08-06 15:59:06 +0100166#ifdef FEAT_DIFF
167 hlf_T diff_hlf; // type of diff highlighting
168#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100169 int filler_lines; // nr of filler lines to be drawn
170 int filler_todo; // nr of filler lines still to do + 1
171#ifdef FEAT_SIGNS
172 sign_attrs_T sattr;
173#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100174} winlinevars_T;
175
176// draw_state values for items that are drawn in sequence:
177#define WL_START 0 // nothing done yet, must be zero
Martin Tournoij7904fa42022-10-04 16:28:45 +0100178#define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar1306b362022-08-06 15:59:06 +0100179#ifdef FEAT_FOLDING
180# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
181#else
182# define WL_FOLD WL_CMDLINE
183#endif
184#ifdef FEAT_SIGNS
185# define WL_SIGN (WL_FOLD + 1) // column for signs
186#else
187# define WL_SIGN WL_FOLD // column for signs
188#endif
189#define WL_NR (WL_SIGN + 1) // line number
190#ifdef FEAT_LINEBREAK
191# define WL_BRI (WL_NR + 1) // 'breakindent'
192#else
193# define WL_BRI WL_NR
194#endif
195#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
196# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
197#else
198# define WL_SBR WL_BRI
199#endif
200#define WL_LINE (WL_SBR + 1) // text in the line
201
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100202#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200203/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000204 * Return TRUE if CursorLineSign highlight is to be used.
205 */
206 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100207use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000208{
209 return wp->w_p_cul
210 && lnum == wp->w_cursor.lnum
211 && (wp->w_p_culopt_flags & CULOPT_NBR);
212}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100213#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000214
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100215
216#ifdef FEAT_FOLDING
217/*
218 * Setup for drawing the 'foldcolumn', if there is one.
219 */
220 static void
221handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
222{
223 int fdc = compute_foldcolumn(wp, 0);
224
225 if (fdc <= 0)
226 return;
227
228 // Allocate a buffer, "wlv->extra[]" may already be in use.
229 vim_free(wlv->p_extra_free);
230 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
Yegappan Lakshmanan465de3a2022-12-26 12:50:04 +0000231 if (wlv->p_extra_free == NULL)
232 return;
233
234 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
zeertzjq58e1e012023-06-04 18:46:28 +0100235 wp, FALSE, wlv->lnum);
Yegappan Lakshmanan465de3a2022-12-26 12:50:04 +0000236 wlv->p_extra_free[wlv->n_extra] = NUL;
237 wlv->p_extra = wlv->p_extra_free;
238 wlv->c_extra = NUL;
239 wlv->c_final = NUL;
240 if (use_cursor_line_highlight(wp, wlv->lnum))
241 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
242 else
243 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100244}
245#endif
246
247#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000248/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100249 * Get information needed to display the sign in line "wlv->lnum" in window
250 * "wp".
251 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200252 * Otherwise the sign is going to be displayed in the sign column.
253 */
254 static void
255get_sign_display_info(
256 int nrcol,
257 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100258 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200259{
260 int text_sign;
261# ifdef FEAT_SIGN_ICONS
262 int icon_sign;
263# endif
264
265 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100266 wlv->c_extra = ' ';
267 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200268 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100269 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200270 else
271 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100272 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100273 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000274 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100275 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100276 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200277 }
278
Bram Moolenaar1306b362022-08-06 15:59:06 +0100279 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200280#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100281 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200282#endif
283 )
284 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100285 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200286# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100287 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200288 if (gui.in_use && icon_sign != 0)
289 {
290 // Use the image in this position.
291 if (nrcol)
292 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100293 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100294 sprintf((char *)wlv->extra, "%-*c ",
295 number_width(wp), SIGN_BYTE);
296 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100297 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200298 }
299 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100300 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200301# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100302 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
303 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200304 {
305 if (nrcol)
306 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100307 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100308 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200309 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100310 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100311 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200312 }
313 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100314 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200315 }
316# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100317 wlv->c_final = NUL;
318 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200319 }
320 else
321# endif
322 if (text_sign != 0)
323 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100324 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100325 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200326 {
327 if (nrcol)
328 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100329 int width = number_width(wp) - 2;
330 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200331
332 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100333 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100334 vim_snprintf((char *)wlv->extra + n,
335 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100336 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200337 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100338 wlv->c_extra = NUL;
339 wlv->c_final = NUL;
340 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200341 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000342
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100343 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100344 && wlv->sattr.sat_culhl > 0)
345 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000346 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100347 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200348 }
349 }
350}
351#endif
352
Bram Moolenaard7657e92022-09-20 18:59:30 +0100353/*
354 * Display the absolute or relative line number. After the first row fill with
355 * blanks when the 'n' flag isn't in 'cpo'.
356 */
357 static void
358handle_lnum_col(
359 win_T *wp,
360 winlinevars_T *wlv,
361 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100362 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100363{
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100364 int has_cpo_n = vim_strchr(p_cpo, CPO_NUMCOL) != NULL;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100365 int lnum_row = wlv->startrow + wlv->filler_lines
366#ifdef FEAT_PROP_POPUP
367 + wlv->text_prop_above_count
368#endif
369 ;
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100370
Bram Moolenaard7657e92022-09-20 18:59:30 +0100371 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100372 && (wlv->row <= lnum_row || !has_cpo_n)
Bram Moolenaar37251162022-10-06 20:48:00 +0100373 // there is no line number in a wrapped line when "n" is in
374 // 'cpoptions', but 'breakindent' assumes it anyway.
375 && !((has_cpo_n
376#ifdef FEAT_LINEBREAK
377 && !wp->w_p_bri
378#endif
379 ) && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100380 {
381#ifdef FEAT_SIGNS
382 // If 'signcolumn' is set to 'number' and a sign is present
383 // in 'lnum', then display the sign instead of the line
384 // number.
385 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
386 get_sign_display_info(TRUE, wp, wlv);
387 else
388#endif
389 {
390 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100391 // When there are text properties above the line put the line number
392 // below them.
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100393 if (wlv->row == lnum_row
zeertzjq88bb3e02023-05-02 20:52:59 +0100394 && (wp->w_skipcol == 0 || wlv->row > 0
Bram Moolenaareb4de622022-10-15 13:42:17 +0100395 || (wp->w_p_nu && wp->w_p_rnu)))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100396 {
397 long num;
398 char *fmt = "%*ld ";
399
400 if (wp->w_p_nu && !wp->w_p_rnu)
401 // 'number' + 'norelativenumber'
402 num = (long)wlv->lnum;
403 else
404 {
405 // 'relativenumber', don't use negative numbers
406 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
407 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
408 {
409 // 'number' + 'relativenumber'
410 num = wlv->lnum;
411 fmt = "%-*ld ";
412 }
413 }
414
415 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100416 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100417 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
418 ++wlv->p_extra)
419 *wlv->p_extra = '-';
420#ifdef FEAT_RIGHTLEFT
421 if (wp->w_p_rl) // reverse line numbers
422 {
423 char_u *p1, *p2;
424 int t;
425
426 // like rl_mirror(), but keep the space at the end
427 p2 = skipwhite(wlv->extra);
428 p2 = skiptowhite(p2) - 1;
429 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
430 {
431 t = *p1;
432 *p1 = *p2;
433 *p2 = t;
434 }
435 }
436#endif
437 wlv->p_extra = wlv->extra;
438 wlv->c_extra = NUL;
439 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100440 }
441 else
442 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100443 wlv->c_extra = ' ';
444 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100445 }
446 wlv->n_extra = number_width(wp) + 1;
447 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
448#ifdef FEAT_SYN_HL
449 // When 'cursorline' is set highlight the line number of
450 // the current line differently.
451 // When 'cursorlineopt' does not have "line" only
452 // highlight the line number itself.
453 // TODO: Can we use CursorLine instead of CursorLineNr
454 // when CursorLineNr isn't set?
455 if (wp->w_p_cul
456 && wlv->lnum == wp->w_cursor.lnum
457 && (wp->w_p_culopt_flags & CULOPT_NBR)
458 && (wlv->row == wlv->startrow + wlv->filler_lines
459 || (wlv->row > wlv->startrow + wlv->filler_lines
460 && (wp->w_p_culopt_flags & CULOPT_LINE))))
461 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
462#endif
463 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
464 && HL_ATTR(HLF_LNA) != 0)
465 // Use LineNrAbove
466 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
467 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
468 && HL_ATTR(HLF_LNB) != 0)
469 // Use LineNrBelow
470 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
471 }
472#ifdef FEAT_SIGNS
473 if (num_attr)
474 wlv->char_attr = num_attr;
475#endif
476 }
477}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100478
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100479#ifdef FEAT_LINEBREAK
480 static void
481handle_breakindent(win_T *wp, winlinevars_T *wlv)
482{
483 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100484 && *get_showbreak_value(wp) != NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100485 // draw indent after showbreak value
486 wlv->draw_state = WL_BRI;
487 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
488 // After the showbreak, draw the breakindent
489 wlv->draw_state = WL_BRI - 1;
490
491 // draw 'breakindent': indent wrapped text accordingly
492 if (wlv->draw_state == WL_BRI - 1)
493 {
494 wlv->draw_state = WL_BRI;
495 // if wlv->need_showbreak is set, breakindent also applies
496 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
497# ifdef FEAT_DIFF
498 && wlv->filler_lines == 0
499# endif
500# ifdef FEAT_PROP_POPUP
501 && !wlv->dont_use_showbreak
502# endif
503 )
504 {
505 wlv->char_attr = 0;
506# ifdef FEAT_DIFF
507 if (wlv->diff_hlf != (hlf_T)0)
508 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
509# endif
510 wlv->p_extra = NULL;
511 wlv->c_extra = ' ';
512 wlv->c_final = NUL;
513 wlv->n_extra = get_breakindent_win(wp,
514 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
515 if (wlv->row == wlv->startrow)
516 {
517 wlv->n_extra -= win_col_off2(wp);
518 if (wlv->n_extra < 0)
519 wlv->n_extra = 0;
520 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100521 if (wp->w_skipcol > 0 && wlv->startrow == 0
522 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100523 wlv->need_showbreak = FALSE;
524 // Correct end of highlighted area for 'breakindent',
525 // required when 'linebreak' is also set.
526 if (wlv->tocol == wlv->vcol)
527 wlv->tocol += wlv->n_extra;
528 }
529 }
530}
531#endif
532
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100533#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
534 static void
535handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
536{
537# ifdef FEAT_DIFF
538 if (wlv->filler_todo > 0)
539 {
540 // Draw "deleted" diff line(s).
541 if (char2cells(wp->w_fill_chars.diff) > 1)
542 {
543 wlv->c_extra = '-';
544 wlv->c_final = NUL;
545 }
546 else
547 {
548 wlv->c_extra = wp->w_fill_chars.diff;
549 wlv->c_final = NUL;
550 }
551# ifdef FEAT_RIGHTLEFT
552 if (wp->w_p_rl)
553 wlv->n_extra = wlv->col + 1;
554 else
555# endif
556 wlv->n_extra = wp->w_width - wlv->col;
557 wlv->char_attr = HL_ATTR(HLF_DED);
558 }
559# endif
560
561# ifdef FEAT_LINEBREAK
562 char_u *sbr = get_showbreak_value(wp);
563 if (*sbr != NUL && wlv->need_showbreak)
564 {
565 // Draw 'showbreak' at the start of each broken line.
566 wlv->p_extra = sbr;
567 wlv->c_extra = NUL;
568 wlv->c_final = NUL;
569 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100570 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100571 wlv->need_showbreak = FALSE;
572 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100573
574 // Correct start of highlighted area for 'showbreak'.
575 if (wlv->fromcol >= wlv->vcol && wlv->fromcol < wlv->vcol_sbr)
576 wlv->fromcol = wlv->vcol_sbr;
577
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100578 // Correct end of highlighted area for 'showbreak',
579 // required when 'linebreak' is also set.
580 if (wlv->tocol == wlv->vcol)
581 wlv->tocol += wlv->n_extra;
582 // combine 'showbreak' with 'wincolor'
583 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
584# ifdef FEAT_SYN_HL
585 // combine 'showbreak' with 'cursorline'
586 if (wlv->cul_attr != 0)
587 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
588# endif
589 }
590# endif
591}
592#endif
593
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100594#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100595/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100596 * Return the cell size of virtual text after truncation.
597 */
598 static int
599textprop_size_after_trunc(
600 win_T *wp,
601 int flags, // TP_FLAG_ALIGN_*
602 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100603 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100604 char_u *text,
605 int *n_used_ptr)
606{
607 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100608 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100609 int len = (int)STRLEN(text);
610 int strsize = 0;
611 int n_used;
612
Bram Moolenaar7e017462022-10-11 21:02:09 +0100613 // if the remaining size is to small and 'wrap' is set we wrap anyway and
614 // use the next line
615 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100616 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100617 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100618 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100619 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
620 {
621 int clen = ptr2cells(text + n_used);
622
623 if (strsize + clen > space)
624 break;
625 strsize += clen;
626 }
627 *n_used_ptr = n_used;
628 return strsize;
629}
630
631/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100632 * Take care of padding, right-align and truncation of virtual text after a
633 * line.
634 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
635 * padding, right-align and truncation. Otherwise only the size is computed.
636 * When "n_attr" is NULL returns the number of screen cells used.
637 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100638 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100639 int
640text_prop_position(
641 win_T *wp,
642 textprop_T *tp,
porygonisaduck38854b52022-11-27 20:55:05 +0000643 int vcol, // current text column
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100644 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100645 int *n_extra, // nr of bytes for virtual text
646 char_u **p_extra, // virtual text
647 int *n_attr, // attribute cells, NULL if not used
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000648 int *n_attr_skip, // cells to skip attr, NULL if not used
649 int do_skip) // skip_cells is not zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200650{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100651 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100652 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100653 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
Bram Moolenaar1aeb3eb2023-01-01 14:04:51 +0000654 int wrap = tp->tp_col < MAXCOL || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100655 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
porygonisaduck38854b52022-11-27 20:55:05 +0000656 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100657 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100658 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100659 int before = room; // spaces before the text
660 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100661 int n_used = *n_extra;
662 char_u *l = NULL;
663 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100664 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100665 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200666
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100667 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100668 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100669 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100670
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100671 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100672 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100673 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100674 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar2354b662023-04-23 21:42:25 +0100675 if (after < 0)
676 {
677 // text "above" has too much padding to fit
678 padding += after;
679 after = 0;
680 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100681 }
682 else
683 {
684 // Right-align: fill with before
685 if (right)
686 before -= cells;
porygonisaduck38854b52022-11-27 20:55:05 +0000687
688 // Below-align: empty line add one character
Bram Moolenaar7c02ad92022-11-29 21:37:13 +0000689 if (below && vcol == 0 && col_with_padding == col_off
690 && wp->w_width - col_off == before)
691 col_with_padding += 1;
porygonisaduck38854b52022-11-27 20:55:05 +0000692
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100693 if (before < 0
694 || !(right || below)
porygonisaduck38854b52022-11-27 20:55:05 +0000695 || (below ? (col_with_padding <= col_off || !wp->w_p_wrap)
696 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100697 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100698 if (right && (wrap
699 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100700 {
701 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100702 before = wp->w_width - col_off - strsize + room;
703 if (before < 0)
704 before = 0;
705 else
706 n_used = *n_extra;
707 }
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000708 else if (below && before > vcol && do_skip)
709 before -= vcol;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100710 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100711 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100712 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100713 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100714
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100715 // With 'nowrap' add one to show the "extends" character if needed (it
716 // doesn't show if the text just fits).
717 if (!wp->w_p_wrap
718 && n_used < *n_extra
719 && wp->w_lcs_chars.ext != NUL
720 && wp->w_p_list)
721 ++n_used;
722
723 // add 1 for NUL, 2 for when '…' is used
724 if (n_attr != NULL)
Christian Brabandtf1cc4d52023-08-12 00:14:14 +0200725 l = alloc(n_used + before + after + (padding > 0 ? padding : 0) + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100726 if (n_attr == NULL || l != NULL)
727 {
728 int off = 0;
729
730 if (n_attr != NULL)
731 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100732 vim_memset(l, ' ', before);
733 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100734 if (padding > 0)
735 {
736 vim_memset(l + off, ' ', padding);
737 off += padding;
738 }
739 vim_strncpy(l + off, *p_extra, n_used);
740 off += n_used;
741 }
742 else
743 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100744 off = before + after + padding + n_used;
745 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100746 }
747 if (n_attr != NULL)
748 {
749 if (n_used < *n_extra && wp->w_p_wrap)
750 {
751 char_u *lp = l + off - 1;
752
753 if (has_mbyte)
754 {
h-east4c42c7e2023-04-17 21:44:57 +0100755 char_u buf[MB_MAXBYTES + 1];
756 char_u *cp = buf;
757
758 // change the last character to '…', converted to the
759 // current 'encoding'
760 STRCPY(buf, "…");
761 if (!enc_utf8)
762 {
763 vimconv_T vc;
764
765 vc.vc_type = CONV_NONE;
766 convert_setup(&vc, (char_u *)"utf-8", p_enc);
767 if (vc.vc_type != CONV_NONE)
768 {
769 cp = string_convert(&vc, buf, NULL);
770 if (cp == NULL)
771 {
772 // when conversion fails use '>'
773 cp = buf;
774 STRCPY(buf, ">");
775 }
776 convert_setup(&vc, NULL, NULL);
777 }
778 }
779
780 lp -= (*mb_ptr2cells)(cp) - 1;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100781 lp -= (*mb_head_off)(l, lp);
h-east4c42c7e2023-04-17 21:44:57 +0100782 STRCPY(lp, cp);
Bram Moolenaar13845c42022-10-09 15:26:03 +0100783 n_used = lp - l + 3 - before - padding;
h-east4c42c7e2023-04-17 21:44:57 +0100784 if (cp != buf)
785 vim_free(cp);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100786 }
787 else
788 // change last character to '>'
789 *lp = '>';
790 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100791 else if (after > 0)
792 {
793 vim_memset(l + off, ' ', after);
794 l[off + after] = NUL;
795 }
796
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100797 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100798 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100799 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100800 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100801 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100802
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000803 // n_attr_skip will not be decremented before draw_state is
804 // WL_LINE
Christian Brabandtf1cc4d52023-08-12 00:14:14 +0200805 *n_attr_skip = before + (padding > 0 ? padding : 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100806 }
807 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100808 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100809
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100810 if (n_attr == NULL)
811 return cells;
812 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200813}
814#endif
815
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100816/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100817 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100818 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
819 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100820 */
821 static void
822wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
823{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100824 if (wlv->row == 0 && wp->w_skipcol > 0
825#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100826 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100827 && *get_showbreak_value(wp) == NUL
828#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100829 // do not overwrite the 'listchars' "precedes" text with "<<<"
830 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100831 {
832 int off = (int)(current_ScreenLine - ScreenLines);
zeertzjqecb87dd2023-06-03 19:45:06 +0100833 int max_off = off + screen_Columns;
Bram Moolenaareb4de622022-10-15 13:42:17 +0100834 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100835
Bram Moolenaareb4de622022-10-15 13:42:17 +0100836 if (wp->w_p_nu && wp->w_p_rnu)
837 // Do not overwrite the line number, change "123 text" to
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100838 // "123<<<xt".
Bram Moolenaareb4de622022-10-15 13:42:17 +0100839 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
840 {
841 ++off;
842 ++skip;
843 }
844
845 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100846 {
zeertzjqecb87dd2023-06-03 19:45:06 +0100847 if ((*mb_off2cells)(off, max_off) > 1)
848 // When the first half of a double-width character is
849 // overwritten, change the second half to a space.
850 ScreenLines[off + 1] = ' ';
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100851 ScreenLines[off] = '<';
852 if (enc_utf8)
853 ScreenLinesUC[off] = 0;
854 ScreenAttrs[off] = HL_ATTR(HLF_AT);
855 ++off;
856 }
857 }
858
859 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
860 negative_width ? -wp->w_width : wp->w_width,
861 wlv->screen_line_flags);
862}
863
864/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100865 * Called when finished with the line: draw the screen line and handle any
866 * highlighting until the right of the window.
867 */
868 static void
869draw_screen_line(win_T *wp, winlinevars_T *wlv)
870{
871#ifdef FEAT_SYN_HL
872 long v;
873
874 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
875 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100876 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100877 else
878 v = wp->w_leftcol;
879
880 // check if line ends before left margin
881 if (wlv->vcol < v + wlv->col - win_col_off(wp))
882 wlv->vcol = v + wlv->col - win_col_off(wp);
883# ifdef FEAT_CONCEAL
884 // Get rid of the boguscols now, we want to draw until the right
885 // edge for 'cursorcolumn'.
886 wlv->col -= wlv->boguscols;
887 wlv->boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000888# define VCOL_HLC (wlv->vcol - wlv->vcol_off_co - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100889# else
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000890# define VCOL_HLC (wlv->vcol - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100891# endif
892
893 if (wlv->draw_color_col)
894 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
895
896 if (((wp->w_p_cuc
897 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
898 && (int)wp->w_virtcol <
899 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
900 && wlv->lnum != wp->w_cursor.lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000901 || wlv->draw_color_col
902# ifdef LINE_ATTR
903 || wlv->line_attr != 0
904# endif
905 || wlv->win_attr != 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100906# ifdef FEAT_RIGHTLEFT
907 && !wp->w_p_rl
908# endif
909 )
910 {
911 int rightmost_vcol = 0;
912 int i;
913
914 if (wp->w_p_cuc)
915 rightmost_vcol = wp->w_virtcol;
916 if (wlv->draw_color_col)
917 // determine rightmost colorcolumn to possibly draw
918 for (i = 0; wlv->color_cols[i] >= 0; ++i)
919 if (rightmost_vcol < wlv->color_cols[i])
920 rightmost_vcol = wlv->color_cols[i];
921
922 while (wlv->col < wp->w_width)
923 {
924 ScreenLines[wlv->off] = ' ';
925 if (enc_utf8)
926 ScreenLinesUC[wlv->off] = 0;
927 ScreenCols[wlv->off] = MAXCOL;
928 ++wlv->col;
929 if (wlv->draw_color_col)
930 wlv->draw_color_col = advance_color_col(
931 VCOL_HLC, &wlv->color_cols);
932
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000933 int attr = wlv->win_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100934 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000935 attr = HL_ATTR(HLF_CUC);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100936 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000937 attr = HL_ATTR(HLF_MC);
938# ifdef LINE_ATTR
939 else if (wlv->line_attr != 0)
940 attr = wlv->line_attr;
941# endif
942 ScreenAttrs[wlv->off++] = attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100943
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000944 if (VCOL_HLC >= rightmost_vcol
945# ifdef LINE_ATTR
946 && wlv->line_attr == 0
947# endif
948 && wlv->win_attr == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100949 break;
950
951 ++wlv->vcol;
952 }
953 }
954#endif
955
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100956 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100957 ++wlv->row;
958 ++wlv->screen_row;
959}
960#undef VCOL_HLC
961
962/*
963 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100964 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100965 */
966 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100967win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100968{
969 wlv->col = 0;
970 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
971
972#ifdef FEAT_RIGHTLEFT
973 if (wp->w_p_rl)
974 {
975 // Rightleft window: process the text in the normal direction, but put
976 // it in current_ScreenLine[] from right to left. Start at the
977 // rightmost column of the window.
978 wlv->col = wp->w_width - 1;
979 wlv->off += wlv->col;
980 wlv->screen_line_flags |= SLF_RIGHTLEFT;
981 }
982#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100983 if (save_extra)
984 {
985 // reset the drawing state for the start of a wrapped line
986 wlv->draw_state = WL_START;
987 wlv->saved_n_extra = wlv->n_extra;
988 wlv->saved_p_extra = wlv->p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +0100989 vim_free(wlv->saved_p_extra_free);
990 wlv->saved_p_extra_free = wlv->p_extra_free;
991 wlv->p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000992 wlv->saved_extra_attr = wlv->extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000993 wlv->saved_n_attr_skip = wlv->n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000994 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100995 wlv->saved_c_extra = wlv->c_extra;
996 wlv->saved_c_final = wlv->c_final;
997#ifdef FEAT_SYN_HL
998 if (!(wlv->cul_screenline
999# ifdef FEAT_DIFF
1000 && wlv->diff_hlf == (hlf_T)0
1001# endif
1002 ))
1003 wlv->saved_char_attr = wlv->char_attr;
1004 else
1005#endif
1006 wlv->saved_char_attr = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001007
1008 // these are not used until restored in win_line_continue()
Bram Moolenaar1306b362022-08-06 15:59:06 +01001009 wlv->n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001010 wlv->n_attr_skip = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001011 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001012}
1013
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001014/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001015 * Called when wlv->draw_state is set to WL_LINE.
1016 */
1017 static void
1018win_line_continue(winlinevars_T *wlv)
1019{
1020 if (wlv->saved_n_extra > 0)
1021 {
1022 // Continue item from end of wrapped line.
1023 wlv->n_extra = wlv->saved_n_extra;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001024 wlv->saved_n_extra = 0;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001025 wlv->c_extra = wlv->saved_c_extra;
1026 wlv->c_final = wlv->saved_c_final;
1027 wlv->p_extra = wlv->saved_p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +01001028 vim_free(wlv->p_extra_free);
1029 wlv->p_extra_free = wlv->saved_p_extra_free;
1030 wlv->saved_p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001031 wlv->extra_attr = wlv->saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001032 wlv->n_attr_skip = wlv->saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001033 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001034 wlv->char_attr = wlv->saved_char_attr;
1035 }
1036 else
1037 wlv->char_attr = wlv->win_attr;
1038}
1039
zeertzjqb7acea12022-12-12 13:20:43 +00001040#ifdef FEAT_SYN_HL
1041 static void
1042apply_cursorline_highlight(
1043 winlinevars_T *wlv,
1044 int sign_present UNUSED)
1045{
1046 wlv->cul_attr = HL_ATTR(HLF_CUL);
1047# ifdef FEAT_SIGNS
1048 // Combine the 'cursorline' and sign highlighting, depending on
1049 // the sign priority.
1050 if (sign_present && wlv->sattr.sat_linehl > 0)
1051 {
1052 if (wlv->sattr.sat_priority >= 100)
1053 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1054 else
1055 wlv->line_attr = hl_combine_attr(wlv->line_attr, wlv->cul_attr);
1056 }
1057 else
1058# endif
1059# if defined(FEAT_QUICKFIX)
1060 // let the line attribute overrule 'cursorline', otherwise
1061 // it disappears when both have background set;
1062 // 'cursorline' can use underline or bold to make it show
1063 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1064# else
1065 wlv->line_attr = wlv->cul_attr;
1066# endif
1067}
1068#endif
1069
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001070/*
Luuk van Baal30805a12023-05-27 22:22:10 +01001071 * Display line "lnum" of window "wp" on the screen.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001072 * Start at row "startrow", stop when "endrow" is reached.
Luuk van Baal30805a12023-05-27 22:22:10 +01001073 * When "number_only" is TRUE only update the number column.
1074 * "spv" is used to store information for spell checking, kept between
1075 * sequential calls for the same window.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001076 * wp->w_virtcol needs to be valid.
1077 *
1078 * Return the number of last row the line occupies.
1079 */
1080 int
1081win_line(
1082 win_T *wp,
1083 linenr_T lnum,
1084 int startrow,
1085 int endrow,
Luuk van Baal30805a12023-05-27 22:22:10 +01001086 int number_only,
1087 spellvars_T *spv UNUSED)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001088{
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001089 winlinevars_T wlv; // variables passed between functions
1090
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001091 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001092 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001093 char_u *line; // current line
1094 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001095
Bram Moolenaar1306b362022-08-06 15:59:06 +01001096#ifdef FEAT_PROP_POPUP
1097 char_u *p_extra_free2 = NULL; // another p_extra to be freed
1098#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001099#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001100 int in_linebreak = FALSE; // n_extra set for showing linebreak
1101#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001102 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +01001103 // displaying eol at end-of-line
1104 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001105 int lcs_prec_todo = wp->w_lcs_chars.prec;
1106 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001107
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001108 int n_attr = 0; // chars with special attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001109 int saved_attr2 = 0; // char_attr saved for n_attr
1110 int n_attr3 = 0; // chars with overruling special attr
1111 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001112
Bram Moolenaarcd105412022-10-10 19:50:42 +01001113 int n_skip = 0; // nr of cells to skip for 'nowrap' or
1114 // concealing
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001115#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001116 int skip_cells = 0; // nr of cells to skip for virtual text
1117 // after the line, when w_skipcol is
1118 // larger than the text length
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001119#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001120
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001121 int fromcol_prev = -2; // start of inverting after cursor
1122 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001123 int lnum_in_visual_area = FALSE;
1124 pos_T pos;
1125 long v;
1126
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001127 int attr_pri = FALSE; // char_attr has priority
1128 int area_highlighting = FALSE; // Visual or incsearch highlighting
1129 // in this line
1130 int vi_attr = 0; // attributes for Visual and incsearch
1131 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001132 int area_attr = 0; // attributes desired by highlighting
1133 int search_attr = 0; // attributes desired by 'hlsearch'
1134#ifdef FEAT_SYN_HL
1135 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1136 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001137 int prev_syntax_col = -1; // column of prev_syntax_attr
1138 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001139 int has_syntax = FALSE; // this buffer has syntax highl.
1140 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001141#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001142#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001143 int did_line = FALSE; // set to TRUE when line text done
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001144 int text_prop_count;
1145 int text_prop_next = 0; // next text property to use
1146 textprop_T *text_props = NULL;
1147 int *text_prop_idxs = NULL;
1148 int text_props_active = 0;
1149 proptype_T *text_prop_type = NULL;
1150 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001151 int text_prop_attr_comb = 0; // text_prop_attr combined with
1152 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001153 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001154 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001155 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001156 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001157 int saved_search_attr = 0; // search_attr to be used when n_extra
1158 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001159 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001160 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001161#endif
1162#ifdef FEAT_SPELL
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001163 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001164# define SPWORDLEN 150
1165 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1166 int nextlinecol = 0; // column where nextline[] starts
1167 int nextline_idx = 0; // index in nextline[] where next line
1168 // starts
1169 int spell_attr = 0; // attributes desired by spelling
1170 int word_end = 0; // last byte with same spell_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001171 int cur_checked_col = 0; // checked column for current line
1172#endif
1173 int extra_check = 0; // has extra highlighting
1174 int multi_attr = 0; // attributes desired by multibyte
1175 int mb_l = 1; // multi-byte byte length
1176 int mb_c = 0; // decoded multi-byte character
1177 int mb_utf8 = FALSE; // screen char is UTF-8 char
1178 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001179#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001180 int change_start = MAXCOL; // first col of changed area
1181 int change_end = -1; // last col of changed area
1182#endif
1183 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001184 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001185 int in_multispace = FALSE; // in multiple consecutive spaces
1186 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001187#ifdef LINE_ATTR
Bram Moolenaarbf915842022-08-06 22:38:02 +01001188 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001189#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001190 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001191 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001192#ifdef FEAT_ARABIC
1193 int prev_c = 0; // previous Arabic character
1194 int prev_c1 = 0; // first composing char for prev_c
1195#endif
1196#if defined(LINE_ATTR)
1197 int did_line_attr = 0;
1198#endif
1199#ifdef FEAT_TERMINAL
1200 int get_term_attr = FALSE;
1201#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001202
Martin Tournoijba43e762022-10-13 22:12:15 +01001203#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001204 // margin columns for the screen line, needed for when 'cursorlineopt'
1205 // contains "screenline"
1206 int left_curline_col = 0;
1207 int right_curline_col = 0;
1208#endif
1209
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001210#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1211 int feedback_col = 0;
1212 int feedback_old_attr = -1;
1213#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001214
1215#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1216 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001217#endif
1218#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001219 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001220#endif
1221#ifdef FEAT_CONCEAL
1222 int syntax_flags = 0;
1223 int syntax_seqnr = 0;
1224 int prev_syntax_id = 0;
1225 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1226 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001227 int did_wcol = FALSE;
1228 int old_boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001229# define VCOL_HLC (wlv.vcol - wlv.vcol_off_co - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001230# define FIX_FOR_BOGUSCOLS \
1231 { \
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001232 wlv.n_extra += wlv.vcol_off_co; \
1233 wlv.vcol -= wlv.vcol_off_co; \
1234 wlv.vcol_off_co = 0; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001235 wlv.col -= wlv.boguscols; \
1236 old_boguscols = wlv.boguscols; \
1237 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001238 }
1239#else
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001240# define VCOL_HLC (wlv.vcol - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001241#endif
1242
1243 if (startrow > endrow) // past the end already!
1244 return startrow;
1245
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001246 CLEAR_FIELD(wlv);
1247
1248 wlv.lnum = lnum;
1249 wlv.startrow = startrow;
1250 wlv.row = startrow;
1251 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001252 wlv.fromcol = -10;
1253 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001254#ifdef FEAT_LINEBREAK
1255 wlv.vcol_sbr = -1;
1256#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001257
1258 if (!number_only)
1259 {
1260 // To speed up the loop below, set extra_check when there is linebreak,
1261 // trailing white space and/or syntax processing to be done.
1262#ifdef FEAT_LINEBREAK
1263 extra_check = wp->w_p_lbr;
1264#endif
1265#ifdef FEAT_SYN_HL
1266 if (syntax_present(wp) && !wp->w_s->b_syn_error
1267# ifdef SYN_TIME_LIMIT
1268 && !wp->w_s->b_syn_slow
1269# endif
1270 )
1271 {
1272 // Prepare for syntax highlighting in this line. When there is an
1273 // error, stop syntax highlighting.
1274 save_did_emsg = did_emsg;
1275 did_emsg = FALSE;
1276 syntax_start(wp, lnum);
1277 if (did_emsg)
1278 wp->w_s->b_syn_error = TRUE;
1279 else
1280 {
1281 did_emsg = save_did_emsg;
1282#ifdef SYN_TIME_LIMIT
1283 if (!wp->w_s->b_syn_slow)
1284#endif
1285 {
1286 has_syntax = TRUE;
1287 extra_check = TRUE;
1288 }
1289 }
1290 }
1291
1292 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001293 wlv.color_cols = wp->w_p_cc_cols;
1294 if (wlv.color_cols != NULL)
1295 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001296#endif
1297
1298#ifdef FEAT_TERMINAL
1299 if (term_show_buffer(wp->w_buffer))
1300 {
1301 extra_check = TRUE;
1302 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001303 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001304 }
1305#endif
1306
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001307 // handle Visual active in this window
1308 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1309 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001310 pos_T *top, *bot;
1311
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001312 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1313 {
1314 // Visual is after curwin->w_cursor
1315 top = &curwin->w_cursor;
1316 bot = &VIsual;
1317 }
1318 else
1319 {
1320 // Visual is before curwin->w_cursor
1321 top = &VIsual;
1322 bot = &curwin->w_cursor;
1323 }
1324 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1325 if (VIsual_mode == Ctrl_V)
1326 {
1327 // block mode
1328 if (lnum_in_visual_area)
1329 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001330 wlv.fromcol = wp->w_old_cursor_fcol;
1331 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001332 }
1333 }
1334 else
1335 {
1336 // non-block mode
1337 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001338 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001339 else if (lnum == top->lnum)
1340 {
1341 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001342 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001343 else
1344 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001345 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001346 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001347 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001348 }
1349 }
1350 if (VIsual_mode != 'V' && lnum == bot->lnum)
1351 {
1352 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1353 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001354 wlv.fromcol = -10;
1355 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001356 }
1357 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001358 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001359 else
1360 {
1361 pos = *bot;
1362 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001363 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1364 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001365 else
1366 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001367 getvvcol(wp, &pos, NULL, NULL,
1368 (colnr_T *)&wlv.tocol);
1369 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001370 }
1371 }
1372 }
1373 }
1374
1375 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001376 if (!highlight_match && lnum == curwin->w_cursor.lnum
1377 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001378#ifdef FEAT_GUI
1379 && !gui.in_use
1380#endif
1381 )
1382 noinvcur = TRUE;
1383
1384 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001385 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001386 {
1387 area_highlighting = TRUE;
1388 vi_attr = HL_ATTR(HLF_V);
1389#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1390 if ((clip_star.available && !clip_star.owned
1391 && clip_isautosel_star())
1392 || (clip_plus.available && !clip_plus.owned
1393 && clip_isautosel_plus()))
1394 vi_attr = HL_ATTR(HLF_VNC);
1395#endif
1396 }
1397 }
1398
1399 // handle 'incsearch' and ":s///c" highlighting
1400 else if (highlight_match
1401 && wp == curwin
1402 && lnum >= curwin->w_cursor.lnum
1403 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1404 {
1405 if (lnum == curwin->w_cursor.lnum)
1406 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001407 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001408 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001409 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001410 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1411 {
1412 pos.lnum = lnum;
1413 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001414 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001415 }
1416 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001417 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001418 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001419 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1420 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001421 area_highlighting = TRUE;
1422 vi_attr = HL_ATTR(HLF_I);
1423 }
1424 }
1425
1426#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001427 wlv.filler_lines = diff_check(wp, lnum);
1428 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001429 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001430 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001431 {
1432 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001433 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001434 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001435 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001436 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001437 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001438 }
1439 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001440 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001441 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001442 area_highlighting = TRUE;
1443 }
1444 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001445 wlv.filler_lines = wp->w_topfill;
1446 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001447#endif
1448
1449#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001450 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001451 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001452 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001453#endif
1454
1455#ifdef LINE_ATTR
1456# ifdef FEAT_SIGNS
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001457 // If this line has a sign with line highlighting set wlv.line_attr.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001458 if (sign_present)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001459 wlv.line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001460# endif
1461# if defined(FEAT_QUICKFIX)
1462 // Highlight the current line in the quickfix window.
1463 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001464 wlv.line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001465# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001466 if (wlv.line_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001467 area_highlighting = TRUE;
1468#endif
1469
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001470#ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01001471 if (spv->spv_has_spell && !number_only)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001472 {
Luuk van Baal30805a12023-05-27 22:22:10 +01001473 // Prepare for spell checking.
1474 extra_check = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001475
Luuk van Baal30805a12023-05-27 22:22:10 +01001476 // When a word wrapped from the previous line the start of the
1477 // current line is valid.
1478 if (lnum == spv->spv_checked_lnum)
1479 cur_checked_col = spv->spv_checked_col;
Luuk van Baale84c7732023-05-31 18:57:36 +01001480 // Previous line was not spell checked, check for capital. This happens
1481 // for the first line in an updated region or after a closed fold.
1482 if (spv->spv_capcol_lnum == 0 && check_need_cap(wp, lnum, 0))
1483 spv->spv_cap_col = 0;
1484 else if (lnum != spv->spv_capcol_lnum)
Luuk van Baal30805a12023-05-27 22:22:10 +01001485 spv->spv_cap_col = -1;
1486 spv->spv_checked_lnum = 0;
1487
Luuk van Baal30805a12023-05-27 22:22:10 +01001488 // Get the start of the next line, so that words that wrap to the
1489 // next line are found too: "et<line-break>al.".
1490 // Trick: skip a few chars for C/shell/Vim comments
1491 nextline[SPWORDLEN] = NUL;
1492 if (lnum < wp->w_buffer->b_ml.ml_line_count)
Luuk van Baale84c7732023-05-31 18:57:36 +01001493 {
1494 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1495 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1496 }
1497 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1498
1499 // If current line is empty, check first word in next line for capital.
1500 ptr = skipwhite(line);
1501 if (*ptr == NUL)
1502 {
1503 spv->spv_cap_col = 0;
1504 spv->spv_capcol_lnum = lnum + 1;
1505 }
1506 // For checking first word with a capital skip white space.
1507 else if (spv->spv_cap_col == 0)
1508 spv->spv_cap_col = ptr - line;
1509
Luuk van Baal30805a12023-05-27 22:22:10 +01001510 // Copy the end of the current line into nextline[].
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001511 if (nextline[SPWORDLEN] == NUL)
1512 {
1513 // No next line or it is empty.
1514 nextlinecol = MAXCOL;
1515 nextline_idx = 0;
1516 }
1517 else
1518 {
1519 v = (long)STRLEN(line);
1520 if (v < SPWORDLEN)
1521 {
1522 // Short line, use it completely and append the start of the
1523 // next line.
1524 nextlinecol = 0;
1525 mch_memmove(nextline, line, (size_t)v);
1526 STRMOVE(nextline + v, nextline + SPWORDLEN);
1527 nextline_idx = v + 1;
1528 }
1529 else
1530 {
1531 // Long line, use only the last SPWORDLEN bytes.
1532 nextlinecol = v - SPWORDLEN;
1533 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1534 nextline_idx = SPWORDLEN + 1;
1535 }
1536 }
1537 }
1538#endif
1539
Luuk van Baale84c7732023-05-31 18:57:36 +01001540 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1541 ptr = line;
1542
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001543 if (wp->w_p_list)
1544 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001545 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001546 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001547 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001548 || wp->w_lcs_chars.trail
1549 || wp->w_lcs_chars.lead
1550 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001551 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001552
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001553 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001554 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001555 {
1556 trailcol = (colnr_T)STRLEN(ptr);
1557 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1558 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001559 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001560 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001561 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001562 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001563 {
1564 leadcol = 0;
1565 while (VIM_ISWHITE(ptr[leadcol]))
1566 ++leadcol;
1567 if (ptr[leadcol] == NUL)
1568 // in a line full of spaces all of them are treated as trailing
1569 leadcol = (colnr_T)0;
1570 else
1571 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001572 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001573 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001574 }
1575
Bram Moolenaard7657e92022-09-20 18:59:30 +01001576 wlv.wcr_attr = get_wcr_attr(wp);
1577 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001578 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001579 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001580 area_highlighting = TRUE;
1581 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001582
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001583 // When w_skipcol is non-zero and there is virtual text above the actual
1584 // text, then this much of the virtual text is skipped.
1585 int skipcol_in_text_prop_above = 0;
1586
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001587#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001588 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001589 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001590
1591 char_u *prop_start;
1592 text_prop_count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE);
1593 if (text_prop_count > 0)
1594 {
1595 // Make a copy of the properties, so that they are properly
1596 // aligned.
1597 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1598 if (text_props != NULL)
1599 mch_memmove(text_props, prop_start,
1600 text_prop_count * sizeof(textprop_T));
1601
1602 // Allocate an array for the indexes.
1603 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1604 if (text_prop_idxs == NULL)
1605 VIM_CLEAR(text_props);
1606
1607 if (text_props != NULL)
1608 {
1609 area_highlighting = TRUE;
1610 extra_check = TRUE;
1611
1612 // When skipping virtual text the props need to be sorted. The
1613 // order is reversed!
1614 if (lnum == wp->w_topline && wp->w_skipcol > 0)
1615 {
1616 for (int i = 0; i < text_prop_count; ++i)
1617 text_prop_idxs[i] = i;
1618 sort_text_props(wp->w_buffer, text_props,
1619 text_prop_idxs, text_prop_count);
1620 }
1621
1622 // Text props "above" move the line number down to where the text
1623 // is. Only count the ones that are visible, not those that are
1624 // skipped because of w_skipcol.
1625 int text_width = wp->w_width - win_col_off(wp);
1626 for (int i = text_prop_count - 1; i >= 0; --i)
1627 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1628 {
1629 if (lnum == wp->w_topline
1630 && wp->w_skipcol - skipcol_in_text_prop_above
1631 >= text_width)
1632 {
1633 // This virtual text above is skipped, remove it from
1634 // the array.
1635 skipcol_in_text_prop_above += text_width;
1636 for (int j = i + 1; j < text_prop_count; ++j)
1637 text_props[j - 1] = text_props[j];
1638 ++i;
1639 --text_prop_count;
1640 }
1641 else
1642 ++wlv.text_prop_above_count;
1643 }
1644 }
1645 }
Bram Moolenaara572b932023-02-19 14:34:37 +00001646
1647 if (number_only)
1648 {
1649 // skip over rows only used for virtual text above
1650 wlv.row += wlv.text_prop_above_count;
1651 if (wlv.row > endrow)
1652 return wlv.row;
1653 wlv.screen_row += wlv.text_prop_above_count;
1654 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001655#endif
1656
1657 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1658 // first character to be displayed.
1659 if (wp->w_p_wrap)
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001660 v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001661 else
1662 v = wp->w_leftcol;
1663 if (v > 0 && !number_only)
1664 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001665 char_u *prev_ptr = ptr;
1666 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001667 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001668
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001669 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001670 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001671 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001672 charsize = win_lbr_chartabsize(&cts, NULL);
1673 cts.cts_vcol += charsize;
1674 prev_ptr = cts.cts_ptr;
1675 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001676 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001677 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001678 ptr = cts.cts_ptr;
1679 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001680
1681 // When:
1682 // - 'cuc' is set, or
1683 // - 'colorcolumn' is set, or
1684 // - 'virtualedit' is set, or
1685 // - the visual mode is active,
1686 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001687 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001688#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001689 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001690#endif
1691 virtual_active() ||
1692 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001693 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001694
1695 // Handle a character that's not completely on the screen: Put ptr at
1696 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001697 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001698 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001699 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001700 ptr = prev_ptr;
1701 // If the character fits on the screen, don't need to skip it.
1702 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001703 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1704 && wlv.col == 0)
1705 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001706 }
1707
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001708#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001709 // If there the text doesn't reach to the desired column, need to skip
1710 // "skip_cells" cells when virtual text follows.
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001711 if ((!wp->w_p_wrap || (lnum == wp->w_topline && wp->w_skipcol > 0))
1712 && v > wlv.vcol)
Bram Moolenaarcd105412022-10-10 19:50:42 +01001713 skip_cells = v - wlv.vcol;
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001714#endif
Bram Moolenaarcd105412022-10-10 19:50:42 +01001715
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001716 // Adjust for when the inverted text is before the screen,
1717 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001718 if (wlv.tocol <= wlv.vcol)
1719 wlv.fromcol = 0;
1720 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1721 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001722
1723#ifdef FEAT_LINEBREAK
1724 // When w_skipcol is non-zero, first line needs 'showbreak'
1725 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001726 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001727#endif
1728#ifdef FEAT_SPELL
1729 // When spell checking a word we need to figure out the start of the
1730 // word and if it's badly spelled or not.
Luuk van Baal30805a12023-05-27 22:22:10 +01001731 if (spv->spv_has_spell)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001732 {
1733 int len;
1734 colnr_T linecol = (colnr_T)(ptr - line);
1735 hlf_T spell_hlf = HLF_COUNT;
1736
1737 pos = wp->w_cursor;
1738 wp->w_cursor.lnum = lnum;
1739 wp->w_cursor.col = linecol;
1740 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1741
1742 // spell_move_to() may call ml_get() and make "line" invalid
1743 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1744 ptr = line + linecol;
1745
1746 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1747 {
1748 // no bad word found at line start, don't check until end of a
1749 // word
1750 spell_hlf = HLF_COUNT;
1751 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1752 }
1753 else
1754 {
1755 // bad word found, use attributes until end of word
1756 word_end = wp->w_cursor.col + len + 1;
1757
1758 // Turn index into actual attributes.
1759 if (spell_hlf != HLF_COUNT)
1760 spell_attr = highlight_attr[spell_hlf];
1761 }
1762 wp->w_cursor = pos;
1763
1764# ifdef FEAT_SYN_HL
1765 // Need to restart syntax highlighting for this line.
1766 if (has_syntax)
1767 syntax_start(wp, lnum);
1768# endif
1769 }
1770#endif
1771 }
1772
1773 // Correct highlighting for cursor that can't be disabled.
1774 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001775 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001776 {
1777 if (noinvcur)
1778 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001779 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001780 {
1781 // highlighting starts at cursor, let it start just after the
1782 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001783 fromcol_prev = wlv.fromcol;
1784 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001785 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001786 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001787 // restart highlighting after the cursor
1788 fromcol_prev = wp->w_virtcol;
1789 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001790 if (wlv.fromcol >= wlv.tocol)
1791 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001792 }
1793
1794#ifdef FEAT_SEARCH_EXTRA
1795 if (!number_only)
1796 {
1797 v = (long)(ptr - line);
1798 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1799 &line, &screen_search_hl,
1800 &search_attr);
1801 ptr = line + v; // "line" may have been updated
1802 }
1803#endif
1804
1805#ifdef FEAT_SYN_HL
1806 // Cursor line highlighting for 'cursorline' in the current window.
1807 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1808 {
1809 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001810 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001811 if (!(wp == curwin && VIsual_active)
1812 && wp->w_p_culopt_flags != CULOPT_NBR)
1813 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001814 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001815 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1816
zeertzjqb7acea12022-12-12 13:20:43 +00001817 // Only apply CursorLine highlight here when "screenline" is not
1818 // present in 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001819 if (!wlv.cul_screenline)
zeertzjqb7acea12022-12-12 13:20:43 +00001820 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001821 else
1822 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001823 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001824 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1825 }
1826 area_highlighting = TRUE;
1827 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001828 }
1829#endif
1830
Bram Moolenaar1306b362022-08-06 15:59:06 +01001831 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001832
1833 // Repeat for the whole displayed line.
1834 for (;;)
1835 {
1836#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001837 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001838#endif
1839#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001840 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001841#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001842
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001843 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001844 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001845 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001846#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001847 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001848 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001849 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001850 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001851 }
1852#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001853 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001854 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001855 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001856 if (cmdwin_type != 0 && wp == curwin)
1857 {
1858 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001859 wlv.n_extra = 1;
1860 wlv.c_extra = cmdwin_type;
1861 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001862 wlv.char_attr =
1863 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001864 }
1865 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001866#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001867 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001868 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001869 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001870 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001871 }
1872#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001873#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001874 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001875 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001876 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001877 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001878 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001879 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001880 }
1881#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001882 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001883 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001884 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001885 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001886 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001887 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001888#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001889 // Check if 'breakindent' applies and show it.
1890 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1891 if (wlv.n_extra == 0)
1892 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001893#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001894#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001895 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001896 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001897 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001898 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001899 }
1900#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001901 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001902 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001903 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001904 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001905 }
1906 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001907
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001908#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001909 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001910 && wlv.vcol >= left_curline_col
1911 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001912 {
zeertzjqb7acea12022-12-12 13:20:43 +00001913 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001914 }
1915#endif
1916
1917 // When still displaying '$' of change command, stop at cursor.
1918 // When only displaying the (relative) line number and that's done,
1919 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001920 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001921 && lnum == wp->w_cursor.lnum
1922 && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001923 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001924#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001925 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001926#endif
1927 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001928 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001929 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001930 // Pretend we have finished updating the window. Except when
1931 // 'cursorcolumn' is set.
1932#ifdef FEAT_SYN_HL
1933 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001934 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001935 else
1936#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001937 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001938 break;
1939 }
1940
Bram Moolenaar1306b362022-08-06 15:59:06 +01001941 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001942 {
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001943#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001944 if (text_props != NULL)
1945 {
1946 int pi;
1947 int bcol = (int)(ptr - line);
1948
Bram Moolenaar1306b362022-08-06 15:59:06 +01001949 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001950# ifdef FEAT_LINEBREAK
1951 && !in_linebreak
1952# endif
1953 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001954 --bcol; // still working on the previous char, e.g. Tab
1955
1956 // Check if any active property ends.
1957 for (pi = 0; pi < text_props_active; ++pi)
1958 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001959 int tpi = text_prop_idxs[pi];
1960 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001961
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001962 // An inline property ends when after the start column plus
1963 // length. An "above" property ends when used and n_extra
1964 // is zero.
1965 if ((tp->tp_col != MAXCOL
1966 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001967 {
1968 if (pi + 1 < text_props_active)
1969 mch_memmove(text_prop_idxs + pi,
1970 text_prop_idxs + pi + 1,
1971 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001972 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001973 --text_props_active;
1974 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001975# ifdef FEAT_LINEBREAK
1976 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001977 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001978 syntax_attr = 0;
1979# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001980 }
1981 }
1982
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001983# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001984 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001985 // not on the next char yet, don't start another prop
1986 --bcol;
1987# endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001988 int display_text_first = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001989
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001990 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001991 // With 'nowrap' and not in the first screen line only "below"
1992 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001993 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001994 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001995 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001996 && (wp->w_p_wrap
1997 || wlv.row == startrow
1998 || (text_props[text_prop_next].tp_flags
1999 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002000 || (bcol == 0
2001 && (text_props[text_prop_next].tp_flags
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002002 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002003 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002004 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01002005 if (text_props[text_prop_next].tp_col == MAXCOL
2006 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002007 + text_props[text_prop_next].tp_len)
2008 text_prop_idxs[text_props_active++] = text_prop_next;
2009 ++text_prop_next;
2010 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002011
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002012 if (wlv.n_extra == 0 || !wlv.extra_for_textprop)
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002013 {
2014 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002015 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002016 text_prop_flags = 0;
2017 text_prop_type = NULL;
2018 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002019 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002020 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002021 if (text_props_active > 0 && wlv.n_extra == 0
2022 && !display_text_first)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002023 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01002024 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002025 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002026 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002027
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002028 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002029 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002030
2031 // Sort the properties on priority and/or starting last.
2032 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002033 sort_text_props(wp->w_buffer, text_props,
2034 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002035
2036 for (pi = 0; pi < text_props_active; ++pi)
2037 {
2038 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002039 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002040 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002041 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002042
Bram Moolenaarcd105412022-10-10 19:50:42 +01002043 // Only use a text property that can be displayed.
2044 // Skip "after" properties when wrap is off and at the
2045 // end of the window.
2046 if (pt != NULL
2047 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2048 && tp->tp_id != -MAXCOL
2049 && !(tp->tp_id < 0
2050 && !wp->w_p_wrap
2051 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2052 | TP_FLAG_ALIGN_ABOVE
2053 | TP_FLAG_ALIGN_BELOW)) == 0
2054 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002055 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002056 if (tp->tp_col == MAXCOL
2057 && *ptr == NUL
2058 && ((wp->w_p_list && lcs_eol_one > 0
2059 && (tp->tp_flags
2060 & TP_FLAG_ALIGN_ABOVE) == 0)
2061 || (ptr == line
2062 && !did_line
2063 && (tp->tp_flags
2064 & TP_FLAG_ALIGN_BELOW))))
2065 {
2066 // skip this prop, first display the '$' after
2067 // the line or display an empty line
2068 text_prop_follows = TRUE;
2069 if (used_tpi < 0)
2070 display_text_first = TRUE;
2071 continue;
2072 }
2073
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002074 if (pt->pt_hl_id > 0)
2075 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002076 text_prop_type = pt;
2077 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002078 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002079 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2080 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002081 text_prop_flags = pt->pt_flags;
2082 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002083 used_tpi = tpi;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002084 display_text_first = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002085 }
2086 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002087 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002088 && -text_prop_id
2089 <= wp->w_buffer->b_textprop_text.ga_len)
2090 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002091 textprop_T *tp = &text_props[used_tpi];
2092 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002093 ->b_textprop_text.ga_data)[
2094 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002095 int above = (tp->tp_flags
2096 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002097 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002098
2099 // reset the ID in the copy to avoid it being used
2100 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002101 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002102
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002103 if (p != NULL)
2104 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002105 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002106 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002107 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002108 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002109 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
2110 int padding = tp->tp_col == MAXCOL
2111 && tp->tp_len > 1
2112 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002113
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002114 // Insert virtual text before the current
2115 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002116 wlv.p_extra = p;
2117 wlv.c_extra = NUL;
2118 wlv.c_final = NUL;
2119 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002120 wlv.extra_for_textprop = TRUE;
zeertzjq6e940d92023-08-17 23:21:40 +02002121 wlv.start_extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002122 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2123 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002124 n_attr = mb_charlen(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002125 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002126 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002127 if (*ptr == NUL)
2128 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002129 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002130#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002131 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002132 {
2133 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002134 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002135 wlv.need_showbreak = FALSE;
2136 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002137 }
2138#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002139 if ((right || above || below || !wrap
2140 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002141 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002142 char_u *prev_p_extra = wlv.p_extra;
2143 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002144
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002145 // Take care of padding, right-align and
2146 // truncation.
2147 // Shared with win_lbr_chartabsize(), must do
2148 // exactly the same.
2149 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002150 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002151 wlv.col,
2152 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002153 &n_attr, &wlv.n_attr_skip,
2154 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002155 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002156 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002157 // wlv.p_extra was allocated
2158 vim_free(p_extra_free2);
2159 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002160 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002161
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002162 if (above)
2163 wlv.vcol_off_tp = wlv.n_extra;
2164
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002165 if (lcs_eol_one < 0
2166 && wp->w_p_wrap
2167 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002168 + wlv.n_extra - 2 > wp->w_width)
2169 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002170 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002171
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002172 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002173 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002174 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002175 {
2176 draw_screen_line(wp, &wlv);
2177
2178 // When line got too long for screen break
2179 // here.
2180 if (wlv.row == endrow)
2181 {
2182 ++wlv.row;
2183 break;
2184 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002185 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002186 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002187 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002188 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002189 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002190
Bram Moolenaarcd105412022-10-10 19:50:42 +01002191 // If the text didn't reach until the first window
2192 // column we need to skip cells.
2193 if (skip_cells > 0)
2194 {
2195 if (wlv.n_extra > skip_cells)
2196 {
2197 wlv.n_extra -= skip_cells;
2198 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002199 wlv.n_attr_skip -= skip_cells;
2200 if (wlv.n_attr_skip < 0)
2201 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002202 skip_cells = 0;
2203 }
2204 else
2205 {
2206 // the whole text is left of the window, drop
2207 // it and advance to the next one
2208 skip_cells -= wlv.n_extra;
2209 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002210 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002211 bail_out = TRUE;
2212 }
2213 }
2214
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002215 // If another text prop follows the condition below at
2216 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002217 // If this is an "above" text prop and 'nowrap' the we
2218 // must wrap anyway.
2219 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002220 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002221 && (wp->w_p_wrap
2222 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002223 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002224
2225 if (bail_out)
2226 // starting a new line for "below"
2227 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002228 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002229 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002230 else if (text_prop_next < text_prop_count
2231 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002232 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2233 || (!wp->w_p_wrap
2234 && wlv.col == wp->w_width - 1
2235 && (text_props[text_prop_next].tp_flags
2236 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002237 // When at last-but-one character and a text property
2238 // follows after it, we may need to flush the line after
2239 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002240 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002241 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002242 }
zeertzjq6e940d92023-08-17 23:21:40 +02002243
2244 if (wlv.start_extra_for_textprop)
2245 {
2246 wlv.start_extra_for_textprop = FALSE;
2247 // restore search_attr and area_attr when n_extra
2248 // is down to zero
2249 saved_search_attr = search_attr;
2250 saved_area_attr = area_attr;
2251 search_attr = 0;
2252 area_attr = 0;
2253 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002254#endif
2255
zeertzjq6e940d92023-08-17 23:21:40 +02002256 int *area_attr_p =
2257#ifdef FEAT_PROP_POPUP
2258 wlv.extra_for_textprop ? &saved_area_attr :
2259#endif
2260 &area_attr;
2261
2262 // handle Visual or match highlighting in this line
2263 if (wlv.vcol == wlv.fromcol
2264 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
2265 && ((wlv.n_extra == 0 && (*mb_ptr2cells)(ptr) > 1)
2266 || (wlv.n_extra > 0 && wlv.p_extra != NULL
2267 && (*mb_ptr2cells)(wlv.p_extra) > 1)))
2268 || ((int)vcol_prev == fromcol_prev
2269 && vcol_prev < wlv.vcol // not at margin
2270 && wlv.vcol < wlv.tocol))
2271 *area_attr_p = vi_attr; // start highlighting
2272 else if (*area_attr_p != 0
2273 && (wlv.vcol == wlv.tocol
2274 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
2275 *area_attr_p = 0; // stop highlighting
2276
zeertzjqe500ae82023-08-17 22:35:26 +02002277#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaare38fc862022-08-11 17:24:50 +01002278 if (wlv.n_extra == 0)
2279 {
2280 // Check for start/end of 'hlsearch' and other matches.
2281 // After end, check for start/end of next match.
2282 // When another match, have to check for start again.
2283 v = (long)(ptr - line);
2284 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2285 &screen_search_hl, &has_match_conc,
2286 &match_conc, did_line_attr, lcs_eol_one,
2287 &on_last_col);
2288 ptr = line + v; // "line" may have been changed
Bram Moolenaare38fc862022-08-11 17:24:50 +01002289
2290 // Do not allow a conceal over EOL otherwise EOL will be missed
2291 // and bad things happen.
2292 if (*ptr == NUL)
2293 has_match_conc = 0;
zeertzjqb25dbb32023-08-13 18:11:05 +02002294 }
zeertzjqe500ae82023-08-17 22:35:26 +02002295#endif
zeertzjqb25dbb32023-08-13 18:11:05 +02002296
Bram Moolenaare38fc862022-08-11 17:24:50 +01002297#ifdef FEAT_DIFF
2298 if (wlv.diff_hlf != (hlf_T)0)
2299 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002300 // When there is extra text (e.g. virtual text) it gets the
2301 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002302 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2303 && wlv.n_extra == 0)
2304 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002305 if (wlv.diff_hlf == HLF_TXD
2306 && ((ptr - line > change_end && wlv.n_extra == 0)
2307 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002308 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002309 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002310 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2311 && wp->w_p_culopt_flags != CULOPT_NBR
2312 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2313 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002314 wlv.line_attr = hl_combine_attr(
2315 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002316 }
2317#endif
2318
Bram Moolenaara74fda62019-10-19 17:38:03 +02002319#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002320 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002321 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002322 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002323# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002324 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002325 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002326# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002327 // Get syntax attribute.
2328 if (has_syntax)
2329 {
2330 // Get the syntax attribute for the character. If there
2331 // is an error, disable syntax highlighting.
2332 save_did_emsg = did_emsg;
2333 did_emsg = FALSE;
2334
2335 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002336 if (v == prev_syntax_col)
2337 // at same column again
2338 syntax_attr = prev_syntax_attr;
2339 else
2340 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002341# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002342 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002343# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002344 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002345# ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01002346 spv->spv_has_spell ? &can_spell :
Bram Moolenaar34390282019-10-16 14:38:26 +02002347# endif
Luuk van Baal30805a12023-05-27 22:22:10 +01002348 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002349 prev_syntax_col = v;
2350 prev_syntax_attr = syntax_attr;
2351 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002352
Bram Moolenaar34390282019-10-16 14:38:26 +02002353 if (did_emsg)
2354 {
2355 wp->w_s->b_syn_error = TRUE;
2356 has_syntax = FALSE;
2357 syntax_attr = 0;
2358 }
2359 else
2360 did_emsg = save_did_emsg;
2361# ifdef SYN_TIME_LIMIT
2362 if (wp->w_s->b_syn_slow)
2363 has_syntax = FALSE;
2364# endif
2365
2366 // Need to get the line again, a multi-line regexp may
2367 // have made it invalid.
2368 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2369 ptr = line + v;
2370# ifdef FEAT_CONCEAL
2371 // no concealing past the end of the line, it interferes
2372 // with line highlighting
2373 if (*ptr == NUL)
2374 syntax_flags = 0;
2375 else
2376 syntax_flags = get_syntax_info(&syntax_seqnr);
2377# endif
2378 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002379 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002380# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002381 // Combine text property highlight into syntax highlight.
2382 if (text_prop_type != NULL)
2383 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002384 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002385 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2386 else
2387 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002388 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002389 }
2390# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002391#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002392
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002393 // Decide which of the highlight attributes to use.
2394 attr_pri = TRUE;
2395#ifdef LINE_ATTR
2396 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002397 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002398 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002399 if (!highlight_match)
2400 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002401 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002402# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002403 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002404# endif
2405 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002406 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002407 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002408 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002409# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002410 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002411# endif
2412 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002413 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002414 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2415 || wlv.vcol < wlv.fromcol
2416 || vcol_prev < fromcol_prev
2417 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002418 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002419 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002420 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002421# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002422 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002423# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002424 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002425# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002426 attr_pri = FALSE;
2427 }
2428#else
2429 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002430 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002431 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002432 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002433#endif
2434 else
2435 {
2436 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002437#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002438 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002439#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002440 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002441#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002442 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002443#ifdef FEAT_PROP_POPUP
2444 // override with text property highlight when "override" is TRUE
2445 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002446 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002447#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002448 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002449
2450 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002451 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002452 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002453 if (wlv.char_attr == 0)
2454 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002455 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002456 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002457 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002458
2459 // Get the next character to put on the screen.
2460
2461 // The "p_extra" points to the extra stuff that is inserted to
2462 // represent special characters (non-printable stuff) and other
2463 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002464 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002465 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2466 // "p_extra[n_extra]".
2467 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002468 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002469 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002470 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002471 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002472 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2473 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002474 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2475 if (enc_utf8 && utf_char2len(c) > 1)
2476 {
2477 mb_utf8 = TRUE;
2478 u8cc[0] = 0;
2479 c = 0xc0;
2480 }
2481 else
2482 mb_utf8 = FALSE;
2483 }
2484 else
2485 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002486 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002487 if (has_mbyte)
2488 {
2489 mb_c = c;
2490 if (enc_utf8)
2491 {
2492 // If the UTF-8 character is more than one byte:
2493 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002494 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002495 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002496 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002497 mb_l = 1;
2498 else if (mb_l > 1)
2499 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002500 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002501 mb_utf8 = TRUE;
2502 c = 0xc0;
2503 }
2504 }
2505 else
2506 {
2507 // if this is a DBCS character, put it in "mb_c"
2508 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002509 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002510 mb_l = 1;
2511 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002512 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002513 }
2514 if (mb_l == 0) // at the NUL at end-of-line
2515 mb_l = 1;
2516
2517 // If a double-width char doesn't fit display a '>' in the
2518 // last column.
2519 if ((
2520# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002521 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002522# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002523 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002524 && (*mb_char2cells)(mb_c) == 2)
2525 {
2526 c = '>';
2527 mb_c = c;
2528 mb_l = 1;
2529 mb_utf8 = FALSE;
2530 multi_attr = HL_ATTR(HLF_AT);
2531#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002532 if (wlv.cul_attr)
2533 multi_attr = hl_combine_attr(
2534 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002535#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002536 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002537
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002538 // put the pointer back to output the double-width
2539 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002540 ++wlv.n_extra;
2541 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002542 }
2543 else
2544 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002545 wlv.n_extra -= mb_l - 1;
2546 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002547 }
2548 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002549 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002550 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002551 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002552#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002553 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002554 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002555 // Only restore search_attr and area_attr after "n_extra" in
2556 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002557 if (wlv.saved_n_extra <= 0)
2558 {
2559 if (search_attr == 0)
2560 search_attr = saved_search_attr;
2561 if (area_attr == 0 && *ptr != NUL)
2562 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002563
2564 if (wlv.extra_for_textprop)
2565 // wlv.extra_attr should be used at this position but
2566 // not any further.
2567 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002568 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002569
2570 wlv.extra_for_textprop = FALSE;
2571 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002572 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002573#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002574 }
2575 else
2576 {
2577#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002578 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002579#endif
zeertzjqe500ae82023-08-17 22:35:26 +02002580#ifdef FEAT_SPELL
2581 char_u *prev_ptr = ptr;
2582#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002583
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002584 // Get a character from the line itself.
2585 c = *ptr;
2586#ifdef FEAT_LINEBREAK
2587 c0 = *ptr;
2588#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002589#ifdef FEAT_PROP_POPUP
2590 if (c == NUL)
2591 // text is finished, may display a "below" virtual text
2592 did_line = TRUE;
2593#endif
2594
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002595 if (has_mbyte)
2596 {
2597 mb_c = c;
2598 if (enc_utf8)
2599 {
2600 // If the UTF-8 character is more than one byte: Decode it
2601 // into "mb_c".
2602 mb_l = utfc_ptr2len(ptr);
2603 mb_utf8 = FALSE;
2604 if (mb_l > 1)
2605 {
2606 mb_c = utfc_ptr2char(ptr, u8cc);
2607 // Overlong encoded ASCII or ASCII with composing char
2608 // is displayed normally, except a NUL.
2609 if (mb_c < 0x80)
2610 {
2611 c = mb_c;
2612#ifdef FEAT_LINEBREAK
2613 c0 = mb_c;
2614#endif
2615 }
2616 mb_utf8 = TRUE;
2617
2618 // At start of the line we can have a composing char.
2619 // Draw it as a space with a composing char.
2620 if (utf_iscomposing(mb_c))
2621 {
2622 int i;
2623
2624 for (i = Screen_mco - 1; i > 0; --i)
2625 u8cc[i] = u8cc[i - 1];
2626 u8cc[0] = mb_c;
2627 mb_c = ' ';
2628 }
2629 }
2630
2631 if ((mb_l == 1 && c >= 0x80)
2632 || (mb_l >= 1 && mb_c == 0)
2633 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2634 {
2635 // Illegal UTF-8 byte: display as <xx>.
2636 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002637 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002638# ifdef FEAT_RIGHTLEFT
2639 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002640 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002641# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002642 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002643 c = *wlv.p_extra;
2644 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002645 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002646 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2647 wlv.c_extra = NUL;
2648 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002649 if (area_attr == 0 && search_attr == 0)
2650 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002651 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002652 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002653 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002654 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002655 }
2656 }
2657 else if (mb_l == 0) // at the NUL at end-of-line
2658 mb_l = 1;
2659#ifdef FEAT_ARABIC
2660 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2661 {
2662 // Do Arabic shaping.
2663 int pc, pc1, nc;
2664 int pcc[MAX_MCO];
2665
2666 // The idea of what is the previous and next
2667 // character depends on 'rightleft'.
2668 if (wp->w_p_rl)
2669 {
2670 pc = prev_c;
2671 pc1 = prev_c1;
2672 nc = utf_ptr2char(ptr + mb_l);
2673 prev_c1 = u8cc[0];
2674 }
2675 else
2676 {
2677 pc = utfc_ptr2char(ptr + mb_l, pcc);
2678 nc = prev_c;
2679 pc1 = pcc[0];
2680 }
2681 prev_c = mb_c;
2682
2683 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2684 }
2685 else
2686 prev_c = mb_c;
2687#endif
2688 }
2689 else // enc_dbcs
2690 {
2691 mb_l = MB_BYTE2LEN(c);
2692 if (mb_l == 0) // at the NUL at end-of-line
2693 mb_l = 1;
2694 else if (mb_l > 1)
2695 {
2696 // We assume a second byte below 32 is illegal.
2697 // Hopefully this is OK for all double-byte encodings!
2698 if (ptr[1] >= 32)
2699 mb_c = (c << 8) + ptr[1];
2700 else
2701 {
2702 if (ptr[1] == NUL)
2703 {
2704 // head byte at end of line
2705 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002706 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002707 }
2708 else
2709 {
2710 // illegal tail byte
2711 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002712 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002713 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002714 wlv.p_extra = wlv.extra;
2715 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002716 wlv.c_extra = NUL;
2717 wlv.c_final = NUL;
2718 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002719 if (area_attr == 0 && search_attr == 0)
2720 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002721 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002722 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002723 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002724 // save current attr
2725 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002726 }
2727 mb_c = c;
2728 }
2729 }
2730 }
2731 // If a double-width char doesn't fit display a '>' in the
2732 // last column; the character is displayed at the start of the
2733 // next line.
2734 if ((
2735# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002736 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002737# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002738 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002739 && (*mb_char2cells)(mb_c) == 2)
2740 {
2741 c = '>';
2742 mb_c = c;
2743 mb_utf8 = FALSE;
2744 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002745 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002746 // Put pointer back so that the character will be
2747 // displayed at the start of the next line.
2748 --ptr;
2749#ifdef FEAT_CONCEAL
2750 did_decrement_ptr = TRUE;
2751#endif
2752 }
2753 else if (*ptr != NUL)
2754 ptr += mb_l - 1;
2755
2756 // If a double-width char doesn't fit at the left side display
2757 // a '<' in the first column. Don't do this for unprintable
2758 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002759 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002760 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002761 wlv.n_extra = 1;
2762 wlv.c_extra = MB_FILLER_CHAR;
2763 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002764 c = ' ';
2765 if (area_attr == 0 && search_attr == 0)
2766 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002767 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002768 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002769 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002770 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002771 }
2772 mb_c = c;
2773 mb_utf8 = FALSE;
2774 mb_l = 1;
2775 }
2776
2777 }
2778 ++ptr;
2779
2780 if (extra_check)
2781 {
2782#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002783 // Check spelling (unless at the end of the line).
2784 // Only do this when there is no syntax highlighting, the
2785 // @Spell cluster is not used or the current syntax item
2786 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002787 v = (long)(ptr - line);
Luuk van Baal30805a12023-05-27 22:22:10 +01002788 if (spv->spv_has_spell && v >= word_end && v > cur_checked_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002789 {
2790 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002791 // do not calculate cap_col at the end of the line or when
2792 // only white space is following
2793 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002794# ifdef FEAT_SYN_HL
2795 !has_syntax ||
2796# endif
2797 can_spell))
2798 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002799 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002800 int len;
2801 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002802
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002803 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002804 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002805
2806 // Use nextline[] if possible, it has the start of the
2807 // next line concatenated.
2808 if ((prev_ptr - line) - nextlinecol >= 0)
2809 p = nextline + (prev_ptr - line) - nextlinecol;
2810 else
2811 p = prev_ptr;
Luuk van Baal30805a12023-05-27 22:22:10 +01002812 spv->spv_cap_col -= (int)(prev_ptr - line);
2813 len = spell_check(wp, p, &spell_hlf, &spv->spv_cap_col,
2814 spv->spv_unchanged);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002815 word_end = v + len;
2816
2817 // In Insert mode only highlight a word that
2818 // doesn't touch the cursor.
2819 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002820 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002821 && wp->w_cursor.lnum == lnum
2822 && wp->w_cursor.col >=
2823 (colnr_T)(prev_ptr - line)
2824 && wp->w_cursor.col < (colnr_T)word_end)
2825 {
2826 spell_hlf = HLF_COUNT;
2827 spell_redraw_lnum = lnum;
2828 }
2829
2830 if (spell_hlf == HLF_COUNT && p != prev_ptr
2831 && (p - nextline) + len > nextline_idx)
2832 {
2833 // Remember that the good word continues at the
2834 // start of the next line.
Luuk van Baal30805a12023-05-27 22:22:10 +01002835 spv->spv_checked_lnum = lnum + 1;
2836 spv->spv_checked_col = (p - nextline) + len
2837 - nextline_idx;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002838 }
2839
2840 // Turn index into actual attributes.
2841 if (spell_hlf != HLF_COUNT)
2842 spell_attr = highlight_attr[spell_hlf];
2843
Luuk van Baal30805a12023-05-27 22:22:10 +01002844 if (spv->spv_cap_col > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002845 {
2846 if (p != prev_ptr
Luuk van Baal30805a12023-05-27 22:22:10 +01002847 && (p - nextline) + spv->spv_cap_col
2848 >= nextline_idx)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002849 {
2850 // Remember that the word in the next line
2851 // must start with a capital.
Luuk van Baal30805a12023-05-27 22:22:10 +01002852 spv->spv_capcol_lnum = lnum + 1;
2853 spv->spv_cap_col = ((p - nextline)
2854 + spv->spv_cap_col - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002855 }
2856 else
2857 // Compute the actual column.
Luuk van Baal30805a12023-05-27 22:22:10 +01002858 spv->spv_cap_col += (prev_ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002859 }
2860 }
2861 }
2862 if (spell_attr != 0)
2863 {
2864 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002865 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2866 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002867 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002868 wlv.char_attr = hl_combine_attr(spell_attr,
2869 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002870 }
2871#endif
2872#ifdef FEAT_LINEBREAK
2873 // Found last space before word: check for line break.
2874 if (wp->w_p_lbr && c0 == c
2875 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2876 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002877 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2878 : 0;
2879 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002880 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002881
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002882 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002883# ifdef FEAT_PROP_POPUP
2884 // do not want virtual text counted here
2885 cts.cts_has_prop_with_text = FALSE;
2886# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002887 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002888 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002889
2890 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002891 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002892 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002893 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002894 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2895 if (wlv.n_extra < 0)
2896 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002897 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002898 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002899 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002900 // line break, but for TABs the highlighting should
2901 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002902 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002903
Bram Moolenaar1306b362022-08-06 15:59:06 +01002904 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002905# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002906 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002907 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002908 wp->w_buffer->b_p_vts_array) - 1;
2909# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002910 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002911 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002912# endif
2913
Bram Moolenaar1306b362022-08-06 15:59:06 +01002914 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2915 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002916# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002917 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002918 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002919# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002920 if (VIM_ISWHITE(c))
2921 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002922# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002923 if (c == TAB)
2924 // See "Tab alignment" below.
2925 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002926# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002927 if (!wp->w_p_list)
2928 c = ' ';
2929 }
2930 }
2931#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002932 in_multispace = c == ' '
2933 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2934 if (!in_multispace)
2935 multispace_pos = 0;
2936
Bram Moolenaareed9d462021-02-15 20:38:25 +01002937 // 'list': Change char 160 to 'nbsp' and space to 'space'
2938 // setting in 'listchars'. But not when the character is
2939 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002940 if (wp->w_p_list
2941 && ((((c == 160 && mb_l == 1)
2942 || (mb_utf8
2943 && ((mb_c == 160 && mb_l == 2)
2944 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002945 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002946 || (c == ' '
2947 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002948 && (wp->w_lcs_chars.space
2949 || (in_multispace
2950 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002951 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002952 && ptr - line <= trailcol)))
2953 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002954 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2955 {
2956 c = wp->w_lcs_chars.multispace[multispace_pos++];
2957 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2958 multispace_pos = 0;
2959 }
2960 else
2961 c = (c == ' ') ? wp->w_lcs_chars.space
2962 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002963 if (area_attr == 0 && search_attr == 0)
2964 {
2965 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002966 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002967 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002968 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002969 }
2970 mb_c = c;
2971 if (enc_utf8 && utf_char2len(c) > 1)
2972 {
2973 mb_utf8 = TRUE;
2974 u8cc[0] = 0;
2975 c = 0xc0;
2976 }
2977 else
2978 mb_utf8 = FALSE;
2979 }
2980
zeertzjq2e7cba32022-06-10 15:30:32 +01002981 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2982 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002983 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002984 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2985 && wp->w_lcs_chars.leadmultispace != NULL)
2986 {
2987 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002988 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2989 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002990 multispace_pos = 0;
2991 }
2992
2993 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2994 c = wp->w_lcs_chars.trail;
2995
2996 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2997 c = wp->w_lcs_chars.lead;
2998
zeertzjq2e7cba32022-06-10 15:30:32 +01002999 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003000 c = wp->w_lcs_chars.space;
3001
3002
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003003 if (!attr_pri)
3004 {
3005 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003006 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003007 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003008 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003009 }
3010 mb_c = c;
3011 if (enc_utf8 && utf_char2len(c) > 1)
3012 {
3013 mb_utf8 = TRUE;
3014 u8cc[0] = 0;
3015 c = 0xc0;
3016 }
3017 else
3018 mb_utf8 = FALSE;
3019 }
3020 }
3021
3022 // Handling of non-printable characters.
3023 if (!vim_isprintc(c))
3024 {
3025 // when getting a character from the file, we may have to
3026 // turn it into something else on the way to putting it
3027 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01003028 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003029 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003030 int tab_len = 0;
3031 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003032#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003033 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01003034
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003035 // only adjust the tab_len, when at the first column
3036 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01003037 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003038 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003039#endif
3040 // tab amount depends on current column
3041#ifdef FEAT_VARTABS
3042 tab_len = tabstop_padding(vcol_adjusted,
3043 wp->w_buffer->b_p_ts,
3044 wp->w_buffer->b_p_vts_array) - 1;
3045#else
3046 tab_len = (int)wp->w_buffer->b_p_ts
3047 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
3048#endif
3049
3050#ifdef FEAT_LINEBREAK
3051 if (!wp->w_p_lbr || !wp->w_p_list)
3052#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003053 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003054 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01003055 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003056 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003057#ifdef FEAT_LINEBREAK
3058 else
3059 {
3060 char_u *p;
3061 int len;
3062 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003063 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003064
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003065# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003066 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003067 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003068 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003069
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003070 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003071 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003072 && old_boguscols > 0
3073 && wlv.n_extra > tab_len)
3074 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003075# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003076 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003077 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003078 // If wlv.n_extra > 0, it gives the number of chars
3079 // to use for a tab, else we need to calculate the
3080 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003081 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3082 len = tab_len * tab2_len;
3083 if (wp->w_lcs_chars.tab3)
3084 len += mb_char2len(wp->w_lcs_chars.tab3)
3085 - tab2_len;
3086 if (wlv.n_extra > 0)
3087 len += wlv.n_extra - tab_len;
3088 c = wp->w_lcs_chars.tab1;
3089 p = alloc(len + 1);
3090 if (p == NULL)
3091 wlv.n_extra = 0;
3092 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003093 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003094 vim_memset(p, ' ', len);
3095 p[len] = NUL;
3096 vim_free(wlv.p_extra_free);
3097 wlv.p_extra_free = p;
3098 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003099 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003100 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003101
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003102 if (*p == NUL)
3103 {
3104 tab_len = i;
3105 break;
3106 }
3107
3108 // if tab3 is given, use it for the last
3109 // char
3110 if (wp->w_lcs_chars.tab3
3111 && i == tab_len - 1)
3112 lcs = wp->w_lcs_chars.tab3;
3113 p += mb_char2bytes(lcs, p);
3114 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003115 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003116 }
3117 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003118# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003119 // n_extra will be increased by
3120 // FIX_FOX_BOGUSCOLS macro below, so need to
3121 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003122 if (wlv.vcol_off_co > 0)
3123 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003124# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003125 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003126 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003127 }
3128#endif
3129#ifdef FEAT_CONCEAL
3130 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003131 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003132
3133 // Tab alignment should be identical regardless of
3134 // 'conceallevel' value. So tab compensates of all
3135 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003136 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003137 // line. Note that the tab can be longer than
3138 // 'tabstop' when there are concealed characters.
3139 FIX_FOR_BOGUSCOLS;
3140
3141 // Make sure, the highlighting for the tab char will be
3142 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003143 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003144 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003145 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003146 tab_len += vc_saved;
3147 }
3148#endif
3149 mb_utf8 = FALSE; // don't draw as UTF-8
3150 if (wp->w_p_list)
3151 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003152 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003153 ? wp->w_lcs_chars.tab3
3154 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003155#ifdef FEAT_LINEBREAK
h-east194555c2023-03-02 18:49:09 +00003156 if (wp->w_p_lbr && wlv.p_extra != NULL
3157 && *wlv.p_extra != NUL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003158 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003159 else
3160#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003161 wlv.c_extra = wp->w_lcs_chars.tab2;
3162 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003163 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003164 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003165 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003166 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003167 mb_c = c;
3168 if (enc_utf8 && utf_char2len(c) > 1)
3169 {
3170 mb_utf8 = TRUE;
3171 u8cc[0] = 0;
3172 c = 0xc0;
3173 }
3174 }
3175 else
3176 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003177 wlv.c_final = NUL;
3178 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003179 c = ' ';
3180 }
3181 }
3182 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003183 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003184 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003185 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3186 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003187 && VIsual_mode != Ctrl_V
3188 && (
3189# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003190 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003191# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003192 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003193 && !(noinvcur
3194 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003195 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003196 && lcs_eol_one > 0)
3197 {
3198 // Display a '$' after the line or highlight an extra
3199 // character if the line break is included.
3200#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3201 // For a diff line the highlighting continues after the
3202 // "$".
3203 if (
3204# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003205 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003206# ifdef LINE_ATTR
3207 &&
3208# endif
3209# endif
3210# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003211 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003212# endif
3213 )
3214#endif
3215 {
3216 // In virtualedit, visual selections may extend
3217 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003218 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003219 && wlv.tocol != MAXCOL
3220 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003221 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003222 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003223 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003224 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3225 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003226 else
3227 c = ' ';
3228 lcs_eol_one = -1;
3229 --ptr; // put it back at the NUL
3230 if (!attr_pri)
3231 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003232 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003233 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003234 n_attr = 1;
3235 }
3236 mb_c = c;
3237 if (enc_utf8 && utf_char2len(c) > 1)
3238 {
3239 mb_utf8 = TRUE;
3240 u8cc[0] = 0;
3241 c = 0xc0;
3242 }
3243 else
3244 mb_utf8 = FALSE; // don't draw as UTF-8
3245 }
3246 else if (c != NUL)
3247 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003248 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3249 if (wlv.n_extra == 0)
3250 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003251#ifdef FEAT_RIGHTLEFT
3252 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003253 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003254#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003255 wlv.c_extra = NUL;
3256 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003257#ifdef FEAT_LINEBREAK
3258 if (wp->w_p_lbr)
3259 {
3260 char_u *p;
3261
Bram Moolenaar1306b362022-08-06 15:59:06 +01003262 c = *wlv.p_extra;
3263 p = alloc(wlv.n_extra + 1);
3264 vim_memset(p, ' ', wlv.n_extra);
3265 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3266 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003267 vim_free(wlv.p_extra_free);
3268 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003269 }
3270 else
3271#endif
3272 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003273 wlv.n_extra = byte2cells(c) - 1;
3274 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003275 }
3276 if (!attr_pri)
3277 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003278 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003279 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003280 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003281 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003282 }
3283 mb_utf8 = FALSE; // don't draw as UTF-8
3284 }
3285 else if (VIsual_active
3286 && (VIsual_mode == Ctrl_V
3287 || VIsual_mode == 'v')
3288 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003289 && wlv.tocol != MAXCOL
3290 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003291 && (
3292#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003293 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003294#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003295 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003296 {
3297 c = ' ';
3298 --ptr; // put it back at the NUL
3299 }
3300#if defined(LINE_ATTR)
3301 else if ((
3302# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003303 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003304# endif
3305# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003306 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003307# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003308 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003309 ) && (
3310# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003311 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003312# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003313 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003314# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003315 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003316# endif
3317 < wp->w_width)))
3318 {
3319 // Highlight until the right side of the window
3320 c = ' ';
3321 --ptr; // put it back at the NUL
3322
3323 // Remember we do the char for line highlighting.
3324 ++did_line_attr;
3325
3326 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003327 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003328 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003329 || (wp->w_p_list &&
3330 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003331 wlv.char_attr = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003332# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003333 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003334 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003335 wlv.diff_hlf = HLF_CHD;
3336 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003337 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003338 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003339 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3340 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003341 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003342 || (wlv.vcol >= left_curline_col
3343 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003344 wlv.char_attr = hl_combine_attr(
3345 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003346 }
3347 }
3348# endif
3349# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003350 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003351 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003352 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003353 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3354 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003355 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003356 if (!wlv.cul_screenline
3357 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003358 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003359 wlv.char_attr = hl_combine_attr(
3360 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003361 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003362 else if (wlv.line_attr)
3363 wlv.char_attr = hl_combine_attr(
3364 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003365 }
3366# endif
3367 }
3368#endif
3369 }
3370
3371#ifdef FEAT_CONCEAL
3372 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003373 && (wp != curwin || lnum != wp->w_cursor.lnum
3374 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003375 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3376 && !(lnum_in_visual_area
3377 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3378 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003379 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003380 if (((prev_syntax_id != syntax_seqnr
3381 && (syntax_flags & HL_CONCEAL) != 0)
3382 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003383 && (syn_get_sub_char() != NUL
3384 || (has_match_conc && match_conc)
3385 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003386 && wp->w_p_cole != 3)
3387 {
3388 // First time at this concealed item: display one
3389 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003390 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003391 c = match_conc;
3392 else if (syn_get_sub_char() != NUL)
3393 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003394 else if (wp->w_lcs_chars.conceal != NUL)
3395 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003396 else
3397 c = ' ';
3398
3399 prev_syntax_id = syntax_seqnr;
3400
Bram Moolenaar1306b362022-08-06 15:59:06 +01003401 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003402 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003403 wlv.vcol += wlv.n_extra;
3404 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003405 {
3406# ifdef FEAT_RIGHTLEFT
3407 if (wp->w_p_rl)
3408 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003409 wlv.col -= wlv.n_extra;
3410 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003411 }
3412 else
3413# endif
3414 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003415 wlv.boguscols += wlv.n_extra;
3416 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003417 }
3418 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003419 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003420 n_attr = 0;
3421 }
3422 else if (n_skip == 0)
3423 {
3424 is_concealing = TRUE;
3425 n_skip = 1;
3426 }
3427 mb_c = c;
3428 if (enc_utf8 && utf_char2len(c) > 1)
3429 {
3430 mb_utf8 = TRUE;
3431 u8cc[0] = 0;
3432 c = 0xc0;
3433 }
3434 else
3435 mb_utf8 = FALSE; // don't draw as UTF-8
3436 }
3437 else
3438 {
3439 prev_syntax_id = 0;
3440 is_concealing = FALSE;
3441 }
3442
3443 if (n_skip > 0 && did_decrement_ptr)
3444 // not showing the '>', put pointer back to avoid getting stuck
3445 ++ptr;
3446
3447#endif // FEAT_CONCEAL
3448 }
3449
3450#ifdef FEAT_CONCEAL
3451 // In the cursor line and we may be concealing characters: correct
3452 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003453 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003454 && wp == curwin && lnum == wp->w_cursor.lnum
3455 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003456 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003457 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003458# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003459 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003460 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003461 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003462# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003463 wp->w_wcol = wlv.col - wlv.boguscols;
3464 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003465 did_wcol = TRUE;
3466 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003467# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003468 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003469# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003470 }
3471#endif
3472
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003473 // Use "wlv.extra_attr", but don't override visual selection
3474 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003475 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3476 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003477 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003478 && (!attr_pri
3479#ifdef FEAT_PROP_POPUP
3480 || (text_prop_flags & PT_FLAG_OVERRIDE)
3481#endif
3482 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003483 {
3484#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003485 if (wlv.line_attr)
3486 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003487 else
3488#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003489 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003490#ifdef FEAT_PROP_POPUP
3491 if (reset_extra_attr)
3492 {
3493 reset_extra_attr = FALSE;
3494 wlv.extra_attr = 0;
3495 }
3496#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003497 }
3498
3499#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3500 // XIM don't send preedit_start and preedit_end, but they send
3501 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3502 // im_is_preediting() here.
3503 if (p_imst == IM_ON_THE_SPOT
3504 && xic != NULL
3505 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003506 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003507 && !p_imdisable
3508 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003509 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003510 {
3511 colnr_T tcol;
3512
3513 if (preedit_end_col == MAXCOL)
3514 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3515 else
3516 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003517 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003518 {
3519 if (feedback_old_attr < 0)
3520 {
3521 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003522 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003523 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003524 wlv.char_attr = im_get_feedback_attr(feedback_col);
3525 if (wlv.char_attr < 0)
3526 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003527 feedback_col++;
3528 }
3529 else if (feedback_old_attr >= 0)
3530 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003531 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003532 feedback_old_attr = -1;
3533 feedback_col = 0;
3534 }
3535 }
3536#endif
3537 // Handle the case where we are in column 0 but not on the first
3538 // character of the line and the user wants us to show us a
3539 // special character (via 'listchars' option "precedes:<char>".
3540 if (lcs_prec_todo != NUL
3541 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003542 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3543 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003544#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003545 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003546#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003547 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003548 && c != NUL)
3549 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003550 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003551 lcs_prec_todo = NUL;
3552 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3553 {
3554 // Double-width character being overwritten by the "precedes"
3555 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003556 wlv.c_extra = MB_FILLER_CHAR;
3557 wlv.c_final = NUL;
3558 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003559 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003560 wlv.extra_attr =
3561 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003562 }
3563 mb_c = c;
3564 if (enc_utf8 && utf_char2len(c) > 1)
3565 {
3566 mb_utf8 = TRUE;
3567 u8cc[0] = 0;
3568 c = 0xc0;
3569 }
3570 else
3571 mb_utf8 = FALSE; // don't draw as UTF-8
3572 if (!attr_pri)
3573 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003574 saved_attr3 = wlv.char_attr; // save current attr
3575 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003576 n_attr3 = 1;
3577 }
3578 }
3579
3580 // At end of the text line or just after the last character.
3581 if ((c == NUL
3582#if defined(LINE_ATTR)
3583 || did_line_attr == 1
3584#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003585 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003586 {
3587#ifdef FEAT_SEARCH_EXTRA
3588 // flag to indicate whether prevcol equals startcol of search_hl or
3589 // one of the matches
3590 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3591 (long)(ptr - line) - (c == NUL));
3592#endif
3593 // Invert at least one char, used for Visual and empty line or
3594 // highlight match at end of line. If it's beyond the last
3595 // char on the screen, just overwrite that one (tricky!) Not
3596 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003597 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003598 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003599 && (VIsual_mode != Ctrl_V
3600 || lnum == VIsual.lnum
3601 || lnum == curwin->w_cursor.lnum)
3602 && c == NUL)
3603#ifdef FEAT_SEARCH_EXTRA
3604 // highlight 'hlsearch' match at end of line
3605 || (prevcol_hl_flag
3606# ifdef FEAT_SYN_HL
3607 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3608 && !(wp == curwin && VIsual_active))
3609# endif
3610# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003611 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003612# endif
3613# if defined(LINE_ATTR)
3614 && did_line_attr <= 1
3615# endif
3616 )
3617#endif
3618 ))
3619 {
3620 int n = 0;
3621
3622#ifdef FEAT_RIGHTLEFT
3623 if (wp->w_p_rl)
3624 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003625 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003626 n = 1;
3627 }
3628 else
3629#endif
3630 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003631 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003632 n = -1;
3633 }
3634 if (n != 0)
3635 {
3636 // At the window boundary, highlight the last character
3637 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003638 wlv.off += n;
3639 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003640 }
3641 else
3642 {
3643 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003644 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003645 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003646 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003647 }
3648#ifdef FEAT_SEARCH_EXTRA
3649 if (area_attr == 0)
3650 {
3651 // Use attributes from match with highest priority among
3652 // 'search_hl' and the match list.
3653 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003654 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003655 }
3656#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003657 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003658 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003659#ifdef FEAT_RIGHTLEFT
3660 if (wp->w_p_rl)
3661 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003662 --wlv.col;
3663 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003664 }
3665 else
3666#endif
3667 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003668 ++wlv.col;
3669 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003670 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003671 ++wlv.vcol;
3672 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003673 }
3674 }
3675
3676 // At end of the text line.
3677 if (c == NUL)
3678 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003679#ifdef FEAT_PROP_POPUP
3680 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003681 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003682 // Put the pointer back to the NUL.
3683 --ptr;
3684 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003685 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003686 else
3687#endif
3688 {
3689 draw_screen_line(wp, &wlv);
3690
3691 // Update w_cline_height and w_cline_folded if the cursor line
3692 // was updated (saves a call to plines() later).
3693 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3694 {
3695 curwin->w_cline_row = startrow;
3696 curwin->w_cline_height = wlv.row - startrow;
3697#ifdef FEAT_FOLDING
3698 curwin->w_cline_folded = FALSE;
3699#endif
3700 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3701 }
3702 break;
3703 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003704 }
3705
3706 // Show "extends" character from 'listchars' if beyond the line end and
3707 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003708 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003709 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003710 && wp->w_p_list
3711 && !wp->w_p_wrap
3712#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003713 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003714#endif
3715 && (
3716#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003717 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003718#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003719 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003720 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003721 || lcs_eol_one > 0
3722 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003723 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003724 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003725 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003726 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003727 mb_c = c;
3728 if (enc_utf8 && utf_char2len(c) > 1)
3729 {
3730 mb_utf8 = TRUE;
3731 u8cc[0] = 0;
3732 c = 0xc0;
3733 }
3734 else
3735 mb_utf8 = FALSE;
3736 }
3737
3738#ifdef FEAT_SYN_HL
3739 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003740 if (wlv.draw_color_col)
3741 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003742
3743 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3744 // highlight the cursor position itself.
3745 // Also highlight the 'colorcolumn' if it is different than
3746 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003747 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3748 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003749 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003750 if (((wlv.draw_state == WL_LINE
3751 || wlv.draw_state == WL_BRI
3752 || wlv.draw_state == WL_SBR)
3753 && !lnum_in_visual_area
3754 && search_attr == 0
3755 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003756# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003757 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003758# endif
3759 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003760 {
3761 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3762 && lnum != wp->w_cursor.lnum)
3763 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003764 vcol_save_attr = wlv.char_attr;
3765 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3766 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003767 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003768 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003769 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003770 vcol_save_attr = wlv.char_attr;
3771 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003772 }
3773 }
3774#endif
3775
3776 // Store character to be displayed.
3777 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003778 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003779 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003780 {
3781 // Store the character.
3782#if defined(FEAT_RIGHTLEFT)
3783 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3784 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003785 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003786 --wlv.off;
3787 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003788 }
3789#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003790 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003791 if (enc_dbcs == DBCS_JPNU)
3792 {
3793 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003794 ScreenLines[wlv.off] = 0x8e;
3795 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003796 }
3797 else if (enc_utf8)
3798 {
3799 if (mb_utf8)
3800 {
3801 int i;
3802
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003803 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003804 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003805 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003806 for (i = 0; i < Screen_mco; ++i)
3807 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003808 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003809 if (u8cc[i] == 0)
3810 break;
3811 }
3812 }
3813 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003814 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003815 }
3816 if (multi_attr)
3817 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003818 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003819 multi_attr = 0;
3820 }
3821 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003822 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003823
zeertzjqe500ae82023-08-17 22:35:26 +02003824 ScreenCols[wlv.off] = wlv.vcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003825
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003826 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3827 {
3828 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003829 ++wlv.off;
3830 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003831 if (enc_utf8)
3832 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003833 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003834 else
3835 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003836 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003837 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003838#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003839 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003840#endif
3841 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003842 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003843 // When "wlv.tocol" is halfway a character, set it to the end
3844 // of the character, otherwise highlighting won't stop.
3845 if (wlv.tocol == wlv.vcol)
3846 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003847
zeertzjqe500ae82023-08-17 22:35:26 +02003848 ScreenCols[wlv.off] = wlv.vcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003849
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003850#ifdef FEAT_RIGHTLEFT
3851 if (wp->w_p_rl)
3852 {
3853 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003854 --wlv.off;
3855 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003856 }
3857#endif
3858 }
3859#ifdef FEAT_RIGHTLEFT
3860 if (wp->w_p_rl)
3861 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003862 --wlv.off;
3863 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003864 }
3865 else
3866#endif
3867 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003868 ++wlv.off;
3869 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003870 }
3871 }
3872#ifdef FEAT_CONCEAL
3873 else if (wp->w_p_cole > 0 && is_concealing)
3874 {
3875 --n_skip;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003876 ++wlv.vcol_off_co;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003877 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003878 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003879 if (wp->w_p_wrap)
3880 {
3881 // Special voodoo required if 'wrap' is on.
3882 //
3883 // Advance the column indicator to force the line
3884 // drawing to wrap early. This will make the line
3885 // take up the same screen space when parts are concealed,
3886 // so that cursor line computations aren't messed up.
3887 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003888 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003889 // trailing junk to be written out of the screen line
3890 // we are building, 'boguscols' keeps track of the number
3891 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003892 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003893 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003894 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003895# ifdef FEAT_RIGHTLEFT
3896 if (wp->w_p_rl)
3897 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003898 wlv.col -= wlv.n_extra;
3899 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003900 }
3901 else
3902# endif
3903 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003904 wlv.col += wlv.n_extra;
3905 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003906 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003907 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003908 n_attr = 0;
3909 }
3910
3911
3912 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3913 {
3914 // Need to fill two screen columns.
3915# ifdef FEAT_RIGHTLEFT
3916 if (wp->w_p_rl)
3917 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003918 --wlv.boguscols;
3919 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003920 }
3921 else
3922# endif
3923 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003924 ++wlv.boguscols;
3925 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003926 }
3927 }
3928
3929# ifdef FEAT_RIGHTLEFT
3930 if (wp->w_p_rl)
3931 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003932 --wlv.boguscols;
3933 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003934 }
3935 else
3936# endif
3937 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003938 ++wlv.boguscols;
3939 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003940 }
3941 }
3942 else
3943 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003944 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003945 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003946 wlv.vcol += wlv.n_extra;
3947 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003948 n_attr = 0;
3949 }
3950 }
3951
3952 }
3953#endif // FEAT_CONCEAL
3954 else
3955 --n_skip;
3956
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003957 // Only advance the "wlv.vcol" when after the 'number' or
3958 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003959 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003960#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003961 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003962#endif
3963 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003964 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003965
3966#ifdef FEAT_SYN_HL
3967 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003968 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003969#endif
3970
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003971 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003972 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3973 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003974
3975 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003976 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003977 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003978 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003979 if (wlv.n_attr_skip > 0)
3980 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003981
3982 // At end of screen line and there is more to come: Display the line
3983 // so far. If there is no more to display it is caught above.
3984 if ((
3985#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003986 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003987#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003988 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003989 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003990 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003991#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003992 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003993#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003994#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003995 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003996#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003997 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003998 && wlv.p_extra != at_end_str)
3999 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
4000 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004001 )
4002 {
4003#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01004004 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01004005 wlv_screen_line(wp, &wlv, FALSE);
4006 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004007 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004008 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004009#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01004010 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004011#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004012 ++wlv.row;
4013 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004014
4015 // When not wrapping and finished diff lines, or when displayed
4016 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01004017 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004018#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004019 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004020#endif
4021#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01004022 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004023#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01004024 ) || lcs_eol_one == -1)
4025#ifdef FEAT_PROP_POPUP
4026 && !text_prop_follows
4027#endif
4028 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004029 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004030#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004031 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004032 {
4033 // do not output more of the line, only the "below" prop
4034 ptr += STRLEN(ptr);
4035# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004036 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004037# endif
4038 }
4039#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004040
4041 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004042 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004043#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004044 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004045#endif
4046 )
4047 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004048 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
4049 draw_vsep_win(wp, wlv.row);
4050 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004051 }
4052
4053 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004054 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004055 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004056 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004057 break;
4058 }
4059
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004060 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004061#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004062 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004063#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004064#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004065 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004066#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004067 && wp->w_width == Columns)
4068 {
4069 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004070 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004071
4072 // Special trick to make copy/paste of wrapped lines work with
4073 // xterm/screen: write an extra character beyond the end of
4074 // the line. This will work with all terminal types
4075 // (regardless of the xn,am settings).
4076 // Only do this on a fast tty.
4077 // Only do this if the cursor is on the current line
4078 // (something has been written in it).
4079 // Don't do this for the GUI.
4080 // Don't do this for double-width characters.
4081 // Don't do this for a window not at the right screen border.
4082 if (p_tf
4083#ifdef FEAT_GUI
4084 && !gui.in_use
4085#endif
4086 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004087 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4088 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004089 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004090 || (*mb_off2cells)(
4091 LineOffset[wlv.screen_row - 1]
4092 + (int)Columns - 2,
4093 LineOffset[wlv.screen_row]
4094 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004095 {
4096 // First make sure we are at the end of the screen line,
4097 // then output the same character again to let the
4098 // terminal know about the wrap. If the terminal doesn't
4099 // auto-wrap, we overwrite the character.
4100 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004101 screen_char(LineOffset[wlv.screen_row - 1]
4102 + (unsigned)Columns - 1,
4103 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004104
4105 // When there is a multi-byte character, just output a
4106 // space to keep it simple.
4107 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004108 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004109 out_char(' ');
4110 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004111 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004112 + (Columns - 1)]);
4113 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004114 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004115 screen_start(); // don't know where cursor is now
4116 }
4117 }
4118
Bram Moolenaar1306b362022-08-06 15:59:06 +01004119 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004120
Bram Moolenaareed9d462021-02-15 20:38:25 +01004121 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004122#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004123 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004124# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004125 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004126# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004127 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004128 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004129#endif
4130#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004131 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004132 // When the filler lines are actually below the last line of the
4133 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004134 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004135 break;
4136#endif
4137 }
4138
4139 } // for every character in the line
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004140#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004141 vim_free(text_props);
4142 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004143 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004144#endif
4145
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004146 vim_free(wlv.p_extra_free);
zeertzjq58e1e012023-06-04 18:46:28 +01004147 vim_free(wlv.saved_p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004148 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004149}