blob: 632fd742ae5f54d00109be023e12890b0fae90a3 [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 Moolenaar1306b362022-08-06 15:59:06 +0100133 int c_extra; // extra chars, all the same
134 int c_final; // final char, mandatory if set
135
136 // saved "extra" items for when draw_state becomes WL_LINE (again)
137 int saved_n_extra;
138 char_u *saved_p_extra;
139 int saved_c_extra;
140 int saved_c_final;
141 int saved_char_attr;
142
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100143 char_u extra[NUMBUFLEN + MB_MAXBYTES];
144 // "%ld " and 'fdc' must fit in here, as well
145 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100146
Bram Moolenaar1306b362022-08-06 15:59:06 +0100147#ifdef FEAT_DIFF
148 hlf_T diff_hlf; // type of diff highlighting
149#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100150 int filler_lines; // nr of filler lines to be drawn
151 int filler_todo; // nr of filler lines still to do + 1
152#ifdef FEAT_SIGNS
153 sign_attrs_T sattr;
154#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100155} winlinevars_T;
156
157// draw_state values for items that are drawn in sequence:
158#define WL_START 0 // nothing done yet, must be zero
Martin Tournoij7904fa42022-10-04 16:28:45 +0100159#define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar1306b362022-08-06 15:59:06 +0100160#ifdef FEAT_FOLDING
161# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
162#else
163# define WL_FOLD WL_CMDLINE
164#endif
165#ifdef FEAT_SIGNS
166# define WL_SIGN (WL_FOLD + 1) // column for signs
167#else
168# define WL_SIGN WL_FOLD // column for signs
169#endif
170#define WL_NR (WL_SIGN + 1) // line number
171#ifdef FEAT_LINEBREAK
172# define WL_BRI (WL_NR + 1) // 'breakindent'
173#else
174# define WL_BRI WL_NR
175#endif
176#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
177# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
178#else
179# define WL_SBR WL_BRI
180#endif
181#define WL_LINE (WL_SBR + 1) // text in the line
182
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100183#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200184/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000185 * Return TRUE if CursorLineSign highlight is to be used.
186 */
187 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100188use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000189{
190 return wp->w_p_cul
191 && lnum == wp->w_cursor.lnum
192 && (wp->w_p_culopt_flags & CULOPT_NBR);
193}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100194#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000195
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100196
197#ifdef FEAT_FOLDING
198/*
199 * Setup for drawing the 'foldcolumn', if there is one.
200 */
201 static void
202handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
203{
204 int fdc = compute_foldcolumn(wp, 0);
205
206 if (fdc <= 0)
207 return;
208
209 // Allocate a buffer, "wlv->extra[]" may already be in use.
210 vim_free(wlv->p_extra_free);
211 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
212 if (wlv->p_extra_free != NULL)
213 {
214 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
215 wp, FALSE, wlv->lnum);
216 wlv->p_extra_free[wlv->n_extra] = NUL;
217 wlv->p_extra = wlv->p_extra_free;
218 wlv->c_extra = NUL;
219 wlv->c_final = NUL;
220 if (use_cursor_line_highlight(wp, wlv->lnum))
221 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
222 else
223 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
224 }
225}
226#endif
227
228#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000229/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100230 * Get information needed to display the sign in line "wlv->lnum" in window
231 * "wp".
232 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200233 * Otherwise the sign is going to be displayed in the sign column.
234 */
235 static void
236get_sign_display_info(
237 int nrcol,
238 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100239 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200240{
241 int text_sign;
242# ifdef FEAT_SIGN_ICONS
243 int icon_sign;
244# endif
245
246 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100247 wlv->c_extra = ' ';
248 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200249 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100250 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200251 else
252 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100253 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100254 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000255 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100256 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100257 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200258 }
259
Bram Moolenaar1306b362022-08-06 15:59:06 +0100260 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200261#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100262 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200263#endif
264 )
265 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100266 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200267# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100268 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200269 if (gui.in_use && icon_sign != 0)
270 {
271 // Use the image in this position.
272 if (nrcol)
273 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100274 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100275 sprintf((char *)wlv->extra, "%-*c ",
276 number_width(wp), SIGN_BYTE);
277 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100278 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200279 }
280 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100281 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200282# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100283 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
284 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200285 {
286 if (nrcol)
287 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100288 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100289 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200290 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100291 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100292 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200293 }
294 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100295 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200296 }
297# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100298 wlv->c_final = NUL;
299 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200300 }
301 else
302# endif
303 if (text_sign != 0)
304 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100305 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100306 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200307 {
308 if (nrcol)
309 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100310 int width = number_width(wp) - 2;
311 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200312
313 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100314 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100315 vim_snprintf((char *)wlv->extra + n,
316 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100317 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200318 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100319 wlv->c_extra = NUL;
320 wlv->c_final = NUL;
321 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200322 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000323
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100324 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100325 && wlv->sattr.sat_culhl > 0)
326 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000327 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100328 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200329 }
330 }
331}
332#endif
333
Bram Moolenaard7657e92022-09-20 18:59:30 +0100334/*
335 * Display the absolute or relative line number. After the first row fill with
336 * blanks when the 'n' flag isn't in 'cpo'.
337 */
338 static void
339handle_lnum_col(
340 win_T *wp,
341 winlinevars_T *wlv,
342 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100343 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100344{
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100345 int has_cpo_n = vim_strchr(p_cpo, CPO_NUMCOL) != NULL;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100346 int lnum_row = wlv->startrow + wlv->filler_lines
347#ifdef FEAT_PROP_POPUP
348 + wlv->text_prop_above_count
349#endif
350 ;
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100351
Bram Moolenaard7657e92022-09-20 18:59:30 +0100352 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100353 && (wlv->row <= lnum_row || !has_cpo_n)
Bram Moolenaar37251162022-10-06 20:48:00 +0100354 // there is no line number in a wrapped line when "n" is in
355 // 'cpoptions', but 'breakindent' assumes it anyway.
356 && !((has_cpo_n
357#ifdef FEAT_LINEBREAK
358 && !wp->w_p_bri
359#endif
360 ) && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100361 {
362#ifdef FEAT_SIGNS
363 // If 'signcolumn' is set to 'number' and a sign is present
364 // in 'lnum', then display the sign instead of the line
365 // number.
366 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
367 get_sign_display_info(TRUE, wp, wlv);
368 else
369#endif
370 {
371 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100372 // When there are text properties above the line put the line number
373 // below them.
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100374 if (wlv->row == lnum_row
Bram Moolenaareb4de622022-10-15 13:42:17 +0100375 && (wp->w_skipcol == 0 || wlv->row > wp->w_winrow
376 || (wp->w_p_nu && wp->w_p_rnu)))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100377 {
378 long num;
379 char *fmt = "%*ld ";
380
381 if (wp->w_p_nu && !wp->w_p_rnu)
382 // 'number' + 'norelativenumber'
383 num = (long)wlv->lnum;
384 else
385 {
386 // 'relativenumber', don't use negative numbers
387 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
388 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
389 {
390 // 'number' + 'relativenumber'
391 num = wlv->lnum;
392 fmt = "%-*ld ";
393 }
394 }
395
396 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100397 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100398 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
399 ++wlv->p_extra)
400 *wlv->p_extra = '-';
401#ifdef FEAT_RIGHTLEFT
402 if (wp->w_p_rl) // reverse line numbers
403 {
404 char_u *p1, *p2;
405 int t;
406
407 // like rl_mirror(), but keep the space at the end
408 p2 = skipwhite(wlv->extra);
409 p2 = skiptowhite(p2) - 1;
410 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
411 {
412 t = *p1;
413 *p1 = *p2;
414 *p2 = t;
415 }
416 }
417#endif
418 wlv->p_extra = wlv->extra;
419 wlv->c_extra = NUL;
420 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100421 }
422 else
423 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100424 wlv->c_extra = ' ';
425 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100426 }
427 wlv->n_extra = number_width(wp) + 1;
428 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
429#ifdef FEAT_SYN_HL
430 // When 'cursorline' is set highlight the line number of
431 // the current line differently.
432 // When 'cursorlineopt' does not have "line" only
433 // highlight the line number itself.
434 // TODO: Can we use CursorLine instead of CursorLineNr
435 // when CursorLineNr isn't set?
436 if (wp->w_p_cul
437 && wlv->lnum == wp->w_cursor.lnum
438 && (wp->w_p_culopt_flags & CULOPT_NBR)
439 && (wlv->row == wlv->startrow + wlv->filler_lines
440 || (wlv->row > wlv->startrow + wlv->filler_lines
441 && (wp->w_p_culopt_flags & CULOPT_LINE))))
442 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
443#endif
444 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
445 && HL_ATTR(HLF_LNA) != 0)
446 // Use LineNrAbove
447 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
448 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
449 && HL_ATTR(HLF_LNB) != 0)
450 // Use LineNrBelow
451 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
452 }
453#ifdef FEAT_SIGNS
454 if (num_attr)
455 wlv->char_attr = num_attr;
456#endif
457 }
458}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100459
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100460#ifdef FEAT_LINEBREAK
461 static void
462handle_breakindent(win_T *wp, winlinevars_T *wlv)
463{
464 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100465 && *get_showbreak_value(wp) != NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100466 // draw indent after showbreak value
467 wlv->draw_state = WL_BRI;
468 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
469 // After the showbreak, draw the breakindent
470 wlv->draw_state = WL_BRI - 1;
471
472 // draw 'breakindent': indent wrapped text accordingly
473 if (wlv->draw_state == WL_BRI - 1)
474 {
475 wlv->draw_state = WL_BRI;
476 // if wlv->need_showbreak is set, breakindent also applies
477 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
478# ifdef FEAT_DIFF
479 && wlv->filler_lines == 0
480# endif
481# ifdef FEAT_PROP_POPUP
482 && !wlv->dont_use_showbreak
483# endif
484 )
485 {
486 wlv->char_attr = 0;
487# ifdef FEAT_DIFF
488 if (wlv->diff_hlf != (hlf_T)0)
489 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
490# endif
491 wlv->p_extra = NULL;
492 wlv->c_extra = ' ';
493 wlv->c_final = NUL;
494 wlv->n_extra = get_breakindent_win(wp,
495 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
496 if (wlv->row == wlv->startrow)
497 {
498 wlv->n_extra -= win_col_off2(wp);
499 if (wlv->n_extra < 0)
500 wlv->n_extra = 0;
501 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100502 if (wp->w_skipcol > 0 && wlv->startrow == 0
503 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100504 wlv->need_showbreak = FALSE;
505 // Correct end of highlighted area for 'breakindent',
506 // required when 'linebreak' is also set.
507 if (wlv->tocol == wlv->vcol)
508 wlv->tocol += wlv->n_extra;
509 }
510 }
511}
512#endif
513
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100514#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
515 static void
516handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
517{
518# ifdef FEAT_DIFF
519 if (wlv->filler_todo > 0)
520 {
521 // Draw "deleted" diff line(s).
522 if (char2cells(wp->w_fill_chars.diff) > 1)
523 {
524 wlv->c_extra = '-';
525 wlv->c_final = NUL;
526 }
527 else
528 {
529 wlv->c_extra = wp->w_fill_chars.diff;
530 wlv->c_final = NUL;
531 }
532# ifdef FEAT_RIGHTLEFT
533 if (wp->w_p_rl)
534 wlv->n_extra = wlv->col + 1;
535 else
536# endif
537 wlv->n_extra = wp->w_width - wlv->col;
538 wlv->char_attr = HL_ATTR(HLF_DED);
539 }
540# endif
541
542# ifdef FEAT_LINEBREAK
543 char_u *sbr = get_showbreak_value(wp);
544 if (*sbr != NUL && wlv->need_showbreak)
545 {
546 // Draw 'showbreak' at the start of each broken line.
547 wlv->p_extra = sbr;
548 wlv->c_extra = NUL;
549 wlv->c_final = NUL;
550 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100551 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100552 wlv->need_showbreak = FALSE;
553 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
554 // Correct end of highlighted area for 'showbreak',
555 // required when 'linebreak' is also set.
556 if (wlv->tocol == wlv->vcol)
557 wlv->tocol += wlv->n_extra;
558 // combine 'showbreak' with 'wincolor'
559 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
560# ifdef FEAT_SYN_HL
561 // combine 'showbreak' with 'cursorline'
562 if (wlv->cul_attr != 0)
563 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
564# endif
565 }
566# endif
567}
568#endif
569
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100570#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100571/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100572 * Return the cell size of virtual text after truncation.
573 */
574 static int
575textprop_size_after_trunc(
576 win_T *wp,
577 int flags, // TP_FLAG_ALIGN_*
578 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100579 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100580 char_u *text,
581 int *n_used_ptr)
582{
583 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100584 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100585 int len = (int)STRLEN(text);
586 int strsize = 0;
587 int n_used;
588
Bram Moolenaar7e017462022-10-11 21:02:09 +0100589 // if the remaining size is to small and 'wrap' is set we wrap anyway and
590 // use the next line
591 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100592 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100593 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100594 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100595 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
596 {
597 int clen = ptr2cells(text + n_used);
598
599 if (strsize + clen > space)
600 break;
601 strsize += clen;
602 }
603 *n_used_ptr = n_used;
604 return strsize;
605}
606
607/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100608 * Take care of padding, right-align and truncation of virtual text after a
609 * line.
610 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
611 * padding, right-align and truncation. Otherwise only the size is computed.
612 * When "n_attr" is NULL returns the number of screen cells used.
613 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100614 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100615 int
616text_prop_position(
617 win_T *wp,
618 textprop_T *tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100619 int vcol UNUSED, // current text column
620 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100621 int *n_extra, // nr of bytes for virtual text
622 char_u **p_extra, // virtual text
623 int *n_attr, // attribute cells, NULL if not used
624 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200625{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100626 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100627 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100628 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
629 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
630 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
631 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100632 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100633 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100634 int before = room; // spaces before the text
635 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100636 int n_used = *n_extra;
637 char_u *l = NULL;
638 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100639 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100640 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar1206c162022-10-10 15:40:04 +0100641 int cont_on_next_line = below && col_with_padding > win_col_off(wp)
642 && !wp->w_p_wrap;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200643
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100644 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100645 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100646 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100647 int skip_add = 0;
648
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100649 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100650 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100651 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100652 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100653 }
654 else
655 {
656 // Right-align: fill with before
657 if (right)
658 before -= cells;
659 if (before < 0
660 || !(right || below)
661 || (below
Bram Moolenaarccf28372022-10-10 21:10:03 +0100662 ? (col_with_padding <= col_off || !wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100663 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100664 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100665 if (right && (wrap
666 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100667 {
668 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100669 before = wp->w_width - col_off - strsize + room;
670 if (before < 0)
671 before = 0;
672 else
673 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100674 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100675 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100676 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100677 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100678 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100679 else if (below && before > 0)
680 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100681 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100682 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100683
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100684 // With 'nowrap' add one to show the "extends" character if needed (it
685 // doesn't show if the text just fits).
686 if (!wp->w_p_wrap
687 && n_used < *n_extra
688 && wp->w_lcs_chars.ext != NUL
689 && wp->w_p_list)
690 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100691 if (!wp->w_p_wrap && below && padding > 0)
692 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100693
694 // add 1 for NUL, 2 for when '…' is used
695 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100696 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100697 if (n_attr == NULL || l != NULL)
698 {
699 int off = 0;
700
701 if (n_attr != NULL)
702 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100703 vim_memset(l, ' ', before);
704 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100705 if (padding > 0)
706 {
707 vim_memset(l + off, ' ', padding);
708 off += padding;
709 }
710 vim_strncpy(l + off, *p_extra, n_used);
711 off += n_used;
712 }
713 else
714 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100715 off = before + after + padding + n_used;
716 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100717 }
718 if (n_attr != NULL)
719 {
720 if (n_used < *n_extra && wp->w_p_wrap)
721 {
722 char_u *lp = l + off - 1;
723
724 if (has_mbyte)
725 {
726 // change last character to '…'
727 lp -= (*mb_head_off)(l, lp);
728 STRCPY(lp, "…");
Bram Moolenaar13845c42022-10-09 15:26:03 +0100729 n_used = lp - l + 3 - before - padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100730 }
731 else
732 // change last character to '>'
733 *lp = '>';
734 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100735 else if (after > 0)
736 {
737 vim_memset(l + off, ' ', after);
738 l[off + after] = NUL;
739 }
740
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100741 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100742 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100743 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100744 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100745 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100746
747 // Add "skip_add" when starting a new line or wrapping,
748 // n_attr_skip will then be decremented in the number column.
749 *n_attr_skip = before + padding
750 + (cont_on_next_line || before > 0 ? skip_add : 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100751 }
752 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100753 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100754
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100755 if (n_attr == NULL)
756 return cells;
757 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200758}
759#endif
760
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100761/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100762 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100763 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
764 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100765 */
766 static void
767wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
768{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100769 if (wlv->row == 0 && wp->w_skipcol > 0
770#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100771 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100772 && *get_showbreak_value(wp) == NUL
773#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100774 // do not overwrite the 'listchars' "precedes" text with "<<<"
775 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100776 {
777 int off = (int)(current_ScreenLine - ScreenLines);
Bram Moolenaareb4de622022-10-15 13:42:17 +0100778 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100779
Bram Moolenaareb4de622022-10-15 13:42:17 +0100780 if (wp->w_p_nu && wp->w_p_rnu)
781 // Do not overwrite the line number, change "123 text" to
782 // "123>>>xt".
783 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
784 {
785 ++off;
786 ++skip;
787 }
788
789 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100790 {
791 ScreenLines[off] = '<';
792 if (enc_utf8)
793 ScreenLinesUC[off] = 0;
794 ScreenAttrs[off] = HL_ATTR(HLF_AT);
795 ++off;
796 }
797 }
798
799 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
800 negative_width ? -wp->w_width : wp->w_width,
801 wlv->screen_line_flags);
802}
803
804/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100805 * Called when finished with the line: draw the screen line and handle any
806 * highlighting until the right of the window.
807 */
808 static void
809draw_screen_line(win_T *wp, winlinevars_T *wlv)
810{
811#ifdef FEAT_SYN_HL
812 long v;
813
814 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
815 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100816 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100817 else
818 v = wp->w_leftcol;
819
820 // check if line ends before left margin
821 if (wlv->vcol < v + wlv->col - win_col_off(wp))
822 wlv->vcol = v + wlv->col - win_col_off(wp);
823# ifdef FEAT_CONCEAL
824 // Get rid of the boguscols now, we want to draw until the right
825 // edge for 'cursorcolumn'.
826 wlv->col -= wlv->boguscols;
827 wlv->boguscols = 0;
828# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
829# else
830# define VCOL_HLC (wlv->vcol)
831# endif
832
833 if (wlv->draw_color_col)
834 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
835
836 if (((wp->w_p_cuc
837 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
838 && (int)wp->w_virtcol <
839 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
840 && wlv->lnum != wp->w_cursor.lnum)
841 || wlv->draw_color_col
842 || wlv->win_attr != 0)
843# ifdef FEAT_RIGHTLEFT
844 && !wp->w_p_rl
845# endif
846 )
847 {
848 int rightmost_vcol = 0;
849 int i;
850
851 if (wp->w_p_cuc)
852 rightmost_vcol = wp->w_virtcol;
853 if (wlv->draw_color_col)
854 // determine rightmost colorcolumn to possibly draw
855 for (i = 0; wlv->color_cols[i] >= 0; ++i)
856 if (rightmost_vcol < wlv->color_cols[i])
857 rightmost_vcol = wlv->color_cols[i];
858
859 while (wlv->col < wp->w_width)
860 {
861 ScreenLines[wlv->off] = ' ';
862 if (enc_utf8)
863 ScreenLinesUC[wlv->off] = 0;
864 ScreenCols[wlv->off] = MAXCOL;
865 ++wlv->col;
866 if (wlv->draw_color_col)
867 wlv->draw_color_col = advance_color_col(
868 VCOL_HLC, &wlv->color_cols);
869
870 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
871 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
872 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
873 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
874 else
875 ScreenAttrs[wlv->off++] = wlv->win_attr;
876
877 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
878 break;
879
880 ++wlv->vcol;
881 }
882 }
883#endif
884
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100885 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100886 ++wlv->row;
887 ++wlv->screen_row;
888}
889#undef VCOL_HLC
890
891/*
892 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100893 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100894 */
895 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100896win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100897{
898 wlv->col = 0;
899 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
900
901#ifdef FEAT_RIGHTLEFT
902 if (wp->w_p_rl)
903 {
904 // Rightleft window: process the text in the normal direction, but put
905 // it in current_ScreenLine[] from right to left. Start at the
906 // rightmost column of the window.
907 wlv->col = wp->w_width - 1;
908 wlv->off += wlv->col;
909 wlv->screen_line_flags |= SLF_RIGHTLEFT;
910 }
911#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100912 if (save_extra)
913 {
914 // reset the drawing state for the start of a wrapped line
915 wlv->draw_state = WL_START;
916 wlv->saved_n_extra = wlv->n_extra;
917 wlv->saved_p_extra = wlv->p_extra;
918 wlv->saved_c_extra = wlv->c_extra;
919 wlv->saved_c_final = wlv->c_final;
920#ifdef FEAT_SYN_HL
921 if (!(wlv->cul_screenline
922# ifdef FEAT_DIFF
923 && wlv->diff_hlf == (hlf_T)0
924# endif
925 ))
926 wlv->saved_char_attr = wlv->char_attr;
927 else
928#endif
929 wlv->saved_char_attr = 0;
930 wlv->n_extra = 0;
931 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100932}
933
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200934/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100935 * Called when wlv->draw_state is set to WL_LINE.
936 */
937 static void
938win_line_continue(winlinevars_T *wlv)
939{
940 if (wlv->saved_n_extra > 0)
941 {
942 // Continue item from end of wrapped line.
943 wlv->n_extra = wlv->saved_n_extra;
944 wlv->c_extra = wlv->saved_c_extra;
945 wlv->c_final = wlv->saved_c_final;
946 wlv->p_extra = wlv->saved_p_extra;
947 wlv->char_attr = wlv->saved_char_attr;
948 }
949 else
950 wlv->char_attr = wlv->win_attr;
951}
952
953/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200954 * Display line "lnum" of window 'wp' on the screen.
955 * Start at row "startrow", stop when "endrow" is reached.
956 * wp->w_virtcol needs to be valid.
957 *
958 * Return the number of last row the line occupies.
959 */
960 int
961win_line(
962 win_T *wp,
963 linenr_T lnum,
964 int startrow,
965 int endrow,
966 int nochange UNUSED, // not updating for changed text
967 int number_only) // only update the number column
968{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100969 winlinevars_T wlv; // variables passed between functions
970
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200971 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100972 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200973 char_u *line; // current line
974 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200975
Bram Moolenaar1306b362022-08-06 15:59:06 +0100976#ifdef FEAT_PROP_POPUP
977 char_u *p_extra_free2 = NULL; // another p_extra to be freed
978#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200979 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000980#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000981 int in_linebreak = FALSE; // n_extra set for showing linebreak
982#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200983 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100984 // displaying eol at end-of-line
985 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000986 int lcs_prec_todo = wp->w_lcs_chars.prec;
987 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200988
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100989 int n_attr = 0; // chars with special attr
990 int n_attr_skip = 0; // chars to skip before using extra_attr
991 int saved_attr2 = 0; // char_attr saved for n_attr
992 int n_attr3 = 0; // chars with overruling special attr
993 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200994
Bram Moolenaarcd105412022-10-10 19:50:42 +0100995 int n_skip = 0; // nr of cells to skip for 'nowrap' or
996 // concealing
Bram Moolenaard3283fb2022-10-10 20:33:25 +0100997#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +0100998 int skip_cells = 0; // nr of cells to skip for virtual text
999 // after the line, when w_skipcol is
1000 // larger than the text length
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001001#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001002
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001003 int fromcol_prev = -2; // start of inverting after cursor
1004 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001005 int lnum_in_visual_area = FALSE;
1006 pos_T pos;
1007 long v;
1008
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001009 int attr_pri = FALSE; // char_attr has priority
1010 int area_highlighting = FALSE; // Visual or incsearch highlighting
1011 // in this line
1012 int vi_attr = 0; // attributes for Visual and incsearch
1013 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001014 int area_attr = 0; // attributes desired by highlighting
1015 int search_attr = 0; // attributes desired by 'hlsearch'
1016#ifdef FEAT_SYN_HL
1017 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1018 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001019 int prev_syntax_col = -1; // column of prev_syntax_attr
1020 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001021 int has_syntax = FALSE; // this buffer has syntax highl.
1022 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001023#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001024#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001025 int text_prop_count;
1026 int text_prop_next = 0; // next text property to use
1027 textprop_T *text_props = NULL;
1028 int *text_prop_idxs = NULL;
1029 int text_props_active = 0;
1030 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001031 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001032 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001033 int text_prop_attr_comb = 0; // text_prop_attr combined with
1034 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001035 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001036 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001037 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001038 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001039 int saved_search_attr = 0; // search_attr to be used when n_extra
1040 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001041 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001042#endif
1043#ifdef FEAT_SPELL
1044 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001045 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001046# define SPWORDLEN 150
1047 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1048 int nextlinecol = 0; // column where nextline[] starts
1049 int nextline_idx = 0; // index in nextline[] where next line
1050 // starts
1051 int spell_attr = 0; // attributes desired by spelling
1052 int word_end = 0; // last byte with same spell_attr
1053 static linenr_T checked_lnum = 0; // line number for "checked_col"
1054 static int checked_col = 0; // column in "checked_lnum" up to which
1055 // there are no spell errors
1056 static int cap_col = -1; // column to check for Cap word
1057 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1058 int cur_checked_col = 0; // checked column for current line
1059#endif
1060 int extra_check = 0; // has extra highlighting
1061 int multi_attr = 0; // attributes desired by multibyte
1062 int mb_l = 1; // multi-byte byte length
1063 int mb_c = 0; // decoded multi-byte character
1064 int mb_utf8 = FALSE; // screen char is UTF-8 char
1065 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001066#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001067 int change_start = MAXCOL; // first col of changed area
1068 int change_end = -1; // last col of changed area
1069#endif
1070 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001071 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001072 int in_multispace = FALSE; // in multiple consecutive spaces
1073 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001074#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
1075 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
1076# define LINE_ATTR
1077 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +01001078 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001079#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001080 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001081 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001082#ifdef FEAT_ARABIC
1083 int prev_c = 0; // previous Arabic character
1084 int prev_c1 = 0; // first composing char for prev_c
1085#endif
1086#if defined(LINE_ATTR)
1087 int did_line_attr = 0;
1088#endif
1089#ifdef FEAT_TERMINAL
1090 int get_term_attr = FALSE;
1091#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001092
Martin Tournoijba43e762022-10-13 22:12:15 +01001093#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001094 // margin columns for the screen line, needed for when 'cursorlineopt'
1095 // contains "screenline"
1096 int left_curline_col = 0;
1097 int right_curline_col = 0;
1098#endif
1099
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001100#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1101 int feedback_col = 0;
1102 int feedback_old_attr = -1;
1103#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001104
1105#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1106 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001107#endif
1108#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001109 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001110#endif
1111#ifdef FEAT_CONCEAL
1112 int syntax_flags = 0;
1113 int syntax_seqnr = 0;
1114 int prev_syntax_id = 0;
1115 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1116 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001117 int did_wcol = FALSE;
1118 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001119# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001120# define FIX_FOR_BOGUSCOLS \
1121 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001122 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001123 wlv.vcol -= wlv.vcol_off; \
1124 wlv.vcol_off = 0; \
1125 wlv.col -= wlv.boguscols; \
1126 old_boguscols = wlv.boguscols; \
1127 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001128 }
1129#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001130# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001131#endif
1132
1133 if (startrow > endrow) // past the end already!
1134 return startrow;
1135
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001136 CLEAR_FIELD(wlv);
1137
1138 wlv.lnum = lnum;
1139 wlv.startrow = startrow;
1140 wlv.row = startrow;
1141 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001142 wlv.fromcol = -10;
1143 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001144#ifdef FEAT_LINEBREAK
1145 wlv.vcol_sbr = -1;
1146#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001147
1148 if (!number_only)
1149 {
1150 // To speed up the loop below, set extra_check when there is linebreak,
1151 // trailing white space and/or syntax processing to be done.
1152#ifdef FEAT_LINEBREAK
1153 extra_check = wp->w_p_lbr;
1154#endif
1155#ifdef FEAT_SYN_HL
1156 if (syntax_present(wp) && !wp->w_s->b_syn_error
1157# ifdef SYN_TIME_LIMIT
1158 && !wp->w_s->b_syn_slow
1159# endif
1160 )
1161 {
1162 // Prepare for syntax highlighting in this line. When there is an
1163 // error, stop syntax highlighting.
1164 save_did_emsg = did_emsg;
1165 did_emsg = FALSE;
1166 syntax_start(wp, lnum);
1167 if (did_emsg)
1168 wp->w_s->b_syn_error = TRUE;
1169 else
1170 {
1171 did_emsg = save_did_emsg;
1172#ifdef SYN_TIME_LIMIT
1173 if (!wp->w_s->b_syn_slow)
1174#endif
1175 {
1176 has_syntax = TRUE;
1177 extra_check = TRUE;
1178 }
1179 }
1180 }
1181
1182 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001183 wlv.color_cols = wp->w_p_cc_cols;
1184 if (wlv.color_cols != NULL)
1185 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001186#endif
1187
1188#ifdef FEAT_TERMINAL
1189 if (term_show_buffer(wp->w_buffer))
1190 {
1191 extra_check = TRUE;
1192 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001193 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001194 }
1195#endif
1196
1197#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001198 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001199 {
1200 // Prepare for spell checking.
1201 has_spell = TRUE;
1202 extra_check = TRUE;
1203
1204 // Get the start of the next line, so that words that wrap to the
1205 // next line are found too: "et<line-break>al.".
1206 // Trick: skip a few chars for C/shell/Vim comments
1207 nextline[SPWORDLEN] = NUL;
1208 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1209 {
1210 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1211 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1212 }
1213
1214 // When a word wrapped from the previous line the start of the
1215 // current line is valid.
1216 if (lnum == checked_lnum)
1217 cur_checked_col = checked_col;
1218 checked_lnum = 0;
1219
1220 // When there was a sentence end in the previous line may require a
1221 // word starting with capital in this line. In line 1 always check
1222 // the first word.
1223 if (lnum != capcol_lnum)
1224 cap_col = -1;
1225 if (lnum == 1)
1226 cap_col = 0;
1227 capcol_lnum = 0;
1228 }
1229#endif
1230
1231 // handle Visual active in this window
1232 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1233 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001234 pos_T *top, *bot;
1235
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001236 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1237 {
1238 // Visual is after curwin->w_cursor
1239 top = &curwin->w_cursor;
1240 bot = &VIsual;
1241 }
1242 else
1243 {
1244 // Visual is before curwin->w_cursor
1245 top = &VIsual;
1246 bot = &curwin->w_cursor;
1247 }
1248 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1249 if (VIsual_mode == Ctrl_V)
1250 {
1251 // block mode
1252 if (lnum_in_visual_area)
1253 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001254 wlv.fromcol = wp->w_old_cursor_fcol;
1255 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001256 }
1257 }
1258 else
1259 {
1260 // non-block mode
1261 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001262 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001263 else if (lnum == top->lnum)
1264 {
1265 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001266 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001267 else
1268 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001269 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001270 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001271 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001272 }
1273 }
1274 if (VIsual_mode != 'V' && lnum == bot->lnum)
1275 {
1276 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1277 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001278 wlv.fromcol = -10;
1279 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001280 }
1281 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001282 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001283 else
1284 {
1285 pos = *bot;
1286 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001287 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1288 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001289 else
1290 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001291 getvvcol(wp, &pos, NULL, NULL,
1292 (colnr_T *)&wlv.tocol);
1293 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001294 }
1295 }
1296 }
1297 }
1298
1299 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001300 if (!highlight_match && lnum == curwin->w_cursor.lnum
1301 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001302#ifdef FEAT_GUI
1303 && !gui.in_use
1304#endif
1305 )
1306 noinvcur = TRUE;
1307
1308 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001309 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001310 {
1311 area_highlighting = TRUE;
1312 vi_attr = HL_ATTR(HLF_V);
1313#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1314 if ((clip_star.available && !clip_star.owned
1315 && clip_isautosel_star())
1316 || (clip_plus.available && !clip_plus.owned
1317 && clip_isautosel_plus()))
1318 vi_attr = HL_ATTR(HLF_VNC);
1319#endif
1320 }
1321 }
1322
1323 // handle 'incsearch' and ":s///c" highlighting
1324 else if (highlight_match
1325 && wp == curwin
1326 && lnum >= curwin->w_cursor.lnum
1327 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1328 {
1329 if (lnum == curwin->w_cursor.lnum)
1330 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001331 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001332 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001333 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001334 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1335 {
1336 pos.lnum = lnum;
1337 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001338 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001339 }
1340 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001341 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001342 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001343 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1344 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001345 area_highlighting = TRUE;
1346 vi_attr = HL_ATTR(HLF_I);
1347 }
1348 }
1349
1350#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001351 wlv.filler_lines = diff_check(wp, lnum);
1352 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001353 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001354 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001355 {
1356 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001357 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001358 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001359 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001360 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001361 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001362 }
1363 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001364 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001365 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001366 area_highlighting = TRUE;
1367 }
1368 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001369 wlv.filler_lines = wp->w_topfill;
1370 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001371#endif
1372
1373#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001374 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001375 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001376 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001377#endif
1378
1379#ifdef LINE_ATTR
1380# ifdef FEAT_SIGNS
1381 // If this line has a sign with line highlighting set line_attr.
1382 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001383 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001384# endif
1385# if defined(FEAT_QUICKFIX)
1386 // Highlight the current line in the quickfix window.
1387 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1388 line_attr = HL_ATTR(HLF_QFL);
1389# endif
1390 if (line_attr != 0)
1391 area_highlighting = TRUE;
1392#endif
1393
1394 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1395 ptr = line;
1396
1397#ifdef FEAT_SPELL
1398 if (has_spell && !number_only)
1399 {
1400 // For checking first word with a capital skip white space.
1401 if (cap_col == 0)
1402 cap_col = getwhitecols(line);
1403
1404 // To be able to spell-check over line boundaries copy the end of the
1405 // current line into nextline[]. Above the start of the next line was
1406 // copied to nextline[SPWORDLEN].
1407 if (nextline[SPWORDLEN] == NUL)
1408 {
1409 // No next line or it is empty.
1410 nextlinecol = MAXCOL;
1411 nextline_idx = 0;
1412 }
1413 else
1414 {
1415 v = (long)STRLEN(line);
1416 if (v < SPWORDLEN)
1417 {
1418 // Short line, use it completely and append the start of the
1419 // next line.
1420 nextlinecol = 0;
1421 mch_memmove(nextline, line, (size_t)v);
1422 STRMOVE(nextline + v, nextline + SPWORDLEN);
1423 nextline_idx = v + 1;
1424 }
1425 else
1426 {
1427 // Long line, use only the last SPWORDLEN bytes.
1428 nextlinecol = v - SPWORDLEN;
1429 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1430 nextline_idx = SPWORDLEN + 1;
1431 }
1432 }
1433 }
1434#endif
1435
1436 if (wp->w_p_list)
1437 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001438 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001439 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001440 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001441 || wp->w_lcs_chars.trail
1442 || wp->w_lcs_chars.lead
1443 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001444 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001445
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001446 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001447 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001448 {
1449 trailcol = (colnr_T)STRLEN(ptr);
1450 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1451 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001452 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001453 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001454 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001455 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001456 {
1457 leadcol = 0;
1458 while (VIM_ISWHITE(ptr[leadcol]))
1459 ++leadcol;
1460 if (ptr[leadcol] == NUL)
1461 // in a line full of spaces all of them are treated as trailing
1462 leadcol = (colnr_T)0;
1463 else
1464 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001465 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001466 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001467 }
1468
Bram Moolenaard7657e92022-09-20 18:59:30 +01001469 wlv.wcr_attr = get_wcr_attr(wp);
1470 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001471 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001472 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001473 area_highlighting = TRUE;
1474 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001475
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001476#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001477 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001478 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001479#endif
1480
1481 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1482 // first character to be displayed.
1483 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001484 v = startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001485 else
1486 v = wp->w_leftcol;
1487 if (v > 0 && !number_only)
1488 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001489 char_u *prev_ptr = ptr;
1490 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001491 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001492
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001493 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001494 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001495 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001496 charsize = win_lbr_chartabsize(&cts, NULL);
1497 cts.cts_vcol += charsize;
1498 prev_ptr = cts.cts_ptr;
1499 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001500 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001501 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001502 ptr = cts.cts_ptr;
1503 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001504
1505 // When:
1506 // - 'cuc' is set, or
1507 // - 'colorcolumn' is set, or
1508 // - 'virtualedit' is set, or
1509 // - the visual mode is active,
1510 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001511 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001512#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001513 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001514#endif
1515 virtual_active() ||
1516 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001517 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001518
1519 // Handle a character that's not completely on the screen: Put ptr at
1520 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001521 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001522 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001523 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001524 ptr = prev_ptr;
1525 // If the character fits on the screen, don't need to skip it.
1526 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001527 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1528 && wlv.col == 0)
1529 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001530 }
1531
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001532#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001533 // If there the text doesn't reach to the desired column, need to skip
1534 // "skip_cells" cells when virtual text follows.
1535 if (!wp->w_p_wrap && v > wlv.vcol)
1536 skip_cells = v - wlv.vcol;
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001537#endif
Bram Moolenaarcd105412022-10-10 19:50:42 +01001538
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001539 // Adjust for when the inverted text is before the screen,
1540 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001541 if (wlv.tocol <= wlv.vcol)
1542 wlv.fromcol = 0;
1543 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1544 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001545
1546#ifdef FEAT_LINEBREAK
1547 // When w_skipcol is non-zero, first line needs 'showbreak'
1548 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001549 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001550#endif
1551#ifdef FEAT_SPELL
1552 // When spell checking a word we need to figure out the start of the
1553 // word and if it's badly spelled or not.
1554 if (has_spell)
1555 {
1556 int len;
1557 colnr_T linecol = (colnr_T)(ptr - line);
1558 hlf_T spell_hlf = HLF_COUNT;
1559
1560 pos = wp->w_cursor;
1561 wp->w_cursor.lnum = lnum;
1562 wp->w_cursor.col = linecol;
1563 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1564
1565 // spell_move_to() may call ml_get() and make "line" invalid
1566 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1567 ptr = line + linecol;
1568
1569 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1570 {
1571 // no bad word found at line start, don't check until end of a
1572 // word
1573 spell_hlf = HLF_COUNT;
1574 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1575 }
1576 else
1577 {
1578 // bad word found, use attributes until end of word
1579 word_end = wp->w_cursor.col + len + 1;
1580
1581 // Turn index into actual attributes.
1582 if (spell_hlf != HLF_COUNT)
1583 spell_attr = highlight_attr[spell_hlf];
1584 }
1585 wp->w_cursor = pos;
1586
1587# ifdef FEAT_SYN_HL
1588 // Need to restart syntax highlighting for this line.
1589 if (has_syntax)
1590 syntax_start(wp, lnum);
1591# endif
1592 }
1593#endif
1594 }
1595
1596 // Correct highlighting for cursor that can't be disabled.
1597 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001598 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001599 {
1600 if (noinvcur)
1601 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001602 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001603 {
1604 // highlighting starts at cursor, let it start just after the
1605 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001606 fromcol_prev = wlv.fromcol;
1607 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001608 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001609 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001610 // restart highlighting after the cursor
1611 fromcol_prev = wp->w_virtcol;
1612 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001613 if (wlv.fromcol >= wlv.tocol)
1614 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001615 }
1616
1617#ifdef FEAT_SEARCH_EXTRA
1618 if (!number_only)
1619 {
1620 v = (long)(ptr - line);
1621 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1622 &line, &screen_search_hl,
1623 &search_attr);
1624 ptr = line + v; // "line" may have been updated
1625 }
1626#endif
1627
1628#ifdef FEAT_SYN_HL
1629 // Cursor line highlighting for 'cursorline' in the current window.
1630 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1631 {
1632 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001633 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001634 if (!(wp == curwin && VIsual_active)
1635 && wp->w_p_culopt_flags != CULOPT_NBR)
1636 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001637 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001638 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1639
1640 // Only set line_attr here when "screenline" is not present in
1641 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001642 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001643 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001644 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001645# ifdef FEAT_SIGNS
1646 // Combine the 'cursorline' and sign highlighting, depending on
1647 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001648 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001649 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001650 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001651 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001652 else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001653 line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001654 }
1655 else
1656# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001657# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001658 // let the line attribute overrule 'cursorline', otherwise
1659 // it disappears when both have background set;
1660 // 'cursorline' can use underline or bold to make it show
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001661 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001662# else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001663 line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001664# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001665 }
1666 else
1667 {
1668 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001669 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1670 }
1671 area_highlighting = TRUE;
1672 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001673 }
1674#endif
1675
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001676#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001677 {
1678 char_u *prop_start;
1679
1680 text_prop_count = get_text_props(wp->w_buffer, lnum,
1681 &prop_start, FALSE);
1682 if (text_prop_count > 0)
1683 {
1684 // Make a copy of the properties, so that they are properly
1685 // aligned.
1686 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1687 if (text_props != NULL)
1688 mch_memmove(text_props, prop_start,
1689 text_prop_count * sizeof(textprop_T));
1690
1691 // Allocate an array for the indexes.
1692 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001693 if (text_prop_idxs == NULL)
1694 VIM_CLEAR(text_props);
1695
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001696 if (text_props != NULL)
1697 {
1698 area_highlighting = TRUE;
1699 extra_check = TRUE;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +01001700 // text props "above" move the line number down to where the
1701 // text is.
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001702 for (int i = 0; i < text_prop_count; ++i)
1703 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1704 ++wlv.text_prop_above_count;
1705 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001706 }
1707 }
1708#endif
1709
Bram Moolenaar1306b362022-08-06 15:59:06 +01001710 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001711
1712 // Repeat for the whole displayed line.
1713 for (;;)
1714 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001715 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001716#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001717 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001718#endif
1719#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001720 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001721#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001722
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001723 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001724 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001725 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001726#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001727 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001728 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001729 wlv.cul_attr = 0;
zeertzjq4f33bc22021-08-05 17:57:02 +02001730 line_attr = line_attr_save;
1731 }
1732#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001733 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001734 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001735 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001736 if (cmdwin_type != 0 && wp == curwin)
1737 {
1738 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001739 wlv.n_extra = 1;
1740 wlv.c_extra = cmdwin_type;
1741 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001742 wlv.char_attr =
1743 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001744 }
1745 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001746#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001747 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001748 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001749 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001750 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001751 }
1752#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001753#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001754 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001755 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001756 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001757 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001758 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001759 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001760 }
1761#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001762 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001763 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001764 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001765 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001766 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001767 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001768#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001769 // Check if 'breakindent' applies and show it.
1770 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1771 if (wlv.n_extra == 0)
1772 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001773#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001774#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001775 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001776 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001777 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001778 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001779 }
1780#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001781 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001782 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001783 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001784 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001785 }
1786 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001787
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001788#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001789 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001790 && wlv.vcol >= left_curline_col
1791 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001792 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001793 wlv.cul_attr = HL_ATTR(HLF_CUL);
1794 line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001795 }
1796#endif
1797
1798 // When still displaying '$' of change command, stop at cursor.
1799 // When only displaying the (relative) line number and that's done,
1800 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001801 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001802 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001803 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001804#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001805 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001806#endif
1807 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001808 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001809 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001810 // Pretend we have finished updating the window. Except when
1811 // 'cursorcolumn' is set.
1812#ifdef FEAT_SYN_HL
1813 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001814 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001815 else
1816#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001817 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001818 break;
1819 }
1820
Bram Moolenaar1306b362022-08-06 15:59:06 +01001821 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001822 {
1823 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001824 if (wlv.vcol == wlv.fromcol
1825 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1826 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001827 && (*mb_ptr2cells)(ptr) > 1)
1828 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001829 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001830 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001831 area_attr = vi_attr; // start highlighting
1832 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001833 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001834 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001835 area_attr = 0; // stop highlighting
1836
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001837#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001838 if (text_props != NULL)
1839 {
1840 int pi;
1841 int bcol = (int)(ptr - line);
1842
Bram Moolenaar1306b362022-08-06 15:59:06 +01001843 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001844# ifdef FEAT_LINEBREAK
1845 && !in_linebreak
1846# endif
1847 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001848 --bcol; // still working on the previous char, e.g. Tab
1849
1850 // Check if any active property ends.
1851 for (pi = 0; pi < text_props_active; ++pi)
1852 {
1853 int tpi = text_prop_idxs[pi];
1854
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001855 if (text_props[tpi].tp_col != MAXCOL
1856 && bcol >= text_props[tpi].tp_col - 1
1857 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001858 {
1859 if (pi + 1 < text_props_active)
1860 mch_memmove(text_prop_idxs + pi,
1861 text_prop_idxs + pi + 1,
1862 sizeof(int)
1863 * (text_props_active - (pi + 1)));
1864 --text_props_active;
1865 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001866# ifdef FEAT_LINEBREAK
1867 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001868 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001869 syntax_attr = 0;
1870# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001871 }
1872 }
1873
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001874# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001875 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001876 // not on the next char yet, don't start another prop
1877 --bcol;
1878# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001879 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001880 // With 'nowrap' and not in the first screen line only "below"
1881 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001882 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001883 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001884 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001885 && (wp->w_p_wrap
1886 || wlv.row == startrow
1887 || (text_props[text_prop_next].tp_flags
1888 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001889 || (bcol == 0 &&
1890 (text_props[text_prop_next].tp_flags
1891 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001892 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001893 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001894 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001895 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1896 {
1897 // first display the '$' after the line
1898 text_prop_follows = TRUE;
1899 break;
1900 }
1901 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001902 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001903 + text_props[text_prop_next].tp_len)
1904 text_prop_idxs[text_props_active++] = text_prop_next;
1905 ++text_prop_next;
1906 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001907
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001908 if (wlv.n_extra == 0 || !extra_for_textprop)
1909 {
1910 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001911 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001912 text_prop_flags = 0;
1913 text_prop_type = NULL;
1914 text_prop_id = 0;
1915 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001916 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001917 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001918 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001919 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001920 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001921
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001922 // Sort the properties on priority and/or starting last.
1923 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001924 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001925 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001926 sort_text_props(wp->w_buffer, text_props,
1927 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001928
1929 for (pi = 0; pi < text_props_active; ++pi)
1930 {
1931 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001932 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001933 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01001934 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001935
Bram Moolenaarcd105412022-10-10 19:50:42 +01001936 // Only use a text property that can be displayed.
1937 // Skip "after" properties when wrap is off and at the
1938 // end of the window.
1939 if (pt != NULL
1940 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
1941 && tp->tp_id != -MAXCOL
1942 && !(tp->tp_id < 0
1943 && !wp->w_p_wrap
1944 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
1945 | TP_FLAG_ALIGN_ABOVE
1946 | TP_FLAG_ALIGN_BELOW)) == 0
1947 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001948 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001949 if (pt->pt_hl_id > 0)
1950 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001951 text_prop_type = pt;
1952 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001953 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001954 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001955 text_prop_flags = pt->pt_flags;
1956 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001957 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001958 }
1959 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001960 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001961 && -text_prop_id
1962 <= wp->w_buffer->b_textprop_text.ga_len)
1963 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001964 textprop_T *tp = &text_props[used_tpi];
1965 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001966 ->b_textprop_text.ga_data)[
1967 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001968 int above = (tp->tp_flags
1969 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01001970 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001971
1972 // reset the ID in the copy to avoid it being used
1973 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001974 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001975
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001976 if (p != NULL)
1977 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001978 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001979 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001980 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001981 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001982 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1983 int padding = tp->tp_col == MAXCOL
1984 && tp->tp_len > 1
1985 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001986
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001987 // Insert virtual text before the current
1988 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001989 wlv.p_extra = p;
1990 wlv.c_extra = NUL;
1991 wlv.c_final = NUL;
1992 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001993 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001994 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001995 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001996 // restore search_attr and area_attr when n_extra
1997 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001998 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001999 saved_area_attr = area_attr;
2000 search_attr = 0;
2001 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002002 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002003 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002004 if (*ptr == NUL)
2005 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002006 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002007#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002008 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002009 {
2010 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002011 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002012 wlv.need_showbreak = FALSE;
2013 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002014 }
2015#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002016 if ((right || above || below || !wrap
2017 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002018 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002019 char_u *prev_p_extra = wlv.p_extra;
2020 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002021
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002022 // Take care of padding, right-align and
2023 // truncation.
2024 // Shared with win_lbr_chartabsize(), must do
2025 // exactly the same.
2026 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002027 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002028 wlv.col,
2029 &wlv.n_extra, &wlv.p_extra,
2030 &n_attr, &n_attr_skip);
2031 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002032 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002033 // wlv.p_extra was allocated
2034 vim_free(p_extra_free2);
2035 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002036 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002037
Bram Moolenaara4abe512022-09-15 19:44:09 +01002038 if (lcs_eol_one < 0 && wlv.col
2039 + wlv.n_extra - 2 > wp->w_width)
2040 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002041 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002042
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002043 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002044 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002045 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002046 {
2047 draw_screen_line(wp, &wlv);
2048
2049 // When line got too long for screen break
2050 // here.
2051 if (wlv.row == endrow)
2052 {
2053 ++wlv.row;
2054 break;
2055 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002056 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002057 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002058 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002059 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002060 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002061
Bram Moolenaarcd105412022-10-10 19:50:42 +01002062 // If the text didn't reach until the first window
2063 // column we need to skip cells.
2064 if (skip_cells > 0)
2065 {
2066 if (wlv.n_extra > skip_cells)
2067 {
2068 wlv.n_extra -= skip_cells;
2069 wlv.p_extra += skip_cells;
2070 n_attr_skip -= skip_cells;
2071 if (n_attr_skip < 0)
2072 n_attr_skip = 0;
2073 skip_cells = 0;
2074 }
2075 else
2076 {
2077 // the whole text is left of the window, drop
2078 // it and advance to the next one
2079 skip_cells -= wlv.n_extra;
2080 wlv.n_extra = 0;
2081 n_attr_skip = 0;
2082 bail_out = TRUE;
2083 }
2084 }
2085
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002086 // If another text prop follows the condition below at
2087 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002088 // If this is an "above" text prop and 'nowrap' the we
2089 // must wrap anyway.
2090 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002091 text_prop_follows |= other_tpi != -1
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002092 && (wp->w_p_wrap
2093 || (text_props[other_tpi].tp_flags
2094 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002095
2096 if (bail_out)
2097 // starting a new line for "below"
2098 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002099 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002100 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002101 else if (text_prop_next < text_prop_count
2102 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002103 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2104 || (!wp->w_p_wrap
2105 && wlv.col == wp->w_width - 1
2106 && (text_props[text_prop_next].tp_flags
2107 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002108 // When at last-but-one character and a text property
2109 // follows after it, we may need to flush the line after
2110 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002111 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002112 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002113 }
2114#endif
2115
Bram Moolenaare38fc862022-08-11 17:24:50 +01002116#ifdef FEAT_SEARCH_EXTRA
2117 if (wlv.n_extra == 0)
2118 {
2119 // Check for start/end of 'hlsearch' and other matches.
2120 // After end, check for start/end of next match.
2121 // When another match, have to check for start again.
2122 v = (long)(ptr - line);
2123 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2124 &screen_search_hl, &has_match_conc,
2125 &match_conc, did_line_attr, lcs_eol_one,
2126 &on_last_col);
2127 ptr = line + v; // "line" may have been changed
2128 prev_ptr = ptr;
2129
2130 // Do not allow a conceal over EOL otherwise EOL will be missed
2131 // and bad things happen.
2132 if (*ptr == NUL)
2133 has_match_conc = 0;
2134 }
2135#endif
2136
2137#ifdef FEAT_DIFF
2138 if (wlv.diff_hlf != (hlf_T)0)
2139 {
2140 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2141 && wlv.n_extra == 0)
2142 wlv.diff_hlf = HLF_TXD; // changed text
2143 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2144 && wlv.n_extra == 0)
2145 wlv.diff_hlf = HLF_CHD; // changed line
2146 line_attr = HL_ATTR(wlv.diff_hlf);
2147 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2148 && wp->w_p_culopt_flags != CULOPT_NBR
2149 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2150 && wlv.vcol <= right_curline_col)))
2151 line_attr = hl_combine_attr(
2152 line_attr, HL_ATTR(HLF_CUL));
2153 }
2154#endif
2155
Bram Moolenaara74fda62019-10-19 17:38:03 +02002156#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002157 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002158 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002159 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002160# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002161 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002162 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002163# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002164 // Get syntax attribute.
2165 if (has_syntax)
2166 {
2167 // Get the syntax attribute for the character. If there
2168 // is an error, disable syntax highlighting.
2169 save_did_emsg = did_emsg;
2170 did_emsg = FALSE;
2171
2172 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002173 if (v == prev_syntax_col)
2174 // at same column again
2175 syntax_attr = prev_syntax_attr;
2176 else
2177 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002178# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002179 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002180# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002181 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002182# ifdef FEAT_SPELL
2183 has_spell ? &can_spell :
2184# endif
2185 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002186 prev_syntax_col = v;
2187 prev_syntax_attr = syntax_attr;
2188 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002189
Bram Moolenaar34390282019-10-16 14:38:26 +02002190 if (did_emsg)
2191 {
2192 wp->w_s->b_syn_error = TRUE;
2193 has_syntax = FALSE;
2194 syntax_attr = 0;
2195 }
2196 else
2197 did_emsg = save_did_emsg;
2198# ifdef SYN_TIME_LIMIT
2199 if (wp->w_s->b_syn_slow)
2200 has_syntax = FALSE;
2201# endif
2202
2203 // Need to get the line again, a multi-line regexp may
2204 // have made it invalid.
2205 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2206 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002207 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002208# ifdef FEAT_CONCEAL
2209 // no concealing past the end of the line, it interferes
2210 // with line highlighting
2211 if (*ptr == NUL)
2212 syntax_flags = 0;
2213 else
2214 syntax_flags = get_syntax_info(&syntax_seqnr);
2215# endif
2216 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002217 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002218# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002219 // Combine text property highlight into syntax highlight.
2220 if (text_prop_type != NULL)
2221 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002222 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002223 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2224 else
2225 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002226 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002227 }
2228# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002229#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002230
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002231 // Decide which of the highlight attributes to use.
2232 attr_pri = TRUE;
2233#ifdef LINE_ATTR
2234 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002235 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002236 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002237 if (!highlight_match)
2238 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002239 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002240# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002241 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002242# endif
2243 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002244 else if (search_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, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002247# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002248 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002249# endif
2250 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002251 else if (line_attr != 0
2252 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2253 || wlv.vcol < wlv.fromcol
2254 || vcol_prev < fromcol_prev
2255 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002256 {
2257 // Use line_attr when not in the Visual or 'incsearch' area
2258 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002259# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002260 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002261# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002262 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002263# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002264 attr_pri = FALSE;
2265 }
2266#else
2267 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002268 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002269 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002270 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002271#endif
2272 else
2273 {
2274 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002275#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002276 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002277#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002278 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002279#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002280 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002281#ifdef FEAT_PROP_POPUP
2282 // override with text property highlight when "override" is TRUE
2283 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002284 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002285#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002286 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002287
2288 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002289 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002290 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002291 if (wlv.char_attr == 0)
2292 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002293 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002294 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002295 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002296
2297 // Get the next character to put on the screen.
2298
2299 // The "p_extra" points to the extra stuff that is inserted to
2300 // represent special characters (non-printable stuff) and other
2301 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002302 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002303 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2304 // "p_extra[n_extra]".
2305 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002306 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002307 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002308 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002309 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002310 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2311 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002312 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2313 if (enc_utf8 && utf_char2len(c) > 1)
2314 {
2315 mb_utf8 = TRUE;
2316 u8cc[0] = 0;
2317 c = 0xc0;
2318 }
2319 else
2320 mb_utf8 = FALSE;
2321 }
2322 else
2323 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002324 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002325 if (has_mbyte)
2326 {
2327 mb_c = c;
2328 if (enc_utf8)
2329 {
2330 // If the UTF-8 character is more than one byte:
2331 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002332 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002333 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002334 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002335 mb_l = 1;
2336 else if (mb_l > 1)
2337 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002338 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002339 mb_utf8 = TRUE;
2340 c = 0xc0;
2341 }
2342 }
2343 else
2344 {
2345 // if this is a DBCS character, put it in "mb_c"
2346 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002347 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002348 mb_l = 1;
2349 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002350 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002351 }
2352 if (mb_l == 0) // at the NUL at end-of-line
2353 mb_l = 1;
2354
2355 // If a double-width char doesn't fit display a '>' in the
2356 // last column.
2357 if ((
2358# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002359 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002360# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002361 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002362 && (*mb_char2cells)(mb_c) == 2)
2363 {
2364 c = '>';
2365 mb_c = c;
2366 mb_l = 1;
2367 mb_utf8 = FALSE;
2368 multi_attr = HL_ATTR(HLF_AT);
2369#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002370 if (wlv.cul_attr)
2371 multi_attr = hl_combine_attr(
2372 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002373#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002374 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002375
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002376 // put the pointer back to output the double-width
2377 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002378 ++wlv.n_extra;
2379 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002380 }
2381 else
2382 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002383 wlv.n_extra -= mb_l - 1;
2384 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002385 }
2386 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002387 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002388 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002389 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002390#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002391 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002392 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002393 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002394 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002395 if (search_attr == 0)
2396 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002397 if (area_attr == 0 && *ptr != NUL)
2398 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002399 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002400#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002401 }
2402 else
2403 {
2404#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002405 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002406#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002407 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002408
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002409 // Get a character from the line itself.
2410 c = *ptr;
2411#ifdef FEAT_LINEBREAK
2412 c0 = *ptr;
2413#endif
2414 if (has_mbyte)
2415 {
2416 mb_c = c;
2417 if (enc_utf8)
2418 {
2419 // If the UTF-8 character is more than one byte: Decode it
2420 // into "mb_c".
2421 mb_l = utfc_ptr2len(ptr);
2422 mb_utf8 = FALSE;
2423 if (mb_l > 1)
2424 {
2425 mb_c = utfc_ptr2char(ptr, u8cc);
2426 // Overlong encoded ASCII or ASCII with composing char
2427 // is displayed normally, except a NUL.
2428 if (mb_c < 0x80)
2429 {
2430 c = mb_c;
2431#ifdef FEAT_LINEBREAK
2432 c0 = mb_c;
2433#endif
2434 }
2435 mb_utf8 = TRUE;
2436
2437 // At start of the line we can have a composing char.
2438 // Draw it as a space with a composing char.
2439 if (utf_iscomposing(mb_c))
2440 {
2441 int i;
2442
2443 for (i = Screen_mco - 1; i > 0; --i)
2444 u8cc[i] = u8cc[i - 1];
2445 u8cc[0] = mb_c;
2446 mb_c = ' ';
2447 }
2448 }
2449
2450 if ((mb_l == 1 && c >= 0x80)
2451 || (mb_l >= 1 && mb_c == 0)
2452 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2453 {
2454 // Illegal UTF-8 byte: display as <xx>.
2455 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002456 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002457# ifdef FEAT_RIGHTLEFT
2458 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002459 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002460# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002461 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002462 c = *wlv.p_extra;
2463 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002464 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002465 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2466 wlv.c_extra = NUL;
2467 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002468 if (area_attr == 0 && search_attr == 0)
2469 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002470 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002471 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002472 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002473 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002474 }
2475 }
2476 else if (mb_l == 0) // at the NUL at end-of-line
2477 mb_l = 1;
2478#ifdef FEAT_ARABIC
2479 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2480 {
2481 // Do Arabic shaping.
2482 int pc, pc1, nc;
2483 int pcc[MAX_MCO];
2484
2485 // The idea of what is the previous and next
2486 // character depends on 'rightleft'.
2487 if (wp->w_p_rl)
2488 {
2489 pc = prev_c;
2490 pc1 = prev_c1;
2491 nc = utf_ptr2char(ptr + mb_l);
2492 prev_c1 = u8cc[0];
2493 }
2494 else
2495 {
2496 pc = utfc_ptr2char(ptr + mb_l, pcc);
2497 nc = prev_c;
2498 pc1 = pcc[0];
2499 }
2500 prev_c = mb_c;
2501
2502 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2503 }
2504 else
2505 prev_c = mb_c;
2506#endif
2507 }
2508 else // enc_dbcs
2509 {
2510 mb_l = MB_BYTE2LEN(c);
2511 if (mb_l == 0) // at the NUL at end-of-line
2512 mb_l = 1;
2513 else if (mb_l > 1)
2514 {
2515 // We assume a second byte below 32 is illegal.
2516 // Hopefully this is OK for all double-byte encodings!
2517 if (ptr[1] >= 32)
2518 mb_c = (c << 8) + ptr[1];
2519 else
2520 {
2521 if (ptr[1] == NUL)
2522 {
2523 // head byte at end of line
2524 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002525 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002526 }
2527 else
2528 {
2529 // illegal tail byte
2530 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002531 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002532 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002533 wlv.p_extra = wlv.extra;
2534 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002535 wlv.c_extra = NUL;
2536 wlv.c_final = NUL;
2537 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002538 if (area_attr == 0 && search_attr == 0)
2539 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002540 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002541 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002542 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002543 // save current attr
2544 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002545 }
2546 mb_c = c;
2547 }
2548 }
2549 }
2550 // If a double-width char doesn't fit display a '>' in the
2551 // last column; the character is displayed at the start of the
2552 // next line.
2553 if ((
2554# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002555 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002556# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002557 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002558 && (*mb_char2cells)(mb_c) == 2)
2559 {
2560 c = '>';
2561 mb_c = c;
2562 mb_utf8 = FALSE;
2563 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002564 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002565 // Put pointer back so that the character will be
2566 // displayed at the start of the next line.
2567 --ptr;
2568#ifdef FEAT_CONCEAL
2569 did_decrement_ptr = TRUE;
2570#endif
2571 }
2572 else if (*ptr != NUL)
2573 ptr += mb_l - 1;
2574
2575 // If a double-width char doesn't fit at the left side display
2576 // a '<' in the first column. Don't do this for unprintable
2577 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002578 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002579 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002580 wlv.n_extra = 1;
2581 wlv.c_extra = MB_FILLER_CHAR;
2582 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002583 c = ' ';
2584 if (area_attr == 0 && search_attr == 0)
2585 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002586 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002587 extra_attr = hl_combine_attr(
2588 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002589 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002590 }
2591 mb_c = c;
2592 mb_utf8 = FALSE;
2593 mb_l = 1;
2594 }
2595
2596 }
2597 ++ptr;
2598
2599 if (extra_check)
2600 {
2601#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002602 // Check spelling (unless at the end of the line).
2603 // Only do this when there is no syntax highlighting, the
2604 // @Spell cluster is not used or the current syntax item
2605 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002606 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002607 if (has_spell && v >= word_end && v > cur_checked_col)
2608 {
2609 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002610 // do not calculate cap_col at the end of the line or when
2611 // only white space is following
2612 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002613# ifdef FEAT_SYN_HL
2614 !has_syntax ||
2615# endif
2616 can_spell))
2617 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002618 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002619 int len;
2620 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002621
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002622 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002623 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002624
2625 // Use nextline[] if possible, it has the start of the
2626 // next line concatenated.
2627 if ((prev_ptr - line) - nextlinecol >= 0)
2628 p = nextline + (prev_ptr - line) - nextlinecol;
2629 else
2630 p = prev_ptr;
2631 cap_col -= (int)(prev_ptr - line);
2632 len = spell_check(wp, p, &spell_hlf, &cap_col,
2633 nochange);
2634 word_end = v + len;
2635
2636 // In Insert mode only highlight a word that
2637 // doesn't touch the cursor.
2638 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002639 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002640 && wp->w_cursor.lnum == lnum
2641 && wp->w_cursor.col >=
2642 (colnr_T)(prev_ptr - line)
2643 && wp->w_cursor.col < (colnr_T)word_end)
2644 {
2645 spell_hlf = HLF_COUNT;
2646 spell_redraw_lnum = lnum;
2647 }
2648
2649 if (spell_hlf == HLF_COUNT && p != prev_ptr
2650 && (p - nextline) + len > nextline_idx)
2651 {
2652 // Remember that the good word continues at the
2653 // start of the next line.
2654 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002655 checked_col = (int)((p - nextline)
2656 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002657 }
2658
2659 // Turn index into actual attributes.
2660 if (spell_hlf != HLF_COUNT)
2661 spell_attr = highlight_attr[spell_hlf];
2662
2663 if (cap_col > 0)
2664 {
2665 if (p != prev_ptr
2666 && (p - nextline) + cap_col >= nextline_idx)
2667 {
2668 // Remember that the word in the next line
2669 // must start with a capital.
2670 capcol_lnum = lnum + 1;
2671 cap_col = (int)((p - nextline) + cap_col
2672 - nextline_idx);
2673 }
2674 else
2675 // Compute the actual column.
2676 cap_col += (int)(prev_ptr - line);
2677 }
2678 }
2679 }
2680 if (spell_attr != 0)
2681 {
2682 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002683 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2684 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002685 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002686 wlv.char_attr = hl_combine_attr(spell_attr,
2687 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002688 }
2689#endif
2690#ifdef FEAT_LINEBREAK
2691 // Found last space before word: check for line break.
2692 if (wp->w_p_lbr && c0 == c
2693 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2694 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002695 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2696 : 0;
2697 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002698 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002699
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002700 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002701# ifdef FEAT_PROP_POPUP
2702 // do not want virtual text counted here
2703 cts.cts_has_prop_with_text = FALSE;
2704# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002705 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002706 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002707
2708 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002709 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002710 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002711 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002712 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2713 if (wlv.n_extra < 0)
2714 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002715 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002716 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002717 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002718 // line break, but for TABs the highlighting should
2719 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002720 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002721
Bram Moolenaar1306b362022-08-06 15:59:06 +01002722 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002723# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002724 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002725 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002726 wp->w_buffer->b_p_vts_array) - 1;
2727# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002728 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002729 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002730# endif
2731
Bram Moolenaar1306b362022-08-06 15:59:06 +01002732 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2733 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002734# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002735 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002736 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002737# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002738 if (VIM_ISWHITE(c))
2739 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002740# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002741 if (c == TAB)
2742 // See "Tab alignment" below.
2743 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002744# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002745 if (!wp->w_p_list)
2746 c = ' ';
2747 }
2748 }
2749#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002750 in_multispace = c == ' '
2751 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2752 if (!in_multispace)
2753 multispace_pos = 0;
2754
Bram Moolenaareed9d462021-02-15 20:38:25 +01002755 // 'list': Change char 160 to 'nbsp' and space to 'space'
2756 // setting in 'listchars'. But not when the character is
2757 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002758 if (wp->w_p_list
2759 && ((((c == 160 && mb_l == 1)
2760 || (mb_utf8
2761 && ((mb_c == 160 && mb_l == 2)
2762 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002763 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002764 || (c == ' '
2765 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002766 && (wp->w_lcs_chars.space
2767 || (in_multispace
2768 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002769 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002770 && ptr - line <= trailcol)))
2771 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002772 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2773 {
2774 c = wp->w_lcs_chars.multispace[multispace_pos++];
2775 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2776 multispace_pos = 0;
2777 }
2778 else
2779 c = (c == ' ') ? wp->w_lcs_chars.space
2780 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002781 if (area_attr == 0 && search_attr == 0)
2782 {
2783 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002784 extra_attr = hl_combine_attr(wlv.win_attr,
2785 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002786 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002787 }
2788 mb_c = c;
2789 if (enc_utf8 && utf_char2len(c) > 1)
2790 {
2791 mb_utf8 = TRUE;
2792 u8cc[0] = 0;
2793 c = 0xc0;
2794 }
2795 else
2796 mb_utf8 = FALSE;
2797 }
2798
zeertzjq2e7cba32022-06-10 15:30:32 +01002799 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2800 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002801 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002802 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2803 && wp->w_lcs_chars.leadmultispace != NULL)
2804 {
2805 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002806 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2807 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002808 multispace_pos = 0;
2809 }
2810
2811 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2812 c = wp->w_lcs_chars.trail;
2813
2814 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2815 c = wp->w_lcs_chars.lead;
2816
zeertzjq2e7cba32022-06-10 15:30:32 +01002817 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002818 c = wp->w_lcs_chars.space;
2819
2820
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002821 if (!attr_pri)
2822 {
2823 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002824 extra_attr = hl_combine_attr(wlv.win_attr,
2825 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002826 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002827 }
2828 mb_c = c;
2829 if (enc_utf8 && utf_char2len(c) > 1)
2830 {
2831 mb_utf8 = TRUE;
2832 u8cc[0] = 0;
2833 c = 0xc0;
2834 }
2835 else
2836 mb_utf8 = FALSE;
2837 }
2838 }
2839
2840 // Handling of non-printable characters.
2841 if (!vim_isprintc(c))
2842 {
2843 // when getting a character from the file, we may have to
2844 // turn it into something else on the way to putting it
2845 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002846 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002847 {
2848 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002849 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002850#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002851 char_u *sbr = get_showbreak_value(wp);
2852
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002853 // only adjust the tab_len, when at the first column
2854 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002855 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002856 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002857#endif
2858 // tab amount depends on current column
2859#ifdef FEAT_VARTABS
2860 tab_len = tabstop_padding(vcol_adjusted,
2861 wp->w_buffer->b_p_ts,
2862 wp->w_buffer->b_p_vts_array) - 1;
2863#else
2864 tab_len = (int)wp->w_buffer->b_p_ts
2865 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2866#endif
2867
2868#ifdef FEAT_LINEBREAK
2869 if (!wp->w_p_lbr || !wp->w_p_list)
2870#endif
2871 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002872 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002873#ifdef FEAT_LINEBREAK
2874 else
2875 {
2876 char_u *p;
2877 int len;
2878 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002879 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002880
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002881# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002882 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002883 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002884 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002885
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002886 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002887 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002888 && old_boguscols > 0
2889 && wlv.n_extra > tab_len)
2890 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002891# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002892 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002893 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002894 // If wlv.n_extra > 0, it gives the number of
2895 // chars, to use for a tab, else we need to
2896 // calculate the width for a tab.
2897 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
2898 len = tab_len * tab2_len;
2899 if (wp->w_lcs_chars.tab3)
2900 len += mb_char2len(wp->w_lcs_chars.tab3)
2901 - tab2_len;
2902 if (wlv.n_extra > 0)
2903 len += wlv.n_extra - tab_len;
2904 c = wp->w_lcs_chars.tab1;
2905 p = alloc(len + 1);
2906 if (p == NULL)
2907 wlv.n_extra = 0;
2908 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002909 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002910 vim_memset(p, ' ', len);
2911 p[len] = NUL;
2912 vim_free(wlv.p_extra_free);
2913 wlv.p_extra_free = p;
2914 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002915 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002916 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002917
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002918 if (*p == NUL)
2919 {
2920 tab_len = i;
2921 break;
2922 }
2923
2924 // if tab3 is given, use it for the last
2925 // char
2926 if (wp->w_lcs_chars.tab3
2927 && i == tab_len - 1)
2928 lcs = wp->w_lcs_chars.tab3;
2929 p += mb_char2bytes(lcs, p);
2930 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002931 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002932 }
2933 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002934# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002935 // n_extra will be increased by
2936 // FIX_FOX_BOGUSCOLS macro below, so need to
2937 // adjust for that here
2938 if (wlv.vcol_off > 0)
2939 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002940# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002941 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002942 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002943 }
2944#endif
2945#ifdef FEAT_CONCEAL
2946 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002947 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002948
2949 // Tab alignment should be identical regardless of
2950 // 'conceallevel' value. So tab compensates of all
2951 // previous concealed characters, and thus resets
2952 // vcol_off and boguscols accumulated so far in the
2953 // line. Note that the tab can be longer than
2954 // 'tabstop' when there are concealed characters.
2955 FIX_FOR_BOGUSCOLS;
2956
2957 // Make sure, the highlighting for the tab char will be
2958 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002959 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002960 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002961 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002962 tab_len += vc_saved;
2963 }
2964#endif
2965 mb_utf8 = FALSE; // don't draw as UTF-8
2966 if (wp->w_p_list)
2967 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002968 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002969 ? wp->w_lcs_chars.tab3
2970 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002971#ifdef FEAT_LINEBREAK
2972 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002973 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002974 else
2975#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002976 wlv.c_extra = wp->w_lcs_chars.tab2;
2977 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002978 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002979 extra_attr = hl_combine_attr(wlv.win_attr,
2980 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002981 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002982 mb_c = c;
2983 if (enc_utf8 && utf_char2len(c) > 1)
2984 {
2985 mb_utf8 = TRUE;
2986 u8cc[0] = 0;
2987 c = 0xc0;
2988 }
2989 }
2990 else
2991 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002992 wlv.c_final = NUL;
2993 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002994 c = ' ';
2995 }
2996 }
2997 else if (c == NUL
2998 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002999 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3000 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003001 && VIsual_mode != Ctrl_V
3002 && (
3003# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003004 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003005# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003006 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003007 && !(noinvcur
3008 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003009 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003010 && lcs_eol_one > 0)
3011 {
3012 // Display a '$' after the line or highlight an extra
3013 // character if the line break is included.
3014#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3015 // For a diff line the highlighting continues after the
3016 // "$".
3017 if (
3018# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003019 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003020# ifdef LINE_ATTR
3021 &&
3022# endif
3023# endif
3024# ifdef LINE_ATTR
3025 line_attr == 0
3026# endif
3027 )
3028#endif
3029 {
3030 // In virtualedit, visual selections may extend
3031 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003032 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003033 && wlv.tocol != MAXCOL
3034 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003035 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003036 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003037 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003038 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3039 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003040 else
3041 c = ' ';
3042 lcs_eol_one = -1;
3043 --ptr; // put it back at the NUL
3044 if (!attr_pri)
3045 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003046 extra_attr = hl_combine_attr(wlv.win_attr,
3047 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003048 n_attr = 1;
3049 }
3050 mb_c = c;
3051 if (enc_utf8 && utf_char2len(c) > 1)
3052 {
3053 mb_utf8 = TRUE;
3054 u8cc[0] = 0;
3055 c = 0xc0;
3056 }
3057 else
3058 mb_utf8 = FALSE; // don't draw as UTF-8
3059 }
3060 else if (c != NUL)
3061 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003062 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3063 if (wlv.n_extra == 0)
3064 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003065#ifdef FEAT_RIGHTLEFT
3066 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003067 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003068#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003069 wlv.c_extra = NUL;
3070 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003071#ifdef FEAT_LINEBREAK
3072 if (wp->w_p_lbr)
3073 {
3074 char_u *p;
3075
Bram Moolenaar1306b362022-08-06 15:59:06 +01003076 c = *wlv.p_extra;
3077 p = alloc(wlv.n_extra + 1);
3078 vim_memset(p, ' ', wlv.n_extra);
3079 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3080 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003081 vim_free(wlv.p_extra_free);
3082 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003083 }
3084 else
3085#endif
3086 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003087 wlv.n_extra = byte2cells(c) - 1;
3088 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003089 }
3090 if (!attr_pri)
3091 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003092 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003093 extra_attr = hl_combine_attr(wlv.win_attr,
3094 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003095 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003096 }
3097 mb_utf8 = FALSE; // don't draw as UTF-8
3098 }
3099 else if (VIsual_active
3100 && (VIsual_mode == Ctrl_V
3101 || VIsual_mode == 'v')
3102 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003103 && wlv.tocol != MAXCOL
3104 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003105 && (
3106#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003107 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003108#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003109 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003110 {
3111 c = ' ';
3112 --ptr; // put it back at the NUL
3113 }
3114#if defined(LINE_ATTR)
3115 else if ((
3116# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003117 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003118# endif
3119# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003120 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003121# endif
3122 line_attr != 0
3123 ) && (
3124# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003125 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003126# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003127 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003128# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003129 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003130# endif
3131 < wp->w_width)))
3132 {
3133 // Highlight until the right side of the window
3134 c = ' ';
3135 --ptr; // put it back at the NUL
3136
3137 // Remember we do the char for line highlighting.
3138 ++did_line_attr;
3139
3140 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01003141 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003142 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003143 || (wp->w_p_list &&
3144 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003145 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003146# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003147 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003148 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003149 wlv.diff_hlf = HLF_CHD;
3150 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003151 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003152 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003153 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3154 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003155 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003156 || (wlv.vcol >= left_curline_col
3157 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003158 wlv.char_attr = hl_combine_attr(
3159 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003160 }
3161 }
3162# endif
3163# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003164 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003165 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003166 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003167 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3168 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003169 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003170 if (!wlv.cul_screenline
3171 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003172 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003173 wlv.char_attr = hl_combine_attr(
3174 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003175 }
3176 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003177 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3178 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003179 }
3180# endif
3181 }
3182#endif
3183 }
3184
3185#ifdef FEAT_CONCEAL
3186 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003187 && (wp != curwin || lnum != wp->w_cursor.lnum
3188 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003189 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3190 && !(lnum_in_visual_area
3191 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3192 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003193 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003194 if (((prev_syntax_id != syntax_seqnr
3195 && (syntax_flags & HL_CONCEAL) != 0)
3196 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003197 && (syn_get_sub_char() != NUL
3198 || (has_match_conc && match_conc)
3199 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003200 && wp->w_p_cole != 3)
3201 {
3202 // First time at this concealed item: display one
3203 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003204 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003205 c = match_conc;
3206 else if (syn_get_sub_char() != NUL)
3207 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003208 else if (wp->w_lcs_chars.conceal != NUL)
3209 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003210 else
3211 c = ' ';
3212
3213 prev_syntax_id = syntax_seqnr;
3214
Bram Moolenaar1306b362022-08-06 15:59:06 +01003215 if (wlv.n_extra > 0)
3216 wlv.vcol_off += wlv.n_extra;
3217 wlv.vcol += wlv.n_extra;
3218 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003219 {
3220# ifdef FEAT_RIGHTLEFT
3221 if (wp->w_p_rl)
3222 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003223 wlv.col -= wlv.n_extra;
3224 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003225 }
3226 else
3227# endif
3228 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003229 wlv.boguscols += wlv.n_extra;
3230 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003231 }
3232 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003233 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003234 n_attr = 0;
3235 }
3236 else if (n_skip == 0)
3237 {
3238 is_concealing = TRUE;
3239 n_skip = 1;
3240 }
3241 mb_c = c;
3242 if (enc_utf8 && utf_char2len(c) > 1)
3243 {
3244 mb_utf8 = TRUE;
3245 u8cc[0] = 0;
3246 c = 0xc0;
3247 }
3248 else
3249 mb_utf8 = FALSE; // don't draw as UTF-8
3250 }
3251 else
3252 {
3253 prev_syntax_id = 0;
3254 is_concealing = FALSE;
3255 }
3256
3257 if (n_skip > 0 && did_decrement_ptr)
3258 // not showing the '>', put pointer back to avoid getting stuck
3259 ++ptr;
3260
3261#endif // FEAT_CONCEAL
3262 }
3263
3264#ifdef FEAT_CONCEAL
3265 // In the cursor line and we may be concealing characters: correct
3266 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003267 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003268 && wp == curwin && lnum == wp->w_cursor.lnum
3269 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003270 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003271 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003272# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003273 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003274 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003275 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003276# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003277 wp->w_wcol = wlv.col - wlv.boguscols;
3278 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003279 did_wcol = TRUE;
3280 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003281# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003282 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003283# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003284 }
3285#endif
3286
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003287 // Use "extra_attr", but don't override visual selection highlighting,
3288 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003289 // Don't use "extra_attr" until n_attr_skip is zero.
3290 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003291 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003292 && (!attr_pri
3293#ifdef FEAT_PROP_POPUP
3294 || (text_prop_flags & PT_FLAG_OVERRIDE)
3295#endif
3296 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003297 {
3298#ifdef LINE_ATTR
3299 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003300 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003301 else
3302#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003303 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003304 }
3305
3306#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3307 // XIM don't send preedit_start and preedit_end, but they send
3308 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3309 // im_is_preediting() here.
3310 if (p_imst == IM_ON_THE_SPOT
3311 && xic != NULL
3312 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003313 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003314 && !p_imdisable
3315 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003316 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003317 {
3318 colnr_T tcol;
3319
3320 if (preedit_end_col == MAXCOL)
3321 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3322 else
3323 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003324 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003325 {
3326 if (feedback_old_attr < 0)
3327 {
3328 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003329 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003330 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003331 wlv.char_attr = im_get_feedback_attr(feedback_col);
3332 if (wlv.char_attr < 0)
3333 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003334 feedback_col++;
3335 }
3336 else if (feedback_old_attr >= 0)
3337 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003338 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003339 feedback_old_attr = -1;
3340 feedback_col = 0;
3341 }
3342 }
3343#endif
3344 // Handle the case where we are in column 0 but not on the first
3345 // character of the line and the user wants us to show us a
3346 // special character (via 'listchars' option "precedes:<char>".
3347 if (lcs_prec_todo != NUL
3348 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003349 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3350 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003351#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003352 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003353#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003354 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003355 && c != NUL)
3356 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003357 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003358 lcs_prec_todo = NUL;
3359 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3360 {
3361 // Double-width character being overwritten by the "precedes"
3362 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003363 wlv.c_extra = MB_FILLER_CHAR;
3364 wlv.c_final = NUL;
3365 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003366 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003367 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003368 }
3369 mb_c = c;
3370 if (enc_utf8 && utf_char2len(c) > 1)
3371 {
3372 mb_utf8 = TRUE;
3373 u8cc[0] = 0;
3374 c = 0xc0;
3375 }
3376 else
3377 mb_utf8 = FALSE; // don't draw as UTF-8
3378 if (!attr_pri)
3379 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003380 saved_attr3 = wlv.char_attr; // save current attr
3381 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003382 n_attr3 = 1;
3383 }
3384 }
3385
3386 // At end of the text line or just after the last character.
3387 if ((c == NUL
3388#if defined(LINE_ATTR)
3389 || did_line_attr == 1
3390#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003391 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003392 {
3393#ifdef FEAT_SEARCH_EXTRA
3394 // flag to indicate whether prevcol equals startcol of search_hl or
3395 // one of the matches
3396 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3397 (long)(ptr - line) - (c == NUL));
3398#endif
3399 // Invert at least one char, used for Visual and empty line or
3400 // highlight match at end of line. If it's beyond the last
3401 // char on the screen, just overwrite that one (tricky!) Not
3402 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003403 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003404 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003405 && (VIsual_mode != Ctrl_V
3406 || lnum == VIsual.lnum
3407 || lnum == curwin->w_cursor.lnum)
3408 && c == NUL)
3409#ifdef FEAT_SEARCH_EXTRA
3410 // highlight 'hlsearch' match at end of line
3411 || (prevcol_hl_flag
3412# ifdef FEAT_SYN_HL
3413 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3414 && !(wp == curwin && VIsual_active))
3415# endif
3416# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003417 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003418# endif
3419# if defined(LINE_ATTR)
3420 && did_line_attr <= 1
3421# endif
3422 )
3423#endif
3424 ))
3425 {
3426 int n = 0;
3427
3428#ifdef FEAT_RIGHTLEFT
3429 if (wp->w_p_rl)
3430 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003431 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003432 n = 1;
3433 }
3434 else
3435#endif
3436 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003437 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003438 n = -1;
3439 }
3440 if (n != 0)
3441 {
3442 // At the window boundary, highlight the last character
3443 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003444 wlv.off += n;
3445 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003446 }
3447 else
3448 {
3449 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003450 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003451 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003452 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003453 }
3454#ifdef FEAT_SEARCH_EXTRA
3455 if (area_attr == 0)
3456 {
3457 // Use attributes from match with highest priority among
3458 // 'search_hl' and the match list.
3459 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003460 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003461 }
3462#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003463 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003464 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003465#ifdef FEAT_RIGHTLEFT
3466 if (wp->w_p_rl)
3467 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003468 --wlv.col;
3469 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003470 }
3471 else
3472#endif
3473 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003474 ++wlv.col;
3475 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003476 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003477 ++wlv.vcol;
3478 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003479 }
3480 }
3481
3482 // At end of the text line.
3483 if (c == NUL)
3484 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003485 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003486
3487 // Update w_cline_height and w_cline_folded if the cursor line was
3488 // updated (saves a call to plines() later).
3489 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3490 {
3491 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003492 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003493#ifdef FEAT_FOLDING
3494 curwin->w_cline_folded = FALSE;
3495#endif
3496 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3497 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003498 break;
3499 }
3500
3501 // Show "extends" character from 'listchars' if beyond the line end and
3502 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003503 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003504 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003505 && wp->w_p_list
3506 && !wp->w_p_wrap
3507#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003508 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003509#endif
3510 && (
3511#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003512 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003513#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003514 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003515 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003516 || lcs_eol_one > 0
3517 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003518 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003519 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003520 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003521 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003522 mb_c = c;
3523 if (enc_utf8 && utf_char2len(c) > 1)
3524 {
3525 mb_utf8 = TRUE;
3526 u8cc[0] = 0;
3527 c = 0xc0;
3528 }
3529 else
3530 mb_utf8 = FALSE;
3531 }
3532
3533#ifdef FEAT_SYN_HL
3534 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003535 if (wlv.draw_color_col)
3536 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003537
3538 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3539 // highlight the cursor position itself.
3540 // Also highlight the 'colorcolumn' if it is different than
3541 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003542 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3543 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003544 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003545 if (((wlv.draw_state == WL_LINE
3546 || wlv.draw_state == WL_BRI
3547 || wlv.draw_state == WL_SBR)
3548 && !lnum_in_visual_area
3549 && search_attr == 0
3550 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003551# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003552 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003553# endif
3554 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003555 {
3556 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3557 && lnum != wp->w_cursor.lnum)
3558 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003559 vcol_save_attr = wlv.char_attr;
3560 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3561 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003562 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003563 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003564 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003565 vcol_save_attr = wlv.char_attr;
3566 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003567 }
3568 }
3569#endif
3570
3571 // Store character to be displayed.
3572 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003573 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003574 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003575 {
3576 // Store the character.
3577#if defined(FEAT_RIGHTLEFT)
3578 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3579 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003580 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003581 --wlv.off;
3582 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003583 }
3584#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003585 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003586 if (enc_dbcs == DBCS_JPNU)
3587 {
3588 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003589 ScreenLines[wlv.off] = 0x8e;
3590 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003591 }
3592 else if (enc_utf8)
3593 {
3594 if (mb_utf8)
3595 {
3596 int i;
3597
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003598 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003599 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003600 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003601 for (i = 0; i < Screen_mco; ++i)
3602 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003603 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003604 if (u8cc[i] == 0)
3605 break;
3606 }
3607 }
3608 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003609 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003610 }
3611 if (multi_attr)
3612 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003613 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003614 multi_attr = 0;
3615 }
3616 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003617 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003618
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003619 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003620
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003621 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3622 {
3623 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003624 ++wlv.off;
3625 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003626 if (enc_utf8)
3627 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003628 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003629 else
3630 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003631 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003632 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003633#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003634 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003635#endif
3636 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003637 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003638 // When "wlv.tocol" is halfway a character, set it to the end
3639 // of the character, otherwise highlighting won't stop.
3640 if (wlv.tocol == wlv.vcol)
3641 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003642
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003643 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003644
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003645#ifdef FEAT_RIGHTLEFT
3646 if (wp->w_p_rl)
3647 {
3648 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003649 --wlv.off;
3650 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003651 }
3652#endif
3653 }
3654#ifdef FEAT_RIGHTLEFT
3655 if (wp->w_p_rl)
3656 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003657 --wlv.off;
3658 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003659 }
3660 else
3661#endif
3662 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003663 ++wlv.off;
3664 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003665 }
3666 }
3667#ifdef FEAT_CONCEAL
3668 else if (wp->w_p_cole > 0 && is_concealing)
3669 {
3670 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003671 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003672 if (wlv.n_extra > 0)
3673 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003674 if (wp->w_p_wrap)
3675 {
3676 // Special voodoo required if 'wrap' is on.
3677 //
3678 // Advance the column indicator to force the line
3679 // drawing to wrap early. This will make the line
3680 // take up the same screen space when parts are concealed,
3681 // so that cursor line computations aren't messed up.
3682 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003683 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003684 // trailing junk to be written out of the screen line
3685 // we are building, 'boguscols' keeps track of the number
3686 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003687 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003688 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003689 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003690# ifdef FEAT_RIGHTLEFT
3691 if (wp->w_p_rl)
3692 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003693 wlv.col -= wlv.n_extra;
3694 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003695 }
3696 else
3697# endif
3698 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003699 wlv.col += wlv.n_extra;
3700 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003701 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003702 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003703 n_attr = 0;
3704 }
3705
3706
3707 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3708 {
3709 // Need to fill two screen columns.
3710# ifdef FEAT_RIGHTLEFT
3711 if (wp->w_p_rl)
3712 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003713 --wlv.boguscols;
3714 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003715 }
3716 else
3717# endif
3718 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003719 ++wlv.boguscols;
3720 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003721 }
3722 }
3723
3724# ifdef FEAT_RIGHTLEFT
3725 if (wp->w_p_rl)
3726 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003727 --wlv.boguscols;
3728 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003729 }
3730 else
3731# endif
3732 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003733 ++wlv.boguscols;
3734 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003735 }
3736 }
3737 else
3738 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003739 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003740 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003741 wlv.vcol += wlv.n_extra;
3742 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003743 n_attr = 0;
3744 }
3745 }
3746
3747 }
3748#endif // FEAT_CONCEAL
3749 else
3750 --n_skip;
3751
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003752 // Only advance the "wlv.vcol" when after the 'number' or
3753 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003754 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003755#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003756 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003757#endif
3758 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003759 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003760
3761#ifdef FEAT_SYN_HL
3762 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003763 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003764#endif
3765
3766 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003767 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3768 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003769
3770 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003771 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003772 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003773 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003774 if (n_attr_skip > 0)
3775 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003776
3777 // At end of screen line and there is more to come: Display the line
3778 // so far. If there is no more to display it is caught above.
3779 if ((
3780#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003781 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003782#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003783 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003784 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003785 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003786#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003787 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003788#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003789#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003790 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003791#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003792 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003793 && wlv.p_extra != at_end_str)
3794 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3795 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003796 )
3797 {
3798#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003799 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003800 wlv_screen_line(wp, &wlv, FALSE);
3801 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003802 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003803#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003804 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003805#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003806 ++wlv.row;
3807 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003808
3809 // When not wrapping and finished diff lines, or when displayed
3810 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01003811 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003812#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003813 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003814#endif
3815#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01003816 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003817#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01003818 ) || lcs_eol_one == -1)
3819#ifdef FEAT_PROP_POPUP
3820 && !text_prop_follows
3821#endif
3822 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003823 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003824#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003825 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003826 {
3827 // do not output more of the line, only the "below" prop
3828 ptr += STRLEN(ptr);
3829# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003830 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003831# endif
3832 }
3833#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003834
3835 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003836 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003837#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003838 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003839#endif
3840 )
3841 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003842 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3843 draw_vsep_win(wp, wlv.row);
3844 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003845 }
3846
3847 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003848 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003849 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003850 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003851 break;
3852 }
3853
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003854 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003855#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003856 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003857#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003858#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003859 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003860#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003861 && wp->w_width == Columns)
3862 {
3863 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003864 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003865
3866 // Special trick to make copy/paste of wrapped lines work with
3867 // xterm/screen: write an extra character beyond the end of
3868 // the line. This will work with all terminal types
3869 // (regardless of the xn,am settings).
3870 // Only do this on a fast tty.
3871 // Only do this if the cursor is on the current line
3872 // (something has been written in it).
3873 // Don't do this for the GUI.
3874 // Don't do this for double-width characters.
3875 // Don't do this for a window not at the right screen border.
3876 if (p_tf
3877#ifdef FEAT_GUI
3878 && !gui.in_use
3879#endif
3880 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003881 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3882 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003883 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003884 || (*mb_off2cells)(
3885 LineOffset[wlv.screen_row - 1]
3886 + (int)Columns - 2,
3887 LineOffset[wlv.screen_row]
3888 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003889 {
3890 // First make sure we are at the end of the screen line,
3891 // then output the same character again to let the
3892 // terminal know about the wrap. If the terminal doesn't
3893 // auto-wrap, we overwrite the character.
3894 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003895 screen_char(LineOffset[wlv.screen_row - 1]
3896 + (unsigned)Columns - 1,
3897 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003898
3899 // When there is a multi-byte character, just output a
3900 // space to keep it simple.
3901 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003902 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003903 out_char(' ');
3904 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003905 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003906 + (Columns - 1)]);
3907 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003908 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003909 screen_start(); // don't know where cursor is now
3910 }
3911 }
3912
Bram Moolenaar1306b362022-08-06 15:59:06 +01003913 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003914
Bram Moolenaareed9d462021-02-15 20:38:25 +01003915 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003916#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003917 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003918# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003919 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003920# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003921 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003922 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003923#endif
3924#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003925 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003926 // When the filler lines are actually below the last line of the
3927 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003928 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003929 break;
3930#endif
3931 }
3932
3933 } // for every character in the line
3934
3935#ifdef FEAT_SPELL
3936 // After an empty line check first word for capital.
3937 if (*skipwhite(line) == NUL)
3938 {
3939 capcol_lnum = lnum + 1;
3940 cap_col = 0;
3941 }
3942#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003943#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003944 vim_free(text_props);
3945 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003946 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003947#endif
3948
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003949 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003950 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003951}