blob: c38cdbc528034f0fa010b39c95afb276ba6b7ea9 [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)
349 && !(has_cpo_n && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100350 {
351#ifdef FEAT_SIGNS
352 // If 'signcolumn' is set to 'number' and a sign is present
353 // in 'lnum', then display the sign instead of the line
354 // number.
355 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
356 get_sign_display_info(TRUE, wp, wlv);
357 else
358#endif
359 {
360 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100361 // When there are text properties above the line put the line number
362 // below them.
363 if (wlv->row == wlv->startrow + wlv->filler_lines
364#ifdef FEAT_PROP_POPUP
365 + wlv->text_prop_above_count
Bram Moolenaard7657e92022-09-20 18:59:30 +0100366#endif
Bram Moolenaar06618f92022-10-06 19:21:20 +0100367 && (wp->w_skipcol == 0 || wlv->row > wp->w_winrow))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100368 {
369 long num;
370 char *fmt = "%*ld ";
371
372 if (wp->w_p_nu && !wp->w_p_rnu)
373 // 'number' + 'norelativenumber'
374 num = (long)wlv->lnum;
375 else
376 {
377 // 'relativenumber', don't use negative numbers
378 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
379 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
380 {
381 // 'number' + 'relativenumber'
382 num = wlv->lnum;
383 fmt = "%-*ld ";
384 }
385 }
386
387 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100388 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100389 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
390 ++wlv->p_extra)
391 *wlv->p_extra = '-';
392#ifdef FEAT_RIGHTLEFT
393 if (wp->w_p_rl) // reverse line numbers
394 {
395 char_u *p1, *p2;
396 int t;
397
398 // like rl_mirror(), but keep the space at the end
399 p2 = skipwhite(wlv->extra);
400 p2 = skiptowhite(p2) - 1;
401 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
402 {
403 t = *p1;
404 *p1 = *p2;
405 *p2 = t;
406 }
407 }
408#endif
409 wlv->p_extra = wlv->extra;
410 wlv->c_extra = NUL;
411 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100412 }
413 else
414 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100415 wlv->c_extra = ' ';
416 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100417 }
418 wlv->n_extra = number_width(wp) + 1;
419 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
420#ifdef FEAT_SYN_HL
421 // When 'cursorline' is set highlight the line number of
422 // the current line differently.
423 // When 'cursorlineopt' does not have "line" only
424 // highlight the line number itself.
425 // TODO: Can we use CursorLine instead of CursorLineNr
426 // when CursorLineNr isn't set?
427 if (wp->w_p_cul
428 && wlv->lnum == wp->w_cursor.lnum
429 && (wp->w_p_culopt_flags & CULOPT_NBR)
430 && (wlv->row == wlv->startrow + wlv->filler_lines
431 || (wlv->row > wlv->startrow + wlv->filler_lines
432 && (wp->w_p_culopt_flags & CULOPT_LINE))))
433 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
434#endif
435 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
436 && HL_ATTR(HLF_LNA) != 0)
437 // Use LineNrAbove
438 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
439 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
440 && HL_ATTR(HLF_LNB) != 0)
441 // Use LineNrBelow
442 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
443 }
444#ifdef FEAT_SIGNS
445 if (num_attr)
446 wlv->char_attr = num_attr;
447#endif
448 }
449}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100450
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100451#ifdef FEAT_LINEBREAK
452 static void
453handle_breakindent(win_T *wp, winlinevars_T *wlv)
454{
455 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
456 && *get_showbreak_value(wp) != NUL)
457 // draw indent after showbreak value
458 wlv->draw_state = WL_BRI;
459 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
460 // After the showbreak, draw the breakindent
461 wlv->draw_state = WL_BRI - 1;
462
463 // draw 'breakindent': indent wrapped text accordingly
464 if (wlv->draw_state == WL_BRI - 1)
465 {
466 wlv->draw_state = WL_BRI;
467 // if wlv->need_showbreak is set, breakindent also applies
468 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
469# ifdef FEAT_DIFF
470 && wlv->filler_lines == 0
471# endif
472# ifdef FEAT_PROP_POPUP
473 && !wlv->dont_use_showbreak
474# endif
475 )
476 {
477 wlv->char_attr = 0;
478# ifdef FEAT_DIFF
479 if (wlv->diff_hlf != (hlf_T)0)
480 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
481# endif
482 wlv->p_extra = NULL;
483 wlv->c_extra = ' ';
484 wlv->c_final = NUL;
485 wlv->n_extra = get_breakindent_win(wp,
486 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
487 if (wlv->row == wlv->startrow)
488 {
489 wlv->n_extra -= win_col_off2(wp);
490 if (wlv->n_extra < 0)
491 wlv->n_extra = 0;
492 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100493 if (wp->w_skipcol > 0 && wlv->startrow == 0
494 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100495 wlv->need_showbreak = FALSE;
496 // Correct end of highlighted area for 'breakindent',
497 // required when 'linebreak' is also set.
498 if (wlv->tocol == wlv->vcol)
499 wlv->tocol += wlv->n_extra;
500 }
501 }
502}
503#endif
504
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100505#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
506 static void
507handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
508{
509# ifdef FEAT_DIFF
510 if (wlv->filler_todo > 0)
511 {
512 // Draw "deleted" diff line(s).
513 if (char2cells(wp->w_fill_chars.diff) > 1)
514 {
515 wlv->c_extra = '-';
516 wlv->c_final = NUL;
517 }
518 else
519 {
520 wlv->c_extra = wp->w_fill_chars.diff;
521 wlv->c_final = NUL;
522 }
523# ifdef FEAT_RIGHTLEFT
524 if (wp->w_p_rl)
525 wlv->n_extra = wlv->col + 1;
526 else
527# endif
528 wlv->n_extra = wp->w_width - wlv->col;
529 wlv->char_attr = HL_ATTR(HLF_DED);
530 }
531# endif
532
533# ifdef FEAT_LINEBREAK
534 char_u *sbr = get_showbreak_value(wp);
535 if (*sbr != NUL && wlv->need_showbreak)
536 {
537 // Draw 'showbreak' at the start of each broken line.
538 wlv->p_extra = sbr;
539 wlv->c_extra = NUL;
540 wlv->c_final = NUL;
541 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100542 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100543 wlv->need_showbreak = FALSE;
544 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
545 // Correct end of highlighted area for 'showbreak',
546 // required when 'linebreak' is also set.
547 if (wlv->tocol == wlv->vcol)
548 wlv->tocol += wlv->n_extra;
549 // combine 'showbreak' with 'wincolor'
550 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
551# ifdef FEAT_SYN_HL
552 // combine 'showbreak' with 'cursorline'
553 if (wlv->cul_attr != 0)
554 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
555# endif
556 }
557# endif
558}
559#endif
560
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100561#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100562/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100563 * Return the cell size of virtual text after truncation.
564 */
565 static int
566textprop_size_after_trunc(
567 win_T *wp,
568 int flags, // TP_FLAG_ALIGN_*
569 int added,
570 char_u *text,
571 int *n_used_ptr)
572{
573 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
574 ? wp->w_width : added;
575 int len = (int)STRLEN(text);
576 int strsize = 0;
577 int n_used;
578
579 // if the remaining size is to small wrap anyway and use the next line
580 if (space < PROP_TEXT_MIN_CELLS)
581 space += wp->w_width;
582 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
583 {
584 int clen = ptr2cells(text + n_used);
585
586 if (strsize + clen > space)
587 break;
588 strsize += clen;
589 }
590 *n_used_ptr = n_used;
591 return strsize;
592}
593
594/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100595 * Take care of padding, right-align and truncation of virtual text after a
596 * line.
597 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
598 * padding, right-align and truncation. Otherwise only the size is computed.
599 * When "n_attr" is NULL returns the number of screen cells used.
600 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100601 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100602 int
603text_prop_position(
604 win_T *wp,
605 textprop_T *tp,
606 int vcol, // current screen column
607 int *n_extra, // nr of bytes for virtual text
608 char_u **p_extra, // virtual text
609 int *n_attr, // attribute cells, NULL if not used
610 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200611{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100612 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100613 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100614 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
615 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
616 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
617 ? tp->tp_len - 1 : 0;
618 int col_with_padding = vcol + (below ? 0 : padding);
619 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100620 int before = room; // spaces before the text
621 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100622 int n_used = *n_extra;
623 char_u *l = NULL;
624 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100625 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
626 tp->tp_flags, before, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200627
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100628 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100629 {
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100630 int col_off = win_col_off(wp) + win_col_off2(wp);
631 int skip_add = 0;
632
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100633 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100634 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100635 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100636 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100637 }
638 else
639 {
640 // Right-align: fill with before
641 if (right)
642 before -= cells;
643 if (before < 0
644 || !(right || below)
645 || (below
646 ? (col_with_padding == 0 || !wp->w_p_wrap)
647 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100648 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100649 if (right && (wrap || room < PROP_TEXT_MIN_CELLS))
650 {
651 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100652 before = wp->w_width - col_off - strsize + room;
653 if (before < 0)
654 before = 0;
655 else
656 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100657 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100658 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100659 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100660 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100661 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100662 else if (below && before > 0)
663 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100664 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100665 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100666
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100667 // With 'nowrap' add one to show the "extends" character if needed (it
668 // doesn't show if the text just fits).
669 if (!wp->w_p_wrap
670 && n_used < *n_extra
671 && wp->w_lcs_chars.ext != NUL
672 && wp->w_p_list)
673 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100674 if (!wp->w_p_wrap && below && padding > 0)
675 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100676
677 // add 1 for NUL, 2 for when '…' is used
678 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100679 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100680 if (n_attr == NULL || l != NULL)
681 {
682 int off = 0;
683
684 if (n_attr != NULL)
685 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100686 vim_memset(l, ' ', before);
687 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100688 if (padding > 0)
689 {
690 vim_memset(l + off, ' ', padding);
691 off += padding;
692 }
693 vim_strncpy(l + off, *p_extra, n_used);
694 off += n_used;
695 }
696 else
697 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100698 off = before + after + padding + n_used;
699 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100700 }
701 if (n_attr != NULL)
702 {
703 if (n_used < *n_extra && wp->w_p_wrap)
704 {
705 char_u *lp = l + off - 1;
706
707 if (has_mbyte)
708 {
709 // change last character to '…'
710 lp -= (*mb_head_off)(l, lp);
711 STRCPY(lp, "…");
712 n_used = lp - l + 3 - padding;
713 }
714 else
715 // change last character to '>'
716 *lp = '>';
717 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100718 else if (after > 0)
719 {
720 vim_memset(l + off, ' ', after);
721 l[off + after] = NUL;
722 }
723
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100724 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100725 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100726 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100727 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100728 *n_attr -= padding + after;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100729 *n_attr_skip = before + padding + skip_add;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100730 }
731 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100732 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100733
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100734 if (n_attr == NULL)
735 return cells;
736 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200737}
738#endif
739
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100740/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100741 * Call screen_line() using values from "wlv".
742 * Also takes care of putting "<<<" on the first line for 'smoothscroll'.
743 */
744 static void
745wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
746{
747 if (wlv->row == 0 && wp->w_skipcol > 0)
748 {
749 int off = (int)(current_ScreenLine - ScreenLines);
750
751 for (int i = 0; i < 3; ++i)
752 {
753 ScreenLines[off] = '<';
754 if (enc_utf8)
755 ScreenLinesUC[off] = 0;
756 ScreenAttrs[off] = HL_ATTR(HLF_AT);
757 ++off;
758 }
759 }
760
761 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
762 negative_width ? -wp->w_width : wp->w_width,
763 wlv->screen_line_flags);
764}
765
766/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100767 * Called when finished with the line: draw the screen line and handle any
768 * highlighting until the right of the window.
769 */
770 static void
771draw_screen_line(win_T *wp, winlinevars_T *wlv)
772{
773#ifdef FEAT_SYN_HL
774 long v;
775
776 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
777 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100778 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100779 else
780 v = wp->w_leftcol;
781
782 // check if line ends before left margin
783 if (wlv->vcol < v + wlv->col - win_col_off(wp))
784 wlv->vcol = v + wlv->col - win_col_off(wp);
785# ifdef FEAT_CONCEAL
786 // Get rid of the boguscols now, we want to draw until the right
787 // edge for 'cursorcolumn'.
788 wlv->col -= wlv->boguscols;
789 wlv->boguscols = 0;
790# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
791# else
792# define VCOL_HLC (wlv->vcol)
793# endif
794
795 if (wlv->draw_color_col)
796 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
797
798 if (((wp->w_p_cuc
799 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
800 && (int)wp->w_virtcol <
801 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
802 && wlv->lnum != wp->w_cursor.lnum)
803 || wlv->draw_color_col
804 || wlv->win_attr != 0)
805# ifdef FEAT_RIGHTLEFT
806 && !wp->w_p_rl
807# endif
808 )
809 {
810 int rightmost_vcol = 0;
811 int i;
812
813 if (wp->w_p_cuc)
814 rightmost_vcol = wp->w_virtcol;
815 if (wlv->draw_color_col)
816 // determine rightmost colorcolumn to possibly draw
817 for (i = 0; wlv->color_cols[i] >= 0; ++i)
818 if (rightmost_vcol < wlv->color_cols[i])
819 rightmost_vcol = wlv->color_cols[i];
820
821 while (wlv->col < wp->w_width)
822 {
823 ScreenLines[wlv->off] = ' ';
824 if (enc_utf8)
825 ScreenLinesUC[wlv->off] = 0;
826 ScreenCols[wlv->off] = MAXCOL;
827 ++wlv->col;
828 if (wlv->draw_color_col)
829 wlv->draw_color_col = advance_color_col(
830 VCOL_HLC, &wlv->color_cols);
831
832 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
833 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
834 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
835 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
836 else
837 ScreenAttrs[wlv->off++] = wlv->win_attr;
838
839 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
840 break;
841
842 ++wlv->vcol;
843 }
844 }
845#endif
846
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100847 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100848 ++wlv->row;
849 ++wlv->screen_row;
850}
851#undef VCOL_HLC
852
853/*
854 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100855 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100856 */
857 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100858win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100859{
860 wlv->col = 0;
861 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
862
863#ifdef FEAT_RIGHTLEFT
864 if (wp->w_p_rl)
865 {
866 // Rightleft window: process the text in the normal direction, but put
867 // it in current_ScreenLine[] from right to left. Start at the
868 // rightmost column of the window.
869 wlv->col = wp->w_width - 1;
870 wlv->off += wlv->col;
871 wlv->screen_line_flags |= SLF_RIGHTLEFT;
872 }
873#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100874 if (save_extra)
875 {
876 // reset the drawing state for the start of a wrapped line
877 wlv->draw_state = WL_START;
878 wlv->saved_n_extra = wlv->n_extra;
879 wlv->saved_p_extra = wlv->p_extra;
880 wlv->saved_c_extra = wlv->c_extra;
881 wlv->saved_c_final = wlv->c_final;
882#ifdef FEAT_SYN_HL
883 if (!(wlv->cul_screenline
884# ifdef FEAT_DIFF
885 && wlv->diff_hlf == (hlf_T)0
886# endif
887 ))
888 wlv->saved_char_attr = wlv->char_attr;
889 else
890#endif
891 wlv->saved_char_attr = 0;
892 wlv->n_extra = 0;
893 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100894}
895
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200896/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100897 * Called when wlv->draw_state is set to WL_LINE.
898 */
899 static void
900win_line_continue(winlinevars_T *wlv)
901{
902 if (wlv->saved_n_extra > 0)
903 {
904 // Continue item from end of wrapped line.
905 wlv->n_extra = wlv->saved_n_extra;
906 wlv->c_extra = wlv->saved_c_extra;
907 wlv->c_final = wlv->saved_c_final;
908 wlv->p_extra = wlv->saved_p_extra;
909 wlv->char_attr = wlv->saved_char_attr;
910 }
911 else
912 wlv->char_attr = wlv->win_attr;
913}
914
915/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200916 * Display line "lnum" of window 'wp' on the screen.
917 * Start at row "startrow", stop when "endrow" is reached.
918 * wp->w_virtcol needs to be valid.
919 *
920 * Return the number of last row the line occupies.
921 */
922 int
923win_line(
924 win_T *wp,
925 linenr_T lnum,
926 int startrow,
927 int endrow,
928 int nochange UNUSED, // not updating for changed text
929 int number_only) // only update the number column
930{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100931 winlinevars_T wlv; // variables passed between functions
932
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200933 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100934 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200935 char_u *line; // current line
936 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200937
Bram Moolenaar1306b362022-08-06 15:59:06 +0100938#ifdef FEAT_PROP_POPUP
939 char_u *p_extra_free2 = NULL; // another p_extra to be freed
940#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200941 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000942#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000943 int in_linebreak = FALSE; // n_extra set for showing linebreak
944#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200945 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100946 // displaying eol at end-of-line
947 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000948 int lcs_prec_todo = wp->w_lcs_chars.prec;
949 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200950
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100951 int n_attr = 0; // chars with special attr
952 int n_attr_skip = 0; // chars to skip before using extra_attr
953 int saved_attr2 = 0; // char_attr saved for n_attr
954 int n_attr3 = 0; // chars with overruling special attr
955 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200956
957 int n_skip = 0; // nr of chars to skip for 'nowrap'
958
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200959 int fromcol_prev = -2; // start of inverting after cursor
960 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200961 int lnum_in_visual_area = FALSE;
962 pos_T pos;
963 long v;
964
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200965 int attr_pri = FALSE; // char_attr has priority
966 int area_highlighting = FALSE; // Visual or incsearch highlighting
967 // in this line
968 int vi_attr = 0; // attributes for Visual and incsearch
969 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200970 int area_attr = 0; // attributes desired by highlighting
971 int search_attr = 0; // attributes desired by 'hlsearch'
972#ifdef FEAT_SYN_HL
973 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
974 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200975 int prev_syntax_col = -1; // column of prev_syntax_attr
976 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200977 int has_syntax = FALSE; // this buffer has syntax highl.
978 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200979#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100980#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200981 int text_prop_count;
982 int text_prop_next = 0; // next text property to use
983 textprop_T *text_props = NULL;
984 int *text_prop_idxs = NULL;
985 int text_props_active = 0;
986 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +0100987 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200988 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +0100989 int text_prop_attr_comb = 0; // text_prop_attr combined with
990 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100991 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100992 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +0100993 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100994 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +0100995 int saved_search_attr = 0; // search_attr to be used when n_extra
996 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +0100997 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200998#endif
999#ifdef FEAT_SPELL
1000 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001001 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001002# define SPWORDLEN 150
1003 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1004 int nextlinecol = 0; // column where nextline[] starts
1005 int nextline_idx = 0; // index in nextline[] where next line
1006 // starts
1007 int spell_attr = 0; // attributes desired by spelling
1008 int word_end = 0; // last byte with same spell_attr
1009 static linenr_T checked_lnum = 0; // line number for "checked_col"
1010 static int checked_col = 0; // column in "checked_lnum" up to which
1011 // there are no spell errors
1012 static int cap_col = -1; // column to check for Cap word
1013 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1014 int cur_checked_col = 0; // checked column for current line
1015#endif
1016 int extra_check = 0; // has extra highlighting
1017 int multi_attr = 0; // attributes desired by multibyte
1018 int mb_l = 1; // multi-byte byte length
1019 int mb_c = 0; // decoded multi-byte character
1020 int mb_utf8 = FALSE; // screen char is UTF-8 char
1021 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001022#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001023 int change_start = MAXCOL; // first col of changed area
1024 int change_end = -1; // last col of changed area
1025#endif
1026 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001027 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001028 int in_multispace = FALSE; // in multiple consecutive spaces
1029 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001030#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
1031 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
1032# define LINE_ATTR
1033 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +01001034 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001035#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001036 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001037 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001038#ifdef FEAT_ARABIC
1039 int prev_c = 0; // previous Arabic character
1040 int prev_c1 = 0; // first composing char for prev_c
1041#endif
1042#if defined(LINE_ATTR)
1043 int did_line_attr = 0;
1044#endif
1045#ifdef FEAT_TERMINAL
1046 int get_term_attr = FALSE;
1047#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001048
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001049#ifdef FEAT_SYN_HL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001050 // margin columns for the screen line, needed for when 'cursorlineopt'
1051 // contains "screenline"
1052 int left_curline_col = 0;
1053 int right_curline_col = 0;
1054#endif
1055
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001056#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1057 int feedback_col = 0;
1058 int feedback_old_attr = -1;
1059#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001060
1061#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1062 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001063 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001064#endif
1065#ifdef FEAT_CONCEAL
1066 int syntax_flags = 0;
1067 int syntax_seqnr = 0;
1068 int prev_syntax_id = 0;
1069 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1070 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001071 int did_wcol = FALSE;
1072 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001073# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001074# define FIX_FOR_BOGUSCOLS \
1075 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001076 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001077 wlv.vcol -= wlv.vcol_off; \
1078 wlv.vcol_off = 0; \
1079 wlv.col -= wlv.boguscols; \
1080 old_boguscols = wlv.boguscols; \
1081 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001082 }
1083#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001084# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001085#endif
1086
1087 if (startrow > endrow) // past the end already!
1088 return startrow;
1089
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001090 CLEAR_FIELD(wlv);
1091
1092 wlv.lnum = lnum;
1093 wlv.startrow = startrow;
1094 wlv.row = startrow;
1095 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001096 wlv.fromcol = -10;
1097 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001098#ifdef FEAT_LINEBREAK
1099 wlv.vcol_sbr = -1;
1100#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001101
1102 if (!number_only)
1103 {
1104 // To speed up the loop below, set extra_check when there is linebreak,
1105 // trailing white space and/or syntax processing to be done.
1106#ifdef FEAT_LINEBREAK
1107 extra_check = wp->w_p_lbr;
1108#endif
1109#ifdef FEAT_SYN_HL
1110 if (syntax_present(wp) && !wp->w_s->b_syn_error
1111# ifdef SYN_TIME_LIMIT
1112 && !wp->w_s->b_syn_slow
1113# endif
1114 )
1115 {
1116 // Prepare for syntax highlighting in this line. When there is an
1117 // error, stop syntax highlighting.
1118 save_did_emsg = did_emsg;
1119 did_emsg = FALSE;
1120 syntax_start(wp, lnum);
1121 if (did_emsg)
1122 wp->w_s->b_syn_error = TRUE;
1123 else
1124 {
1125 did_emsg = save_did_emsg;
1126#ifdef SYN_TIME_LIMIT
1127 if (!wp->w_s->b_syn_slow)
1128#endif
1129 {
1130 has_syntax = TRUE;
1131 extra_check = TRUE;
1132 }
1133 }
1134 }
1135
1136 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001137 wlv.color_cols = wp->w_p_cc_cols;
1138 if (wlv.color_cols != NULL)
1139 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001140#endif
1141
1142#ifdef FEAT_TERMINAL
1143 if (term_show_buffer(wp->w_buffer))
1144 {
1145 extra_check = TRUE;
1146 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001147 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001148 }
1149#endif
1150
1151#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001152 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001153 {
1154 // Prepare for spell checking.
1155 has_spell = TRUE;
1156 extra_check = TRUE;
1157
1158 // Get the start of the next line, so that words that wrap to the
1159 // next line are found too: "et<line-break>al.".
1160 // Trick: skip a few chars for C/shell/Vim comments
1161 nextline[SPWORDLEN] = NUL;
1162 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1163 {
1164 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1165 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1166 }
1167
1168 // When a word wrapped from the previous line the start of the
1169 // current line is valid.
1170 if (lnum == checked_lnum)
1171 cur_checked_col = checked_col;
1172 checked_lnum = 0;
1173
1174 // When there was a sentence end in the previous line may require a
1175 // word starting with capital in this line. In line 1 always check
1176 // the first word.
1177 if (lnum != capcol_lnum)
1178 cap_col = -1;
1179 if (lnum == 1)
1180 cap_col = 0;
1181 capcol_lnum = 0;
1182 }
1183#endif
1184
1185 // handle Visual active in this window
1186 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1187 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001188 pos_T *top, *bot;
1189
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001190 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1191 {
1192 // Visual is after curwin->w_cursor
1193 top = &curwin->w_cursor;
1194 bot = &VIsual;
1195 }
1196 else
1197 {
1198 // Visual is before curwin->w_cursor
1199 top = &VIsual;
1200 bot = &curwin->w_cursor;
1201 }
1202 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1203 if (VIsual_mode == Ctrl_V)
1204 {
1205 // block mode
1206 if (lnum_in_visual_area)
1207 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001208 wlv.fromcol = wp->w_old_cursor_fcol;
1209 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001210 }
1211 }
1212 else
1213 {
1214 // non-block mode
1215 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001216 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001217 else if (lnum == top->lnum)
1218 {
1219 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001220 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001221 else
1222 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001223 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001224 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001225 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001226 }
1227 }
1228 if (VIsual_mode != 'V' && lnum == bot->lnum)
1229 {
1230 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1231 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001232 wlv.fromcol = -10;
1233 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001234 }
1235 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001236 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001237 else
1238 {
1239 pos = *bot;
1240 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001241 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1242 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001243 else
1244 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001245 getvvcol(wp, &pos, NULL, NULL,
1246 (colnr_T *)&wlv.tocol);
1247 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001248 }
1249 }
1250 }
1251 }
1252
1253 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001254 if (!highlight_match && lnum == curwin->w_cursor.lnum
1255 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001256#ifdef FEAT_GUI
1257 && !gui.in_use
1258#endif
1259 )
1260 noinvcur = TRUE;
1261
1262 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001263 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001264 {
1265 area_highlighting = TRUE;
1266 vi_attr = HL_ATTR(HLF_V);
1267#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1268 if ((clip_star.available && !clip_star.owned
1269 && clip_isautosel_star())
1270 || (clip_plus.available && !clip_plus.owned
1271 && clip_isautosel_plus()))
1272 vi_attr = HL_ATTR(HLF_VNC);
1273#endif
1274 }
1275 }
1276
1277 // handle 'incsearch' and ":s///c" highlighting
1278 else if (highlight_match
1279 && wp == curwin
1280 && lnum >= curwin->w_cursor.lnum
1281 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1282 {
1283 if (lnum == curwin->w_cursor.lnum)
1284 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001285 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001286 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001287 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001288 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1289 {
1290 pos.lnum = lnum;
1291 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001292 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001293 }
1294 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001295 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001296 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001297 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1298 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001299 area_highlighting = TRUE;
1300 vi_attr = HL_ATTR(HLF_I);
1301 }
1302 }
1303
1304#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001305 wlv.filler_lines = diff_check(wp, lnum);
1306 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001307 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001308 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001309 {
1310 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001311 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001312 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001313 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001314 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001315 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001316 }
1317 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001318 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001319 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001320 area_highlighting = TRUE;
1321 }
1322 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001323 wlv.filler_lines = wp->w_topfill;
1324 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001325#endif
1326
1327#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001328 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001329 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001330 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001331#endif
1332
1333#ifdef LINE_ATTR
1334# ifdef FEAT_SIGNS
1335 // If this line has a sign with line highlighting set line_attr.
1336 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001337 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001338# endif
1339# if defined(FEAT_QUICKFIX)
1340 // Highlight the current line in the quickfix window.
1341 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1342 line_attr = HL_ATTR(HLF_QFL);
1343# endif
1344 if (line_attr != 0)
1345 area_highlighting = TRUE;
1346#endif
1347
1348 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1349 ptr = line;
1350
1351#ifdef FEAT_SPELL
1352 if (has_spell && !number_only)
1353 {
1354 // For checking first word with a capital skip white space.
1355 if (cap_col == 0)
1356 cap_col = getwhitecols(line);
1357
1358 // To be able to spell-check over line boundaries copy the end of the
1359 // current line into nextline[]. Above the start of the next line was
1360 // copied to nextline[SPWORDLEN].
1361 if (nextline[SPWORDLEN] == NUL)
1362 {
1363 // No next line or it is empty.
1364 nextlinecol = MAXCOL;
1365 nextline_idx = 0;
1366 }
1367 else
1368 {
1369 v = (long)STRLEN(line);
1370 if (v < SPWORDLEN)
1371 {
1372 // Short line, use it completely and append the start of the
1373 // next line.
1374 nextlinecol = 0;
1375 mch_memmove(nextline, line, (size_t)v);
1376 STRMOVE(nextline + v, nextline + SPWORDLEN);
1377 nextline_idx = v + 1;
1378 }
1379 else
1380 {
1381 // Long line, use only the last SPWORDLEN bytes.
1382 nextlinecol = v - SPWORDLEN;
1383 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1384 nextline_idx = SPWORDLEN + 1;
1385 }
1386 }
1387 }
1388#endif
1389
1390 if (wp->w_p_list)
1391 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001392 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001393 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001394 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001395 || wp->w_lcs_chars.trail
1396 || wp->w_lcs_chars.lead
1397 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001398 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001399
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001400 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001401 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001402 {
1403 trailcol = (colnr_T)STRLEN(ptr);
1404 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1405 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001406 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001407 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001408 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001409 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001410 {
1411 leadcol = 0;
1412 while (VIM_ISWHITE(ptr[leadcol]))
1413 ++leadcol;
1414 if (ptr[leadcol] == NUL)
1415 // in a line full of spaces all of them are treated as trailing
1416 leadcol = (colnr_T)0;
1417 else
1418 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001419 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001420 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001421 }
1422
Bram Moolenaard7657e92022-09-20 18:59:30 +01001423 wlv.wcr_attr = get_wcr_attr(wp);
1424 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001425 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001426 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001427 area_highlighting = TRUE;
1428 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001429
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001430#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001431 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001432 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001433#endif
1434
1435 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1436 // first character to be displayed.
1437 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001438 v = startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001439 else
1440 v = wp->w_leftcol;
1441 if (v > 0 && !number_only)
1442 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001443 char_u *prev_ptr = ptr;
1444 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001445 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001446
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001447 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001448 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001449 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001450 charsize = win_lbr_chartabsize(&cts, NULL);
1451 cts.cts_vcol += charsize;
1452 prev_ptr = cts.cts_ptr;
1453 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001454 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001455 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001456 ptr = cts.cts_ptr;
1457 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001458
1459 // When:
1460 // - 'cuc' is set, or
1461 // - 'colorcolumn' is set, or
1462 // - 'virtualedit' is set, or
1463 // - the visual mode is active,
1464 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001465 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001466#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001467 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001468#endif
1469 virtual_active() ||
1470 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001471 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001472
1473 // Handle a character that's not completely on the screen: Put ptr at
1474 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001475 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001476 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001477 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001478 ptr = prev_ptr;
1479 // If the character fits on the screen, don't need to skip it.
1480 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001481 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1482 && wlv.col == 0)
1483 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001484 }
1485
1486 // Adjust for when the inverted text is before the screen,
1487 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001488 if (wlv.tocol <= wlv.vcol)
1489 wlv.fromcol = 0;
1490 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1491 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001492
1493#ifdef FEAT_LINEBREAK
1494 // When w_skipcol is non-zero, first line needs 'showbreak'
1495 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001496 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001497#endif
1498#ifdef FEAT_SPELL
1499 // When spell checking a word we need to figure out the start of the
1500 // word and if it's badly spelled or not.
1501 if (has_spell)
1502 {
1503 int len;
1504 colnr_T linecol = (colnr_T)(ptr - line);
1505 hlf_T spell_hlf = HLF_COUNT;
1506
1507 pos = wp->w_cursor;
1508 wp->w_cursor.lnum = lnum;
1509 wp->w_cursor.col = linecol;
1510 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1511
1512 // spell_move_to() may call ml_get() and make "line" invalid
1513 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1514 ptr = line + linecol;
1515
1516 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1517 {
1518 // no bad word found at line start, don't check until end of a
1519 // word
1520 spell_hlf = HLF_COUNT;
1521 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1522 }
1523 else
1524 {
1525 // bad word found, use attributes until end of word
1526 word_end = wp->w_cursor.col + len + 1;
1527
1528 // Turn index into actual attributes.
1529 if (spell_hlf != HLF_COUNT)
1530 spell_attr = highlight_attr[spell_hlf];
1531 }
1532 wp->w_cursor = pos;
1533
1534# ifdef FEAT_SYN_HL
1535 // Need to restart syntax highlighting for this line.
1536 if (has_syntax)
1537 syntax_start(wp, lnum);
1538# endif
1539 }
1540#endif
1541 }
1542
1543 // Correct highlighting for cursor that can't be disabled.
1544 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001545 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001546 {
1547 if (noinvcur)
1548 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001549 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001550 {
1551 // highlighting starts at cursor, let it start just after the
1552 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001553 fromcol_prev = wlv.fromcol;
1554 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001555 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001556 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001557 // restart highlighting after the cursor
1558 fromcol_prev = wp->w_virtcol;
1559 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001560 if (wlv.fromcol >= wlv.tocol)
1561 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001562 }
1563
1564#ifdef FEAT_SEARCH_EXTRA
1565 if (!number_only)
1566 {
1567 v = (long)(ptr - line);
1568 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1569 &line, &screen_search_hl,
1570 &search_attr);
1571 ptr = line + v; // "line" may have been updated
1572 }
1573#endif
1574
1575#ifdef FEAT_SYN_HL
1576 // Cursor line highlighting for 'cursorline' in the current window.
1577 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1578 {
1579 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001580 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001581 if (!(wp == curwin && VIsual_active)
1582 && wp->w_p_culopt_flags != CULOPT_NBR)
1583 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001584 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001585 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1586
1587 // Only set line_attr here when "screenline" is not present in
1588 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001589 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001590 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001591 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001592# ifdef FEAT_SIGNS
1593 // Combine the 'cursorline' and sign highlighting, depending on
1594 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001595 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001596 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001597 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001598 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001599 else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001600 line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001601 }
1602 else
1603# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001604# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001605 // let the line attribute overrule 'cursorline', otherwise
1606 // it disappears when both have background set;
1607 // 'cursorline' can use underline or bold to make it show
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001608 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001609# else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001610 line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001611# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001612 }
1613 else
1614 {
1615 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001616 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1617 }
1618 area_highlighting = TRUE;
1619 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001620 }
1621#endif
1622
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001623#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001624 {
1625 char_u *prop_start;
1626
1627 text_prop_count = get_text_props(wp->w_buffer, lnum,
1628 &prop_start, FALSE);
1629 if (text_prop_count > 0)
1630 {
1631 // Make a copy of the properties, so that they are properly
1632 // aligned.
1633 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1634 if (text_props != NULL)
1635 mch_memmove(text_props, prop_start,
1636 text_prop_count * sizeof(textprop_T));
1637
1638 // Allocate an array for the indexes.
1639 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001640 if (text_prop_idxs == NULL)
1641 VIM_CLEAR(text_props);
1642
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001643 if (text_props != NULL)
1644 {
1645 area_highlighting = TRUE;
1646 extra_check = TRUE;
1647 for (int i = 0; i < text_prop_count; ++i)
1648 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1649 ++wlv.text_prop_above_count;
1650 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001651 }
1652 }
1653#endif
1654
Bram Moolenaar1306b362022-08-06 15:59:06 +01001655 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001656
1657 // Repeat for the whole displayed line.
1658 for (;;)
1659 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001660 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001661#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001662 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001663#endif
1664#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001665 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001666#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001667
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001668 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001669 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001670 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001671#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001672 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001673 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001674 wlv.cul_attr = 0;
zeertzjq4f33bc22021-08-05 17:57:02 +02001675 line_attr = line_attr_save;
1676 }
1677#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001678 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001679 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001680 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001681 if (cmdwin_type != 0 && wp == curwin)
1682 {
1683 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001684 wlv.n_extra = 1;
1685 wlv.c_extra = cmdwin_type;
1686 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001687 wlv.char_attr =
1688 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001689 }
1690 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001691#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001692 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001693 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001694 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001695 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001696 }
1697#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001698#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001699 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001700 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001701 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001702 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001703 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001704 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001705 }
1706#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001707 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001708 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001709 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001710 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001711 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001712 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001713#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001714 // Check if 'breakindent' applies and show it.
1715 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1716 if (wlv.n_extra == 0)
1717 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001718#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001719#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001720 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001721 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001722 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001723 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001724 }
1725#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001726 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001727 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001728 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001729 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001730 }
1731 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001732
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001733#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001734 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001735 && wlv.vcol >= left_curline_col
1736 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001737 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001738 wlv.cul_attr = HL_ATTR(HLF_CUL);
1739 line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001740 }
1741#endif
1742
1743 // When still displaying '$' of change command, stop at cursor.
1744 // When only displaying the (relative) line number and that's done,
1745 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001746 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001747 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001748 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001749#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001750 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001751#endif
1752 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001753 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001754 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001755 // Pretend we have finished updating the window. Except when
1756 // 'cursorcolumn' is set.
1757#ifdef FEAT_SYN_HL
1758 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001759 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001760 else
1761#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001762 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001763 break;
1764 }
1765
Bram Moolenaar1306b362022-08-06 15:59:06 +01001766 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001767 {
1768 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001769 if (wlv.vcol == wlv.fromcol
1770 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1771 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001772 && (*mb_ptr2cells)(ptr) > 1)
1773 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001774 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001775 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001776 area_attr = vi_attr; // start highlighting
1777 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001778 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001779 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001780 area_attr = 0; // stop highlighting
1781
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001782#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001783 if (text_props != NULL)
1784 {
1785 int pi;
1786 int bcol = (int)(ptr - line);
1787
Bram Moolenaar1306b362022-08-06 15:59:06 +01001788 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001789# ifdef FEAT_LINEBREAK
1790 && !in_linebreak
1791# endif
1792 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001793 --bcol; // still working on the previous char, e.g. Tab
1794
1795 // Check if any active property ends.
1796 for (pi = 0; pi < text_props_active; ++pi)
1797 {
1798 int tpi = text_prop_idxs[pi];
1799
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001800 if (text_props[tpi].tp_col != MAXCOL
1801 && bcol >= text_props[tpi].tp_col - 1
1802 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001803 {
1804 if (pi + 1 < text_props_active)
1805 mch_memmove(text_prop_idxs + pi,
1806 text_prop_idxs + pi + 1,
1807 sizeof(int)
1808 * (text_props_active - (pi + 1)));
1809 --text_props_active;
1810 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001811# ifdef FEAT_LINEBREAK
1812 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001813 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001814 syntax_attr = 0;
1815# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001816 }
1817 }
1818
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001819# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001820 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001821 // not on the next char yet, don't start another prop
1822 --bcol;
1823# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001824 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001825 // With 'nowrap' and not in the first screen line only "below"
1826 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001827 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001828 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001829 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001830 && (wp->w_p_wrap
1831 || wlv.row == startrow
1832 || (text_props[text_prop_next].tp_flags
1833 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001834 || (bcol == 0 &&
1835 (text_props[text_prop_next].tp_flags
1836 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001837 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001838 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001839 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001840 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1841 {
1842 // first display the '$' after the line
1843 text_prop_follows = TRUE;
1844 break;
1845 }
1846 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001847 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001848 + text_props[text_prop_next].tp_len)
1849 text_prop_idxs[text_props_active++] = text_prop_next;
1850 ++text_prop_next;
1851 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001852
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001853 if (wlv.n_extra == 0 || !extra_for_textprop)
1854 {
1855 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001856 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001857 text_prop_flags = 0;
1858 text_prop_type = NULL;
1859 text_prop_id = 0;
1860 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001861 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001862 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001863 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001864 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001865 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001866
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001867 // Sort the properties on priority and/or starting last.
1868 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001869 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001870 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001871 sort_text_props(wp->w_buffer, text_props,
1872 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001873
1874 for (pi = 0; pi < text_props_active; ++pi)
1875 {
1876 int tpi = text_prop_idxs[pi];
1877 proptype_T *pt = text_prop_type_by_id(
1878 wp->w_buffer, text_props[tpi].tp_type);
1879
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001880 if (pt != NULL && (pt->pt_hl_id > 0
1881 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001882 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001883 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001884 if (pt->pt_hl_id > 0)
1885 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001886 text_prop_type = pt;
1887 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001888 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001889 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001890 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001891 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001892 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001893 }
1894 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001895 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001896 && -text_prop_id
1897 <= wp->w_buffer->b_textprop_text.ga_len)
1898 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001899 textprop_T *tp = &text_props[used_tpi];
1900 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001901 ->b_textprop_text.ga_data)[
1902 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001903 int above = (tp->tp_flags
1904 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001905
1906 // reset the ID in the copy to avoid it being used
1907 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001908 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001909
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001910 if (p != NULL)
1911 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001912 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001913 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001914 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001915 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001916 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1917 int padding = tp->tp_col == MAXCOL
1918 && tp->tp_len > 1
1919 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001920
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001921 // Insert virtual text before the current
1922 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001923 wlv.p_extra = p;
1924 wlv.c_extra = NUL;
1925 wlv.c_final = NUL;
1926 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001927 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001928 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001929 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001930 // restore search_attr and area_attr when n_extra
1931 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001932 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001933 saved_area_attr = area_attr;
1934 search_attr = 0;
1935 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001936 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001937 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001938 if (*ptr == NUL)
1939 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001940 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001941#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001942 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001943 {
1944 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001945 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001946 wlv.need_showbreak = FALSE;
1947 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001948 }
1949#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001950 if ((right || above || below || !wrap
1951 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001952 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001953 char_u *prev_p_extra = wlv.p_extra;
1954 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001955
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001956 // Take care of padding, right-align and
1957 // truncation.
1958 // Shared with win_lbr_chartabsize(), must do
1959 // exactly the same.
1960 start_line = text_prop_position(wp, tp,
1961 wlv.col,
1962 &wlv.n_extra, &wlv.p_extra,
1963 &n_attr, &n_attr_skip);
1964 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001965 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001966 // wlv.p_extra was allocated
1967 vim_free(p_extra_free2);
1968 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001969 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001970
Bram Moolenaara4abe512022-09-15 19:44:09 +01001971 if (lcs_eol_one < 0 && wlv.col
1972 + wlv.n_extra - 2 > wp->w_width)
1973 // don't bail out at end of line
1974 lcs_eol_one = 0;
1975
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001976 // When 'wrap' is off then for "below" we need
1977 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001978 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001979 {
1980 draw_screen_line(wp, &wlv);
1981
1982 // When line got too long for screen break
1983 // here.
1984 if (wlv.row == endrow)
1985 {
1986 ++wlv.row;
1987 break;
1988 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001989 win_line_start(wp, &wlv, TRUE);
1990 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001991 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001992 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001993 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001994
1995 // If another text prop follows the condition below at
1996 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001997 // If this is an "above" text prop and 'nowrap' the we
1998 // must wrap anyway.
1999 text_prop_above = above;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002000 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002001 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002002 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002003 else if (text_prop_next < text_prop_count
2004 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002005 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2006 || (!wp->w_p_wrap
2007 && wlv.col == wp->w_width - 1
2008 && (text_props[text_prop_next].tp_flags
2009 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002010 // When at last-but-one character and a text property
2011 // follows after it, we may need to flush the line after
2012 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002013 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002014 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002015 }
2016#endif
2017
Bram Moolenaare38fc862022-08-11 17:24:50 +01002018#ifdef FEAT_SEARCH_EXTRA
2019 if (wlv.n_extra == 0)
2020 {
2021 // Check for start/end of 'hlsearch' and other matches.
2022 // After end, check for start/end of next match.
2023 // When another match, have to check for start again.
2024 v = (long)(ptr - line);
2025 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2026 &screen_search_hl, &has_match_conc,
2027 &match_conc, did_line_attr, lcs_eol_one,
2028 &on_last_col);
2029 ptr = line + v; // "line" may have been changed
2030 prev_ptr = ptr;
2031
2032 // Do not allow a conceal over EOL otherwise EOL will be missed
2033 // and bad things happen.
2034 if (*ptr == NUL)
2035 has_match_conc = 0;
2036 }
2037#endif
2038
2039#ifdef FEAT_DIFF
2040 if (wlv.diff_hlf != (hlf_T)0)
2041 {
2042 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2043 && wlv.n_extra == 0)
2044 wlv.diff_hlf = HLF_TXD; // changed text
2045 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2046 && wlv.n_extra == 0)
2047 wlv.diff_hlf = HLF_CHD; // changed line
2048 line_attr = HL_ATTR(wlv.diff_hlf);
2049 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2050 && wp->w_p_culopt_flags != CULOPT_NBR
2051 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2052 && wlv.vcol <= right_curline_col)))
2053 line_attr = hl_combine_attr(
2054 line_attr, HL_ATTR(HLF_CUL));
2055 }
2056#endif
2057
Bram Moolenaara74fda62019-10-19 17:38:03 +02002058#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002059 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002060 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002061 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002062# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002063 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002064 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002065# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002066 // Get syntax attribute.
2067 if (has_syntax)
2068 {
2069 // Get the syntax attribute for the character. If there
2070 // is an error, disable syntax highlighting.
2071 save_did_emsg = did_emsg;
2072 did_emsg = FALSE;
2073
2074 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002075 if (v == prev_syntax_col)
2076 // at same column again
2077 syntax_attr = prev_syntax_attr;
2078 else
2079 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002080# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002081 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002082# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002083 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002084# ifdef FEAT_SPELL
2085 has_spell ? &can_spell :
2086# endif
2087 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002088 prev_syntax_col = v;
2089 prev_syntax_attr = syntax_attr;
2090 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002091
Bram Moolenaar34390282019-10-16 14:38:26 +02002092 if (did_emsg)
2093 {
2094 wp->w_s->b_syn_error = TRUE;
2095 has_syntax = FALSE;
2096 syntax_attr = 0;
2097 }
2098 else
2099 did_emsg = save_did_emsg;
2100# ifdef SYN_TIME_LIMIT
2101 if (wp->w_s->b_syn_slow)
2102 has_syntax = FALSE;
2103# endif
2104
2105 // Need to get the line again, a multi-line regexp may
2106 // have made it invalid.
2107 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2108 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002109 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002110# ifdef FEAT_CONCEAL
2111 // no concealing past the end of the line, it interferes
2112 // with line highlighting
2113 if (*ptr == NUL)
2114 syntax_flags = 0;
2115 else
2116 syntax_flags = get_syntax_info(&syntax_seqnr);
2117# endif
2118 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002119 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002120# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002121 // Combine text property highlight into syntax highlight.
2122 if (text_prop_type != NULL)
2123 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002124 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002125 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2126 else
2127 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002128 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002129 }
2130# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002131#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002132
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002133 // Decide which of the highlight attributes to use.
2134 attr_pri = TRUE;
2135#ifdef LINE_ATTR
2136 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002137 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002138 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002139 if (!highlight_match)
2140 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002141 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002142# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002143 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002144# endif
2145 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002146 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002147 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002148 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002149# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002150 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002151# endif
2152 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002153 else if (line_attr != 0
2154 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2155 || wlv.vcol < wlv.fromcol
2156 || vcol_prev < fromcol_prev
2157 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002158 {
2159 // Use line_attr when not in the Visual or 'incsearch' area
2160 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002161# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002162 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002163# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002164 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002165# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002166 attr_pri = FALSE;
2167 }
2168#else
2169 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002170 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002171 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002172 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002173#endif
2174 else
2175 {
2176 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002177#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002178 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002179#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002180 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002181#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002182 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002183#ifdef FEAT_PROP_POPUP
2184 // override with text property highlight when "override" is TRUE
2185 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002186 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002187#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002188 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002189
2190 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002191 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002192 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002193 if (wlv.char_attr == 0)
2194 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002195 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002196 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002197 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002198
2199 // Get the next character to put on the screen.
2200
2201 // The "p_extra" points to the extra stuff that is inserted to
2202 // represent special characters (non-printable stuff) and other
2203 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002204 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002205 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2206 // "p_extra[n_extra]".
2207 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002208 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002209 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002210 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002211 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002212 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2213 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002214 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2215 if (enc_utf8 && utf_char2len(c) > 1)
2216 {
2217 mb_utf8 = TRUE;
2218 u8cc[0] = 0;
2219 c = 0xc0;
2220 }
2221 else
2222 mb_utf8 = FALSE;
2223 }
2224 else
2225 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002226 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002227 if (has_mbyte)
2228 {
2229 mb_c = c;
2230 if (enc_utf8)
2231 {
2232 // If the UTF-8 character is more than one byte:
2233 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002234 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002235 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002236 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002237 mb_l = 1;
2238 else if (mb_l > 1)
2239 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002240 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002241 mb_utf8 = TRUE;
2242 c = 0xc0;
2243 }
2244 }
2245 else
2246 {
2247 // if this is a DBCS character, put it in "mb_c"
2248 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002249 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002250 mb_l = 1;
2251 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002252 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002253 }
2254 if (mb_l == 0) // at the NUL at end-of-line
2255 mb_l = 1;
2256
2257 // If a double-width char doesn't fit display a '>' in the
2258 // last column.
2259 if ((
2260# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002261 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002262# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002263 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002264 && (*mb_char2cells)(mb_c) == 2)
2265 {
2266 c = '>';
2267 mb_c = c;
2268 mb_l = 1;
2269 mb_utf8 = FALSE;
2270 multi_attr = HL_ATTR(HLF_AT);
2271#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002272 if (wlv.cul_attr)
2273 multi_attr = hl_combine_attr(
2274 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002275#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002276 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002277
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002278 // put the pointer back to output the double-width
2279 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002280 ++wlv.n_extra;
2281 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002282 }
2283 else
2284 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002285 wlv.n_extra -= mb_l - 1;
2286 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002287 }
2288 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002289 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002290 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002291 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002292#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002293 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002294 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002295 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002296 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002297 if (search_attr == 0)
2298 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002299 if (area_attr == 0 && *ptr != NUL)
2300 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002301 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002302#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002303 }
2304 else
2305 {
2306#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002307 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002308#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002309 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002310
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002311 // Get a character from the line itself.
2312 c = *ptr;
2313#ifdef FEAT_LINEBREAK
2314 c0 = *ptr;
2315#endif
2316 if (has_mbyte)
2317 {
2318 mb_c = c;
2319 if (enc_utf8)
2320 {
2321 // If the UTF-8 character is more than one byte: Decode it
2322 // into "mb_c".
2323 mb_l = utfc_ptr2len(ptr);
2324 mb_utf8 = FALSE;
2325 if (mb_l > 1)
2326 {
2327 mb_c = utfc_ptr2char(ptr, u8cc);
2328 // Overlong encoded ASCII or ASCII with composing char
2329 // is displayed normally, except a NUL.
2330 if (mb_c < 0x80)
2331 {
2332 c = mb_c;
2333#ifdef FEAT_LINEBREAK
2334 c0 = mb_c;
2335#endif
2336 }
2337 mb_utf8 = TRUE;
2338
2339 // At start of the line we can have a composing char.
2340 // Draw it as a space with a composing char.
2341 if (utf_iscomposing(mb_c))
2342 {
2343 int i;
2344
2345 for (i = Screen_mco - 1; i > 0; --i)
2346 u8cc[i] = u8cc[i - 1];
2347 u8cc[0] = mb_c;
2348 mb_c = ' ';
2349 }
2350 }
2351
2352 if ((mb_l == 1 && c >= 0x80)
2353 || (mb_l >= 1 && mb_c == 0)
2354 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2355 {
2356 // Illegal UTF-8 byte: display as <xx>.
2357 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002358 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002359# ifdef FEAT_RIGHTLEFT
2360 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002361 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002362# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002363 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002364 c = *wlv.p_extra;
2365 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002366 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002367 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2368 wlv.c_extra = NUL;
2369 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002370 if (area_attr == 0 && search_attr == 0)
2371 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002372 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002373 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002374 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002375 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002376 }
2377 }
2378 else if (mb_l == 0) // at the NUL at end-of-line
2379 mb_l = 1;
2380#ifdef FEAT_ARABIC
2381 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2382 {
2383 // Do Arabic shaping.
2384 int pc, pc1, nc;
2385 int pcc[MAX_MCO];
2386
2387 // The idea of what is the previous and next
2388 // character depends on 'rightleft'.
2389 if (wp->w_p_rl)
2390 {
2391 pc = prev_c;
2392 pc1 = prev_c1;
2393 nc = utf_ptr2char(ptr + mb_l);
2394 prev_c1 = u8cc[0];
2395 }
2396 else
2397 {
2398 pc = utfc_ptr2char(ptr + mb_l, pcc);
2399 nc = prev_c;
2400 pc1 = pcc[0];
2401 }
2402 prev_c = mb_c;
2403
2404 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2405 }
2406 else
2407 prev_c = mb_c;
2408#endif
2409 }
2410 else // enc_dbcs
2411 {
2412 mb_l = MB_BYTE2LEN(c);
2413 if (mb_l == 0) // at the NUL at end-of-line
2414 mb_l = 1;
2415 else if (mb_l > 1)
2416 {
2417 // We assume a second byte below 32 is illegal.
2418 // Hopefully this is OK for all double-byte encodings!
2419 if (ptr[1] >= 32)
2420 mb_c = (c << 8) + ptr[1];
2421 else
2422 {
2423 if (ptr[1] == NUL)
2424 {
2425 // head byte at end of line
2426 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002427 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002428 }
2429 else
2430 {
2431 // illegal tail byte
2432 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002433 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002434 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002435 wlv.p_extra = wlv.extra;
2436 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002437 wlv.c_extra = NUL;
2438 wlv.c_final = NUL;
2439 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002440 if (area_attr == 0 && search_attr == 0)
2441 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002442 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002443 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002444 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002445 // save current attr
2446 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002447 }
2448 mb_c = c;
2449 }
2450 }
2451 }
2452 // If a double-width char doesn't fit display a '>' in the
2453 // last column; the character is displayed at the start of the
2454 // next line.
2455 if ((
2456# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002457 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002458# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002459 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002460 && (*mb_char2cells)(mb_c) == 2)
2461 {
2462 c = '>';
2463 mb_c = c;
2464 mb_utf8 = FALSE;
2465 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002466 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002467 // Put pointer back so that the character will be
2468 // displayed at the start of the next line.
2469 --ptr;
2470#ifdef FEAT_CONCEAL
2471 did_decrement_ptr = TRUE;
2472#endif
2473 }
2474 else if (*ptr != NUL)
2475 ptr += mb_l - 1;
2476
2477 // If a double-width char doesn't fit at the left side display
2478 // a '<' in the first column. Don't do this for unprintable
2479 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002480 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002481 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002482 wlv.n_extra = 1;
2483 wlv.c_extra = MB_FILLER_CHAR;
2484 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002485 c = ' ';
2486 if (area_attr == 0 && search_attr == 0)
2487 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002488 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002489 extra_attr = hl_combine_attr(
2490 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002491 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002492 }
2493 mb_c = c;
2494 mb_utf8 = FALSE;
2495 mb_l = 1;
2496 }
2497
2498 }
2499 ++ptr;
2500
2501 if (extra_check)
2502 {
2503#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002504 // Check spelling (unless at the end of the line).
2505 // Only do this when there is no syntax highlighting, the
2506 // @Spell cluster is not used or the current syntax item
2507 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002508 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002509 if (has_spell && v >= word_end && v > cur_checked_col)
2510 {
2511 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002512 // do not calculate cap_col at the end of the line or when
2513 // only white space is following
2514 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002515# ifdef FEAT_SYN_HL
2516 !has_syntax ||
2517# endif
2518 can_spell))
2519 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002520 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002521 int len;
2522 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002523
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002524 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002525 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002526
2527 // Use nextline[] if possible, it has the start of the
2528 // next line concatenated.
2529 if ((prev_ptr - line) - nextlinecol >= 0)
2530 p = nextline + (prev_ptr - line) - nextlinecol;
2531 else
2532 p = prev_ptr;
2533 cap_col -= (int)(prev_ptr - line);
2534 len = spell_check(wp, p, &spell_hlf, &cap_col,
2535 nochange);
2536 word_end = v + len;
2537
2538 // In Insert mode only highlight a word that
2539 // doesn't touch the cursor.
2540 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002541 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002542 && wp->w_cursor.lnum == lnum
2543 && wp->w_cursor.col >=
2544 (colnr_T)(prev_ptr - line)
2545 && wp->w_cursor.col < (colnr_T)word_end)
2546 {
2547 spell_hlf = HLF_COUNT;
2548 spell_redraw_lnum = lnum;
2549 }
2550
2551 if (spell_hlf == HLF_COUNT && p != prev_ptr
2552 && (p - nextline) + len > nextline_idx)
2553 {
2554 // Remember that the good word continues at the
2555 // start of the next line.
2556 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002557 checked_col = (int)((p - nextline)
2558 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002559 }
2560
2561 // Turn index into actual attributes.
2562 if (spell_hlf != HLF_COUNT)
2563 spell_attr = highlight_attr[spell_hlf];
2564
2565 if (cap_col > 0)
2566 {
2567 if (p != prev_ptr
2568 && (p - nextline) + cap_col >= nextline_idx)
2569 {
2570 // Remember that the word in the next line
2571 // must start with a capital.
2572 capcol_lnum = lnum + 1;
2573 cap_col = (int)((p - nextline) + cap_col
2574 - nextline_idx);
2575 }
2576 else
2577 // Compute the actual column.
2578 cap_col += (int)(prev_ptr - line);
2579 }
2580 }
2581 }
2582 if (spell_attr != 0)
2583 {
2584 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002585 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2586 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002587 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002588 wlv.char_attr = hl_combine_attr(spell_attr,
2589 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002590 }
2591#endif
2592#ifdef FEAT_LINEBREAK
2593 // Found last space before word: check for line break.
2594 if (wp->w_p_lbr && c0 == c
2595 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2596 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002597 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2598 : 0;
2599 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002600 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002601
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002602 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002603# ifdef FEAT_PROP_POPUP
2604 // do not want virtual text counted here
2605 cts.cts_has_prop_with_text = FALSE;
2606# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002607 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002608 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002609
2610 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002611 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002612 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002613 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002614 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2615 if (wlv.n_extra < 0)
2616 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002617 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002618 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002619 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002620 // line break, but for TABs the highlighting should
2621 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002622 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002623
Bram Moolenaar1306b362022-08-06 15:59:06 +01002624 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002625# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002626 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002627 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002628 wp->w_buffer->b_p_vts_array) - 1;
2629# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002630 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002631 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002632# endif
2633
Bram Moolenaar1306b362022-08-06 15:59:06 +01002634 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2635 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002636# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002637 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002638 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002639# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002640 if (VIM_ISWHITE(c))
2641 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002642# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002643 if (c == TAB)
2644 // See "Tab alignment" below.
2645 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002646# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002647 if (!wp->w_p_list)
2648 c = ' ';
2649 }
2650 }
2651#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002652 in_multispace = c == ' '
2653 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2654 if (!in_multispace)
2655 multispace_pos = 0;
2656
Bram Moolenaareed9d462021-02-15 20:38:25 +01002657 // 'list': Change char 160 to 'nbsp' and space to 'space'
2658 // setting in 'listchars'. But not when the character is
2659 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002660 if (wp->w_p_list
2661 && ((((c == 160 && mb_l == 1)
2662 || (mb_utf8
2663 && ((mb_c == 160 && mb_l == 2)
2664 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002665 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002666 || (c == ' '
2667 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002668 && (wp->w_lcs_chars.space
2669 || (in_multispace
2670 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002671 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002672 && ptr - line <= trailcol)))
2673 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002674 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2675 {
2676 c = wp->w_lcs_chars.multispace[multispace_pos++];
2677 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2678 multispace_pos = 0;
2679 }
2680 else
2681 c = (c == ' ') ? wp->w_lcs_chars.space
2682 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002683 if (area_attr == 0 && search_attr == 0)
2684 {
2685 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002686 extra_attr = hl_combine_attr(wlv.win_attr,
2687 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002688 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002689 }
2690 mb_c = c;
2691 if (enc_utf8 && utf_char2len(c) > 1)
2692 {
2693 mb_utf8 = TRUE;
2694 u8cc[0] = 0;
2695 c = 0xc0;
2696 }
2697 else
2698 mb_utf8 = FALSE;
2699 }
2700
zeertzjq2e7cba32022-06-10 15:30:32 +01002701 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2702 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002703 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002704 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2705 && wp->w_lcs_chars.leadmultispace != NULL)
2706 {
2707 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002708 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2709 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002710 multispace_pos = 0;
2711 }
2712
2713 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2714 c = wp->w_lcs_chars.trail;
2715
2716 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2717 c = wp->w_lcs_chars.lead;
2718
zeertzjq2e7cba32022-06-10 15:30:32 +01002719 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002720 c = wp->w_lcs_chars.space;
2721
2722
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002723 if (!attr_pri)
2724 {
2725 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002726 extra_attr = hl_combine_attr(wlv.win_attr,
2727 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002728 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002729 }
2730 mb_c = c;
2731 if (enc_utf8 && utf_char2len(c) > 1)
2732 {
2733 mb_utf8 = TRUE;
2734 u8cc[0] = 0;
2735 c = 0xc0;
2736 }
2737 else
2738 mb_utf8 = FALSE;
2739 }
2740 }
2741
2742 // Handling of non-printable characters.
2743 if (!vim_isprintc(c))
2744 {
2745 // when getting a character from the file, we may have to
2746 // turn it into something else on the way to putting it
2747 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002748 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002749 {
2750 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002751 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002752#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002753 char_u *sbr = get_showbreak_value(wp);
2754
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002755 // only adjust the tab_len, when at the first column
2756 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002757 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002758 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002759#endif
2760 // tab amount depends on current column
2761#ifdef FEAT_VARTABS
2762 tab_len = tabstop_padding(vcol_adjusted,
2763 wp->w_buffer->b_p_ts,
2764 wp->w_buffer->b_p_vts_array) - 1;
2765#else
2766 tab_len = (int)wp->w_buffer->b_p_ts
2767 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2768#endif
2769
2770#ifdef FEAT_LINEBREAK
2771 if (!wp->w_p_lbr || !wp->w_p_list)
2772#endif
2773 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002774 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002775#ifdef FEAT_LINEBREAK
2776 else
2777 {
2778 char_u *p;
2779 int len;
2780 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002781 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002782
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002783# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002784 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002785 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002786 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002787
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002788 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002789 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002790 && old_boguscols > 0
2791 && wlv.n_extra > tab_len)
2792 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002793# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002794 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002795 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002796 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002797 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002798 if (wp->w_lcs_chars.tab3)
2799 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002800 if (wlv.n_extra > 0)
2801 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002802 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002803 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002804 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002805 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002806 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002807 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002808 vim_memset(p, ' ', len);
2809 p[len] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002810 vim_free(wlv.p_extra_free);
2811 wlv.p_extra_free = p;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002812 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002813 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002814 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002815
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002816 if (*p == NUL)
2817 {
2818 tab_len = i;
2819 break;
2820 }
2821
2822 // if tab3 is given, use it for the last char
2823 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2824 lcs = wp->w_lcs_chars.tab3;
2825 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002826 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002827 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002828 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002829 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002830# ifdef FEAT_CONCEAL
2831 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2832 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002833 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002834 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002835# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002836 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002837 }
2838#endif
2839#ifdef FEAT_CONCEAL
2840 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002841 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002842
2843 // Tab alignment should be identical regardless of
2844 // 'conceallevel' value. So tab compensates of all
2845 // previous concealed characters, and thus resets
2846 // vcol_off and boguscols accumulated so far in the
2847 // line. Note that the tab can be longer than
2848 // 'tabstop' when there are concealed characters.
2849 FIX_FOR_BOGUSCOLS;
2850
2851 // Make sure, the highlighting for the tab char will be
2852 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002853 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002854 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002855 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002856 tab_len += vc_saved;
2857 }
2858#endif
2859 mb_utf8 = FALSE; // don't draw as UTF-8
2860 if (wp->w_p_list)
2861 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002862 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002863 ? wp->w_lcs_chars.tab3
2864 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002865#ifdef FEAT_LINEBREAK
2866 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002867 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002868 else
2869#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002870 wlv.c_extra = wp->w_lcs_chars.tab2;
2871 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002872 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002873 extra_attr = hl_combine_attr(wlv.win_attr,
2874 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002875 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002876 mb_c = c;
2877 if (enc_utf8 && utf_char2len(c) > 1)
2878 {
2879 mb_utf8 = TRUE;
2880 u8cc[0] = 0;
2881 c = 0xc0;
2882 }
2883 }
2884 else
2885 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002886 wlv.c_final = NUL;
2887 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002888 c = ' ';
2889 }
2890 }
2891 else if (c == NUL
2892 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002893 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
2894 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002895 && VIsual_mode != Ctrl_V
2896 && (
2897# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002898 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002899# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002900 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002901 && !(noinvcur
2902 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002903 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002904 && lcs_eol_one > 0)
2905 {
2906 // Display a '$' after the line or highlight an extra
2907 // character if the line break is included.
2908#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2909 // For a diff line the highlighting continues after the
2910 // "$".
2911 if (
2912# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002913 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002914# ifdef LINE_ATTR
2915 &&
2916# endif
2917# endif
2918# ifdef LINE_ATTR
2919 line_attr == 0
2920# endif
2921 )
2922#endif
2923 {
2924 // In virtualedit, visual selections may extend
2925 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002926 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002927 && wlv.tocol != MAXCOL
2928 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002929 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002930 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002931 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002932 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2933 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002934 else
2935 c = ' ';
2936 lcs_eol_one = -1;
2937 --ptr; // put it back at the NUL
2938 if (!attr_pri)
2939 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002940 extra_attr = hl_combine_attr(wlv.win_attr,
2941 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002942 n_attr = 1;
2943 }
2944 mb_c = c;
2945 if (enc_utf8 && utf_char2len(c) > 1)
2946 {
2947 mb_utf8 = TRUE;
2948 u8cc[0] = 0;
2949 c = 0xc0;
2950 }
2951 else
2952 mb_utf8 = FALSE; // don't draw as UTF-8
2953 }
2954 else if (c != NUL)
2955 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002956 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2957 if (wlv.n_extra == 0)
2958 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002959#ifdef FEAT_RIGHTLEFT
2960 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002961 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002962#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002963 wlv.c_extra = NUL;
2964 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002965#ifdef FEAT_LINEBREAK
2966 if (wp->w_p_lbr)
2967 {
2968 char_u *p;
2969
Bram Moolenaar1306b362022-08-06 15:59:06 +01002970 c = *wlv.p_extra;
2971 p = alloc(wlv.n_extra + 1);
2972 vim_memset(p, ' ', wlv.n_extra);
2973 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2974 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002975 vim_free(wlv.p_extra_free);
2976 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002977 }
2978 else
2979#endif
2980 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002981 wlv.n_extra = byte2cells(c) - 1;
2982 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002983 }
2984 if (!attr_pri)
2985 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002986 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002987 extra_attr = hl_combine_attr(wlv.win_attr,
2988 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002989 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002990 }
2991 mb_utf8 = FALSE; // don't draw as UTF-8
2992 }
2993 else if (VIsual_active
2994 && (VIsual_mode == Ctrl_V
2995 || VIsual_mode == 'v')
2996 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002997 && wlv.tocol != MAXCOL
2998 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002999 && (
3000#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003001 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003002#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003003 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003004 {
3005 c = ' ';
3006 --ptr; // put it back at the NUL
3007 }
3008#if defined(LINE_ATTR)
3009 else if ((
3010# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003011 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003012# endif
3013# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003014 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003015# endif
3016 line_attr != 0
3017 ) && (
3018# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003019 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003020# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003021 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003022# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003023 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003024# endif
3025 < wp->w_width)))
3026 {
3027 // Highlight until the right side of the window
3028 c = ' ';
3029 --ptr; // put it back at the NUL
3030
3031 // Remember we do the char for line highlighting.
3032 ++did_line_attr;
3033
3034 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01003035 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003036 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003037 || (wp->w_p_list &&
3038 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003039 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003040# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003041 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003042 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003043 wlv.diff_hlf = HLF_CHD;
3044 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003045 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003046 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003047 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3048 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003049 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003050 || (wlv.vcol >= left_curline_col
3051 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003052 wlv.char_attr = hl_combine_attr(
3053 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003054 }
3055 }
3056# endif
3057# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003058 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003059 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003060 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003061 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3062 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003063 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003064 if (!wlv.cul_screenline
3065 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003066 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003067 wlv.char_attr = hl_combine_attr(
3068 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003069 }
3070 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003071 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3072 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003073 }
3074# endif
3075 }
3076#endif
3077 }
3078
3079#ifdef FEAT_CONCEAL
3080 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003081 && (wp != curwin || lnum != wp->w_cursor.lnum
3082 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003083 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3084 && !(lnum_in_visual_area
3085 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3086 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003087 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003088 if (((prev_syntax_id != syntax_seqnr
3089 && (syntax_flags & HL_CONCEAL) != 0)
3090 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003091 && (syn_get_sub_char() != NUL
3092 || (has_match_conc && match_conc)
3093 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003094 && wp->w_p_cole != 3)
3095 {
3096 // First time at this concealed item: display one
3097 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003098 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003099 c = match_conc;
3100 else if (syn_get_sub_char() != NUL)
3101 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003102 else if (wp->w_lcs_chars.conceal != NUL)
3103 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003104 else
3105 c = ' ';
3106
3107 prev_syntax_id = syntax_seqnr;
3108
Bram Moolenaar1306b362022-08-06 15:59:06 +01003109 if (wlv.n_extra > 0)
3110 wlv.vcol_off += wlv.n_extra;
3111 wlv.vcol += wlv.n_extra;
3112 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003113 {
3114# ifdef FEAT_RIGHTLEFT
3115 if (wp->w_p_rl)
3116 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003117 wlv.col -= wlv.n_extra;
3118 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003119 }
3120 else
3121# endif
3122 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003123 wlv.boguscols += wlv.n_extra;
3124 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003125 }
3126 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003127 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003128 n_attr = 0;
3129 }
3130 else if (n_skip == 0)
3131 {
3132 is_concealing = TRUE;
3133 n_skip = 1;
3134 }
3135 mb_c = c;
3136 if (enc_utf8 && utf_char2len(c) > 1)
3137 {
3138 mb_utf8 = TRUE;
3139 u8cc[0] = 0;
3140 c = 0xc0;
3141 }
3142 else
3143 mb_utf8 = FALSE; // don't draw as UTF-8
3144 }
3145 else
3146 {
3147 prev_syntax_id = 0;
3148 is_concealing = FALSE;
3149 }
3150
3151 if (n_skip > 0 && did_decrement_ptr)
3152 // not showing the '>', put pointer back to avoid getting stuck
3153 ++ptr;
3154
3155#endif // FEAT_CONCEAL
3156 }
3157
3158#ifdef FEAT_CONCEAL
3159 // In the cursor line and we may be concealing characters: correct
3160 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003161 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003162 && wp == curwin && lnum == wp->w_cursor.lnum
3163 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003164 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003165 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003166# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003167 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003168 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003169 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003170# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003171 wp->w_wcol = wlv.col - wlv.boguscols;
3172 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003173 did_wcol = TRUE;
3174 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003175# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003176 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003177# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003178 }
3179#endif
3180
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003181 // Use "extra_attr", but don't override visual selection highlighting,
3182 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003183 // Don't use "extra_attr" until n_attr_skip is zero.
3184 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003185 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003186 && (!attr_pri
3187#ifdef FEAT_PROP_POPUP
3188 || (text_prop_flags & PT_FLAG_OVERRIDE)
3189#endif
3190 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003191 {
3192#ifdef LINE_ATTR
3193 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003194 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003195 else
3196#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003197 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003198 }
3199
3200#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3201 // XIM don't send preedit_start and preedit_end, but they send
3202 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3203 // im_is_preediting() here.
3204 if (p_imst == IM_ON_THE_SPOT
3205 && xic != NULL
3206 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003207 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003208 && !p_imdisable
3209 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003210 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003211 {
3212 colnr_T tcol;
3213
3214 if (preedit_end_col == MAXCOL)
3215 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3216 else
3217 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003218 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003219 {
3220 if (feedback_old_attr < 0)
3221 {
3222 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003223 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003224 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003225 wlv.char_attr = im_get_feedback_attr(feedback_col);
3226 if (wlv.char_attr < 0)
3227 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003228 feedback_col++;
3229 }
3230 else if (feedback_old_attr >= 0)
3231 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003232 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003233 feedback_old_attr = -1;
3234 feedback_col = 0;
3235 }
3236 }
3237#endif
3238 // Handle the case where we are in column 0 but not on the first
3239 // character of the line and the user wants us to show us a
3240 // special character (via 'listchars' option "precedes:<char>".
3241 if (lcs_prec_todo != NUL
3242 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003243 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3244 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003245#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003246 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003247#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003248 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003249 && c != NUL)
3250 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003251 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003252 lcs_prec_todo = NUL;
3253 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3254 {
3255 // Double-width character being overwritten by the "precedes"
3256 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003257 wlv.c_extra = MB_FILLER_CHAR;
3258 wlv.c_final = NUL;
3259 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003260 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003261 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003262 }
3263 mb_c = c;
3264 if (enc_utf8 && utf_char2len(c) > 1)
3265 {
3266 mb_utf8 = TRUE;
3267 u8cc[0] = 0;
3268 c = 0xc0;
3269 }
3270 else
3271 mb_utf8 = FALSE; // don't draw as UTF-8
3272 if (!attr_pri)
3273 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003274 saved_attr3 = wlv.char_attr; // save current attr
3275 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003276 n_attr3 = 1;
3277 }
3278 }
3279
3280 // At end of the text line or just after the last character.
3281 if ((c == NUL
3282#if defined(LINE_ATTR)
3283 || did_line_attr == 1
3284#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003285 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003286 {
3287#ifdef FEAT_SEARCH_EXTRA
3288 // flag to indicate whether prevcol equals startcol of search_hl or
3289 // one of the matches
3290 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3291 (long)(ptr - line) - (c == NUL));
3292#endif
3293 // Invert at least one char, used for Visual and empty line or
3294 // highlight match at end of line. If it's beyond the last
3295 // char on the screen, just overwrite that one (tricky!) Not
3296 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003297 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003298 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003299 && (VIsual_mode != Ctrl_V
3300 || lnum == VIsual.lnum
3301 || lnum == curwin->w_cursor.lnum)
3302 && c == NUL)
3303#ifdef FEAT_SEARCH_EXTRA
3304 // highlight 'hlsearch' match at end of line
3305 || (prevcol_hl_flag
3306# ifdef FEAT_SYN_HL
3307 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3308 && !(wp == curwin && VIsual_active))
3309# endif
3310# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003311 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003312# endif
3313# if defined(LINE_ATTR)
3314 && did_line_attr <= 1
3315# endif
3316 )
3317#endif
3318 ))
3319 {
3320 int n = 0;
3321
3322#ifdef FEAT_RIGHTLEFT
3323 if (wp->w_p_rl)
3324 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003325 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003326 n = 1;
3327 }
3328 else
3329#endif
3330 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003331 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003332 n = -1;
3333 }
3334 if (n != 0)
3335 {
3336 // At the window boundary, highlight the last character
3337 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003338 wlv.off += n;
3339 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003340 }
3341 else
3342 {
3343 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003344 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003345 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003346 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003347 }
3348#ifdef FEAT_SEARCH_EXTRA
3349 if (area_attr == 0)
3350 {
3351 // Use attributes from match with highest priority among
3352 // 'search_hl' and the match list.
3353 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003354 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003355 }
3356#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003357 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003358 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003359#ifdef FEAT_RIGHTLEFT
3360 if (wp->w_p_rl)
3361 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003362 --wlv.col;
3363 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003364 }
3365 else
3366#endif
3367 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003368 ++wlv.col;
3369 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003370 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003371 ++wlv.vcol;
3372 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003373 }
3374 }
3375
3376 // At end of the text line.
3377 if (c == NUL)
3378 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003379 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003380
3381 // Update w_cline_height and w_cline_folded if the cursor line was
3382 // updated (saves a call to plines() later).
3383 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3384 {
3385 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003386 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003387#ifdef FEAT_FOLDING
3388 curwin->w_cline_folded = FALSE;
3389#endif
3390 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3391 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003392 break;
3393 }
3394
3395 // Show "extends" character from 'listchars' if beyond the line end and
3396 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003397 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003398 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003399 && wp->w_p_list
3400 && !wp->w_p_wrap
3401#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003402 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003403#endif
3404 && (
3405#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003406 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003407#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003408 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003409 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003410 || lcs_eol_one > 0
3411 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003412 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003413 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003414 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003415 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003416 mb_c = c;
3417 if (enc_utf8 && utf_char2len(c) > 1)
3418 {
3419 mb_utf8 = TRUE;
3420 u8cc[0] = 0;
3421 c = 0xc0;
3422 }
3423 else
3424 mb_utf8 = FALSE;
3425 }
3426
3427#ifdef FEAT_SYN_HL
3428 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003429 if (wlv.draw_color_col)
3430 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003431
3432 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3433 // highlight the cursor position itself.
3434 // Also highlight the 'colorcolumn' if it is different than
3435 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003436 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3437 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003438 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003439 if (((wlv.draw_state == WL_LINE
3440 || wlv.draw_state == WL_BRI
3441 || wlv.draw_state == WL_SBR)
3442 && !lnum_in_visual_area
3443 && search_attr == 0
3444 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003445# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003446 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003447# endif
3448 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003449 {
3450 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3451 && lnum != wp->w_cursor.lnum)
3452 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003453 vcol_save_attr = wlv.char_attr;
3454 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3455 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003456 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003457 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003458 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003459 vcol_save_attr = wlv.char_attr;
3460 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003461 }
3462 }
3463#endif
3464
3465 // Store character to be displayed.
3466 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003467 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003468 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003469 {
3470 // Store the character.
3471#if defined(FEAT_RIGHTLEFT)
3472 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3473 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003474 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003475 --wlv.off;
3476 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003477 }
3478#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003479 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003480 if (enc_dbcs == DBCS_JPNU)
3481 {
3482 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003483 ScreenLines[wlv.off] = 0x8e;
3484 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003485 }
3486 else if (enc_utf8)
3487 {
3488 if (mb_utf8)
3489 {
3490 int i;
3491
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003492 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003493 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003494 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003495 for (i = 0; i < Screen_mco; ++i)
3496 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003497 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003498 if (u8cc[i] == 0)
3499 break;
3500 }
3501 }
3502 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003503 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003504 }
3505 if (multi_attr)
3506 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003507 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003508 multi_attr = 0;
3509 }
3510 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003511 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003512
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003513 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003514
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003515 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3516 {
3517 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003518 ++wlv.off;
3519 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003520 if (enc_utf8)
3521 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003522 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003523 else
3524 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003525 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003526 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003527#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003528 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003529#endif
3530 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003531 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003532 // When "wlv.tocol" is halfway a character, set it to the end
3533 // of the character, otherwise highlighting won't stop.
3534 if (wlv.tocol == wlv.vcol)
3535 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003536
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003537 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003538
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003539#ifdef FEAT_RIGHTLEFT
3540 if (wp->w_p_rl)
3541 {
3542 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003543 --wlv.off;
3544 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003545 }
3546#endif
3547 }
3548#ifdef FEAT_RIGHTLEFT
3549 if (wp->w_p_rl)
3550 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003551 --wlv.off;
3552 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003553 }
3554 else
3555#endif
3556 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003557 ++wlv.off;
3558 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003559 }
3560 }
3561#ifdef FEAT_CONCEAL
3562 else if (wp->w_p_cole > 0 && is_concealing)
3563 {
3564 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003565 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003566 if (wlv.n_extra > 0)
3567 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003568 if (wp->w_p_wrap)
3569 {
3570 // Special voodoo required if 'wrap' is on.
3571 //
3572 // Advance the column indicator to force the line
3573 // drawing to wrap early. This will make the line
3574 // take up the same screen space when parts are concealed,
3575 // so that cursor line computations aren't messed up.
3576 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003577 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003578 // trailing junk to be written out of the screen line
3579 // we are building, 'boguscols' keeps track of the number
3580 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003581 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003582 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003583 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003584# ifdef FEAT_RIGHTLEFT
3585 if (wp->w_p_rl)
3586 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003587 wlv.col -= wlv.n_extra;
3588 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003589 }
3590 else
3591# endif
3592 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003593 wlv.col += wlv.n_extra;
3594 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003595 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003596 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003597 n_attr = 0;
3598 }
3599
3600
3601 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3602 {
3603 // Need to fill two screen columns.
3604# ifdef FEAT_RIGHTLEFT
3605 if (wp->w_p_rl)
3606 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003607 --wlv.boguscols;
3608 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003609 }
3610 else
3611# endif
3612 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003613 ++wlv.boguscols;
3614 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003615 }
3616 }
3617
3618# ifdef FEAT_RIGHTLEFT
3619 if (wp->w_p_rl)
3620 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003621 --wlv.boguscols;
3622 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003623 }
3624 else
3625# endif
3626 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003627 ++wlv.boguscols;
3628 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003629 }
3630 }
3631 else
3632 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003633 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003634 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003635 wlv.vcol += wlv.n_extra;
3636 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003637 n_attr = 0;
3638 }
3639 }
3640
3641 }
3642#endif // FEAT_CONCEAL
3643 else
3644 --n_skip;
3645
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003646 // Only advance the "wlv.vcol" when after the 'number' or
3647 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003648 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003649#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003650 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003651#endif
3652 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003653 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003654
3655#ifdef FEAT_SYN_HL
3656 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003657 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003658#endif
3659
3660 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003661 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3662 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003663
3664 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003665 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003666 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003667 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003668 if (n_attr_skip > 0)
3669 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003670
3671 // At end of screen line and there is more to come: Display the line
3672 // so far. If there is no more to display it is caught above.
3673 if ((
3674#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003675 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003676#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003677 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003678 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003679 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003680#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003681 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003682#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003683#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003684 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003685#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003686 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003687 && wlv.p_extra != at_end_str)
3688 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3689 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003690 )
3691 {
3692#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003693 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003694 wlv_screen_line(wp, &wlv, FALSE);
3695 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003696 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003697#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003698 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003699#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003700 ++wlv.row;
3701 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003702
3703 // When not wrapping and finished diff lines, or when displayed
3704 // '$' and highlighting until last column, break here.
3705 if ((!wp->w_p_wrap
3706#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003707 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003708#endif
3709#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003710 && !text_prop_above && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003711#endif
3712 ) || lcs_eol_one == -1)
3713 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003714#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003715 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003716 {
3717 // do not output more of the line, only the "below" prop
3718 ptr += STRLEN(ptr);
3719# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003720 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003721# endif
3722 }
3723#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003724
3725 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003726 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003727#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003728 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003729#endif
3730 )
3731 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003732 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3733 draw_vsep_win(wp, wlv.row);
3734 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003735 }
3736
3737 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003738 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003739 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003740 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003741 break;
3742 }
3743
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003744 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003745#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003746 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003747#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003748#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003749 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003750#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003751 && wp->w_width == Columns)
3752 {
3753 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003754 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003755
3756 // Special trick to make copy/paste of wrapped lines work with
3757 // xterm/screen: write an extra character beyond the end of
3758 // the line. This will work with all terminal types
3759 // (regardless of the xn,am settings).
3760 // Only do this on a fast tty.
3761 // Only do this if the cursor is on the current line
3762 // (something has been written in it).
3763 // Don't do this for the GUI.
3764 // Don't do this for double-width characters.
3765 // Don't do this for a window not at the right screen border.
3766 if (p_tf
3767#ifdef FEAT_GUI
3768 && !gui.in_use
3769#endif
3770 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003771 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3772 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003773 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003774 || (*mb_off2cells)(
3775 LineOffset[wlv.screen_row - 1]
3776 + (int)Columns - 2,
3777 LineOffset[wlv.screen_row]
3778 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003779 {
3780 // First make sure we are at the end of the screen line,
3781 // then output the same character again to let the
3782 // terminal know about the wrap. If the terminal doesn't
3783 // auto-wrap, we overwrite the character.
3784 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003785 screen_char(LineOffset[wlv.screen_row - 1]
3786 + (unsigned)Columns - 1,
3787 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003788
3789 // When there is a multi-byte character, just output a
3790 // space to keep it simple.
3791 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003792 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003793 out_char(' ');
3794 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003795 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003796 + (Columns - 1)]);
3797 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003798 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003799 screen_start(); // don't know where cursor is now
3800 }
3801 }
3802
Bram Moolenaar1306b362022-08-06 15:59:06 +01003803 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003804
Bram Moolenaareed9d462021-02-15 20:38:25 +01003805 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003806#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003807 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003808# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003809 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003810# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003811 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003812 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003813#endif
3814#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003815 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003816 // When the filler lines are actually below the last line of the
3817 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003818 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003819 break;
3820#endif
3821 }
3822
3823 } // for every character in the line
3824
3825#ifdef FEAT_SPELL
3826 // After an empty line check first word for capital.
3827 if (*skipwhite(line) == NUL)
3828 {
3829 capcol_lnum = lnum + 1;
3830 cap_col = 0;
3831 }
3832#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003833#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003834 vim_free(text_props);
3835 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003836 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003837#endif
3838
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003839 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003840 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003841}