blob: 63bc96c4da08170b033d403ec182e70a2fb49be9 [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
zeertzjqb557f482023-08-22 22:07:34 +02001113 int skip_cells = 0; // nr of cells to skip for w_leftcol or
1114 // w_skipcol or concealing
1115 int skipped_cells = 0; // nr of skipped cells for virtual text
1116 // to be added to wlv.vcol later
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001117 int fromcol_prev = -2; // start of inverting after cursor
1118 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001119 int lnum_in_visual_area = FALSE;
1120 pos_T pos;
1121 long v;
1122
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001123 int attr_pri = FALSE; // char_attr has priority
1124 int area_highlighting = FALSE; // Visual or incsearch highlighting
1125 // in this line
1126 int vi_attr = 0; // attributes for Visual and incsearch
1127 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001128 int area_attr = 0; // attributes desired by highlighting
1129 int search_attr = 0; // attributes desired by 'hlsearch'
1130#ifdef FEAT_SYN_HL
1131 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1132 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001133 int prev_syntax_col = -1; // column of prev_syntax_attr
1134 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001135 int has_syntax = FALSE; // this buffer has syntax highl.
1136 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001137#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001138#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001139 int did_line = FALSE; // set to TRUE when line text done
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001140 int text_prop_count;
1141 int text_prop_next = 0; // next text property to use
1142 textprop_T *text_props = NULL;
1143 int *text_prop_idxs = NULL;
1144 int text_props_active = 0;
1145 proptype_T *text_prop_type = NULL;
1146 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001147 int text_prop_attr_comb = 0; // text_prop_attr combined with
1148 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001149 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001150 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001151 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001152 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001153 int saved_search_attr = 0; // search_attr to be used when n_extra
1154 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001155 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001156 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001157#endif
1158#ifdef FEAT_SPELL
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001159 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001160# define SPWORDLEN 150
1161 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1162 int nextlinecol = 0; // column where nextline[] starts
1163 int nextline_idx = 0; // index in nextline[] where next line
1164 // starts
1165 int spell_attr = 0; // attributes desired by spelling
1166 int word_end = 0; // last byte with same spell_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001167 int cur_checked_col = 0; // checked column for current line
1168#endif
1169 int extra_check = 0; // has extra highlighting
1170 int multi_attr = 0; // attributes desired by multibyte
1171 int mb_l = 1; // multi-byte byte length
1172 int mb_c = 0; // decoded multi-byte character
1173 int mb_utf8 = FALSE; // screen char is UTF-8 char
1174 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001175#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001176 int change_start = MAXCOL; // first col of changed area
1177 int change_end = -1; // last col of changed area
1178#endif
1179 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001180 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001181 int in_multispace = FALSE; // in multiple consecutive spaces
1182 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001183#ifdef LINE_ATTR
Bram Moolenaarbf915842022-08-06 22:38:02 +01001184 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001185#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001186 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001187 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001188#ifdef FEAT_ARABIC
1189 int prev_c = 0; // previous Arabic character
1190 int prev_c1 = 0; // first composing char for prev_c
1191#endif
1192#if defined(LINE_ATTR)
1193 int did_line_attr = 0;
1194#endif
1195#ifdef FEAT_TERMINAL
1196 int get_term_attr = FALSE;
1197#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001198
Martin Tournoijba43e762022-10-13 22:12:15 +01001199#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001200 // margin columns for the screen line, needed for when 'cursorlineopt'
1201 // contains "screenline"
1202 int left_curline_col = 0;
1203 int right_curline_col = 0;
1204#endif
1205
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001206#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1207 int feedback_col = 0;
1208 int feedback_old_attr = -1;
1209#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001210
1211#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1212 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001213#endif
1214#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001215 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001216#endif
1217#ifdef FEAT_CONCEAL
1218 int syntax_flags = 0;
1219 int syntax_seqnr = 0;
1220 int prev_syntax_id = 0;
1221 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1222 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001223 int did_wcol = FALSE;
1224 int old_boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001225# define VCOL_HLC (wlv.vcol - wlv.vcol_off_co - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001226# define FIX_FOR_BOGUSCOLS \
1227 { \
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001228 wlv.n_extra += wlv.vcol_off_co; \
1229 wlv.vcol -= wlv.vcol_off_co; \
1230 wlv.vcol_off_co = 0; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001231 wlv.col -= wlv.boguscols; \
1232 old_boguscols = wlv.boguscols; \
1233 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001234 }
1235#else
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001236# define VCOL_HLC (wlv.vcol - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001237#endif
1238
1239 if (startrow > endrow) // past the end already!
1240 return startrow;
1241
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001242 CLEAR_FIELD(wlv);
1243
1244 wlv.lnum = lnum;
1245 wlv.startrow = startrow;
1246 wlv.row = startrow;
1247 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001248 wlv.fromcol = -10;
1249 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001250#ifdef FEAT_LINEBREAK
1251 wlv.vcol_sbr = -1;
1252#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001253
1254 if (!number_only)
1255 {
1256 // To speed up the loop below, set extra_check when there is linebreak,
1257 // trailing white space and/or syntax processing to be done.
1258#ifdef FEAT_LINEBREAK
1259 extra_check = wp->w_p_lbr;
1260#endif
1261#ifdef FEAT_SYN_HL
1262 if (syntax_present(wp) && !wp->w_s->b_syn_error
1263# ifdef SYN_TIME_LIMIT
1264 && !wp->w_s->b_syn_slow
1265# endif
1266 )
1267 {
1268 // Prepare for syntax highlighting in this line. When there is an
1269 // error, stop syntax highlighting.
1270 save_did_emsg = did_emsg;
1271 did_emsg = FALSE;
1272 syntax_start(wp, lnum);
1273 if (did_emsg)
1274 wp->w_s->b_syn_error = TRUE;
1275 else
1276 {
1277 did_emsg = save_did_emsg;
1278#ifdef SYN_TIME_LIMIT
1279 if (!wp->w_s->b_syn_slow)
1280#endif
1281 {
1282 has_syntax = TRUE;
1283 extra_check = TRUE;
1284 }
1285 }
1286 }
1287
1288 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001289 wlv.color_cols = wp->w_p_cc_cols;
1290 if (wlv.color_cols != NULL)
1291 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001292#endif
1293
1294#ifdef FEAT_TERMINAL
1295 if (term_show_buffer(wp->w_buffer))
1296 {
1297 extra_check = TRUE;
1298 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001299 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001300 }
1301#endif
1302
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001303 // handle Visual active in this window
1304 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1305 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001306 pos_T *top, *bot;
1307
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001308 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1309 {
1310 // Visual is after curwin->w_cursor
1311 top = &curwin->w_cursor;
1312 bot = &VIsual;
1313 }
1314 else
1315 {
1316 // Visual is before curwin->w_cursor
1317 top = &VIsual;
1318 bot = &curwin->w_cursor;
1319 }
1320 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1321 if (VIsual_mode == Ctrl_V)
1322 {
1323 // block mode
1324 if (lnum_in_visual_area)
1325 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001326 wlv.fromcol = wp->w_old_cursor_fcol;
1327 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001328 }
1329 }
1330 else
1331 {
1332 // non-block mode
1333 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001334 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001335 else if (lnum == top->lnum)
1336 {
1337 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001338 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001339 else
1340 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001341 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001342 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001343 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001344 }
1345 }
1346 if (VIsual_mode != 'V' && lnum == bot->lnum)
1347 {
1348 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1349 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001350 wlv.fromcol = -10;
1351 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001352 }
1353 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001354 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001355 else
1356 {
1357 pos = *bot;
1358 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001359 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1360 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001361 else
1362 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001363 getvvcol(wp, &pos, NULL, NULL,
1364 (colnr_T *)&wlv.tocol);
1365 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001366 }
1367 }
1368 }
1369 }
1370
1371 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001372 if (!highlight_match && lnum == curwin->w_cursor.lnum
1373 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001374#ifdef FEAT_GUI
1375 && !gui.in_use
1376#endif
1377 )
1378 noinvcur = TRUE;
1379
1380 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001381 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001382 {
1383 area_highlighting = TRUE;
1384 vi_attr = HL_ATTR(HLF_V);
1385#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1386 if ((clip_star.available && !clip_star.owned
1387 && clip_isautosel_star())
1388 || (clip_plus.available && !clip_plus.owned
1389 && clip_isautosel_plus()))
1390 vi_attr = HL_ATTR(HLF_VNC);
1391#endif
1392 }
1393 }
1394
1395 // handle 'incsearch' and ":s///c" highlighting
1396 else if (highlight_match
1397 && wp == curwin
1398 && lnum >= curwin->w_cursor.lnum
1399 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1400 {
1401 if (lnum == curwin->w_cursor.lnum)
1402 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001403 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001404 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001405 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001406 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1407 {
1408 pos.lnum = lnum;
1409 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001410 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001411 }
1412 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001413 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001414 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001415 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1416 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001417 area_highlighting = TRUE;
1418 vi_attr = HL_ATTR(HLF_I);
1419 }
1420 }
1421
1422#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001423 wlv.filler_lines = diff_check(wp, lnum);
1424 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001425 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001426 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001427 {
1428 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001429 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001430 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001431 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001432 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001433 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001434 }
1435 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001436 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001437 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001438 area_highlighting = TRUE;
1439 }
1440 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001441 wlv.filler_lines = wp->w_topfill;
1442 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001443#endif
1444
1445#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001446 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001447 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001448 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001449#endif
1450
1451#ifdef LINE_ATTR
1452# ifdef FEAT_SIGNS
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001453 // If this line has a sign with line highlighting set wlv.line_attr.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001454 if (sign_present)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001455 wlv.line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001456# endif
1457# if defined(FEAT_QUICKFIX)
1458 // Highlight the current line in the quickfix window.
1459 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001460 wlv.line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001461# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001462 if (wlv.line_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001463 area_highlighting = TRUE;
1464#endif
1465
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001466#ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01001467 if (spv->spv_has_spell && !number_only)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001468 {
Luuk van Baal30805a12023-05-27 22:22:10 +01001469 // Prepare for spell checking.
1470 extra_check = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001471
Luuk van Baal30805a12023-05-27 22:22:10 +01001472 // When a word wrapped from the previous line the start of the
1473 // current line is valid.
1474 if (lnum == spv->spv_checked_lnum)
1475 cur_checked_col = spv->spv_checked_col;
Luuk van Baale84c7732023-05-31 18:57:36 +01001476 // Previous line was not spell checked, check for capital. This happens
1477 // for the first line in an updated region or after a closed fold.
1478 if (spv->spv_capcol_lnum == 0 && check_need_cap(wp, lnum, 0))
1479 spv->spv_cap_col = 0;
1480 else if (lnum != spv->spv_capcol_lnum)
Luuk van Baal30805a12023-05-27 22:22:10 +01001481 spv->spv_cap_col = -1;
1482 spv->spv_checked_lnum = 0;
1483
Luuk van Baal30805a12023-05-27 22:22:10 +01001484 // Get the start of the next line, so that words that wrap to the
1485 // next line are found too: "et<line-break>al.".
1486 // Trick: skip a few chars for C/shell/Vim comments
1487 nextline[SPWORDLEN] = NUL;
1488 if (lnum < wp->w_buffer->b_ml.ml_line_count)
Luuk van Baale84c7732023-05-31 18:57:36 +01001489 {
1490 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1491 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1492 }
1493 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1494
1495 // If current line is empty, check first word in next line for capital.
1496 ptr = skipwhite(line);
1497 if (*ptr == NUL)
1498 {
1499 spv->spv_cap_col = 0;
1500 spv->spv_capcol_lnum = lnum + 1;
1501 }
1502 // For checking first word with a capital skip white space.
1503 else if (spv->spv_cap_col == 0)
1504 spv->spv_cap_col = ptr - line;
1505
Luuk van Baal30805a12023-05-27 22:22:10 +01001506 // Copy the end of the current line into nextline[].
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001507 if (nextline[SPWORDLEN] == NUL)
1508 {
1509 // No next line or it is empty.
1510 nextlinecol = MAXCOL;
1511 nextline_idx = 0;
1512 }
1513 else
1514 {
1515 v = (long)STRLEN(line);
1516 if (v < SPWORDLEN)
1517 {
1518 // Short line, use it completely and append the start of the
1519 // next line.
1520 nextlinecol = 0;
1521 mch_memmove(nextline, line, (size_t)v);
1522 STRMOVE(nextline + v, nextline + SPWORDLEN);
1523 nextline_idx = v + 1;
1524 }
1525 else
1526 {
1527 // Long line, use only the last SPWORDLEN bytes.
1528 nextlinecol = v - SPWORDLEN;
1529 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1530 nextline_idx = SPWORDLEN + 1;
1531 }
1532 }
1533 }
1534#endif
1535
Luuk van Baale84c7732023-05-31 18:57:36 +01001536 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1537 ptr = line;
1538
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001539 if (wp->w_p_list)
1540 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001541 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001542 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001543 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001544 || wp->w_lcs_chars.trail
1545 || wp->w_lcs_chars.lead
1546 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001547 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001548
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001549 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001550 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001551 {
1552 trailcol = (colnr_T)STRLEN(ptr);
1553 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1554 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001555 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001556 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001557 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001558 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001559 {
1560 leadcol = 0;
1561 while (VIM_ISWHITE(ptr[leadcol]))
1562 ++leadcol;
1563 if (ptr[leadcol] == NUL)
1564 // in a line full of spaces all of them are treated as trailing
1565 leadcol = (colnr_T)0;
1566 else
1567 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001568 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001569 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001570 }
1571
Bram Moolenaard7657e92022-09-20 18:59:30 +01001572 wlv.wcr_attr = get_wcr_attr(wp);
1573 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001574 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001575 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001576 area_highlighting = TRUE;
1577 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001578
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001579 // When w_skipcol is non-zero and there is virtual text above the actual
1580 // text, then this much of the virtual text is skipped.
1581 int skipcol_in_text_prop_above = 0;
1582
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001583#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001584 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001585 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001586
1587 char_u *prop_start;
1588 text_prop_count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE);
1589 if (text_prop_count > 0)
1590 {
1591 // Make a copy of the properties, so that they are properly
1592 // aligned.
1593 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1594 if (text_props != NULL)
1595 mch_memmove(text_props, prop_start,
1596 text_prop_count * sizeof(textprop_T));
1597
1598 // Allocate an array for the indexes.
1599 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1600 if (text_prop_idxs == NULL)
1601 VIM_CLEAR(text_props);
1602
1603 if (text_props != NULL)
1604 {
1605 area_highlighting = TRUE;
1606 extra_check = TRUE;
1607
1608 // When skipping virtual text the props need to be sorted. The
1609 // order is reversed!
1610 if (lnum == wp->w_topline && wp->w_skipcol > 0)
1611 {
1612 for (int i = 0; i < text_prop_count; ++i)
1613 text_prop_idxs[i] = i;
1614 sort_text_props(wp->w_buffer, text_props,
1615 text_prop_idxs, text_prop_count);
1616 }
1617
1618 // Text props "above" move the line number down to where the text
1619 // is. Only count the ones that are visible, not those that are
1620 // skipped because of w_skipcol.
1621 int text_width = wp->w_width - win_col_off(wp);
1622 for (int i = text_prop_count - 1; i >= 0; --i)
1623 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1624 {
1625 if (lnum == wp->w_topline
1626 && wp->w_skipcol - skipcol_in_text_prop_above
1627 >= text_width)
1628 {
1629 // This virtual text above is skipped, remove it from
1630 // the array.
1631 skipcol_in_text_prop_above += text_width;
1632 for (int j = i + 1; j < text_prop_count; ++j)
1633 text_props[j - 1] = text_props[j];
1634 ++i;
1635 --text_prop_count;
1636 }
1637 else
1638 ++wlv.text_prop_above_count;
1639 }
1640 }
1641 }
Bram Moolenaara572b932023-02-19 14:34:37 +00001642
1643 if (number_only)
1644 {
1645 // skip over rows only used for virtual text above
1646 wlv.row += wlv.text_prop_above_count;
1647 if (wlv.row > endrow)
1648 return wlv.row;
1649 wlv.screen_row += wlv.text_prop_above_count;
1650 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001651#endif
1652
1653 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1654 // first character to be displayed.
1655 if (wp->w_p_wrap)
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001656 v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001657 else
1658 v = wp->w_leftcol;
1659 if (v > 0 && !number_only)
1660 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001661 char_u *prev_ptr = ptr;
1662 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001663 int charsize = 0;
zeertzjqb557f482023-08-22 22:07:34 +02001664 int head = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001665
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001666 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
zeertzjqb557f482023-08-22 22:07:34 +02001667 cts.cts_max_head_vcol = v;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001668 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001669 {
zeertzjqb557f482023-08-22 22:07:34 +02001670 head = 0;
1671 charsize = win_lbr_chartabsize(&cts, &head);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001672 cts.cts_vcol += charsize;
1673 prev_ptr = cts.cts_ptr;
1674 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001675 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001676 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001677 ptr = cts.cts_ptr;
1678 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001679
1680 // When:
1681 // - 'cuc' is set, or
1682 // - 'colorcolumn' is set, or
1683 // - 'virtualedit' is set, or
1684 // - the visual mode is active,
1685 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001686 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001687#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001688 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001689#endif
1690 virtual_active() ||
1691 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001692 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001693
1694 // Handle a character that's not completely on the screen: Put ptr at
1695 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001696 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001697 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001698 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001699 ptr = prev_ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001700 }
zeertzjqb557f482023-08-22 22:07:34 +02001701 if (v > wlv.vcol)
1702 skip_cells = v - wlv.vcol - head;
Bram Moolenaarcd105412022-10-10 19:50:42 +01001703
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001704 // Adjust for when the inverted text is before the screen,
1705 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001706 if (wlv.tocol <= wlv.vcol)
1707 wlv.fromcol = 0;
1708 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1709 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001710
1711#ifdef FEAT_LINEBREAK
1712 // When w_skipcol is non-zero, first line needs 'showbreak'
1713 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001714 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001715#endif
1716#ifdef FEAT_SPELL
1717 // When spell checking a word we need to figure out the start of the
1718 // word and if it's badly spelled or not.
Luuk van Baal30805a12023-05-27 22:22:10 +01001719 if (spv->spv_has_spell)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001720 {
1721 int len;
1722 colnr_T linecol = (colnr_T)(ptr - line);
1723 hlf_T spell_hlf = HLF_COUNT;
1724
1725 pos = wp->w_cursor;
1726 wp->w_cursor.lnum = lnum;
1727 wp->w_cursor.col = linecol;
1728 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1729
1730 // spell_move_to() may call ml_get() and make "line" invalid
1731 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1732 ptr = line + linecol;
1733
1734 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1735 {
1736 // no bad word found at line start, don't check until end of a
1737 // word
1738 spell_hlf = HLF_COUNT;
1739 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1740 }
1741 else
1742 {
1743 // bad word found, use attributes until end of word
1744 word_end = wp->w_cursor.col + len + 1;
1745
1746 // Turn index into actual attributes.
1747 if (spell_hlf != HLF_COUNT)
1748 spell_attr = highlight_attr[spell_hlf];
1749 }
1750 wp->w_cursor = pos;
1751
1752# ifdef FEAT_SYN_HL
1753 // Need to restart syntax highlighting for this line.
1754 if (has_syntax)
1755 syntax_start(wp, lnum);
1756# endif
1757 }
1758#endif
1759 }
1760
1761 // Correct highlighting for cursor that can't be disabled.
1762 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001763 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001764 {
1765 if (noinvcur)
1766 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001767 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001768 {
1769 // highlighting starts at cursor, let it start just after the
1770 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001771 fromcol_prev = wlv.fromcol;
1772 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001773 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001774 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001775 // restart highlighting after the cursor
1776 fromcol_prev = wp->w_virtcol;
1777 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001778 if (wlv.fromcol >= wlv.tocol)
1779 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001780 }
1781
1782#ifdef FEAT_SEARCH_EXTRA
1783 if (!number_only)
1784 {
1785 v = (long)(ptr - line);
1786 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1787 &line, &screen_search_hl,
1788 &search_attr);
1789 ptr = line + v; // "line" may have been updated
1790 }
1791#endif
1792
1793#ifdef FEAT_SYN_HL
1794 // Cursor line highlighting for 'cursorline' in the current window.
1795 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1796 {
1797 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001798 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001799 if (!(wp == curwin && VIsual_active)
1800 && wp->w_p_culopt_flags != CULOPT_NBR)
1801 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001802 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001803 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1804
zeertzjqb7acea12022-12-12 13:20:43 +00001805 // Only apply CursorLine highlight here when "screenline" is not
1806 // present in 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001807 if (!wlv.cul_screenline)
zeertzjqb7acea12022-12-12 13:20:43 +00001808 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001809 else
1810 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001811 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001812 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1813 }
1814 area_highlighting = TRUE;
1815 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001816 }
1817#endif
1818
Bram Moolenaar1306b362022-08-06 15:59:06 +01001819 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001820
1821 // Repeat for the whole displayed line.
1822 for (;;)
1823 {
1824#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001825 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001826#endif
1827#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001828 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001829#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001830
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001831 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001832 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001833 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001834#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001835 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001836 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001837 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001838 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001839 }
1840#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001841 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001842 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001843 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001844 if (cmdwin_type != 0 && wp == curwin)
1845 {
1846 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001847 wlv.n_extra = 1;
1848 wlv.c_extra = cmdwin_type;
1849 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001850 wlv.char_attr =
1851 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001852 }
1853 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001854#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001855 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001856 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001857 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001858 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001859 }
1860#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001861#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001862 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001863 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001864 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001865 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001866 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001867 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001868 }
1869#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001870 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001871 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001872 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001873 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001874 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001875 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001876#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001877 // Check if 'breakindent' applies and show it.
1878 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1879 if (wlv.n_extra == 0)
1880 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001881#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001882#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001883 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001884 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001885 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001886 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001887 }
1888#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001889 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001890 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001891 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001892 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001893 }
1894 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001895
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001896#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001897 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001898 && wlv.vcol >= left_curline_col
1899 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001900 {
zeertzjqb7acea12022-12-12 13:20:43 +00001901 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001902 }
1903#endif
1904
1905 // When still displaying '$' of change command, stop at cursor.
1906 // When only displaying the (relative) line number and that's done,
1907 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001908 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001909 && lnum == wp->w_cursor.lnum
1910 && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001911 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001912#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001913 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001914#endif
1915 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001916 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001917 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001918 // Pretend we have finished updating the window. Except when
1919 // 'cursorcolumn' is set.
1920#ifdef FEAT_SYN_HL
1921 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001922 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001923 else
1924#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001925 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001926 break;
1927 }
1928
Bram Moolenaar1306b362022-08-06 15:59:06 +01001929 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001930 {
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001931#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001932 if (text_props != NULL)
1933 {
1934 int pi;
1935 int bcol = (int)(ptr - line);
1936
Bram Moolenaar1306b362022-08-06 15:59:06 +01001937 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001938# ifdef FEAT_LINEBREAK
1939 && !in_linebreak
1940# endif
1941 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001942 --bcol; // still working on the previous char, e.g. Tab
1943
1944 // Check if any active property ends.
1945 for (pi = 0; pi < text_props_active; ++pi)
1946 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001947 int tpi = text_prop_idxs[pi];
1948 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001949
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001950 // An inline property ends when after the start column plus
1951 // length. An "above" property ends when used and n_extra
1952 // is zero.
1953 if ((tp->tp_col != MAXCOL
1954 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001955 {
1956 if (pi + 1 < text_props_active)
1957 mch_memmove(text_prop_idxs + pi,
1958 text_prop_idxs + pi + 1,
1959 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001960 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001961 --text_props_active;
1962 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001963# ifdef FEAT_LINEBREAK
1964 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001965 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001966 syntax_attr = 0;
1967# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001968 }
1969 }
1970
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001971# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001972 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001973 // not on the next char yet, don't start another prop
1974 --bcol;
1975# endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001976 int display_text_first = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001977
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001978 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001979 // With 'nowrap' and not in the first screen line only "below"
1980 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001981 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001982 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001983 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001984 && (wp->w_p_wrap
1985 || wlv.row == startrow
1986 || (text_props[text_prop_next].tp_flags
1987 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001988 || (bcol == 0
1989 && (text_props[text_prop_next].tp_flags
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001990 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001991 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001992 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001993 if (text_props[text_prop_next].tp_col == MAXCOL
1994 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001995 + text_props[text_prop_next].tp_len)
1996 text_prop_idxs[text_props_active++] = text_prop_next;
1997 ++text_prop_next;
1998 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001999
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002000 if (wlv.n_extra == 0 ||
2001 (!wlv.extra_for_textprop
2002#ifdef FEAT_PROP_POPUP
2003 && !(text_prop_type != NULL &&
2004 text_prop_flags & PT_FLAG_OVERRIDE)
2005#endif
2006 ))
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002007 {
2008 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002009 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002010 text_prop_flags = 0;
2011 text_prop_type = NULL;
2012 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002013 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002014 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002015 if (text_props_active > 0 && wlv.n_extra == 0
2016 && !display_text_first)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002017 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01002018 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002019 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002020 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002021
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002022 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002023 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002024
2025 // Sort the properties on priority and/or starting last.
2026 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002027 sort_text_props(wp->w_buffer, text_props,
2028 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002029
2030 for (pi = 0; pi < text_props_active; ++pi)
2031 {
2032 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002033 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002034 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002035 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002036
Bram Moolenaarcd105412022-10-10 19:50:42 +01002037 // Only use a text property that can be displayed.
2038 // Skip "after" properties when wrap is off and at the
2039 // end of the window.
2040 if (pt != NULL
2041 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2042 && tp->tp_id != -MAXCOL
2043 && !(tp->tp_id < 0
2044 && !wp->w_p_wrap
2045 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2046 | TP_FLAG_ALIGN_ABOVE
2047 | TP_FLAG_ALIGN_BELOW)) == 0
2048 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002049 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002050 if (tp->tp_col == MAXCOL
2051 && *ptr == NUL
2052 && ((wp->w_p_list && lcs_eol_one > 0
2053 && (tp->tp_flags
2054 & TP_FLAG_ALIGN_ABOVE) == 0)
2055 || (ptr == line
2056 && !did_line
2057 && (tp->tp_flags
2058 & TP_FLAG_ALIGN_BELOW))))
2059 {
2060 // skip this prop, first display the '$' after
2061 // the line or display an empty line
2062 text_prop_follows = TRUE;
2063 if (used_tpi < 0)
2064 display_text_first = TRUE;
2065 continue;
2066 }
2067
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002068 if (pt->pt_hl_id > 0)
2069 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002070 text_prop_type = pt;
2071 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002072 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002073 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2074 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002075 text_prop_flags = pt->pt_flags;
2076 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002077 used_tpi = tpi;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002078 display_text_first = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002079 }
2080 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002081 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002082 && -text_prop_id
2083 <= wp->w_buffer->b_textprop_text.ga_len)
2084 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002085 textprop_T *tp = &text_props[used_tpi];
2086 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002087 ->b_textprop_text.ga_data)[
2088 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002089 int above = (tp->tp_flags
2090 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002091 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002092
2093 // reset the ID in the copy to avoid it being used
2094 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002095 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002096
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002097 if (p != NULL)
2098 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002099 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002100 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002101 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002102 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002103 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
2104 int padding = tp->tp_col == MAXCOL
2105 && tp->tp_len > 1
2106 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002107
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002108 // Insert virtual text before the current
2109 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002110 wlv.p_extra = p;
2111 wlv.c_extra = NUL;
2112 wlv.c_final = NUL;
2113 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002114 wlv.extra_for_textprop = TRUE;
zeertzjq6e940d92023-08-17 23:21:40 +02002115 wlv.start_extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002116 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2117 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002118 n_attr = mb_charlen(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002119 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002120 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002121 if (*ptr == NUL)
2122 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002123 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002124#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002125 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002126 {
2127 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002128 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002129 wlv.need_showbreak = FALSE;
2130 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002131 }
2132#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002133 if ((right || above || below || !wrap
2134 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002135 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002136 char_u *prev_p_extra = wlv.p_extra;
2137 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002138
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002139 // Take care of padding, right-align and
2140 // truncation.
2141 // Shared with win_lbr_chartabsize(), must do
2142 // exactly the same.
2143 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002144 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002145 wlv.col,
2146 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002147 &n_attr, &wlv.n_attr_skip,
2148 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002149 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002150 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002151 // wlv.p_extra was allocated
2152 vim_free(p_extra_free2);
2153 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002154 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002155
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002156 if (above)
2157 wlv.vcol_off_tp = wlv.n_extra;
2158
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002159 if (lcs_eol_one < 0
2160 && wp->w_p_wrap
2161 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002162 + wlv.n_extra - 2 > wp->w_width)
2163 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002164 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002165
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002166 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002167 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002168 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002169 {
2170 draw_screen_line(wp, &wlv);
2171
2172 // When line got too long for screen break
2173 // here.
2174 if (wlv.row == endrow)
2175 {
2176 ++wlv.row;
2177 break;
2178 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002179 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002180 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002181 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002182 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002183 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002184
Bram Moolenaarcd105412022-10-10 19:50:42 +01002185 // If the text didn't reach until the first window
2186 // column we need to skip cells.
2187 if (skip_cells > 0)
2188 {
2189 if (wlv.n_extra > skip_cells)
2190 {
2191 wlv.n_extra -= skip_cells;
2192 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002193 wlv.n_attr_skip -= skip_cells;
2194 if (wlv.n_attr_skip < 0)
2195 wlv.n_attr_skip = 0;
zeertzjqb557f482023-08-22 22:07:34 +02002196 skipped_cells += skip_cells;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002197 skip_cells = 0;
2198 }
2199 else
2200 {
2201 // the whole text is left of the window, drop
2202 // it and advance to the next one
2203 skip_cells -= wlv.n_extra;
zeertzjqb557f482023-08-22 22:07:34 +02002204 skipped_cells += wlv.n_extra;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002205 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002206 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002207 bail_out = TRUE;
2208 }
2209 }
2210
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002211 // If another text prop follows the condition below at
2212 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002213 // If this is an "above" text prop and 'nowrap' the we
2214 // must wrap anyway.
2215 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002216 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002217 && (wp->w_p_wrap
2218 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002219 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002220
2221 if (bail_out)
2222 // starting a new line for "below"
2223 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002224 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002225 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002226 else if (text_prop_next < text_prop_count
2227 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002228 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2229 || (!wp->w_p_wrap
2230 && wlv.col == wp->w_width - 1
2231 && (text_props[text_prop_next].tp_flags
2232 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002233 // When at last-but-one character and a text property
2234 // follows after it, we may need to flush the line after
2235 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002236 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002237 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002238 }
zeertzjq6e940d92023-08-17 23:21:40 +02002239
2240 if (wlv.start_extra_for_textprop)
2241 {
2242 wlv.start_extra_for_textprop = FALSE;
2243 // restore search_attr and area_attr when n_extra
2244 // is down to zero
2245 saved_search_attr = search_attr;
2246 saved_area_attr = area_attr;
2247 search_attr = 0;
2248 area_attr = 0;
2249 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002250#endif
2251
zeertzjq6e940d92023-08-17 23:21:40 +02002252 int *area_attr_p =
2253#ifdef FEAT_PROP_POPUP
2254 wlv.extra_for_textprop ? &saved_area_attr :
2255#endif
2256 &area_attr;
2257
2258 // handle Visual or match highlighting in this line
2259 if (wlv.vcol == wlv.fromcol
2260 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
2261 && ((wlv.n_extra == 0 && (*mb_ptr2cells)(ptr) > 1)
2262 || (wlv.n_extra > 0 && wlv.p_extra != NULL
2263 && (*mb_ptr2cells)(wlv.p_extra) > 1)))
2264 || ((int)vcol_prev == fromcol_prev
2265 && vcol_prev < wlv.vcol // not at margin
2266 && wlv.vcol < wlv.tocol))
2267 *area_attr_p = vi_attr; // start highlighting
2268 else if (*area_attr_p != 0
2269 && (wlv.vcol == wlv.tocol
2270 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
2271 *area_attr_p = 0; // stop highlighting
2272
zeertzjqe500ae82023-08-17 22:35:26 +02002273#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaare38fc862022-08-11 17:24:50 +01002274 if (wlv.n_extra == 0)
2275 {
2276 // Check for start/end of 'hlsearch' and other matches.
2277 // After end, check for start/end of next match.
2278 // When another match, have to check for start again.
2279 v = (long)(ptr - line);
2280 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2281 &screen_search_hl, &has_match_conc,
2282 &match_conc, did_line_attr, lcs_eol_one,
2283 &on_last_col);
2284 ptr = line + v; // "line" may have been changed
Bram Moolenaare38fc862022-08-11 17:24:50 +01002285
2286 // Do not allow a conceal over EOL otherwise EOL will be missed
2287 // and bad things happen.
2288 if (*ptr == NUL)
2289 has_match_conc = 0;
zeertzjqb25dbb32023-08-13 18:11:05 +02002290 }
zeertzjqe500ae82023-08-17 22:35:26 +02002291#endif
zeertzjqb25dbb32023-08-13 18:11:05 +02002292
Bram Moolenaare38fc862022-08-11 17:24:50 +01002293#ifdef FEAT_DIFF
2294 if (wlv.diff_hlf != (hlf_T)0)
2295 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002296 // When there is extra text (e.g. virtual text) it gets the
2297 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002298 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2299 && wlv.n_extra == 0)
2300 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002301 if (wlv.diff_hlf == HLF_TXD
2302 && ((ptr - line > change_end && wlv.n_extra == 0)
2303 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002304 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002305 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002306 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2307 && wp->w_p_culopt_flags != CULOPT_NBR
2308 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2309 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002310 wlv.line_attr = hl_combine_attr(
2311 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002312 }
2313#endif
2314
Bram Moolenaara74fda62019-10-19 17:38:03 +02002315#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002316 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002317 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002318 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002319# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002320 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002321 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002322# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002323 // Get syntax attribute.
2324 if (has_syntax)
2325 {
2326 // Get the syntax attribute for the character. If there
2327 // is an error, disable syntax highlighting.
2328 save_did_emsg = did_emsg;
2329 did_emsg = FALSE;
2330
2331 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002332 if (v == prev_syntax_col)
2333 // at same column again
2334 syntax_attr = prev_syntax_attr;
2335 else
2336 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002337# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002338 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002339# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002340 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002341# ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01002342 spv->spv_has_spell ? &can_spell :
Bram Moolenaar34390282019-10-16 14:38:26 +02002343# endif
Luuk van Baal30805a12023-05-27 22:22:10 +01002344 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002345 prev_syntax_col = v;
2346 prev_syntax_attr = syntax_attr;
2347 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002348
Bram Moolenaar34390282019-10-16 14:38:26 +02002349 if (did_emsg)
2350 {
2351 wp->w_s->b_syn_error = TRUE;
2352 has_syntax = FALSE;
2353 syntax_attr = 0;
2354 }
2355 else
2356 did_emsg = save_did_emsg;
2357# ifdef SYN_TIME_LIMIT
2358 if (wp->w_s->b_syn_slow)
2359 has_syntax = FALSE;
2360# endif
2361
2362 // Need to get the line again, a multi-line regexp may
2363 // have made it invalid.
2364 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2365 ptr = line + v;
2366# ifdef FEAT_CONCEAL
2367 // no concealing past the end of the line, it interferes
2368 // with line highlighting
2369 if (*ptr == NUL)
2370 syntax_flags = 0;
2371 else
2372 syntax_flags = get_syntax_info(&syntax_seqnr);
2373# endif
2374 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002375 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002376# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002377 // Combine text property highlight into syntax highlight.
2378 if (text_prop_type != NULL)
2379 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002380 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002381 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2382 else
2383 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002384 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002385 }
2386# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002387#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002388
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002389 // Decide which of the highlight attributes to use.
2390 attr_pri = TRUE;
2391#ifdef LINE_ATTR
2392 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002393 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002394 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002395 if (!highlight_match)
2396 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002397 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002398# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002399 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002400# endif
2401 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002402 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002403 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002404 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002405# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002406 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002407# endif
2408 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002409 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002410 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2411 || wlv.vcol < wlv.fromcol
2412 || vcol_prev < fromcol_prev
2413 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002414 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002415 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002416 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002417# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002418 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002419# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002420 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002421# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002422 attr_pri = FALSE;
2423 }
2424#else
2425 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002426 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002427 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002428 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002429#endif
2430 else
2431 {
2432 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002433#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002434 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002435#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002436 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002437#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002438 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002439#ifdef FEAT_PROP_POPUP
2440 // override with text property highlight when "override" is TRUE
2441 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002442 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002443#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002444 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002445
2446 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002447 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002448 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002449 if (wlv.char_attr == 0)
2450 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002451 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002452 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002453 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002454
2455 // Get the next character to put on the screen.
2456
2457 // The "p_extra" points to the extra stuff that is inserted to
2458 // represent special characters (non-printable stuff) and other
2459 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002460 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002461 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2462 // "p_extra[n_extra]".
2463 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002464 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002465 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002466 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002467 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002468 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2469 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002470 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2471 if (enc_utf8 && utf_char2len(c) > 1)
2472 {
2473 mb_utf8 = TRUE;
2474 u8cc[0] = 0;
2475 c = 0xc0;
2476 }
2477 else
2478 mb_utf8 = FALSE;
2479 }
2480 else
2481 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002482 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002483 if (has_mbyte)
2484 {
2485 mb_c = c;
2486 if (enc_utf8)
2487 {
2488 // If the UTF-8 character is more than one byte:
2489 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002490 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002491 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002492 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002493 mb_l = 1;
2494 else if (mb_l > 1)
2495 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002496 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002497 mb_utf8 = TRUE;
2498 c = 0xc0;
2499 }
2500 }
2501 else
2502 {
2503 // if this is a DBCS character, put it in "mb_c"
2504 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002505 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002506 mb_l = 1;
2507 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002508 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002509 }
2510 if (mb_l == 0) // at the NUL at end-of-line
2511 mb_l = 1;
2512
2513 // If a double-width char doesn't fit display a '>' in the
2514 // last column.
2515 if ((
2516# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002517 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002518# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002519 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002520 && (*mb_char2cells)(mb_c) == 2)
2521 {
2522 c = '>';
2523 mb_c = c;
2524 mb_l = 1;
2525 mb_utf8 = FALSE;
2526 multi_attr = HL_ATTR(HLF_AT);
2527#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002528 if (wlv.cul_attr)
2529 multi_attr = hl_combine_attr(
2530 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002531#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002532 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002533
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002534 // put the pointer back to output the double-width
2535 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002536 ++wlv.n_extra;
2537 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002538 }
2539 else
2540 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002541 wlv.n_extra -= mb_l - 1;
2542 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002543 }
2544 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002545 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002546 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002547 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002548#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002549 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002550 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002551 // Only restore search_attr and area_attr after "n_extra" in
2552 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002553 if (wlv.saved_n_extra <= 0)
2554 {
2555 if (search_attr == 0)
2556 search_attr = saved_search_attr;
2557 if (area_attr == 0 && *ptr != NUL)
2558 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002559
2560 if (wlv.extra_for_textprop)
2561 // wlv.extra_attr should be used at this position but
2562 // not any further.
2563 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002564 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002565
2566 wlv.extra_for_textprop = FALSE;
2567 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002568 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002569#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002570 }
2571 else
2572 {
2573#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002574 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002575#endif
zeertzjqe500ae82023-08-17 22:35:26 +02002576#ifdef FEAT_SPELL
2577 char_u *prev_ptr = ptr;
2578#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002579
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002580 // Get a character from the line itself.
2581 c = *ptr;
2582#ifdef FEAT_LINEBREAK
2583 c0 = *ptr;
2584#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002585 if (c == NUL)
zeertzjqb557f482023-08-22 22:07:34 +02002586 {
2587#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002588 // text is finished, may display a "below" virtual text
2589 did_line = TRUE;
2590#endif
zeertzjqb557f482023-08-22 22:07:34 +02002591 // no more cells to skip
2592 skip_cells = 0;
2593 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002594
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.
zeertzjqb557f482023-08-22 22:07:34 +02002759 if (skip_cells > 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
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002890 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002891 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002892 // line break, but for TABs the highlighting should
2893 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002894 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002895
Bram Moolenaar1306b362022-08-06 15:59:06 +01002896 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002897# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002898 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002899 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002900 wp->w_buffer->b_p_vts_array) - 1;
2901# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002902 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002903 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002904# endif
2905
Bram Moolenaar1306b362022-08-06 15:59:06 +01002906 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2907 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002908# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002909 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002910 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002911# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002912 if (VIM_ISWHITE(c))
2913 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002914# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002915 if (c == TAB)
2916 // See "Tab alignment" below.
2917 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002918# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002919 if (!wp->w_p_list)
2920 c = ' ';
2921 }
2922 }
2923#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002924 in_multispace = c == ' '
2925 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2926 if (!in_multispace)
2927 multispace_pos = 0;
2928
Bram Moolenaareed9d462021-02-15 20:38:25 +01002929 // 'list': Change char 160 to 'nbsp' and space to 'space'
2930 // setting in 'listchars'. But not when the character is
2931 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002932 if (wp->w_p_list
2933 && ((((c == 160 && mb_l == 1)
2934 || (mb_utf8
2935 && ((mb_c == 160 && mb_l == 2)
2936 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002937 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002938 || (c == ' '
2939 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002940 && (wp->w_lcs_chars.space
2941 || (in_multispace
2942 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002943 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002944 && ptr - line <= trailcol)))
2945 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002946 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2947 {
2948 c = wp->w_lcs_chars.multispace[multispace_pos++];
2949 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2950 multispace_pos = 0;
2951 }
2952 else
2953 c = (c == ' ') ? wp->w_lcs_chars.space
2954 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002955 if (area_attr == 0 && search_attr == 0)
2956 {
2957 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002958 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002959 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002960 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002961 }
2962 mb_c = c;
2963 if (enc_utf8 && utf_char2len(c) > 1)
2964 {
2965 mb_utf8 = TRUE;
2966 u8cc[0] = 0;
2967 c = 0xc0;
2968 }
2969 else
2970 mb_utf8 = FALSE;
2971 }
2972
zeertzjq2e7cba32022-06-10 15:30:32 +01002973 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2974 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002975 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002976 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2977 && wp->w_lcs_chars.leadmultispace != NULL)
2978 {
2979 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002980 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2981 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002982 multispace_pos = 0;
2983 }
2984
2985 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2986 c = wp->w_lcs_chars.trail;
2987
2988 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2989 c = wp->w_lcs_chars.lead;
2990
zeertzjq2e7cba32022-06-10 15:30:32 +01002991 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002992 c = wp->w_lcs_chars.space;
2993
2994
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002995 if (!attr_pri)
2996 {
2997 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002998 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002999 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003000 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003001 }
3002 mb_c = c;
3003 if (enc_utf8 && utf_char2len(c) > 1)
3004 {
3005 mb_utf8 = TRUE;
3006 u8cc[0] = 0;
3007 c = 0xc0;
3008 }
3009 else
3010 mb_utf8 = FALSE;
3011 }
3012 }
3013
3014 // Handling of non-printable characters.
3015 if (!vim_isprintc(c))
3016 {
3017 // when getting a character from the file, we may have to
3018 // turn it into something else on the way to putting it
3019 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01003020 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003021 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003022 int tab_len = 0;
3023 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003024#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003025 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01003026
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003027 // only adjust the tab_len, when at the first column
3028 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01003029 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003030 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003031#endif
3032 // tab amount depends on current column
3033#ifdef FEAT_VARTABS
3034 tab_len = tabstop_padding(vcol_adjusted,
3035 wp->w_buffer->b_p_ts,
3036 wp->w_buffer->b_p_vts_array) - 1;
3037#else
3038 tab_len = (int)wp->w_buffer->b_p_ts
3039 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
3040#endif
3041
3042#ifdef FEAT_LINEBREAK
3043 if (!wp->w_p_lbr || !wp->w_p_list)
3044#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003045 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003046 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01003047 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003048 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003049#ifdef FEAT_LINEBREAK
3050 else
3051 {
3052 char_u *p;
3053 int len;
3054 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003055 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003056
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003057# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003058 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003059 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003060 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003061
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003062 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003063 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003064 && old_boguscols > 0
3065 && wlv.n_extra > tab_len)
3066 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003067# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003068 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003069 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003070 // If wlv.n_extra > 0, it gives the number of chars
3071 // to use for a tab, else we need to calculate the
3072 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003073 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3074 len = tab_len * tab2_len;
3075 if (wp->w_lcs_chars.tab3)
3076 len += mb_char2len(wp->w_lcs_chars.tab3)
3077 - tab2_len;
3078 if (wlv.n_extra > 0)
3079 len += wlv.n_extra - tab_len;
3080 c = wp->w_lcs_chars.tab1;
3081 p = alloc(len + 1);
3082 if (p == NULL)
3083 wlv.n_extra = 0;
3084 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003085 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003086 vim_memset(p, ' ', len);
3087 p[len] = NUL;
3088 vim_free(wlv.p_extra_free);
3089 wlv.p_extra_free = p;
3090 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003091 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003092 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003093
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003094 if (*p == NUL)
3095 {
3096 tab_len = i;
3097 break;
3098 }
3099
3100 // if tab3 is given, use it for the last
3101 // char
3102 if (wp->w_lcs_chars.tab3
3103 && i == tab_len - 1)
3104 lcs = wp->w_lcs_chars.tab3;
3105 p += mb_char2bytes(lcs, p);
3106 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003107 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003108 }
3109 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003110# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003111 // n_extra will be increased by
3112 // FIX_FOX_BOGUSCOLS macro below, so need to
3113 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003114 if (wlv.vcol_off_co > 0)
3115 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003116# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003117 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003118 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003119 }
3120#endif
3121#ifdef FEAT_CONCEAL
3122 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003123 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003124
3125 // Tab alignment should be identical regardless of
3126 // 'conceallevel' value. So tab compensates of all
3127 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003128 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003129 // line. Note that the tab can be longer than
3130 // 'tabstop' when there are concealed characters.
3131 FIX_FOR_BOGUSCOLS;
3132
3133 // Make sure, the highlighting for the tab char will be
3134 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003135 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003136 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003137 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003138 tab_len += vc_saved;
3139 }
3140#endif
3141 mb_utf8 = FALSE; // don't draw as UTF-8
3142 if (wp->w_p_list)
3143 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003144 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003145 ? wp->w_lcs_chars.tab3
3146 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003147#ifdef FEAT_LINEBREAK
h-east194555c2023-03-02 18:49:09 +00003148 if (wp->w_p_lbr && wlv.p_extra != NULL
3149 && *wlv.p_extra != NUL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003150 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003151 else
3152#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003153 wlv.c_extra = wp->w_lcs_chars.tab2;
3154 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003155 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003156 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003157 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003158 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003159 mb_c = c;
3160 if (enc_utf8 && utf_char2len(c) > 1)
3161 {
3162 mb_utf8 = TRUE;
3163 u8cc[0] = 0;
3164 c = 0xc0;
3165 }
3166 }
3167 else
3168 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003169 wlv.c_final = NUL;
3170 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003171 c = ' ';
3172 }
3173 }
3174 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003175 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003176 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003177 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3178 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003179 && VIsual_mode != Ctrl_V
3180 && (
3181# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003182 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003183# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003184 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003185 && !(noinvcur
3186 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003187 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003188 && lcs_eol_one > 0)
3189 {
3190 // Display a '$' after the line or highlight an extra
3191 // character if the line break is included.
3192#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3193 // For a diff line the highlighting continues after the
3194 // "$".
3195 if (
3196# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003197 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003198# ifdef LINE_ATTR
3199 &&
3200# endif
3201# endif
3202# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003203 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003204# endif
3205 )
3206#endif
3207 {
3208 // In virtualedit, visual selections may extend
3209 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003210 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003211 && wlv.tocol != MAXCOL
3212 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003213 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003214 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003215 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003216 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3217 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003218 else
3219 c = ' ';
3220 lcs_eol_one = -1;
3221 --ptr; // put it back at the NUL
3222 if (!attr_pri)
3223 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003224 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003225 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003226 n_attr = 1;
3227 }
3228 mb_c = c;
3229 if (enc_utf8 && utf_char2len(c) > 1)
3230 {
3231 mb_utf8 = TRUE;
3232 u8cc[0] = 0;
3233 c = 0xc0;
3234 }
3235 else
3236 mb_utf8 = FALSE; // don't draw as UTF-8
3237 }
3238 else if (c != NUL)
3239 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003240 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3241 if (wlv.n_extra == 0)
3242 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003243#ifdef FEAT_RIGHTLEFT
3244 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003245 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003246#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003247 wlv.c_extra = NUL;
3248 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003249#ifdef FEAT_LINEBREAK
3250 if (wp->w_p_lbr)
3251 {
3252 char_u *p;
3253
Bram Moolenaar1306b362022-08-06 15:59:06 +01003254 c = *wlv.p_extra;
3255 p = alloc(wlv.n_extra + 1);
3256 vim_memset(p, ' ', wlv.n_extra);
3257 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3258 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003259 vim_free(wlv.p_extra_free);
3260 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003261 }
3262 else
3263#endif
3264 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003265 wlv.n_extra = byte2cells(c) - 1;
3266 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003267 }
3268 if (!attr_pri)
3269 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003270 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003271 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003272 HL_ATTR(HLF_8));
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003273#ifdef FEAT_PROP_POPUP
3274 if (text_prop_type != NULL &&
3275 text_prop_flags & PT_FLAG_OVERRIDE)
3276 wlv.extra_attr = hl_combine_attr(text_prop_attr, wlv.extra_attr);
3277#endif
3278
Bram Moolenaar1306b362022-08-06 15:59:06 +01003279 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003280 }
3281 mb_utf8 = FALSE; // don't draw as UTF-8
3282 }
3283 else if (VIsual_active
3284 && (VIsual_mode == Ctrl_V
3285 || VIsual_mode == 'v')
3286 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003287 && wlv.tocol != MAXCOL
3288 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003289 && (
3290#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003291 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003292#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003293 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003294 {
3295 c = ' ';
3296 --ptr; // put it back at the NUL
3297 }
3298#if defined(LINE_ATTR)
3299 else if ((
3300# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003301 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003302# endif
3303# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003304 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003305# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003306 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003307 ) && (
3308# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003309 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003310# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003311 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003312# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003313 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003314# endif
3315 < wp->w_width)))
3316 {
3317 // Highlight until the right side of the window
3318 c = ' ';
3319 --ptr; // put it back at the NUL
3320
3321 // Remember we do the char for line highlighting.
3322 ++did_line_attr;
3323
3324 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003325 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003326 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003327 || (wp->w_p_list &&
3328 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003329 wlv.char_attr = wlv.line_attr;
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003330#ifdef FEAT_SIGNS
3331 // At end of line: if Sign is present with line highlight, reset char_attr
Christian Brabandte1eaae22023-08-19 22:36:12 +02003332 // but not when cursorline is active
3333 if (sign_present && wlv.sattr.sat_linehl > 0 && wlv.draw_state == WL_LINE
3334 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum))
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003335 wlv.char_attr = wlv.sattr.sat_linehl;
3336#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003337# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003338 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003339 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003340 wlv.diff_hlf = HLF_CHD;
3341 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003342 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003343 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003344 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3345 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003346 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003347 || (wlv.vcol >= left_curline_col
3348 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003349 wlv.char_attr = hl_combine_attr(
3350 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003351 }
3352 }
3353# endif
3354# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003355 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003356 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003357 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003358 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3359 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003360 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003361 if (!wlv.cul_screenline
3362 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003363 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003364 wlv.char_attr = hl_combine_attr(
3365 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003366 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003367 else if (wlv.line_attr)
3368 wlv.char_attr = hl_combine_attr(
3369 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003370 }
3371# endif
3372 }
3373#endif
3374 }
3375
3376#ifdef FEAT_CONCEAL
3377 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003378 && (wp != curwin || lnum != wp->w_cursor.lnum
3379 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003380 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3381 && !(lnum_in_visual_area
3382 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3383 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003384 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003385 if (((prev_syntax_id != syntax_seqnr
3386 && (syntax_flags & HL_CONCEAL) != 0)
3387 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003388 && (syn_get_sub_char() != NUL
3389 || (has_match_conc && match_conc)
3390 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003391 && wp->w_p_cole != 3)
3392 {
3393 // First time at this concealed item: display one
3394 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003395 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003396 c = match_conc;
3397 else if (syn_get_sub_char() != NUL)
3398 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003399 else if (wp->w_lcs_chars.conceal != NUL)
3400 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003401 else
3402 c = ' ';
3403
3404 prev_syntax_id = syntax_seqnr;
3405
Bram Moolenaar1306b362022-08-06 15:59:06 +01003406 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003407 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003408 wlv.vcol += wlv.n_extra;
3409 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003410 {
3411# ifdef FEAT_RIGHTLEFT
3412 if (wp->w_p_rl)
3413 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003414 wlv.col -= wlv.n_extra;
3415 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003416 }
3417 else
3418# endif
3419 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003420 wlv.boguscols += wlv.n_extra;
3421 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003422 }
3423 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003424 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003425 n_attr = 0;
3426 }
zeertzjqb557f482023-08-22 22:07:34 +02003427 else if (skip_cells == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003428 {
3429 is_concealing = TRUE;
zeertzjqb557f482023-08-22 22:07:34 +02003430 skip_cells = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003431 }
3432 mb_c = c;
3433 if (enc_utf8 && utf_char2len(c) > 1)
3434 {
3435 mb_utf8 = TRUE;
3436 u8cc[0] = 0;
3437 c = 0xc0;
3438 }
3439 else
3440 mb_utf8 = FALSE; // don't draw as UTF-8
3441 }
3442 else
3443 {
3444 prev_syntax_id = 0;
3445 is_concealing = FALSE;
3446 }
3447
zeertzjqb557f482023-08-22 22:07:34 +02003448 if (skip_cells > 0 && did_decrement_ptr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003449 // not showing the '>', put pointer back to avoid getting stuck
3450 ++ptr;
3451
3452#endif // FEAT_CONCEAL
3453 }
3454
3455#ifdef FEAT_CONCEAL
3456 // In the cursor line and we may be concealing characters: correct
3457 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003458 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003459 && wp == curwin && lnum == wp->w_cursor.lnum
3460 && conceal_cursor_line(wp)
zeertzjqb557f482023-08-22 22:07:34 +02003461 && (int)wp->w_virtcol <= wlv.vcol + skip_cells)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003462 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003463# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003464 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003465 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003466 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003467# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003468 wp->w_wcol = wlv.col - wlv.boguscols;
3469 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003470 did_wcol = TRUE;
3471 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003472# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003473 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003474# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003475 }
3476#endif
3477
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003478 // Use "wlv.extra_attr", but don't override visual selection
3479 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003480 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3481 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003482 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003483 && (!attr_pri
3484#ifdef FEAT_PROP_POPUP
3485 || (text_prop_flags & PT_FLAG_OVERRIDE)
3486#endif
3487 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003488 {
3489#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003490 if (wlv.line_attr)
3491 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003492 else
3493#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003494 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003495#ifdef FEAT_PROP_POPUP
3496 if (reset_extra_attr)
3497 {
3498 reset_extra_attr = FALSE;
3499 wlv.extra_attr = 0;
3500 }
3501#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003502 }
3503
3504#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3505 // XIM don't send preedit_start and preedit_end, but they send
3506 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3507 // im_is_preediting() here.
3508 if (p_imst == IM_ON_THE_SPOT
3509 && xic != NULL
3510 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003511 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003512 && !p_imdisable
3513 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003514 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003515 {
3516 colnr_T tcol;
3517
3518 if (preedit_end_col == MAXCOL)
3519 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3520 else
3521 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003522 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003523 {
3524 if (feedback_old_attr < 0)
3525 {
3526 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003527 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003528 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003529 wlv.char_attr = im_get_feedback_attr(feedback_col);
3530 if (wlv.char_attr < 0)
3531 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003532 feedback_col++;
3533 }
3534 else if (feedback_old_attr >= 0)
3535 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003536 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003537 feedback_old_attr = -1;
3538 feedback_col = 0;
3539 }
3540 }
3541#endif
3542 // Handle the case where we are in column 0 but not on the first
3543 // character of the line and the user wants us to show us a
3544 // special character (via 'listchars' option "precedes:<char>".
3545 if (lcs_prec_todo != NUL
3546 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003547 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3548 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003549#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003550 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003551#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003552 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003553 && c != NUL)
3554 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003555 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003556 lcs_prec_todo = NUL;
3557 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3558 {
3559 // Double-width character being overwritten by the "precedes"
3560 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003561 wlv.c_extra = MB_FILLER_CHAR;
3562 wlv.c_final = NUL;
3563 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003564 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003565 wlv.extra_attr =
3566 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003567 }
3568 mb_c = c;
3569 if (enc_utf8 && utf_char2len(c) > 1)
3570 {
3571 mb_utf8 = TRUE;
3572 u8cc[0] = 0;
3573 c = 0xc0;
3574 }
3575 else
3576 mb_utf8 = FALSE; // don't draw as UTF-8
3577 if (!attr_pri)
3578 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003579 saved_attr3 = wlv.char_attr; // save current attr
3580 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003581 n_attr3 = 1;
3582 }
3583 }
3584
3585 // At end of the text line or just after the last character.
3586 if ((c == NUL
3587#if defined(LINE_ATTR)
3588 || did_line_attr == 1
3589#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003590 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003591 {
3592#ifdef FEAT_SEARCH_EXTRA
3593 // flag to indicate whether prevcol equals startcol of search_hl or
3594 // one of the matches
3595 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3596 (long)(ptr - line) - (c == NUL));
3597#endif
3598 // Invert at least one char, used for Visual and empty line or
3599 // highlight match at end of line. If it's beyond the last
3600 // char on the screen, just overwrite that one (tricky!) Not
3601 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003602 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003603 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003604 && (VIsual_mode != Ctrl_V
3605 || lnum == VIsual.lnum
3606 || lnum == curwin->w_cursor.lnum)
3607 && c == NUL)
3608#ifdef FEAT_SEARCH_EXTRA
3609 // highlight 'hlsearch' match at end of line
3610 || (prevcol_hl_flag
3611# ifdef FEAT_SYN_HL
3612 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3613 && !(wp == curwin && VIsual_active))
3614# endif
3615# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003616 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003617# endif
3618# if defined(LINE_ATTR)
3619 && did_line_attr <= 1
3620# endif
3621 )
3622#endif
3623 ))
3624 {
3625 int n = 0;
3626
3627#ifdef FEAT_RIGHTLEFT
3628 if (wp->w_p_rl)
3629 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003630 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003631 n = 1;
3632 }
3633 else
3634#endif
3635 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003636 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003637 n = -1;
3638 }
3639 if (n != 0)
3640 {
3641 // At the window boundary, highlight the last character
3642 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003643 wlv.off += n;
3644 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003645 }
3646 else
3647 {
3648 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003649 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003650 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003651 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003652 }
3653#ifdef FEAT_SEARCH_EXTRA
3654 if (area_attr == 0)
3655 {
3656 // Use attributes from match with highest priority among
3657 // 'search_hl' and the match list.
3658 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003659 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003660 }
3661#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003662 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003663 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003664#ifdef FEAT_RIGHTLEFT
3665 if (wp->w_p_rl)
3666 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003667 --wlv.col;
3668 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003669 }
3670 else
3671#endif
3672 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003673 ++wlv.col;
3674 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003675 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003676 ++wlv.vcol;
3677 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003678 }
3679 }
3680
3681 // At end of the text line.
3682 if (c == NUL)
3683 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003684#ifdef FEAT_PROP_POPUP
3685 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003686 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003687 // Put the pointer back to the NUL.
3688 --ptr;
3689 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003690 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003691 else
3692#endif
3693 {
3694 draw_screen_line(wp, &wlv);
3695
3696 // Update w_cline_height and w_cline_folded if the cursor line
3697 // was updated (saves a call to plines() later).
3698 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3699 {
3700 curwin->w_cline_row = startrow;
3701 curwin->w_cline_height = wlv.row - startrow;
3702#ifdef FEAT_FOLDING
3703 curwin->w_cline_folded = FALSE;
3704#endif
3705 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3706 }
3707 break;
3708 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003709 }
3710
3711 // Show "extends" character from 'listchars' if beyond the line end and
3712 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003713 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003714 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003715 && wp->w_p_list
3716 && !wp->w_p_wrap
3717#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003718 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003719#endif
3720 && (
3721#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003722 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003723#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003724 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003725 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003726 || lcs_eol_one > 0
3727 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
zeertzjq6a389722023-08-27 19:04:14 +02003728 || *wlv.p_extra != NUL))
3729#ifdef FEAT_PROP_POPUP
3730 || text_prop_next < text_prop_count
3731#endif
3732 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003733 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003734 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003735 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003736 mb_c = c;
3737 if (enc_utf8 && utf_char2len(c) > 1)
3738 {
3739 mb_utf8 = TRUE;
3740 u8cc[0] = 0;
3741 c = 0xc0;
3742 }
3743 else
3744 mb_utf8 = FALSE;
3745 }
3746
3747#ifdef FEAT_SYN_HL
3748 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003749 if (wlv.draw_color_col)
3750 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003751
3752 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3753 // highlight the cursor position itself.
3754 // Also highlight the 'colorcolumn' if it is different than
3755 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003756 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3757 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003758 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003759 if (((wlv.draw_state == WL_LINE
3760 || wlv.draw_state == WL_BRI
3761 || wlv.draw_state == WL_SBR)
3762 && !lnum_in_visual_area
3763 && search_attr == 0
3764 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003765# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003766 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003767# endif
3768 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003769 {
3770 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3771 && lnum != wp->w_cursor.lnum)
3772 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003773 vcol_save_attr = wlv.char_attr;
3774 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3775 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003776 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003777 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003778 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003779 vcol_save_attr = wlv.char_attr;
3780 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003781 }
3782 }
3783#endif
3784
zeertzjq8fc6a1d2023-08-20 18:12:54 +02003785 if (wlv.draw_state == WL_LINE)
3786 vcol_prev = wlv.vcol;
3787
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003788 // Store character to be displayed.
3789 // Skip characters that are left of the screen for 'nowrap'.
zeertzjqb557f482023-08-22 22:07:34 +02003790 if (wlv.draw_state < WL_LINE || skip_cells <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003791 {
3792 // Store the character.
3793#if defined(FEAT_RIGHTLEFT)
3794 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3795 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003796 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003797 --wlv.off;
3798 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003799 }
3800#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003801 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003802 if (enc_dbcs == DBCS_JPNU)
3803 {
3804 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003805 ScreenLines[wlv.off] = 0x8e;
3806 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003807 }
3808 else if (enc_utf8)
3809 {
3810 if (mb_utf8)
3811 {
3812 int i;
3813
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003814 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003815 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003816 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003817 for (i = 0; i < Screen_mco; ++i)
3818 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003819 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003820 if (u8cc[i] == 0)
3821 break;
3822 }
3823 }
3824 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003825 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003826 }
3827 if (multi_attr)
3828 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003829 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003830 multi_attr = 0;
3831 }
3832 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003833 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003834
zeertzjqe500ae82023-08-17 22:35:26 +02003835 ScreenCols[wlv.off] = wlv.vcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003836
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003837 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3838 {
3839 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003840 ++wlv.off;
3841 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003842 if (enc_utf8)
3843 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003844 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003845 else
3846 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003847 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003848 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003849#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003850 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003851#endif
3852 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003853 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003854 // When "wlv.tocol" is halfway a character, set it to the end
3855 // of the character, otherwise highlighting won't stop.
3856 if (wlv.tocol == wlv.vcol)
3857 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003858
zeertzjqe500ae82023-08-17 22:35:26 +02003859 ScreenCols[wlv.off] = wlv.vcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003860
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003861#ifdef FEAT_RIGHTLEFT
3862 if (wp->w_p_rl)
3863 {
3864 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003865 --wlv.off;
3866 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003867 }
3868#endif
3869 }
3870#ifdef FEAT_RIGHTLEFT
3871 if (wp->w_p_rl)
3872 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003873 --wlv.off;
3874 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003875 }
3876 else
3877#endif
3878 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003879 ++wlv.off;
3880 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003881 }
3882 }
3883#ifdef FEAT_CONCEAL
3884 else if (wp->w_p_cole > 0 && is_concealing)
3885 {
zeertzjqb557f482023-08-22 22:07:34 +02003886 --skip_cells;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003887 ++wlv.vcol_off_co;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003888 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003889 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003890 if (wp->w_p_wrap)
3891 {
3892 // Special voodoo required if 'wrap' is on.
3893 //
3894 // Advance the column indicator to force the line
3895 // drawing to wrap early. This will make the line
3896 // take up the same screen space when parts are concealed,
3897 // so that cursor line computations aren't messed up.
3898 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003899 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003900 // trailing junk to be written out of the screen line
3901 // we are building, 'boguscols' keeps track of the number
3902 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003903 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003904 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003905 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003906# ifdef FEAT_RIGHTLEFT
3907 if (wp->w_p_rl)
3908 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003909 wlv.col -= wlv.n_extra;
3910 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003911 }
3912 else
3913# endif
3914 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003915 wlv.col += wlv.n_extra;
3916 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003917 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003918 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003919 n_attr = 0;
3920 }
3921
3922
3923 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3924 {
3925 // Need to fill two screen columns.
3926# ifdef FEAT_RIGHTLEFT
3927 if (wp->w_p_rl)
3928 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003929 --wlv.boguscols;
3930 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003931 }
3932 else
3933# endif
3934 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003935 ++wlv.boguscols;
3936 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003937 }
3938 }
3939
3940# ifdef FEAT_RIGHTLEFT
3941 if (wp->w_p_rl)
3942 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003943 --wlv.boguscols;
3944 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003945 }
3946 else
3947# endif
3948 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003949 ++wlv.boguscols;
3950 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003951 }
3952 }
3953 else
3954 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003955 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003956 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003957 wlv.vcol += wlv.n_extra;
3958 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003959 n_attr = 0;
3960 }
3961 }
3962
3963 }
3964#endif // FEAT_CONCEAL
3965 else
zeertzjqb557f482023-08-22 22:07:34 +02003966 --skip_cells;
3967
3968 if (wlv.draw_state > WL_NR && skipped_cells > 0)
3969 {
3970 wlv.vcol += skipped_cells;
3971 skipped_cells = 0;
3972 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003973
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003974 // Only advance the "wlv.vcol" when after the 'number' or
3975 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003976 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003977#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003978 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003979#endif
3980 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003981 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003982
3983#ifdef FEAT_SYN_HL
3984 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003985 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003986#endif
3987
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003988 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003989 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3990 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003991
3992 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003993 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003994 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003995 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003996 if (wlv.n_attr_skip > 0)
3997 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003998
3999 // At end of screen line and there is more to come: Display the line
4000 // so far. If there is no more to display it is caught above.
4001 if ((
4002#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004003 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004004#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004005 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01004006 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02004007 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004008#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004009 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004010#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004011#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004012 || text_prop_above || text_prop_follows
zeertzjq6a389722023-08-27 19:04:14 +02004013 || text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004014#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01004015 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01004016 && wlv.p_extra != at_end_str)
4017 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
4018 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004019 )
4020 {
4021#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01004022 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01004023 wlv_screen_line(wp, &wlv, FALSE);
4024 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004025 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004026 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004027#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01004028 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004029#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004030 ++wlv.row;
4031 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004032
4033 // When not wrapping and finished diff lines, or when displayed
4034 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01004035 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004036#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004037 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004038#endif
4039#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01004040 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004041#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01004042 ) || lcs_eol_one == -1)
4043#ifdef FEAT_PROP_POPUP
4044 && !text_prop_follows
4045#endif
4046 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004047 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004048#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004049 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004050 {
4051 // do not output more of the line, only the "below" prop
4052 ptr += STRLEN(ptr);
4053# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004054 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004055# endif
4056 }
4057#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004058
4059 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004060 if (wlv.draw_state != WL_LINE
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
4064 )
4065 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004066 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
4067 draw_vsep_win(wp, wlv.row);
4068 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004069 }
4070
4071 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004072 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004073 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004074 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004075 break;
4076 }
4077
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004078 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004079#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004080 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004081#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004082#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004083 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004084#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004085 && wp->w_width == Columns)
4086 {
4087 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004088 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004089
4090 // Special trick to make copy/paste of wrapped lines work with
4091 // xterm/screen: write an extra character beyond the end of
4092 // the line. This will work with all terminal types
4093 // (regardless of the xn,am settings).
4094 // Only do this on a fast tty.
4095 // Only do this if the cursor is on the current line
4096 // (something has been written in it).
4097 // Don't do this for the GUI.
4098 // Don't do this for double-width characters.
4099 // Don't do this for a window not at the right screen border.
4100 if (p_tf
4101#ifdef FEAT_GUI
4102 && !gui.in_use
4103#endif
4104 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004105 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4106 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004107 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004108 || (*mb_off2cells)(
4109 LineOffset[wlv.screen_row - 1]
4110 + (int)Columns - 2,
4111 LineOffset[wlv.screen_row]
4112 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004113 {
4114 // First make sure we are at the end of the screen line,
4115 // then output the same character again to let the
4116 // terminal know about the wrap. If the terminal doesn't
4117 // auto-wrap, we overwrite the character.
4118 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004119 screen_char(LineOffset[wlv.screen_row - 1]
4120 + (unsigned)Columns - 1,
4121 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004122
4123 // When there is a multi-byte character, just output a
4124 // space to keep it simple.
4125 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004126 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004127 out_char(' ');
4128 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004129 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004130 + (Columns - 1)]);
4131 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004132 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004133 screen_start(); // don't know where cursor is now
4134 }
4135 }
4136
Bram Moolenaar1306b362022-08-06 15:59:06 +01004137 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004138
Bram Moolenaareed9d462021-02-15 20:38:25 +01004139 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004140#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004141 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004142# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004143 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004144# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004145 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004146 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004147#endif
4148#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004149 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004150 // When the filler lines are actually below the last line of the
4151 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004152 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004153 break;
4154#endif
4155 }
4156
4157 } // for every character in the line
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004158#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004159 vim_free(text_props);
4160 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004161 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004162#endif
4163
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004164 vim_free(wlv.p_extra_free);
zeertzjq58e1e012023-06-04 18:46:28 +01004165 vim_free(wlv.saved_p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004166 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004167}