blob: c1ff24c73eef316e169368f33f66979386a45adc [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 Moolenaar1306b362022-08-06 15:59:06 +010078// structure with variables passed between win_line() and other functions
79typedef struct {
80 int draw_state; // what to draw next
81
82 linenr_T lnum; // line number to be drawn
83
84 int startrow; // first row in the window to be drawn
85 int row; // row in the window, excl w_winrow
86 int screen_row; // row on the screen, incl w_winrow
87
88 long vcol; // virtual column, before wrapping
89 int col; // visual column on screen, after wrapping
90#ifdef FEAT_CONCEAL
91 int boguscols; // nonexistent columns added to "col" to force
92 // wrapping
93 int vcol_off; // offset for concealed characters
94#endif
95#ifdef FEAT_SYN_HL
96 int draw_color_col; // highlight colorcolumn
97 int *color_cols; // pointer to according columns array
98#endif
99 int eol_hl_off; // 1 if highlighted char after EOL
100
101 unsigned off; // offset in ScreenLines/ScreenAttrs
102
103 int win_attr; // background for the whole window, except
104 // margins and "~" lines.
Bram Moolenaard7657e92022-09-20 18:59:30 +0100105 int wcr_attr; // attributes from 'wincolor'
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100106#ifdef FEAT_SYN_HL
107 int cul_attr; // set when 'cursorline' active
108#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100109
110 int screen_line_flags; // flags for screen_line()
111
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100112 int fromcol; // start of inverting
113 int tocol; // end of inverting
114
115#ifdef FEAT_LINEBREAK
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100116 long vcol_sbr; // virtual column after showbreak
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100117 int need_showbreak; // overlong line, skipping first x chars
118 int dont_use_showbreak; // do not use 'showbreak'
119#endif
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100120#ifdef FEAT_PROP_POPUP
121 int text_prop_above_count;
122#endif
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100123
Bram Moolenaar1306b362022-08-06 15:59:06 +0100124 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
125 int cul_screenline;
126
127 int char_attr; // attributes for the next character
128
129 int n_extra; // number of extra bytes
130 char_u *p_extra; // string of extra chars, plus NUL, only used
131 // when c_extra and c_final are NUL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100132 char_u *p_extra_free; // p_extra buffer that needs to be freed
Bram Moolenaaree28c702022-11-17 14:56:00 +0000133 int extra_attr; // attributes for p_extra, should be combined
134 // with win_attr if needed
Bram Moolenaar1306b362022-08-06 15:59:06 +0100135 int c_extra; // extra chars, all the same
136 int c_final; // final char, mandatory if set
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000137 int extra_for_textprop; // wlv.n_extra set for textprop
Bram Moolenaar1306b362022-08-06 15:59:06 +0100138
139 // saved "extra" items for when draw_state becomes WL_LINE (again)
140 int saved_n_extra;
141 char_u *saved_p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000142 int saved_extra_attr;
143 int saved_extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100144 int saved_c_extra;
145 int saved_c_final;
146 int saved_char_attr;
147
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100148 char_u extra[NUMBUFLEN + MB_MAXBYTES];
149 // "%ld " and 'fdc' must fit in here, as well
150 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100151
Bram Moolenaar1306b362022-08-06 15:59:06 +0100152#ifdef FEAT_DIFF
153 hlf_T diff_hlf; // type of diff highlighting
154#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100155 int filler_lines; // nr of filler lines to be drawn
156 int filler_todo; // nr of filler lines still to do + 1
157#ifdef FEAT_SIGNS
158 sign_attrs_T sattr;
159#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100160} winlinevars_T;
161
162// draw_state values for items that are drawn in sequence:
163#define WL_START 0 // nothing done yet, must be zero
Martin Tournoij7904fa42022-10-04 16:28:45 +0100164#define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar1306b362022-08-06 15:59:06 +0100165#ifdef FEAT_FOLDING
166# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
167#else
168# define WL_FOLD WL_CMDLINE
169#endif
170#ifdef FEAT_SIGNS
171# define WL_SIGN (WL_FOLD + 1) // column for signs
172#else
173# define WL_SIGN WL_FOLD // column for signs
174#endif
175#define WL_NR (WL_SIGN + 1) // line number
176#ifdef FEAT_LINEBREAK
177# define WL_BRI (WL_NR + 1) // 'breakindent'
178#else
179# define WL_BRI WL_NR
180#endif
181#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
182# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
183#else
184# define WL_SBR WL_BRI
185#endif
186#define WL_LINE (WL_SBR + 1) // text in the line
187
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100188#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200189/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000190 * Return TRUE if CursorLineSign highlight is to be used.
191 */
192 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100193use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000194{
195 return wp->w_p_cul
196 && lnum == wp->w_cursor.lnum
197 && (wp->w_p_culopt_flags & CULOPT_NBR);
198}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100199#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000200
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100201
202#ifdef FEAT_FOLDING
203/*
204 * Setup for drawing the 'foldcolumn', if there is one.
205 */
206 static void
207handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
208{
209 int fdc = compute_foldcolumn(wp, 0);
210
211 if (fdc <= 0)
212 return;
213
214 // Allocate a buffer, "wlv->extra[]" may already be in use.
215 vim_free(wlv->p_extra_free);
216 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
217 if (wlv->p_extra_free != NULL)
218 {
219 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
220 wp, FALSE, wlv->lnum);
221 wlv->p_extra_free[wlv->n_extra] = NUL;
222 wlv->p_extra = wlv->p_extra_free;
223 wlv->c_extra = NUL;
224 wlv->c_final = NUL;
225 if (use_cursor_line_highlight(wp, wlv->lnum))
226 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
227 else
228 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
229 }
230}
231#endif
232
233#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000234/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100235 * Get information needed to display the sign in line "wlv->lnum" in window
236 * "wp".
237 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200238 * Otherwise the sign is going to be displayed in the sign column.
239 */
240 static void
241get_sign_display_info(
242 int nrcol,
243 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100244 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200245{
246 int text_sign;
247# ifdef FEAT_SIGN_ICONS
248 int icon_sign;
249# endif
250
251 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100252 wlv->c_extra = ' ';
253 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200254 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100255 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200256 else
257 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100258 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100259 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000260 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100261 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100262 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200263 }
264
Bram Moolenaar1306b362022-08-06 15:59:06 +0100265 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200266#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100267 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200268#endif
269 )
270 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100271 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200272# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100273 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200274 if (gui.in_use && icon_sign != 0)
275 {
276 // Use the image in this position.
277 if (nrcol)
278 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100279 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100280 sprintf((char *)wlv->extra, "%-*c ",
281 number_width(wp), SIGN_BYTE);
282 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100283 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200284 }
285 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100286 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200287# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100288 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
289 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200290 {
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 ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200295 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100296 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 = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200301 }
302# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100303 wlv->c_final = NUL;
304 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200305 }
306 else
307# endif
308 if (text_sign != 0)
309 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100310 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100311 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200312 {
313 if (nrcol)
314 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100315 int width = number_width(wp) - 2;
316 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200317
318 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100319 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100320 vim_snprintf((char *)wlv->extra + n,
321 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100322 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200323 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100324 wlv->c_extra = NUL;
325 wlv->c_final = NUL;
326 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200327 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000328
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100329 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100330 && wlv->sattr.sat_culhl > 0)
331 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000332 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100333 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200334 }
335 }
336}
337#endif
338
Bram Moolenaard7657e92022-09-20 18:59:30 +0100339/*
340 * Display the absolute or relative line number. After the first row fill with
341 * blanks when the 'n' flag isn't in 'cpo'.
342 */
343 static void
344handle_lnum_col(
345 win_T *wp,
346 winlinevars_T *wlv,
347 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100348 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100349{
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100350 int has_cpo_n = vim_strchr(p_cpo, CPO_NUMCOL) != NULL;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100351 int lnum_row = wlv->startrow + wlv->filler_lines
352#ifdef FEAT_PROP_POPUP
353 + wlv->text_prop_above_count
354#endif
355 ;
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100356
Bram Moolenaard7657e92022-09-20 18:59:30 +0100357 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100358 && (wlv->row <= lnum_row || !has_cpo_n)
Bram Moolenaar37251162022-10-06 20:48:00 +0100359 // there is no line number in a wrapped line when "n" is in
360 // 'cpoptions', but 'breakindent' assumes it anyway.
361 && !((has_cpo_n
362#ifdef FEAT_LINEBREAK
363 && !wp->w_p_bri
364#endif
365 ) && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100366 {
367#ifdef FEAT_SIGNS
368 // If 'signcolumn' is set to 'number' and a sign is present
369 // in 'lnum', then display the sign instead of the line
370 // number.
371 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
372 get_sign_display_info(TRUE, wp, wlv);
373 else
374#endif
375 {
376 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100377 // When there are text properties above the line put the line number
378 // below them.
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100379 if (wlv->row == lnum_row
Bram Moolenaareb4de622022-10-15 13:42:17 +0100380 && (wp->w_skipcol == 0 || wlv->row > wp->w_winrow
381 || (wp->w_p_nu && wp->w_p_rnu)))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100382 {
383 long num;
384 char *fmt = "%*ld ";
385
386 if (wp->w_p_nu && !wp->w_p_rnu)
387 // 'number' + 'norelativenumber'
388 num = (long)wlv->lnum;
389 else
390 {
391 // 'relativenumber', don't use negative numbers
392 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
393 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
394 {
395 // 'number' + 'relativenumber'
396 num = wlv->lnum;
397 fmt = "%-*ld ";
398 }
399 }
400
401 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100402 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100403 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
404 ++wlv->p_extra)
405 *wlv->p_extra = '-';
406#ifdef FEAT_RIGHTLEFT
407 if (wp->w_p_rl) // reverse line numbers
408 {
409 char_u *p1, *p2;
410 int t;
411
412 // like rl_mirror(), but keep the space at the end
413 p2 = skipwhite(wlv->extra);
414 p2 = skiptowhite(p2) - 1;
415 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
416 {
417 t = *p1;
418 *p1 = *p2;
419 *p2 = t;
420 }
421 }
422#endif
423 wlv->p_extra = wlv->extra;
424 wlv->c_extra = NUL;
425 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100426 }
427 else
428 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100429 wlv->c_extra = ' ';
430 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100431 }
432 wlv->n_extra = number_width(wp) + 1;
433 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
434#ifdef FEAT_SYN_HL
435 // When 'cursorline' is set highlight the line number of
436 // the current line differently.
437 // When 'cursorlineopt' does not have "line" only
438 // highlight the line number itself.
439 // TODO: Can we use CursorLine instead of CursorLineNr
440 // when CursorLineNr isn't set?
441 if (wp->w_p_cul
442 && wlv->lnum == wp->w_cursor.lnum
443 && (wp->w_p_culopt_flags & CULOPT_NBR)
444 && (wlv->row == wlv->startrow + wlv->filler_lines
445 || (wlv->row > wlv->startrow + wlv->filler_lines
446 && (wp->w_p_culopt_flags & CULOPT_LINE))))
447 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
448#endif
449 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
450 && HL_ATTR(HLF_LNA) != 0)
451 // Use LineNrAbove
452 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
453 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
454 && HL_ATTR(HLF_LNB) != 0)
455 // Use LineNrBelow
456 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
457 }
458#ifdef FEAT_SIGNS
459 if (num_attr)
460 wlv->char_attr = num_attr;
461#endif
462 }
463}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100464
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100465#ifdef FEAT_LINEBREAK
466 static void
467handle_breakindent(win_T *wp, winlinevars_T *wlv)
468{
469 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100470 && *get_showbreak_value(wp) != NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100471 // draw indent after showbreak value
472 wlv->draw_state = WL_BRI;
473 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
474 // After the showbreak, draw the breakindent
475 wlv->draw_state = WL_BRI - 1;
476
477 // draw 'breakindent': indent wrapped text accordingly
478 if (wlv->draw_state == WL_BRI - 1)
479 {
480 wlv->draw_state = WL_BRI;
481 // if wlv->need_showbreak is set, breakindent also applies
482 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
483# ifdef FEAT_DIFF
484 && wlv->filler_lines == 0
485# endif
486# ifdef FEAT_PROP_POPUP
487 && !wlv->dont_use_showbreak
488# endif
489 )
490 {
491 wlv->char_attr = 0;
492# ifdef FEAT_DIFF
493 if (wlv->diff_hlf != (hlf_T)0)
494 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
495# endif
496 wlv->p_extra = NULL;
497 wlv->c_extra = ' ';
498 wlv->c_final = NUL;
499 wlv->n_extra = get_breakindent_win(wp,
500 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
501 if (wlv->row == wlv->startrow)
502 {
503 wlv->n_extra -= win_col_off2(wp);
504 if (wlv->n_extra < 0)
505 wlv->n_extra = 0;
506 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100507 if (wp->w_skipcol > 0 && wlv->startrow == 0
508 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100509 wlv->need_showbreak = FALSE;
510 // Correct end of highlighted area for 'breakindent',
511 // required when 'linebreak' is also set.
512 if (wlv->tocol == wlv->vcol)
513 wlv->tocol += wlv->n_extra;
514 }
515 }
516}
517#endif
518
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100519#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
520 static void
521handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
522{
523# ifdef FEAT_DIFF
524 if (wlv->filler_todo > 0)
525 {
526 // Draw "deleted" diff line(s).
527 if (char2cells(wp->w_fill_chars.diff) > 1)
528 {
529 wlv->c_extra = '-';
530 wlv->c_final = NUL;
531 }
532 else
533 {
534 wlv->c_extra = wp->w_fill_chars.diff;
535 wlv->c_final = NUL;
536 }
537# ifdef FEAT_RIGHTLEFT
538 if (wp->w_p_rl)
539 wlv->n_extra = wlv->col + 1;
540 else
541# endif
542 wlv->n_extra = wp->w_width - wlv->col;
543 wlv->char_attr = HL_ATTR(HLF_DED);
544 }
545# endif
546
547# ifdef FEAT_LINEBREAK
548 char_u *sbr = get_showbreak_value(wp);
549 if (*sbr != NUL && wlv->need_showbreak)
550 {
551 // Draw 'showbreak' at the start of each broken line.
552 wlv->p_extra = sbr;
553 wlv->c_extra = NUL;
554 wlv->c_final = NUL;
555 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100556 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100557 wlv->need_showbreak = FALSE;
558 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
559 // Correct end of highlighted area for 'showbreak',
560 // required when 'linebreak' is also set.
561 if (wlv->tocol == wlv->vcol)
562 wlv->tocol += wlv->n_extra;
563 // combine 'showbreak' with 'wincolor'
564 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
565# ifdef FEAT_SYN_HL
566 // combine 'showbreak' with 'cursorline'
567 if (wlv->cul_attr != 0)
568 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
569# endif
570 }
571# endif
572}
573#endif
574
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100575#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100576/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100577 * Return the cell size of virtual text after truncation.
578 */
579 static int
580textprop_size_after_trunc(
581 win_T *wp,
582 int flags, // TP_FLAG_ALIGN_*
583 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100584 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100585 char_u *text,
586 int *n_used_ptr)
587{
588 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100589 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100590 int len = (int)STRLEN(text);
591 int strsize = 0;
592 int n_used;
593
Bram Moolenaar7e017462022-10-11 21:02:09 +0100594 // if the remaining size is to small and 'wrap' is set we wrap anyway and
595 // use the next line
596 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100597 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100598 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100599 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100600 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
601 {
602 int clen = ptr2cells(text + n_used);
603
604 if (strsize + clen > space)
605 break;
606 strsize += clen;
607 }
608 *n_used_ptr = n_used;
609 return strsize;
610}
611
612/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100613 * Take care of padding, right-align and truncation of virtual text after a
614 * line.
615 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
616 * padding, right-align and truncation. Otherwise only the size is computed.
617 * When "n_attr" is NULL returns the number of screen cells used.
618 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100619 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100620 int
621text_prop_position(
622 win_T *wp,
623 textprop_T *tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100624 int vcol UNUSED, // current text column
625 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100626 int *n_extra, // nr of bytes for virtual text
627 char_u **p_extra, // virtual text
628 int *n_attr, // attribute cells, NULL if not used
629 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200630{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100631 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100632 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100633 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
634 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
635 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
636 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100637 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100638 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100639 int before = room; // spaces before the text
640 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100641 int n_used = *n_extra;
642 char_u *l = NULL;
643 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100644 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100645 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar1206c162022-10-10 15:40:04 +0100646 int cont_on_next_line = below && col_with_padding > win_col_off(wp)
647 && !wp->w_p_wrap;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200648
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100649 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100650 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100651 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100652 int skip_add = 0;
653
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100654 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100655 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100656 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100657 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100658 }
659 else
660 {
661 // Right-align: fill with before
662 if (right)
663 before -= cells;
664 if (before < 0
665 || !(right || below)
666 || (below
Bram Moolenaarccf28372022-10-10 21:10:03 +0100667 ? (col_with_padding <= col_off || !wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100668 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100669 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100670 if (right && (wrap
671 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100672 {
673 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100674 before = wp->w_width - col_off - strsize + room;
675 if (before < 0)
676 before = 0;
677 else
678 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100679 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100680 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100681 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100682 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100683 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100684 else if (below && before > 0)
685 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100686 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100687 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100688
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100689 // With 'nowrap' add one to show the "extends" character if needed (it
690 // doesn't show if the text just fits).
691 if (!wp->w_p_wrap
692 && n_used < *n_extra
693 && wp->w_lcs_chars.ext != NUL
694 && wp->w_p_list)
695 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100696 if (!wp->w_p_wrap && below && padding > 0)
697 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100698
699 // add 1 for NUL, 2 for when '…' is used
700 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100701 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100702 if (n_attr == NULL || l != NULL)
703 {
704 int off = 0;
705
706 if (n_attr != NULL)
707 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100708 vim_memset(l, ' ', before);
709 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100710 if (padding > 0)
711 {
712 vim_memset(l + off, ' ', padding);
713 off += padding;
714 }
715 vim_strncpy(l + off, *p_extra, n_used);
716 off += n_used;
717 }
718 else
719 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100720 off = before + after + padding + n_used;
721 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100722 }
723 if (n_attr != NULL)
724 {
725 if (n_used < *n_extra && wp->w_p_wrap)
726 {
727 char_u *lp = l + off - 1;
728
729 if (has_mbyte)
730 {
731 // change last character to '…'
732 lp -= (*mb_head_off)(l, lp);
733 STRCPY(lp, "…");
Bram Moolenaar13845c42022-10-09 15:26:03 +0100734 n_used = lp - l + 3 - before - padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100735 }
736 else
737 // change last character to '>'
738 *lp = '>';
739 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100740 else if (after > 0)
741 {
742 vim_memset(l + off, ' ', after);
743 l[off + after] = NUL;
744 }
745
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100746 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100747 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100748 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100749 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100750 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100751
752 // Add "skip_add" when starting a new line or wrapping,
753 // n_attr_skip will then be decremented in the number column.
754 *n_attr_skip = before + padding
755 + (cont_on_next_line || before > 0 ? skip_add : 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100756 }
757 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100758 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100759
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100760 if (n_attr == NULL)
761 return cells;
762 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200763}
764#endif
765
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100766/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100767 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100768 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
769 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100770 */
771 static void
772wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
773{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100774 if (wlv->row == 0 && wp->w_skipcol > 0
775#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100776 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100777 && *get_showbreak_value(wp) == NUL
778#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100779 // do not overwrite the 'listchars' "precedes" text with "<<<"
780 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100781 {
782 int off = (int)(current_ScreenLine - ScreenLines);
Bram Moolenaareb4de622022-10-15 13:42:17 +0100783 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100784
Bram Moolenaareb4de622022-10-15 13:42:17 +0100785 if (wp->w_p_nu && wp->w_p_rnu)
786 // Do not overwrite the line number, change "123 text" to
787 // "123>>>xt".
788 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
789 {
790 ++off;
791 ++skip;
792 }
793
794 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100795 {
796 ScreenLines[off] = '<';
797 if (enc_utf8)
798 ScreenLinesUC[off] = 0;
799 ScreenAttrs[off] = HL_ATTR(HLF_AT);
800 ++off;
801 }
802 }
803
804 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
805 negative_width ? -wp->w_width : wp->w_width,
806 wlv->screen_line_flags);
807}
808
809/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100810 * Called when finished with the line: draw the screen line and handle any
811 * highlighting until the right of the window.
812 */
813 static void
814draw_screen_line(win_T *wp, winlinevars_T *wlv)
815{
816#ifdef FEAT_SYN_HL
817 long v;
818
819 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
820 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100821 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100822 else
823 v = wp->w_leftcol;
824
825 // check if line ends before left margin
826 if (wlv->vcol < v + wlv->col - win_col_off(wp))
827 wlv->vcol = v + wlv->col - win_col_off(wp);
828# ifdef FEAT_CONCEAL
829 // Get rid of the boguscols now, we want to draw until the right
830 // edge for 'cursorcolumn'.
831 wlv->col -= wlv->boguscols;
832 wlv->boguscols = 0;
833# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
834# else
835# define VCOL_HLC (wlv->vcol)
836# endif
837
838 if (wlv->draw_color_col)
839 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
840
841 if (((wp->w_p_cuc
842 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
843 && (int)wp->w_virtcol <
844 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
845 && wlv->lnum != wp->w_cursor.lnum)
846 || wlv->draw_color_col
847 || wlv->win_attr != 0)
848# ifdef FEAT_RIGHTLEFT
849 && !wp->w_p_rl
850# endif
851 )
852 {
853 int rightmost_vcol = 0;
854 int i;
855
856 if (wp->w_p_cuc)
857 rightmost_vcol = wp->w_virtcol;
858 if (wlv->draw_color_col)
859 // determine rightmost colorcolumn to possibly draw
860 for (i = 0; wlv->color_cols[i] >= 0; ++i)
861 if (rightmost_vcol < wlv->color_cols[i])
862 rightmost_vcol = wlv->color_cols[i];
863
864 while (wlv->col < wp->w_width)
865 {
866 ScreenLines[wlv->off] = ' ';
867 if (enc_utf8)
868 ScreenLinesUC[wlv->off] = 0;
869 ScreenCols[wlv->off] = MAXCOL;
870 ++wlv->col;
871 if (wlv->draw_color_col)
872 wlv->draw_color_col = advance_color_col(
873 VCOL_HLC, &wlv->color_cols);
874
875 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
876 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
877 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
878 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
879 else
880 ScreenAttrs[wlv->off++] = wlv->win_attr;
881
882 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
883 break;
884
885 ++wlv->vcol;
886 }
887 }
888#endif
889
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100890 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100891 ++wlv->row;
892 ++wlv->screen_row;
893}
894#undef VCOL_HLC
895
896/*
897 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100898 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100899 */
900 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100901win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100902{
903 wlv->col = 0;
904 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
905
906#ifdef FEAT_RIGHTLEFT
907 if (wp->w_p_rl)
908 {
909 // Rightleft window: process the text in the normal direction, but put
910 // it in current_ScreenLine[] from right to left. Start at the
911 // rightmost column of the window.
912 wlv->col = wp->w_width - 1;
913 wlv->off += wlv->col;
914 wlv->screen_line_flags |= SLF_RIGHTLEFT;
915 }
916#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100917 if (save_extra)
918 {
919 // reset the drawing state for the start of a wrapped line
920 wlv->draw_state = WL_START;
921 wlv->saved_n_extra = wlv->n_extra;
922 wlv->saved_p_extra = wlv->p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000923 wlv->saved_extra_attr = wlv->extra_attr;
924 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100925 wlv->saved_c_extra = wlv->c_extra;
926 wlv->saved_c_final = wlv->c_final;
927#ifdef FEAT_SYN_HL
928 if (!(wlv->cul_screenline
929# ifdef FEAT_DIFF
930 && wlv->diff_hlf == (hlf_T)0
931# endif
932 ))
933 wlv->saved_char_attr = wlv->char_attr;
934 else
935#endif
936 wlv->saved_char_attr = 0;
937 wlv->n_extra = 0;
938 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100939}
940
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200941/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100942 * Called when wlv->draw_state is set to WL_LINE.
943 */
944 static void
945win_line_continue(winlinevars_T *wlv)
946{
947 if (wlv->saved_n_extra > 0)
948 {
949 // Continue item from end of wrapped line.
950 wlv->n_extra = wlv->saved_n_extra;
951 wlv->c_extra = wlv->saved_c_extra;
952 wlv->c_final = wlv->saved_c_final;
953 wlv->p_extra = wlv->saved_p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000954 wlv->extra_attr = wlv->saved_extra_attr;
955 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100956 wlv->char_attr = wlv->saved_char_attr;
957 }
958 else
959 wlv->char_attr = wlv->win_attr;
960}
961
962/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200963 * Display line "lnum" of window 'wp' on the screen.
964 * Start at row "startrow", stop when "endrow" is reached.
965 * wp->w_virtcol needs to be valid.
966 *
967 * Return the number of last row the line occupies.
968 */
969 int
970win_line(
971 win_T *wp,
972 linenr_T lnum,
973 int startrow,
974 int endrow,
975 int nochange UNUSED, // not updating for changed text
976 int number_only) // only update the number column
977{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100978 winlinevars_T wlv; // variables passed between functions
979
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200980 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100981 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200982 char_u *line; // current line
983 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200984
Bram Moolenaar1306b362022-08-06 15:59:06 +0100985#ifdef FEAT_PROP_POPUP
986 char_u *p_extra_free2 = NULL; // another p_extra to be freed
987#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000988#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000989 int in_linebreak = FALSE; // n_extra set for showing linebreak
990#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200991 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100992 // displaying eol at end-of-line
993 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000994 int lcs_prec_todo = wp->w_lcs_chars.prec;
995 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200996
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100997 int n_attr = 0; // chars with special attr
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000998 int n_attr_skip = 0; // chars to skip bef. using wlv.extra_attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100999 int saved_attr2 = 0; // char_attr saved for n_attr
1000 int n_attr3 = 0; // chars with overruling special attr
1001 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001002
Bram Moolenaarcd105412022-10-10 19:50:42 +01001003 int n_skip = 0; // nr of cells to skip for 'nowrap' or
1004 // concealing
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001005#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001006 int skip_cells = 0; // nr of cells to skip for virtual text
1007 // after the line, when w_skipcol is
1008 // larger than the text length
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001009#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001010
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001011 int fromcol_prev = -2; // start of inverting after cursor
1012 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001013 int lnum_in_visual_area = FALSE;
1014 pos_T pos;
1015 long v;
1016
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001017 int attr_pri = FALSE; // char_attr has priority
1018 int area_highlighting = FALSE; // Visual or incsearch highlighting
1019 // in this line
1020 int vi_attr = 0; // attributes for Visual and incsearch
1021 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001022 int area_attr = 0; // attributes desired by highlighting
1023 int search_attr = 0; // attributes desired by 'hlsearch'
1024#ifdef FEAT_SYN_HL
1025 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1026 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001027 int prev_syntax_col = -1; // column of prev_syntax_attr
1028 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001029 int has_syntax = FALSE; // this buffer has syntax highl.
1030 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001031#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001032#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001033 int text_prop_count;
1034 int text_prop_next = 0; // next text property to use
1035 textprop_T *text_props = NULL;
1036 int *text_prop_idxs = NULL;
1037 int text_props_active = 0;
1038 proptype_T *text_prop_type = NULL;
1039 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001040 int text_prop_attr_comb = 0; // text_prop_attr combined with
1041 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001042 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001043 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001044 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001045 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001046 int saved_search_attr = 0; // search_attr to be used when n_extra
1047 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001048 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001049#endif
1050#ifdef FEAT_SPELL
1051 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001052 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001053# define SPWORDLEN 150
1054 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1055 int nextlinecol = 0; // column where nextline[] starts
1056 int nextline_idx = 0; // index in nextline[] where next line
1057 // starts
1058 int spell_attr = 0; // attributes desired by spelling
1059 int word_end = 0; // last byte with same spell_attr
1060 static linenr_T checked_lnum = 0; // line number for "checked_col"
1061 static int checked_col = 0; // column in "checked_lnum" up to which
1062 // there are no spell errors
1063 static int cap_col = -1; // column to check for Cap word
1064 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1065 int cur_checked_col = 0; // checked column for current line
1066#endif
1067 int extra_check = 0; // has extra highlighting
1068 int multi_attr = 0; // attributes desired by multibyte
1069 int mb_l = 1; // multi-byte byte length
1070 int mb_c = 0; // decoded multi-byte character
1071 int mb_utf8 = FALSE; // screen char is UTF-8 char
1072 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001073#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001074 int change_start = MAXCOL; // first col of changed area
1075 int change_end = -1; // last col of changed area
1076#endif
1077 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001078 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001079 int in_multispace = FALSE; // in multiple consecutive spaces
1080 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001081#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
1082 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
1083# define LINE_ATTR
1084 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +01001085 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001086#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001087 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001088 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001089#ifdef FEAT_ARABIC
1090 int prev_c = 0; // previous Arabic character
1091 int prev_c1 = 0; // first composing char for prev_c
1092#endif
1093#if defined(LINE_ATTR)
1094 int did_line_attr = 0;
1095#endif
1096#ifdef FEAT_TERMINAL
1097 int get_term_attr = FALSE;
1098#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001099
Martin Tournoijba43e762022-10-13 22:12:15 +01001100#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001101 // margin columns for the screen line, needed for when 'cursorlineopt'
1102 // contains "screenline"
1103 int left_curline_col = 0;
1104 int right_curline_col = 0;
1105#endif
1106
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001107#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1108 int feedback_col = 0;
1109 int feedback_old_attr = -1;
1110#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001111
1112#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1113 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001114#endif
1115#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001116 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001117#endif
1118#ifdef FEAT_CONCEAL
1119 int syntax_flags = 0;
1120 int syntax_seqnr = 0;
1121 int prev_syntax_id = 0;
1122 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1123 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001124 int did_wcol = FALSE;
1125 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001126# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001127# define FIX_FOR_BOGUSCOLS \
1128 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001129 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001130 wlv.vcol -= wlv.vcol_off; \
1131 wlv.vcol_off = 0; \
1132 wlv.col -= wlv.boguscols; \
1133 old_boguscols = wlv.boguscols; \
1134 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001135 }
1136#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001137# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001138#endif
1139
1140 if (startrow > endrow) // past the end already!
1141 return startrow;
1142
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001143 CLEAR_FIELD(wlv);
1144
1145 wlv.lnum = lnum;
1146 wlv.startrow = startrow;
1147 wlv.row = startrow;
1148 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001149 wlv.fromcol = -10;
1150 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001151#ifdef FEAT_LINEBREAK
1152 wlv.vcol_sbr = -1;
1153#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001154
1155 if (!number_only)
1156 {
1157 // To speed up the loop below, set extra_check when there is linebreak,
1158 // trailing white space and/or syntax processing to be done.
1159#ifdef FEAT_LINEBREAK
1160 extra_check = wp->w_p_lbr;
1161#endif
1162#ifdef FEAT_SYN_HL
1163 if (syntax_present(wp) && !wp->w_s->b_syn_error
1164# ifdef SYN_TIME_LIMIT
1165 && !wp->w_s->b_syn_slow
1166# endif
1167 )
1168 {
1169 // Prepare for syntax highlighting in this line. When there is an
1170 // error, stop syntax highlighting.
1171 save_did_emsg = did_emsg;
1172 did_emsg = FALSE;
1173 syntax_start(wp, lnum);
1174 if (did_emsg)
1175 wp->w_s->b_syn_error = TRUE;
1176 else
1177 {
1178 did_emsg = save_did_emsg;
1179#ifdef SYN_TIME_LIMIT
1180 if (!wp->w_s->b_syn_slow)
1181#endif
1182 {
1183 has_syntax = TRUE;
1184 extra_check = TRUE;
1185 }
1186 }
1187 }
1188
1189 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001190 wlv.color_cols = wp->w_p_cc_cols;
1191 if (wlv.color_cols != NULL)
1192 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001193#endif
1194
1195#ifdef FEAT_TERMINAL
1196 if (term_show_buffer(wp->w_buffer))
1197 {
1198 extra_check = TRUE;
1199 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001200 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001201 }
1202#endif
1203
1204#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001205 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001206 {
1207 // Prepare for spell checking.
1208 has_spell = TRUE;
1209 extra_check = TRUE;
1210
1211 // Get the start of the next line, so that words that wrap to the
1212 // next line are found too: "et<line-break>al.".
1213 // Trick: skip a few chars for C/shell/Vim comments
1214 nextline[SPWORDLEN] = NUL;
1215 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1216 {
1217 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1218 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1219 }
1220
1221 // When a word wrapped from the previous line the start of the
1222 // current line is valid.
1223 if (lnum == checked_lnum)
1224 cur_checked_col = checked_col;
1225 checked_lnum = 0;
1226
1227 // When there was a sentence end in the previous line may require a
1228 // word starting with capital in this line. In line 1 always check
1229 // the first word.
1230 if (lnum != capcol_lnum)
1231 cap_col = -1;
1232 if (lnum == 1)
1233 cap_col = 0;
1234 capcol_lnum = 0;
1235 }
1236#endif
1237
1238 // handle Visual active in this window
1239 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1240 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001241 pos_T *top, *bot;
1242
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001243 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1244 {
1245 // Visual is after curwin->w_cursor
1246 top = &curwin->w_cursor;
1247 bot = &VIsual;
1248 }
1249 else
1250 {
1251 // Visual is before curwin->w_cursor
1252 top = &VIsual;
1253 bot = &curwin->w_cursor;
1254 }
1255 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1256 if (VIsual_mode == Ctrl_V)
1257 {
1258 // block mode
1259 if (lnum_in_visual_area)
1260 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001261 wlv.fromcol = wp->w_old_cursor_fcol;
1262 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001263 }
1264 }
1265 else
1266 {
1267 // non-block mode
1268 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001269 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001270 else if (lnum == top->lnum)
1271 {
1272 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001273 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001274 else
1275 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001276 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001277 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001278 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001279 }
1280 }
1281 if (VIsual_mode != 'V' && lnum == bot->lnum)
1282 {
1283 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1284 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001285 wlv.fromcol = -10;
1286 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001287 }
1288 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001289 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001290 else
1291 {
1292 pos = *bot;
1293 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001294 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1295 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001296 else
1297 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001298 getvvcol(wp, &pos, NULL, NULL,
1299 (colnr_T *)&wlv.tocol);
1300 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001301 }
1302 }
1303 }
1304 }
1305
1306 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001307 if (!highlight_match && lnum == curwin->w_cursor.lnum
1308 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001309#ifdef FEAT_GUI
1310 && !gui.in_use
1311#endif
1312 )
1313 noinvcur = TRUE;
1314
1315 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001316 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001317 {
1318 area_highlighting = TRUE;
1319 vi_attr = HL_ATTR(HLF_V);
1320#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1321 if ((clip_star.available && !clip_star.owned
1322 && clip_isautosel_star())
1323 || (clip_plus.available && !clip_plus.owned
1324 && clip_isautosel_plus()))
1325 vi_attr = HL_ATTR(HLF_VNC);
1326#endif
1327 }
1328 }
1329
1330 // handle 'incsearch' and ":s///c" highlighting
1331 else if (highlight_match
1332 && wp == curwin
1333 && lnum >= curwin->w_cursor.lnum
1334 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1335 {
1336 if (lnum == curwin->w_cursor.lnum)
1337 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001338 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001339 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001340 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001341 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1342 {
1343 pos.lnum = lnum;
1344 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001345 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001346 }
1347 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001348 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001349 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001350 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1351 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001352 area_highlighting = TRUE;
1353 vi_attr = HL_ATTR(HLF_I);
1354 }
1355 }
1356
1357#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001358 wlv.filler_lines = diff_check(wp, lnum);
1359 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001360 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001361 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001362 {
1363 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001364 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001365 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001366 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001367 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001368 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001369 }
1370 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001371 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001372 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001373 area_highlighting = TRUE;
1374 }
1375 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001376 wlv.filler_lines = wp->w_topfill;
1377 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001378#endif
1379
1380#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001381 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001382 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001383 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001384#endif
1385
1386#ifdef LINE_ATTR
1387# ifdef FEAT_SIGNS
1388 // If this line has a sign with line highlighting set line_attr.
1389 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001390 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001391# endif
1392# if defined(FEAT_QUICKFIX)
1393 // Highlight the current line in the quickfix window.
1394 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1395 line_attr = HL_ATTR(HLF_QFL);
1396# endif
1397 if (line_attr != 0)
1398 area_highlighting = TRUE;
1399#endif
1400
1401 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1402 ptr = line;
1403
1404#ifdef FEAT_SPELL
1405 if (has_spell && !number_only)
1406 {
1407 // For checking first word with a capital skip white space.
1408 if (cap_col == 0)
1409 cap_col = getwhitecols(line);
1410
1411 // To be able to spell-check over line boundaries copy the end of the
1412 // current line into nextline[]. Above the start of the next line was
1413 // copied to nextline[SPWORDLEN].
1414 if (nextline[SPWORDLEN] == NUL)
1415 {
1416 // No next line or it is empty.
1417 nextlinecol = MAXCOL;
1418 nextline_idx = 0;
1419 }
1420 else
1421 {
1422 v = (long)STRLEN(line);
1423 if (v < SPWORDLEN)
1424 {
1425 // Short line, use it completely and append the start of the
1426 // next line.
1427 nextlinecol = 0;
1428 mch_memmove(nextline, line, (size_t)v);
1429 STRMOVE(nextline + v, nextline + SPWORDLEN);
1430 nextline_idx = v + 1;
1431 }
1432 else
1433 {
1434 // Long line, use only the last SPWORDLEN bytes.
1435 nextlinecol = v - SPWORDLEN;
1436 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1437 nextline_idx = SPWORDLEN + 1;
1438 }
1439 }
1440 }
1441#endif
1442
1443 if (wp->w_p_list)
1444 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001445 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001446 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001447 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001448 || wp->w_lcs_chars.trail
1449 || wp->w_lcs_chars.lead
1450 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001451 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001452
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001453 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001454 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001455 {
1456 trailcol = (colnr_T)STRLEN(ptr);
1457 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1458 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001459 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001460 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001461 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001462 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001463 {
1464 leadcol = 0;
1465 while (VIM_ISWHITE(ptr[leadcol]))
1466 ++leadcol;
1467 if (ptr[leadcol] == NUL)
1468 // in a line full of spaces all of them are treated as trailing
1469 leadcol = (colnr_T)0;
1470 else
1471 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001472 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001473 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001474 }
1475
Bram Moolenaard7657e92022-09-20 18:59:30 +01001476 wlv.wcr_attr = get_wcr_attr(wp);
1477 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001478 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001479 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001480 area_highlighting = TRUE;
1481 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001482
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001483#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001484 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001485 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001486#endif
1487
1488 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1489 // first character to be displayed.
1490 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001491 v = startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001492 else
1493 v = wp->w_leftcol;
1494 if (v > 0 && !number_only)
1495 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001496 char_u *prev_ptr = ptr;
1497 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001498 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001499
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001500 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001501 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001502 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001503 charsize = win_lbr_chartabsize(&cts, NULL);
1504 cts.cts_vcol += charsize;
1505 prev_ptr = cts.cts_ptr;
1506 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001507 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001508 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001509 ptr = cts.cts_ptr;
1510 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001511
1512 // When:
1513 // - 'cuc' is set, or
1514 // - 'colorcolumn' is set, or
1515 // - 'virtualedit' is set, or
1516 // - the visual mode is active,
1517 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001518 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001519#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001520 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001521#endif
1522 virtual_active() ||
1523 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001524 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001525
1526 // Handle a character that's not completely on the screen: Put ptr at
1527 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001528 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001529 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001530 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001531 ptr = prev_ptr;
1532 // If the character fits on the screen, don't need to skip it.
1533 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001534 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1535 && wlv.col == 0)
1536 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001537 }
1538
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001539#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001540 // If there the text doesn't reach to the desired column, need to skip
1541 // "skip_cells" cells when virtual text follows.
1542 if (!wp->w_p_wrap && v > wlv.vcol)
1543 skip_cells = v - wlv.vcol;
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001544#endif
Bram Moolenaarcd105412022-10-10 19:50:42 +01001545
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001546 // Adjust for when the inverted text is before the screen,
1547 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001548 if (wlv.tocol <= wlv.vcol)
1549 wlv.fromcol = 0;
1550 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1551 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001552
1553#ifdef FEAT_LINEBREAK
1554 // When w_skipcol is non-zero, first line needs 'showbreak'
1555 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001556 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001557#endif
1558#ifdef FEAT_SPELL
1559 // When spell checking a word we need to figure out the start of the
1560 // word and if it's badly spelled or not.
1561 if (has_spell)
1562 {
1563 int len;
1564 colnr_T linecol = (colnr_T)(ptr - line);
1565 hlf_T spell_hlf = HLF_COUNT;
1566
1567 pos = wp->w_cursor;
1568 wp->w_cursor.lnum = lnum;
1569 wp->w_cursor.col = linecol;
1570 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1571
1572 // spell_move_to() may call ml_get() and make "line" invalid
1573 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1574 ptr = line + linecol;
1575
1576 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1577 {
1578 // no bad word found at line start, don't check until end of a
1579 // word
1580 spell_hlf = HLF_COUNT;
1581 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1582 }
1583 else
1584 {
1585 // bad word found, use attributes until end of word
1586 word_end = wp->w_cursor.col + len + 1;
1587
1588 // Turn index into actual attributes.
1589 if (spell_hlf != HLF_COUNT)
1590 spell_attr = highlight_attr[spell_hlf];
1591 }
1592 wp->w_cursor = pos;
1593
1594# ifdef FEAT_SYN_HL
1595 // Need to restart syntax highlighting for this line.
1596 if (has_syntax)
1597 syntax_start(wp, lnum);
1598# endif
1599 }
1600#endif
1601 }
1602
1603 // Correct highlighting for cursor that can't be disabled.
1604 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001605 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001606 {
1607 if (noinvcur)
1608 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001609 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001610 {
1611 // highlighting starts at cursor, let it start just after the
1612 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001613 fromcol_prev = wlv.fromcol;
1614 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001615 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001616 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001617 // restart highlighting after the cursor
1618 fromcol_prev = wp->w_virtcol;
1619 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001620 if (wlv.fromcol >= wlv.tocol)
1621 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001622 }
1623
1624#ifdef FEAT_SEARCH_EXTRA
1625 if (!number_only)
1626 {
1627 v = (long)(ptr - line);
1628 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1629 &line, &screen_search_hl,
1630 &search_attr);
1631 ptr = line + v; // "line" may have been updated
1632 }
1633#endif
1634
1635#ifdef FEAT_SYN_HL
1636 // Cursor line highlighting for 'cursorline' in the current window.
1637 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1638 {
1639 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001640 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001641 if (!(wp == curwin && VIsual_active)
1642 && wp->w_p_culopt_flags != CULOPT_NBR)
1643 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001644 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001645 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1646
1647 // Only set line_attr here when "screenline" is not present in
1648 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001649 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001650 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001651 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001652# ifdef FEAT_SIGNS
1653 // Combine the 'cursorline' and sign highlighting, depending on
1654 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001655 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001656 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001657 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001658 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001659 else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001660 line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001661 }
1662 else
1663# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001664# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001665 // let the line attribute overrule 'cursorline', otherwise
1666 // it disappears when both have background set;
1667 // 'cursorline' can use underline or bold to make it show
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001668 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001669# else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001670 line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001671# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001672 }
1673 else
1674 {
1675 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001676 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1677 }
1678 area_highlighting = TRUE;
1679 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001680 }
1681#endif
1682
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001683#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001684 {
1685 char_u *prop_start;
1686
1687 text_prop_count = get_text_props(wp->w_buffer, lnum,
1688 &prop_start, FALSE);
1689 if (text_prop_count > 0)
1690 {
1691 // Make a copy of the properties, so that they are properly
1692 // aligned.
1693 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1694 if (text_props != NULL)
1695 mch_memmove(text_props, prop_start,
1696 text_prop_count * sizeof(textprop_T));
1697
1698 // Allocate an array for the indexes.
1699 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001700 if (text_prop_idxs == NULL)
1701 VIM_CLEAR(text_props);
1702
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001703 if (text_props != NULL)
1704 {
1705 area_highlighting = TRUE;
1706 extra_check = TRUE;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +01001707 // text props "above" move the line number down to where the
1708 // text is.
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001709 for (int i = 0; i < text_prop_count; ++i)
1710 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1711 ++wlv.text_prop_above_count;
1712 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001713 }
1714 }
1715#endif
1716
Bram Moolenaar1306b362022-08-06 15:59:06 +01001717 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001718
1719 // Repeat for the whole displayed line.
1720 for (;;)
1721 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001722 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001723#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001724 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001725#endif
1726#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001727 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001728#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001729
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001730 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001731 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001732 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001733#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001734 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001735 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001736 wlv.cul_attr = 0;
zeertzjq4f33bc22021-08-05 17:57:02 +02001737 line_attr = line_attr_save;
1738 }
1739#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001740 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001741 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001742 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001743 if (cmdwin_type != 0 && wp == curwin)
1744 {
1745 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001746 wlv.n_extra = 1;
1747 wlv.c_extra = cmdwin_type;
1748 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001749 wlv.char_attr =
1750 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001751 }
1752 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001753#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001754 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001755 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001756 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001757 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001758 }
1759#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001760#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001761 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001762 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001763 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001764 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001765 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001766 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001767 }
1768#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001769 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001770 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001771 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001772 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001773 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001774 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001775#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001776 // Check if 'breakindent' applies and show it.
1777 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1778 if (wlv.n_extra == 0)
1779 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001780#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001781#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001782 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001783 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001784 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001785 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001786 }
1787#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001788 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001789 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001790 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001791 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001792 }
1793 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001794
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001795#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001796 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001797 && wlv.vcol >= left_curline_col
1798 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001799 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001800 wlv.cul_attr = HL_ATTR(HLF_CUL);
1801 line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001802 }
1803#endif
1804
1805 // When still displaying '$' of change command, stop at cursor.
1806 // When only displaying the (relative) line number and that's done,
1807 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001808 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001809 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001810 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001811#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001812 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001813#endif
1814 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001815 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001816 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001817 // Pretend we have finished updating the window. Except when
1818 // 'cursorcolumn' is set.
1819#ifdef FEAT_SYN_HL
1820 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001821 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001822 else
1823#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001824 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001825 break;
1826 }
1827
Bram Moolenaar1306b362022-08-06 15:59:06 +01001828 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001829 {
1830 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001831 if (wlv.vcol == wlv.fromcol
1832 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1833 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001834 && (*mb_ptr2cells)(ptr) > 1)
1835 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001836 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001837 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001838 area_attr = vi_attr; // start highlighting
1839 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001840 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001841 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001842 area_attr = 0; // stop highlighting
1843
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001844#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001845 if (text_props != NULL)
1846 {
1847 int pi;
1848 int bcol = (int)(ptr - line);
1849
Bram Moolenaar1306b362022-08-06 15:59:06 +01001850 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001851# ifdef FEAT_LINEBREAK
1852 && !in_linebreak
1853# endif
1854 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001855 --bcol; // still working on the previous char, e.g. Tab
1856
1857 // Check if any active property ends.
1858 for (pi = 0; pi < text_props_active; ++pi)
1859 {
1860 int tpi = text_prop_idxs[pi];
1861
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001862 if (text_props[tpi].tp_col != MAXCOL
1863 && bcol >= text_props[tpi].tp_col - 1
1864 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001865 {
1866 if (pi + 1 < text_props_active)
1867 mch_memmove(text_prop_idxs + pi,
1868 text_prop_idxs + pi + 1,
1869 sizeof(int)
1870 * (text_props_active - (pi + 1)));
1871 --text_props_active;
1872 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001873# ifdef FEAT_LINEBREAK
1874 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001875 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001876 syntax_attr = 0;
1877# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001878 }
1879 }
1880
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001881# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001882 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001883 // not on the next char yet, don't start another prop
1884 --bcol;
1885# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001886 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001887 // With 'nowrap' and not in the first screen line only "below"
1888 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001889 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001890 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001891 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001892 && (wp->w_p_wrap
1893 || wlv.row == startrow
1894 || (text_props[text_prop_next].tp_flags
1895 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001896 || (bcol == 0 &&
1897 (text_props[text_prop_next].tp_flags
1898 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001899 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001900 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001901 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001902 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1903 {
1904 // first display the '$' after the line
1905 text_prop_follows = TRUE;
1906 break;
1907 }
1908 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001909 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001910 + text_props[text_prop_next].tp_len)
1911 text_prop_idxs[text_props_active++] = text_prop_next;
1912 ++text_prop_next;
1913 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001914
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001915 if (wlv.n_extra == 0 || !wlv.extra_for_textprop)
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001916 {
1917 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001918 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001919 text_prop_flags = 0;
1920 text_prop_type = NULL;
1921 text_prop_id = 0;
1922 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001923 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001924 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001925 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001926 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001927 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001928
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001929 // Sort the properties on priority and/or starting last.
1930 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001931 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001932 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001933 sort_text_props(wp->w_buffer, text_props,
1934 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001935
1936 for (pi = 0; pi < text_props_active; ++pi)
1937 {
1938 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001939 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001940 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01001941 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001942
Bram Moolenaarcd105412022-10-10 19:50:42 +01001943 // Only use a text property that can be displayed.
1944 // Skip "after" properties when wrap is off and at the
1945 // end of the window.
1946 if (pt != NULL
1947 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
1948 && tp->tp_id != -MAXCOL
1949 && !(tp->tp_id < 0
1950 && !wp->w_p_wrap
1951 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
1952 | TP_FLAG_ALIGN_ABOVE
1953 | TP_FLAG_ALIGN_BELOW)) == 0
1954 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001955 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001956 if (pt->pt_hl_id > 0)
1957 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001958 text_prop_type = pt;
1959 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001960 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001961 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001962 text_prop_flags = pt->pt_flags;
1963 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001964 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001965 }
1966 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001967 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001968 && -text_prop_id
1969 <= wp->w_buffer->b_textprop_text.ga_len)
1970 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001971 textprop_T *tp = &text_props[used_tpi];
1972 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001973 ->b_textprop_text.ga_data)[
1974 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001975 int above = (tp->tp_flags
1976 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01001977 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001978
1979 // reset the ID in the copy to avoid it being used
1980 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001981 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001982
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001983 if (p != NULL)
1984 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001985 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001986 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001987 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001988 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001989 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1990 int padding = tp->tp_col == MAXCOL
1991 && tp->tp_len > 1
1992 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001993
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001994 // Insert virtual text before the current
1995 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001996 wlv.p_extra = p;
1997 wlv.c_extra = NUL;
1998 wlv.c_final = NUL;
1999 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002000 wlv.extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002001 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2002 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002003 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002004 // restore search_attr and area_attr when n_extra
2005 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01002006 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002007 saved_area_attr = area_attr;
2008 search_attr = 0;
2009 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002010 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002011 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002012 if (*ptr == NUL)
2013 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002014 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002015#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002016 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002017 {
2018 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002019 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002020 wlv.need_showbreak = FALSE;
2021 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002022 }
2023#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002024 if ((right || above || below || !wrap
2025 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002026 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002027 char_u *prev_p_extra = wlv.p_extra;
2028 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002029
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002030 // Take care of padding, right-align and
2031 // truncation.
2032 // Shared with win_lbr_chartabsize(), must do
2033 // exactly the same.
2034 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002035 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002036 wlv.col,
2037 &wlv.n_extra, &wlv.p_extra,
2038 &n_attr, &n_attr_skip);
2039 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002040 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002041 // wlv.p_extra was allocated
2042 vim_free(p_extra_free2);
2043 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002044 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002045
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002046 if (lcs_eol_one < 0
2047 && wp->w_p_wrap
2048 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002049 + wlv.n_extra - 2 > wp->w_width)
2050 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002051 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002052
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002053 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002054 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002055 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002056 {
2057 draw_screen_line(wp, &wlv);
2058
2059 // When line got too long for screen break
2060 // here.
2061 if (wlv.row == endrow)
2062 {
2063 ++wlv.row;
2064 break;
2065 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002066 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002067 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002068 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002069 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002070 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002071
Bram Moolenaarcd105412022-10-10 19:50:42 +01002072 // If the text didn't reach until the first window
2073 // column we need to skip cells.
2074 if (skip_cells > 0)
2075 {
2076 if (wlv.n_extra > skip_cells)
2077 {
2078 wlv.n_extra -= skip_cells;
2079 wlv.p_extra += skip_cells;
2080 n_attr_skip -= skip_cells;
2081 if (n_attr_skip < 0)
2082 n_attr_skip = 0;
2083 skip_cells = 0;
2084 }
2085 else
2086 {
2087 // the whole text is left of the window, drop
2088 // it and advance to the next one
2089 skip_cells -= wlv.n_extra;
2090 wlv.n_extra = 0;
2091 n_attr_skip = 0;
2092 bail_out = TRUE;
2093 }
2094 }
2095
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002096 // If another text prop follows the condition below at
2097 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002098 // If this is an "above" text prop and 'nowrap' the we
2099 // must wrap anyway.
2100 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002101 text_prop_follows |= other_tpi != -1
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002102 && (wp->w_p_wrap
2103 || (text_props[other_tpi].tp_flags
2104 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002105
2106 if (bail_out)
2107 // starting a new line for "below"
2108 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002109 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002110 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002111 else if (text_prop_next < text_prop_count
2112 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002113 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2114 || (!wp->w_p_wrap
2115 && wlv.col == wp->w_width - 1
2116 && (text_props[text_prop_next].tp_flags
2117 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002118 // When at last-but-one character and a text property
2119 // follows after it, we may need to flush the line after
2120 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002121 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002122 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002123 }
2124#endif
2125
Bram Moolenaare38fc862022-08-11 17:24:50 +01002126#ifdef FEAT_SEARCH_EXTRA
2127 if (wlv.n_extra == 0)
2128 {
2129 // Check for start/end of 'hlsearch' and other matches.
2130 // After end, check for start/end of next match.
2131 // When another match, have to check for start again.
2132 v = (long)(ptr - line);
2133 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2134 &screen_search_hl, &has_match_conc,
2135 &match_conc, did_line_attr, lcs_eol_one,
2136 &on_last_col);
2137 ptr = line + v; // "line" may have been changed
2138 prev_ptr = ptr;
2139
2140 // Do not allow a conceal over EOL otherwise EOL will be missed
2141 // and bad things happen.
2142 if (*ptr == NUL)
2143 has_match_conc = 0;
2144 }
2145#endif
2146
2147#ifdef FEAT_DIFF
2148 if (wlv.diff_hlf != (hlf_T)0)
2149 {
2150 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2151 && wlv.n_extra == 0)
2152 wlv.diff_hlf = HLF_TXD; // changed text
2153 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2154 && wlv.n_extra == 0)
2155 wlv.diff_hlf = HLF_CHD; // changed line
2156 line_attr = HL_ATTR(wlv.diff_hlf);
2157 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2158 && wp->w_p_culopt_flags != CULOPT_NBR
2159 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2160 && wlv.vcol <= right_curline_col)))
2161 line_attr = hl_combine_attr(
2162 line_attr, HL_ATTR(HLF_CUL));
2163 }
2164#endif
2165
Bram Moolenaara74fda62019-10-19 17:38:03 +02002166#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002167 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002168 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002169 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002170# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002171 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002172 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002173# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002174 // Get syntax attribute.
2175 if (has_syntax)
2176 {
2177 // Get the syntax attribute for the character. If there
2178 // is an error, disable syntax highlighting.
2179 save_did_emsg = did_emsg;
2180 did_emsg = FALSE;
2181
2182 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002183 if (v == prev_syntax_col)
2184 // at same column again
2185 syntax_attr = prev_syntax_attr;
2186 else
2187 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002188# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002189 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002190# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002191 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002192# ifdef FEAT_SPELL
2193 has_spell ? &can_spell :
2194# endif
2195 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002196 prev_syntax_col = v;
2197 prev_syntax_attr = syntax_attr;
2198 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002199
Bram Moolenaar34390282019-10-16 14:38:26 +02002200 if (did_emsg)
2201 {
2202 wp->w_s->b_syn_error = TRUE;
2203 has_syntax = FALSE;
2204 syntax_attr = 0;
2205 }
2206 else
2207 did_emsg = save_did_emsg;
2208# ifdef SYN_TIME_LIMIT
2209 if (wp->w_s->b_syn_slow)
2210 has_syntax = FALSE;
2211# endif
2212
2213 // Need to get the line again, a multi-line regexp may
2214 // have made it invalid.
2215 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2216 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002217 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002218# ifdef FEAT_CONCEAL
2219 // no concealing past the end of the line, it interferes
2220 // with line highlighting
2221 if (*ptr == NUL)
2222 syntax_flags = 0;
2223 else
2224 syntax_flags = get_syntax_info(&syntax_seqnr);
2225# endif
2226 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002227 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002228# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002229 // Combine text property highlight into syntax highlight.
2230 if (text_prop_type != NULL)
2231 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002232 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002233 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2234 else
2235 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002236 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002237 }
2238# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002239#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002240
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002241 // Decide which of the highlight attributes to use.
2242 attr_pri = TRUE;
2243#ifdef LINE_ATTR
2244 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002245 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002246 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002247 if (!highlight_match)
2248 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002249 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002250# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002251 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002252# endif
2253 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002254 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002255 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002256 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002257# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002258 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002259# endif
2260 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002261 else if (line_attr != 0
2262 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2263 || wlv.vcol < wlv.fromcol
2264 || vcol_prev < fromcol_prev
2265 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002266 {
2267 // Use line_attr when not in the Visual or 'incsearch' area
2268 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002269# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002270 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002271# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002272 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002273# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002274 attr_pri = FALSE;
2275 }
2276#else
2277 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002278 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002279 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002280 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002281#endif
2282 else
2283 {
2284 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002285#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002286 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002287#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002288 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002289#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002290 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002291#ifdef FEAT_PROP_POPUP
2292 // override with text property highlight when "override" is TRUE
2293 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002294 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002295#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002296 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002297
2298 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002299 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002300 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002301 if (wlv.char_attr == 0)
2302 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002303 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002304 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002305 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002306
2307 // Get the next character to put on the screen.
2308
2309 // The "p_extra" points to the extra stuff that is inserted to
2310 // represent special characters (non-printable stuff) and other
2311 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002312 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002313 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2314 // "p_extra[n_extra]".
2315 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002316 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002317 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002318 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002319 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002320 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2321 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002322 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2323 if (enc_utf8 && utf_char2len(c) > 1)
2324 {
2325 mb_utf8 = TRUE;
2326 u8cc[0] = 0;
2327 c = 0xc0;
2328 }
2329 else
2330 mb_utf8 = FALSE;
2331 }
2332 else
2333 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002334 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002335 if (has_mbyte)
2336 {
2337 mb_c = c;
2338 if (enc_utf8)
2339 {
2340 // If the UTF-8 character is more than one byte:
2341 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002342 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002343 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002344 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002345 mb_l = 1;
2346 else if (mb_l > 1)
2347 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002348 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002349 mb_utf8 = TRUE;
2350 c = 0xc0;
2351 }
2352 }
2353 else
2354 {
2355 // if this is a DBCS character, put it in "mb_c"
2356 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002357 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002358 mb_l = 1;
2359 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002360 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002361 }
2362 if (mb_l == 0) // at the NUL at end-of-line
2363 mb_l = 1;
2364
2365 // If a double-width char doesn't fit display a '>' in the
2366 // last column.
2367 if ((
2368# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002369 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002370# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002371 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002372 && (*mb_char2cells)(mb_c) == 2)
2373 {
2374 c = '>';
2375 mb_c = c;
2376 mb_l = 1;
2377 mb_utf8 = FALSE;
2378 multi_attr = HL_ATTR(HLF_AT);
2379#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002380 if (wlv.cul_attr)
2381 multi_attr = hl_combine_attr(
2382 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002383#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002384 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002385
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002386 // put the pointer back to output the double-width
2387 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002388 ++wlv.n_extra;
2389 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002390 }
2391 else
2392 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002393 wlv.n_extra -= mb_l - 1;
2394 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002395 }
2396 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002397 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002398 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002399 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002400#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002401 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002402 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002403 wlv.extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002404 in_linebreak = FALSE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002405
2406 // only restore search_attr and area_attr after extra in the
2407 // next screen line is also done
2408 if (wlv.saved_n_extra <= 0)
2409 {
2410 if (search_attr == 0)
2411 search_attr = saved_search_attr;
2412 if (area_attr == 0 && *ptr != NUL)
2413 area_attr = saved_area_attr;
2414 }
Bram Moolenaare38fc862022-08-11 17:24:50 +01002415 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002416#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002417 }
2418 else
2419 {
2420#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002421 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002422#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002423 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002424
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002425 // Get a character from the line itself.
2426 c = *ptr;
2427#ifdef FEAT_LINEBREAK
2428 c0 = *ptr;
2429#endif
2430 if (has_mbyte)
2431 {
2432 mb_c = c;
2433 if (enc_utf8)
2434 {
2435 // If the UTF-8 character is more than one byte: Decode it
2436 // into "mb_c".
2437 mb_l = utfc_ptr2len(ptr);
2438 mb_utf8 = FALSE;
2439 if (mb_l > 1)
2440 {
2441 mb_c = utfc_ptr2char(ptr, u8cc);
2442 // Overlong encoded ASCII or ASCII with composing char
2443 // is displayed normally, except a NUL.
2444 if (mb_c < 0x80)
2445 {
2446 c = mb_c;
2447#ifdef FEAT_LINEBREAK
2448 c0 = mb_c;
2449#endif
2450 }
2451 mb_utf8 = TRUE;
2452
2453 // At start of the line we can have a composing char.
2454 // Draw it as a space with a composing char.
2455 if (utf_iscomposing(mb_c))
2456 {
2457 int i;
2458
2459 for (i = Screen_mco - 1; i > 0; --i)
2460 u8cc[i] = u8cc[i - 1];
2461 u8cc[0] = mb_c;
2462 mb_c = ' ';
2463 }
2464 }
2465
2466 if ((mb_l == 1 && c >= 0x80)
2467 || (mb_l >= 1 && mb_c == 0)
2468 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2469 {
2470 // Illegal UTF-8 byte: display as <xx>.
2471 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002472 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002473# ifdef FEAT_RIGHTLEFT
2474 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002475 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002476# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002477 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002478 c = *wlv.p_extra;
2479 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002480 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002481 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2482 wlv.c_extra = NUL;
2483 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002484 if (area_attr == 0 && search_attr == 0)
2485 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002486 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002487 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002488 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002489 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002490 }
2491 }
2492 else if (mb_l == 0) // at the NUL at end-of-line
2493 mb_l = 1;
2494#ifdef FEAT_ARABIC
2495 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2496 {
2497 // Do Arabic shaping.
2498 int pc, pc1, nc;
2499 int pcc[MAX_MCO];
2500
2501 // The idea of what is the previous and next
2502 // character depends on 'rightleft'.
2503 if (wp->w_p_rl)
2504 {
2505 pc = prev_c;
2506 pc1 = prev_c1;
2507 nc = utf_ptr2char(ptr + mb_l);
2508 prev_c1 = u8cc[0];
2509 }
2510 else
2511 {
2512 pc = utfc_ptr2char(ptr + mb_l, pcc);
2513 nc = prev_c;
2514 pc1 = pcc[0];
2515 }
2516 prev_c = mb_c;
2517
2518 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2519 }
2520 else
2521 prev_c = mb_c;
2522#endif
2523 }
2524 else // enc_dbcs
2525 {
2526 mb_l = MB_BYTE2LEN(c);
2527 if (mb_l == 0) // at the NUL at end-of-line
2528 mb_l = 1;
2529 else if (mb_l > 1)
2530 {
2531 // We assume a second byte below 32 is illegal.
2532 // Hopefully this is OK for all double-byte encodings!
2533 if (ptr[1] >= 32)
2534 mb_c = (c << 8) + ptr[1];
2535 else
2536 {
2537 if (ptr[1] == NUL)
2538 {
2539 // head byte at end of line
2540 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002541 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002542 }
2543 else
2544 {
2545 // illegal tail byte
2546 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002547 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002548 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002549 wlv.p_extra = wlv.extra;
2550 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002551 wlv.c_extra = NUL;
2552 wlv.c_final = NUL;
2553 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002554 if (area_attr == 0 && search_attr == 0)
2555 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002556 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002557 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002558 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002559 // save current attr
2560 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002561 }
2562 mb_c = c;
2563 }
2564 }
2565 }
2566 // If a double-width char doesn't fit display a '>' in the
2567 // last column; the character is displayed at the start of the
2568 // next line.
2569 if ((
2570# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002571 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002572# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002573 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002574 && (*mb_char2cells)(mb_c) == 2)
2575 {
2576 c = '>';
2577 mb_c = c;
2578 mb_utf8 = FALSE;
2579 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002580 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002581 // Put pointer back so that the character will be
2582 // displayed at the start of the next line.
2583 --ptr;
2584#ifdef FEAT_CONCEAL
2585 did_decrement_ptr = TRUE;
2586#endif
2587 }
2588 else if (*ptr != NUL)
2589 ptr += mb_l - 1;
2590
2591 // If a double-width char doesn't fit at the left side display
2592 // a '<' in the first column. Don't do this for unprintable
2593 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002594 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002595 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002596 wlv.n_extra = 1;
2597 wlv.c_extra = MB_FILLER_CHAR;
2598 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002599 c = ' ';
2600 if (area_attr == 0 && search_attr == 0)
2601 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002602 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002603 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002604 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002605 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002606 }
2607 mb_c = c;
2608 mb_utf8 = FALSE;
2609 mb_l = 1;
2610 }
2611
2612 }
2613 ++ptr;
2614
2615 if (extra_check)
2616 {
2617#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002618 // Check spelling (unless at the end of the line).
2619 // Only do this when there is no syntax highlighting, the
2620 // @Spell cluster is not used or the current syntax item
2621 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002622 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002623 if (has_spell && v >= word_end && v > cur_checked_col)
2624 {
2625 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002626 // do not calculate cap_col at the end of the line or when
2627 // only white space is following
2628 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002629# ifdef FEAT_SYN_HL
2630 !has_syntax ||
2631# endif
2632 can_spell))
2633 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002634 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002635 int len;
2636 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002637
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002638 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002639 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002640
2641 // Use nextline[] if possible, it has the start of the
2642 // next line concatenated.
2643 if ((prev_ptr - line) - nextlinecol >= 0)
2644 p = nextline + (prev_ptr - line) - nextlinecol;
2645 else
2646 p = prev_ptr;
2647 cap_col -= (int)(prev_ptr - line);
2648 len = spell_check(wp, p, &spell_hlf, &cap_col,
2649 nochange);
2650 word_end = v + len;
2651
2652 // In Insert mode only highlight a word that
2653 // doesn't touch the cursor.
2654 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002655 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002656 && wp->w_cursor.lnum == lnum
2657 && wp->w_cursor.col >=
2658 (colnr_T)(prev_ptr - line)
2659 && wp->w_cursor.col < (colnr_T)word_end)
2660 {
2661 spell_hlf = HLF_COUNT;
2662 spell_redraw_lnum = lnum;
2663 }
2664
2665 if (spell_hlf == HLF_COUNT && p != prev_ptr
2666 && (p - nextline) + len > nextline_idx)
2667 {
2668 // Remember that the good word continues at the
2669 // start of the next line.
2670 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002671 checked_col = (int)((p - nextline)
2672 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002673 }
2674
2675 // Turn index into actual attributes.
2676 if (spell_hlf != HLF_COUNT)
2677 spell_attr = highlight_attr[spell_hlf];
2678
2679 if (cap_col > 0)
2680 {
2681 if (p != prev_ptr
2682 && (p - nextline) + cap_col >= nextline_idx)
2683 {
2684 // Remember that the word in the next line
2685 // must start with a capital.
2686 capcol_lnum = lnum + 1;
2687 cap_col = (int)((p - nextline) + cap_col
2688 - nextline_idx);
2689 }
2690 else
2691 // Compute the actual column.
2692 cap_col += (int)(prev_ptr - line);
2693 }
2694 }
2695 }
2696 if (spell_attr != 0)
2697 {
2698 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002699 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2700 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002701 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002702 wlv.char_attr = hl_combine_attr(spell_attr,
2703 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002704 }
2705#endif
2706#ifdef FEAT_LINEBREAK
2707 // Found last space before word: check for line break.
2708 if (wp->w_p_lbr && c0 == c
2709 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2710 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002711 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2712 : 0;
2713 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002714 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002715
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002716 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002717# ifdef FEAT_PROP_POPUP
2718 // do not want virtual text counted here
2719 cts.cts_has_prop_with_text = FALSE;
2720# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002721 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002722 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002723
2724 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002725 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002726 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002727 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002728 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2729 if (wlv.n_extra < 0)
2730 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002731 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002732 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002733 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002734 // line break, but for TABs the highlighting should
2735 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002736 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002737
Bram Moolenaar1306b362022-08-06 15:59:06 +01002738 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002739# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002740 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002741 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002742 wp->w_buffer->b_p_vts_array) - 1;
2743# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002744 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002745 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002746# endif
2747
Bram Moolenaar1306b362022-08-06 15:59:06 +01002748 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2749 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002750# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002751 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002752 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002753# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002754 if (VIM_ISWHITE(c))
2755 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002756# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002757 if (c == TAB)
2758 // See "Tab alignment" below.
2759 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002760# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002761 if (!wp->w_p_list)
2762 c = ' ';
2763 }
2764 }
2765#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002766 in_multispace = c == ' '
2767 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2768 if (!in_multispace)
2769 multispace_pos = 0;
2770
Bram Moolenaareed9d462021-02-15 20:38:25 +01002771 // 'list': Change char 160 to 'nbsp' and space to 'space'
2772 // setting in 'listchars'. But not when the character is
2773 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002774 if (wp->w_p_list
2775 && ((((c == 160 && mb_l == 1)
2776 || (mb_utf8
2777 && ((mb_c == 160 && mb_l == 2)
2778 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002779 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002780 || (c == ' '
2781 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002782 && (wp->w_lcs_chars.space
2783 || (in_multispace
2784 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002785 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002786 && ptr - line <= trailcol)))
2787 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002788 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2789 {
2790 c = wp->w_lcs_chars.multispace[multispace_pos++];
2791 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2792 multispace_pos = 0;
2793 }
2794 else
2795 c = (c == ' ') ? wp->w_lcs_chars.space
2796 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002797 if (area_attr == 0 && search_attr == 0)
2798 {
2799 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002800 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002801 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002802 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002803 }
2804 mb_c = c;
2805 if (enc_utf8 && utf_char2len(c) > 1)
2806 {
2807 mb_utf8 = TRUE;
2808 u8cc[0] = 0;
2809 c = 0xc0;
2810 }
2811 else
2812 mb_utf8 = FALSE;
2813 }
2814
zeertzjq2e7cba32022-06-10 15:30:32 +01002815 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2816 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002817 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002818 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2819 && wp->w_lcs_chars.leadmultispace != NULL)
2820 {
2821 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002822 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2823 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002824 multispace_pos = 0;
2825 }
2826
2827 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2828 c = wp->w_lcs_chars.trail;
2829
2830 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2831 c = wp->w_lcs_chars.lead;
2832
zeertzjq2e7cba32022-06-10 15:30:32 +01002833 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002834 c = wp->w_lcs_chars.space;
2835
2836
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002837 if (!attr_pri)
2838 {
2839 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002840 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002841 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002842 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002843 }
2844 mb_c = c;
2845 if (enc_utf8 && utf_char2len(c) > 1)
2846 {
2847 mb_utf8 = TRUE;
2848 u8cc[0] = 0;
2849 c = 0xc0;
2850 }
2851 else
2852 mb_utf8 = FALSE;
2853 }
2854 }
2855
2856 // Handling of non-printable characters.
2857 if (!vim_isprintc(c))
2858 {
2859 // when getting a character from the file, we may have to
2860 // turn it into something else on the way to putting it
2861 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002862 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002863 {
2864 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002865 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002866#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002867 char_u *sbr = get_showbreak_value(wp);
2868
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002869 // only adjust the tab_len, when at the first column
2870 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002871 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002872 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002873#endif
2874 // tab amount depends on current column
2875#ifdef FEAT_VARTABS
2876 tab_len = tabstop_padding(vcol_adjusted,
2877 wp->w_buffer->b_p_ts,
2878 wp->w_buffer->b_p_vts_array) - 1;
2879#else
2880 tab_len = (int)wp->w_buffer->b_p_ts
2881 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2882#endif
2883
2884#ifdef FEAT_LINEBREAK
2885 if (!wp->w_p_lbr || !wp->w_p_list)
2886#endif
2887 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002888 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002889#ifdef FEAT_LINEBREAK
2890 else
2891 {
2892 char_u *p;
2893 int len;
2894 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002895 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002896
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002897# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002898 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002899 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002900 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002901
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002902 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002903 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002904 && old_boguscols > 0
2905 && wlv.n_extra > tab_len)
2906 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002907# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002908 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002909 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002910 // If wlv.n_extra > 0, it gives the number of
2911 // chars, to use for a tab, else we need to
2912 // calculate the width for a tab.
2913 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
2914 len = tab_len * tab2_len;
2915 if (wp->w_lcs_chars.tab3)
2916 len += mb_char2len(wp->w_lcs_chars.tab3)
2917 - tab2_len;
2918 if (wlv.n_extra > 0)
2919 len += wlv.n_extra - tab_len;
2920 c = wp->w_lcs_chars.tab1;
2921 p = alloc(len + 1);
2922 if (p == NULL)
2923 wlv.n_extra = 0;
2924 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002925 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002926 vim_memset(p, ' ', len);
2927 p[len] = NUL;
2928 vim_free(wlv.p_extra_free);
2929 wlv.p_extra_free = p;
2930 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002931 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002932 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002933
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002934 if (*p == NUL)
2935 {
2936 tab_len = i;
2937 break;
2938 }
2939
2940 // if tab3 is given, use it for the last
2941 // char
2942 if (wp->w_lcs_chars.tab3
2943 && i == tab_len - 1)
2944 lcs = wp->w_lcs_chars.tab3;
2945 p += mb_char2bytes(lcs, p);
2946 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002947 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002948 }
2949 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002950# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002951 // n_extra will be increased by
2952 // FIX_FOX_BOGUSCOLS macro below, so need to
2953 // adjust for that here
2954 if (wlv.vcol_off > 0)
2955 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002956# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002957 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002958 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002959 }
2960#endif
2961#ifdef FEAT_CONCEAL
2962 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002963 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002964
2965 // Tab alignment should be identical regardless of
2966 // 'conceallevel' value. So tab compensates of all
2967 // previous concealed characters, and thus resets
2968 // vcol_off and boguscols accumulated so far in the
2969 // line. Note that the tab can be longer than
2970 // 'tabstop' when there are concealed characters.
2971 FIX_FOR_BOGUSCOLS;
2972
2973 // Make sure, the highlighting for the tab char will be
2974 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002975 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002976 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002977 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002978 tab_len += vc_saved;
2979 }
2980#endif
2981 mb_utf8 = FALSE; // don't draw as UTF-8
2982 if (wp->w_p_list)
2983 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002984 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002985 ? wp->w_lcs_chars.tab3
2986 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002987#ifdef FEAT_LINEBREAK
2988 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002989 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002990 else
2991#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002992 wlv.c_extra = wp->w_lcs_chars.tab2;
2993 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002994 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002995 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002996 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002997 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002998 mb_c = c;
2999 if (enc_utf8 && utf_char2len(c) > 1)
3000 {
3001 mb_utf8 = TRUE;
3002 u8cc[0] = 0;
3003 c = 0xc0;
3004 }
3005 }
3006 else
3007 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003008 wlv.c_final = NUL;
3009 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003010 c = ' ';
3011 }
3012 }
3013 else if (c == NUL
3014 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003015 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3016 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003017 && VIsual_mode != Ctrl_V
3018 && (
3019# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003020 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003021# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003022 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003023 && !(noinvcur
3024 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003025 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003026 && lcs_eol_one > 0)
3027 {
3028 // Display a '$' after the line or highlight an extra
3029 // character if the line break is included.
3030#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3031 // For a diff line the highlighting continues after the
3032 // "$".
3033 if (
3034# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003035 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003036# ifdef LINE_ATTR
3037 &&
3038# endif
3039# endif
3040# ifdef LINE_ATTR
3041 line_attr == 0
3042# endif
3043 )
3044#endif
3045 {
3046 // In virtualedit, visual selections may extend
3047 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003048 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003049 && wlv.tocol != MAXCOL
3050 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003051 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003052 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003053 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003054 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3055 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003056 else
3057 c = ' ';
3058 lcs_eol_one = -1;
3059 --ptr; // put it back at the NUL
3060 if (!attr_pri)
3061 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003062 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003063 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003064 n_attr = 1;
3065 }
3066 mb_c = c;
3067 if (enc_utf8 && utf_char2len(c) > 1)
3068 {
3069 mb_utf8 = TRUE;
3070 u8cc[0] = 0;
3071 c = 0xc0;
3072 }
3073 else
3074 mb_utf8 = FALSE; // don't draw as UTF-8
3075 }
3076 else if (c != NUL)
3077 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003078 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3079 if (wlv.n_extra == 0)
3080 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003081#ifdef FEAT_RIGHTLEFT
3082 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003083 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003084#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003085 wlv.c_extra = NUL;
3086 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003087#ifdef FEAT_LINEBREAK
3088 if (wp->w_p_lbr)
3089 {
3090 char_u *p;
3091
Bram Moolenaar1306b362022-08-06 15:59:06 +01003092 c = *wlv.p_extra;
3093 p = alloc(wlv.n_extra + 1);
3094 vim_memset(p, ' ', wlv.n_extra);
3095 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3096 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003097 vim_free(wlv.p_extra_free);
3098 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003099 }
3100 else
3101#endif
3102 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003103 wlv.n_extra = byte2cells(c) - 1;
3104 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003105 }
3106 if (!attr_pri)
3107 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003108 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003109 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003110 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003111 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003112 }
3113 mb_utf8 = FALSE; // don't draw as UTF-8
3114 }
3115 else if (VIsual_active
3116 && (VIsual_mode == Ctrl_V
3117 || VIsual_mode == 'v')
3118 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003119 && wlv.tocol != MAXCOL
3120 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003121 && (
3122#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003123 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003124#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003125 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003126 {
3127 c = ' ';
3128 --ptr; // put it back at the NUL
3129 }
3130#if defined(LINE_ATTR)
3131 else if ((
3132# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003133 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003134# endif
3135# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003136 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003137# endif
3138 line_attr != 0
3139 ) && (
3140# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003141 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003142# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003143 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003144# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003145 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003146# endif
3147 < wp->w_width)))
3148 {
3149 // Highlight until the right side of the window
3150 c = ' ';
3151 --ptr; // put it back at the NUL
3152
3153 // Remember we do the char for line highlighting.
3154 ++did_line_attr;
3155
3156 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01003157 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003158 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003159 || (wp->w_p_list &&
3160 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003161 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003162# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003163 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003164 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003165 wlv.diff_hlf = HLF_CHD;
3166 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003167 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003168 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003169 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3170 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003171 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003172 || (wlv.vcol >= left_curline_col
3173 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003174 wlv.char_attr = hl_combine_attr(
3175 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003176 }
3177 }
3178# endif
3179# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003180 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003181 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003182 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003183 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3184 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003185 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003186 if (!wlv.cul_screenline
3187 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003188 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003189 wlv.char_attr = hl_combine_attr(
3190 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003191 }
3192 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003193 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3194 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003195 }
3196# endif
3197 }
3198#endif
3199 }
3200
3201#ifdef FEAT_CONCEAL
3202 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003203 && (wp != curwin || lnum != wp->w_cursor.lnum
3204 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003205 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3206 && !(lnum_in_visual_area
3207 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3208 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003209 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003210 if (((prev_syntax_id != syntax_seqnr
3211 && (syntax_flags & HL_CONCEAL) != 0)
3212 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003213 && (syn_get_sub_char() != NUL
3214 || (has_match_conc && match_conc)
3215 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003216 && wp->w_p_cole != 3)
3217 {
3218 // First time at this concealed item: display one
3219 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003220 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003221 c = match_conc;
3222 else if (syn_get_sub_char() != NUL)
3223 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003224 else if (wp->w_lcs_chars.conceal != NUL)
3225 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003226 else
3227 c = ' ';
3228
3229 prev_syntax_id = syntax_seqnr;
3230
Bram Moolenaar1306b362022-08-06 15:59:06 +01003231 if (wlv.n_extra > 0)
3232 wlv.vcol_off += wlv.n_extra;
3233 wlv.vcol += wlv.n_extra;
3234 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003235 {
3236# ifdef FEAT_RIGHTLEFT
3237 if (wp->w_p_rl)
3238 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003239 wlv.col -= wlv.n_extra;
3240 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003241 }
3242 else
3243# endif
3244 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003245 wlv.boguscols += wlv.n_extra;
3246 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003247 }
3248 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003249 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003250 n_attr = 0;
3251 }
3252 else if (n_skip == 0)
3253 {
3254 is_concealing = TRUE;
3255 n_skip = 1;
3256 }
3257 mb_c = c;
3258 if (enc_utf8 && utf_char2len(c) > 1)
3259 {
3260 mb_utf8 = TRUE;
3261 u8cc[0] = 0;
3262 c = 0xc0;
3263 }
3264 else
3265 mb_utf8 = FALSE; // don't draw as UTF-8
3266 }
3267 else
3268 {
3269 prev_syntax_id = 0;
3270 is_concealing = FALSE;
3271 }
3272
3273 if (n_skip > 0 && did_decrement_ptr)
3274 // not showing the '>', put pointer back to avoid getting stuck
3275 ++ptr;
3276
3277#endif // FEAT_CONCEAL
3278 }
3279
3280#ifdef FEAT_CONCEAL
3281 // In the cursor line and we may be concealing characters: correct
3282 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003283 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003284 && wp == curwin && lnum == wp->w_cursor.lnum
3285 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003286 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003287 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003288# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003289 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003290 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003291 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003292# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003293 wp->w_wcol = wlv.col - wlv.boguscols;
3294 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003295 did_wcol = TRUE;
3296 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003297# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003298 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003299# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003300 }
3301#endif
3302
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003303 // Use "wlv.extra_attr", but don't override visual selection
3304 // highlighting, unless text property overrides.
3305 // Don't use "wlv.extra_attr" until n_attr_skip is zero.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003306 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003307 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003308 && (!attr_pri
3309#ifdef FEAT_PROP_POPUP
3310 || (text_prop_flags & PT_FLAG_OVERRIDE)
3311#endif
3312 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003313 {
3314#ifdef LINE_ATTR
3315 if (line_attr)
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003316 wlv.char_attr = hl_combine_attr(line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003317 else
3318#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003319 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003320 }
3321
3322#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3323 // XIM don't send preedit_start and preedit_end, but they send
3324 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3325 // im_is_preediting() here.
3326 if (p_imst == IM_ON_THE_SPOT
3327 && xic != NULL
3328 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003329 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003330 && !p_imdisable
3331 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003332 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003333 {
3334 colnr_T tcol;
3335
3336 if (preedit_end_col == MAXCOL)
3337 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3338 else
3339 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003340 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003341 {
3342 if (feedback_old_attr < 0)
3343 {
3344 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003345 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003346 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003347 wlv.char_attr = im_get_feedback_attr(feedback_col);
3348 if (wlv.char_attr < 0)
3349 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003350 feedback_col++;
3351 }
3352 else if (feedback_old_attr >= 0)
3353 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003354 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003355 feedback_old_attr = -1;
3356 feedback_col = 0;
3357 }
3358 }
3359#endif
3360 // Handle the case where we are in column 0 but not on the first
3361 // character of the line and the user wants us to show us a
3362 // special character (via 'listchars' option "precedes:<char>".
3363 if (lcs_prec_todo != NUL
3364 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003365 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3366 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003367#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003368 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003369#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003370 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003371 && c != NUL)
3372 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003373 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003374 lcs_prec_todo = NUL;
3375 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3376 {
3377 // Double-width character being overwritten by the "precedes"
3378 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003379 wlv.c_extra = MB_FILLER_CHAR;
3380 wlv.c_final = NUL;
3381 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003382 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003383 wlv.extra_attr =
3384 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003385 }
3386 mb_c = c;
3387 if (enc_utf8 && utf_char2len(c) > 1)
3388 {
3389 mb_utf8 = TRUE;
3390 u8cc[0] = 0;
3391 c = 0xc0;
3392 }
3393 else
3394 mb_utf8 = FALSE; // don't draw as UTF-8
3395 if (!attr_pri)
3396 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003397 saved_attr3 = wlv.char_attr; // save current attr
3398 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003399 n_attr3 = 1;
3400 }
3401 }
3402
3403 // At end of the text line or just after the last character.
3404 if ((c == NUL
3405#if defined(LINE_ATTR)
3406 || did_line_attr == 1
3407#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003408 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003409 {
3410#ifdef FEAT_SEARCH_EXTRA
3411 // flag to indicate whether prevcol equals startcol of search_hl or
3412 // one of the matches
3413 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3414 (long)(ptr - line) - (c == NUL));
3415#endif
3416 // Invert at least one char, used for Visual and empty line or
3417 // highlight match at end of line. If it's beyond the last
3418 // char on the screen, just overwrite that one (tricky!) Not
3419 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003420 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003421 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003422 && (VIsual_mode != Ctrl_V
3423 || lnum == VIsual.lnum
3424 || lnum == curwin->w_cursor.lnum)
3425 && c == NUL)
3426#ifdef FEAT_SEARCH_EXTRA
3427 // highlight 'hlsearch' match at end of line
3428 || (prevcol_hl_flag
3429# ifdef FEAT_SYN_HL
3430 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3431 && !(wp == curwin && VIsual_active))
3432# endif
3433# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003434 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003435# endif
3436# if defined(LINE_ATTR)
3437 && did_line_attr <= 1
3438# endif
3439 )
3440#endif
3441 ))
3442 {
3443 int n = 0;
3444
3445#ifdef FEAT_RIGHTLEFT
3446 if (wp->w_p_rl)
3447 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003448 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003449 n = 1;
3450 }
3451 else
3452#endif
3453 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003454 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003455 n = -1;
3456 }
3457 if (n != 0)
3458 {
3459 // At the window boundary, highlight the last character
3460 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003461 wlv.off += n;
3462 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003463 }
3464 else
3465 {
3466 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003467 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003468 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003469 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003470 }
3471#ifdef FEAT_SEARCH_EXTRA
3472 if (area_attr == 0)
3473 {
3474 // Use attributes from match with highest priority among
3475 // 'search_hl' and the match list.
3476 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003477 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003478 }
3479#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003480 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003481 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003482#ifdef FEAT_RIGHTLEFT
3483 if (wp->w_p_rl)
3484 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003485 --wlv.col;
3486 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003487 }
3488 else
3489#endif
3490 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003491 ++wlv.col;
3492 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003493 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003494 ++wlv.vcol;
3495 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003496 }
3497 }
3498
3499 // At end of the text line.
3500 if (c == NUL)
3501 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003502 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003503
3504 // Update w_cline_height and w_cline_folded if the cursor line was
3505 // updated (saves a call to plines() later).
3506 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3507 {
3508 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003509 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003510#ifdef FEAT_FOLDING
3511 curwin->w_cline_folded = FALSE;
3512#endif
3513 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3514 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003515 break;
3516 }
3517
3518 // Show "extends" character from 'listchars' if beyond the line end and
3519 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003520 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003521 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003522 && wp->w_p_list
3523 && !wp->w_p_wrap
3524#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003525 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003526#endif
3527 && (
3528#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003529 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003530#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003531 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003532 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003533 || lcs_eol_one > 0
3534 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003535 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003536 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003537 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003538 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003539 mb_c = c;
3540 if (enc_utf8 && utf_char2len(c) > 1)
3541 {
3542 mb_utf8 = TRUE;
3543 u8cc[0] = 0;
3544 c = 0xc0;
3545 }
3546 else
3547 mb_utf8 = FALSE;
3548 }
3549
3550#ifdef FEAT_SYN_HL
3551 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003552 if (wlv.draw_color_col)
3553 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003554
3555 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3556 // highlight the cursor position itself.
3557 // Also highlight the 'colorcolumn' if it is different than
3558 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003559 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3560 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003561 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003562 if (((wlv.draw_state == WL_LINE
3563 || wlv.draw_state == WL_BRI
3564 || wlv.draw_state == WL_SBR)
3565 && !lnum_in_visual_area
3566 && search_attr == 0
3567 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003568# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003569 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003570# endif
3571 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003572 {
3573 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3574 && lnum != wp->w_cursor.lnum)
3575 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003576 vcol_save_attr = wlv.char_attr;
3577 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3578 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003579 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003580 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003581 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003582 vcol_save_attr = wlv.char_attr;
3583 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003584 }
3585 }
3586#endif
3587
3588 // Store character to be displayed.
3589 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003590 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003591 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003592 {
3593 // Store the character.
3594#if defined(FEAT_RIGHTLEFT)
3595 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3596 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003597 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003598 --wlv.off;
3599 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003600 }
3601#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003602 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003603 if (enc_dbcs == DBCS_JPNU)
3604 {
3605 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003606 ScreenLines[wlv.off] = 0x8e;
3607 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003608 }
3609 else if (enc_utf8)
3610 {
3611 if (mb_utf8)
3612 {
3613 int i;
3614
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003615 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003616 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003617 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003618 for (i = 0; i < Screen_mco; ++i)
3619 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003620 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003621 if (u8cc[i] == 0)
3622 break;
3623 }
3624 }
3625 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003626 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003627 }
3628 if (multi_attr)
3629 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003630 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003631 multi_attr = 0;
3632 }
3633 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003634 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003635
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003636 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003637
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003638 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3639 {
3640 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003641 ++wlv.off;
3642 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003643 if (enc_utf8)
3644 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003645 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003646 else
3647 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003648 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003649 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003650#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003651 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003652#endif
3653 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003654 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003655 // When "wlv.tocol" is halfway a character, set it to the end
3656 // of the character, otherwise highlighting won't stop.
3657 if (wlv.tocol == wlv.vcol)
3658 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003659
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003660 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003661
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003662#ifdef FEAT_RIGHTLEFT
3663 if (wp->w_p_rl)
3664 {
3665 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003666 --wlv.off;
3667 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003668 }
3669#endif
3670 }
3671#ifdef FEAT_RIGHTLEFT
3672 if (wp->w_p_rl)
3673 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003674 --wlv.off;
3675 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003676 }
3677 else
3678#endif
3679 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003680 ++wlv.off;
3681 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003682 }
3683 }
3684#ifdef FEAT_CONCEAL
3685 else if (wp->w_p_cole > 0 && is_concealing)
3686 {
3687 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003688 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003689 if (wlv.n_extra > 0)
3690 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003691 if (wp->w_p_wrap)
3692 {
3693 // Special voodoo required if 'wrap' is on.
3694 //
3695 // Advance the column indicator to force the line
3696 // drawing to wrap early. This will make the line
3697 // take up the same screen space when parts are concealed,
3698 // so that cursor line computations aren't messed up.
3699 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003700 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003701 // trailing junk to be written out of the screen line
3702 // we are building, 'boguscols' keeps track of the number
3703 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003704 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003705 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003706 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003707# ifdef FEAT_RIGHTLEFT
3708 if (wp->w_p_rl)
3709 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003710 wlv.col -= wlv.n_extra;
3711 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003712 }
3713 else
3714# endif
3715 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003716 wlv.col += wlv.n_extra;
3717 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003718 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003719 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003720 n_attr = 0;
3721 }
3722
3723
3724 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3725 {
3726 // Need to fill two screen columns.
3727# ifdef FEAT_RIGHTLEFT
3728 if (wp->w_p_rl)
3729 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003730 --wlv.boguscols;
3731 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003732 }
3733 else
3734# endif
3735 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003736 ++wlv.boguscols;
3737 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003738 }
3739 }
3740
3741# ifdef FEAT_RIGHTLEFT
3742 if (wp->w_p_rl)
3743 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003744 --wlv.boguscols;
3745 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003746 }
3747 else
3748# endif
3749 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003750 ++wlv.boguscols;
3751 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003752 }
3753 }
3754 else
3755 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003756 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003757 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003758 wlv.vcol += wlv.n_extra;
3759 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003760 n_attr = 0;
3761 }
3762 }
3763
3764 }
3765#endif // FEAT_CONCEAL
3766 else
3767 --n_skip;
3768
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003769 // Only advance the "wlv.vcol" when after the 'number' or
3770 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003771 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003772#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003773 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003774#endif
3775 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003776 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003777
3778#ifdef FEAT_SYN_HL
3779 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003780 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003781#endif
3782
3783 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003784 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3785 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003786
3787 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003788 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003789 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003790 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003791 if (n_attr_skip > 0)
3792 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003793
3794 // At end of screen line and there is more to come: Display the line
3795 // so far. If there is no more to display it is caught above.
3796 if ((
3797#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003798 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003799#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003800 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003801 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003802 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003803#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003804 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003805#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003806#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003807 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003808#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003809 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003810 && wlv.p_extra != at_end_str)
3811 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3812 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003813 )
3814 {
3815#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003816 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003817 wlv_screen_line(wp, &wlv, FALSE);
3818 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003819 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003820#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003821 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003822#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003823 ++wlv.row;
3824 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003825
3826 // When not wrapping and finished diff lines, or when displayed
3827 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01003828 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003829#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003830 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003831#endif
3832#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01003833 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003834#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01003835 ) || lcs_eol_one == -1)
3836#ifdef FEAT_PROP_POPUP
3837 && !text_prop_follows
3838#endif
3839 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003840 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003841#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003842 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003843 {
3844 // do not output more of the line, only the "below" prop
3845 ptr += STRLEN(ptr);
3846# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003847 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003848# endif
3849 }
3850#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003851
3852 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003853 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003854#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003855 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003856#endif
3857 )
3858 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003859 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3860 draw_vsep_win(wp, wlv.row);
3861 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003862 }
3863
3864 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003865 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003866 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003867 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003868 break;
3869 }
3870
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003871 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003872#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003873 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003874#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003875#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003876 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003877#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003878 && wp->w_width == Columns)
3879 {
3880 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003881 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003882
3883 // Special trick to make copy/paste of wrapped lines work with
3884 // xterm/screen: write an extra character beyond the end of
3885 // the line. This will work with all terminal types
3886 // (regardless of the xn,am settings).
3887 // Only do this on a fast tty.
3888 // Only do this if the cursor is on the current line
3889 // (something has been written in it).
3890 // Don't do this for the GUI.
3891 // Don't do this for double-width characters.
3892 // Don't do this for a window not at the right screen border.
3893 if (p_tf
3894#ifdef FEAT_GUI
3895 && !gui.in_use
3896#endif
3897 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003898 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3899 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003900 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003901 || (*mb_off2cells)(
3902 LineOffset[wlv.screen_row - 1]
3903 + (int)Columns - 2,
3904 LineOffset[wlv.screen_row]
3905 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003906 {
3907 // First make sure we are at the end of the screen line,
3908 // then output the same character again to let the
3909 // terminal know about the wrap. If the terminal doesn't
3910 // auto-wrap, we overwrite the character.
3911 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003912 screen_char(LineOffset[wlv.screen_row - 1]
3913 + (unsigned)Columns - 1,
3914 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003915
3916 // When there is a multi-byte character, just output a
3917 // space to keep it simple.
3918 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003919 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003920 out_char(' ');
3921 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003922 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003923 + (Columns - 1)]);
3924 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003925 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003926 screen_start(); // don't know where cursor is now
3927 }
3928 }
3929
Bram Moolenaar1306b362022-08-06 15:59:06 +01003930 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003931
Bram Moolenaareed9d462021-02-15 20:38:25 +01003932 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003933#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003934 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003935# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003936 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003937# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003938 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003939 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003940#endif
3941#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003942 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003943 // When the filler lines are actually below the last line of the
3944 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003945 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003946 break;
3947#endif
3948 }
3949
3950 } // for every character in the line
3951
3952#ifdef FEAT_SPELL
3953 // After an empty line check first word for capital.
3954 if (*skipwhite(line) == NUL)
3955 {
3956 capcol_lnum = lnum + 1;
3957 cap_col = 0;
3958 }
3959#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003960#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003961 vim_free(text_props);
3962 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003963 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003964#endif
3965
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003966 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003967 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003968}