blob: 8824a0121281f998575b10107e8d3ff6ee1fddea [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;
346
Bram Moolenaard7657e92022-09-20 18:59:30 +0100347 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100348 && (wlv->row == wlv->startrow + wlv->filler_lines || !has_cpo_n)
Bram Moolenaar37251162022-10-06 20:48:00 +0100349 // there is no line number in a wrapped line when "n" is in
350 // 'cpoptions', but 'breakindent' assumes it anyway.
351 && !((has_cpo_n
352#ifdef FEAT_LINEBREAK
353 && !wp->w_p_bri
354#endif
355 ) && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100356 {
357#ifdef FEAT_SIGNS
358 // If 'signcolumn' is set to 'number' and a sign is present
359 // in 'lnum', then display the sign instead of the line
360 // number.
361 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
362 get_sign_display_info(TRUE, wp, wlv);
363 else
364#endif
365 {
366 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100367 // When there are text properties above the line put the line number
368 // below them.
369 if (wlv->row == wlv->startrow + wlv->filler_lines
370#ifdef FEAT_PROP_POPUP
371 + wlv->text_prop_above_count
Bram Moolenaard7657e92022-09-20 18:59:30 +0100372#endif
Bram Moolenaareb4de622022-10-15 13:42:17 +0100373 && (wp->w_skipcol == 0 || wlv->row > wp->w_winrow
374 || (wp->w_p_nu && wp->w_p_rnu)))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100375 {
376 long num;
377 char *fmt = "%*ld ";
378
379 if (wp->w_p_nu && !wp->w_p_rnu)
380 // 'number' + 'norelativenumber'
381 num = (long)wlv->lnum;
382 else
383 {
384 // 'relativenumber', don't use negative numbers
385 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
386 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
387 {
388 // 'number' + 'relativenumber'
389 num = wlv->lnum;
390 fmt = "%-*ld ";
391 }
392 }
393
394 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100395 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100396 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
397 ++wlv->p_extra)
398 *wlv->p_extra = '-';
399#ifdef FEAT_RIGHTLEFT
400 if (wp->w_p_rl) // reverse line numbers
401 {
402 char_u *p1, *p2;
403 int t;
404
405 // like rl_mirror(), but keep the space at the end
406 p2 = skipwhite(wlv->extra);
407 p2 = skiptowhite(p2) - 1;
408 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
409 {
410 t = *p1;
411 *p1 = *p2;
412 *p2 = t;
413 }
414 }
415#endif
416 wlv->p_extra = wlv->extra;
417 wlv->c_extra = NUL;
418 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100419 }
420 else
421 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100422 wlv->c_extra = ' ';
423 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100424 }
425 wlv->n_extra = number_width(wp) + 1;
426 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
427#ifdef FEAT_SYN_HL
428 // When 'cursorline' is set highlight the line number of
429 // the current line differently.
430 // When 'cursorlineopt' does not have "line" only
431 // highlight the line number itself.
432 // TODO: Can we use CursorLine instead of CursorLineNr
433 // when CursorLineNr isn't set?
434 if (wp->w_p_cul
435 && wlv->lnum == wp->w_cursor.lnum
436 && (wp->w_p_culopt_flags & CULOPT_NBR)
437 && (wlv->row == wlv->startrow + wlv->filler_lines
438 || (wlv->row > wlv->startrow + wlv->filler_lines
439 && (wp->w_p_culopt_flags & CULOPT_LINE))))
440 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
441#endif
442 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
443 && HL_ATTR(HLF_LNA) != 0)
444 // Use LineNrAbove
445 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
446 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
447 && HL_ATTR(HLF_LNB) != 0)
448 // Use LineNrBelow
449 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
450 }
451#ifdef FEAT_SIGNS
452 if (num_attr)
453 wlv->char_attr = num_attr;
454#endif
455 }
456}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100457
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100458#ifdef FEAT_LINEBREAK
459 static void
460handle_breakindent(win_T *wp, winlinevars_T *wlv)
461{
462 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100463 && *get_showbreak_value(wp) != NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100464 // draw indent after showbreak value
465 wlv->draw_state = WL_BRI;
466 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
467 // After the showbreak, draw the breakindent
468 wlv->draw_state = WL_BRI - 1;
469
470 // draw 'breakindent': indent wrapped text accordingly
471 if (wlv->draw_state == WL_BRI - 1)
472 {
473 wlv->draw_state = WL_BRI;
474 // if wlv->need_showbreak is set, breakindent also applies
475 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
476# ifdef FEAT_DIFF
477 && wlv->filler_lines == 0
478# endif
479# ifdef FEAT_PROP_POPUP
480 && !wlv->dont_use_showbreak
481# endif
482 )
483 {
484 wlv->char_attr = 0;
485# ifdef FEAT_DIFF
486 if (wlv->diff_hlf != (hlf_T)0)
487 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
488# endif
489 wlv->p_extra = NULL;
490 wlv->c_extra = ' ';
491 wlv->c_final = NUL;
492 wlv->n_extra = get_breakindent_win(wp,
493 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
494 if (wlv->row == wlv->startrow)
495 {
496 wlv->n_extra -= win_col_off2(wp);
497 if (wlv->n_extra < 0)
498 wlv->n_extra = 0;
499 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100500 if (wp->w_skipcol > 0 && wlv->startrow == 0
501 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100502 wlv->need_showbreak = FALSE;
503 // Correct end of highlighted area for 'breakindent',
504 // required when 'linebreak' is also set.
505 if (wlv->tocol == wlv->vcol)
506 wlv->tocol += wlv->n_extra;
507 }
508 }
509}
510#endif
511
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100512#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
513 static void
514handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
515{
516# ifdef FEAT_DIFF
517 if (wlv->filler_todo > 0)
518 {
519 // Draw "deleted" diff line(s).
520 if (char2cells(wp->w_fill_chars.diff) > 1)
521 {
522 wlv->c_extra = '-';
523 wlv->c_final = NUL;
524 }
525 else
526 {
527 wlv->c_extra = wp->w_fill_chars.diff;
528 wlv->c_final = NUL;
529 }
530# ifdef FEAT_RIGHTLEFT
531 if (wp->w_p_rl)
532 wlv->n_extra = wlv->col + 1;
533 else
534# endif
535 wlv->n_extra = wp->w_width - wlv->col;
536 wlv->char_attr = HL_ATTR(HLF_DED);
537 }
538# endif
539
540# ifdef FEAT_LINEBREAK
541 char_u *sbr = get_showbreak_value(wp);
542 if (*sbr != NUL && wlv->need_showbreak)
543 {
544 // Draw 'showbreak' at the start of each broken line.
545 wlv->p_extra = sbr;
546 wlv->c_extra = NUL;
547 wlv->c_final = NUL;
548 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100549 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100550 wlv->need_showbreak = FALSE;
551 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
552 // Correct end of highlighted area for 'showbreak',
553 // required when 'linebreak' is also set.
554 if (wlv->tocol == wlv->vcol)
555 wlv->tocol += wlv->n_extra;
556 // combine 'showbreak' with 'wincolor'
557 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
558# ifdef FEAT_SYN_HL
559 // combine 'showbreak' with 'cursorline'
560 if (wlv->cul_attr != 0)
561 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
562# endif
563 }
564# endif
565}
566#endif
567
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100568#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100569/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100570 * Return the cell size of virtual text after truncation.
571 */
572 static int
573textprop_size_after_trunc(
574 win_T *wp,
575 int flags, // TP_FLAG_ALIGN_*
576 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100577 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100578 char_u *text,
579 int *n_used_ptr)
580{
581 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100582 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100583 int len = (int)STRLEN(text);
584 int strsize = 0;
585 int n_used;
586
Bram Moolenaar7e017462022-10-11 21:02:09 +0100587 // if the remaining size is to small and 'wrap' is set we wrap anyway and
588 // use the next line
589 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100590 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100591 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100592 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100593 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
594 {
595 int clen = ptr2cells(text + n_used);
596
597 if (strsize + clen > space)
598 break;
599 strsize += clen;
600 }
601 *n_used_ptr = n_used;
602 return strsize;
603}
604
605/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100606 * Take care of padding, right-align and truncation of virtual text after a
607 * line.
608 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
609 * padding, right-align and truncation. Otherwise only the size is computed.
610 * When "n_attr" is NULL returns the number of screen cells used.
611 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100612 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100613 int
614text_prop_position(
615 win_T *wp,
616 textprop_T *tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100617 int vcol UNUSED, // current text column
618 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100619 int *n_extra, // nr of bytes for virtual text
620 char_u **p_extra, // virtual text
621 int *n_attr, // attribute cells, NULL if not used
622 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200623{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100624 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100625 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100626 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
627 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
628 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
629 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100630 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100631 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100632 int before = room; // spaces before the text
633 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100634 int n_used = *n_extra;
635 char_u *l = NULL;
636 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100637 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100638 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar1206c162022-10-10 15:40:04 +0100639 int cont_on_next_line = below && col_with_padding > win_col_off(wp)
640 && !wp->w_p_wrap;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200641
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100642 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100643 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100644 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100645 int skip_add = 0;
646
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100647 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100648 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100649 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100650 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100651 }
652 else
653 {
654 // Right-align: fill with before
655 if (right)
656 before -= cells;
657 if (before < 0
658 || !(right || below)
659 || (below
Bram Moolenaarccf28372022-10-10 21:10:03 +0100660 ? (col_with_padding <= col_off || !wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100661 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100662 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100663 if (right && (wrap
664 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100665 {
666 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100667 before = wp->w_width - col_off - strsize + room;
668 if (before < 0)
669 before = 0;
670 else
671 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100672 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100673 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100674 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100675 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100676 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100677 else if (below && before > 0)
678 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100679 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100680 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100681
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100682 // With 'nowrap' add one to show the "extends" character if needed (it
683 // doesn't show if the text just fits).
684 if (!wp->w_p_wrap
685 && n_used < *n_extra
686 && wp->w_lcs_chars.ext != NUL
687 && wp->w_p_list)
688 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100689 if (!wp->w_p_wrap && below && padding > 0)
690 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100691
692 // add 1 for NUL, 2 for when '…' is used
693 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100694 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100695 if (n_attr == NULL || l != NULL)
696 {
697 int off = 0;
698
699 if (n_attr != NULL)
700 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100701 vim_memset(l, ' ', before);
702 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100703 if (padding > 0)
704 {
705 vim_memset(l + off, ' ', padding);
706 off += padding;
707 }
708 vim_strncpy(l + off, *p_extra, n_used);
709 off += n_used;
710 }
711 else
712 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100713 off = before + after + padding + n_used;
714 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100715 }
716 if (n_attr != NULL)
717 {
718 if (n_used < *n_extra && wp->w_p_wrap)
719 {
720 char_u *lp = l + off - 1;
721
722 if (has_mbyte)
723 {
724 // change last character to '…'
725 lp -= (*mb_head_off)(l, lp);
726 STRCPY(lp, "…");
Bram Moolenaar13845c42022-10-09 15:26:03 +0100727 n_used = lp - l + 3 - before - padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100728 }
729 else
730 // change last character to '>'
731 *lp = '>';
732 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100733 else if (after > 0)
734 {
735 vim_memset(l + off, ' ', after);
736 l[off + after] = NUL;
737 }
738
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100739 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100740 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100741 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100742 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100743 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100744
745 // Add "skip_add" when starting a new line or wrapping,
746 // n_attr_skip will then be decremented in the number column.
747 *n_attr_skip = before + padding
748 + (cont_on_next_line || before > 0 ? skip_add : 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100749 }
750 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100751 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100752
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100753 if (n_attr == NULL)
754 return cells;
755 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200756}
757#endif
758
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100759/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100760 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100761 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
762 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100763 */
764 static void
765wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
766{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100767 if (wlv->row == 0 && wp->w_skipcol > 0
768#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100769 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100770 && *get_showbreak_value(wp) == NUL
771#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100772 // do not overwrite the 'listchars' "precedes" text with "<<<"
773 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100774 {
775 int off = (int)(current_ScreenLine - ScreenLines);
Bram Moolenaareb4de622022-10-15 13:42:17 +0100776 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100777
Bram Moolenaareb4de622022-10-15 13:42:17 +0100778 if (wp->w_p_nu && wp->w_p_rnu)
779 // Do not overwrite the line number, change "123 text" to
780 // "123>>>xt".
781 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
782 {
783 ++off;
784 ++skip;
785 }
786
787 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100788 {
789 ScreenLines[off] = '<';
790 if (enc_utf8)
791 ScreenLinesUC[off] = 0;
792 ScreenAttrs[off] = HL_ATTR(HLF_AT);
793 ++off;
794 }
795 }
796
797 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
798 negative_width ? -wp->w_width : wp->w_width,
799 wlv->screen_line_flags);
800}
801
802/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100803 * Called when finished with the line: draw the screen line and handle any
804 * highlighting until the right of the window.
805 */
806 static void
807draw_screen_line(win_T *wp, winlinevars_T *wlv)
808{
809#ifdef FEAT_SYN_HL
810 long v;
811
812 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
813 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100814 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100815 else
816 v = wp->w_leftcol;
817
818 // check if line ends before left margin
819 if (wlv->vcol < v + wlv->col - win_col_off(wp))
820 wlv->vcol = v + wlv->col - win_col_off(wp);
821# ifdef FEAT_CONCEAL
822 // Get rid of the boguscols now, we want to draw until the right
823 // edge for 'cursorcolumn'.
824 wlv->col -= wlv->boguscols;
825 wlv->boguscols = 0;
826# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
827# else
828# define VCOL_HLC (wlv->vcol)
829# endif
830
831 if (wlv->draw_color_col)
832 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
833
834 if (((wp->w_p_cuc
835 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
836 && (int)wp->w_virtcol <
837 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
838 && wlv->lnum != wp->w_cursor.lnum)
839 || wlv->draw_color_col
840 || wlv->win_attr != 0)
841# ifdef FEAT_RIGHTLEFT
842 && !wp->w_p_rl
843# endif
844 )
845 {
846 int rightmost_vcol = 0;
847 int i;
848
849 if (wp->w_p_cuc)
850 rightmost_vcol = wp->w_virtcol;
851 if (wlv->draw_color_col)
852 // determine rightmost colorcolumn to possibly draw
853 for (i = 0; wlv->color_cols[i] >= 0; ++i)
854 if (rightmost_vcol < wlv->color_cols[i])
855 rightmost_vcol = wlv->color_cols[i];
856
857 while (wlv->col < wp->w_width)
858 {
859 ScreenLines[wlv->off] = ' ';
860 if (enc_utf8)
861 ScreenLinesUC[wlv->off] = 0;
862 ScreenCols[wlv->off] = MAXCOL;
863 ++wlv->col;
864 if (wlv->draw_color_col)
865 wlv->draw_color_col = advance_color_col(
866 VCOL_HLC, &wlv->color_cols);
867
868 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
869 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
870 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
871 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
872 else
873 ScreenAttrs[wlv->off++] = wlv->win_attr;
874
875 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
876 break;
877
878 ++wlv->vcol;
879 }
880 }
881#endif
882
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100883 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100884 ++wlv->row;
885 ++wlv->screen_row;
886}
887#undef VCOL_HLC
888
889/*
890 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100891 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100892 */
893 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100894win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100895{
896 wlv->col = 0;
897 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
898
899#ifdef FEAT_RIGHTLEFT
900 if (wp->w_p_rl)
901 {
902 // Rightleft window: process the text in the normal direction, but put
903 // it in current_ScreenLine[] from right to left. Start at the
904 // rightmost column of the window.
905 wlv->col = wp->w_width - 1;
906 wlv->off += wlv->col;
907 wlv->screen_line_flags |= SLF_RIGHTLEFT;
908 }
909#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100910 if (save_extra)
911 {
912 // reset the drawing state for the start of a wrapped line
913 wlv->draw_state = WL_START;
914 wlv->saved_n_extra = wlv->n_extra;
915 wlv->saved_p_extra = wlv->p_extra;
916 wlv->saved_c_extra = wlv->c_extra;
917 wlv->saved_c_final = wlv->c_final;
918#ifdef FEAT_SYN_HL
919 if (!(wlv->cul_screenline
920# ifdef FEAT_DIFF
921 && wlv->diff_hlf == (hlf_T)0
922# endif
923 ))
924 wlv->saved_char_attr = wlv->char_attr;
925 else
926#endif
927 wlv->saved_char_attr = 0;
928 wlv->n_extra = 0;
929 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100930}
931
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200932/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100933 * Called when wlv->draw_state is set to WL_LINE.
934 */
935 static void
936win_line_continue(winlinevars_T *wlv)
937{
938 if (wlv->saved_n_extra > 0)
939 {
940 // Continue item from end of wrapped line.
941 wlv->n_extra = wlv->saved_n_extra;
942 wlv->c_extra = wlv->saved_c_extra;
943 wlv->c_final = wlv->saved_c_final;
944 wlv->p_extra = wlv->saved_p_extra;
945 wlv->char_attr = wlv->saved_char_attr;
946 }
947 else
948 wlv->char_attr = wlv->win_attr;
949}
950
951/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200952 * Display line "lnum" of window 'wp' on the screen.
953 * Start at row "startrow", stop when "endrow" is reached.
954 * wp->w_virtcol needs to be valid.
955 *
956 * Return the number of last row the line occupies.
957 */
958 int
959win_line(
960 win_T *wp,
961 linenr_T lnum,
962 int startrow,
963 int endrow,
964 int nochange UNUSED, // not updating for changed text
965 int number_only) // only update the number column
966{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100967 winlinevars_T wlv; // variables passed between functions
968
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200969 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100970 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200971 char_u *line; // current line
972 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200973
Bram Moolenaar1306b362022-08-06 15:59:06 +0100974#ifdef FEAT_PROP_POPUP
975 char_u *p_extra_free2 = NULL; // another p_extra to be freed
976#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200977 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000978#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000979 int in_linebreak = FALSE; // n_extra set for showing linebreak
980#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200981 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100982 // displaying eol at end-of-line
983 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000984 int lcs_prec_todo = wp->w_lcs_chars.prec;
985 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200986
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100987 int n_attr = 0; // chars with special attr
988 int n_attr_skip = 0; // chars to skip before using extra_attr
989 int saved_attr2 = 0; // char_attr saved for n_attr
990 int n_attr3 = 0; // chars with overruling special attr
991 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200992
Bram Moolenaarcd105412022-10-10 19:50:42 +0100993 int n_skip = 0; // nr of cells to skip for 'nowrap' or
994 // concealing
Bram Moolenaard3283fb2022-10-10 20:33:25 +0100995#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +0100996 int skip_cells = 0; // nr of cells to skip for virtual text
997 // after the line, when w_skipcol is
998 // larger than the text length
Bram Moolenaard3283fb2022-10-10 20:33:25 +0100999#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001000
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001001 int fromcol_prev = -2; // start of inverting after cursor
1002 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001003 int lnum_in_visual_area = FALSE;
1004 pos_T pos;
1005 long v;
1006
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001007 int attr_pri = FALSE; // char_attr has priority
1008 int area_highlighting = FALSE; // Visual or incsearch highlighting
1009 // in this line
1010 int vi_attr = 0; // attributes for Visual and incsearch
1011 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001012 int area_attr = 0; // attributes desired by highlighting
1013 int search_attr = 0; // attributes desired by 'hlsearch'
1014#ifdef FEAT_SYN_HL
1015 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1016 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001017 int prev_syntax_col = -1; // column of prev_syntax_attr
1018 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001019 int has_syntax = FALSE; // this buffer has syntax highl.
1020 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001021#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001022#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001023 int text_prop_count;
1024 int text_prop_next = 0; // next text property to use
1025 textprop_T *text_props = NULL;
1026 int *text_prop_idxs = NULL;
1027 int text_props_active = 0;
1028 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001029 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001030 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001031 int text_prop_attr_comb = 0; // text_prop_attr combined with
1032 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001033 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001034 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001035 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001036 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001037 int saved_search_attr = 0; // search_attr to be used when n_extra
1038 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001039 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001040#endif
1041#ifdef FEAT_SPELL
1042 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001043 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001044# define SPWORDLEN 150
1045 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1046 int nextlinecol = 0; // column where nextline[] starts
1047 int nextline_idx = 0; // index in nextline[] where next line
1048 // starts
1049 int spell_attr = 0; // attributes desired by spelling
1050 int word_end = 0; // last byte with same spell_attr
1051 static linenr_T checked_lnum = 0; // line number for "checked_col"
1052 static int checked_col = 0; // column in "checked_lnum" up to which
1053 // there are no spell errors
1054 static int cap_col = -1; // column to check for Cap word
1055 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1056 int cur_checked_col = 0; // checked column for current line
1057#endif
1058 int extra_check = 0; // has extra highlighting
1059 int multi_attr = 0; // attributes desired by multibyte
1060 int mb_l = 1; // multi-byte byte length
1061 int mb_c = 0; // decoded multi-byte character
1062 int mb_utf8 = FALSE; // screen char is UTF-8 char
1063 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001064#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001065 int change_start = MAXCOL; // first col of changed area
1066 int change_end = -1; // last col of changed area
1067#endif
1068 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001069 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001070 int in_multispace = FALSE; // in multiple consecutive spaces
1071 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001072#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
1073 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
1074# define LINE_ATTR
1075 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +01001076 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001077#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001078 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001079 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001080#ifdef FEAT_ARABIC
1081 int prev_c = 0; // previous Arabic character
1082 int prev_c1 = 0; // first composing char for prev_c
1083#endif
1084#if defined(LINE_ATTR)
1085 int did_line_attr = 0;
1086#endif
1087#ifdef FEAT_TERMINAL
1088 int get_term_attr = FALSE;
1089#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001090
Martin Tournoijba43e762022-10-13 22:12:15 +01001091#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001092 // margin columns for the screen line, needed for when 'cursorlineopt'
1093 // contains "screenline"
1094 int left_curline_col = 0;
1095 int right_curline_col = 0;
1096#endif
1097
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001098#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1099 int feedback_col = 0;
1100 int feedback_old_attr = -1;
1101#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001102
1103#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1104 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001105#endif
1106#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001107 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001108#endif
1109#ifdef FEAT_CONCEAL
1110 int syntax_flags = 0;
1111 int syntax_seqnr = 0;
1112 int prev_syntax_id = 0;
1113 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1114 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001115 int did_wcol = FALSE;
1116 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001117# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001118# define FIX_FOR_BOGUSCOLS \
1119 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001120 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001121 wlv.vcol -= wlv.vcol_off; \
1122 wlv.vcol_off = 0; \
1123 wlv.col -= wlv.boguscols; \
1124 old_boguscols = wlv.boguscols; \
1125 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001126 }
1127#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001128# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001129#endif
1130
1131 if (startrow > endrow) // past the end already!
1132 return startrow;
1133
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001134 CLEAR_FIELD(wlv);
1135
1136 wlv.lnum = lnum;
1137 wlv.startrow = startrow;
1138 wlv.row = startrow;
1139 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001140 wlv.fromcol = -10;
1141 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001142#ifdef FEAT_LINEBREAK
1143 wlv.vcol_sbr = -1;
1144#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001145
1146 if (!number_only)
1147 {
1148 // To speed up the loop below, set extra_check when there is linebreak,
1149 // trailing white space and/or syntax processing to be done.
1150#ifdef FEAT_LINEBREAK
1151 extra_check = wp->w_p_lbr;
1152#endif
1153#ifdef FEAT_SYN_HL
1154 if (syntax_present(wp) && !wp->w_s->b_syn_error
1155# ifdef SYN_TIME_LIMIT
1156 && !wp->w_s->b_syn_slow
1157# endif
1158 )
1159 {
1160 // Prepare for syntax highlighting in this line. When there is an
1161 // error, stop syntax highlighting.
1162 save_did_emsg = did_emsg;
1163 did_emsg = FALSE;
1164 syntax_start(wp, lnum);
1165 if (did_emsg)
1166 wp->w_s->b_syn_error = TRUE;
1167 else
1168 {
1169 did_emsg = save_did_emsg;
1170#ifdef SYN_TIME_LIMIT
1171 if (!wp->w_s->b_syn_slow)
1172#endif
1173 {
1174 has_syntax = TRUE;
1175 extra_check = TRUE;
1176 }
1177 }
1178 }
1179
1180 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001181 wlv.color_cols = wp->w_p_cc_cols;
1182 if (wlv.color_cols != NULL)
1183 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001184#endif
1185
1186#ifdef FEAT_TERMINAL
1187 if (term_show_buffer(wp->w_buffer))
1188 {
1189 extra_check = TRUE;
1190 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001191 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001192 }
1193#endif
1194
1195#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001196 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001197 {
1198 // Prepare for spell checking.
1199 has_spell = TRUE;
1200 extra_check = TRUE;
1201
1202 // Get the start of the next line, so that words that wrap to the
1203 // next line are found too: "et<line-break>al.".
1204 // Trick: skip a few chars for C/shell/Vim comments
1205 nextline[SPWORDLEN] = NUL;
1206 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1207 {
1208 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1209 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1210 }
1211
1212 // When a word wrapped from the previous line the start of the
1213 // current line is valid.
1214 if (lnum == checked_lnum)
1215 cur_checked_col = checked_col;
1216 checked_lnum = 0;
1217
1218 // When there was a sentence end in the previous line may require a
1219 // word starting with capital in this line. In line 1 always check
1220 // the first word.
1221 if (lnum != capcol_lnum)
1222 cap_col = -1;
1223 if (lnum == 1)
1224 cap_col = 0;
1225 capcol_lnum = 0;
1226 }
1227#endif
1228
1229 // handle Visual active in this window
1230 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1231 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001232 pos_T *top, *bot;
1233
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001234 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1235 {
1236 // Visual is after curwin->w_cursor
1237 top = &curwin->w_cursor;
1238 bot = &VIsual;
1239 }
1240 else
1241 {
1242 // Visual is before curwin->w_cursor
1243 top = &VIsual;
1244 bot = &curwin->w_cursor;
1245 }
1246 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1247 if (VIsual_mode == Ctrl_V)
1248 {
1249 // block mode
1250 if (lnum_in_visual_area)
1251 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001252 wlv.fromcol = wp->w_old_cursor_fcol;
1253 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001254 }
1255 }
1256 else
1257 {
1258 // non-block mode
1259 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001260 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001261 else if (lnum == top->lnum)
1262 {
1263 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001264 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001265 else
1266 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001267 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001268 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001269 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001270 }
1271 }
1272 if (VIsual_mode != 'V' && lnum == bot->lnum)
1273 {
1274 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1275 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001276 wlv.fromcol = -10;
1277 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001278 }
1279 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001280 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001281 else
1282 {
1283 pos = *bot;
1284 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001285 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1286 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001287 else
1288 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001289 getvvcol(wp, &pos, NULL, NULL,
1290 (colnr_T *)&wlv.tocol);
1291 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001292 }
1293 }
1294 }
1295 }
1296
1297 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001298 if (!highlight_match && lnum == curwin->w_cursor.lnum
1299 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001300#ifdef FEAT_GUI
1301 && !gui.in_use
1302#endif
1303 )
1304 noinvcur = TRUE;
1305
1306 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001307 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001308 {
1309 area_highlighting = TRUE;
1310 vi_attr = HL_ATTR(HLF_V);
1311#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1312 if ((clip_star.available && !clip_star.owned
1313 && clip_isautosel_star())
1314 || (clip_plus.available && !clip_plus.owned
1315 && clip_isautosel_plus()))
1316 vi_attr = HL_ATTR(HLF_VNC);
1317#endif
1318 }
1319 }
1320
1321 // handle 'incsearch' and ":s///c" highlighting
1322 else if (highlight_match
1323 && wp == curwin
1324 && lnum >= curwin->w_cursor.lnum
1325 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1326 {
1327 if (lnum == curwin->w_cursor.lnum)
1328 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001329 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001330 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001331 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001332 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1333 {
1334 pos.lnum = lnum;
1335 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001336 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001337 }
1338 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001339 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001340 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001341 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1342 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001343 area_highlighting = TRUE;
1344 vi_attr = HL_ATTR(HLF_I);
1345 }
1346 }
1347
1348#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001349 wlv.filler_lines = diff_check(wp, lnum);
1350 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001351 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001352 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001353 {
1354 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001355 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001356 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001357 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001358 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001359 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001360 }
1361 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001362 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001363 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001364 area_highlighting = TRUE;
1365 }
1366 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001367 wlv.filler_lines = wp->w_topfill;
1368 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001369#endif
1370
1371#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001372 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001373 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001374 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001375#endif
1376
1377#ifdef LINE_ATTR
1378# ifdef FEAT_SIGNS
1379 // If this line has a sign with line highlighting set line_attr.
1380 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001381 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001382# endif
1383# if defined(FEAT_QUICKFIX)
1384 // Highlight the current line in the quickfix window.
1385 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1386 line_attr = HL_ATTR(HLF_QFL);
1387# endif
1388 if (line_attr != 0)
1389 area_highlighting = TRUE;
1390#endif
1391
1392 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1393 ptr = line;
1394
1395#ifdef FEAT_SPELL
1396 if (has_spell && !number_only)
1397 {
1398 // For checking first word with a capital skip white space.
1399 if (cap_col == 0)
1400 cap_col = getwhitecols(line);
1401
1402 // To be able to spell-check over line boundaries copy the end of the
1403 // current line into nextline[]. Above the start of the next line was
1404 // copied to nextline[SPWORDLEN].
1405 if (nextline[SPWORDLEN] == NUL)
1406 {
1407 // No next line or it is empty.
1408 nextlinecol = MAXCOL;
1409 nextline_idx = 0;
1410 }
1411 else
1412 {
1413 v = (long)STRLEN(line);
1414 if (v < SPWORDLEN)
1415 {
1416 // Short line, use it completely and append the start of the
1417 // next line.
1418 nextlinecol = 0;
1419 mch_memmove(nextline, line, (size_t)v);
1420 STRMOVE(nextline + v, nextline + SPWORDLEN);
1421 nextline_idx = v + 1;
1422 }
1423 else
1424 {
1425 // Long line, use only the last SPWORDLEN bytes.
1426 nextlinecol = v - SPWORDLEN;
1427 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1428 nextline_idx = SPWORDLEN + 1;
1429 }
1430 }
1431 }
1432#endif
1433
1434 if (wp->w_p_list)
1435 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001436 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001437 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001438 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001439 || wp->w_lcs_chars.trail
1440 || wp->w_lcs_chars.lead
1441 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001442 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001443
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001444 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001445 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001446 {
1447 trailcol = (colnr_T)STRLEN(ptr);
1448 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1449 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001450 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001451 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001452 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001453 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001454 {
1455 leadcol = 0;
1456 while (VIM_ISWHITE(ptr[leadcol]))
1457 ++leadcol;
1458 if (ptr[leadcol] == NUL)
1459 // in a line full of spaces all of them are treated as trailing
1460 leadcol = (colnr_T)0;
1461 else
1462 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001463 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001464 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001465 }
1466
Bram Moolenaard7657e92022-09-20 18:59:30 +01001467 wlv.wcr_attr = get_wcr_attr(wp);
1468 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001469 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001470 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001471 area_highlighting = TRUE;
1472 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001473
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001474#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001475 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001476 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001477#endif
1478
1479 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1480 // first character to be displayed.
1481 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001482 v = startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001483 else
1484 v = wp->w_leftcol;
1485 if (v > 0 && !number_only)
1486 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001487 char_u *prev_ptr = ptr;
1488 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001489 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001490
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001491 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001492 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001493 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001494 charsize = win_lbr_chartabsize(&cts, NULL);
1495 cts.cts_vcol += charsize;
1496 prev_ptr = cts.cts_ptr;
1497 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001498 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001499 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001500 ptr = cts.cts_ptr;
1501 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001502
1503 // When:
1504 // - 'cuc' is set, or
1505 // - 'colorcolumn' is set, or
1506 // - 'virtualedit' is set, or
1507 // - the visual mode is active,
1508 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001509 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001510#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001511 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001512#endif
1513 virtual_active() ||
1514 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001515 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001516
1517 // Handle a character that's not completely on the screen: Put ptr at
1518 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001519 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001520 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001521 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001522 ptr = prev_ptr;
1523 // If the character fits on the screen, don't need to skip it.
1524 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001525 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1526 && wlv.col == 0)
1527 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001528 }
1529
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001530#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001531 // If there the text doesn't reach to the desired column, need to skip
1532 // "skip_cells" cells when virtual text follows.
1533 if (!wp->w_p_wrap && v > wlv.vcol)
1534 skip_cells = v - wlv.vcol;
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001535#endif
Bram Moolenaarcd105412022-10-10 19:50:42 +01001536
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001537 // Adjust for when the inverted text is before the screen,
1538 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001539 if (wlv.tocol <= wlv.vcol)
1540 wlv.fromcol = 0;
1541 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1542 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001543
1544#ifdef FEAT_LINEBREAK
1545 // When w_skipcol is non-zero, first line needs 'showbreak'
1546 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001547 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001548#endif
1549#ifdef FEAT_SPELL
1550 // When spell checking a word we need to figure out the start of the
1551 // word and if it's badly spelled or not.
1552 if (has_spell)
1553 {
1554 int len;
1555 colnr_T linecol = (colnr_T)(ptr - line);
1556 hlf_T spell_hlf = HLF_COUNT;
1557
1558 pos = wp->w_cursor;
1559 wp->w_cursor.lnum = lnum;
1560 wp->w_cursor.col = linecol;
1561 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1562
1563 // spell_move_to() may call ml_get() and make "line" invalid
1564 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1565 ptr = line + linecol;
1566
1567 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1568 {
1569 // no bad word found at line start, don't check until end of a
1570 // word
1571 spell_hlf = HLF_COUNT;
1572 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1573 }
1574 else
1575 {
1576 // bad word found, use attributes until end of word
1577 word_end = wp->w_cursor.col + len + 1;
1578
1579 // Turn index into actual attributes.
1580 if (spell_hlf != HLF_COUNT)
1581 spell_attr = highlight_attr[spell_hlf];
1582 }
1583 wp->w_cursor = pos;
1584
1585# ifdef FEAT_SYN_HL
1586 // Need to restart syntax highlighting for this line.
1587 if (has_syntax)
1588 syntax_start(wp, lnum);
1589# endif
1590 }
1591#endif
1592 }
1593
1594 // Correct highlighting for cursor that can't be disabled.
1595 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001596 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001597 {
1598 if (noinvcur)
1599 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001600 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001601 {
1602 // highlighting starts at cursor, let it start just after the
1603 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001604 fromcol_prev = wlv.fromcol;
1605 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001606 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001607 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001608 // restart highlighting after the cursor
1609 fromcol_prev = wp->w_virtcol;
1610 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001611 if (wlv.fromcol >= wlv.tocol)
1612 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001613 }
1614
1615#ifdef FEAT_SEARCH_EXTRA
1616 if (!number_only)
1617 {
1618 v = (long)(ptr - line);
1619 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1620 &line, &screen_search_hl,
1621 &search_attr);
1622 ptr = line + v; // "line" may have been updated
1623 }
1624#endif
1625
1626#ifdef FEAT_SYN_HL
1627 // Cursor line highlighting for 'cursorline' in the current window.
1628 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1629 {
1630 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001631 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001632 if (!(wp == curwin && VIsual_active)
1633 && wp->w_p_culopt_flags != CULOPT_NBR)
1634 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001635 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001636 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1637
1638 // Only set line_attr here when "screenline" is not present in
1639 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001640 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001641 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001642 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001643# ifdef FEAT_SIGNS
1644 // Combine the 'cursorline' and sign highlighting, depending on
1645 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001646 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001647 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001648 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001649 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001650 else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001651 line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001652 }
1653 else
1654# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001655# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001656 // let the line attribute overrule 'cursorline', otherwise
1657 // it disappears when both have background set;
1658 // 'cursorline' can use underline or bold to make it show
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001659 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001660# else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001661 line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001662# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001663 }
1664 else
1665 {
1666 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001667 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1668 }
1669 area_highlighting = TRUE;
1670 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001671 }
1672#endif
1673
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001674#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001675 {
1676 char_u *prop_start;
1677
1678 text_prop_count = get_text_props(wp->w_buffer, lnum,
1679 &prop_start, FALSE);
1680 if (text_prop_count > 0)
1681 {
1682 // Make a copy of the properties, so that they are properly
1683 // aligned.
1684 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1685 if (text_props != NULL)
1686 mch_memmove(text_props, prop_start,
1687 text_prop_count * sizeof(textprop_T));
1688
1689 // Allocate an array for the indexes.
1690 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001691 if (text_prop_idxs == NULL)
1692 VIM_CLEAR(text_props);
1693
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001694 if (text_props != NULL)
1695 {
1696 area_highlighting = TRUE;
1697 extra_check = TRUE;
1698 for (int i = 0; i < text_prop_count; ++i)
1699 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1700 ++wlv.text_prop_above_count;
1701 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001702 }
1703 }
1704#endif
1705
Bram Moolenaar1306b362022-08-06 15:59:06 +01001706 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001707
1708 // Repeat for the whole displayed line.
1709 for (;;)
1710 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001711 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001712#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001713 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001714#endif
1715#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001716 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001717#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001718
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001719 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001720 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001721 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001722#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001723 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001724 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001725 wlv.cul_attr = 0;
zeertzjq4f33bc22021-08-05 17:57:02 +02001726 line_attr = line_attr_save;
1727 }
1728#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001729 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001730 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001731 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001732 if (cmdwin_type != 0 && wp == curwin)
1733 {
1734 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001735 wlv.n_extra = 1;
1736 wlv.c_extra = cmdwin_type;
1737 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001738 wlv.char_attr =
1739 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001740 }
1741 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001742#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001743 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001744 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001745 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001746 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001747 }
1748#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001749#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001750 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001751 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001752 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001753 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001754 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001755 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001756 }
1757#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001758 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001759 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001760 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001761 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001762 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001763 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001764#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001765 // Check if 'breakindent' applies and show it.
1766 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1767 if (wlv.n_extra == 0)
1768 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001769#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001770#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001771 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001772 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001773 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001774 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001775 }
1776#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001777 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001778 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001779 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001780 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001781 }
1782 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001783
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001784#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001785 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001786 && wlv.vcol >= left_curline_col
1787 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001788 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001789 wlv.cul_attr = HL_ATTR(HLF_CUL);
1790 line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001791 }
1792#endif
1793
1794 // When still displaying '$' of change command, stop at cursor.
1795 // When only displaying the (relative) line number and that's done,
1796 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001797 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001798 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001799 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001800#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001801 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001802#endif
1803 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001804 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001805 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001806 // Pretend we have finished updating the window. Except when
1807 // 'cursorcolumn' is set.
1808#ifdef FEAT_SYN_HL
1809 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001810 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001811 else
1812#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001813 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001814 break;
1815 }
1816
Bram Moolenaar1306b362022-08-06 15:59:06 +01001817 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001818 {
1819 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001820 if (wlv.vcol == wlv.fromcol
1821 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1822 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001823 && (*mb_ptr2cells)(ptr) > 1)
1824 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001825 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001826 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001827 area_attr = vi_attr; // start highlighting
1828 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001829 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001830 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001831 area_attr = 0; // stop highlighting
1832
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001833#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001834 if (text_props != NULL)
1835 {
1836 int pi;
1837 int bcol = (int)(ptr - line);
1838
Bram Moolenaar1306b362022-08-06 15:59:06 +01001839 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001840# ifdef FEAT_LINEBREAK
1841 && !in_linebreak
1842# endif
1843 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001844 --bcol; // still working on the previous char, e.g. Tab
1845
1846 // Check if any active property ends.
1847 for (pi = 0; pi < text_props_active; ++pi)
1848 {
1849 int tpi = text_prop_idxs[pi];
1850
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001851 if (text_props[tpi].tp_col != MAXCOL
1852 && bcol >= text_props[tpi].tp_col - 1
1853 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001854 {
1855 if (pi + 1 < text_props_active)
1856 mch_memmove(text_prop_idxs + pi,
1857 text_prop_idxs + pi + 1,
1858 sizeof(int)
1859 * (text_props_active - (pi + 1)));
1860 --text_props_active;
1861 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001862# ifdef FEAT_LINEBREAK
1863 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001864 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001865 syntax_attr = 0;
1866# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001867 }
1868 }
1869
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001870# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001871 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001872 // not on the next char yet, don't start another prop
1873 --bcol;
1874# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001875 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001876 // With 'nowrap' and not in the first screen line only "below"
1877 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001878 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001879 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001880 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001881 && (wp->w_p_wrap
1882 || wlv.row == startrow
1883 || (text_props[text_prop_next].tp_flags
1884 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001885 || (bcol == 0 &&
1886 (text_props[text_prop_next].tp_flags
1887 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001888 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001889 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001890 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001891 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1892 {
1893 // first display the '$' after the line
1894 text_prop_follows = TRUE;
1895 break;
1896 }
1897 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001898 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001899 + text_props[text_prop_next].tp_len)
1900 text_prop_idxs[text_props_active++] = text_prop_next;
1901 ++text_prop_next;
1902 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001903
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001904 if (wlv.n_extra == 0 || !extra_for_textprop)
1905 {
1906 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001907 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001908 text_prop_flags = 0;
1909 text_prop_type = NULL;
1910 text_prop_id = 0;
1911 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001912 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001913 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001914 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001915 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001916 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001917
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001918 // Sort the properties on priority and/or starting last.
1919 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001920 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001921 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001922 sort_text_props(wp->w_buffer, text_props,
1923 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001924
1925 for (pi = 0; pi < text_props_active; ++pi)
1926 {
1927 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001928 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001929 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01001930 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001931
Bram Moolenaarcd105412022-10-10 19:50:42 +01001932 // Only use a text property that can be displayed.
1933 // Skip "after" properties when wrap is off and at the
1934 // end of the window.
1935 if (pt != NULL
1936 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
1937 && tp->tp_id != -MAXCOL
1938 && !(tp->tp_id < 0
1939 && !wp->w_p_wrap
1940 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
1941 | TP_FLAG_ALIGN_ABOVE
1942 | TP_FLAG_ALIGN_BELOW)) == 0
1943 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001944 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001945 if (pt->pt_hl_id > 0)
1946 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001947 text_prop_type = pt;
1948 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001949 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001950 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001951 text_prop_flags = pt->pt_flags;
1952 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001953 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001954 }
1955 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001956 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001957 && -text_prop_id
1958 <= wp->w_buffer->b_textprop_text.ga_len)
1959 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001960 textprop_T *tp = &text_props[used_tpi];
1961 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001962 ->b_textprop_text.ga_data)[
1963 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001964 int above = (tp->tp_flags
1965 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01001966 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001967
1968 // reset the ID in the copy to avoid it being used
1969 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001970 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001971
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001972 if (p != NULL)
1973 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001974 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001975 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001976 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001977 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001978 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1979 int padding = tp->tp_col == MAXCOL
1980 && tp->tp_len > 1
1981 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001982
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001983 // Insert virtual text before the current
1984 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001985 wlv.p_extra = p;
1986 wlv.c_extra = NUL;
1987 wlv.c_final = NUL;
1988 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001989 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001990 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001991 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001992 // restore search_attr and area_attr when n_extra
1993 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001994 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001995 saved_area_attr = area_attr;
1996 search_attr = 0;
1997 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001998 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001999 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002000 if (*ptr == NUL)
2001 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002002 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002003#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002004 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002005 {
2006 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002007 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002008 wlv.need_showbreak = FALSE;
2009 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002010 }
2011#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002012 if ((right || above || below || !wrap
2013 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002014 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002015 char_u *prev_p_extra = wlv.p_extra;
2016 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002017
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002018 // Take care of padding, right-align and
2019 // truncation.
2020 // Shared with win_lbr_chartabsize(), must do
2021 // exactly the same.
2022 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002023 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002024 wlv.col,
2025 &wlv.n_extra, &wlv.p_extra,
2026 &n_attr, &n_attr_skip);
2027 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002028 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002029 // wlv.p_extra was allocated
2030 vim_free(p_extra_free2);
2031 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002032 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002033
Bram Moolenaara4abe512022-09-15 19:44:09 +01002034 if (lcs_eol_one < 0 && wlv.col
2035 + wlv.n_extra - 2 > wp->w_width)
2036 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002037 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002038
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002039 // When 'wrap' is off then for "below" we need
2040 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002041 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002042 {
2043 draw_screen_line(wp, &wlv);
2044
2045 // When line got too long for screen break
2046 // here.
2047 if (wlv.row == endrow)
2048 {
2049 ++wlv.row;
2050 break;
2051 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002052 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002053 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002054 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002055 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002056 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002057
Bram Moolenaarcd105412022-10-10 19:50:42 +01002058 // If the text didn't reach until the first window
2059 // column we need to skip cells.
2060 if (skip_cells > 0)
2061 {
2062 if (wlv.n_extra > skip_cells)
2063 {
2064 wlv.n_extra -= skip_cells;
2065 wlv.p_extra += skip_cells;
2066 n_attr_skip -= skip_cells;
2067 if (n_attr_skip < 0)
2068 n_attr_skip = 0;
2069 skip_cells = 0;
2070 }
2071 else
2072 {
2073 // the whole text is left of the window, drop
2074 // it and advance to the next one
2075 skip_cells -= wlv.n_extra;
2076 wlv.n_extra = 0;
2077 n_attr_skip = 0;
2078 bail_out = TRUE;
2079 }
2080 }
2081
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002082 // If another text prop follows the condition below at
2083 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002084 // If this is an "above" text prop and 'nowrap' the we
2085 // must wrap anyway.
2086 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002087 text_prop_follows |= other_tpi != -1
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002088 && (wp->w_p_wrap
2089 || (text_props[other_tpi].tp_flags
2090 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002091
2092 if (bail_out)
2093 // starting a new line for "below"
2094 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002095 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002096 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002097 else if (text_prop_next < text_prop_count
2098 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002099 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2100 || (!wp->w_p_wrap
2101 && wlv.col == wp->w_width - 1
2102 && (text_props[text_prop_next].tp_flags
2103 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002104 // When at last-but-one character and a text property
2105 // follows after it, we may need to flush the line after
2106 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002107 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002108 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002109 }
2110#endif
2111
Bram Moolenaare38fc862022-08-11 17:24:50 +01002112#ifdef FEAT_SEARCH_EXTRA
2113 if (wlv.n_extra == 0)
2114 {
2115 // Check for start/end of 'hlsearch' and other matches.
2116 // After end, check for start/end of next match.
2117 // When another match, have to check for start again.
2118 v = (long)(ptr - line);
2119 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2120 &screen_search_hl, &has_match_conc,
2121 &match_conc, did_line_attr, lcs_eol_one,
2122 &on_last_col);
2123 ptr = line + v; // "line" may have been changed
2124 prev_ptr = ptr;
2125
2126 // Do not allow a conceal over EOL otherwise EOL will be missed
2127 // and bad things happen.
2128 if (*ptr == NUL)
2129 has_match_conc = 0;
2130 }
2131#endif
2132
2133#ifdef FEAT_DIFF
2134 if (wlv.diff_hlf != (hlf_T)0)
2135 {
2136 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2137 && wlv.n_extra == 0)
2138 wlv.diff_hlf = HLF_TXD; // changed text
2139 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2140 && wlv.n_extra == 0)
2141 wlv.diff_hlf = HLF_CHD; // changed line
2142 line_attr = HL_ATTR(wlv.diff_hlf);
2143 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2144 && wp->w_p_culopt_flags != CULOPT_NBR
2145 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2146 && wlv.vcol <= right_curline_col)))
2147 line_attr = hl_combine_attr(
2148 line_attr, HL_ATTR(HLF_CUL));
2149 }
2150#endif
2151
Bram Moolenaara74fda62019-10-19 17:38:03 +02002152#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002153 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002154 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002155 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002156# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002157 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002158 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002159# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002160 // Get syntax attribute.
2161 if (has_syntax)
2162 {
2163 // Get the syntax attribute for the character. If there
2164 // is an error, disable syntax highlighting.
2165 save_did_emsg = did_emsg;
2166 did_emsg = FALSE;
2167
2168 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002169 if (v == prev_syntax_col)
2170 // at same column again
2171 syntax_attr = prev_syntax_attr;
2172 else
2173 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002174# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002175 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002176# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002177 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002178# ifdef FEAT_SPELL
2179 has_spell ? &can_spell :
2180# endif
2181 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002182 prev_syntax_col = v;
2183 prev_syntax_attr = syntax_attr;
2184 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002185
Bram Moolenaar34390282019-10-16 14:38:26 +02002186 if (did_emsg)
2187 {
2188 wp->w_s->b_syn_error = TRUE;
2189 has_syntax = FALSE;
2190 syntax_attr = 0;
2191 }
2192 else
2193 did_emsg = save_did_emsg;
2194# ifdef SYN_TIME_LIMIT
2195 if (wp->w_s->b_syn_slow)
2196 has_syntax = FALSE;
2197# endif
2198
2199 // Need to get the line again, a multi-line regexp may
2200 // have made it invalid.
2201 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2202 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002203 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002204# ifdef FEAT_CONCEAL
2205 // no concealing past the end of the line, it interferes
2206 // with line highlighting
2207 if (*ptr == NUL)
2208 syntax_flags = 0;
2209 else
2210 syntax_flags = get_syntax_info(&syntax_seqnr);
2211# endif
2212 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002213 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002214# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002215 // Combine text property highlight into syntax highlight.
2216 if (text_prop_type != NULL)
2217 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002218 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002219 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2220 else
2221 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002222 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002223 }
2224# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002225#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002226
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002227 // Decide which of the highlight attributes to use.
2228 attr_pri = TRUE;
2229#ifdef LINE_ATTR
2230 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002231 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002232 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002233 if (!highlight_match)
2234 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002235 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002236# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002237 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002238# endif
2239 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002240 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002241 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002242 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002243# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002244 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002245# endif
2246 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002247 else if (line_attr != 0
2248 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2249 || wlv.vcol < wlv.fromcol
2250 || vcol_prev < fromcol_prev
2251 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002252 {
2253 // Use line_attr when not in the Visual or 'incsearch' area
2254 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002255# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002256 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002257# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002258 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002259# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002260 attr_pri = FALSE;
2261 }
2262#else
2263 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002264 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002265 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002266 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002267#endif
2268 else
2269 {
2270 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002271#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002272 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002273#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002274 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002275#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002276 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002277#ifdef FEAT_PROP_POPUP
2278 // override with text property highlight when "override" is TRUE
2279 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002280 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002281#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002282 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002283
2284 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002285 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002286 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002287 if (wlv.char_attr == 0)
2288 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002289 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002290 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002291 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002292
2293 // Get the next character to put on the screen.
2294
2295 // The "p_extra" points to the extra stuff that is inserted to
2296 // represent special characters (non-printable stuff) and other
2297 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002298 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002299 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2300 // "p_extra[n_extra]".
2301 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002302 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002303 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002304 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002305 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002306 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2307 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002308 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2309 if (enc_utf8 && utf_char2len(c) > 1)
2310 {
2311 mb_utf8 = TRUE;
2312 u8cc[0] = 0;
2313 c = 0xc0;
2314 }
2315 else
2316 mb_utf8 = FALSE;
2317 }
2318 else
2319 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002320 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002321 if (has_mbyte)
2322 {
2323 mb_c = c;
2324 if (enc_utf8)
2325 {
2326 // If the UTF-8 character is more than one byte:
2327 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002328 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002329 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002330 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002331 mb_l = 1;
2332 else if (mb_l > 1)
2333 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002334 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002335 mb_utf8 = TRUE;
2336 c = 0xc0;
2337 }
2338 }
2339 else
2340 {
2341 // if this is a DBCS character, put it in "mb_c"
2342 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002343 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002344 mb_l = 1;
2345 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002346 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002347 }
2348 if (mb_l == 0) // at the NUL at end-of-line
2349 mb_l = 1;
2350
2351 // If a double-width char doesn't fit display a '>' in the
2352 // last column.
2353 if ((
2354# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002355 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002356# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002357 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002358 && (*mb_char2cells)(mb_c) == 2)
2359 {
2360 c = '>';
2361 mb_c = c;
2362 mb_l = 1;
2363 mb_utf8 = FALSE;
2364 multi_attr = HL_ATTR(HLF_AT);
2365#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002366 if (wlv.cul_attr)
2367 multi_attr = hl_combine_attr(
2368 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002369#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002370 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002371
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002372 // put the pointer back to output the double-width
2373 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002374 ++wlv.n_extra;
2375 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002376 }
2377 else
2378 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002379 wlv.n_extra -= mb_l - 1;
2380 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002381 }
2382 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002383 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002384 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002385 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002386#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002387 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002388 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002389 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002390 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002391 if (search_attr == 0)
2392 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002393 if (area_attr == 0 && *ptr != NUL)
2394 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002395 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002396#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002397 }
2398 else
2399 {
2400#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002401 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002402#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002403 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002404
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002405 // Get a character from the line itself.
2406 c = *ptr;
2407#ifdef FEAT_LINEBREAK
2408 c0 = *ptr;
2409#endif
2410 if (has_mbyte)
2411 {
2412 mb_c = c;
2413 if (enc_utf8)
2414 {
2415 // If the UTF-8 character is more than one byte: Decode it
2416 // into "mb_c".
2417 mb_l = utfc_ptr2len(ptr);
2418 mb_utf8 = FALSE;
2419 if (mb_l > 1)
2420 {
2421 mb_c = utfc_ptr2char(ptr, u8cc);
2422 // Overlong encoded ASCII or ASCII with composing char
2423 // is displayed normally, except a NUL.
2424 if (mb_c < 0x80)
2425 {
2426 c = mb_c;
2427#ifdef FEAT_LINEBREAK
2428 c0 = mb_c;
2429#endif
2430 }
2431 mb_utf8 = TRUE;
2432
2433 // At start of the line we can have a composing char.
2434 // Draw it as a space with a composing char.
2435 if (utf_iscomposing(mb_c))
2436 {
2437 int i;
2438
2439 for (i = Screen_mco - 1; i > 0; --i)
2440 u8cc[i] = u8cc[i - 1];
2441 u8cc[0] = mb_c;
2442 mb_c = ' ';
2443 }
2444 }
2445
2446 if ((mb_l == 1 && c >= 0x80)
2447 || (mb_l >= 1 && mb_c == 0)
2448 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2449 {
2450 // Illegal UTF-8 byte: display as <xx>.
2451 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002452 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002453# ifdef FEAT_RIGHTLEFT
2454 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002455 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002456# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002457 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002458 c = *wlv.p_extra;
2459 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002460 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002461 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2462 wlv.c_extra = NUL;
2463 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002464 if (area_attr == 0 && search_attr == 0)
2465 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002466 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002467 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002468 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002469 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002470 }
2471 }
2472 else if (mb_l == 0) // at the NUL at end-of-line
2473 mb_l = 1;
2474#ifdef FEAT_ARABIC
2475 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2476 {
2477 // Do Arabic shaping.
2478 int pc, pc1, nc;
2479 int pcc[MAX_MCO];
2480
2481 // The idea of what is the previous and next
2482 // character depends on 'rightleft'.
2483 if (wp->w_p_rl)
2484 {
2485 pc = prev_c;
2486 pc1 = prev_c1;
2487 nc = utf_ptr2char(ptr + mb_l);
2488 prev_c1 = u8cc[0];
2489 }
2490 else
2491 {
2492 pc = utfc_ptr2char(ptr + mb_l, pcc);
2493 nc = prev_c;
2494 pc1 = pcc[0];
2495 }
2496 prev_c = mb_c;
2497
2498 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2499 }
2500 else
2501 prev_c = mb_c;
2502#endif
2503 }
2504 else // enc_dbcs
2505 {
2506 mb_l = MB_BYTE2LEN(c);
2507 if (mb_l == 0) // at the NUL at end-of-line
2508 mb_l = 1;
2509 else if (mb_l > 1)
2510 {
2511 // We assume a second byte below 32 is illegal.
2512 // Hopefully this is OK for all double-byte encodings!
2513 if (ptr[1] >= 32)
2514 mb_c = (c << 8) + ptr[1];
2515 else
2516 {
2517 if (ptr[1] == NUL)
2518 {
2519 // head byte at end of line
2520 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002521 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002522 }
2523 else
2524 {
2525 // illegal tail byte
2526 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002527 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002528 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002529 wlv.p_extra = wlv.extra;
2530 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002531 wlv.c_extra = NUL;
2532 wlv.c_final = NUL;
2533 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002534 if (area_attr == 0 && search_attr == 0)
2535 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002536 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002537 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002538 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002539 // save current attr
2540 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002541 }
2542 mb_c = c;
2543 }
2544 }
2545 }
2546 // If a double-width char doesn't fit display a '>' in the
2547 // last column; the character is displayed at the start of the
2548 // next line.
2549 if ((
2550# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002551 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002552# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002553 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002554 && (*mb_char2cells)(mb_c) == 2)
2555 {
2556 c = '>';
2557 mb_c = c;
2558 mb_utf8 = FALSE;
2559 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002560 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002561 // Put pointer back so that the character will be
2562 // displayed at the start of the next line.
2563 --ptr;
2564#ifdef FEAT_CONCEAL
2565 did_decrement_ptr = TRUE;
2566#endif
2567 }
2568 else if (*ptr != NUL)
2569 ptr += mb_l - 1;
2570
2571 // If a double-width char doesn't fit at the left side display
2572 // a '<' in the first column. Don't do this for unprintable
2573 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002574 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002575 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002576 wlv.n_extra = 1;
2577 wlv.c_extra = MB_FILLER_CHAR;
2578 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002579 c = ' ';
2580 if (area_attr == 0 && search_attr == 0)
2581 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002582 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002583 extra_attr = hl_combine_attr(
2584 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002585 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002586 }
2587 mb_c = c;
2588 mb_utf8 = FALSE;
2589 mb_l = 1;
2590 }
2591
2592 }
2593 ++ptr;
2594
2595 if (extra_check)
2596 {
2597#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002598 // Check spelling (unless at the end of the line).
2599 // Only do this when there is no syntax highlighting, the
2600 // @Spell cluster is not used or the current syntax item
2601 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002602 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002603 if (has_spell && v >= word_end && v > cur_checked_col)
2604 {
2605 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002606 // do not calculate cap_col at the end of the line or when
2607 // only white space is following
2608 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002609# ifdef FEAT_SYN_HL
2610 !has_syntax ||
2611# endif
2612 can_spell))
2613 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002614 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002615 int len;
2616 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002617
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002618 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002619 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002620
2621 // Use nextline[] if possible, it has the start of the
2622 // next line concatenated.
2623 if ((prev_ptr - line) - nextlinecol >= 0)
2624 p = nextline + (prev_ptr - line) - nextlinecol;
2625 else
2626 p = prev_ptr;
2627 cap_col -= (int)(prev_ptr - line);
2628 len = spell_check(wp, p, &spell_hlf, &cap_col,
2629 nochange);
2630 word_end = v + len;
2631
2632 // In Insert mode only highlight a word that
2633 // doesn't touch the cursor.
2634 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002635 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002636 && wp->w_cursor.lnum == lnum
2637 && wp->w_cursor.col >=
2638 (colnr_T)(prev_ptr - line)
2639 && wp->w_cursor.col < (colnr_T)word_end)
2640 {
2641 spell_hlf = HLF_COUNT;
2642 spell_redraw_lnum = lnum;
2643 }
2644
2645 if (spell_hlf == HLF_COUNT && p != prev_ptr
2646 && (p - nextline) + len > nextline_idx)
2647 {
2648 // Remember that the good word continues at the
2649 // start of the next line.
2650 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002651 checked_col = (int)((p - nextline)
2652 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002653 }
2654
2655 // Turn index into actual attributes.
2656 if (spell_hlf != HLF_COUNT)
2657 spell_attr = highlight_attr[spell_hlf];
2658
2659 if (cap_col > 0)
2660 {
2661 if (p != prev_ptr
2662 && (p - nextline) + cap_col >= nextline_idx)
2663 {
2664 // Remember that the word in the next line
2665 // must start with a capital.
2666 capcol_lnum = lnum + 1;
2667 cap_col = (int)((p - nextline) + cap_col
2668 - nextline_idx);
2669 }
2670 else
2671 // Compute the actual column.
2672 cap_col += (int)(prev_ptr - line);
2673 }
2674 }
2675 }
2676 if (spell_attr != 0)
2677 {
2678 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002679 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2680 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002681 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002682 wlv.char_attr = hl_combine_attr(spell_attr,
2683 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002684 }
2685#endif
2686#ifdef FEAT_LINEBREAK
2687 // Found last space before word: check for line break.
2688 if (wp->w_p_lbr && c0 == c
2689 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2690 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002691 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2692 : 0;
2693 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002694 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002695
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002696 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002697# ifdef FEAT_PROP_POPUP
2698 // do not want virtual text counted here
2699 cts.cts_has_prop_with_text = FALSE;
2700# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002701 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002702 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002703
2704 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002705 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002706 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002707 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002708 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2709 if (wlv.n_extra < 0)
2710 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002711 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002712 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002713 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002714 // line break, but for TABs the highlighting should
2715 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002716 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002717
Bram Moolenaar1306b362022-08-06 15:59:06 +01002718 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002719# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002720 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002721 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002722 wp->w_buffer->b_p_vts_array) - 1;
2723# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002724 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002725 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002726# endif
2727
Bram Moolenaar1306b362022-08-06 15:59:06 +01002728 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2729 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002730# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002731 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002732 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002733# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002734 if (VIM_ISWHITE(c))
2735 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002736# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002737 if (c == TAB)
2738 // See "Tab alignment" below.
2739 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002740# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002741 if (!wp->w_p_list)
2742 c = ' ';
2743 }
2744 }
2745#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002746 in_multispace = c == ' '
2747 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2748 if (!in_multispace)
2749 multispace_pos = 0;
2750
Bram Moolenaareed9d462021-02-15 20:38:25 +01002751 // 'list': Change char 160 to 'nbsp' and space to 'space'
2752 // setting in 'listchars'. But not when the character is
2753 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002754 if (wp->w_p_list
2755 && ((((c == 160 && mb_l == 1)
2756 || (mb_utf8
2757 && ((mb_c == 160 && mb_l == 2)
2758 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002759 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002760 || (c == ' '
2761 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002762 && (wp->w_lcs_chars.space
2763 || (in_multispace
2764 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002765 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002766 && ptr - line <= trailcol)))
2767 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002768 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2769 {
2770 c = wp->w_lcs_chars.multispace[multispace_pos++];
2771 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2772 multispace_pos = 0;
2773 }
2774 else
2775 c = (c == ' ') ? wp->w_lcs_chars.space
2776 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002777 if (area_attr == 0 && search_attr == 0)
2778 {
2779 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002780 extra_attr = hl_combine_attr(wlv.win_attr,
2781 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002782 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002783 }
2784 mb_c = c;
2785 if (enc_utf8 && utf_char2len(c) > 1)
2786 {
2787 mb_utf8 = TRUE;
2788 u8cc[0] = 0;
2789 c = 0xc0;
2790 }
2791 else
2792 mb_utf8 = FALSE;
2793 }
2794
zeertzjq2e7cba32022-06-10 15:30:32 +01002795 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2796 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002797 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002798 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2799 && wp->w_lcs_chars.leadmultispace != NULL)
2800 {
2801 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002802 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2803 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002804 multispace_pos = 0;
2805 }
2806
2807 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2808 c = wp->w_lcs_chars.trail;
2809
2810 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2811 c = wp->w_lcs_chars.lead;
2812
zeertzjq2e7cba32022-06-10 15:30:32 +01002813 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002814 c = wp->w_lcs_chars.space;
2815
2816
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002817 if (!attr_pri)
2818 {
2819 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002820 extra_attr = hl_combine_attr(wlv.win_attr,
2821 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002822 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002823 }
2824 mb_c = c;
2825 if (enc_utf8 && utf_char2len(c) > 1)
2826 {
2827 mb_utf8 = TRUE;
2828 u8cc[0] = 0;
2829 c = 0xc0;
2830 }
2831 else
2832 mb_utf8 = FALSE;
2833 }
2834 }
2835
2836 // Handling of non-printable characters.
2837 if (!vim_isprintc(c))
2838 {
2839 // when getting a character from the file, we may have to
2840 // turn it into something else on the way to putting it
2841 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002842 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002843 {
2844 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002845 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002846#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002847 char_u *sbr = get_showbreak_value(wp);
2848
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002849 // only adjust the tab_len, when at the first column
2850 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002851 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002852 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002853#endif
2854 // tab amount depends on current column
2855#ifdef FEAT_VARTABS
2856 tab_len = tabstop_padding(vcol_adjusted,
2857 wp->w_buffer->b_p_ts,
2858 wp->w_buffer->b_p_vts_array) - 1;
2859#else
2860 tab_len = (int)wp->w_buffer->b_p_ts
2861 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2862#endif
2863
2864#ifdef FEAT_LINEBREAK
2865 if (!wp->w_p_lbr || !wp->w_p_list)
2866#endif
2867 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002868 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002869#ifdef FEAT_LINEBREAK
2870 else
2871 {
2872 char_u *p;
2873 int len;
2874 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002875 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002876
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002877# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002878 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002879 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002880 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002881
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002882 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002883 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002884 && old_boguscols > 0
2885 && wlv.n_extra > tab_len)
2886 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002887# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002888 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002889 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002890 // If wlv.n_extra > 0, it gives the number of
2891 // chars, to use for a tab, else we need to
2892 // calculate the width for a tab.
2893 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
2894 len = tab_len * tab2_len;
2895 if (wp->w_lcs_chars.tab3)
2896 len += mb_char2len(wp->w_lcs_chars.tab3)
2897 - tab2_len;
2898 if (wlv.n_extra > 0)
2899 len += wlv.n_extra - tab_len;
2900 c = wp->w_lcs_chars.tab1;
2901 p = alloc(len + 1);
2902 if (p == NULL)
2903 wlv.n_extra = 0;
2904 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002905 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002906 vim_memset(p, ' ', len);
2907 p[len] = NUL;
2908 vim_free(wlv.p_extra_free);
2909 wlv.p_extra_free = p;
2910 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002911 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002912 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002913
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002914 if (*p == NUL)
2915 {
2916 tab_len = i;
2917 break;
2918 }
2919
2920 // if tab3 is given, use it for the last
2921 // char
2922 if (wp->w_lcs_chars.tab3
2923 && i == tab_len - 1)
2924 lcs = wp->w_lcs_chars.tab3;
2925 p += mb_char2bytes(lcs, p);
2926 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002927 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002928 }
2929 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002930# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002931 // n_extra will be increased by
2932 // FIX_FOX_BOGUSCOLS macro below, so need to
2933 // adjust for that here
2934 if (wlv.vcol_off > 0)
2935 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002936# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002937 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002938 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002939 }
2940#endif
2941#ifdef FEAT_CONCEAL
2942 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002943 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002944
2945 // Tab alignment should be identical regardless of
2946 // 'conceallevel' value. So tab compensates of all
2947 // previous concealed characters, and thus resets
2948 // vcol_off and boguscols accumulated so far in the
2949 // line. Note that the tab can be longer than
2950 // 'tabstop' when there are concealed characters.
2951 FIX_FOR_BOGUSCOLS;
2952
2953 // Make sure, the highlighting for the tab char will be
2954 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002955 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002956 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002957 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002958 tab_len += vc_saved;
2959 }
2960#endif
2961 mb_utf8 = FALSE; // don't draw as UTF-8
2962 if (wp->w_p_list)
2963 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002964 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002965 ? wp->w_lcs_chars.tab3
2966 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002967#ifdef FEAT_LINEBREAK
2968 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002969 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002970 else
2971#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002972 wlv.c_extra = wp->w_lcs_chars.tab2;
2973 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002974 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002975 extra_attr = hl_combine_attr(wlv.win_attr,
2976 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002977 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002978 mb_c = c;
2979 if (enc_utf8 && utf_char2len(c) > 1)
2980 {
2981 mb_utf8 = TRUE;
2982 u8cc[0] = 0;
2983 c = 0xc0;
2984 }
2985 }
2986 else
2987 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002988 wlv.c_final = NUL;
2989 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002990 c = ' ';
2991 }
2992 }
2993 else if (c == NUL
2994 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002995 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
2996 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002997 && VIsual_mode != Ctrl_V
2998 && (
2999# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003000 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003001# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003002 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003003 && !(noinvcur
3004 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003005 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003006 && lcs_eol_one > 0)
3007 {
3008 // Display a '$' after the line or highlight an extra
3009 // character if the line break is included.
3010#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3011 // For a diff line the highlighting continues after the
3012 // "$".
3013 if (
3014# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003015 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003016# ifdef LINE_ATTR
3017 &&
3018# endif
3019# endif
3020# ifdef LINE_ATTR
3021 line_attr == 0
3022# endif
3023 )
3024#endif
3025 {
3026 // In virtualedit, visual selections may extend
3027 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003028 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003029 && wlv.tocol != MAXCOL
3030 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003031 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003032 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003033 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003034 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3035 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003036 else
3037 c = ' ';
3038 lcs_eol_one = -1;
3039 --ptr; // put it back at the NUL
3040 if (!attr_pri)
3041 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003042 extra_attr = hl_combine_attr(wlv.win_attr,
3043 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003044 n_attr = 1;
3045 }
3046 mb_c = c;
3047 if (enc_utf8 && utf_char2len(c) > 1)
3048 {
3049 mb_utf8 = TRUE;
3050 u8cc[0] = 0;
3051 c = 0xc0;
3052 }
3053 else
3054 mb_utf8 = FALSE; // don't draw as UTF-8
3055 }
3056 else if (c != NUL)
3057 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003058 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3059 if (wlv.n_extra == 0)
3060 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003061#ifdef FEAT_RIGHTLEFT
3062 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003063 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003064#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003065 wlv.c_extra = NUL;
3066 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003067#ifdef FEAT_LINEBREAK
3068 if (wp->w_p_lbr)
3069 {
3070 char_u *p;
3071
Bram Moolenaar1306b362022-08-06 15:59:06 +01003072 c = *wlv.p_extra;
3073 p = alloc(wlv.n_extra + 1);
3074 vim_memset(p, ' ', wlv.n_extra);
3075 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3076 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003077 vim_free(wlv.p_extra_free);
3078 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003079 }
3080 else
3081#endif
3082 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003083 wlv.n_extra = byte2cells(c) - 1;
3084 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003085 }
3086 if (!attr_pri)
3087 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003088 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003089 extra_attr = hl_combine_attr(wlv.win_attr,
3090 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003091 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003092 }
3093 mb_utf8 = FALSE; // don't draw as UTF-8
3094 }
3095 else if (VIsual_active
3096 && (VIsual_mode == Ctrl_V
3097 || VIsual_mode == 'v')
3098 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003099 && wlv.tocol != MAXCOL
3100 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003101 && (
3102#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003103 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003104#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003105 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003106 {
3107 c = ' ';
3108 --ptr; // put it back at the NUL
3109 }
3110#if defined(LINE_ATTR)
3111 else if ((
3112# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003113 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003114# endif
3115# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003116 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003117# endif
3118 line_attr != 0
3119 ) && (
3120# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003121 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003122# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003123 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003124# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003125 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003126# endif
3127 < wp->w_width)))
3128 {
3129 // Highlight until the right side of the window
3130 c = ' ';
3131 --ptr; // put it back at the NUL
3132
3133 // Remember we do the char for line highlighting.
3134 ++did_line_attr;
3135
3136 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01003137 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003138 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003139 || (wp->w_p_list &&
3140 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003141 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003142# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003143 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003144 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003145 wlv.diff_hlf = HLF_CHD;
3146 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003147 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003148 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003149 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3150 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003151 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003152 || (wlv.vcol >= left_curline_col
3153 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003154 wlv.char_attr = hl_combine_attr(
3155 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003156 }
3157 }
3158# endif
3159# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003160 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003161 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003162 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003163 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3164 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003165 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003166 if (!wlv.cul_screenline
3167 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003168 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003169 wlv.char_attr = hl_combine_attr(
3170 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003171 }
3172 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003173 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3174 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003175 }
3176# endif
3177 }
3178#endif
3179 }
3180
3181#ifdef FEAT_CONCEAL
3182 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003183 && (wp != curwin || lnum != wp->w_cursor.lnum
3184 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003185 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3186 && !(lnum_in_visual_area
3187 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3188 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003189 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003190 if (((prev_syntax_id != syntax_seqnr
3191 && (syntax_flags & HL_CONCEAL) != 0)
3192 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003193 && (syn_get_sub_char() != NUL
3194 || (has_match_conc && match_conc)
3195 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003196 && wp->w_p_cole != 3)
3197 {
3198 // First time at this concealed item: display one
3199 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003200 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003201 c = match_conc;
3202 else if (syn_get_sub_char() != NUL)
3203 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003204 else if (wp->w_lcs_chars.conceal != NUL)
3205 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003206 else
3207 c = ' ';
3208
3209 prev_syntax_id = syntax_seqnr;
3210
Bram Moolenaar1306b362022-08-06 15:59:06 +01003211 if (wlv.n_extra > 0)
3212 wlv.vcol_off += wlv.n_extra;
3213 wlv.vcol += wlv.n_extra;
3214 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003215 {
3216# ifdef FEAT_RIGHTLEFT
3217 if (wp->w_p_rl)
3218 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003219 wlv.col -= wlv.n_extra;
3220 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003221 }
3222 else
3223# endif
3224 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003225 wlv.boguscols += wlv.n_extra;
3226 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003227 }
3228 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003229 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003230 n_attr = 0;
3231 }
3232 else if (n_skip == 0)
3233 {
3234 is_concealing = TRUE;
3235 n_skip = 1;
3236 }
3237 mb_c = c;
3238 if (enc_utf8 && utf_char2len(c) > 1)
3239 {
3240 mb_utf8 = TRUE;
3241 u8cc[0] = 0;
3242 c = 0xc0;
3243 }
3244 else
3245 mb_utf8 = FALSE; // don't draw as UTF-8
3246 }
3247 else
3248 {
3249 prev_syntax_id = 0;
3250 is_concealing = FALSE;
3251 }
3252
3253 if (n_skip > 0 && did_decrement_ptr)
3254 // not showing the '>', put pointer back to avoid getting stuck
3255 ++ptr;
3256
3257#endif // FEAT_CONCEAL
3258 }
3259
3260#ifdef FEAT_CONCEAL
3261 // In the cursor line and we may be concealing characters: correct
3262 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003263 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003264 && wp == curwin && lnum == wp->w_cursor.lnum
3265 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003266 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003267 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003268# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003269 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003270 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003271 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003272# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003273 wp->w_wcol = wlv.col - wlv.boguscols;
3274 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003275 did_wcol = TRUE;
3276 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003277# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003278 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003279# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003280 }
3281#endif
3282
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003283 // Use "extra_attr", but don't override visual selection highlighting,
3284 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003285 // Don't use "extra_attr" until n_attr_skip is zero.
3286 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003287 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003288 && (!attr_pri
3289#ifdef FEAT_PROP_POPUP
3290 || (text_prop_flags & PT_FLAG_OVERRIDE)
3291#endif
3292 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003293 {
3294#ifdef LINE_ATTR
3295 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003296 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003297 else
3298#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003299 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003300 }
3301
3302#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3303 // XIM don't send preedit_start and preedit_end, but they send
3304 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3305 // im_is_preediting() here.
3306 if (p_imst == IM_ON_THE_SPOT
3307 && xic != NULL
3308 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003309 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003310 && !p_imdisable
3311 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003312 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003313 {
3314 colnr_T tcol;
3315
3316 if (preedit_end_col == MAXCOL)
3317 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3318 else
3319 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003320 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003321 {
3322 if (feedback_old_attr < 0)
3323 {
3324 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003325 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003326 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003327 wlv.char_attr = im_get_feedback_attr(feedback_col);
3328 if (wlv.char_attr < 0)
3329 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003330 feedback_col++;
3331 }
3332 else if (feedback_old_attr >= 0)
3333 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003334 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003335 feedback_old_attr = -1;
3336 feedback_col = 0;
3337 }
3338 }
3339#endif
3340 // Handle the case where we are in column 0 but not on the first
3341 // character of the line and the user wants us to show us a
3342 // special character (via 'listchars' option "precedes:<char>".
3343 if (lcs_prec_todo != NUL
3344 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003345 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3346 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003347#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003348 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003349#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003350 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003351 && c != NUL)
3352 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003353 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003354 lcs_prec_todo = NUL;
3355 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3356 {
3357 // Double-width character being overwritten by the "precedes"
3358 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003359 wlv.c_extra = MB_FILLER_CHAR;
3360 wlv.c_final = NUL;
3361 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003362 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003363 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003364 }
3365 mb_c = c;
3366 if (enc_utf8 && utf_char2len(c) > 1)
3367 {
3368 mb_utf8 = TRUE;
3369 u8cc[0] = 0;
3370 c = 0xc0;
3371 }
3372 else
3373 mb_utf8 = FALSE; // don't draw as UTF-8
3374 if (!attr_pri)
3375 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003376 saved_attr3 = wlv.char_attr; // save current attr
3377 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003378 n_attr3 = 1;
3379 }
3380 }
3381
3382 // At end of the text line or just after the last character.
3383 if ((c == NUL
3384#if defined(LINE_ATTR)
3385 || did_line_attr == 1
3386#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003387 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003388 {
3389#ifdef FEAT_SEARCH_EXTRA
3390 // flag to indicate whether prevcol equals startcol of search_hl or
3391 // one of the matches
3392 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3393 (long)(ptr - line) - (c == NUL));
3394#endif
3395 // Invert at least one char, used for Visual and empty line or
3396 // highlight match at end of line. If it's beyond the last
3397 // char on the screen, just overwrite that one (tricky!) Not
3398 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003399 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003400 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003401 && (VIsual_mode != Ctrl_V
3402 || lnum == VIsual.lnum
3403 || lnum == curwin->w_cursor.lnum)
3404 && c == NUL)
3405#ifdef FEAT_SEARCH_EXTRA
3406 // highlight 'hlsearch' match at end of line
3407 || (prevcol_hl_flag
3408# ifdef FEAT_SYN_HL
3409 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3410 && !(wp == curwin && VIsual_active))
3411# endif
3412# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003413 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003414# endif
3415# if defined(LINE_ATTR)
3416 && did_line_attr <= 1
3417# endif
3418 )
3419#endif
3420 ))
3421 {
3422 int n = 0;
3423
3424#ifdef FEAT_RIGHTLEFT
3425 if (wp->w_p_rl)
3426 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003427 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003428 n = 1;
3429 }
3430 else
3431#endif
3432 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003433 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003434 n = -1;
3435 }
3436 if (n != 0)
3437 {
3438 // At the window boundary, highlight the last character
3439 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003440 wlv.off += n;
3441 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003442 }
3443 else
3444 {
3445 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003446 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003447 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003448 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003449 }
3450#ifdef FEAT_SEARCH_EXTRA
3451 if (area_attr == 0)
3452 {
3453 // Use attributes from match with highest priority among
3454 // 'search_hl' and the match list.
3455 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003456 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003457 }
3458#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003459 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003460 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003461#ifdef FEAT_RIGHTLEFT
3462 if (wp->w_p_rl)
3463 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003464 --wlv.col;
3465 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003466 }
3467 else
3468#endif
3469 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003470 ++wlv.col;
3471 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003472 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003473 ++wlv.vcol;
3474 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003475 }
3476 }
3477
3478 // At end of the text line.
3479 if (c == NUL)
3480 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003481 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003482
3483 // Update w_cline_height and w_cline_folded if the cursor line was
3484 // updated (saves a call to plines() later).
3485 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3486 {
3487 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003488 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003489#ifdef FEAT_FOLDING
3490 curwin->w_cline_folded = FALSE;
3491#endif
3492 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3493 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003494 break;
3495 }
3496
3497 // Show "extends" character from 'listchars' if beyond the line end and
3498 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003499 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003500 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003501 && wp->w_p_list
3502 && !wp->w_p_wrap
3503#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003504 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003505#endif
3506 && (
3507#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003508 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003509#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003510 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003511 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003512 || lcs_eol_one > 0
3513 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003514 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003515 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003516 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003517 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003518 mb_c = c;
3519 if (enc_utf8 && utf_char2len(c) > 1)
3520 {
3521 mb_utf8 = TRUE;
3522 u8cc[0] = 0;
3523 c = 0xc0;
3524 }
3525 else
3526 mb_utf8 = FALSE;
3527 }
3528
3529#ifdef FEAT_SYN_HL
3530 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003531 if (wlv.draw_color_col)
3532 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003533
3534 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3535 // highlight the cursor position itself.
3536 // Also highlight the 'colorcolumn' if it is different than
3537 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003538 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3539 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003540 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003541 if (((wlv.draw_state == WL_LINE
3542 || wlv.draw_state == WL_BRI
3543 || wlv.draw_state == WL_SBR)
3544 && !lnum_in_visual_area
3545 && search_attr == 0
3546 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003547# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003548 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003549# endif
3550 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003551 {
3552 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3553 && lnum != wp->w_cursor.lnum)
3554 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003555 vcol_save_attr = wlv.char_attr;
3556 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3557 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003558 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003559 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003560 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003561 vcol_save_attr = wlv.char_attr;
3562 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003563 }
3564 }
3565#endif
3566
3567 // Store character to be displayed.
3568 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003569 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003570 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003571 {
3572 // Store the character.
3573#if defined(FEAT_RIGHTLEFT)
3574 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3575 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003576 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003577 --wlv.off;
3578 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003579 }
3580#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003581 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003582 if (enc_dbcs == DBCS_JPNU)
3583 {
3584 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003585 ScreenLines[wlv.off] = 0x8e;
3586 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003587 }
3588 else if (enc_utf8)
3589 {
3590 if (mb_utf8)
3591 {
3592 int i;
3593
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003594 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003595 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003596 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003597 for (i = 0; i < Screen_mco; ++i)
3598 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003599 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003600 if (u8cc[i] == 0)
3601 break;
3602 }
3603 }
3604 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003605 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003606 }
3607 if (multi_attr)
3608 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003609 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003610 multi_attr = 0;
3611 }
3612 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003613 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003614
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003615 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003616
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003617 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3618 {
3619 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003620 ++wlv.off;
3621 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003622 if (enc_utf8)
3623 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003624 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003625 else
3626 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003627 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003628 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003629#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003630 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003631#endif
3632 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003633 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003634 // When "wlv.tocol" is halfway a character, set it to the end
3635 // of the character, otherwise highlighting won't stop.
3636 if (wlv.tocol == wlv.vcol)
3637 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003638
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003639 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003640
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003641#ifdef FEAT_RIGHTLEFT
3642 if (wp->w_p_rl)
3643 {
3644 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003645 --wlv.off;
3646 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003647 }
3648#endif
3649 }
3650#ifdef FEAT_RIGHTLEFT
3651 if (wp->w_p_rl)
3652 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003653 --wlv.off;
3654 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003655 }
3656 else
3657#endif
3658 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003659 ++wlv.off;
3660 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003661 }
3662 }
3663#ifdef FEAT_CONCEAL
3664 else if (wp->w_p_cole > 0 && is_concealing)
3665 {
3666 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003667 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003668 if (wlv.n_extra > 0)
3669 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003670 if (wp->w_p_wrap)
3671 {
3672 // Special voodoo required if 'wrap' is on.
3673 //
3674 // Advance the column indicator to force the line
3675 // drawing to wrap early. This will make the line
3676 // take up the same screen space when parts are concealed,
3677 // so that cursor line computations aren't messed up.
3678 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003679 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003680 // trailing junk to be written out of the screen line
3681 // we are building, 'boguscols' keeps track of the number
3682 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003683 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003684 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003685 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003686# ifdef FEAT_RIGHTLEFT
3687 if (wp->w_p_rl)
3688 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003689 wlv.col -= wlv.n_extra;
3690 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003691 }
3692 else
3693# endif
3694 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003695 wlv.col += wlv.n_extra;
3696 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003697 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003698 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003699 n_attr = 0;
3700 }
3701
3702
3703 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3704 {
3705 // Need to fill two screen columns.
3706# ifdef FEAT_RIGHTLEFT
3707 if (wp->w_p_rl)
3708 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003709 --wlv.boguscols;
3710 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003711 }
3712 else
3713# endif
3714 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003715 ++wlv.boguscols;
3716 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003717 }
3718 }
3719
3720# ifdef FEAT_RIGHTLEFT
3721 if (wp->w_p_rl)
3722 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003723 --wlv.boguscols;
3724 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003725 }
3726 else
3727# endif
3728 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003729 ++wlv.boguscols;
3730 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003731 }
3732 }
3733 else
3734 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003735 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003736 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003737 wlv.vcol += wlv.n_extra;
3738 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003739 n_attr = 0;
3740 }
3741 }
3742
3743 }
3744#endif // FEAT_CONCEAL
3745 else
3746 --n_skip;
3747
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003748 // Only advance the "wlv.vcol" when after the 'number' or
3749 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003750 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003751#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003752 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003753#endif
3754 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003755 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003756
3757#ifdef FEAT_SYN_HL
3758 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003759 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003760#endif
3761
3762 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003763 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3764 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003765
3766 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003767 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003768 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003769 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003770 if (n_attr_skip > 0)
3771 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003772
3773 // At end of screen line and there is more to come: Display the line
3774 // so far. If there is no more to display it is caught above.
3775 if ((
3776#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003777 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003778#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003779 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003780 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003781 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003782#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003783 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003784#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003785#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003786 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003787#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003788 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003789 && wlv.p_extra != at_end_str)
3790 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3791 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003792 )
3793 {
3794#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003795 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003796 wlv_screen_line(wp, &wlv, FALSE);
3797 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003798 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003799#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003800 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003801#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003802 ++wlv.row;
3803 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003804
3805 // When not wrapping and finished diff lines, or when displayed
3806 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01003807 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003808#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003809 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003810#endif
3811#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01003812 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003813#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01003814 ) || lcs_eol_one == -1)
3815#ifdef FEAT_PROP_POPUP
3816 && !text_prop_follows
3817#endif
3818 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003819 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003820#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003821 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003822 {
3823 // do not output more of the line, only the "below" prop
3824 ptr += STRLEN(ptr);
3825# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003826 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003827# endif
3828 }
3829#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003830
3831 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003832 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003833#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003834 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003835#endif
3836 )
3837 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003838 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3839 draw_vsep_win(wp, wlv.row);
3840 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003841 }
3842
3843 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003844 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003845 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003846 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003847 break;
3848 }
3849
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003850 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003851#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003852 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003853#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003854#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003855 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003856#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003857 && wp->w_width == Columns)
3858 {
3859 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003860 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003861
3862 // Special trick to make copy/paste of wrapped lines work with
3863 // xterm/screen: write an extra character beyond the end of
3864 // the line. This will work with all terminal types
3865 // (regardless of the xn,am settings).
3866 // Only do this on a fast tty.
3867 // Only do this if the cursor is on the current line
3868 // (something has been written in it).
3869 // Don't do this for the GUI.
3870 // Don't do this for double-width characters.
3871 // Don't do this for a window not at the right screen border.
3872 if (p_tf
3873#ifdef FEAT_GUI
3874 && !gui.in_use
3875#endif
3876 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003877 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3878 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003879 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003880 || (*mb_off2cells)(
3881 LineOffset[wlv.screen_row - 1]
3882 + (int)Columns - 2,
3883 LineOffset[wlv.screen_row]
3884 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003885 {
3886 // First make sure we are at the end of the screen line,
3887 // then output the same character again to let the
3888 // terminal know about the wrap. If the terminal doesn't
3889 // auto-wrap, we overwrite the character.
3890 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003891 screen_char(LineOffset[wlv.screen_row - 1]
3892 + (unsigned)Columns - 1,
3893 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003894
3895 // When there is a multi-byte character, just output a
3896 // space to keep it simple.
3897 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003898 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003899 out_char(' ');
3900 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003901 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003902 + (Columns - 1)]);
3903 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003904 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003905 screen_start(); // don't know where cursor is now
3906 }
3907 }
3908
Bram Moolenaar1306b362022-08-06 15:59:06 +01003909 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003910
Bram Moolenaareed9d462021-02-15 20:38:25 +01003911 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003912#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003913 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003914# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003915 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003916# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003917 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003918 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003919#endif
3920#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003921 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003922 // When the filler lines are actually below the last line of the
3923 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003924 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003925 break;
3926#endif
3927 }
3928
3929 } // for every character in the line
3930
3931#ifdef FEAT_SPELL
3932 // After an empty line check first word for capital.
3933 if (*skipwhite(line) == NUL)
3934 {
3935 capcol_lnum = lnum + 1;
3936 cap_col = 0;
3937 }
3938#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003939#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003940 vim_free(text_props);
3941 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003942 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003943#endif
3944
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003945 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003946 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003947}