blob: cddb6ab654cf932076e4d1d1e213575cb18ae572 [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
462 && *get_showbreak_value(wp) != NUL)
463 // 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,
576 char_u *text,
577 int *n_used_ptr)
578{
579 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
580 ? wp->w_width : added;
581 int len = (int)STRLEN(text);
582 int strsize = 0;
583 int n_used;
584
585 // if the remaining size is to small wrap anyway and use the next line
586 if (space < PROP_TEXT_MIN_CELLS)
587 space += wp->w_width;
588 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
589 {
590 int clen = ptr2cells(text + n_used);
591
592 if (strsize + clen > space)
593 break;
594 strsize += clen;
595 }
596 *n_used_ptr = n_used;
597 return strsize;
598}
599
600/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100601 * Take care of padding, right-align and truncation of virtual text after a
602 * line.
603 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
604 * padding, right-align and truncation. Otherwise only the size is computed.
605 * When "n_attr" is NULL returns the number of screen cells used.
606 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100607 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100608 int
609text_prop_position(
610 win_T *wp,
611 textprop_T *tp,
612 int vcol, // current screen column
613 int *n_extra, // nr of bytes for virtual text
614 char_u **p_extra, // virtual text
615 int *n_attr, // attribute cells, NULL if not used
616 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200617{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100618 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100619 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100620 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
621 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
622 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
623 ? tp->tp_len - 1 : 0;
624 int col_with_padding = vcol + (below ? 0 : padding);
625 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100626 int before = room; // spaces before the text
627 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100628 int n_used = *n_extra;
629 char_u *l = NULL;
630 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100631 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
632 tp->tp_flags, before, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200633
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100634 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100635 {
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100636 int col_off = win_col_off(wp) + win_col_off2(wp);
637 int skip_add = 0;
638
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100639 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100640 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100641 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100642 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100643 }
644 else
645 {
646 // Right-align: fill with before
647 if (right)
648 before -= cells;
649 if (before < 0
650 || !(right || below)
651 || (below
652 ? (col_with_padding == 0 || !wp->w_p_wrap)
653 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100654 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100655 if (right && (wrap || room < PROP_TEXT_MIN_CELLS))
656 {
657 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100658 before = wp->w_width - col_off - strsize + room;
659 if (before < 0)
660 before = 0;
661 else
662 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100663 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100664 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100665 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100666 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100667 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100668 else if (below && before > 0)
669 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100670 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100671 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100672
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100673 // With 'nowrap' add one to show the "extends" character if needed (it
674 // doesn't show if the text just fits).
675 if (!wp->w_p_wrap
676 && n_used < *n_extra
677 && wp->w_lcs_chars.ext != NUL
678 && wp->w_p_list)
679 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100680 if (!wp->w_p_wrap && below && padding > 0)
681 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100682
683 // add 1 for NUL, 2 for when '…' is used
684 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100685 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100686 if (n_attr == NULL || l != NULL)
687 {
688 int off = 0;
689
690 if (n_attr != NULL)
691 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100692 vim_memset(l, ' ', before);
693 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100694 if (padding > 0)
695 {
696 vim_memset(l + off, ' ', padding);
697 off += padding;
698 }
699 vim_strncpy(l + off, *p_extra, n_used);
700 off += n_used;
701 }
702 else
703 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100704 off = before + after + padding + n_used;
705 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100706 }
707 if (n_attr != NULL)
708 {
709 if (n_used < *n_extra && wp->w_p_wrap)
710 {
711 char_u *lp = l + off - 1;
712
713 if (has_mbyte)
714 {
715 // change last character to '…'
716 lp -= (*mb_head_off)(l, lp);
717 STRCPY(lp, "…");
718 n_used = lp - l + 3 - padding;
719 }
720 else
721 // change last character to '>'
722 *lp = '>';
723 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100724 else if (after > 0)
725 {
726 vim_memset(l + off, ' ', after);
727 l[off + after] = NUL;
728 }
729
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100730 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100731 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100732 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100733 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100734 *n_attr -= padding + after;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100735 *n_attr_skip = before + padding + skip_add;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100736 }
737 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100738 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100739
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100740 if (n_attr == NULL)
741 return cells;
742 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200743}
744#endif
745
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100746/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100747 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100748 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
749 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100750 */
751 static void
752wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
753{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100754 if (wlv->row == 0 && wp->w_skipcol > 0
755#if defined(FEAT_LINEBREAK)
756 && *get_showbreak_value(wp) == NUL
757#endif
758 )
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100759 {
760 int off = (int)(current_ScreenLine - ScreenLines);
761
762 for (int i = 0; i < 3; ++i)
763 {
764 ScreenLines[off] = '<';
765 if (enc_utf8)
766 ScreenLinesUC[off] = 0;
767 ScreenAttrs[off] = HL_ATTR(HLF_AT);
768 ++off;
769 }
770 }
771
772 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
773 negative_width ? -wp->w_width : wp->w_width,
774 wlv->screen_line_flags);
775}
776
777/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100778 * Called when finished with the line: draw the screen line and handle any
779 * highlighting until the right of the window.
780 */
781 static void
782draw_screen_line(win_T *wp, winlinevars_T *wlv)
783{
784#ifdef FEAT_SYN_HL
785 long v;
786
787 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
788 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100789 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100790 else
791 v = wp->w_leftcol;
792
793 // check if line ends before left margin
794 if (wlv->vcol < v + wlv->col - win_col_off(wp))
795 wlv->vcol = v + wlv->col - win_col_off(wp);
796# ifdef FEAT_CONCEAL
797 // Get rid of the boguscols now, we want to draw until the right
798 // edge for 'cursorcolumn'.
799 wlv->col -= wlv->boguscols;
800 wlv->boguscols = 0;
801# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
802# else
803# define VCOL_HLC (wlv->vcol)
804# endif
805
806 if (wlv->draw_color_col)
807 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
808
809 if (((wp->w_p_cuc
810 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
811 && (int)wp->w_virtcol <
812 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
813 && wlv->lnum != wp->w_cursor.lnum)
814 || wlv->draw_color_col
815 || wlv->win_attr != 0)
816# ifdef FEAT_RIGHTLEFT
817 && !wp->w_p_rl
818# endif
819 )
820 {
821 int rightmost_vcol = 0;
822 int i;
823
824 if (wp->w_p_cuc)
825 rightmost_vcol = wp->w_virtcol;
826 if (wlv->draw_color_col)
827 // determine rightmost colorcolumn to possibly draw
828 for (i = 0; wlv->color_cols[i] >= 0; ++i)
829 if (rightmost_vcol < wlv->color_cols[i])
830 rightmost_vcol = wlv->color_cols[i];
831
832 while (wlv->col < wp->w_width)
833 {
834 ScreenLines[wlv->off] = ' ';
835 if (enc_utf8)
836 ScreenLinesUC[wlv->off] = 0;
837 ScreenCols[wlv->off] = MAXCOL;
838 ++wlv->col;
839 if (wlv->draw_color_col)
840 wlv->draw_color_col = advance_color_col(
841 VCOL_HLC, &wlv->color_cols);
842
843 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
844 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
845 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
846 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
847 else
848 ScreenAttrs[wlv->off++] = wlv->win_attr;
849
850 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
851 break;
852
853 ++wlv->vcol;
854 }
855 }
856#endif
857
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100858 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100859 ++wlv->row;
860 ++wlv->screen_row;
861}
862#undef VCOL_HLC
863
864/*
865 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100866 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100867 */
868 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100869win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100870{
871 wlv->col = 0;
872 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
873
874#ifdef FEAT_RIGHTLEFT
875 if (wp->w_p_rl)
876 {
877 // Rightleft window: process the text in the normal direction, but put
878 // it in current_ScreenLine[] from right to left. Start at the
879 // rightmost column of the window.
880 wlv->col = wp->w_width - 1;
881 wlv->off += wlv->col;
882 wlv->screen_line_flags |= SLF_RIGHTLEFT;
883 }
884#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100885 if (save_extra)
886 {
887 // reset the drawing state for the start of a wrapped line
888 wlv->draw_state = WL_START;
889 wlv->saved_n_extra = wlv->n_extra;
890 wlv->saved_p_extra = wlv->p_extra;
891 wlv->saved_c_extra = wlv->c_extra;
892 wlv->saved_c_final = wlv->c_final;
893#ifdef FEAT_SYN_HL
894 if (!(wlv->cul_screenline
895# ifdef FEAT_DIFF
896 && wlv->diff_hlf == (hlf_T)0
897# endif
898 ))
899 wlv->saved_char_attr = wlv->char_attr;
900 else
901#endif
902 wlv->saved_char_attr = 0;
903 wlv->n_extra = 0;
904 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100905}
906
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200907/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100908 * Called when wlv->draw_state is set to WL_LINE.
909 */
910 static void
911win_line_continue(winlinevars_T *wlv)
912{
913 if (wlv->saved_n_extra > 0)
914 {
915 // Continue item from end of wrapped line.
916 wlv->n_extra = wlv->saved_n_extra;
917 wlv->c_extra = wlv->saved_c_extra;
918 wlv->c_final = wlv->saved_c_final;
919 wlv->p_extra = wlv->saved_p_extra;
920 wlv->char_attr = wlv->saved_char_attr;
921 }
922 else
923 wlv->char_attr = wlv->win_attr;
924}
925
926/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200927 * Display line "lnum" of window 'wp' on the screen.
928 * Start at row "startrow", stop when "endrow" is reached.
929 * wp->w_virtcol needs to be valid.
930 *
931 * Return the number of last row the line occupies.
932 */
933 int
934win_line(
935 win_T *wp,
936 linenr_T lnum,
937 int startrow,
938 int endrow,
939 int nochange UNUSED, // not updating for changed text
940 int number_only) // only update the number column
941{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100942 winlinevars_T wlv; // variables passed between functions
943
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200944 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100945 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200946 char_u *line; // current line
947 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200948
Bram Moolenaar1306b362022-08-06 15:59:06 +0100949#ifdef FEAT_PROP_POPUP
950 char_u *p_extra_free2 = NULL; // another p_extra to be freed
951#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200952 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000953#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000954 int in_linebreak = FALSE; // n_extra set for showing linebreak
955#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200956 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100957 // displaying eol at end-of-line
958 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000959 int lcs_prec_todo = wp->w_lcs_chars.prec;
960 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200961
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100962 int n_attr = 0; // chars with special attr
963 int n_attr_skip = 0; // chars to skip before using extra_attr
964 int saved_attr2 = 0; // char_attr saved for n_attr
965 int n_attr3 = 0; // chars with overruling special attr
966 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200967
968 int n_skip = 0; // nr of chars to skip for 'nowrap'
969
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200970 int fromcol_prev = -2; // start of inverting after cursor
971 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200972 int lnum_in_visual_area = FALSE;
973 pos_T pos;
974 long v;
975
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200976 int attr_pri = FALSE; // char_attr has priority
977 int area_highlighting = FALSE; // Visual or incsearch highlighting
978 // in this line
979 int vi_attr = 0; // attributes for Visual and incsearch
980 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200981 int area_attr = 0; // attributes desired by highlighting
982 int search_attr = 0; // attributes desired by 'hlsearch'
983#ifdef FEAT_SYN_HL
984 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
985 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200986 int prev_syntax_col = -1; // column of prev_syntax_attr
987 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200988 int has_syntax = FALSE; // this buffer has syntax highl.
989 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200990#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100991#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200992 int text_prop_count;
993 int text_prop_next = 0; // next text property to use
994 textprop_T *text_props = NULL;
995 int *text_prop_idxs = NULL;
996 int text_props_active = 0;
997 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +0100998 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200999 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001000 int text_prop_attr_comb = 0; // text_prop_attr combined with
1001 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001002 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001003 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001004 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001005 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001006 int saved_search_attr = 0; // search_attr to be used when n_extra
1007 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001008 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001009#endif
1010#ifdef FEAT_SPELL
1011 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001012 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001013# define SPWORDLEN 150
1014 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1015 int nextlinecol = 0; // column where nextline[] starts
1016 int nextline_idx = 0; // index in nextline[] where next line
1017 // starts
1018 int spell_attr = 0; // attributes desired by spelling
1019 int word_end = 0; // last byte with same spell_attr
1020 static linenr_T checked_lnum = 0; // line number for "checked_col"
1021 static int checked_col = 0; // column in "checked_lnum" up to which
1022 // there are no spell errors
1023 static int cap_col = -1; // column to check for Cap word
1024 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1025 int cur_checked_col = 0; // checked column for current line
1026#endif
1027 int extra_check = 0; // has extra highlighting
1028 int multi_attr = 0; // attributes desired by multibyte
1029 int mb_l = 1; // multi-byte byte length
1030 int mb_c = 0; // decoded multi-byte character
1031 int mb_utf8 = FALSE; // screen char is UTF-8 char
1032 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001033#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001034 int change_start = MAXCOL; // first col of changed area
1035 int change_end = -1; // last col of changed area
1036#endif
1037 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001038 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001039 int in_multispace = FALSE; // in multiple consecutive spaces
1040 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001041#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
1042 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
1043# define LINE_ATTR
1044 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +01001045 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001046#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001047 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001048 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001049#ifdef FEAT_ARABIC
1050 int prev_c = 0; // previous Arabic character
1051 int prev_c1 = 0; // first composing char for prev_c
1052#endif
1053#if defined(LINE_ATTR)
1054 int did_line_attr = 0;
1055#endif
1056#ifdef FEAT_TERMINAL
1057 int get_term_attr = FALSE;
1058#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001059
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001060#ifdef FEAT_SYN_HL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001061 // margin columns for the screen line, needed for when 'cursorlineopt'
1062 // contains "screenline"
1063 int left_curline_col = 0;
1064 int right_curline_col = 0;
1065#endif
1066
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001067#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1068 int feedback_col = 0;
1069 int feedback_old_attr = -1;
1070#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001071
1072#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1073 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001074 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001075#endif
1076#ifdef FEAT_CONCEAL
1077 int syntax_flags = 0;
1078 int syntax_seqnr = 0;
1079 int prev_syntax_id = 0;
1080 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1081 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001082 int did_wcol = FALSE;
1083 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001084# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001085# define FIX_FOR_BOGUSCOLS \
1086 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001087 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001088 wlv.vcol -= wlv.vcol_off; \
1089 wlv.vcol_off = 0; \
1090 wlv.col -= wlv.boguscols; \
1091 old_boguscols = wlv.boguscols; \
1092 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001093 }
1094#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001095# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001096#endif
1097
1098 if (startrow > endrow) // past the end already!
1099 return startrow;
1100
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001101 CLEAR_FIELD(wlv);
1102
1103 wlv.lnum = lnum;
1104 wlv.startrow = startrow;
1105 wlv.row = startrow;
1106 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001107 wlv.fromcol = -10;
1108 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001109#ifdef FEAT_LINEBREAK
1110 wlv.vcol_sbr = -1;
1111#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001112
1113 if (!number_only)
1114 {
1115 // To speed up the loop below, set extra_check when there is linebreak,
1116 // trailing white space and/or syntax processing to be done.
1117#ifdef FEAT_LINEBREAK
1118 extra_check = wp->w_p_lbr;
1119#endif
1120#ifdef FEAT_SYN_HL
1121 if (syntax_present(wp) && !wp->w_s->b_syn_error
1122# ifdef SYN_TIME_LIMIT
1123 && !wp->w_s->b_syn_slow
1124# endif
1125 )
1126 {
1127 // Prepare for syntax highlighting in this line. When there is an
1128 // error, stop syntax highlighting.
1129 save_did_emsg = did_emsg;
1130 did_emsg = FALSE;
1131 syntax_start(wp, lnum);
1132 if (did_emsg)
1133 wp->w_s->b_syn_error = TRUE;
1134 else
1135 {
1136 did_emsg = save_did_emsg;
1137#ifdef SYN_TIME_LIMIT
1138 if (!wp->w_s->b_syn_slow)
1139#endif
1140 {
1141 has_syntax = TRUE;
1142 extra_check = TRUE;
1143 }
1144 }
1145 }
1146
1147 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001148 wlv.color_cols = wp->w_p_cc_cols;
1149 if (wlv.color_cols != NULL)
1150 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001151#endif
1152
1153#ifdef FEAT_TERMINAL
1154 if (term_show_buffer(wp->w_buffer))
1155 {
1156 extra_check = TRUE;
1157 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001158 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001159 }
1160#endif
1161
1162#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001163 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001164 {
1165 // Prepare for spell checking.
1166 has_spell = TRUE;
1167 extra_check = TRUE;
1168
1169 // Get the start of the next line, so that words that wrap to the
1170 // next line are found too: "et<line-break>al.".
1171 // Trick: skip a few chars for C/shell/Vim comments
1172 nextline[SPWORDLEN] = NUL;
1173 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1174 {
1175 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1176 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1177 }
1178
1179 // When a word wrapped from the previous line the start of the
1180 // current line is valid.
1181 if (lnum == checked_lnum)
1182 cur_checked_col = checked_col;
1183 checked_lnum = 0;
1184
1185 // When there was a sentence end in the previous line may require a
1186 // word starting with capital in this line. In line 1 always check
1187 // the first word.
1188 if (lnum != capcol_lnum)
1189 cap_col = -1;
1190 if (lnum == 1)
1191 cap_col = 0;
1192 capcol_lnum = 0;
1193 }
1194#endif
1195
1196 // handle Visual active in this window
1197 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1198 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001199 pos_T *top, *bot;
1200
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001201 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1202 {
1203 // Visual is after curwin->w_cursor
1204 top = &curwin->w_cursor;
1205 bot = &VIsual;
1206 }
1207 else
1208 {
1209 // Visual is before curwin->w_cursor
1210 top = &VIsual;
1211 bot = &curwin->w_cursor;
1212 }
1213 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1214 if (VIsual_mode == Ctrl_V)
1215 {
1216 // block mode
1217 if (lnum_in_visual_area)
1218 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001219 wlv.fromcol = wp->w_old_cursor_fcol;
1220 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001221 }
1222 }
1223 else
1224 {
1225 // non-block mode
1226 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001227 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001228 else if (lnum == top->lnum)
1229 {
1230 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001231 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001232 else
1233 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001234 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001235 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001236 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001237 }
1238 }
1239 if (VIsual_mode != 'V' && lnum == bot->lnum)
1240 {
1241 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1242 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001243 wlv.fromcol = -10;
1244 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001245 }
1246 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001247 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001248 else
1249 {
1250 pos = *bot;
1251 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001252 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1253 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001254 else
1255 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001256 getvvcol(wp, &pos, NULL, NULL,
1257 (colnr_T *)&wlv.tocol);
1258 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001259 }
1260 }
1261 }
1262 }
1263
1264 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001265 if (!highlight_match && lnum == curwin->w_cursor.lnum
1266 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001267#ifdef FEAT_GUI
1268 && !gui.in_use
1269#endif
1270 )
1271 noinvcur = TRUE;
1272
1273 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001274 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001275 {
1276 area_highlighting = TRUE;
1277 vi_attr = HL_ATTR(HLF_V);
1278#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1279 if ((clip_star.available && !clip_star.owned
1280 && clip_isautosel_star())
1281 || (clip_plus.available && !clip_plus.owned
1282 && clip_isautosel_plus()))
1283 vi_attr = HL_ATTR(HLF_VNC);
1284#endif
1285 }
1286 }
1287
1288 // handle 'incsearch' and ":s///c" highlighting
1289 else if (highlight_match
1290 && wp == curwin
1291 && lnum >= curwin->w_cursor.lnum
1292 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1293 {
1294 if (lnum == curwin->w_cursor.lnum)
1295 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001296 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001297 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001298 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001299 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1300 {
1301 pos.lnum = lnum;
1302 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001303 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001304 }
1305 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001306 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001307 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001308 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1309 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001310 area_highlighting = TRUE;
1311 vi_attr = HL_ATTR(HLF_I);
1312 }
1313 }
1314
1315#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001316 wlv.filler_lines = diff_check(wp, lnum);
1317 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001318 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001319 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001320 {
1321 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001322 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001323 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001324 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001325 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001326 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001327 }
1328 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001329 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001330 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001331 area_highlighting = TRUE;
1332 }
1333 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001334 wlv.filler_lines = wp->w_topfill;
1335 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001336#endif
1337
1338#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001339 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001340 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001341 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001342#endif
1343
1344#ifdef LINE_ATTR
1345# ifdef FEAT_SIGNS
1346 // If this line has a sign with line highlighting set line_attr.
1347 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001348 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001349# endif
1350# if defined(FEAT_QUICKFIX)
1351 // Highlight the current line in the quickfix window.
1352 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1353 line_attr = HL_ATTR(HLF_QFL);
1354# endif
1355 if (line_attr != 0)
1356 area_highlighting = TRUE;
1357#endif
1358
1359 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1360 ptr = line;
1361
1362#ifdef FEAT_SPELL
1363 if (has_spell && !number_only)
1364 {
1365 // For checking first word with a capital skip white space.
1366 if (cap_col == 0)
1367 cap_col = getwhitecols(line);
1368
1369 // To be able to spell-check over line boundaries copy the end of the
1370 // current line into nextline[]. Above the start of the next line was
1371 // copied to nextline[SPWORDLEN].
1372 if (nextline[SPWORDLEN] == NUL)
1373 {
1374 // No next line or it is empty.
1375 nextlinecol = MAXCOL;
1376 nextline_idx = 0;
1377 }
1378 else
1379 {
1380 v = (long)STRLEN(line);
1381 if (v < SPWORDLEN)
1382 {
1383 // Short line, use it completely and append the start of the
1384 // next line.
1385 nextlinecol = 0;
1386 mch_memmove(nextline, line, (size_t)v);
1387 STRMOVE(nextline + v, nextline + SPWORDLEN);
1388 nextline_idx = v + 1;
1389 }
1390 else
1391 {
1392 // Long line, use only the last SPWORDLEN bytes.
1393 nextlinecol = v - SPWORDLEN;
1394 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1395 nextline_idx = SPWORDLEN + 1;
1396 }
1397 }
1398 }
1399#endif
1400
1401 if (wp->w_p_list)
1402 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001403 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001404 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001405 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001406 || wp->w_lcs_chars.trail
1407 || wp->w_lcs_chars.lead
1408 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001409 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001410
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001411 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001412 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001413 {
1414 trailcol = (colnr_T)STRLEN(ptr);
1415 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1416 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001417 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001418 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001419 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001420 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001421 {
1422 leadcol = 0;
1423 while (VIM_ISWHITE(ptr[leadcol]))
1424 ++leadcol;
1425 if (ptr[leadcol] == NUL)
1426 // in a line full of spaces all of them are treated as trailing
1427 leadcol = (colnr_T)0;
1428 else
1429 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001430 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001431 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001432 }
1433
Bram Moolenaard7657e92022-09-20 18:59:30 +01001434 wlv.wcr_attr = get_wcr_attr(wp);
1435 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001436 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001437 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001438 area_highlighting = TRUE;
1439 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001440
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001441#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001442 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001443 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001444#endif
1445
1446 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1447 // first character to be displayed.
1448 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001449 v = startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001450 else
1451 v = wp->w_leftcol;
1452 if (v > 0 && !number_only)
1453 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001454 char_u *prev_ptr = ptr;
1455 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001456 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001457
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001458 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001459 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001460 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001461 charsize = win_lbr_chartabsize(&cts, NULL);
1462 cts.cts_vcol += charsize;
1463 prev_ptr = cts.cts_ptr;
1464 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001465 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001466 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001467 ptr = cts.cts_ptr;
1468 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001469
1470 // When:
1471 // - 'cuc' is set, or
1472 // - 'colorcolumn' is set, or
1473 // - 'virtualedit' is set, or
1474 // - the visual mode is active,
1475 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001476 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001477#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001478 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001479#endif
1480 virtual_active() ||
1481 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001482 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001483
1484 // Handle a character that's not completely on the screen: Put ptr at
1485 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001486 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001487 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001488 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001489 ptr = prev_ptr;
1490 // If the character fits on the screen, don't need to skip it.
1491 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001492 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1493 && wlv.col == 0)
1494 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001495 }
1496
1497 // Adjust for when the inverted text is before the screen,
1498 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001499 if (wlv.tocol <= wlv.vcol)
1500 wlv.fromcol = 0;
1501 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1502 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001503
1504#ifdef FEAT_LINEBREAK
1505 // When w_skipcol is non-zero, first line needs 'showbreak'
1506 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001507 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001508#endif
1509#ifdef FEAT_SPELL
1510 // When spell checking a word we need to figure out the start of the
1511 // word and if it's badly spelled or not.
1512 if (has_spell)
1513 {
1514 int len;
1515 colnr_T linecol = (colnr_T)(ptr - line);
1516 hlf_T spell_hlf = HLF_COUNT;
1517
1518 pos = wp->w_cursor;
1519 wp->w_cursor.lnum = lnum;
1520 wp->w_cursor.col = linecol;
1521 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1522
1523 // spell_move_to() may call ml_get() and make "line" invalid
1524 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1525 ptr = line + linecol;
1526
1527 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1528 {
1529 // no bad word found at line start, don't check until end of a
1530 // word
1531 spell_hlf = HLF_COUNT;
1532 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1533 }
1534 else
1535 {
1536 // bad word found, use attributes until end of word
1537 word_end = wp->w_cursor.col + len + 1;
1538
1539 // Turn index into actual attributes.
1540 if (spell_hlf != HLF_COUNT)
1541 spell_attr = highlight_attr[spell_hlf];
1542 }
1543 wp->w_cursor = pos;
1544
1545# ifdef FEAT_SYN_HL
1546 // Need to restart syntax highlighting for this line.
1547 if (has_syntax)
1548 syntax_start(wp, lnum);
1549# endif
1550 }
1551#endif
1552 }
1553
1554 // Correct highlighting for cursor that can't be disabled.
1555 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001556 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001557 {
1558 if (noinvcur)
1559 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001560 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001561 {
1562 // highlighting starts at cursor, let it start just after the
1563 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001564 fromcol_prev = wlv.fromcol;
1565 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001566 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001567 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001568 // restart highlighting after the cursor
1569 fromcol_prev = wp->w_virtcol;
1570 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001571 if (wlv.fromcol >= wlv.tocol)
1572 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001573 }
1574
1575#ifdef FEAT_SEARCH_EXTRA
1576 if (!number_only)
1577 {
1578 v = (long)(ptr - line);
1579 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1580 &line, &screen_search_hl,
1581 &search_attr);
1582 ptr = line + v; // "line" may have been updated
1583 }
1584#endif
1585
1586#ifdef FEAT_SYN_HL
1587 // Cursor line highlighting for 'cursorline' in the current window.
1588 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1589 {
1590 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001591 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001592 if (!(wp == curwin && VIsual_active)
1593 && wp->w_p_culopt_flags != CULOPT_NBR)
1594 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001595 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001596 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1597
1598 // Only set line_attr here when "screenline" is not present in
1599 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001600 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001601 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001602 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001603# ifdef FEAT_SIGNS
1604 // Combine the 'cursorline' and sign highlighting, depending on
1605 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001606 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001607 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001608 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001609 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001610 else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001611 line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001612 }
1613 else
1614# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001615# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001616 // let the line attribute overrule 'cursorline', otherwise
1617 // it disappears when both have background set;
1618 // 'cursorline' can use underline or bold to make it show
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001619 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001620# else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001621 line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001622# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001623 }
1624 else
1625 {
1626 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001627 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1628 }
1629 area_highlighting = TRUE;
1630 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001631 }
1632#endif
1633
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001634#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001635 {
1636 char_u *prop_start;
1637
1638 text_prop_count = get_text_props(wp->w_buffer, lnum,
1639 &prop_start, FALSE);
1640 if (text_prop_count > 0)
1641 {
1642 // Make a copy of the properties, so that they are properly
1643 // aligned.
1644 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1645 if (text_props != NULL)
1646 mch_memmove(text_props, prop_start,
1647 text_prop_count * sizeof(textprop_T));
1648
1649 // Allocate an array for the indexes.
1650 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001651 if (text_prop_idxs == NULL)
1652 VIM_CLEAR(text_props);
1653
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001654 if (text_props != NULL)
1655 {
1656 area_highlighting = TRUE;
1657 extra_check = TRUE;
1658 for (int i = 0; i < text_prop_count; ++i)
1659 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1660 ++wlv.text_prop_above_count;
1661 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001662 }
1663 }
1664#endif
1665
Bram Moolenaar1306b362022-08-06 15:59:06 +01001666 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001667
1668 // Repeat for the whole displayed line.
1669 for (;;)
1670 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001671 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001672#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001673 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001674#endif
1675#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001676 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001677#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001678
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001679 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001680 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001681 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001682#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001683 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001684 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001685 wlv.cul_attr = 0;
zeertzjq4f33bc22021-08-05 17:57:02 +02001686 line_attr = line_attr_save;
1687 }
1688#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001689 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001690 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001691 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001692 if (cmdwin_type != 0 && wp == curwin)
1693 {
1694 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001695 wlv.n_extra = 1;
1696 wlv.c_extra = cmdwin_type;
1697 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001698 wlv.char_attr =
1699 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001700 }
1701 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001702#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001703 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001704 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001705 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001706 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001707 }
1708#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001709#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001710 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001711 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001712 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001713 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001714 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001715 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001716 }
1717#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001718 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001719 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001720 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001721 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001722 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001723 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001724#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001725 // Check if 'breakindent' applies and show it.
1726 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1727 if (wlv.n_extra == 0)
1728 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001729#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001730#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001731 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001732 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001733 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001734 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001735 }
1736#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001737 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001738 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001739 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001740 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001741 }
1742 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001743
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001744#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001745 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001746 && wlv.vcol >= left_curline_col
1747 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001748 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001749 wlv.cul_attr = HL_ATTR(HLF_CUL);
1750 line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001751 }
1752#endif
1753
1754 // When still displaying '$' of change command, stop at cursor.
1755 // When only displaying the (relative) line number and that's done,
1756 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001757 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001758 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001759 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001760#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001761 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001762#endif
1763 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001764 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001765 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001766 // Pretend we have finished updating the window. Except when
1767 // 'cursorcolumn' is set.
1768#ifdef FEAT_SYN_HL
1769 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001770 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001771 else
1772#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001773 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001774 break;
1775 }
1776
Bram Moolenaar1306b362022-08-06 15:59:06 +01001777 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001778 {
1779 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001780 if (wlv.vcol == wlv.fromcol
1781 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1782 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001783 && (*mb_ptr2cells)(ptr) > 1)
1784 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001785 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001786 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001787 area_attr = vi_attr; // start highlighting
1788 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001789 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001790 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001791 area_attr = 0; // stop highlighting
1792
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001793#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001794 if (text_props != NULL)
1795 {
1796 int pi;
1797 int bcol = (int)(ptr - line);
1798
Bram Moolenaar1306b362022-08-06 15:59:06 +01001799 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001800# ifdef FEAT_LINEBREAK
1801 && !in_linebreak
1802# endif
1803 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001804 --bcol; // still working on the previous char, e.g. Tab
1805
1806 // Check if any active property ends.
1807 for (pi = 0; pi < text_props_active; ++pi)
1808 {
1809 int tpi = text_prop_idxs[pi];
1810
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001811 if (text_props[tpi].tp_col != MAXCOL
1812 && bcol >= text_props[tpi].tp_col - 1
1813 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001814 {
1815 if (pi + 1 < text_props_active)
1816 mch_memmove(text_prop_idxs + pi,
1817 text_prop_idxs + pi + 1,
1818 sizeof(int)
1819 * (text_props_active - (pi + 1)));
1820 --text_props_active;
1821 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001822# ifdef FEAT_LINEBREAK
1823 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001824 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001825 syntax_attr = 0;
1826# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001827 }
1828 }
1829
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001830# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001831 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001832 // not on the next char yet, don't start another prop
1833 --bcol;
1834# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001835 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001836 // With 'nowrap' and not in the first screen line only "below"
1837 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001838 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001839 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001840 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001841 && (wp->w_p_wrap
1842 || wlv.row == startrow
1843 || (text_props[text_prop_next].tp_flags
1844 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001845 || (bcol == 0 &&
1846 (text_props[text_prop_next].tp_flags
1847 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001848 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001849 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001850 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001851 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1852 {
1853 // first display the '$' after the line
1854 text_prop_follows = TRUE;
1855 break;
1856 }
1857 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001858 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001859 + text_props[text_prop_next].tp_len)
1860 text_prop_idxs[text_props_active++] = text_prop_next;
1861 ++text_prop_next;
1862 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001863
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001864 if (wlv.n_extra == 0 || !extra_for_textprop)
1865 {
1866 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001867 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001868 text_prop_flags = 0;
1869 text_prop_type = NULL;
1870 text_prop_id = 0;
1871 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001872 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001873 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001874 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001875 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001876 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001877
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001878 // Sort the properties on priority and/or starting last.
1879 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001880 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001881 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001882 sort_text_props(wp->w_buffer, text_props,
1883 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001884
1885 for (pi = 0; pi < text_props_active; ++pi)
1886 {
1887 int tpi = text_prop_idxs[pi];
1888 proptype_T *pt = text_prop_type_by_id(
1889 wp->w_buffer, text_props[tpi].tp_type);
1890
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001891 if (pt != NULL && (pt->pt_hl_id > 0
1892 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001893 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001894 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001895 if (pt->pt_hl_id > 0)
1896 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001897 text_prop_type = pt;
1898 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001899 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001900 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001901 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001902 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001903 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001904 }
1905 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001906 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001907 && -text_prop_id
1908 <= wp->w_buffer->b_textprop_text.ga_len)
1909 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001910 textprop_T *tp = &text_props[used_tpi];
1911 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001912 ->b_textprop_text.ga_data)[
1913 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001914 int above = (tp->tp_flags
1915 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001916
1917 // reset the ID in the copy to avoid it being used
1918 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001919 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001920
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001921 if (p != NULL)
1922 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001923 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001924 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001925 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001926 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001927 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1928 int padding = tp->tp_col == MAXCOL
1929 && tp->tp_len > 1
1930 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001931
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001932 // Insert virtual text before the current
1933 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001934 wlv.p_extra = p;
1935 wlv.c_extra = NUL;
1936 wlv.c_final = NUL;
1937 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001938 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001939 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001940 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001941 // restore search_attr and area_attr when n_extra
1942 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001943 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001944 saved_area_attr = area_attr;
1945 search_attr = 0;
1946 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001947 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001948 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001949 if (*ptr == NUL)
1950 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001951 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001952#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001953 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001954 {
1955 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001956 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001957 wlv.need_showbreak = FALSE;
1958 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001959 }
1960#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001961 if ((right || above || below || !wrap
1962 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001963 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001964 char_u *prev_p_extra = wlv.p_extra;
1965 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001966
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001967 // Take care of padding, right-align and
1968 // truncation.
1969 // Shared with win_lbr_chartabsize(), must do
1970 // exactly the same.
1971 start_line = text_prop_position(wp, tp,
1972 wlv.col,
1973 &wlv.n_extra, &wlv.p_extra,
1974 &n_attr, &n_attr_skip);
1975 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001976 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001977 // wlv.p_extra was allocated
1978 vim_free(p_extra_free2);
1979 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001980 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001981
Bram Moolenaara4abe512022-09-15 19:44:09 +01001982 if (lcs_eol_one < 0 && wlv.col
1983 + wlv.n_extra - 2 > wp->w_width)
1984 // don't bail out at end of line
1985 lcs_eol_one = 0;
1986
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001987 // When 'wrap' is off then for "below" we need
1988 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001989 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001990 {
1991 draw_screen_line(wp, &wlv);
1992
1993 // When line got too long for screen break
1994 // here.
1995 if (wlv.row == endrow)
1996 {
1997 ++wlv.row;
1998 break;
1999 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002000 win_line_start(wp, &wlv, TRUE);
2001 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002002 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002003 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002004 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002005
2006 // If another text prop follows the condition below at
2007 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002008 // If this is an "above" text prop and 'nowrap' the we
2009 // must wrap anyway.
2010 text_prop_above = above;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002011 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002012 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002013 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002014 else if (text_prop_next < text_prop_count
2015 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002016 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2017 || (!wp->w_p_wrap
2018 && wlv.col == wp->w_width - 1
2019 && (text_props[text_prop_next].tp_flags
2020 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002021 // When at last-but-one character and a text property
2022 // follows after it, we may need to flush the line after
2023 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002024 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002025 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002026 }
2027#endif
2028
Bram Moolenaare38fc862022-08-11 17:24:50 +01002029#ifdef FEAT_SEARCH_EXTRA
2030 if (wlv.n_extra == 0)
2031 {
2032 // Check for start/end of 'hlsearch' and other matches.
2033 // After end, check for start/end of next match.
2034 // When another match, have to check for start again.
2035 v = (long)(ptr - line);
2036 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2037 &screen_search_hl, &has_match_conc,
2038 &match_conc, did_line_attr, lcs_eol_one,
2039 &on_last_col);
2040 ptr = line + v; // "line" may have been changed
2041 prev_ptr = ptr;
2042
2043 // Do not allow a conceal over EOL otherwise EOL will be missed
2044 // and bad things happen.
2045 if (*ptr == NUL)
2046 has_match_conc = 0;
2047 }
2048#endif
2049
2050#ifdef FEAT_DIFF
2051 if (wlv.diff_hlf != (hlf_T)0)
2052 {
2053 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2054 && wlv.n_extra == 0)
2055 wlv.diff_hlf = HLF_TXD; // changed text
2056 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2057 && wlv.n_extra == 0)
2058 wlv.diff_hlf = HLF_CHD; // changed line
2059 line_attr = HL_ATTR(wlv.diff_hlf);
2060 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2061 && wp->w_p_culopt_flags != CULOPT_NBR
2062 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2063 && wlv.vcol <= right_curline_col)))
2064 line_attr = hl_combine_attr(
2065 line_attr, HL_ATTR(HLF_CUL));
2066 }
2067#endif
2068
Bram Moolenaara74fda62019-10-19 17:38:03 +02002069#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002070 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002071 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002072 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002073# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002074 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002075 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002076# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002077 // Get syntax attribute.
2078 if (has_syntax)
2079 {
2080 // Get the syntax attribute for the character. If there
2081 // is an error, disable syntax highlighting.
2082 save_did_emsg = did_emsg;
2083 did_emsg = FALSE;
2084
2085 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002086 if (v == prev_syntax_col)
2087 // at same column again
2088 syntax_attr = prev_syntax_attr;
2089 else
2090 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002091# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002092 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002093# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002094 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002095# ifdef FEAT_SPELL
2096 has_spell ? &can_spell :
2097# endif
2098 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002099 prev_syntax_col = v;
2100 prev_syntax_attr = syntax_attr;
2101 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002102
Bram Moolenaar34390282019-10-16 14:38:26 +02002103 if (did_emsg)
2104 {
2105 wp->w_s->b_syn_error = TRUE;
2106 has_syntax = FALSE;
2107 syntax_attr = 0;
2108 }
2109 else
2110 did_emsg = save_did_emsg;
2111# ifdef SYN_TIME_LIMIT
2112 if (wp->w_s->b_syn_slow)
2113 has_syntax = FALSE;
2114# endif
2115
2116 // Need to get the line again, a multi-line regexp may
2117 // have made it invalid.
2118 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2119 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002120 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002121# ifdef FEAT_CONCEAL
2122 // no concealing past the end of the line, it interferes
2123 // with line highlighting
2124 if (*ptr == NUL)
2125 syntax_flags = 0;
2126 else
2127 syntax_flags = get_syntax_info(&syntax_seqnr);
2128# endif
2129 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002130 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002131# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002132 // Combine text property highlight into syntax highlight.
2133 if (text_prop_type != NULL)
2134 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002135 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002136 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2137 else
2138 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002139 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002140 }
2141# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002142#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002143
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002144 // Decide which of the highlight attributes to use.
2145 attr_pri = TRUE;
2146#ifdef LINE_ATTR
2147 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002148 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002149 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002150 if (!highlight_match)
2151 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002152 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002153# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002154 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002155# endif
2156 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002157 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002158 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002159 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002160# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002161 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002162# endif
2163 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002164 else if (line_attr != 0
2165 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2166 || wlv.vcol < wlv.fromcol
2167 || vcol_prev < fromcol_prev
2168 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002169 {
2170 // Use line_attr when not in the Visual or 'incsearch' area
2171 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002172# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002173 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002174# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002175 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002176# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002177 attr_pri = FALSE;
2178 }
2179#else
2180 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002181 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002182 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002183 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002184#endif
2185 else
2186 {
2187 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002188#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002189 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002190#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002191 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002192#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002193 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002194#ifdef FEAT_PROP_POPUP
2195 // override with text property highlight when "override" is TRUE
2196 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002197 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002198#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002199 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002200
2201 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002202 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002203 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002204 if (wlv.char_attr == 0)
2205 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002206 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002207 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002208 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002209
2210 // Get the next character to put on the screen.
2211
2212 // The "p_extra" points to the extra stuff that is inserted to
2213 // represent special characters (non-printable stuff) and other
2214 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002215 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002216 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2217 // "p_extra[n_extra]".
2218 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002219 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002220 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002221 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002222 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002223 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2224 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002225 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2226 if (enc_utf8 && utf_char2len(c) > 1)
2227 {
2228 mb_utf8 = TRUE;
2229 u8cc[0] = 0;
2230 c = 0xc0;
2231 }
2232 else
2233 mb_utf8 = FALSE;
2234 }
2235 else
2236 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002237 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002238 if (has_mbyte)
2239 {
2240 mb_c = c;
2241 if (enc_utf8)
2242 {
2243 // If the UTF-8 character is more than one byte:
2244 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002245 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002246 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002247 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002248 mb_l = 1;
2249 else if (mb_l > 1)
2250 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002251 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002252 mb_utf8 = TRUE;
2253 c = 0xc0;
2254 }
2255 }
2256 else
2257 {
2258 // if this is a DBCS character, put it in "mb_c"
2259 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002260 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002261 mb_l = 1;
2262 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002263 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002264 }
2265 if (mb_l == 0) // at the NUL at end-of-line
2266 mb_l = 1;
2267
2268 // If a double-width char doesn't fit display a '>' in the
2269 // last column.
2270 if ((
2271# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002272 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002273# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002274 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002275 && (*mb_char2cells)(mb_c) == 2)
2276 {
2277 c = '>';
2278 mb_c = c;
2279 mb_l = 1;
2280 mb_utf8 = FALSE;
2281 multi_attr = HL_ATTR(HLF_AT);
2282#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002283 if (wlv.cul_attr)
2284 multi_attr = hl_combine_attr(
2285 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002286#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002287 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002288
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002289 // put the pointer back to output the double-width
2290 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002291 ++wlv.n_extra;
2292 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002293 }
2294 else
2295 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002296 wlv.n_extra -= mb_l - 1;
2297 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002298 }
2299 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002300 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002301 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002302 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002303#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002304 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002305 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002306 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002307 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002308 if (search_attr == 0)
2309 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002310 if (area_attr == 0 && *ptr != NUL)
2311 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002312 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002313#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002314 }
2315 else
2316 {
2317#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002318 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002319#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002320 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002321
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002322 // Get a character from the line itself.
2323 c = *ptr;
2324#ifdef FEAT_LINEBREAK
2325 c0 = *ptr;
2326#endif
2327 if (has_mbyte)
2328 {
2329 mb_c = c;
2330 if (enc_utf8)
2331 {
2332 // If the UTF-8 character is more than one byte: Decode it
2333 // into "mb_c".
2334 mb_l = utfc_ptr2len(ptr);
2335 mb_utf8 = FALSE;
2336 if (mb_l > 1)
2337 {
2338 mb_c = utfc_ptr2char(ptr, u8cc);
2339 // Overlong encoded ASCII or ASCII with composing char
2340 // is displayed normally, except a NUL.
2341 if (mb_c < 0x80)
2342 {
2343 c = mb_c;
2344#ifdef FEAT_LINEBREAK
2345 c0 = mb_c;
2346#endif
2347 }
2348 mb_utf8 = TRUE;
2349
2350 // At start of the line we can have a composing char.
2351 // Draw it as a space with a composing char.
2352 if (utf_iscomposing(mb_c))
2353 {
2354 int i;
2355
2356 for (i = Screen_mco - 1; i > 0; --i)
2357 u8cc[i] = u8cc[i - 1];
2358 u8cc[0] = mb_c;
2359 mb_c = ' ';
2360 }
2361 }
2362
2363 if ((mb_l == 1 && c >= 0x80)
2364 || (mb_l >= 1 && mb_c == 0)
2365 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2366 {
2367 // Illegal UTF-8 byte: display as <xx>.
2368 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002369 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002370# ifdef FEAT_RIGHTLEFT
2371 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002372 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002373# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002374 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002375 c = *wlv.p_extra;
2376 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002377 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002378 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2379 wlv.c_extra = NUL;
2380 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002381 if (area_attr == 0 && search_attr == 0)
2382 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002383 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002384 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002385 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002386 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002387 }
2388 }
2389 else if (mb_l == 0) // at the NUL at end-of-line
2390 mb_l = 1;
2391#ifdef FEAT_ARABIC
2392 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2393 {
2394 // Do Arabic shaping.
2395 int pc, pc1, nc;
2396 int pcc[MAX_MCO];
2397
2398 // The idea of what is the previous and next
2399 // character depends on 'rightleft'.
2400 if (wp->w_p_rl)
2401 {
2402 pc = prev_c;
2403 pc1 = prev_c1;
2404 nc = utf_ptr2char(ptr + mb_l);
2405 prev_c1 = u8cc[0];
2406 }
2407 else
2408 {
2409 pc = utfc_ptr2char(ptr + mb_l, pcc);
2410 nc = prev_c;
2411 pc1 = pcc[0];
2412 }
2413 prev_c = mb_c;
2414
2415 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2416 }
2417 else
2418 prev_c = mb_c;
2419#endif
2420 }
2421 else // enc_dbcs
2422 {
2423 mb_l = MB_BYTE2LEN(c);
2424 if (mb_l == 0) // at the NUL at end-of-line
2425 mb_l = 1;
2426 else if (mb_l > 1)
2427 {
2428 // We assume a second byte below 32 is illegal.
2429 // Hopefully this is OK for all double-byte encodings!
2430 if (ptr[1] >= 32)
2431 mb_c = (c << 8) + ptr[1];
2432 else
2433 {
2434 if (ptr[1] == NUL)
2435 {
2436 // head byte at end of line
2437 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002438 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002439 }
2440 else
2441 {
2442 // illegal tail byte
2443 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002444 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002445 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002446 wlv.p_extra = wlv.extra;
2447 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002448 wlv.c_extra = NUL;
2449 wlv.c_final = NUL;
2450 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002451 if (area_attr == 0 && search_attr == 0)
2452 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002453 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002454 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002455 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002456 // save current attr
2457 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002458 }
2459 mb_c = c;
2460 }
2461 }
2462 }
2463 // If a double-width char doesn't fit display a '>' in the
2464 // last column; the character is displayed at the start of the
2465 // next line.
2466 if ((
2467# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002468 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002469# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002470 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002471 && (*mb_char2cells)(mb_c) == 2)
2472 {
2473 c = '>';
2474 mb_c = c;
2475 mb_utf8 = FALSE;
2476 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002477 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002478 // Put pointer back so that the character will be
2479 // displayed at the start of the next line.
2480 --ptr;
2481#ifdef FEAT_CONCEAL
2482 did_decrement_ptr = TRUE;
2483#endif
2484 }
2485 else if (*ptr != NUL)
2486 ptr += mb_l - 1;
2487
2488 // If a double-width char doesn't fit at the left side display
2489 // a '<' in the first column. Don't do this for unprintable
2490 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002491 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002492 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002493 wlv.n_extra = 1;
2494 wlv.c_extra = MB_FILLER_CHAR;
2495 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002496 c = ' ';
2497 if (area_attr == 0 && search_attr == 0)
2498 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002499 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002500 extra_attr = hl_combine_attr(
2501 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002502 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002503 }
2504 mb_c = c;
2505 mb_utf8 = FALSE;
2506 mb_l = 1;
2507 }
2508
2509 }
2510 ++ptr;
2511
2512 if (extra_check)
2513 {
2514#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002515 // Check spelling (unless at the end of the line).
2516 // Only do this when there is no syntax highlighting, the
2517 // @Spell cluster is not used or the current syntax item
2518 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002519 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002520 if (has_spell && v >= word_end && v > cur_checked_col)
2521 {
2522 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002523 // do not calculate cap_col at the end of the line or when
2524 // only white space is following
2525 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002526# ifdef FEAT_SYN_HL
2527 !has_syntax ||
2528# endif
2529 can_spell))
2530 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002531 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002532 int len;
2533 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002534
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002535 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002536 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002537
2538 // Use nextline[] if possible, it has the start of the
2539 // next line concatenated.
2540 if ((prev_ptr - line) - nextlinecol >= 0)
2541 p = nextline + (prev_ptr - line) - nextlinecol;
2542 else
2543 p = prev_ptr;
2544 cap_col -= (int)(prev_ptr - line);
2545 len = spell_check(wp, p, &spell_hlf, &cap_col,
2546 nochange);
2547 word_end = v + len;
2548
2549 // In Insert mode only highlight a word that
2550 // doesn't touch the cursor.
2551 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002552 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002553 && wp->w_cursor.lnum == lnum
2554 && wp->w_cursor.col >=
2555 (colnr_T)(prev_ptr - line)
2556 && wp->w_cursor.col < (colnr_T)word_end)
2557 {
2558 spell_hlf = HLF_COUNT;
2559 spell_redraw_lnum = lnum;
2560 }
2561
2562 if (spell_hlf == HLF_COUNT && p != prev_ptr
2563 && (p - nextline) + len > nextline_idx)
2564 {
2565 // Remember that the good word continues at the
2566 // start of the next line.
2567 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002568 checked_col = (int)((p - nextline)
2569 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002570 }
2571
2572 // Turn index into actual attributes.
2573 if (spell_hlf != HLF_COUNT)
2574 spell_attr = highlight_attr[spell_hlf];
2575
2576 if (cap_col > 0)
2577 {
2578 if (p != prev_ptr
2579 && (p - nextline) + cap_col >= nextline_idx)
2580 {
2581 // Remember that the word in the next line
2582 // must start with a capital.
2583 capcol_lnum = lnum + 1;
2584 cap_col = (int)((p - nextline) + cap_col
2585 - nextline_idx);
2586 }
2587 else
2588 // Compute the actual column.
2589 cap_col += (int)(prev_ptr - line);
2590 }
2591 }
2592 }
2593 if (spell_attr != 0)
2594 {
2595 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002596 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2597 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002598 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002599 wlv.char_attr = hl_combine_attr(spell_attr,
2600 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002601 }
2602#endif
2603#ifdef FEAT_LINEBREAK
2604 // Found last space before word: check for line break.
2605 if (wp->w_p_lbr && c0 == c
2606 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2607 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002608 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2609 : 0;
2610 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002611 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002612
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002613 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002614# ifdef FEAT_PROP_POPUP
2615 // do not want virtual text counted here
2616 cts.cts_has_prop_with_text = FALSE;
2617# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002618 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002619 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002620
2621 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002622 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002623 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002624 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002625 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2626 if (wlv.n_extra < 0)
2627 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002628 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002629 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002630 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002631 // line break, but for TABs the highlighting should
2632 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002633 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002634
Bram Moolenaar1306b362022-08-06 15:59:06 +01002635 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002636# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002637 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002638 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002639 wp->w_buffer->b_p_vts_array) - 1;
2640# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002641 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002642 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002643# endif
2644
Bram Moolenaar1306b362022-08-06 15:59:06 +01002645 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2646 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002647# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002648 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002649 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002650# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002651 if (VIM_ISWHITE(c))
2652 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002653# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002654 if (c == TAB)
2655 // See "Tab alignment" below.
2656 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002657# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002658 if (!wp->w_p_list)
2659 c = ' ';
2660 }
2661 }
2662#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002663 in_multispace = c == ' '
2664 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2665 if (!in_multispace)
2666 multispace_pos = 0;
2667
Bram Moolenaareed9d462021-02-15 20:38:25 +01002668 // 'list': Change char 160 to 'nbsp' and space to 'space'
2669 // setting in 'listchars'. But not when the character is
2670 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002671 if (wp->w_p_list
2672 && ((((c == 160 && mb_l == 1)
2673 || (mb_utf8
2674 && ((mb_c == 160 && mb_l == 2)
2675 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002676 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002677 || (c == ' '
2678 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002679 && (wp->w_lcs_chars.space
2680 || (in_multispace
2681 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002682 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002683 && ptr - line <= trailcol)))
2684 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002685 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2686 {
2687 c = wp->w_lcs_chars.multispace[multispace_pos++];
2688 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2689 multispace_pos = 0;
2690 }
2691 else
2692 c = (c == ' ') ? wp->w_lcs_chars.space
2693 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002694 if (area_attr == 0 && search_attr == 0)
2695 {
2696 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002697 extra_attr = hl_combine_attr(wlv.win_attr,
2698 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002699 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002700 }
2701 mb_c = c;
2702 if (enc_utf8 && utf_char2len(c) > 1)
2703 {
2704 mb_utf8 = TRUE;
2705 u8cc[0] = 0;
2706 c = 0xc0;
2707 }
2708 else
2709 mb_utf8 = FALSE;
2710 }
2711
zeertzjq2e7cba32022-06-10 15:30:32 +01002712 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2713 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002714 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002715 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2716 && wp->w_lcs_chars.leadmultispace != NULL)
2717 {
2718 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002719 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2720 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002721 multispace_pos = 0;
2722 }
2723
2724 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2725 c = wp->w_lcs_chars.trail;
2726
2727 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2728 c = wp->w_lcs_chars.lead;
2729
zeertzjq2e7cba32022-06-10 15:30:32 +01002730 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002731 c = wp->w_lcs_chars.space;
2732
2733
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002734 if (!attr_pri)
2735 {
2736 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002737 extra_attr = hl_combine_attr(wlv.win_attr,
2738 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002739 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002740 }
2741 mb_c = c;
2742 if (enc_utf8 && utf_char2len(c) > 1)
2743 {
2744 mb_utf8 = TRUE;
2745 u8cc[0] = 0;
2746 c = 0xc0;
2747 }
2748 else
2749 mb_utf8 = FALSE;
2750 }
2751 }
2752
2753 // Handling of non-printable characters.
2754 if (!vim_isprintc(c))
2755 {
2756 // when getting a character from the file, we may have to
2757 // turn it into something else on the way to putting it
2758 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002759 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002760 {
2761 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002762 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002763#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002764 char_u *sbr = get_showbreak_value(wp);
2765
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002766 // only adjust the tab_len, when at the first column
2767 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002768 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002769 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002770#endif
2771 // tab amount depends on current column
2772#ifdef FEAT_VARTABS
2773 tab_len = tabstop_padding(vcol_adjusted,
2774 wp->w_buffer->b_p_ts,
2775 wp->w_buffer->b_p_vts_array) - 1;
2776#else
2777 tab_len = (int)wp->w_buffer->b_p_ts
2778 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2779#endif
2780
2781#ifdef FEAT_LINEBREAK
2782 if (!wp->w_p_lbr || !wp->w_p_list)
2783#endif
2784 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002785 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002786#ifdef FEAT_LINEBREAK
2787 else
2788 {
2789 char_u *p;
2790 int len;
2791 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002792 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002793
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002794# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002795 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002796 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002797 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002798
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002799 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002800 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002801 && old_boguscols > 0
2802 && wlv.n_extra > tab_len)
2803 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002804# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002805 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002806 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002807 // for a tab.
Bram Moolenaara0789472022-10-08 11:16:40 +01002808 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
2809 len = tab_len * tab2_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002810 if (wp->w_lcs_chars.tab3)
Bram Moolenaara0789472022-10-08 11:16:40 +01002811 len += mb_char2len(wp->w_lcs_chars.tab3) - tab2_len;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002812 if (wlv.n_extra > 0)
2813 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002814 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002815 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002816 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002817 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002818 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002819 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002820 vim_memset(p, ' ', len);
2821 p[len] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002822 vim_free(wlv.p_extra_free);
2823 wlv.p_extra_free = p;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002824 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002825 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002826 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002827
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002828 if (*p == NUL)
2829 {
2830 tab_len = i;
2831 break;
2832 }
2833
2834 // if tab3 is given, use it for the last char
2835 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2836 lcs = wp->w_lcs_chars.tab3;
2837 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002838 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002839 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002840 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002841 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002842# ifdef FEAT_CONCEAL
2843 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2844 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002845 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002846 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002847# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002848 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002849 }
2850#endif
2851#ifdef FEAT_CONCEAL
2852 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002853 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002854
2855 // Tab alignment should be identical regardless of
2856 // 'conceallevel' value. So tab compensates of all
2857 // previous concealed characters, and thus resets
2858 // vcol_off and boguscols accumulated so far in the
2859 // line. Note that the tab can be longer than
2860 // 'tabstop' when there are concealed characters.
2861 FIX_FOR_BOGUSCOLS;
2862
2863 // Make sure, the highlighting for the tab char will be
2864 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002865 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002866 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002867 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002868 tab_len += vc_saved;
2869 }
2870#endif
2871 mb_utf8 = FALSE; // don't draw as UTF-8
2872 if (wp->w_p_list)
2873 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002874 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002875 ? wp->w_lcs_chars.tab3
2876 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002877#ifdef FEAT_LINEBREAK
2878 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002879 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002880 else
2881#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002882 wlv.c_extra = wp->w_lcs_chars.tab2;
2883 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002884 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002885 extra_attr = hl_combine_attr(wlv.win_attr,
2886 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002887 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002888 mb_c = c;
2889 if (enc_utf8 && utf_char2len(c) > 1)
2890 {
2891 mb_utf8 = TRUE;
2892 u8cc[0] = 0;
2893 c = 0xc0;
2894 }
2895 }
2896 else
2897 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002898 wlv.c_final = NUL;
2899 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002900 c = ' ';
2901 }
2902 }
2903 else if (c == NUL
2904 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002905 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
2906 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002907 && VIsual_mode != Ctrl_V
2908 && (
2909# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002910 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002911# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002912 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002913 && !(noinvcur
2914 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002915 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002916 && lcs_eol_one > 0)
2917 {
2918 // Display a '$' after the line or highlight an extra
2919 // character if the line break is included.
2920#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2921 // For a diff line the highlighting continues after the
2922 // "$".
2923 if (
2924# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002925 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002926# ifdef LINE_ATTR
2927 &&
2928# endif
2929# endif
2930# ifdef LINE_ATTR
2931 line_attr == 0
2932# endif
2933 )
2934#endif
2935 {
2936 // In virtualedit, visual selections may extend
2937 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002938 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002939 && wlv.tocol != MAXCOL
2940 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002941 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002942 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002943 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002944 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2945 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002946 else
2947 c = ' ';
2948 lcs_eol_one = -1;
2949 --ptr; // put it back at the NUL
2950 if (!attr_pri)
2951 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002952 extra_attr = hl_combine_attr(wlv.win_attr,
2953 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002954 n_attr = 1;
2955 }
2956 mb_c = c;
2957 if (enc_utf8 && utf_char2len(c) > 1)
2958 {
2959 mb_utf8 = TRUE;
2960 u8cc[0] = 0;
2961 c = 0xc0;
2962 }
2963 else
2964 mb_utf8 = FALSE; // don't draw as UTF-8
2965 }
2966 else if (c != NUL)
2967 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002968 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2969 if (wlv.n_extra == 0)
2970 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002971#ifdef FEAT_RIGHTLEFT
2972 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002973 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002974#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002975 wlv.c_extra = NUL;
2976 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002977#ifdef FEAT_LINEBREAK
2978 if (wp->w_p_lbr)
2979 {
2980 char_u *p;
2981
Bram Moolenaar1306b362022-08-06 15:59:06 +01002982 c = *wlv.p_extra;
2983 p = alloc(wlv.n_extra + 1);
2984 vim_memset(p, ' ', wlv.n_extra);
2985 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2986 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002987 vim_free(wlv.p_extra_free);
2988 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002989 }
2990 else
2991#endif
2992 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002993 wlv.n_extra = byte2cells(c) - 1;
2994 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002995 }
2996 if (!attr_pri)
2997 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002998 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002999 extra_attr = hl_combine_attr(wlv.win_attr,
3000 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003001 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003002 }
3003 mb_utf8 = FALSE; // don't draw as UTF-8
3004 }
3005 else if (VIsual_active
3006 && (VIsual_mode == Ctrl_V
3007 || VIsual_mode == 'v')
3008 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003009 && wlv.tocol != MAXCOL
3010 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003011 && (
3012#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003013 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003014#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003015 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003016 {
3017 c = ' ';
3018 --ptr; // put it back at the NUL
3019 }
3020#if defined(LINE_ATTR)
3021 else if ((
3022# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003023 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003024# endif
3025# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003026 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003027# endif
3028 line_attr != 0
3029 ) && (
3030# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003031 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003032# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003033 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003034# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003035 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003036# endif
3037 < wp->w_width)))
3038 {
3039 // Highlight until the right side of the window
3040 c = ' ';
3041 --ptr; // put it back at the NUL
3042
3043 // Remember we do the char for line highlighting.
3044 ++did_line_attr;
3045
3046 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01003047 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003048 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003049 || (wp->w_p_list &&
3050 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003051 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003052# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003053 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003054 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003055 wlv.diff_hlf = HLF_CHD;
3056 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003057 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003058 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003059 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3060 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003061 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003062 || (wlv.vcol >= left_curline_col
3063 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003064 wlv.char_attr = hl_combine_attr(
3065 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003066 }
3067 }
3068# endif
3069# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003070 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003071 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003072 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003073 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3074 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003075 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003076 if (!wlv.cul_screenline
3077 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003078 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003079 wlv.char_attr = hl_combine_attr(
3080 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003081 }
3082 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003083 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3084 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003085 }
3086# endif
3087 }
3088#endif
3089 }
3090
3091#ifdef FEAT_CONCEAL
3092 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003093 && (wp != curwin || lnum != wp->w_cursor.lnum
3094 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003095 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3096 && !(lnum_in_visual_area
3097 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3098 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003099 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003100 if (((prev_syntax_id != syntax_seqnr
3101 && (syntax_flags & HL_CONCEAL) != 0)
3102 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003103 && (syn_get_sub_char() != NUL
3104 || (has_match_conc && match_conc)
3105 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003106 && wp->w_p_cole != 3)
3107 {
3108 // First time at this concealed item: display one
3109 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003110 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003111 c = match_conc;
3112 else if (syn_get_sub_char() != NUL)
3113 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003114 else if (wp->w_lcs_chars.conceal != NUL)
3115 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003116 else
3117 c = ' ';
3118
3119 prev_syntax_id = syntax_seqnr;
3120
Bram Moolenaar1306b362022-08-06 15:59:06 +01003121 if (wlv.n_extra > 0)
3122 wlv.vcol_off += wlv.n_extra;
3123 wlv.vcol += wlv.n_extra;
3124 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003125 {
3126# ifdef FEAT_RIGHTLEFT
3127 if (wp->w_p_rl)
3128 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003129 wlv.col -= wlv.n_extra;
3130 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003131 }
3132 else
3133# endif
3134 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003135 wlv.boguscols += wlv.n_extra;
3136 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003137 }
3138 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003139 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003140 n_attr = 0;
3141 }
3142 else if (n_skip == 0)
3143 {
3144 is_concealing = TRUE;
3145 n_skip = 1;
3146 }
3147 mb_c = c;
3148 if (enc_utf8 && utf_char2len(c) > 1)
3149 {
3150 mb_utf8 = TRUE;
3151 u8cc[0] = 0;
3152 c = 0xc0;
3153 }
3154 else
3155 mb_utf8 = FALSE; // don't draw as UTF-8
3156 }
3157 else
3158 {
3159 prev_syntax_id = 0;
3160 is_concealing = FALSE;
3161 }
3162
3163 if (n_skip > 0 && did_decrement_ptr)
3164 // not showing the '>', put pointer back to avoid getting stuck
3165 ++ptr;
3166
3167#endif // FEAT_CONCEAL
3168 }
3169
3170#ifdef FEAT_CONCEAL
3171 // In the cursor line and we may be concealing characters: correct
3172 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003173 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003174 && wp == curwin && lnum == wp->w_cursor.lnum
3175 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003176 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003177 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003178# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003179 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003180 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003181 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003182# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003183 wp->w_wcol = wlv.col - wlv.boguscols;
3184 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003185 did_wcol = TRUE;
3186 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003187# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003188 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003189# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003190 }
3191#endif
3192
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003193 // Use "extra_attr", but don't override visual selection highlighting,
3194 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003195 // Don't use "extra_attr" until n_attr_skip is zero.
3196 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003197 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003198 && (!attr_pri
3199#ifdef FEAT_PROP_POPUP
3200 || (text_prop_flags & PT_FLAG_OVERRIDE)
3201#endif
3202 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003203 {
3204#ifdef LINE_ATTR
3205 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003206 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003207 else
3208#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003209 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003210 }
3211
3212#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3213 // XIM don't send preedit_start and preedit_end, but they send
3214 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3215 // im_is_preediting() here.
3216 if (p_imst == IM_ON_THE_SPOT
3217 && xic != NULL
3218 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003219 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003220 && !p_imdisable
3221 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003222 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003223 {
3224 colnr_T tcol;
3225
3226 if (preedit_end_col == MAXCOL)
3227 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3228 else
3229 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003230 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003231 {
3232 if (feedback_old_attr < 0)
3233 {
3234 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003235 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003236 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003237 wlv.char_attr = im_get_feedback_attr(feedback_col);
3238 if (wlv.char_attr < 0)
3239 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003240 feedback_col++;
3241 }
3242 else if (feedback_old_attr >= 0)
3243 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003244 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003245 feedback_old_attr = -1;
3246 feedback_col = 0;
3247 }
3248 }
3249#endif
3250 // Handle the case where we are in column 0 but not on the first
3251 // character of the line and the user wants us to show us a
3252 // special character (via 'listchars' option "precedes:<char>".
3253 if (lcs_prec_todo != NUL
3254 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003255 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3256 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003257#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003258 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003259#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003260 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003261 && c != NUL)
3262 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003263 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003264 lcs_prec_todo = NUL;
3265 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3266 {
3267 // Double-width character being overwritten by the "precedes"
3268 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003269 wlv.c_extra = MB_FILLER_CHAR;
3270 wlv.c_final = NUL;
3271 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003272 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003273 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003274 }
3275 mb_c = c;
3276 if (enc_utf8 && utf_char2len(c) > 1)
3277 {
3278 mb_utf8 = TRUE;
3279 u8cc[0] = 0;
3280 c = 0xc0;
3281 }
3282 else
3283 mb_utf8 = FALSE; // don't draw as UTF-8
3284 if (!attr_pri)
3285 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003286 saved_attr3 = wlv.char_attr; // save current attr
3287 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003288 n_attr3 = 1;
3289 }
3290 }
3291
3292 // At end of the text line or just after the last character.
3293 if ((c == NUL
3294#if defined(LINE_ATTR)
3295 || did_line_attr == 1
3296#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003297 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003298 {
3299#ifdef FEAT_SEARCH_EXTRA
3300 // flag to indicate whether prevcol equals startcol of search_hl or
3301 // one of the matches
3302 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3303 (long)(ptr - line) - (c == NUL));
3304#endif
3305 // Invert at least one char, used for Visual and empty line or
3306 // highlight match at end of line. If it's beyond the last
3307 // char on the screen, just overwrite that one (tricky!) Not
3308 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003309 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003310 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003311 && (VIsual_mode != Ctrl_V
3312 || lnum == VIsual.lnum
3313 || lnum == curwin->w_cursor.lnum)
3314 && c == NUL)
3315#ifdef FEAT_SEARCH_EXTRA
3316 // highlight 'hlsearch' match at end of line
3317 || (prevcol_hl_flag
3318# ifdef FEAT_SYN_HL
3319 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3320 && !(wp == curwin && VIsual_active))
3321# endif
3322# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003323 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003324# endif
3325# if defined(LINE_ATTR)
3326 && did_line_attr <= 1
3327# endif
3328 )
3329#endif
3330 ))
3331 {
3332 int n = 0;
3333
3334#ifdef FEAT_RIGHTLEFT
3335 if (wp->w_p_rl)
3336 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003337 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003338 n = 1;
3339 }
3340 else
3341#endif
3342 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003343 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003344 n = -1;
3345 }
3346 if (n != 0)
3347 {
3348 // At the window boundary, highlight the last character
3349 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003350 wlv.off += n;
3351 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003352 }
3353 else
3354 {
3355 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003356 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003357 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003358 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003359 }
3360#ifdef FEAT_SEARCH_EXTRA
3361 if (area_attr == 0)
3362 {
3363 // Use attributes from match with highest priority among
3364 // 'search_hl' and the match list.
3365 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003366 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003367 }
3368#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003369 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003370 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003371#ifdef FEAT_RIGHTLEFT
3372 if (wp->w_p_rl)
3373 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003374 --wlv.col;
3375 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003376 }
3377 else
3378#endif
3379 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003380 ++wlv.col;
3381 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003382 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003383 ++wlv.vcol;
3384 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003385 }
3386 }
3387
3388 // At end of the text line.
3389 if (c == NUL)
3390 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003391 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003392
3393 // Update w_cline_height and w_cline_folded if the cursor line was
3394 // updated (saves a call to plines() later).
3395 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3396 {
3397 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003398 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003399#ifdef FEAT_FOLDING
3400 curwin->w_cline_folded = FALSE;
3401#endif
3402 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3403 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003404 break;
3405 }
3406
3407 // Show "extends" character from 'listchars' if beyond the line end and
3408 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003409 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003410 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003411 && wp->w_p_list
3412 && !wp->w_p_wrap
3413#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003414 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003415#endif
3416 && (
3417#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003418 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003419#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003420 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003421 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003422 || lcs_eol_one > 0
3423 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003424 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003425 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003426 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003427 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003428 mb_c = c;
3429 if (enc_utf8 && utf_char2len(c) > 1)
3430 {
3431 mb_utf8 = TRUE;
3432 u8cc[0] = 0;
3433 c = 0xc0;
3434 }
3435 else
3436 mb_utf8 = FALSE;
3437 }
3438
3439#ifdef FEAT_SYN_HL
3440 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003441 if (wlv.draw_color_col)
3442 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003443
3444 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3445 // highlight the cursor position itself.
3446 // Also highlight the 'colorcolumn' if it is different than
3447 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003448 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3449 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003450 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003451 if (((wlv.draw_state == WL_LINE
3452 || wlv.draw_state == WL_BRI
3453 || wlv.draw_state == WL_SBR)
3454 && !lnum_in_visual_area
3455 && search_attr == 0
3456 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003457# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003458 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003459# endif
3460 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003461 {
3462 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3463 && lnum != wp->w_cursor.lnum)
3464 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003465 vcol_save_attr = wlv.char_attr;
3466 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3467 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003468 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003469 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003470 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003471 vcol_save_attr = wlv.char_attr;
3472 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003473 }
3474 }
3475#endif
3476
3477 // Store character to be displayed.
3478 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003479 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003480 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003481 {
3482 // Store the character.
3483#if defined(FEAT_RIGHTLEFT)
3484 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3485 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003486 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003487 --wlv.off;
3488 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003489 }
3490#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003491 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003492 if (enc_dbcs == DBCS_JPNU)
3493 {
3494 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003495 ScreenLines[wlv.off] = 0x8e;
3496 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003497 }
3498 else if (enc_utf8)
3499 {
3500 if (mb_utf8)
3501 {
3502 int i;
3503
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003504 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003505 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003506 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003507 for (i = 0; i < Screen_mco; ++i)
3508 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003509 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003510 if (u8cc[i] == 0)
3511 break;
3512 }
3513 }
3514 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003515 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003516 }
3517 if (multi_attr)
3518 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003519 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003520 multi_attr = 0;
3521 }
3522 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003523 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003524
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003525 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003526
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003527 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3528 {
3529 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003530 ++wlv.off;
3531 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003532 if (enc_utf8)
3533 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003534 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003535 else
3536 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003537 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003538 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003539#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003540 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003541#endif
3542 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003543 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003544 // When "wlv.tocol" is halfway a character, set it to the end
3545 // of the character, otherwise highlighting won't stop.
3546 if (wlv.tocol == wlv.vcol)
3547 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003548
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003549 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003550
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003551#ifdef FEAT_RIGHTLEFT
3552 if (wp->w_p_rl)
3553 {
3554 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003555 --wlv.off;
3556 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003557 }
3558#endif
3559 }
3560#ifdef FEAT_RIGHTLEFT
3561 if (wp->w_p_rl)
3562 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003563 --wlv.off;
3564 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003565 }
3566 else
3567#endif
3568 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003569 ++wlv.off;
3570 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003571 }
3572 }
3573#ifdef FEAT_CONCEAL
3574 else if (wp->w_p_cole > 0 && is_concealing)
3575 {
3576 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003577 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003578 if (wlv.n_extra > 0)
3579 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003580 if (wp->w_p_wrap)
3581 {
3582 // Special voodoo required if 'wrap' is on.
3583 //
3584 // Advance the column indicator to force the line
3585 // drawing to wrap early. This will make the line
3586 // take up the same screen space when parts are concealed,
3587 // so that cursor line computations aren't messed up.
3588 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003589 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003590 // trailing junk to be written out of the screen line
3591 // we are building, 'boguscols' keeps track of the number
3592 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003593 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003594 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003595 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003596# ifdef FEAT_RIGHTLEFT
3597 if (wp->w_p_rl)
3598 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003599 wlv.col -= wlv.n_extra;
3600 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003601 }
3602 else
3603# endif
3604 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003605 wlv.col += wlv.n_extra;
3606 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003607 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003608 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003609 n_attr = 0;
3610 }
3611
3612
3613 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3614 {
3615 // Need to fill two screen columns.
3616# ifdef FEAT_RIGHTLEFT
3617 if (wp->w_p_rl)
3618 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003619 --wlv.boguscols;
3620 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003621 }
3622 else
3623# endif
3624 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003625 ++wlv.boguscols;
3626 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003627 }
3628 }
3629
3630# ifdef FEAT_RIGHTLEFT
3631 if (wp->w_p_rl)
3632 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003633 --wlv.boguscols;
3634 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003635 }
3636 else
3637# endif
3638 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003639 ++wlv.boguscols;
3640 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003641 }
3642 }
3643 else
3644 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003645 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003646 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003647 wlv.vcol += wlv.n_extra;
3648 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003649 n_attr = 0;
3650 }
3651 }
3652
3653 }
3654#endif // FEAT_CONCEAL
3655 else
3656 --n_skip;
3657
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003658 // Only advance the "wlv.vcol" when after the 'number' or
3659 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003660 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003661#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003662 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003663#endif
3664 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003665 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003666
3667#ifdef FEAT_SYN_HL
3668 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003669 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003670#endif
3671
3672 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003673 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3674 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003675
3676 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003677 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003678 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003679 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003680 if (n_attr_skip > 0)
3681 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003682
3683 // At end of screen line and there is more to come: Display the line
3684 // so far. If there is no more to display it is caught above.
3685 if ((
3686#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003687 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003688#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003689 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003690 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003691 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003692#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003693 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003694#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003695#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003696 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003697#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003698 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003699 && wlv.p_extra != at_end_str)
3700 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3701 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003702 )
3703 {
3704#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003705 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003706 wlv_screen_line(wp, &wlv, FALSE);
3707 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003708 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003709#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003710 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003711#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003712 ++wlv.row;
3713 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003714
3715 // When not wrapping and finished diff lines, or when displayed
3716 // '$' and highlighting until last column, break here.
3717 if ((!wp->w_p_wrap
3718#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003719 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003720#endif
3721#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003722 && !text_prop_above && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003723#endif
3724 ) || lcs_eol_one == -1)
3725 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003726#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003727 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003728 {
3729 // do not output more of the line, only the "below" prop
3730 ptr += STRLEN(ptr);
3731# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003732 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003733# endif
3734 }
3735#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003736
3737 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003738 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003739#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003740 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003741#endif
3742 )
3743 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003744 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3745 draw_vsep_win(wp, wlv.row);
3746 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003747 }
3748
3749 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003750 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003751 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003752 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003753 break;
3754 }
3755
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003756 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003757#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003758 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003759#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003760#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003761 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003762#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003763 && wp->w_width == Columns)
3764 {
3765 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003766 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003767
3768 // Special trick to make copy/paste of wrapped lines work with
3769 // xterm/screen: write an extra character beyond the end of
3770 // the line. This will work with all terminal types
3771 // (regardless of the xn,am settings).
3772 // Only do this on a fast tty.
3773 // Only do this if the cursor is on the current line
3774 // (something has been written in it).
3775 // Don't do this for the GUI.
3776 // Don't do this for double-width characters.
3777 // Don't do this for a window not at the right screen border.
3778 if (p_tf
3779#ifdef FEAT_GUI
3780 && !gui.in_use
3781#endif
3782 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003783 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3784 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003785 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003786 || (*mb_off2cells)(
3787 LineOffset[wlv.screen_row - 1]
3788 + (int)Columns - 2,
3789 LineOffset[wlv.screen_row]
3790 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003791 {
3792 // First make sure we are at the end of the screen line,
3793 // then output the same character again to let the
3794 // terminal know about the wrap. If the terminal doesn't
3795 // auto-wrap, we overwrite the character.
3796 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003797 screen_char(LineOffset[wlv.screen_row - 1]
3798 + (unsigned)Columns - 1,
3799 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003800
3801 // When there is a multi-byte character, just output a
3802 // space to keep it simple.
3803 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003804 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003805 out_char(' ');
3806 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003807 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003808 + (Columns - 1)]);
3809 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003810 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003811 screen_start(); // don't know where cursor is now
3812 }
3813 }
3814
Bram Moolenaar1306b362022-08-06 15:59:06 +01003815 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003816
Bram Moolenaareed9d462021-02-15 20:38:25 +01003817 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003818#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003819 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003820# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003821 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003822# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003823 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003824 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003825#endif
3826#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003827 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003828 // When the filler lines are actually below the last line of the
3829 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003830 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003831 break;
3832#endif
3833 }
3834
3835 } // for every character in the line
3836
3837#ifdef FEAT_SPELL
3838 // After an empty line check first word for capital.
3839 if (*skipwhite(line) == NUL)
3840 {
3841 capcol_lnum = lnum + 1;
3842 cap_col = 0;
3843 }
3844#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003845#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003846 vim_free(text_props);
3847 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003848 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003849#endif
3850
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003851 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003852 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003853}