blob: bc39442132e6217398ce67cd5354012bb7c67b12 [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 Moolenaar06618f92022-10-06 19:21:20 +0100373 && (wp->w_skipcol == 0 || wlv->row > wp->w_winrow))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100374 {
375 long num;
376 char *fmt = "%*ld ";
377
378 if (wp->w_p_nu && !wp->w_p_rnu)
379 // 'number' + 'norelativenumber'
380 num = (long)wlv->lnum;
381 else
382 {
383 // 'relativenumber', don't use negative numbers
384 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
385 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
386 {
387 // 'number' + 'relativenumber'
388 num = wlv->lnum;
389 fmt = "%-*ld ";
390 }
391 }
392
393 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100394 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100395 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
396 ++wlv->p_extra)
397 *wlv->p_extra = '-';
398#ifdef FEAT_RIGHTLEFT
399 if (wp->w_p_rl) // reverse line numbers
400 {
401 char_u *p1, *p2;
402 int t;
403
404 // like rl_mirror(), but keep the space at the end
405 p2 = skipwhite(wlv->extra);
406 p2 = skiptowhite(p2) - 1;
407 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
408 {
409 t = *p1;
410 *p1 = *p2;
411 *p2 = t;
412 }
413 }
414#endif
415 wlv->p_extra = wlv->extra;
416 wlv->c_extra = NUL;
417 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100418 }
419 else
420 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100421 wlv->c_extra = ' ';
422 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100423 }
424 wlv->n_extra = number_width(wp) + 1;
425 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
426#ifdef FEAT_SYN_HL
427 // When 'cursorline' is set highlight the line number of
428 // the current line differently.
429 // When 'cursorlineopt' does not have "line" only
430 // highlight the line number itself.
431 // TODO: Can we use CursorLine instead of CursorLineNr
432 // when CursorLineNr isn't set?
433 if (wp->w_p_cul
434 && wlv->lnum == wp->w_cursor.lnum
435 && (wp->w_p_culopt_flags & CULOPT_NBR)
436 && (wlv->row == wlv->startrow + wlv->filler_lines
437 || (wlv->row > wlv->startrow + wlv->filler_lines
438 && (wp->w_p_culopt_flags & CULOPT_LINE))))
439 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
440#endif
441 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
442 && HL_ATTR(HLF_LNA) != 0)
443 // Use LineNrAbove
444 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
445 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
446 && HL_ATTR(HLF_LNB) != 0)
447 // Use LineNrBelow
448 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
449 }
450#ifdef FEAT_SIGNS
451 if (num_attr)
452 wlv->char_attr = num_attr;
453#endif
454 }
455}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100456
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100457#ifdef FEAT_LINEBREAK
458 static void
459handle_breakindent(win_T *wp, winlinevars_T *wlv)
460{
461 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100462 && *get_showbreak_value(wp) != NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100463 // draw indent after showbreak value
464 wlv->draw_state = WL_BRI;
465 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
466 // After the showbreak, draw the breakindent
467 wlv->draw_state = WL_BRI - 1;
468
469 // draw 'breakindent': indent wrapped text accordingly
470 if (wlv->draw_state == WL_BRI - 1)
471 {
472 wlv->draw_state = WL_BRI;
473 // if wlv->need_showbreak is set, breakindent also applies
474 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
475# ifdef FEAT_DIFF
476 && wlv->filler_lines == 0
477# endif
478# ifdef FEAT_PROP_POPUP
479 && !wlv->dont_use_showbreak
480# endif
481 )
482 {
483 wlv->char_attr = 0;
484# ifdef FEAT_DIFF
485 if (wlv->diff_hlf != (hlf_T)0)
486 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
487# endif
488 wlv->p_extra = NULL;
489 wlv->c_extra = ' ';
490 wlv->c_final = NUL;
491 wlv->n_extra = get_breakindent_win(wp,
492 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
493 if (wlv->row == wlv->startrow)
494 {
495 wlv->n_extra -= win_col_off2(wp);
496 if (wlv->n_extra < 0)
497 wlv->n_extra = 0;
498 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100499 if (wp->w_skipcol > 0 && wlv->startrow == 0
500 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100501 wlv->need_showbreak = FALSE;
502 // Correct end of highlighted area for 'breakindent',
503 // required when 'linebreak' is also set.
504 if (wlv->tocol == wlv->vcol)
505 wlv->tocol += wlv->n_extra;
506 }
507 }
508}
509#endif
510
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100511#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
512 static void
513handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
514{
515# ifdef FEAT_DIFF
516 if (wlv->filler_todo > 0)
517 {
518 // Draw "deleted" diff line(s).
519 if (char2cells(wp->w_fill_chars.diff) > 1)
520 {
521 wlv->c_extra = '-';
522 wlv->c_final = NUL;
523 }
524 else
525 {
526 wlv->c_extra = wp->w_fill_chars.diff;
527 wlv->c_final = NUL;
528 }
529# ifdef FEAT_RIGHTLEFT
530 if (wp->w_p_rl)
531 wlv->n_extra = wlv->col + 1;
532 else
533# endif
534 wlv->n_extra = wp->w_width - wlv->col;
535 wlv->char_attr = HL_ATTR(HLF_DED);
536 }
537# endif
538
539# ifdef FEAT_LINEBREAK
540 char_u *sbr = get_showbreak_value(wp);
541 if (*sbr != NUL && wlv->need_showbreak)
542 {
543 // Draw 'showbreak' at the start of each broken line.
544 wlv->p_extra = sbr;
545 wlv->c_extra = NUL;
546 wlv->c_final = NUL;
547 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100548 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100549 wlv->need_showbreak = FALSE;
550 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
551 // Correct end of highlighted area for 'showbreak',
552 // required when 'linebreak' is also set.
553 if (wlv->tocol == wlv->vcol)
554 wlv->tocol += wlv->n_extra;
555 // combine 'showbreak' with 'wincolor'
556 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
557# ifdef FEAT_SYN_HL
558 // combine 'showbreak' with 'cursorline'
559 if (wlv->cul_attr != 0)
560 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
561# endif
562 }
563# endif
564}
565#endif
566
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100567#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100568/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100569 * Return the cell size of virtual text after truncation.
570 */
571 static int
572textprop_size_after_trunc(
573 win_T *wp,
574 int flags, // TP_FLAG_ALIGN_*
575 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100576 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100577 char_u *text,
578 int *n_used_ptr)
579{
580 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100581 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100582 int len = (int)STRLEN(text);
583 int strsize = 0;
584 int n_used;
585
Bram Moolenaar7e017462022-10-11 21:02:09 +0100586 // if the remaining size is to small and 'wrap' is set we wrap anyway and
587 // use the next line
588 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100589 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100590 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100591 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100592 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
593 {
594 int clen = ptr2cells(text + n_used);
595
596 if (strsize + clen > space)
597 break;
598 strsize += clen;
599 }
600 *n_used_ptr = n_used;
601 return strsize;
602}
603
604/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100605 * Take care of padding, right-align and truncation of virtual text after a
606 * line.
607 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
608 * padding, right-align and truncation. Otherwise only the size is computed.
609 * When "n_attr" is NULL returns the number of screen cells used.
610 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100611 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100612 int
613text_prop_position(
614 win_T *wp,
615 textprop_T *tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100616 int vcol UNUSED, // current text column
617 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100618 int *n_extra, // nr of bytes for virtual text
619 char_u **p_extra, // virtual text
620 int *n_attr, // attribute cells, NULL if not used
621 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200622{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100623 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100624 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100625 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
626 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
627 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
628 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100629 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100630 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100631 int before = room; // spaces before the text
632 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100633 int n_used = *n_extra;
634 char_u *l = NULL;
635 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100636 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100637 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar1206c162022-10-10 15:40:04 +0100638 int cont_on_next_line = below && col_with_padding > win_col_off(wp)
639 && !wp->w_p_wrap;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200640
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100641 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100642 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100643 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100644 int skip_add = 0;
645
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100646 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100647 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100648 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100649 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100650 }
651 else
652 {
653 // Right-align: fill with before
654 if (right)
655 before -= cells;
656 if (before < 0
657 || !(right || below)
658 || (below
Bram Moolenaarccf28372022-10-10 21:10:03 +0100659 ? (col_with_padding <= col_off || !wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100660 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100661 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100662 if (right && (wrap
663 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100664 {
665 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100666 before = wp->w_width - col_off - strsize + room;
667 if (before < 0)
668 before = 0;
669 else
670 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100671 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100672 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100673 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100674 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100675 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100676 else if (below && before > 0)
677 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100678 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100679 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100680
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100681 // With 'nowrap' add one to show the "extends" character if needed (it
682 // doesn't show if the text just fits).
683 if (!wp->w_p_wrap
684 && n_used < *n_extra
685 && wp->w_lcs_chars.ext != NUL
686 && wp->w_p_list)
687 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100688 if (!wp->w_p_wrap && below && padding > 0)
689 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100690
691 // add 1 for NUL, 2 for when '…' is used
692 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100693 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100694 if (n_attr == NULL || l != NULL)
695 {
696 int off = 0;
697
698 if (n_attr != NULL)
699 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100700 vim_memset(l, ' ', before);
701 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100702 if (padding > 0)
703 {
704 vim_memset(l + off, ' ', padding);
705 off += padding;
706 }
707 vim_strncpy(l + off, *p_extra, n_used);
708 off += n_used;
709 }
710 else
711 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100712 off = before + after + padding + n_used;
713 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100714 }
715 if (n_attr != NULL)
716 {
717 if (n_used < *n_extra && wp->w_p_wrap)
718 {
719 char_u *lp = l + off - 1;
720
721 if (has_mbyte)
722 {
723 // change last character to '…'
724 lp -= (*mb_head_off)(l, lp);
725 STRCPY(lp, "…");
Bram Moolenaar13845c42022-10-09 15:26:03 +0100726 n_used = lp - l + 3 - before - padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100727 }
728 else
729 // change last character to '>'
730 *lp = '>';
731 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100732 else if (after > 0)
733 {
734 vim_memset(l + off, ' ', after);
735 l[off + after] = NUL;
736 }
737
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100738 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100739 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100740 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100741 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100742 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100743
744 // Add "skip_add" when starting a new line or wrapping,
745 // n_attr_skip will then be decremented in the number column.
746 *n_attr_skip = before + padding
747 + (cont_on_next_line || before > 0 ? skip_add : 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100748 }
749 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100750 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100751
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100752 if (n_attr == NULL)
753 return cells;
754 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200755}
756#endif
757
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100758/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100759 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100760 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
761 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100762 */
763 static void
764wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
765{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100766 if (wlv->row == 0 && wp->w_skipcol > 0
767#if defined(FEAT_LINEBREAK)
768 && *get_showbreak_value(wp) == NUL
769#endif
770 )
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100771 {
772 int off = (int)(current_ScreenLine - ScreenLines);
773
774 for (int i = 0; i < 3; ++i)
775 {
776 ScreenLines[off] = '<';
777 if (enc_utf8)
778 ScreenLinesUC[off] = 0;
779 ScreenAttrs[off] = HL_ATTR(HLF_AT);
780 ++off;
781 }
782 }
783
784 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
785 negative_width ? -wp->w_width : wp->w_width,
786 wlv->screen_line_flags);
787}
788
789/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100790 * Called when finished with the line: draw the screen line and handle any
791 * highlighting until the right of the window.
792 */
793 static void
794draw_screen_line(win_T *wp, winlinevars_T *wlv)
795{
796#ifdef FEAT_SYN_HL
797 long v;
798
799 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
800 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100801 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100802 else
803 v = wp->w_leftcol;
804
805 // check if line ends before left margin
806 if (wlv->vcol < v + wlv->col - win_col_off(wp))
807 wlv->vcol = v + wlv->col - win_col_off(wp);
808# ifdef FEAT_CONCEAL
809 // Get rid of the boguscols now, we want to draw until the right
810 // edge for 'cursorcolumn'.
811 wlv->col -= wlv->boguscols;
812 wlv->boguscols = 0;
813# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
814# else
815# define VCOL_HLC (wlv->vcol)
816# endif
817
818 if (wlv->draw_color_col)
819 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
820
821 if (((wp->w_p_cuc
822 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
823 && (int)wp->w_virtcol <
824 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
825 && wlv->lnum != wp->w_cursor.lnum)
826 || wlv->draw_color_col
827 || wlv->win_attr != 0)
828# ifdef FEAT_RIGHTLEFT
829 && !wp->w_p_rl
830# endif
831 )
832 {
833 int rightmost_vcol = 0;
834 int i;
835
836 if (wp->w_p_cuc)
837 rightmost_vcol = wp->w_virtcol;
838 if (wlv->draw_color_col)
839 // determine rightmost colorcolumn to possibly draw
840 for (i = 0; wlv->color_cols[i] >= 0; ++i)
841 if (rightmost_vcol < wlv->color_cols[i])
842 rightmost_vcol = wlv->color_cols[i];
843
844 while (wlv->col < wp->w_width)
845 {
846 ScreenLines[wlv->off] = ' ';
847 if (enc_utf8)
848 ScreenLinesUC[wlv->off] = 0;
849 ScreenCols[wlv->off] = MAXCOL;
850 ++wlv->col;
851 if (wlv->draw_color_col)
852 wlv->draw_color_col = advance_color_col(
853 VCOL_HLC, &wlv->color_cols);
854
855 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
856 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
857 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
858 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
859 else
860 ScreenAttrs[wlv->off++] = wlv->win_attr;
861
862 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
863 break;
864
865 ++wlv->vcol;
866 }
867 }
868#endif
869
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100870 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100871 ++wlv->row;
872 ++wlv->screen_row;
873}
874#undef VCOL_HLC
875
876/*
877 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100878 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100879 */
880 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100881win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100882{
883 wlv->col = 0;
884 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
885
886#ifdef FEAT_RIGHTLEFT
887 if (wp->w_p_rl)
888 {
889 // Rightleft window: process the text in the normal direction, but put
890 // it in current_ScreenLine[] from right to left. Start at the
891 // rightmost column of the window.
892 wlv->col = wp->w_width - 1;
893 wlv->off += wlv->col;
894 wlv->screen_line_flags |= SLF_RIGHTLEFT;
895 }
896#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100897 if (save_extra)
898 {
899 // reset the drawing state for the start of a wrapped line
900 wlv->draw_state = WL_START;
901 wlv->saved_n_extra = wlv->n_extra;
902 wlv->saved_p_extra = wlv->p_extra;
903 wlv->saved_c_extra = wlv->c_extra;
904 wlv->saved_c_final = wlv->c_final;
905#ifdef FEAT_SYN_HL
906 if (!(wlv->cul_screenline
907# ifdef FEAT_DIFF
908 && wlv->diff_hlf == (hlf_T)0
909# endif
910 ))
911 wlv->saved_char_attr = wlv->char_attr;
912 else
913#endif
914 wlv->saved_char_attr = 0;
915 wlv->n_extra = 0;
916 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100917}
918
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200919/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100920 * Called when wlv->draw_state is set to WL_LINE.
921 */
922 static void
923win_line_continue(winlinevars_T *wlv)
924{
925 if (wlv->saved_n_extra > 0)
926 {
927 // Continue item from end of wrapped line.
928 wlv->n_extra = wlv->saved_n_extra;
929 wlv->c_extra = wlv->saved_c_extra;
930 wlv->c_final = wlv->saved_c_final;
931 wlv->p_extra = wlv->saved_p_extra;
932 wlv->char_attr = wlv->saved_char_attr;
933 }
934 else
935 wlv->char_attr = wlv->win_attr;
936}
937
938/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200939 * Display line "lnum" of window 'wp' on the screen.
940 * Start at row "startrow", stop when "endrow" is reached.
941 * wp->w_virtcol needs to be valid.
942 *
943 * Return the number of last row the line occupies.
944 */
945 int
946win_line(
947 win_T *wp,
948 linenr_T lnum,
949 int startrow,
950 int endrow,
951 int nochange UNUSED, // not updating for changed text
952 int number_only) // only update the number column
953{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100954 winlinevars_T wlv; // variables passed between functions
955
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200956 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100957 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200958 char_u *line; // current line
959 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200960
Bram Moolenaar1306b362022-08-06 15:59:06 +0100961#ifdef FEAT_PROP_POPUP
962 char_u *p_extra_free2 = NULL; // another p_extra to be freed
963#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200964 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000965#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000966 int in_linebreak = FALSE; // n_extra set for showing linebreak
967#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200968 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100969 // displaying eol at end-of-line
970 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000971 int lcs_prec_todo = wp->w_lcs_chars.prec;
972 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200973
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100974 int n_attr = 0; // chars with special attr
975 int n_attr_skip = 0; // chars to skip before using extra_attr
976 int saved_attr2 = 0; // char_attr saved for n_attr
977 int n_attr3 = 0; // chars with overruling special attr
978 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200979
Bram Moolenaarcd105412022-10-10 19:50:42 +0100980 int n_skip = 0; // nr of cells to skip for 'nowrap' or
981 // concealing
Bram Moolenaard3283fb2022-10-10 20:33:25 +0100982#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +0100983 int skip_cells = 0; // nr of cells to skip for virtual text
984 // after the line, when w_skipcol is
985 // larger than the text length
Bram Moolenaard3283fb2022-10-10 20:33:25 +0100986#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200987
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200988 int fromcol_prev = -2; // start of inverting after cursor
989 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200990 int lnum_in_visual_area = FALSE;
991 pos_T pos;
992 long v;
993
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200994 int attr_pri = FALSE; // char_attr has priority
995 int area_highlighting = FALSE; // Visual or incsearch highlighting
996 // in this line
997 int vi_attr = 0; // attributes for Visual and incsearch
998 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200999 int area_attr = 0; // attributes desired by highlighting
1000 int search_attr = 0; // attributes desired by 'hlsearch'
1001#ifdef FEAT_SYN_HL
1002 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1003 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001004 int prev_syntax_col = -1; // column of prev_syntax_attr
1005 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001006 int has_syntax = FALSE; // this buffer has syntax highl.
1007 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001008#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001009#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001010 int text_prop_count;
1011 int text_prop_next = 0; // next text property to use
1012 textprop_T *text_props = NULL;
1013 int *text_prop_idxs = NULL;
1014 int text_props_active = 0;
1015 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001016 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001017 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001018 int text_prop_attr_comb = 0; // text_prop_attr combined with
1019 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001020 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001021 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001022 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001023 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001024 int saved_search_attr = 0; // search_attr to be used when n_extra
1025 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001026 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001027#endif
1028#ifdef FEAT_SPELL
1029 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001030 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001031# define SPWORDLEN 150
1032 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1033 int nextlinecol = 0; // column where nextline[] starts
1034 int nextline_idx = 0; // index in nextline[] where next line
1035 // starts
1036 int spell_attr = 0; // attributes desired by spelling
1037 int word_end = 0; // last byte with same spell_attr
1038 static linenr_T checked_lnum = 0; // line number for "checked_col"
1039 static int checked_col = 0; // column in "checked_lnum" up to which
1040 // there are no spell errors
1041 static int cap_col = -1; // column to check for Cap word
1042 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1043 int cur_checked_col = 0; // checked column for current line
1044#endif
1045 int extra_check = 0; // has extra highlighting
1046 int multi_attr = 0; // attributes desired by multibyte
1047 int mb_l = 1; // multi-byte byte length
1048 int mb_c = 0; // decoded multi-byte character
1049 int mb_utf8 = FALSE; // screen char is UTF-8 char
1050 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001051#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001052 int change_start = MAXCOL; // first col of changed area
1053 int change_end = -1; // last col of changed area
1054#endif
1055 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001056 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001057 int in_multispace = FALSE; // in multiple consecutive spaces
1058 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001059#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
1060 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
1061# define LINE_ATTR
1062 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +01001063 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001064#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001065 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001066 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001067#ifdef FEAT_ARABIC
1068 int prev_c = 0; // previous Arabic character
1069 int prev_c1 = 0; // first composing char for prev_c
1070#endif
1071#if defined(LINE_ATTR)
1072 int did_line_attr = 0;
1073#endif
1074#ifdef FEAT_TERMINAL
1075 int get_term_attr = FALSE;
1076#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001077
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001078#ifdef FEAT_SYN_HL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001079 // margin columns for the screen line, needed for when 'cursorlineopt'
1080 // contains "screenline"
1081 int left_curline_col = 0;
1082 int right_curline_col = 0;
1083#endif
1084
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001085#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1086 int feedback_col = 0;
1087 int feedback_old_attr = -1;
1088#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001089
1090#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1091 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001092 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001093#endif
1094#ifdef FEAT_CONCEAL
1095 int syntax_flags = 0;
1096 int syntax_seqnr = 0;
1097 int prev_syntax_id = 0;
1098 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1099 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001100 int did_wcol = FALSE;
1101 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001102# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001103# define FIX_FOR_BOGUSCOLS \
1104 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001105 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001106 wlv.vcol -= wlv.vcol_off; \
1107 wlv.vcol_off = 0; \
1108 wlv.col -= wlv.boguscols; \
1109 old_boguscols = wlv.boguscols; \
1110 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001111 }
1112#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001113# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001114#endif
1115
1116 if (startrow > endrow) // past the end already!
1117 return startrow;
1118
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001119 CLEAR_FIELD(wlv);
1120
1121 wlv.lnum = lnum;
1122 wlv.startrow = startrow;
1123 wlv.row = startrow;
1124 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001125 wlv.fromcol = -10;
1126 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001127#ifdef FEAT_LINEBREAK
1128 wlv.vcol_sbr = -1;
1129#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001130
1131 if (!number_only)
1132 {
1133 // To speed up the loop below, set extra_check when there is linebreak,
1134 // trailing white space and/or syntax processing to be done.
1135#ifdef FEAT_LINEBREAK
1136 extra_check = wp->w_p_lbr;
1137#endif
1138#ifdef FEAT_SYN_HL
1139 if (syntax_present(wp) && !wp->w_s->b_syn_error
1140# ifdef SYN_TIME_LIMIT
1141 && !wp->w_s->b_syn_slow
1142# endif
1143 )
1144 {
1145 // Prepare for syntax highlighting in this line. When there is an
1146 // error, stop syntax highlighting.
1147 save_did_emsg = did_emsg;
1148 did_emsg = FALSE;
1149 syntax_start(wp, lnum);
1150 if (did_emsg)
1151 wp->w_s->b_syn_error = TRUE;
1152 else
1153 {
1154 did_emsg = save_did_emsg;
1155#ifdef SYN_TIME_LIMIT
1156 if (!wp->w_s->b_syn_slow)
1157#endif
1158 {
1159 has_syntax = TRUE;
1160 extra_check = TRUE;
1161 }
1162 }
1163 }
1164
1165 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001166 wlv.color_cols = wp->w_p_cc_cols;
1167 if (wlv.color_cols != NULL)
1168 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001169#endif
1170
1171#ifdef FEAT_TERMINAL
1172 if (term_show_buffer(wp->w_buffer))
1173 {
1174 extra_check = TRUE;
1175 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001176 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001177 }
1178#endif
1179
1180#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001181 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001182 {
1183 // Prepare for spell checking.
1184 has_spell = TRUE;
1185 extra_check = TRUE;
1186
1187 // Get the start of the next line, so that words that wrap to the
1188 // next line are found too: "et<line-break>al.".
1189 // Trick: skip a few chars for C/shell/Vim comments
1190 nextline[SPWORDLEN] = NUL;
1191 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1192 {
1193 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1194 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1195 }
1196
1197 // When a word wrapped from the previous line the start of the
1198 // current line is valid.
1199 if (lnum == checked_lnum)
1200 cur_checked_col = checked_col;
1201 checked_lnum = 0;
1202
1203 // When there was a sentence end in the previous line may require a
1204 // word starting with capital in this line. In line 1 always check
1205 // the first word.
1206 if (lnum != capcol_lnum)
1207 cap_col = -1;
1208 if (lnum == 1)
1209 cap_col = 0;
1210 capcol_lnum = 0;
1211 }
1212#endif
1213
1214 // handle Visual active in this window
1215 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1216 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001217 pos_T *top, *bot;
1218
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001219 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1220 {
1221 // Visual is after curwin->w_cursor
1222 top = &curwin->w_cursor;
1223 bot = &VIsual;
1224 }
1225 else
1226 {
1227 // Visual is before curwin->w_cursor
1228 top = &VIsual;
1229 bot = &curwin->w_cursor;
1230 }
1231 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1232 if (VIsual_mode == Ctrl_V)
1233 {
1234 // block mode
1235 if (lnum_in_visual_area)
1236 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001237 wlv.fromcol = wp->w_old_cursor_fcol;
1238 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001239 }
1240 }
1241 else
1242 {
1243 // non-block mode
1244 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001245 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001246 else if (lnum == top->lnum)
1247 {
1248 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001249 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001250 else
1251 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001252 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001253 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001254 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001255 }
1256 }
1257 if (VIsual_mode != 'V' && lnum == bot->lnum)
1258 {
1259 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1260 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001261 wlv.fromcol = -10;
1262 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001263 }
1264 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001265 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001266 else
1267 {
1268 pos = *bot;
1269 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001270 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1271 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001272 else
1273 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001274 getvvcol(wp, &pos, NULL, NULL,
1275 (colnr_T *)&wlv.tocol);
1276 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001277 }
1278 }
1279 }
1280 }
1281
1282 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001283 if (!highlight_match && lnum == curwin->w_cursor.lnum
1284 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001285#ifdef FEAT_GUI
1286 && !gui.in_use
1287#endif
1288 )
1289 noinvcur = TRUE;
1290
1291 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001292 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001293 {
1294 area_highlighting = TRUE;
1295 vi_attr = HL_ATTR(HLF_V);
1296#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1297 if ((clip_star.available && !clip_star.owned
1298 && clip_isautosel_star())
1299 || (clip_plus.available && !clip_plus.owned
1300 && clip_isautosel_plus()))
1301 vi_attr = HL_ATTR(HLF_VNC);
1302#endif
1303 }
1304 }
1305
1306 // handle 'incsearch' and ":s///c" highlighting
1307 else if (highlight_match
1308 && wp == curwin
1309 && lnum >= curwin->w_cursor.lnum
1310 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1311 {
1312 if (lnum == curwin->w_cursor.lnum)
1313 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001314 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001315 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001316 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001317 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1318 {
1319 pos.lnum = lnum;
1320 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001321 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001322 }
1323 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001324 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001325 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001326 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1327 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001328 area_highlighting = TRUE;
1329 vi_attr = HL_ATTR(HLF_I);
1330 }
1331 }
1332
1333#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001334 wlv.filler_lines = diff_check(wp, lnum);
1335 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001336 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001337 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001338 {
1339 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001340 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001341 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001342 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001343 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001344 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001345 }
1346 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001347 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001348 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001349 area_highlighting = TRUE;
1350 }
1351 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001352 wlv.filler_lines = wp->w_topfill;
1353 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001354#endif
1355
1356#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001357 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001358 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001359 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001360#endif
1361
1362#ifdef LINE_ATTR
1363# ifdef FEAT_SIGNS
1364 // If this line has a sign with line highlighting set line_attr.
1365 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001366 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001367# endif
1368# if defined(FEAT_QUICKFIX)
1369 // Highlight the current line in the quickfix window.
1370 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1371 line_attr = HL_ATTR(HLF_QFL);
1372# endif
1373 if (line_attr != 0)
1374 area_highlighting = TRUE;
1375#endif
1376
1377 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1378 ptr = line;
1379
1380#ifdef FEAT_SPELL
1381 if (has_spell && !number_only)
1382 {
1383 // For checking first word with a capital skip white space.
1384 if (cap_col == 0)
1385 cap_col = getwhitecols(line);
1386
1387 // To be able to spell-check over line boundaries copy the end of the
1388 // current line into nextline[]. Above the start of the next line was
1389 // copied to nextline[SPWORDLEN].
1390 if (nextline[SPWORDLEN] == NUL)
1391 {
1392 // No next line or it is empty.
1393 nextlinecol = MAXCOL;
1394 nextline_idx = 0;
1395 }
1396 else
1397 {
1398 v = (long)STRLEN(line);
1399 if (v < SPWORDLEN)
1400 {
1401 // Short line, use it completely and append the start of the
1402 // next line.
1403 nextlinecol = 0;
1404 mch_memmove(nextline, line, (size_t)v);
1405 STRMOVE(nextline + v, nextline + SPWORDLEN);
1406 nextline_idx = v + 1;
1407 }
1408 else
1409 {
1410 // Long line, use only the last SPWORDLEN bytes.
1411 nextlinecol = v - SPWORDLEN;
1412 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1413 nextline_idx = SPWORDLEN + 1;
1414 }
1415 }
1416 }
1417#endif
1418
1419 if (wp->w_p_list)
1420 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001421 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001422 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001423 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001424 || wp->w_lcs_chars.trail
1425 || wp->w_lcs_chars.lead
1426 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001427 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001428
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001429 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001430 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001431 {
1432 trailcol = (colnr_T)STRLEN(ptr);
1433 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1434 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001435 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001436 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001437 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001438 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001439 {
1440 leadcol = 0;
1441 while (VIM_ISWHITE(ptr[leadcol]))
1442 ++leadcol;
1443 if (ptr[leadcol] == NUL)
1444 // in a line full of spaces all of them are treated as trailing
1445 leadcol = (colnr_T)0;
1446 else
1447 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001448 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001449 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001450 }
1451
Bram Moolenaard7657e92022-09-20 18:59:30 +01001452 wlv.wcr_attr = get_wcr_attr(wp);
1453 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001454 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001455 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001456 area_highlighting = TRUE;
1457 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001458
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001459#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001460 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001461 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001462#endif
1463
1464 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1465 // first character to be displayed.
1466 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001467 v = startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001468 else
1469 v = wp->w_leftcol;
1470 if (v > 0 && !number_only)
1471 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001472 char_u *prev_ptr = ptr;
1473 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001474 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001475
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001476 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001477 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001478 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001479 charsize = win_lbr_chartabsize(&cts, NULL);
1480 cts.cts_vcol += charsize;
1481 prev_ptr = cts.cts_ptr;
1482 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001483 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001484 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001485 ptr = cts.cts_ptr;
1486 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001487
1488 // When:
1489 // - 'cuc' is set, or
1490 // - 'colorcolumn' is set, or
1491 // - 'virtualedit' is set, or
1492 // - the visual mode is active,
1493 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001494 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001495#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001496 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001497#endif
1498 virtual_active() ||
1499 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001500 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001501
1502 // Handle a character that's not completely on the screen: Put ptr at
1503 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001504 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001505 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001506 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001507 ptr = prev_ptr;
1508 // If the character fits on the screen, don't need to skip it.
1509 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001510 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1511 && wlv.col == 0)
1512 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001513 }
1514
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001515#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001516 // If there the text doesn't reach to the desired column, need to skip
1517 // "skip_cells" cells when virtual text follows.
1518 if (!wp->w_p_wrap && v > wlv.vcol)
1519 skip_cells = v - wlv.vcol;
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001520#endif
Bram Moolenaarcd105412022-10-10 19:50:42 +01001521
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001522 // Adjust for when the inverted text is before the screen,
1523 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001524 if (wlv.tocol <= wlv.vcol)
1525 wlv.fromcol = 0;
1526 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1527 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001528
1529#ifdef FEAT_LINEBREAK
1530 // When w_skipcol is non-zero, first line needs 'showbreak'
1531 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001532 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001533#endif
1534#ifdef FEAT_SPELL
1535 // When spell checking a word we need to figure out the start of the
1536 // word and if it's badly spelled or not.
1537 if (has_spell)
1538 {
1539 int len;
1540 colnr_T linecol = (colnr_T)(ptr - line);
1541 hlf_T spell_hlf = HLF_COUNT;
1542
1543 pos = wp->w_cursor;
1544 wp->w_cursor.lnum = lnum;
1545 wp->w_cursor.col = linecol;
1546 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1547
1548 // spell_move_to() may call ml_get() and make "line" invalid
1549 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1550 ptr = line + linecol;
1551
1552 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1553 {
1554 // no bad word found at line start, don't check until end of a
1555 // word
1556 spell_hlf = HLF_COUNT;
1557 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1558 }
1559 else
1560 {
1561 // bad word found, use attributes until end of word
1562 word_end = wp->w_cursor.col + len + 1;
1563
1564 // Turn index into actual attributes.
1565 if (spell_hlf != HLF_COUNT)
1566 spell_attr = highlight_attr[spell_hlf];
1567 }
1568 wp->w_cursor = pos;
1569
1570# ifdef FEAT_SYN_HL
1571 // Need to restart syntax highlighting for this line.
1572 if (has_syntax)
1573 syntax_start(wp, lnum);
1574# endif
1575 }
1576#endif
1577 }
1578
1579 // Correct highlighting for cursor that can't be disabled.
1580 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001581 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001582 {
1583 if (noinvcur)
1584 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001585 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001586 {
1587 // highlighting starts at cursor, let it start just after the
1588 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001589 fromcol_prev = wlv.fromcol;
1590 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001591 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001592 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001593 // restart highlighting after the cursor
1594 fromcol_prev = wp->w_virtcol;
1595 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001596 if (wlv.fromcol >= wlv.tocol)
1597 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001598 }
1599
1600#ifdef FEAT_SEARCH_EXTRA
1601 if (!number_only)
1602 {
1603 v = (long)(ptr - line);
1604 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1605 &line, &screen_search_hl,
1606 &search_attr);
1607 ptr = line + v; // "line" may have been updated
1608 }
1609#endif
1610
1611#ifdef FEAT_SYN_HL
1612 // Cursor line highlighting for 'cursorline' in the current window.
1613 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1614 {
1615 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001616 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001617 if (!(wp == curwin && VIsual_active)
1618 && wp->w_p_culopt_flags != CULOPT_NBR)
1619 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001620 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001621 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1622
1623 // Only set line_attr here when "screenline" is not present in
1624 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001625 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001626 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001627 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001628# ifdef FEAT_SIGNS
1629 // Combine the 'cursorline' and sign highlighting, depending on
1630 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001631 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001632 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001633 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001634 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001635 else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001636 line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001637 }
1638 else
1639# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001640# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001641 // let the line attribute overrule 'cursorline', otherwise
1642 // it disappears when both have background set;
1643 // 'cursorline' can use underline or bold to make it show
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001644 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001645# else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001646 line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001647# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001648 }
1649 else
1650 {
1651 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001652 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1653 }
1654 area_highlighting = TRUE;
1655 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001656 }
1657#endif
1658
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001659#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001660 {
1661 char_u *prop_start;
1662
1663 text_prop_count = get_text_props(wp->w_buffer, lnum,
1664 &prop_start, FALSE);
1665 if (text_prop_count > 0)
1666 {
1667 // Make a copy of the properties, so that they are properly
1668 // aligned.
1669 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1670 if (text_props != NULL)
1671 mch_memmove(text_props, prop_start,
1672 text_prop_count * sizeof(textprop_T));
1673
1674 // Allocate an array for the indexes.
1675 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001676 if (text_prop_idxs == NULL)
1677 VIM_CLEAR(text_props);
1678
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001679 if (text_props != NULL)
1680 {
1681 area_highlighting = TRUE;
1682 extra_check = TRUE;
1683 for (int i = 0; i < text_prop_count; ++i)
1684 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1685 ++wlv.text_prop_above_count;
1686 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001687 }
1688 }
1689#endif
1690
Bram Moolenaar1306b362022-08-06 15:59:06 +01001691 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001692
1693 // Repeat for the whole displayed line.
1694 for (;;)
1695 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001696 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001697#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001698 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001699#endif
1700#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001701 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001702#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001703
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001704 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001705 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001706 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001707#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001708 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001709 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001710 wlv.cul_attr = 0;
zeertzjq4f33bc22021-08-05 17:57:02 +02001711 line_attr = line_attr_save;
1712 }
1713#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001714 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001715 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001716 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001717 if (cmdwin_type != 0 && wp == curwin)
1718 {
1719 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001720 wlv.n_extra = 1;
1721 wlv.c_extra = cmdwin_type;
1722 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001723 wlv.char_attr =
1724 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001725 }
1726 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001727#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001728 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001729 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001730 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001731 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001732 }
1733#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001734#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001735 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001736 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001737 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001738 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001739 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001740 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001741 }
1742#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001743 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001744 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001745 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001746 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001747 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001748 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001749#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001750 // Check if 'breakindent' applies and show it.
1751 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1752 if (wlv.n_extra == 0)
1753 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001754#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001755#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001756 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001757 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001758 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001759 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001760 }
1761#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001762 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001763 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001764 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001765 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001766 }
1767 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001768
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001769#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001770 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001771 && wlv.vcol >= left_curline_col
1772 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001773 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001774 wlv.cul_attr = HL_ATTR(HLF_CUL);
1775 line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001776 }
1777#endif
1778
1779 // When still displaying '$' of change command, stop at cursor.
1780 // When only displaying the (relative) line number and that's done,
1781 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001782 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001783 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001784 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001785#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001786 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001787#endif
1788 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001789 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001790 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001791 // Pretend we have finished updating the window. Except when
1792 // 'cursorcolumn' is set.
1793#ifdef FEAT_SYN_HL
1794 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001795 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001796 else
1797#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001798 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001799 break;
1800 }
1801
Bram Moolenaar1306b362022-08-06 15:59:06 +01001802 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001803 {
1804 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001805 if (wlv.vcol == wlv.fromcol
1806 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1807 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001808 && (*mb_ptr2cells)(ptr) > 1)
1809 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001810 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001811 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001812 area_attr = vi_attr; // start highlighting
1813 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001814 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001815 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001816 area_attr = 0; // stop highlighting
1817
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001818#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001819 if (text_props != NULL)
1820 {
1821 int pi;
1822 int bcol = (int)(ptr - line);
1823
Bram Moolenaar1306b362022-08-06 15:59:06 +01001824 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001825# ifdef FEAT_LINEBREAK
1826 && !in_linebreak
1827# endif
1828 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001829 --bcol; // still working on the previous char, e.g. Tab
1830
1831 // Check if any active property ends.
1832 for (pi = 0; pi < text_props_active; ++pi)
1833 {
1834 int tpi = text_prop_idxs[pi];
1835
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001836 if (text_props[tpi].tp_col != MAXCOL
1837 && bcol >= text_props[tpi].tp_col - 1
1838 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001839 {
1840 if (pi + 1 < text_props_active)
1841 mch_memmove(text_prop_idxs + pi,
1842 text_prop_idxs + pi + 1,
1843 sizeof(int)
1844 * (text_props_active - (pi + 1)));
1845 --text_props_active;
1846 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001847# ifdef FEAT_LINEBREAK
1848 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001849 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001850 syntax_attr = 0;
1851# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001852 }
1853 }
1854
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001855# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001856 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001857 // not on the next char yet, don't start another prop
1858 --bcol;
1859# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001860 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001861 // With 'nowrap' and not in the first screen line only "below"
1862 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001863 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001864 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001865 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001866 && (wp->w_p_wrap
1867 || wlv.row == startrow
1868 || (text_props[text_prop_next].tp_flags
1869 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001870 || (bcol == 0 &&
1871 (text_props[text_prop_next].tp_flags
1872 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001873 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001874 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001875 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001876 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1877 {
1878 // first display the '$' after the line
1879 text_prop_follows = TRUE;
1880 break;
1881 }
1882 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001883 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001884 + text_props[text_prop_next].tp_len)
1885 text_prop_idxs[text_props_active++] = text_prop_next;
1886 ++text_prop_next;
1887 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001888
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001889 if (wlv.n_extra == 0 || !extra_for_textprop)
1890 {
1891 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001892 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001893 text_prop_flags = 0;
1894 text_prop_type = NULL;
1895 text_prop_id = 0;
1896 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001897 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001898 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001899 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001900 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001901 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001902
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001903 // Sort the properties on priority and/or starting last.
1904 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001905 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001906 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001907 sort_text_props(wp->w_buffer, text_props,
1908 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001909
1910 for (pi = 0; pi < text_props_active; ++pi)
1911 {
1912 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001913 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001914 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01001915 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001916
Bram Moolenaarcd105412022-10-10 19:50:42 +01001917 // Only use a text property that can be displayed.
1918 // Skip "after" properties when wrap is off and at the
1919 // end of the window.
1920 if (pt != NULL
1921 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
1922 && tp->tp_id != -MAXCOL
1923 && !(tp->tp_id < 0
1924 && !wp->w_p_wrap
1925 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
1926 | TP_FLAG_ALIGN_ABOVE
1927 | TP_FLAG_ALIGN_BELOW)) == 0
1928 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001929 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001930 if (pt->pt_hl_id > 0)
1931 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001932 text_prop_type = pt;
1933 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001934 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001935 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001936 text_prop_flags = pt->pt_flags;
1937 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001938 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001939 }
1940 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001941 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001942 && -text_prop_id
1943 <= wp->w_buffer->b_textprop_text.ga_len)
1944 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001945 textprop_T *tp = &text_props[used_tpi];
1946 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001947 ->b_textprop_text.ga_data)[
1948 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001949 int above = (tp->tp_flags
1950 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01001951 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001952
1953 // reset the ID in the copy to avoid it being used
1954 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001955 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001956
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001957 if (p != NULL)
1958 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001959 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001960 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001961 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001962 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001963 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1964 int padding = tp->tp_col == MAXCOL
1965 && tp->tp_len > 1
1966 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001967
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001968 // Insert virtual text before the current
1969 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001970 wlv.p_extra = p;
1971 wlv.c_extra = NUL;
1972 wlv.c_final = NUL;
1973 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001974 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001975 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001976 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001977 // restore search_attr and area_attr when n_extra
1978 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001979 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001980 saved_area_attr = area_attr;
1981 search_attr = 0;
1982 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001983 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001984 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001985 if (*ptr == NUL)
1986 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001987 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001988#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001989 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001990 {
1991 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001992 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001993 wlv.need_showbreak = FALSE;
1994 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001995 }
1996#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001997 if ((right || above || below || !wrap
1998 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001999 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002000 char_u *prev_p_extra = wlv.p_extra;
2001 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002002
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002003 // Take care of padding, right-align and
2004 // truncation.
2005 // Shared with win_lbr_chartabsize(), must do
2006 // exactly the same.
2007 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002008 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002009 wlv.col,
2010 &wlv.n_extra, &wlv.p_extra,
2011 &n_attr, &n_attr_skip);
2012 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002013 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002014 // wlv.p_extra was allocated
2015 vim_free(p_extra_free2);
2016 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002017 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002018
Bram Moolenaara4abe512022-09-15 19:44:09 +01002019 if (lcs_eol_one < 0 && wlv.col
2020 + wlv.n_extra - 2 > wp->w_width)
2021 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002022 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002023
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002024 // When 'wrap' is off then for "below" we need
2025 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002026 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002027 {
2028 draw_screen_line(wp, &wlv);
2029
2030 // When line got too long for screen break
2031 // here.
2032 if (wlv.row == endrow)
2033 {
2034 ++wlv.row;
2035 break;
2036 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002037 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002038 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002039 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002040 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002041 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002042
Bram Moolenaarcd105412022-10-10 19:50:42 +01002043 // If the text didn't reach until the first window
2044 // column we need to skip cells.
2045 if (skip_cells > 0)
2046 {
2047 if (wlv.n_extra > skip_cells)
2048 {
2049 wlv.n_extra -= skip_cells;
2050 wlv.p_extra += skip_cells;
2051 n_attr_skip -= skip_cells;
2052 if (n_attr_skip < 0)
2053 n_attr_skip = 0;
2054 skip_cells = 0;
2055 }
2056 else
2057 {
2058 // the whole text is left of the window, drop
2059 // it and advance to the next one
2060 skip_cells -= wlv.n_extra;
2061 wlv.n_extra = 0;
2062 n_attr_skip = 0;
2063 bail_out = TRUE;
2064 }
2065 }
2066
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002067 // If another text prop follows the condition below at
2068 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002069 // If this is an "above" text prop and 'nowrap' the we
2070 // must wrap anyway.
2071 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002072 text_prop_follows |= other_tpi != -1
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002073 && (wp->w_p_wrap
2074 || (text_props[other_tpi].tp_flags
2075 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002076
2077 if (bail_out)
2078 // starting a new line for "below"
2079 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002080 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002081 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002082 else if (text_prop_next < text_prop_count
2083 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002084 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2085 || (!wp->w_p_wrap
2086 && wlv.col == wp->w_width - 1
2087 && (text_props[text_prop_next].tp_flags
2088 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002089 // When at last-but-one character and a text property
2090 // follows after it, we may need to flush the line after
2091 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002092 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002093 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002094 }
2095#endif
2096
Bram Moolenaare38fc862022-08-11 17:24:50 +01002097#ifdef FEAT_SEARCH_EXTRA
2098 if (wlv.n_extra == 0)
2099 {
2100 // Check for start/end of 'hlsearch' and other matches.
2101 // After end, check for start/end of next match.
2102 // When another match, have to check for start again.
2103 v = (long)(ptr - line);
2104 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2105 &screen_search_hl, &has_match_conc,
2106 &match_conc, did_line_attr, lcs_eol_one,
2107 &on_last_col);
2108 ptr = line + v; // "line" may have been changed
2109 prev_ptr = ptr;
2110
2111 // Do not allow a conceal over EOL otherwise EOL will be missed
2112 // and bad things happen.
2113 if (*ptr == NUL)
2114 has_match_conc = 0;
2115 }
2116#endif
2117
2118#ifdef FEAT_DIFF
2119 if (wlv.diff_hlf != (hlf_T)0)
2120 {
2121 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2122 && wlv.n_extra == 0)
2123 wlv.diff_hlf = HLF_TXD; // changed text
2124 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2125 && wlv.n_extra == 0)
2126 wlv.diff_hlf = HLF_CHD; // changed line
2127 line_attr = HL_ATTR(wlv.diff_hlf);
2128 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2129 && wp->w_p_culopt_flags != CULOPT_NBR
2130 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2131 && wlv.vcol <= right_curline_col)))
2132 line_attr = hl_combine_attr(
2133 line_attr, HL_ATTR(HLF_CUL));
2134 }
2135#endif
2136
Bram Moolenaara74fda62019-10-19 17:38:03 +02002137#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002138 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002139 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002140 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002141# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002142 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002143 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002144# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002145 // Get syntax attribute.
2146 if (has_syntax)
2147 {
2148 // Get the syntax attribute for the character. If there
2149 // is an error, disable syntax highlighting.
2150 save_did_emsg = did_emsg;
2151 did_emsg = FALSE;
2152
2153 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002154 if (v == prev_syntax_col)
2155 // at same column again
2156 syntax_attr = prev_syntax_attr;
2157 else
2158 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002159# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002160 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002161# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002162 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002163# ifdef FEAT_SPELL
2164 has_spell ? &can_spell :
2165# endif
2166 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002167 prev_syntax_col = v;
2168 prev_syntax_attr = syntax_attr;
2169 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002170
Bram Moolenaar34390282019-10-16 14:38:26 +02002171 if (did_emsg)
2172 {
2173 wp->w_s->b_syn_error = TRUE;
2174 has_syntax = FALSE;
2175 syntax_attr = 0;
2176 }
2177 else
2178 did_emsg = save_did_emsg;
2179# ifdef SYN_TIME_LIMIT
2180 if (wp->w_s->b_syn_slow)
2181 has_syntax = FALSE;
2182# endif
2183
2184 // Need to get the line again, a multi-line regexp may
2185 // have made it invalid.
2186 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2187 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002188 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002189# ifdef FEAT_CONCEAL
2190 // no concealing past the end of the line, it interferes
2191 // with line highlighting
2192 if (*ptr == NUL)
2193 syntax_flags = 0;
2194 else
2195 syntax_flags = get_syntax_info(&syntax_seqnr);
2196# endif
2197 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002198 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002199# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002200 // Combine text property highlight into syntax highlight.
2201 if (text_prop_type != NULL)
2202 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002203 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002204 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2205 else
2206 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002207 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002208 }
2209# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002210#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002211
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002212 // Decide which of the highlight attributes to use.
2213 attr_pri = TRUE;
2214#ifdef LINE_ATTR
2215 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002216 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002217 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002218 if (!highlight_match)
2219 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002220 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002221# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002222 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002223# endif
2224 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002225 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002226 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002227 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002228# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002229 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002230# endif
2231 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002232 else if (line_attr != 0
2233 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2234 || wlv.vcol < wlv.fromcol
2235 || vcol_prev < fromcol_prev
2236 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002237 {
2238 // Use line_attr when not in the Visual or 'incsearch' area
2239 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002240# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002241 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002242# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002243 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002244# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002245 attr_pri = FALSE;
2246 }
2247#else
2248 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002249 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002250 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002251 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002252#endif
2253 else
2254 {
2255 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002256#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002257 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002258#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002259 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002260#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002261 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002262#ifdef FEAT_PROP_POPUP
2263 // override with text property highlight when "override" is TRUE
2264 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002265 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002266#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002267 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002268
2269 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002270 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002271 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002272 if (wlv.char_attr == 0)
2273 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002274 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002275 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002276 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002277
2278 // Get the next character to put on the screen.
2279
2280 // The "p_extra" points to the extra stuff that is inserted to
2281 // represent special characters (non-printable stuff) and other
2282 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002283 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002284 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2285 // "p_extra[n_extra]".
2286 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002287 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002288 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002289 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002290 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002291 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2292 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002293 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2294 if (enc_utf8 && utf_char2len(c) > 1)
2295 {
2296 mb_utf8 = TRUE;
2297 u8cc[0] = 0;
2298 c = 0xc0;
2299 }
2300 else
2301 mb_utf8 = FALSE;
2302 }
2303 else
2304 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002305 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002306 if (has_mbyte)
2307 {
2308 mb_c = c;
2309 if (enc_utf8)
2310 {
2311 // If the UTF-8 character is more than one byte:
2312 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002313 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002314 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002315 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002316 mb_l = 1;
2317 else if (mb_l > 1)
2318 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002319 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002320 mb_utf8 = TRUE;
2321 c = 0xc0;
2322 }
2323 }
2324 else
2325 {
2326 // if this is a DBCS character, put it in "mb_c"
2327 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002328 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002329 mb_l = 1;
2330 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002331 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002332 }
2333 if (mb_l == 0) // at the NUL at end-of-line
2334 mb_l = 1;
2335
2336 // If a double-width char doesn't fit display a '>' in the
2337 // last column.
2338 if ((
2339# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002340 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002341# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002342 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002343 && (*mb_char2cells)(mb_c) == 2)
2344 {
2345 c = '>';
2346 mb_c = c;
2347 mb_l = 1;
2348 mb_utf8 = FALSE;
2349 multi_attr = HL_ATTR(HLF_AT);
2350#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002351 if (wlv.cul_attr)
2352 multi_attr = hl_combine_attr(
2353 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002354#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002355 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002356
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002357 // put the pointer back to output the double-width
2358 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002359 ++wlv.n_extra;
2360 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002361 }
2362 else
2363 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002364 wlv.n_extra -= mb_l - 1;
2365 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002366 }
2367 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002368 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002369 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002370 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002371#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002372 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002373 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002374 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002375 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002376 if (search_attr == 0)
2377 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002378 if (area_attr == 0 && *ptr != NUL)
2379 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002380 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002381#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002382 }
2383 else
2384 {
2385#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002386 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002387#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002388 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002389
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002390 // Get a character from the line itself.
2391 c = *ptr;
2392#ifdef FEAT_LINEBREAK
2393 c0 = *ptr;
2394#endif
2395 if (has_mbyte)
2396 {
2397 mb_c = c;
2398 if (enc_utf8)
2399 {
2400 // If the UTF-8 character is more than one byte: Decode it
2401 // into "mb_c".
2402 mb_l = utfc_ptr2len(ptr);
2403 mb_utf8 = FALSE;
2404 if (mb_l > 1)
2405 {
2406 mb_c = utfc_ptr2char(ptr, u8cc);
2407 // Overlong encoded ASCII or ASCII with composing char
2408 // is displayed normally, except a NUL.
2409 if (mb_c < 0x80)
2410 {
2411 c = mb_c;
2412#ifdef FEAT_LINEBREAK
2413 c0 = mb_c;
2414#endif
2415 }
2416 mb_utf8 = TRUE;
2417
2418 // At start of the line we can have a composing char.
2419 // Draw it as a space with a composing char.
2420 if (utf_iscomposing(mb_c))
2421 {
2422 int i;
2423
2424 for (i = Screen_mco - 1; i > 0; --i)
2425 u8cc[i] = u8cc[i - 1];
2426 u8cc[0] = mb_c;
2427 mb_c = ' ';
2428 }
2429 }
2430
2431 if ((mb_l == 1 && c >= 0x80)
2432 || (mb_l >= 1 && mb_c == 0)
2433 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2434 {
2435 // Illegal UTF-8 byte: display as <xx>.
2436 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002437 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002438# ifdef FEAT_RIGHTLEFT
2439 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002440 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002441# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002442 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002443 c = *wlv.p_extra;
2444 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002445 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002446 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2447 wlv.c_extra = NUL;
2448 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002449 if (area_attr == 0 && search_attr == 0)
2450 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002451 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002452 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002453 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002454 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002455 }
2456 }
2457 else if (mb_l == 0) // at the NUL at end-of-line
2458 mb_l = 1;
2459#ifdef FEAT_ARABIC
2460 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2461 {
2462 // Do Arabic shaping.
2463 int pc, pc1, nc;
2464 int pcc[MAX_MCO];
2465
2466 // The idea of what is the previous and next
2467 // character depends on 'rightleft'.
2468 if (wp->w_p_rl)
2469 {
2470 pc = prev_c;
2471 pc1 = prev_c1;
2472 nc = utf_ptr2char(ptr + mb_l);
2473 prev_c1 = u8cc[0];
2474 }
2475 else
2476 {
2477 pc = utfc_ptr2char(ptr + mb_l, pcc);
2478 nc = prev_c;
2479 pc1 = pcc[0];
2480 }
2481 prev_c = mb_c;
2482
2483 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2484 }
2485 else
2486 prev_c = mb_c;
2487#endif
2488 }
2489 else // enc_dbcs
2490 {
2491 mb_l = MB_BYTE2LEN(c);
2492 if (mb_l == 0) // at the NUL at end-of-line
2493 mb_l = 1;
2494 else if (mb_l > 1)
2495 {
2496 // We assume a second byte below 32 is illegal.
2497 // Hopefully this is OK for all double-byte encodings!
2498 if (ptr[1] >= 32)
2499 mb_c = (c << 8) + ptr[1];
2500 else
2501 {
2502 if (ptr[1] == NUL)
2503 {
2504 // head byte at end of line
2505 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002506 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002507 }
2508 else
2509 {
2510 // illegal tail byte
2511 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002512 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002513 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002514 wlv.p_extra = wlv.extra;
2515 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002516 wlv.c_extra = NUL;
2517 wlv.c_final = NUL;
2518 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002519 if (area_attr == 0 && search_attr == 0)
2520 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002521 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002522 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002523 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002524 // save current attr
2525 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002526 }
2527 mb_c = c;
2528 }
2529 }
2530 }
2531 // If a double-width char doesn't fit display a '>' in the
2532 // last column; the character is displayed at the start of the
2533 // next line.
2534 if ((
2535# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002536 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002537# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002538 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002539 && (*mb_char2cells)(mb_c) == 2)
2540 {
2541 c = '>';
2542 mb_c = c;
2543 mb_utf8 = FALSE;
2544 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002545 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002546 // Put pointer back so that the character will be
2547 // displayed at the start of the next line.
2548 --ptr;
2549#ifdef FEAT_CONCEAL
2550 did_decrement_ptr = TRUE;
2551#endif
2552 }
2553 else if (*ptr != NUL)
2554 ptr += mb_l - 1;
2555
2556 // If a double-width char doesn't fit at the left side display
2557 // a '<' in the first column. Don't do this for unprintable
2558 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002559 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002560 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002561 wlv.n_extra = 1;
2562 wlv.c_extra = MB_FILLER_CHAR;
2563 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002564 c = ' ';
2565 if (area_attr == 0 && search_attr == 0)
2566 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002567 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002568 extra_attr = hl_combine_attr(
2569 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002570 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002571 }
2572 mb_c = c;
2573 mb_utf8 = FALSE;
2574 mb_l = 1;
2575 }
2576
2577 }
2578 ++ptr;
2579
2580 if (extra_check)
2581 {
2582#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002583 // Check spelling (unless at the end of the line).
2584 // Only do this when there is no syntax highlighting, the
2585 // @Spell cluster is not used or the current syntax item
2586 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002587 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002588 if (has_spell && v >= word_end && v > cur_checked_col)
2589 {
2590 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002591 // do not calculate cap_col at the end of the line or when
2592 // only white space is following
2593 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002594# ifdef FEAT_SYN_HL
2595 !has_syntax ||
2596# endif
2597 can_spell))
2598 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002599 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002600 int len;
2601 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002602
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002603 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002604 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002605
2606 // Use nextline[] if possible, it has the start of the
2607 // next line concatenated.
2608 if ((prev_ptr - line) - nextlinecol >= 0)
2609 p = nextline + (prev_ptr - line) - nextlinecol;
2610 else
2611 p = prev_ptr;
2612 cap_col -= (int)(prev_ptr - line);
2613 len = spell_check(wp, p, &spell_hlf, &cap_col,
2614 nochange);
2615 word_end = v + len;
2616
2617 // In Insert mode only highlight a word that
2618 // doesn't touch the cursor.
2619 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002620 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002621 && wp->w_cursor.lnum == lnum
2622 && wp->w_cursor.col >=
2623 (colnr_T)(prev_ptr - line)
2624 && wp->w_cursor.col < (colnr_T)word_end)
2625 {
2626 spell_hlf = HLF_COUNT;
2627 spell_redraw_lnum = lnum;
2628 }
2629
2630 if (spell_hlf == HLF_COUNT && p != prev_ptr
2631 && (p - nextline) + len > nextline_idx)
2632 {
2633 // Remember that the good word continues at the
2634 // start of the next line.
2635 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002636 checked_col = (int)((p - nextline)
2637 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002638 }
2639
2640 // Turn index into actual attributes.
2641 if (spell_hlf != HLF_COUNT)
2642 spell_attr = highlight_attr[spell_hlf];
2643
2644 if (cap_col > 0)
2645 {
2646 if (p != prev_ptr
2647 && (p - nextline) + cap_col >= nextline_idx)
2648 {
2649 // Remember that the word in the next line
2650 // must start with a capital.
2651 capcol_lnum = lnum + 1;
2652 cap_col = (int)((p - nextline) + cap_col
2653 - nextline_idx);
2654 }
2655 else
2656 // Compute the actual column.
2657 cap_col += (int)(prev_ptr - line);
2658 }
2659 }
2660 }
2661 if (spell_attr != 0)
2662 {
2663 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002664 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2665 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002666 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002667 wlv.char_attr = hl_combine_attr(spell_attr,
2668 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002669 }
2670#endif
2671#ifdef FEAT_LINEBREAK
2672 // Found last space before word: check for line break.
2673 if (wp->w_p_lbr && c0 == c
2674 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2675 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002676 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2677 : 0;
2678 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002679 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002680
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002681 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002682# ifdef FEAT_PROP_POPUP
2683 // do not want virtual text counted here
2684 cts.cts_has_prop_with_text = FALSE;
2685# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002686 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002687 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002688
2689 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002690 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002691 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002692 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002693 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2694 if (wlv.n_extra < 0)
2695 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002696 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002697 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002698 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002699 // line break, but for TABs the highlighting should
2700 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002701 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002702
Bram Moolenaar1306b362022-08-06 15:59:06 +01002703 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002704# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002705 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002706 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002707 wp->w_buffer->b_p_vts_array) - 1;
2708# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002709 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002710 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002711# endif
2712
Bram Moolenaar1306b362022-08-06 15:59:06 +01002713 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2714 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002715# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002716 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002717 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002718# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002719 if (VIM_ISWHITE(c))
2720 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002721# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002722 if (c == TAB)
2723 // See "Tab alignment" below.
2724 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002725# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002726 if (!wp->w_p_list)
2727 c = ' ';
2728 }
2729 }
2730#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002731 in_multispace = c == ' '
2732 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2733 if (!in_multispace)
2734 multispace_pos = 0;
2735
Bram Moolenaareed9d462021-02-15 20:38:25 +01002736 // 'list': Change char 160 to 'nbsp' and space to 'space'
2737 // setting in 'listchars'. But not when the character is
2738 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002739 if (wp->w_p_list
2740 && ((((c == 160 && mb_l == 1)
2741 || (mb_utf8
2742 && ((mb_c == 160 && mb_l == 2)
2743 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002744 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002745 || (c == ' '
2746 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002747 && (wp->w_lcs_chars.space
2748 || (in_multispace
2749 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002750 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002751 && ptr - line <= trailcol)))
2752 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002753 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2754 {
2755 c = wp->w_lcs_chars.multispace[multispace_pos++];
2756 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2757 multispace_pos = 0;
2758 }
2759 else
2760 c = (c == ' ') ? wp->w_lcs_chars.space
2761 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002762 if (area_attr == 0 && search_attr == 0)
2763 {
2764 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002765 extra_attr = hl_combine_attr(wlv.win_attr,
2766 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002767 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002768 }
2769 mb_c = c;
2770 if (enc_utf8 && utf_char2len(c) > 1)
2771 {
2772 mb_utf8 = TRUE;
2773 u8cc[0] = 0;
2774 c = 0xc0;
2775 }
2776 else
2777 mb_utf8 = FALSE;
2778 }
2779
zeertzjq2e7cba32022-06-10 15:30:32 +01002780 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2781 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002782 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002783 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2784 && wp->w_lcs_chars.leadmultispace != NULL)
2785 {
2786 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002787 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2788 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002789 multispace_pos = 0;
2790 }
2791
2792 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2793 c = wp->w_lcs_chars.trail;
2794
2795 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2796 c = wp->w_lcs_chars.lead;
2797
zeertzjq2e7cba32022-06-10 15:30:32 +01002798 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002799 c = wp->w_lcs_chars.space;
2800
2801
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002802 if (!attr_pri)
2803 {
2804 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002805 extra_attr = hl_combine_attr(wlv.win_attr,
2806 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002807 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002808 }
2809 mb_c = c;
2810 if (enc_utf8 && utf_char2len(c) > 1)
2811 {
2812 mb_utf8 = TRUE;
2813 u8cc[0] = 0;
2814 c = 0xc0;
2815 }
2816 else
2817 mb_utf8 = FALSE;
2818 }
2819 }
2820
2821 // Handling of non-printable characters.
2822 if (!vim_isprintc(c))
2823 {
2824 // when getting a character from the file, we may have to
2825 // turn it into something else on the way to putting it
2826 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002827 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002828 {
2829 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002830 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002831#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002832 char_u *sbr = get_showbreak_value(wp);
2833
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002834 // only adjust the tab_len, when at the first column
2835 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002836 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002837 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002838#endif
2839 // tab amount depends on current column
2840#ifdef FEAT_VARTABS
2841 tab_len = tabstop_padding(vcol_adjusted,
2842 wp->w_buffer->b_p_ts,
2843 wp->w_buffer->b_p_vts_array) - 1;
2844#else
2845 tab_len = (int)wp->w_buffer->b_p_ts
2846 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2847#endif
2848
2849#ifdef FEAT_LINEBREAK
2850 if (!wp->w_p_lbr || !wp->w_p_list)
2851#endif
2852 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002853 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002854#ifdef FEAT_LINEBREAK
2855 else
2856 {
2857 char_u *p;
2858 int len;
2859 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002860 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002861
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002862# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002863 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002864 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002865 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002866
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002867 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002868 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002869 && old_boguscols > 0
2870 && wlv.n_extra > tab_len)
2871 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002872# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002873 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002874 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002875 // If wlv.n_extra > 0, it gives the number of
2876 // chars, to use for a tab, else we need to
2877 // calculate the width for a tab.
2878 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
2879 len = tab_len * tab2_len;
2880 if (wp->w_lcs_chars.tab3)
2881 len += mb_char2len(wp->w_lcs_chars.tab3)
2882 - tab2_len;
2883 if (wlv.n_extra > 0)
2884 len += wlv.n_extra - tab_len;
2885 c = wp->w_lcs_chars.tab1;
2886 p = alloc(len + 1);
2887 if (p == NULL)
2888 wlv.n_extra = 0;
2889 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002890 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002891 vim_memset(p, ' ', len);
2892 p[len] = NUL;
2893 vim_free(wlv.p_extra_free);
2894 wlv.p_extra_free = p;
2895 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002896 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002897 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002898
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002899 if (*p == NUL)
2900 {
2901 tab_len = i;
2902 break;
2903 }
2904
2905 // if tab3 is given, use it for the last
2906 // char
2907 if (wp->w_lcs_chars.tab3
2908 && i == tab_len - 1)
2909 lcs = wp->w_lcs_chars.tab3;
2910 p += mb_char2bytes(lcs, p);
2911 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002912 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002913 }
2914 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002915# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002916 // n_extra will be increased by
2917 // FIX_FOX_BOGUSCOLS macro below, so need to
2918 // adjust for that here
2919 if (wlv.vcol_off > 0)
2920 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002921# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002922 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002923 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002924 }
2925#endif
2926#ifdef FEAT_CONCEAL
2927 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002928 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002929
2930 // Tab alignment should be identical regardless of
2931 // 'conceallevel' value. So tab compensates of all
2932 // previous concealed characters, and thus resets
2933 // vcol_off and boguscols accumulated so far in the
2934 // line. Note that the tab can be longer than
2935 // 'tabstop' when there are concealed characters.
2936 FIX_FOR_BOGUSCOLS;
2937
2938 // Make sure, the highlighting for the tab char will be
2939 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002940 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002941 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002942 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002943 tab_len += vc_saved;
2944 }
2945#endif
2946 mb_utf8 = FALSE; // don't draw as UTF-8
2947 if (wp->w_p_list)
2948 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002949 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002950 ? wp->w_lcs_chars.tab3
2951 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002952#ifdef FEAT_LINEBREAK
2953 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002954 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002955 else
2956#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002957 wlv.c_extra = wp->w_lcs_chars.tab2;
2958 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002959 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002960 extra_attr = hl_combine_attr(wlv.win_attr,
2961 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002962 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002963 mb_c = c;
2964 if (enc_utf8 && utf_char2len(c) > 1)
2965 {
2966 mb_utf8 = TRUE;
2967 u8cc[0] = 0;
2968 c = 0xc0;
2969 }
2970 }
2971 else
2972 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002973 wlv.c_final = NUL;
2974 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002975 c = ' ';
2976 }
2977 }
2978 else if (c == NUL
2979 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002980 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
2981 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002982 && VIsual_mode != Ctrl_V
2983 && (
2984# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002985 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002986# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002987 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002988 && !(noinvcur
2989 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002990 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002991 && lcs_eol_one > 0)
2992 {
2993 // Display a '$' after the line or highlight an extra
2994 // character if the line break is included.
2995#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2996 // For a diff line the highlighting continues after the
2997 // "$".
2998 if (
2999# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003000 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003001# ifdef LINE_ATTR
3002 &&
3003# endif
3004# endif
3005# ifdef LINE_ATTR
3006 line_attr == 0
3007# endif
3008 )
3009#endif
3010 {
3011 // In virtualedit, visual selections may extend
3012 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003013 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003014 && wlv.tocol != MAXCOL
3015 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003016 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003017 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003018 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003019 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3020 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003021 else
3022 c = ' ';
3023 lcs_eol_one = -1;
3024 --ptr; // put it back at the NUL
3025 if (!attr_pri)
3026 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003027 extra_attr = hl_combine_attr(wlv.win_attr,
3028 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003029 n_attr = 1;
3030 }
3031 mb_c = c;
3032 if (enc_utf8 && utf_char2len(c) > 1)
3033 {
3034 mb_utf8 = TRUE;
3035 u8cc[0] = 0;
3036 c = 0xc0;
3037 }
3038 else
3039 mb_utf8 = FALSE; // don't draw as UTF-8
3040 }
3041 else if (c != NUL)
3042 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003043 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3044 if (wlv.n_extra == 0)
3045 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003046#ifdef FEAT_RIGHTLEFT
3047 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003048 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003049#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003050 wlv.c_extra = NUL;
3051 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003052#ifdef FEAT_LINEBREAK
3053 if (wp->w_p_lbr)
3054 {
3055 char_u *p;
3056
Bram Moolenaar1306b362022-08-06 15:59:06 +01003057 c = *wlv.p_extra;
3058 p = alloc(wlv.n_extra + 1);
3059 vim_memset(p, ' ', wlv.n_extra);
3060 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3061 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003062 vim_free(wlv.p_extra_free);
3063 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003064 }
3065 else
3066#endif
3067 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003068 wlv.n_extra = byte2cells(c) - 1;
3069 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003070 }
3071 if (!attr_pri)
3072 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003073 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003074 extra_attr = hl_combine_attr(wlv.win_attr,
3075 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003076 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003077 }
3078 mb_utf8 = FALSE; // don't draw as UTF-8
3079 }
3080 else if (VIsual_active
3081 && (VIsual_mode == Ctrl_V
3082 || VIsual_mode == 'v')
3083 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003084 && wlv.tocol != MAXCOL
3085 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003086 && (
3087#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003088 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003089#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003090 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003091 {
3092 c = ' ';
3093 --ptr; // put it back at the NUL
3094 }
3095#if defined(LINE_ATTR)
3096 else if ((
3097# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003098 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003099# endif
3100# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003101 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003102# endif
3103 line_attr != 0
3104 ) && (
3105# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003106 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003107# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003108 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003109# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003110 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003111# endif
3112 < wp->w_width)))
3113 {
3114 // Highlight until the right side of the window
3115 c = ' ';
3116 --ptr; // put it back at the NUL
3117
3118 // Remember we do the char for line highlighting.
3119 ++did_line_attr;
3120
3121 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01003122 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003123 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003124 || (wp->w_p_list &&
3125 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003126 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003127# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003128 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003129 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003130 wlv.diff_hlf = HLF_CHD;
3131 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003132 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003133 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003134 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3135 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003136 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003137 || (wlv.vcol >= left_curline_col
3138 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003139 wlv.char_attr = hl_combine_attr(
3140 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003141 }
3142 }
3143# endif
3144# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003145 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003146 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003147 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003148 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3149 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003150 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003151 if (!wlv.cul_screenline
3152 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003153 && 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 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003158 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3159 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003160 }
3161# endif
3162 }
3163#endif
3164 }
3165
3166#ifdef FEAT_CONCEAL
3167 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003168 && (wp != curwin || lnum != wp->w_cursor.lnum
3169 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003170 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3171 && !(lnum_in_visual_area
3172 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3173 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003174 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003175 if (((prev_syntax_id != syntax_seqnr
3176 && (syntax_flags & HL_CONCEAL) != 0)
3177 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003178 && (syn_get_sub_char() != NUL
3179 || (has_match_conc && match_conc)
3180 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003181 && wp->w_p_cole != 3)
3182 {
3183 // First time at this concealed item: display one
3184 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003185 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003186 c = match_conc;
3187 else if (syn_get_sub_char() != NUL)
3188 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003189 else if (wp->w_lcs_chars.conceal != NUL)
3190 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003191 else
3192 c = ' ';
3193
3194 prev_syntax_id = syntax_seqnr;
3195
Bram Moolenaar1306b362022-08-06 15:59:06 +01003196 if (wlv.n_extra > 0)
3197 wlv.vcol_off += wlv.n_extra;
3198 wlv.vcol += wlv.n_extra;
3199 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003200 {
3201# ifdef FEAT_RIGHTLEFT
3202 if (wp->w_p_rl)
3203 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003204 wlv.col -= wlv.n_extra;
3205 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003206 }
3207 else
3208# endif
3209 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003210 wlv.boguscols += wlv.n_extra;
3211 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003212 }
3213 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003214 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003215 n_attr = 0;
3216 }
3217 else if (n_skip == 0)
3218 {
3219 is_concealing = TRUE;
3220 n_skip = 1;
3221 }
3222 mb_c = c;
3223 if (enc_utf8 && utf_char2len(c) > 1)
3224 {
3225 mb_utf8 = TRUE;
3226 u8cc[0] = 0;
3227 c = 0xc0;
3228 }
3229 else
3230 mb_utf8 = FALSE; // don't draw as UTF-8
3231 }
3232 else
3233 {
3234 prev_syntax_id = 0;
3235 is_concealing = FALSE;
3236 }
3237
3238 if (n_skip > 0 && did_decrement_ptr)
3239 // not showing the '>', put pointer back to avoid getting stuck
3240 ++ptr;
3241
3242#endif // FEAT_CONCEAL
3243 }
3244
3245#ifdef FEAT_CONCEAL
3246 // In the cursor line and we may be concealing characters: correct
3247 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003248 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003249 && wp == curwin && lnum == wp->w_cursor.lnum
3250 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003251 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003252 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003253# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003254 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003255 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003256 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003257# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003258 wp->w_wcol = wlv.col - wlv.boguscols;
3259 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003260 did_wcol = TRUE;
3261 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003262# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003263 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003264# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003265 }
3266#endif
3267
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003268 // Use "extra_attr", but don't override visual selection highlighting,
3269 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003270 // Don't use "extra_attr" until n_attr_skip is zero.
3271 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003272 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003273 && (!attr_pri
3274#ifdef FEAT_PROP_POPUP
3275 || (text_prop_flags & PT_FLAG_OVERRIDE)
3276#endif
3277 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003278 {
3279#ifdef LINE_ATTR
3280 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003281 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003282 else
3283#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003284 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003285 }
3286
3287#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3288 // XIM don't send preedit_start and preedit_end, but they send
3289 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3290 // im_is_preediting() here.
3291 if (p_imst == IM_ON_THE_SPOT
3292 && xic != NULL
3293 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003294 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003295 && !p_imdisable
3296 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003297 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003298 {
3299 colnr_T tcol;
3300
3301 if (preedit_end_col == MAXCOL)
3302 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3303 else
3304 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003305 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003306 {
3307 if (feedback_old_attr < 0)
3308 {
3309 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003310 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003311 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003312 wlv.char_attr = im_get_feedback_attr(feedback_col);
3313 if (wlv.char_attr < 0)
3314 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003315 feedback_col++;
3316 }
3317 else if (feedback_old_attr >= 0)
3318 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003319 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003320 feedback_old_attr = -1;
3321 feedback_col = 0;
3322 }
3323 }
3324#endif
3325 // Handle the case where we are in column 0 but not on the first
3326 // character of the line and the user wants us to show us a
3327 // special character (via 'listchars' option "precedes:<char>".
3328 if (lcs_prec_todo != NUL
3329 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003330 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3331 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003332#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003333 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003334#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003335 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003336 && c != NUL)
3337 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003338 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003339 lcs_prec_todo = NUL;
3340 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3341 {
3342 // Double-width character being overwritten by the "precedes"
3343 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003344 wlv.c_extra = MB_FILLER_CHAR;
3345 wlv.c_final = NUL;
3346 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003347 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003348 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003349 }
3350 mb_c = c;
3351 if (enc_utf8 && utf_char2len(c) > 1)
3352 {
3353 mb_utf8 = TRUE;
3354 u8cc[0] = 0;
3355 c = 0xc0;
3356 }
3357 else
3358 mb_utf8 = FALSE; // don't draw as UTF-8
3359 if (!attr_pri)
3360 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003361 saved_attr3 = wlv.char_attr; // save current attr
3362 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003363 n_attr3 = 1;
3364 }
3365 }
3366
3367 // At end of the text line or just after the last character.
3368 if ((c == NUL
3369#if defined(LINE_ATTR)
3370 || did_line_attr == 1
3371#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003372 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003373 {
3374#ifdef FEAT_SEARCH_EXTRA
3375 // flag to indicate whether prevcol equals startcol of search_hl or
3376 // one of the matches
3377 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3378 (long)(ptr - line) - (c == NUL));
3379#endif
3380 // Invert at least one char, used for Visual and empty line or
3381 // highlight match at end of line. If it's beyond the last
3382 // char on the screen, just overwrite that one (tricky!) Not
3383 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003384 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003385 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003386 && (VIsual_mode != Ctrl_V
3387 || lnum == VIsual.lnum
3388 || lnum == curwin->w_cursor.lnum)
3389 && c == NUL)
3390#ifdef FEAT_SEARCH_EXTRA
3391 // highlight 'hlsearch' match at end of line
3392 || (prevcol_hl_flag
3393# ifdef FEAT_SYN_HL
3394 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3395 && !(wp == curwin && VIsual_active))
3396# endif
3397# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003398 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003399# endif
3400# if defined(LINE_ATTR)
3401 && did_line_attr <= 1
3402# endif
3403 )
3404#endif
3405 ))
3406 {
3407 int n = 0;
3408
3409#ifdef FEAT_RIGHTLEFT
3410 if (wp->w_p_rl)
3411 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003412 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003413 n = 1;
3414 }
3415 else
3416#endif
3417 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003418 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003419 n = -1;
3420 }
3421 if (n != 0)
3422 {
3423 // At the window boundary, highlight the last character
3424 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003425 wlv.off += n;
3426 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003427 }
3428 else
3429 {
3430 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003431 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003432 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003433 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003434 }
3435#ifdef FEAT_SEARCH_EXTRA
3436 if (area_attr == 0)
3437 {
3438 // Use attributes from match with highest priority among
3439 // 'search_hl' and the match list.
3440 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003441 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003442 }
3443#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003444 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003445 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003446#ifdef FEAT_RIGHTLEFT
3447 if (wp->w_p_rl)
3448 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003449 --wlv.col;
3450 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003451 }
3452 else
3453#endif
3454 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003455 ++wlv.col;
3456 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003457 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003458 ++wlv.vcol;
3459 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003460 }
3461 }
3462
3463 // At end of the text line.
3464 if (c == NUL)
3465 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003466 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003467
3468 // Update w_cline_height and w_cline_folded if the cursor line was
3469 // updated (saves a call to plines() later).
3470 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3471 {
3472 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003473 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003474#ifdef FEAT_FOLDING
3475 curwin->w_cline_folded = FALSE;
3476#endif
3477 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3478 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003479 break;
3480 }
3481
3482 // Show "extends" character from 'listchars' if beyond the line end and
3483 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003484 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003485 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003486 && wp->w_p_list
3487 && !wp->w_p_wrap
3488#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003489 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003490#endif
3491 && (
3492#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003493 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003494#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003495 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003496 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003497 || lcs_eol_one > 0
3498 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003499 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003500 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003501 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003502 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003503 mb_c = c;
3504 if (enc_utf8 && utf_char2len(c) > 1)
3505 {
3506 mb_utf8 = TRUE;
3507 u8cc[0] = 0;
3508 c = 0xc0;
3509 }
3510 else
3511 mb_utf8 = FALSE;
3512 }
3513
3514#ifdef FEAT_SYN_HL
3515 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003516 if (wlv.draw_color_col)
3517 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003518
3519 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3520 // highlight the cursor position itself.
3521 // Also highlight the 'colorcolumn' if it is different than
3522 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003523 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3524 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003525 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003526 if (((wlv.draw_state == WL_LINE
3527 || wlv.draw_state == WL_BRI
3528 || wlv.draw_state == WL_SBR)
3529 && !lnum_in_visual_area
3530 && search_attr == 0
3531 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003532# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003533 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003534# endif
3535 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003536 {
3537 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3538 && lnum != wp->w_cursor.lnum)
3539 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003540 vcol_save_attr = wlv.char_attr;
3541 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3542 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003543 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003544 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003545 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003546 vcol_save_attr = wlv.char_attr;
3547 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003548 }
3549 }
3550#endif
3551
3552 // Store character to be displayed.
3553 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003554 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003555 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003556 {
3557 // Store the character.
3558#if defined(FEAT_RIGHTLEFT)
3559 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3560 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003561 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003562 --wlv.off;
3563 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003564 }
3565#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003566 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003567 if (enc_dbcs == DBCS_JPNU)
3568 {
3569 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003570 ScreenLines[wlv.off] = 0x8e;
3571 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003572 }
3573 else if (enc_utf8)
3574 {
3575 if (mb_utf8)
3576 {
3577 int i;
3578
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003579 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003580 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003581 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003582 for (i = 0; i < Screen_mco; ++i)
3583 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003584 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003585 if (u8cc[i] == 0)
3586 break;
3587 }
3588 }
3589 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003590 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003591 }
3592 if (multi_attr)
3593 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003594 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003595 multi_attr = 0;
3596 }
3597 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003598 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003599
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003600 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003601
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003602 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3603 {
3604 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003605 ++wlv.off;
3606 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003607 if (enc_utf8)
3608 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003609 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003610 else
3611 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003612 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003613 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003614#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003615 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003616#endif
3617 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003618 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003619 // When "wlv.tocol" is halfway a character, set it to the end
3620 // of the character, otherwise highlighting won't stop.
3621 if (wlv.tocol == wlv.vcol)
3622 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003623
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003624 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003625
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003626#ifdef FEAT_RIGHTLEFT
3627 if (wp->w_p_rl)
3628 {
3629 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003630 --wlv.off;
3631 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003632 }
3633#endif
3634 }
3635#ifdef FEAT_RIGHTLEFT
3636 if (wp->w_p_rl)
3637 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003638 --wlv.off;
3639 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003640 }
3641 else
3642#endif
3643 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003644 ++wlv.off;
3645 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003646 }
3647 }
3648#ifdef FEAT_CONCEAL
3649 else if (wp->w_p_cole > 0 && is_concealing)
3650 {
3651 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003652 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003653 if (wlv.n_extra > 0)
3654 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003655 if (wp->w_p_wrap)
3656 {
3657 // Special voodoo required if 'wrap' is on.
3658 //
3659 // Advance the column indicator to force the line
3660 // drawing to wrap early. This will make the line
3661 // take up the same screen space when parts are concealed,
3662 // so that cursor line computations aren't messed up.
3663 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003664 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003665 // trailing junk to be written out of the screen line
3666 // we are building, 'boguscols' keeps track of the number
3667 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003668 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003669 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003670 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003671# ifdef FEAT_RIGHTLEFT
3672 if (wp->w_p_rl)
3673 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003674 wlv.col -= wlv.n_extra;
3675 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003676 }
3677 else
3678# endif
3679 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003680 wlv.col += wlv.n_extra;
3681 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003682 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003683 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003684 n_attr = 0;
3685 }
3686
3687
3688 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3689 {
3690 // Need to fill two screen columns.
3691# ifdef FEAT_RIGHTLEFT
3692 if (wp->w_p_rl)
3693 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003694 --wlv.boguscols;
3695 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003696 }
3697 else
3698# endif
3699 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003700 ++wlv.boguscols;
3701 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003702 }
3703 }
3704
3705# ifdef FEAT_RIGHTLEFT
3706 if (wp->w_p_rl)
3707 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003708 --wlv.boguscols;
3709 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003710 }
3711 else
3712# endif
3713 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003714 ++wlv.boguscols;
3715 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003716 }
3717 }
3718 else
3719 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003720 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003721 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003722 wlv.vcol += wlv.n_extra;
3723 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003724 n_attr = 0;
3725 }
3726 }
3727
3728 }
3729#endif // FEAT_CONCEAL
3730 else
3731 --n_skip;
3732
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003733 // Only advance the "wlv.vcol" when after the 'number' or
3734 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003735 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003736#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003737 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003738#endif
3739 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003740 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003741
3742#ifdef FEAT_SYN_HL
3743 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003744 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003745#endif
3746
3747 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003748 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3749 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003750
3751 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003752 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003753 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003754 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003755 if (n_attr_skip > 0)
3756 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003757
3758 // At end of screen line and there is more to come: Display the line
3759 // so far. If there is no more to display it is caught above.
3760 if ((
3761#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003762 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003763#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003764 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003765 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003766 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003767#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003768 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003769#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003770#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003771 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003772#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003773 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003774 && wlv.p_extra != at_end_str)
3775 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3776 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003777 )
3778 {
3779#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003780 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003781 wlv_screen_line(wp, &wlv, FALSE);
3782 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003783 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003784#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003785 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003786#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003787 ++wlv.row;
3788 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003789
3790 // When not wrapping and finished diff lines, or when displayed
3791 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01003792 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003793#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003794 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003795#endif
3796#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01003797 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003798#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01003799 ) || lcs_eol_one == -1)
3800#ifdef FEAT_PROP_POPUP
3801 && !text_prop_follows
3802#endif
3803 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003804 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003805#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003806 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003807 {
3808 // do not output more of the line, only the "below" prop
3809 ptr += STRLEN(ptr);
3810# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003811 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003812# endif
3813 }
3814#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003815
3816 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003817 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003818#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003819 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003820#endif
3821 )
3822 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003823 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3824 draw_vsep_win(wp, wlv.row);
3825 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003826 }
3827
3828 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003829 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003830 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003831 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003832 break;
3833 }
3834
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003835 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003836#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003837 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003838#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003839#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003840 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003841#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003842 && wp->w_width == Columns)
3843 {
3844 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003845 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003846
3847 // Special trick to make copy/paste of wrapped lines work with
3848 // xterm/screen: write an extra character beyond the end of
3849 // the line. This will work with all terminal types
3850 // (regardless of the xn,am settings).
3851 // Only do this on a fast tty.
3852 // Only do this if the cursor is on the current line
3853 // (something has been written in it).
3854 // Don't do this for the GUI.
3855 // Don't do this for double-width characters.
3856 // Don't do this for a window not at the right screen border.
3857 if (p_tf
3858#ifdef FEAT_GUI
3859 && !gui.in_use
3860#endif
3861 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003862 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3863 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003864 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003865 || (*mb_off2cells)(
3866 LineOffset[wlv.screen_row - 1]
3867 + (int)Columns - 2,
3868 LineOffset[wlv.screen_row]
3869 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003870 {
3871 // First make sure we are at the end of the screen line,
3872 // then output the same character again to let the
3873 // terminal know about the wrap. If the terminal doesn't
3874 // auto-wrap, we overwrite the character.
3875 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003876 screen_char(LineOffset[wlv.screen_row - 1]
3877 + (unsigned)Columns - 1,
3878 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003879
3880 // When there is a multi-byte character, just output a
3881 // space to keep it simple.
3882 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003883 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003884 out_char(' ');
3885 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003886 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003887 + (Columns - 1)]);
3888 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003889 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003890 screen_start(); // don't know where cursor is now
3891 }
3892 }
3893
Bram Moolenaar1306b362022-08-06 15:59:06 +01003894 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003895
Bram Moolenaareed9d462021-02-15 20:38:25 +01003896 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003897#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003898 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003899# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003900 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003901# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003902 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003903 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003904#endif
3905#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003906 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003907 // When the filler lines are actually below the last line of the
3908 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003909 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003910 break;
3911#endif
3912 }
3913
3914 } // for every character in the line
3915
3916#ifdef FEAT_SPELL
3917 // After an empty line check first word for capital.
3918 if (*skipwhite(line) == NUL)
3919 {
3920 capcol_lnum = lnum + 1;
3921 cap_col = 0;
3922 }
3923#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003924#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003925 vim_free(text_props);
3926 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003927 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003928#endif
3929
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003930 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003931 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003932}