blob: a129bae42057c9d446269afb31ec9c6dca7c1b62 [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.
12 * This is the middle level, drawscreen. is the higher level and screen.c the
13 * 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.
105
106 int screen_line_flags; // flags for screen_line()
107
108 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
109 int cul_screenline;
110
111 int char_attr; // attributes for the next character
112
113 int n_extra; // number of extra bytes
114 char_u *p_extra; // string of extra chars, plus NUL, only used
115 // when c_extra and c_final are NUL
116 int c_extra; // extra chars, all the same
117 int c_final; // final char, mandatory if set
118
119 // saved "extra" items for when draw_state becomes WL_LINE (again)
120 int saved_n_extra;
121 char_u *saved_p_extra;
122 int saved_c_extra;
123 int saved_c_final;
124 int saved_char_attr;
125
126#ifdef FEAT_DIFF
127 hlf_T diff_hlf; // type of diff highlighting
128#endif
129} winlinevars_T;
130
131// draw_state values for items that are drawn in sequence:
132#define WL_START 0 // nothing done yet, must be zero
133#ifdef FEAT_CMDWIN
134# define WL_CMDLINE (WL_START + 1) // cmdline window column
135#else
136# define WL_CMDLINE WL_START
137#endif
138#ifdef FEAT_FOLDING
139# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
140#else
141# define WL_FOLD WL_CMDLINE
142#endif
143#ifdef FEAT_SIGNS
144# define WL_SIGN (WL_FOLD + 1) // column for signs
145#else
146# define WL_SIGN WL_FOLD // column for signs
147#endif
148#define WL_NR (WL_SIGN + 1) // line number
149#ifdef FEAT_LINEBREAK
150# define WL_BRI (WL_NR + 1) // 'breakindent'
151#else
152# define WL_BRI WL_NR
153#endif
154#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
155# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
156#else
157# define WL_SBR WL_BRI
158#endif
159#define WL_LINE (WL_SBR + 1) // text in the line
160
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200161#ifdef FEAT_SIGNS
162/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000163 * Return TRUE if CursorLineSign highlight is to be used.
164 */
165 static int
166use_cursor_line_sign(win_T *wp, linenr_T lnum)
167{
168 return wp->w_p_cul
169 && lnum == wp->w_cursor.lnum
170 && (wp->w_p_culopt_flags & CULOPT_NBR);
171}
172
173/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200174 * Get information needed to display the sign in line 'lnum' in window 'wp'.
175 * If 'nrcol' is TRUE, the sign is going to be displayed in the number column.
176 * Otherwise the sign is going to be displayed in the sign column.
177 */
178 static void
179get_sign_display_info(
180 int nrcol,
181 win_T *wp,
Bram Moolenaare413ea02021-11-24 16:20:13 +0000182 linenr_T lnum,
Bram Moolenaar1306b362022-08-06 15:59:06 +0100183 winlinevars_T *wlv,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200184 sign_attrs_T *sattr,
185 int wcr_attr,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200186 int filler_lines UNUSED,
187 int filler_todo UNUSED,
Bram Moolenaar1306b362022-08-06 15:59:06 +0100188 char_u *extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200189{
190 int text_sign;
191# ifdef FEAT_SIGN_ICONS
192 int icon_sign;
193# endif
194
195 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100196 wlv->c_extra = ' ';
197 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200198 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100199 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200200 else
201 {
Bram Moolenaare413ea02021-11-24 16:20:13 +0000202 if (use_cursor_line_sign(wp, lnum))
Bram Moolenaar1306b362022-08-06 15:59:06 +0100203 wlv->char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000204 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100205 wlv->char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_SC));
206 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200207 }
208
Bram Moolenaar1306b362022-08-06 15:59:06 +0100209 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200210#ifdef FEAT_DIFF
211 + filler_lines && filler_todo <= 0
212#endif
213 )
214 {
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200215 text_sign = (sattr->sat_text != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200216# ifdef FEAT_SIGN_ICONS
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200217 icon_sign = (sattr->sat_icon != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200218 if (gui.in_use && icon_sign != 0)
219 {
220 // Use the image in this position.
221 if (nrcol)
222 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100223 wlv->c_extra = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200224 sprintf((char *)extra, "%-*c ", number_width(wp), SIGN_BYTE);
Bram Moolenaar1306b362022-08-06 15:59:06 +0100225 wlv->p_extra = extra;
226 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200227 }
228 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100229 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200230# ifdef FEAT_NETBEANS_INTG
231 if (netbeans_active() && (buf_signcount(wp->w_buffer, lnum) > 1))
232 {
233 if (nrcol)
234 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100235 wlv->c_extra = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200236 sprintf((char *)extra, "%-*c ", number_width(wp),
237 MULTISIGN_BYTE);
Bram Moolenaar1306b362022-08-06 15:59:06 +0100238 wlv->p_extra = extra;
239 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200240 }
241 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100242 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200243 }
244# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100245 wlv->c_final = NUL;
246 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200247 }
248 else
249# endif
250 if (text_sign != 0)
251 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100252 wlv->p_extra = sattr->sat_text;
253 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200254 {
255 if (nrcol)
256 {
257 int n, width = number_width(wp) - 2;
258
259 for (n = 0; n < width; n++)
260 extra[n] = ' ';
261 extra[n] = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100262 STRCAT(extra, wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200263 STRCAT(extra, " ");
Bram Moolenaar1306b362022-08-06 15:59:06 +0100264 wlv->p_extra = extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200265 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100266 wlv->c_extra = NUL;
267 wlv->c_final = NUL;
268 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200269 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000270
271 if (use_cursor_line_sign(wp, lnum) && sattr->sat_culhl > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100272 wlv->char_attr = sattr->sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000273 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100274 wlv->char_attr = sattr->sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200275 }
276 }
277}
278#endif
279
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100280#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200281static textprop_T *current_text_props = NULL;
282static buf_T *current_buf = NULL;
283
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100284/*
285 * Function passed to qsort() to sort text properties.
286 * Return 1 if "s1" has priority over "s2", -1 if the other way around, zero if
287 * both have the same priority.
288 */
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200289 static int
290text_prop_compare(const void *s1, const void *s2)
291{
292 int idx1, idx2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100293 textprop_T *tp1, *tp2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200294 proptype_T *pt1, *pt2;
295 colnr_T col1, col2;
296
297 idx1 = *(int *)s1;
298 idx2 = *(int *)s2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100299 tp1 = &current_text_props[idx1];
300 tp2 = &current_text_props[idx2];
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100301 col1 = tp1->tp_col;
302 col2 = tp2->tp_col;
303 if (col1 == MAXCOL && col2 == MAXCOL)
304 {
305 int flags1 = 0;
306 int flags2 = 0;
307
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100308 // both props add text are after the line, order on 0: after (default),
309 // 1: right, 2: below (comes last)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100310 if (tp1->tp_flags & TP_FLAG_ALIGN_RIGHT)
311 flags1 = 1;
312 if (tp1->tp_flags & TP_FLAG_ALIGN_BELOW)
313 flags1 = 2;
314 if (tp2->tp_flags & TP_FLAG_ALIGN_RIGHT)
315 flags2 = 1;
316 if (tp2->tp_flags & TP_FLAG_ALIGN_BELOW)
317 flags2 = 2;
318 if (flags1 != flags2)
319 return flags1 < flags2 ? 1 : -1;
320 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100321
322 // property that inserts text has priority over one that doesn't
323 if ((tp1->tp_id < 0) != (tp2->tp_id < 0))
324 return tp1->tp_id < 0 ? 1 : -1;
325
326 // check highest priority, defined by the type
Bram Moolenaardb9b96d2022-08-06 17:38:53 +0100327 pt1 = text_prop_type_by_id(current_buf, tp1->tp_type);
328 pt2 = text_prop_type_by_id(current_buf, tp2->tp_type);
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100329 if (pt1 != pt2)
330 {
331 if (pt1 == NULL)
332 return -1;
333 if (pt2 == NULL)
334 return 1;
335 if (pt1->pt_priority != pt2->pt_priority)
336 return pt1->pt_priority > pt2->pt_priority ? 1 : -1;
337 }
338
339 // same priority, one that starts first wins
340 if (col1 != col2)
341 return col1 < col2 ? 1 : -1;
342 return 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200343}
344#endif
345
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100346/*
347 * Called when finished with the line: draw the screen line and handle any
348 * highlighting until the right of the window.
349 */
350 static void
351draw_screen_line(win_T *wp, winlinevars_T *wlv)
352{
353#ifdef FEAT_SYN_HL
354 long v;
355
356 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
357 if (wp->w_p_wrap)
358 v = wp->w_skipcol;
359 else
360 v = wp->w_leftcol;
361
362 // check if line ends before left margin
363 if (wlv->vcol < v + wlv->col - win_col_off(wp))
364 wlv->vcol = v + wlv->col - win_col_off(wp);
365# ifdef FEAT_CONCEAL
366 // Get rid of the boguscols now, we want to draw until the right
367 // edge for 'cursorcolumn'.
368 wlv->col -= wlv->boguscols;
369 wlv->boguscols = 0;
370# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
371# else
372# define VCOL_HLC (wlv->vcol)
373# endif
374
375 if (wlv->draw_color_col)
376 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
377
378 if (((wp->w_p_cuc
379 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
380 && (int)wp->w_virtcol <
381 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
382 && wlv->lnum != wp->w_cursor.lnum)
383 || wlv->draw_color_col
384 || wlv->win_attr != 0)
385# ifdef FEAT_RIGHTLEFT
386 && !wp->w_p_rl
387# endif
388 )
389 {
390 int rightmost_vcol = 0;
391 int i;
392
393 if (wp->w_p_cuc)
394 rightmost_vcol = wp->w_virtcol;
395 if (wlv->draw_color_col)
396 // determine rightmost colorcolumn to possibly draw
397 for (i = 0; wlv->color_cols[i] >= 0; ++i)
398 if (rightmost_vcol < wlv->color_cols[i])
399 rightmost_vcol = wlv->color_cols[i];
400
401 while (wlv->col < wp->w_width)
402 {
403 ScreenLines[wlv->off] = ' ';
404 if (enc_utf8)
405 ScreenLinesUC[wlv->off] = 0;
406 ScreenCols[wlv->off] = MAXCOL;
407 ++wlv->col;
408 if (wlv->draw_color_col)
409 wlv->draw_color_col = advance_color_col(
410 VCOL_HLC, &wlv->color_cols);
411
412 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
413 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
414 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
415 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
416 else
417 ScreenAttrs[wlv->off++] = wlv->win_attr;
418
419 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
420 break;
421
422 ++wlv->vcol;
423 }
424 }
425#endif
426
427 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
428 wp->w_width, wlv->screen_line_flags);
429 ++wlv->row;
430 ++wlv->screen_row;
431}
432#undef VCOL_HLC
433
434/*
435 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100436 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100437 */
438 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100439win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100440{
441 wlv->col = 0;
442 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
443
444#ifdef FEAT_RIGHTLEFT
445 if (wp->w_p_rl)
446 {
447 // Rightleft window: process the text in the normal direction, but put
448 // it in current_ScreenLine[] from right to left. Start at the
449 // rightmost column of the window.
450 wlv->col = wp->w_width - 1;
451 wlv->off += wlv->col;
452 wlv->screen_line_flags |= SLF_RIGHTLEFT;
453 }
454#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100455 if (save_extra)
456 {
457 // reset the drawing state for the start of a wrapped line
458 wlv->draw_state = WL_START;
459 wlv->saved_n_extra = wlv->n_extra;
460 wlv->saved_p_extra = wlv->p_extra;
461 wlv->saved_c_extra = wlv->c_extra;
462 wlv->saved_c_final = wlv->c_final;
463#ifdef FEAT_SYN_HL
464 if (!(wlv->cul_screenline
465# ifdef FEAT_DIFF
466 && wlv->diff_hlf == (hlf_T)0
467# endif
468 ))
469 wlv->saved_char_attr = wlv->char_attr;
470 else
471#endif
472 wlv->saved_char_attr = 0;
473 wlv->n_extra = 0;
474 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100475}
476
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200477/*
478 * Display line "lnum" of window 'wp' on the screen.
479 * Start at row "startrow", stop when "endrow" is reached.
480 * wp->w_virtcol needs to be valid.
481 *
482 * Return the number of last row the line occupies.
483 */
484 int
485win_line(
486 win_T *wp,
487 linenr_T lnum,
488 int startrow,
489 int endrow,
490 int nochange UNUSED, // not updating for changed text
491 int number_only) // only update the number column
492{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100493 winlinevars_T wlv; // variables passed between functions
494
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200495 int c = 0; // init for GCC
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200496#ifdef FEAT_LINEBREAK
497 long vcol_sbr = -1; // virtual column after showbreak
498#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100499 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200500 char_u *line; // current line
501 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200502
503 char_u extra[21]; // "%ld " and 'fdc' must fit in here
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200504 char_u *p_extra_free = NULL; // p_extra needs to be freed
Bram Moolenaar1306b362022-08-06 15:59:06 +0100505#ifdef FEAT_PROP_POPUP
506 char_u *p_extra_free2 = NULL; // another p_extra to be freed
507#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200508 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000509#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000510 int in_linebreak = FALSE; // n_extra set for showing linebreak
511#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200512 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100513 // displaying eol at end-of-line
514 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000515 int lcs_prec_todo = wp->w_lcs_chars.prec;
516 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200517
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100518 int n_attr = 0; // chars with special attr
519 int n_attr_skip = 0; // chars to skip before using extra_attr
520 int saved_attr2 = 0; // char_attr saved for n_attr
521 int n_attr3 = 0; // chars with overruling special attr
522 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200523
524 int n_skip = 0; // nr of chars to skip for 'nowrap'
525
526 int fromcol = -10; // start of inverting
527 int tocol = MAXCOL; // end of inverting
528 int fromcol_prev = -2; // start of inverting after cursor
529 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200530 int lnum_in_visual_area = FALSE;
531 pos_T pos;
532 long v;
533
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200534 int attr_pri = FALSE; // char_attr has priority
535 int area_highlighting = FALSE; // Visual or incsearch highlighting
536 // in this line
537 int vi_attr = 0; // attributes for Visual and incsearch
538 // highlighting
539 int wcr_attr = 0; // attributes from 'wincolor'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200540 int area_attr = 0; // attributes desired by highlighting
541 int search_attr = 0; // attributes desired by 'hlsearch'
542#ifdef FEAT_SYN_HL
543 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
544 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200545 int prev_syntax_col = -1; // column of prev_syntax_attr
546 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200547 int has_syntax = FALSE; // this buffer has syntax highl.
548 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200549#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100550#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200551 int text_prop_count;
552 int text_prop_next = 0; // next text property to use
553 textprop_T *text_props = NULL;
554 int *text_prop_idxs = NULL;
555 int text_props_active = 0;
556 proptype_T *text_prop_type = NULL;
557 int text_prop_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100558 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100559 int text_prop_flags = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100560 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +0100561 int saved_search_attr = 0; // search_attr to be used when n_extra
562 // goes to zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200563#endif
564#ifdef FEAT_SPELL
565 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000566 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200567# define SPWORDLEN 150
568 char_u nextline[SPWORDLEN * 2];// text with start of the next line
569 int nextlinecol = 0; // column where nextline[] starts
570 int nextline_idx = 0; // index in nextline[] where next line
571 // starts
572 int spell_attr = 0; // attributes desired by spelling
573 int word_end = 0; // last byte with same spell_attr
574 static linenr_T checked_lnum = 0; // line number for "checked_col"
575 static int checked_col = 0; // column in "checked_lnum" up to which
576 // there are no spell errors
577 static int cap_col = -1; // column to check for Cap word
578 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
579 int cur_checked_col = 0; // checked column for current line
580#endif
581 int extra_check = 0; // has extra highlighting
582 int multi_attr = 0; // attributes desired by multibyte
583 int mb_l = 1; // multi-byte byte length
584 int mb_c = 0; // decoded multi-byte character
585 int mb_utf8 = FALSE; // screen char is UTF-8 char
586 int u8cc[MAX_MCO]; // composing UTF-8 chars
587#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
588 int filler_lines = 0; // nr of filler lines to be drawn
589 int filler_todo = 0; // nr of filler lines still to do + 1
Bram Moolenaar936dc602022-03-06 20:47:01 +0000590#else
591# define filler_lines 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200592#endif
593#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200594 int change_start = MAXCOL; // first col of changed area
595 int change_end = -1; // last col of changed area
596#endif
597 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100598 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200599 int in_multispace = FALSE; // in multiple consecutive spaces
600 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200601#ifdef FEAT_LINEBREAK
602 int need_showbreak = FALSE; // overlong line, skipping first x
603 // chars
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +0100604 int dont_use_showbreak = FALSE; // do not use 'showbreak'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200605#endif
606#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
607 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
608# define LINE_ATTR
609 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +0100610 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200611#endif
612#ifdef FEAT_SIGNS
613 int sign_present = FALSE;
614 sign_attrs_T sattr;
James McCoya80aad72021-12-22 19:45:28 +0000615 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200616#endif
617#ifdef FEAT_ARABIC
618 int prev_c = 0; // previous Arabic character
619 int prev_c1 = 0; // first composing char for prev_c
620#endif
621#if defined(LINE_ATTR)
622 int did_line_attr = 0;
623#endif
624#ifdef FEAT_TERMINAL
625 int get_term_attr = FALSE;
626#endif
627#ifdef FEAT_SYN_HL
628 int cul_attr = 0; // set when 'cursorline' active
629
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200630 // margin columns for the screen line, needed for when 'cursorlineopt'
631 // contains "screenline"
632 int left_curline_col = 0;
633 int right_curline_col = 0;
634#endif
635
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200636#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
637 int feedback_col = 0;
638 int feedback_old_attr = -1;
639#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200640
641#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
642 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000643 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200644#endif
645#ifdef FEAT_CONCEAL
646 int syntax_flags = 0;
647 int syntax_seqnr = 0;
648 int prev_syntax_id = 0;
649 int conceal_attr = HL_ATTR(HLF_CONCEAL);
650 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200651 int did_wcol = FALSE;
652 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100653# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200654# define FIX_FOR_BOGUSCOLS \
655 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +0100656 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100657 wlv.vcol -= wlv.vcol_off; \
658 wlv.vcol_off = 0; \
659 wlv.col -= wlv.boguscols; \
660 old_boguscols = wlv.boguscols; \
661 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200662 }
663#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100664# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200665#endif
666
667 if (startrow > endrow) // past the end already!
668 return startrow;
669
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100670 CLEAR_FIELD(wlv);
671
672 wlv.lnum = lnum;
673 wlv.startrow = startrow;
674 wlv.row = startrow;
675 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200676
677 if (!number_only)
678 {
679 // To speed up the loop below, set extra_check when there is linebreak,
680 // trailing white space and/or syntax processing to be done.
681#ifdef FEAT_LINEBREAK
682 extra_check = wp->w_p_lbr;
683#endif
684#ifdef FEAT_SYN_HL
685 if (syntax_present(wp) && !wp->w_s->b_syn_error
686# ifdef SYN_TIME_LIMIT
687 && !wp->w_s->b_syn_slow
688# endif
689 )
690 {
691 // Prepare for syntax highlighting in this line. When there is an
692 // error, stop syntax highlighting.
693 save_did_emsg = did_emsg;
694 did_emsg = FALSE;
695 syntax_start(wp, lnum);
696 if (did_emsg)
697 wp->w_s->b_syn_error = TRUE;
698 else
699 {
700 did_emsg = save_did_emsg;
701#ifdef SYN_TIME_LIMIT
702 if (!wp->w_s->b_syn_slow)
703#endif
704 {
705 has_syntax = TRUE;
706 extra_check = TRUE;
707 }
708 }
709 }
710
711 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100712 wlv.color_cols = wp->w_p_cc_cols;
713 if (wlv.color_cols != NULL)
714 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200715#endif
716
717#ifdef FEAT_TERMINAL
718 if (term_show_buffer(wp->w_buffer))
719 {
720 extra_check = TRUE;
721 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100722 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200723 }
724#endif
725
726#ifdef FEAT_SPELL
727 if (wp->w_p_spell
728 && *wp->w_s->b_p_spl != NUL
729 && wp->w_s->b_langp.ga_len > 0
730 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
731 {
732 // Prepare for spell checking.
733 has_spell = TRUE;
734 extra_check = TRUE;
735
736 // Get the start of the next line, so that words that wrap to the
737 // next line are found too: "et<line-break>al.".
738 // Trick: skip a few chars for C/shell/Vim comments
739 nextline[SPWORDLEN] = NUL;
740 if (lnum < wp->w_buffer->b_ml.ml_line_count)
741 {
742 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
743 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
744 }
745
746 // When a word wrapped from the previous line the start of the
747 // current line is valid.
748 if (lnum == checked_lnum)
749 cur_checked_col = checked_col;
750 checked_lnum = 0;
751
752 // When there was a sentence end in the previous line may require a
753 // word starting with capital in this line. In line 1 always check
754 // the first word.
755 if (lnum != capcol_lnum)
756 cap_col = -1;
757 if (lnum == 1)
758 cap_col = 0;
759 capcol_lnum = 0;
760 }
761#endif
762
763 // handle Visual active in this window
764 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
765 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100766 pos_T *top, *bot;
767
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200768 if (LTOREQ_POS(curwin->w_cursor, VIsual))
769 {
770 // Visual is after curwin->w_cursor
771 top = &curwin->w_cursor;
772 bot = &VIsual;
773 }
774 else
775 {
776 // Visual is before curwin->w_cursor
777 top = &VIsual;
778 bot = &curwin->w_cursor;
779 }
780 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
781 if (VIsual_mode == Ctrl_V)
782 {
783 // block mode
784 if (lnum_in_visual_area)
785 {
786 fromcol = wp->w_old_cursor_fcol;
787 tocol = wp->w_old_cursor_lcol;
788 }
789 }
790 else
791 {
792 // non-block mode
793 if (lnum > top->lnum && lnum <= bot->lnum)
794 fromcol = 0;
795 else if (lnum == top->lnum)
796 {
797 if (VIsual_mode == 'V') // linewise
798 fromcol = 0;
799 else
800 {
801 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
802 if (gchar_pos(top) == NUL)
803 tocol = fromcol + 1;
804 }
805 }
806 if (VIsual_mode != 'V' && lnum == bot->lnum)
807 {
808 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
809 {
810 fromcol = -10;
811 tocol = MAXCOL;
812 }
813 else if (bot->col == MAXCOL)
814 tocol = MAXCOL;
815 else
816 {
817 pos = *bot;
818 if (*p_sel == 'e')
819 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
820 else
821 {
822 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
823 ++tocol;
824 }
825 }
826 }
827 }
828
829 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200830 if (!highlight_match && lnum == curwin->w_cursor.lnum
831 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200832#ifdef FEAT_GUI
833 && !gui.in_use
834#endif
835 )
836 noinvcur = TRUE;
837
838 // if inverting in this line set area_highlighting
839 if (fromcol >= 0)
840 {
841 area_highlighting = TRUE;
842 vi_attr = HL_ATTR(HLF_V);
843#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
844 if ((clip_star.available && !clip_star.owned
845 && clip_isautosel_star())
846 || (clip_plus.available && !clip_plus.owned
847 && clip_isautosel_plus()))
848 vi_attr = HL_ATTR(HLF_VNC);
849#endif
850 }
851 }
852
853 // handle 'incsearch' and ":s///c" highlighting
854 else if (highlight_match
855 && wp == curwin
856 && lnum >= curwin->w_cursor.lnum
857 && lnum <= curwin->w_cursor.lnum + search_match_lines)
858 {
859 if (lnum == curwin->w_cursor.lnum)
860 getvcol(curwin, &(curwin->w_cursor),
861 (colnr_T *)&fromcol, NULL, NULL);
862 else
863 fromcol = 0;
864 if (lnum == curwin->w_cursor.lnum + search_match_lines)
865 {
866 pos.lnum = lnum;
867 pos.col = search_match_endcol;
868 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
869 }
870 else
871 tocol = MAXCOL;
872 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100873 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200874 tocol = fromcol + 1;
875 area_highlighting = TRUE;
876 vi_attr = HL_ATTR(HLF_I);
877 }
878 }
879
880#ifdef FEAT_DIFF
881 filler_lines = diff_check(wp, lnum);
882 if (filler_lines < 0)
883 {
884 if (filler_lines == -1)
885 {
886 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +0100887 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200888 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100889 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200890 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100891 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200892 }
893 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100894 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200895 filler_lines = 0;
896 area_highlighting = TRUE;
897 }
898 if (lnum == wp->w_topline)
899 filler_lines = wp->w_topfill;
900 filler_todo = filler_lines;
901#endif
902
903#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +0100904 sign_present = buf_get_signattrs(wp, lnum, &sattr);
James McCoya80aad72021-12-22 19:45:28 +0000905 if (sign_present)
906 num_attr = sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200907#endif
908
909#ifdef LINE_ATTR
910# ifdef FEAT_SIGNS
911 // If this line has a sign with line highlighting set line_attr.
912 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200913 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200914# endif
915# if defined(FEAT_QUICKFIX)
916 // Highlight the current line in the quickfix window.
917 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
918 line_attr = HL_ATTR(HLF_QFL);
919# endif
920 if (line_attr != 0)
921 area_highlighting = TRUE;
922#endif
923
924 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
925 ptr = line;
926
927#ifdef FEAT_SPELL
928 if (has_spell && !number_only)
929 {
930 // For checking first word with a capital skip white space.
931 if (cap_col == 0)
932 cap_col = getwhitecols(line);
933
934 // To be able to spell-check over line boundaries copy the end of the
935 // current line into nextline[]. Above the start of the next line was
936 // copied to nextline[SPWORDLEN].
937 if (nextline[SPWORDLEN] == NUL)
938 {
939 // No next line or it is empty.
940 nextlinecol = MAXCOL;
941 nextline_idx = 0;
942 }
943 else
944 {
945 v = (long)STRLEN(line);
946 if (v < SPWORDLEN)
947 {
948 // Short line, use it completely and append the start of the
949 // next line.
950 nextlinecol = 0;
951 mch_memmove(nextline, line, (size_t)v);
952 STRMOVE(nextline + v, nextline + SPWORDLEN);
953 nextline_idx = v + 1;
954 }
955 else
956 {
957 // Long line, use only the last SPWORDLEN bytes.
958 nextlinecol = v - SPWORDLEN;
959 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
960 nextline_idx = SPWORDLEN + 1;
961 }
962 }
963 }
964#endif
965
966 if (wp->w_p_list)
967 {
Bram Moolenaareed9d462021-02-15 20:38:25 +0100968 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +0200969 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100970 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +0100971 || wp->w_lcs_chars.trail
972 || wp->w_lcs_chars.lead
973 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200974 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100975
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200976 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100977 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200978 {
979 trailcol = (colnr_T)STRLEN(ptr);
980 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
981 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +0100982 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200983 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100984 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100985 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100986 {
987 leadcol = 0;
988 while (VIM_ISWHITE(ptr[leadcol]))
989 ++leadcol;
990 if (ptr[leadcol] == NUL)
991 // in a line full of spaces all of them are treated as trailing
992 leadcol = (colnr_T)0;
993 else
994 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +0100995 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100996 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200997 }
998
999 wcr_attr = get_wcr_attr(wp);
1000 if (wcr_attr != 0)
1001 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001002 wlv.win_attr = wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001003 area_highlighting = TRUE;
1004 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001005
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001006#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001007 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001008 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001009#endif
1010
1011 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1012 // first character to be displayed.
1013 if (wp->w_p_wrap)
1014 v = wp->w_skipcol;
1015 else
1016 v = wp->w_leftcol;
1017 if (v > 0 && !number_only)
1018 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001019 char_u *prev_ptr = ptr;
1020 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001021 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001022
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001023 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001024 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001025 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001026 charsize = win_lbr_chartabsize(&cts, NULL);
1027 cts.cts_vcol += charsize;
1028 prev_ptr = cts.cts_ptr;
1029 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001030 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001031 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001032 ptr = cts.cts_ptr;
1033 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001034
1035 // When:
1036 // - 'cuc' is set, or
1037 // - 'colorcolumn' is set, or
1038 // - 'virtualedit' is set, or
1039 // - the visual mode is active,
1040 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001041 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001042#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001043 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001044#endif
1045 virtual_active() ||
1046 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001047 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001048
1049 // Handle a character that's not completely on the screen: Put ptr at
1050 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001051 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001052 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001053 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001054 ptr = prev_ptr;
1055 // If the character fits on the screen, don't need to skip it.
1056 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001057 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1058 && wlv.col == 0)
1059 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001060 }
1061
1062 // Adjust for when the inverted text is before the screen,
1063 // and when the start of the inverted text is before the screen.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001064 if (tocol <= wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001065 fromcol = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001066 else if (fromcol >= 0 && fromcol < wlv.vcol)
1067 fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001068
1069#ifdef FEAT_LINEBREAK
1070 // When w_skipcol is non-zero, first line needs 'showbreak'
1071 if (wp->w_p_wrap)
1072 need_showbreak = TRUE;
1073#endif
1074#ifdef FEAT_SPELL
1075 // When spell checking a word we need to figure out the start of the
1076 // word and if it's badly spelled or not.
1077 if (has_spell)
1078 {
1079 int len;
1080 colnr_T linecol = (colnr_T)(ptr - line);
1081 hlf_T spell_hlf = HLF_COUNT;
1082
1083 pos = wp->w_cursor;
1084 wp->w_cursor.lnum = lnum;
1085 wp->w_cursor.col = linecol;
1086 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1087
1088 // spell_move_to() may call ml_get() and make "line" invalid
1089 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1090 ptr = line + linecol;
1091
1092 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1093 {
1094 // no bad word found at line start, don't check until end of a
1095 // word
1096 spell_hlf = HLF_COUNT;
1097 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1098 }
1099 else
1100 {
1101 // bad word found, use attributes until end of word
1102 word_end = wp->w_cursor.col + len + 1;
1103
1104 // Turn index into actual attributes.
1105 if (spell_hlf != HLF_COUNT)
1106 spell_attr = highlight_attr[spell_hlf];
1107 }
1108 wp->w_cursor = pos;
1109
1110# ifdef FEAT_SYN_HL
1111 // Need to restart syntax highlighting for this line.
1112 if (has_syntax)
1113 syntax_start(wp, lnum);
1114# endif
1115 }
1116#endif
1117 }
1118
1119 // Correct highlighting for cursor that can't be disabled.
1120 // Avoids having to check this for each character.
1121 if (fromcol >= 0)
1122 {
1123 if (noinvcur)
1124 {
1125 if ((colnr_T)fromcol == wp->w_virtcol)
1126 {
1127 // highlighting starts at cursor, let it start just after the
1128 // cursor
1129 fromcol_prev = fromcol;
1130 fromcol = -1;
1131 }
1132 else if ((colnr_T)fromcol < wp->w_virtcol)
1133 // restart highlighting after the cursor
1134 fromcol_prev = wp->w_virtcol;
1135 }
1136 if (fromcol >= tocol)
1137 fromcol = -1;
1138 }
1139
1140#ifdef FEAT_SEARCH_EXTRA
1141 if (!number_only)
1142 {
1143 v = (long)(ptr - line);
1144 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1145 &line, &screen_search_hl,
1146 &search_attr);
1147 ptr = line + v; // "line" may have been updated
1148 }
1149#endif
1150
1151#ifdef FEAT_SYN_HL
1152 // Cursor line highlighting for 'cursorline' in the current window.
1153 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1154 {
1155 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001156 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001157 if (!(wp == curwin && VIsual_active)
1158 && wp->w_p_culopt_flags != CULOPT_NBR)
1159 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001160 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001161 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1162
1163 // Only set line_attr here when "screenline" is not present in
1164 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001165 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001166 {
1167 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001168# ifdef FEAT_SIGNS
1169 // Combine the 'cursorline' and sign highlighting, depending on
1170 // the sign priority.
1171 if (sign_present && sattr.sat_linehl > 0)
1172 {
1173 if (sattr.sat_priority >= 100)
1174 line_attr = hl_combine_attr(cul_attr, line_attr);
1175 else
1176 line_attr = hl_combine_attr(line_attr, cul_attr);
1177 }
1178 else
1179# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001180# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001181 // let the line attribute overrule 'cursorline', otherwise
1182 // it disappears when both have background set;
1183 // 'cursorline' can use underline or bold to make it show
1184 line_attr = hl_combine_attr(cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001185# else
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001186 line_attr = cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001187# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001188 }
1189 else
1190 {
1191 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001192 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1193 }
1194 area_highlighting = TRUE;
1195 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001196 }
1197#endif
1198
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001199#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001200 {
1201 char_u *prop_start;
1202
1203 text_prop_count = get_text_props(wp->w_buffer, lnum,
1204 &prop_start, FALSE);
1205 if (text_prop_count > 0)
1206 {
1207 // Make a copy of the properties, so that they are properly
1208 // aligned.
1209 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1210 if (text_props != NULL)
1211 mch_memmove(text_props, prop_start,
1212 text_prop_count * sizeof(textprop_T));
1213
1214 // Allocate an array for the indexes.
1215 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1216 area_highlighting = TRUE;
1217 extra_check = TRUE;
1218 }
1219 }
1220#endif
1221
Bram Moolenaar1306b362022-08-06 15:59:06 +01001222 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001223
1224 // Repeat for the whole displayed line.
1225 for (;;)
1226 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001227 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001228#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001229 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001230#endif
1231#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001232 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001233#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001234
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001235 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001236 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001237 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001238#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001239 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001240 {
1241 cul_attr = 0;
1242 line_attr = line_attr_save;
1243 }
1244#endif
1245
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001246#ifdef FEAT_CMDWIN
Bram Moolenaar1306b362022-08-06 15:59:06 +01001247 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001248 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001249 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001250 if (cmdwin_type != 0 && wp == curwin)
1251 {
1252 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001253 wlv.n_extra = 1;
1254 wlv.c_extra = cmdwin_type;
1255 wlv.c_final = NUL;
1256 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001257 }
1258 }
1259#endif
1260
1261#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001262 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001263 {
1264 int fdc = compute_foldcolumn(wp, 0);
1265
Bram Moolenaar1306b362022-08-06 15:59:06 +01001266 wlv.draw_state = WL_FOLD;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001267 if (fdc > 0)
1268 {
1269 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1270 // already be in use.
1271 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001272 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001273 if (p_extra_free != NULL)
1274 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001275 wlv.n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001276 FALSE, lnum);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001277 p_extra_free[wlv.n_extra] = NUL;
1278 wlv.p_extra = p_extra_free;
1279 wlv.c_extra = NUL;
1280 wlv.c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001281 if (use_cursor_line_sign(wp, lnum))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001282 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001283 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1284 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001285 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001286 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001287 }
1288 }
1289 }
1290#endif
1291
1292#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001293 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001294 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001295 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001296 // Show the sign column when there are any signs in this
1297 // buffer or when using Netbeans.
1298 if (signcolumn_on(wp))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001299 get_sign_display_info(FALSE, wp, lnum, &wlv, &sattr,
1300 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001301 }
1302#endif
1303
Bram Moolenaar1306b362022-08-06 15:59:06 +01001304 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001305 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001306 wlv.draw_state = WL_NR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001307 // Display the absolute or relative line number. After the
1308 // first fill with blanks when the 'n' flag isn't in 'cpo'
1309 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001310 && (wlv.row == startrow + filler_lines
1311 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001312 {
1313#ifdef FEAT_SIGNS
1314 // If 'signcolumn' is set to 'number' and a sign is present
1315 // in 'lnum', then display the sign instead of the line
1316 // number.
1317 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1318 && sign_present)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001319 get_sign_display_info(TRUE, wp, lnum, &wlv, &sattr,
1320 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001321 else
1322#endif
1323 {
1324 // Draw the line number (empty space after wrapping).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001325 if (wlv.row == startrow + filler_lines)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001326 {
1327 long num;
1328 char *fmt = "%*ld ";
1329
1330 if (wp->w_p_nu && !wp->w_p_rnu)
1331 // 'number' + 'norelativenumber'
1332 num = (long)lnum;
1333 else
1334 {
1335 // 'relativenumber', don't use negative numbers
1336 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1337 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1338 {
1339 // 'number' + 'relativenumber'
1340 num = lnum;
1341 fmt = "%-*ld ";
1342 }
1343 }
1344
1345 sprintf((char *)extra, fmt,
1346 number_width(wp), num);
1347 if (wp->w_skipcol > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001348 for (wlv.p_extra = extra; *wlv.p_extra == ' ';
1349 ++wlv.p_extra)
1350 *wlv.p_extra = '-';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001351#ifdef FEAT_RIGHTLEFT
1352 if (wp->w_p_rl) // reverse line numbers
1353 {
1354 char_u *p1, *p2;
1355 int t;
1356
1357 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001358 p2 = skipwhite(extra);
1359 p2 = skiptowhite(p2) - 1;
1360 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001361 {
1362 t = *p1;
1363 *p1 = *p2;
1364 *p2 = t;
1365 }
1366 }
1367#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001368 wlv.p_extra = extra;
1369 wlv.c_extra = NUL;
1370 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001371 }
1372 else
1373 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001374 wlv.c_extra = ' ';
1375 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001376 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001377 wlv.n_extra = number_width(wp) + 1;
1378 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001379#ifdef FEAT_SYN_HL
1380 // When 'cursorline' is set highlight the line number of
1381 // the current line differently.
zeertzjq754d2b42022-03-13 13:40:45 +00001382 // When 'cursorlineopt' does not have "line" only
1383 // highlight the line number itself.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001384 // TODO: Can we use CursorLine instead of CursorLineNr
1385 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001386 if (wp->w_p_cul
1387 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001388 && (wp->w_p_culopt_flags & CULOPT_NBR)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001389 && (wlv.row == startrow + filler_lines
1390 || (wlv.row > startrow + filler_lines
zeertzjq754d2b42022-03-13 13:40:45 +00001391 && (wp->w_p_culopt_flags & CULOPT_LINE))))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001392 wlv.char_attr = hl_combine_attr(wcr_attr,
1393 HL_ATTR(HLF_CLN));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001394#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001395 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1396 && HL_ATTR(HLF_LNA) != 0)
1397 // Use LineNrAbove
Bram Moolenaar1306b362022-08-06 15:59:06 +01001398 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001399 HL_ATTR(HLF_LNA));
1400 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1401 && HL_ATTR(HLF_LNB) != 0)
1402 // Use LineNrBelow
Bram Moolenaar1306b362022-08-06 15:59:06 +01001403 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001404 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001405 }
James McCoya80aad72021-12-22 19:45:28 +00001406#ifdef FEAT_SIGNS
1407 if (num_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001408 wlv.char_attr = num_attr;
James McCoya80aad72021-12-22 19:45:28 +00001409#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001410 }
1411 }
1412
1413#ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001414 if (wp->w_briopt_sbr && wlv.draw_state == WL_BRI - 1
1415 && wlv.n_extra == 0
1416 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001417 // draw indent after showbreak value
Bram Moolenaar1306b362022-08-06 15:59:06 +01001418 wlv.draw_state = WL_BRI;
1419 else if (wp->w_briopt_sbr && wlv.draw_state == WL_SBR
1420 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001421 // After the showbreak, draw the breakindent
Bram Moolenaar1306b362022-08-06 15:59:06 +01001422 wlv.draw_state = WL_BRI - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001423
1424 // draw 'breakindent': indent wrapped text accordingly
Bram Moolenaar1306b362022-08-06 15:59:06 +01001425 if (wlv.draw_state == WL_BRI - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001426 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001427 wlv.draw_state = WL_BRI;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001428 // if need_showbreak is set, breakindent also applies
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001429 if (wp->w_p_bri && (wlv.row != startrow || need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001430# ifdef FEAT_DIFF
1431 && filler_lines == 0
1432# endif
Bram Moolenaar73c38422022-08-07 11:53:40 +01001433# ifdef FEAT_PROP_POPUP
1434 && !dont_use_showbreak
1435# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001436 )
1437 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001438 wlv.char_attr = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001439# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01001440 if (wlv.diff_hlf != (hlf_T)0)
1441 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001442# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001443 wlv.p_extra = NULL;
1444 wlv.c_extra = ' ';
1445 wlv.c_final = NUL;
1446 wlv.n_extra = get_breakindent_win(wp,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001447 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001448 if (wlv.row == startrow)
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001449 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001450 wlv.n_extra -= win_col_off2(wp);
1451 if (wlv.n_extra < 0)
1452 wlv.n_extra = 0;
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001453 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001454 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001455 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001456 // Correct end of highlighted area for 'breakindent',
1457 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001458 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001459 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001460 }
1461 }
1462#endif
1463
1464#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001465 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001466 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001467 char_u *sbr;
1468
Bram Moolenaar1306b362022-08-06 15:59:06 +01001469 wlv.draw_state = WL_SBR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001470# ifdef FEAT_DIFF
1471 if (filler_todo > 0)
1472 {
1473 // Draw "deleted" diff line(s).
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001474 if (char2cells(wp->w_fill_chars.diff) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001475 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001476 wlv.c_extra = '-';
1477 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001478 }
1479 else
1480 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001481 wlv.c_extra = wp->w_fill_chars.diff;
1482 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001483 }
1484# ifdef FEAT_RIGHTLEFT
1485 if (wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001486 wlv.n_extra = wlv.col + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001487 else
1488# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001489 wlv.n_extra = wp->w_width - wlv.col;
1490 wlv.char_attr = HL_ATTR(HLF_DED);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001491 }
1492# endif
1493# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001494 sbr = get_showbreak_value(wp);
1495 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001496 {
1497 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001498 wlv.p_extra = sbr;
1499 wlv.c_extra = NUL;
1500 wlv.c_final = NUL;
1501 wlv.n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001502 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1503 need_showbreak = FALSE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001504 vcol_sbr = wlv.vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001505 // Correct end of highlighted area for 'showbreak',
1506 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001507 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001508 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001509 // combine 'showbreak' with 'wincolor'
Bram Moolenaar1306b362022-08-06 15:59:06 +01001510 wlv.char_attr = hl_combine_attr(wlv.win_attr,
1511 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001512# ifdef FEAT_SYN_HL
1513 // combine 'showbreak' with 'cursorline'
1514 if (cul_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001515 wlv.char_attr = hl_combine_attr(wlv.char_attr,
1516 cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001517# endif
1518 }
1519# endif
1520 }
1521#endif
1522
Bram Moolenaar1306b362022-08-06 15:59:06 +01001523 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001524 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001525 wlv.draw_state = WL_LINE;
1526 if (wlv.saved_n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001527 {
1528 // Continue item from end of wrapped line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001529 wlv.n_extra = wlv.saved_n_extra;
1530 wlv.c_extra = wlv.saved_c_extra;
1531 wlv.c_final = wlv.saved_c_final;
1532 wlv.p_extra = wlv.saved_p_extra;
1533 wlv.char_attr = wlv.saved_char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001534 }
1535 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001536 wlv.char_attr = wlv.win_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001537 }
1538 }
1539#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001540 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001541 && wlv.vcol >= left_curline_col
1542 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001543 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001544 cul_attr = HL_ATTR(HLF_CUL);
1545 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001546 }
1547#endif
1548
1549 // When still displaying '$' of change command, stop at cursor.
1550 // When only displaying the (relative) line number and that's done,
1551 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001552 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001553 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001554 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001555#ifdef FEAT_DIFF
1556 && filler_todo <= 0
1557#endif
1558 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001559 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001560 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col, -wp->w_width,
1561 wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001562 // Pretend we have finished updating the window. Except when
1563 // 'cursorcolumn' is set.
1564#ifdef FEAT_SYN_HL
1565 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001566 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001567 else
1568#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001569 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001570 break;
1571 }
1572
Bram Moolenaar1306b362022-08-06 15:59:06 +01001573 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001574 {
1575 // handle Visual or match highlighting in this line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001576 if (wlv.vcol == fromcol
Bram Moolenaar1306b362022-08-06 15:59:06 +01001577 || (has_mbyte && wlv.vcol + 1 == fromcol && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001578 && (*mb_ptr2cells)(ptr) > 1)
1579 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001580 && vcol_prev < wlv.vcol // not at margin
1581 && wlv.vcol < tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001582 area_attr = vi_attr; // start highlighting
1583 else if (area_attr != 0
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001584 && (wlv.vcol == tocol
1585 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001586 area_attr = 0; // stop highlighting
1587
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001588#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001589 if (text_props != NULL)
1590 {
1591 int pi;
1592 int bcol = (int)(ptr - line);
1593
Bram Moolenaar1306b362022-08-06 15:59:06 +01001594 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001595# ifdef FEAT_LINEBREAK
1596 && !in_linebreak
1597# endif
1598 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001599 --bcol; // still working on the previous char, e.g. Tab
1600
1601 // Check if any active property ends.
1602 for (pi = 0; pi < text_props_active; ++pi)
1603 {
1604 int tpi = text_prop_idxs[pi];
1605
1606 if (bcol >= text_props[tpi].tp_col - 1
1607 + text_props[tpi].tp_len)
1608 {
1609 if (pi + 1 < text_props_active)
1610 mch_memmove(text_prop_idxs + pi,
1611 text_prop_idxs + pi + 1,
1612 sizeof(int)
1613 * (text_props_active - (pi + 1)));
1614 --text_props_active;
1615 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001616# ifdef FEAT_LINEBREAK
1617 // not exactly right but should work in most cases
1618 if (in_linebreak && syntax_attr == text_prop_attr)
1619 syntax_attr = 0;
1620# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001621 }
1622 }
1623
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001624# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001625 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001626 // not on the next char yet, don't start another prop
1627 --bcol;
1628# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001629 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001630 // With 'nowrap' and not in the first screen line only "below"
1631 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001632 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001633 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001634 ? (*ptr == NUL
1635 && (wp->w_p_wrap
1636 || wlv.row == startrow
1637 || (text_props[text_prop_next].tp_flags
1638 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001639 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001640 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001641 if (text_props[text_prop_next].tp_col == MAXCOL
1642 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001643 + text_props[text_prop_next].tp_len)
1644 text_prop_idxs[text_props_active++] = text_prop_next;
1645 ++text_prop_next;
1646 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001647
1648 text_prop_attr = 0;
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001649 text_prop_flags = 0;
Bram Moolenaar053f7122019-09-23 22:17:15 +02001650 text_prop_type = NULL;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001651 text_prop_id = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001652 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001653 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001654 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001655 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001656 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001657
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001658 // Sort the properties on priority and/or starting last.
1659 // Then combine the attributes, highest priority last.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001660 text_prop_follows = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001661 current_text_props = text_props;
1662 current_buf = wp->w_buffer;
1663 qsort((void *)text_prop_idxs, (size_t)text_props_active,
1664 sizeof(int), text_prop_compare);
1665
1666 for (pi = 0; pi < text_props_active; ++pi)
1667 {
1668 int tpi = text_prop_idxs[pi];
1669 proptype_T *pt = text_prop_type_by_id(
1670 wp->w_buffer, text_props[tpi].tp_type);
1671
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001672 if (pt != NULL && (pt->pt_hl_id > 0
1673 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001674 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001675 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001676 if (pt->pt_hl_id > 0)
1677 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001678 text_prop_type = pt;
1679 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001680 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001681 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001682 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001683 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001684 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001685 }
1686 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001687 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001688 && -text_prop_id
1689 <= wp->w_buffer->b_textprop_text.ga_len)
1690 {
1691 char_u *p = ((char_u **)wp->w_buffer
1692 ->b_textprop_text.ga_data)[
1693 -text_prop_id - 1];
Bram Moolenaar1306b362022-08-06 15:59:06 +01001694
1695 // reset the ID in the copy to avoid it being used
1696 // again
1697 text_props[used_tpi].tp_id = -MAXCOL;
1698
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001699 if (p != NULL)
1700 {
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001701 int right = (text_props[used_tpi].tp_flags
1702 & TP_FLAG_ALIGN_RIGHT);
1703 int below = (text_props[used_tpi].tp_flags
1704 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaar398649e2022-08-04 15:03:48 +01001705 int wrap = (text_props[used_tpi].tp_flags
1706 & TP_FLAG_WRAP);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001707
Bram Moolenaar1306b362022-08-06 15:59:06 +01001708 wlv.p_extra = p;
1709 wlv.c_extra = NUL;
1710 wlv.c_final = NUL;
1711 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001712 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001713 n_attr = mb_charlen(p);
Bram Moolenaare38fc862022-08-11 17:24:50 +01001714 saved_search_attr = search_attr;
1715 search_attr = 0; // restore when n_extra is zero
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001716 text_prop_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001717 if (*ptr == NUL)
1718 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001719 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001720#ifdef FEAT_LINEBREAK
Bram Moolenaarcba69522022-08-06 21:03:53 +01001721 if (below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001722 {
1723 // no 'showbreak' before "below" text property
1724 // or after "right" text property
1725 need_showbreak = FALSE;
1726 dont_use_showbreak = TRUE;
1727 }
1728#endif
Bram Moolenaar398649e2022-08-04 15:03:48 +01001729 // Keep in sync with where
1730 // textprop_size_after_trunc() is called in
1731 // win_lbr_chartabsize().
1732 if ((right || below || !wrap) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001733 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001734 int added = wp->w_width - wlv.col;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001735 int n_used = wlv.n_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001736 char_u *l;
Bram Moolenaar398649e2022-08-04 15:03:48 +01001737 int strsize = wrap
Bram Moolenaar1306b362022-08-06 15:59:06 +01001738 ? vim_strsize(wlv.p_extra)
1739 : textprop_size_after_trunc(wp,
1740 below, added, wlv.p_extra, &n_used);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001741
Bram Moolenaar1306b362022-08-06 15:59:06 +01001742 if (wrap || right || below
1743 || n_used < wlv.n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001744 {
Bram Moolenaar398649e2022-08-04 15:03:48 +01001745 // Right-align: fill with spaces
1746 if (right)
1747 added -= strsize;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001748 if (added < 0
1749 || (below
1750 ? wlv.col == 0 || !wp->w_p_wrap
Bram Moolenaar1306b362022-08-06 15:59:06 +01001751 : n_used < wlv.n_extra))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001752 added = 0;
1753 // add 1 for NUL, 2 for when '…' is used
1754 l = alloc(n_used + added + 3);
1755 if (l != NULL)
1756 {
1757 vim_memset(l, ' ', added);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001758 vim_strncpy(l + added, wlv.p_extra,
1759 n_used);
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001760 if (n_used < wlv.n_extra
1761 && wp->w_p_wrap)
Bram Moolenaar398649e2022-08-04 15:03:48 +01001762 {
1763 char_u *lp = l + added + n_used - 1;
1764
1765 if (has_mbyte)
1766 {
1767 // change last character to '…'
1768 lp -= (*mb_head_off)(l, lp);
1769 STRCPY(lp, "…");
1770 n_used = lp - l + 3;
1771 }
1772 else
1773 // change last character to '>'
1774 *lp = '>';
1775 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001776 vim_free(p_extra_free2);
1777 wlv.p_extra = p_extra_free2 = l;
1778 wlv.n_extra = n_used + added;
Bram Moolenaar398649e2022-08-04 15:03:48 +01001779 n_attr_skip = added;
Bram Moolenaar1d8844a2022-08-10 13:39:35 +01001780 n_attr = mb_charlen(wlv.p_extra);
Bram Moolenaar398649e2022-08-04 15:03:48 +01001781 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001782 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001783
1784 // When 'wrap' is off then for "below" we need
1785 // to start a new line explictly.
Bram Moolenaardb9b96d2022-08-06 17:38:53 +01001786 if (below && wlv.col > win_col_off(wp)
1787 && !wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001788 {
1789 draw_screen_line(wp, &wlv);
1790
1791 // When line got too long for screen break
1792 // here.
1793 if (wlv.row == endrow)
1794 {
1795 ++wlv.row;
1796 break;
1797 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001798 win_line_start(wp, &wlv, TRUE);
1799 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001800 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001801 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001802 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001803
1804 // If another text prop follows the condition below at
1805 // the last window column must know.
1806 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001807 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001808 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001809 else if (text_prop_next < text_prop_count
1810 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001811 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
1812 || (!wp->w_p_wrap
1813 && wlv.col == wp->w_width - 1
1814 && (text_props[text_prop_next].tp_flags
1815 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001816 // When at last-but-one character and a text property
1817 // follows after it, we may need to flush the line after
1818 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001819 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01001820 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001821 }
1822#endif
1823
Bram Moolenaare38fc862022-08-11 17:24:50 +01001824#ifdef FEAT_SEARCH_EXTRA
1825 if (wlv.n_extra == 0)
1826 {
1827 // Check for start/end of 'hlsearch' and other matches.
1828 // After end, check for start/end of next match.
1829 // When another match, have to check for start again.
1830 v = (long)(ptr - line);
1831 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1832 &screen_search_hl, &has_match_conc,
1833 &match_conc, did_line_attr, lcs_eol_one,
1834 &on_last_col);
1835 ptr = line + v; // "line" may have been changed
1836 prev_ptr = ptr;
1837
1838 // Do not allow a conceal over EOL otherwise EOL will be missed
1839 // and bad things happen.
1840 if (*ptr == NUL)
1841 has_match_conc = 0;
1842 }
1843#endif
1844
1845#ifdef FEAT_DIFF
1846 if (wlv.diff_hlf != (hlf_T)0)
1847 {
1848 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
1849 && wlv.n_extra == 0)
1850 wlv.diff_hlf = HLF_TXD; // changed text
1851 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
1852 && wlv.n_extra == 0)
1853 wlv.diff_hlf = HLF_CHD; // changed line
1854 line_attr = HL_ATTR(wlv.diff_hlf);
1855 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1856 && wp->w_p_culopt_flags != CULOPT_NBR
1857 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
1858 && wlv.vcol <= right_curline_col)))
1859 line_attr = hl_combine_attr(
1860 line_attr, HL_ATTR(HLF_CUL));
1861 }
1862#endif
1863
Bram Moolenaara74fda62019-10-19 17:38:03 +02001864#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001865 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001866 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001867 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001868# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001869 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001870 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001871# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001872 // Get syntax attribute.
1873 if (has_syntax)
1874 {
1875 // Get the syntax attribute for the character. If there
1876 // is an error, disable syntax highlighting.
1877 save_did_emsg = did_emsg;
1878 did_emsg = FALSE;
1879
1880 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001881 if (v == prev_syntax_col)
1882 // at same column again
1883 syntax_attr = prev_syntax_attr;
1884 else
1885 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001886# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001887 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001888# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001889 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001890# ifdef FEAT_SPELL
1891 has_spell ? &can_spell :
1892# endif
1893 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001894 prev_syntax_col = v;
1895 prev_syntax_attr = syntax_attr;
1896 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001897
Bram Moolenaar34390282019-10-16 14:38:26 +02001898 if (did_emsg)
1899 {
1900 wp->w_s->b_syn_error = TRUE;
1901 has_syntax = FALSE;
1902 syntax_attr = 0;
1903 }
1904 else
1905 did_emsg = save_did_emsg;
1906# ifdef SYN_TIME_LIMIT
1907 if (wp->w_s->b_syn_slow)
1908 has_syntax = FALSE;
1909# endif
1910
1911 // Need to get the line again, a multi-line regexp may
1912 // have made it invalid.
1913 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1914 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001915 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001916# ifdef FEAT_CONCEAL
1917 // no concealing past the end of the line, it interferes
1918 // with line highlighting
1919 if (*ptr == NUL)
1920 syntax_flags = 0;
1921 else
1922 syntax_flags = get_syntax_info(&syntax_seqnr);
1923# endif
1924 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001925 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001926# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001927 // Combine text property highlight into syntax highlight.
1928 if (text_prop_type != NULL)
1929 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001930 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01001931 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1932 else
1933 syntax_attr = text_prop_attr;
1934 }
1935# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001936#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001937
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001938 // Decide which of the highlight attributes to use.
1939 attr_pri = TRUE;
1940#ifdef LINE_ATTR
1941 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001942 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001943 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02001944 if (!highlight_match)
1945 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01001946 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001947# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001948 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001949# endif
1950 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001951 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001952 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001953 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001954# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001955 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001956# endif
1957 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001958 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001959 || wlv.vcol < fromcol || vcol_prev < fromcol_prev
1960 || wlv.vcol >= tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001961 {
1962 // Use line_attr when not in the Visual or 'incsearch' area
1963 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001964# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001965 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01001966# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001967 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001968# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001969 attr_pri = FALSE;
1970 }
1971#else
1972 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001973 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001974 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001975 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001976#endif
1977 else
1978 {
1979 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001980#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001981 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001982#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001983 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001984#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001985 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001986#ifdef FEAT_PROP_POPUP
1987 // override with text property highlight when "override" is TRUE
1988 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001989 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001990#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001991 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001992
1993 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001994 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001995 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001996 if (wlv.char_attr == 0)
1997 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001998 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001999 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002000 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002001
2002 // Get the next character to put on the screen.
2003
2004 // The "p_extra" points to the extra stuff that is inserted to
2005 // represent special characters (non-printable stuff) and other
2006 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002007 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002008 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2009 // "p_extra[n_extra]".
2010 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002011 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002012 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002013 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002014 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002015 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2016 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002017 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2018 if (enc_utf8 && utf_char2len(c) > 1)
2019 {
2020 mb_utf8 = TRUE;
2021 u8cc[0] = 0;
2022 c = 0xc0;
2023 }
2024 else
2025 mb_utf8 = FALSE;
2026 }
2027 else
2028 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002029 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002030 if (has_mbyte)
2031 {
2032 mb_c = c;
2033 if (enc_utf8)
2034 {
2035 // If the UTF-8 character is more than one byte:
2036 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002037 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002038 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002039 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002040 mb_l = 1;
2041 else if (mb_l > 1)
2042 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002043 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002044 mb_utf8 = TRUE;
2045 c = 0xc0;
2046 }
2047 }
2048 else
2049 {
2050 // if this is a DBCS character, put it in "mb_c"
2051 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002052 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002053 mb_l = 1;
2054 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002055 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002056 }
2057 if (mb_l == 0) // at the NUL at end-of-line
2058 mb_l = 1;
2059
2060 // If a double-width char doesn't fit display a '>' in the
2061 // last column.
2062 if ((
2063# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002064 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002065# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002066 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002067 && (*mb_char2cells)(mb_c) == 2)
2068 {
2069 c = '>';
2070 mb_c = c;
2071 mb_l = 1;
2072 mb_utf8 = FALSE;
2073 multi_attr = HL_ATTR(HLF_AT);
2074#ifdef FEAT_SYN_HL
2075 if (cul_attr)
2076 multi_attr = hl_combine_attr(multi_attr, cul_attr);
2077#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002078 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002079
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002080 // put the pointer back to output the double-width
2081 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002082 ++wlv.n_extra;
2083 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002084 }
2085 else
2086 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002087 wlv.n_extra -= mb_l - 1;
2088 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002089 }
2090 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002091 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002092 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002093 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002094#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002095 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002096 {
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002097 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002098 if (search_attr == 0)
2099 search_attr = saved_search_attr;
2100 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002101#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002102 }
2103 else
2104 {
2105#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002106 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002107#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002108 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002109
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002110 // Get a character from the line itself.
2111 c = *ptr;
2112#ifdef FEAT_LINEBREAK
2113 c0 = *ptr;
2114#endif
2115 if (has_mbyte)
2116 {
2117 mb_c = c;
2118 if (enc_utf8)
2119 {
2120 // If the UTF-8 character is more than one byte: Decode it
2121 // into "mb_c".
2122 mb_l = utfc_ptr2len(ptr);
2123 mb_utf8 = FALSE;
2124 if (mb_l > 1)
2125 {
2126 mb_c = utfc_ptr2char(ptr, u8cc);
2127 // Overlong encoded ASCII or ASCII with composing char
2128 // is displayed normally, except a NUL.
2129 if (mb_c < 0x80)
2130 {
2131 c = mb_c;
2132#ifdef FEAT_LINEBREAK
2133 c0 = mb_c;
2134#endif
2135 }
2136 mb_utf8 = TRUE;
2137
2138 // At start of the line we can have a composing char.
2139 // Draw it as a space with a composing char.
2140 if (utf_iscomposing(mb_c))
2141 {
2142 int i;
2143
2144 for (i = Screen_mco - 1; i > 0; --i)
2145 u8cc[i] = u8cc[i - 1];
2146 u8cc[0] = mb_c;
2147 mb_c = ' ';
2148 }
2149 }
2150
2151 if ((mb_l == 1 && c >= 0x80)
2152 || (mb_l >= 1 && mb_c == 0)
2153 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2154 {
2155 // Illegal UTF-8 byte: display as <xx>.
2156 // Non-BMP character : display as ? or fullwidth ?.
2157 transchar_hex(extra, mb_c);
2158# ifdef FEAT_RIGHTLEFT
2159 if (wp->w_p_rl) // reverse
2160 rl_mirror(extra);
2161# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002162 wlv.p_extra = extra;
2163 c = *wlv.p_extra;
2164 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002165 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002166 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2167 wlv.c_extra = NUL;
2168 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002169 if (area_attr == 0 && search_attr == 0)
2170 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002171 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002172 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002173 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002174 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002175 }
2176 }
2177 else if (mb_l == 0) // at the NUL at end-of-line
2178 mb_l = 1;
2179#ifdef FEAT_ARABIC
2180 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2181 {
2182 // Do Arabic shaping.
2183 int pc, pc1, nc;
2184 int pcc[MAX_MCO];
2185
2186 // The idea of what is the previous and next
2187 // character depends on 'rightleft'.
2188 if (wp->w_p_rl)
2189 {
2190 pc = prev_c;
2191 pc1 = prev_c1;
2192 nc = utf_ptr2char(ptr + mb_l);
2193 prev_c1 = u8cc[0];
2194 }
2195 else
2196 {
2197 pc = utfc_ptr2char(ptr + mb_l, pcc);
2198 nc = prev_c;
2199 pc1 = pcc[0];
2200 }
2201 prev_c = mb_c;
2202
2203 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2204 }
2205 else
2206 prev_c = mb_c;
2207#endif
2208 }
2209 else // enc_dbcs
2210 {
2211 mb_l = MB_BYTE2LEN(c);
2212 if (mb_l == 0) // at the NUL at end-of-line
2213 mb_l = 1;
2214 else if (mb_l > 1)
2215 {
2216 // We assume a second byte below 32 is illegal.
2217 // Hopefully this is OK for all double-byte encodings!
2218 if (ptr[1] >= 32)
2219 mb_c = (c << 8) + ptr[1];
2220 else
2221 {
2222 if (ptr[1] == NUL)
2223 {
2224 // head byte at end of line
2225 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002226 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002227 }
2228 else
2229 {
2230 // illegal tail byte
2231 mb_l = 2;
2232 STRCPY(extra, "XX");
2233 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002234 wlv.p_extra = extra;
2235 wlv.n_extra = (int)STRLEN(extra) - 1;
2236 wlv.c_extra = NUL;
2237 wlv.c_final = NUL;
2238 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002239 if (area_attr == 0 && search_attr == 0)
2240 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002241 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002242 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002243 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002244 // save current attr
2245 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002246 }
2247 mb_c = c;
2248 }
2249 }
2250 }
2251 // If a double-width char doesn't fit display a '>' in the
2252 // last column; the character is displayed at the start of the
2253 // next line.
2254 if ((
2255# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002256 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002257# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002258 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002259 && (*mb_char2cells)(mb_c) == 2)
2260 {
2261 c = '>';
2262 mb_c = c;
2263 mb_utf8 = FALSE;
2264 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002265 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002266 // Put pointer back so that the character will be
2267 // displayed at the start of the next line.
2268 --ptr;
2269#ifdef FEAT_CONCEAL
2270 did_decrement_ptr = TRUE;
2271#endif
2272 }
2273 else if (*ptr != NUL)
2274 ptr += mb_l - 1;
2275
2276 // If a double-width char doesn't fit at the left side display
2277 // a '<' in the first column. Don't do this for unprintable
2278 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002279 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002280 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002281 wlv.n_extra = 1;
2282 wlv.c_extra = MB_FILLER_CHAR;
2283 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002284 c = ' ';
2285 if (area_attr == 0 && search_attr == 0)
2286 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002287 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002288 extra_attr = hl_combine_attr(
2289 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002290 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002291 }
2292 mb_c = c;
2293 mb_utf8 = FALSE;
2294 mb_l = 1;
2295 }
2296
2297 }
2298 ++ptr;
2299
2300 if (extra_check)
2301 {
2302#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002303 // Check spelling (unless at the end of the line).
2304 // Only do this when there is no syntax highlighting, the
2305 // @Spell cluster is not used or the current syntax item
2306 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002307 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002308 if (has_spell && v >= word_end && v > cur_checked_col)
2309 {
2310 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002311 // do not calculate cap_col at the end of the line or when
2312 // only white space is following
2313 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002314# ifdef FEAT_SYN_HL
2315 !has_syntax ||
2316# endif
2317 can_spell))
2318 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002319 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002320 int len;
2321 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002322
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002323 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002324 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002325
2326 // Use nextline[] if possible, it has the start of the
2327 // next line concatenated.
2328 if ((prev_ptr - line) - nextlinecol >= 0)
2329 p = nextline + (prev_ptr - line) - nextlinecol;
2330 else
2331 p = prev_ptr;
2332 cap_col -= (int)(prev_ptr - line);
2333 len = spell_check(wp, p, &spell_hlf, &cap_col,
2334 nochange);
2335 word_end = v + len;
2336
2337 // In Insert mode only highlight a word that
2338 // doesn't touch the cursor.
2339 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002340 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002341 && wp->w_cursor.lnum == lnum
2342 && wp->w_cursor.col >=
2343 (colnr_T)(prev_ptr - line)
2344 && wp->w_cursor.col < (colnr_T)word_end)
2345 {
2346 spell_hlf = HLF_COUNT;
2347 spell_redraw_lnum = lnum;
2348 }
2349
2350 if (spell_hlf == HLF_COUNT && p != prev_ptr
2351 && (p - nextline) + len > nextline_idx)
2352 {
2353 // Remember that the good word continues at the
2354 // start of the next line.
2355 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002356 checked_col = (int)((p - nextline)
2357 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002358 }
2359
2360 // Turn index into actual attributes.
2361 if (spell_hlf != HLF_COUNT)
2362 spell_attr = highlight_attr[spell_hlf];
2363
2364 if (cap_col > 0)
2365 {
2366 if (p != prev_ptr
2367 && (p - nextline) + cap_col >= nextline_idx)
2368 {
2369 // Remember that the word in the next line
2370 // must start with a capital.
2371 capcol_lnum = lnum + 1;
2372 cap_col = (int)((p - nextline) + cap_col
2373 - nextline_idx);
2374 }
2375 else
2376 // Compute the actual column.
2377 cap_col += (int)(prev_ptr - line);
2378 }
2379 }
2380 }
2381 if (spell_attr != 0)
2382 {
2383 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002384 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2385 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002386 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002387 wlv.char_attr = hl_combine_attr(spell_attr,
2388 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002389 }
2390#endif
2391#ifdef FEAT_LINEBREAK
2392 // Found last space before word: check for line break.
2393 if (wp->w_p_lbr && c0 == c
2394 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2395 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002396 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2397 : 0;
2398 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002399 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002400
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002401 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002402# ifdef FEAT_PROP_POPUP
2403 // do not want virtual text counted here
2404 cts.cts_has_prop_with_text = FALSE;
2405# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002406 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002407 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002408
2409 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002410 // space for it again.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002411 if (wlv.vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002412 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002413 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2414 if (wlv.n_extra < 0)
2415 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002416 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002417 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002418 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002419 // line break, but for TABs the highlighting should
2420 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002421 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002422
Bram Moolenaar1306b362022-08-06 15:59:06 +01002423 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002424# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002425 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002426 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002427 wp->w_buffer->b_p_vts_array) - 1;
2428# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002429 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002430 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002431# endif
2432
Bram Moolenaar1306b362022-08-06 15:59:06 +01002433 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2434 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002435# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002436 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002437 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002438# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002439 if (VIM_ISWHITE(c))
2440 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002441# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002442 if (c == TAB)
2443 // See "Tab alignment" below.
2444 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002445# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002446 if (!wp->w_p_list)
2447 c = ' ';
2448 }
2449 }
2450#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002451 in_multispace = c == ' '
2452 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2453 if (!in_multispace)
2454 multispace_pos = 0;
2455
Bram Moolenaareed9d462021-02-15 20:38:25 +01002456 // 'list': Change char 160 to 'nbsp' and space to 'space'
2457 // setting in 'listchars'. But not when the character is
2458 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002459 if (wp->w_p_list
2460 && ((((c == 160 && mb_l == 1)
2461 || (mb_utf8
2462 && ((mb_c == 160 && mb_l == 2)
2463 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002464 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002465 || (c == ' '
2466 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002467 && (wp->w_lcs_chars.space
2468 || (in_multispace
2469 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002470 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002471 && ptr - line <= trailcol)))
2472 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002473 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2474 {
2475 c = wp->w_lcs_chars.multispace[multispace_pos++];
2476 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2477 multispace_pos = 0;
2478 }
2479 else
2480 c = (c == ' ') ? wp->w_lcs_chars.space
2481 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002482 if (area_attr == 0 && search_attr == 0)
2483 {
2484 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002485 extra_attr = hl_combine_attr(wlv.win_attr,
2486 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002487 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002488 }
2489 mb_c = c;
2490 if (enc_utf8 && utf_char2len(c) > 1)
2491 {
2492 mb_utf8 = TRUE;
2493 u8cc[0] = 0;
2494 c = 0xc0;
2495 }
2496 else
2497 mb_utf8 = FALSE;
2498 }
2499
zeertzjq2e7cba32022-06-10 15:30:32 +01002500 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2501 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002502 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002503 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2504 && wp->w_lcs_chars.leadmultispace != NULL)
2505 {
2506 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002507 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2508 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002509 multispace_pos = 0;
2510 }
2511
2512 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2513 c = wp->w_lcs_chars.trail;
2514
2515 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2516 c = wp->w_lcs_chars.lead;
2517
zeertzjq2e7cba32022-06-10 15:30:32 +01002518 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002519 c = wp->w_lcs_chars.space;
2520
2521
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002522 if (!attr_pri)
2523 {
2524 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002525 extra_attr = hl_combine_attr(wlv.win_attr,
2526 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002527 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002528 }
2529 mb_c = c;
2530 if (enc_utf8 && utf_char2len(c) > 1)
2531 {
2532 mb_utf8 = TRUE;
2533 u8cc[0] = 0;
2534 c = 0xc0;
2535 }
2536 else
2537 mb_utf8 = FALSE;
2538 }
2539 }
2540
2541 // Handling of non-printable characters.
2542 if (!vim_isprintc(c))
2543 {
2544 // when getting a character from the file, we may have to
2545 // turn it into something else on the way to putting it
2546 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002547 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002548 {
2549 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002550 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002551#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002552 char_u *sbr = get_showbreak_value(wp);
2553
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002554 // only adjust the tab_len, when at the first column
2555 // after the showbreak value was drawn
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002556 if (*sbr != NUL && wlv.vcol == vcol_sbr && wp->w_p_wrap)
2557 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002558#endif
2559 // tab amount depends on current column
2560#ifdef FEAT_VARTABS
2561 tab_len = tabstop_padding(vcol_adjusted,
2562 wp->w_buffer->b_p_ts,
2563 wp->w_buffer->b_p_vts_array) - 1;
2564#else
2565 tab_len = (int)wp->w_buffer->b_p_ts
2566 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2567#endif
2568
2569#ifdef FEAT_LINEBREAK
2570 if (!wp->w_p_lbr || !wp->w_p_list)
2571#endif
2572 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002573 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002574#ifdef FEAT_LINEBREAK
2575 else
2576 {
2577 char_u *p;
2578 int len;
2579 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002580 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002581
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002582# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002583 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002584 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002585 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002586
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002587 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002588 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002589 && old_boguscols > 0
2590 && wlv.n_extra > tab_len)
2591 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002592# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002593 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002594 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002595 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002596 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002597 if (wp->w_lcs_chars.tab3)
2598 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002599 if (wlv.n_extra > 0)
2600 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002601 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002602 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002603 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002604 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002605 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002606 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002607 vim_memset(p, ' ', len);
2608 p[len] = NUL;
2609 vim_free(p_extra_free);
2610 p_extra_free = p;
2611 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002612 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002613 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002614
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002615 if (*p == NUL)
2616 {
2617 tab_len = i;
2618 break;
2619 }
2620
2621 // if tab3 is given, use it for the last char
2622 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2623 lcs = wp->w_lcs_chars.tab3;
2624 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002625 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002626 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002627 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002628 wlv.p_extra = p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002629# ifdef FEAT_CONCEAL
2630 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2631 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002632 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002633 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002634# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002635 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002636 }
2637#endif
2638#ifdef FEAT_CONCEAL
2639 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002640 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002641
2642 // Tab alignment should be identical regardless of
2643 // 'conceallevel' value. So tab compensates of all
2644 // previous concealed characters, and thus resets
2645 // vcol_off and boguscols accumulated so far in the
2646 // line. Note that the tab can be longer than
2647 // 'tabstop' when there are concealed characters.
2648 FIX_FOR_BOGUSCOLS;
2649
2650 // Make sure, the highlighting for the tab char will be
2651 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002652 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002653 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002654 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002655 tab_len += vc_saved;
2656 }
2657#endif
2658 mb_utf8 = FALSE; // don't draw as UTF-8
2659 if (wp->w_p_list)
2660 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002661 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002662 ? wp->w_lcs_chars.tab3
2663 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002664#ifdef FEAT_LINEBREAK
2665 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002666 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002667 else
2668#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002669 wlv.c_extra = wp->w_lcs_chars.tab2;
2670 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002671 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002672 extra_attr = hl_combine_attr(wlv.win_attr,
2673 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002674 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002675 mb_c = c;
2676 if (enc_utf8 && utf_char2len(c) > 1)
2677 {
2678 mb_utf8 = TRUE;
2679 u8cc[0] = 0;
2680 c = 0xc0;
2681 }
2682 }
2683 else
2684 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002685 wlv.c_final = NUL;
2686 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002687 c = ' ';
2688 }
2689 }
2690 else if (c == NUL
2691 && (wp->w_p_list
2692 || ((fromcol >= 0 || fromcol_prev >= 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002693 && tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002694 && VIsual_mode != Ctrl_V
2695 && (
2696# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002697 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002698# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002699 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002700 && !(noinvcur
2701 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002702 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002703 && lcs_eol_one > 0)
2704 {
2705 // Display a '$' after the line or highlight an extra
2706 // character if the line break is included.
2707#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2708 // For a diff line the highlighting continues after the
2709 // "$".
2710 if (
2711# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002712 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002713# ifdef LINE_ATTR
2714 &&
2715# endif
2716# endif
2717# ifdef LINE_ATTR
2718 line_attr == 0
2719# endif
2720 )
2721#endif
2722 {
2723 // In virtualedit, visual selections may extend
2724 // beyond end of line.
2725 if (area_highlighting && virtual_active()
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002726 && tocol != MAXCOL && wlv.vcol < tocol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002727 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002728 else
2729 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002730 wlv.p_extra = at_end_str;
2731 wlv.n_extra = 1;
2732 wlv.c_extra = NUL;
2733 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002734 }
2735 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002736 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2737 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002738 else
2739 c = ' ';
2740 lcs_eol_one = -1;
2741 --ptr; // put it back at the NUL
2742 if (!attr_pri)
2743 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002744 extra_attr = hl_combine_attr(wlv.win_attr,
2745 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002746 n_attr = 1;
2747 }
2748 mb_c = c;
2749 if (enc_utf8 && utf_char2len(c) > 1)
2750 {
2751 mb_utf8 = TRUE;
2752 u8cc[0] = 0;
2753 c = 0xc0;
2754 }
2755 else
2756 mb_utf8 = FALSE; // don't draw as UTF-8
2757 }
2758 else if (c != NUL)
2759 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002760 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2761 if (wlv.n_extra == 0)
2762 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002763#ifdef FEAT_RIGHTLEFT
2764 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002765 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002766#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002767 wlv.c_extra = NUL;
2768 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002769#ifdef FEAT_LINEBREAK
2770 if (wp->w_p_lbr)
2771 {
2772 char_u *p;
2773
Bram Moolenaar1306b362022-08-06 15:59:06 +01002774 c = *wlv.p_extra;
2775 p = alloc(wlv.n_extra + 1);
2776 vim_memset(p, ' ', wlv.n_extra);
2777 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2778 p[wlv.n_extra] = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002779 vim_free(p_extra_free);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002780 p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002781 }
2782 else
2783#endif
2784 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002785 wlv.n_extra = byte2cells(c) - 1;
2786 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002787 }
2788 if (!attr_pri)
2789 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002790 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002791 extra_attr = hl_combine_attr(wlv.win_attr,
2792 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002793 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002794 }
2795 mb_utf8 = FALSE; // don't draw as UTF-8
2796 }
2797 else if (VIsual_active
2798 && (VIsual_mode == Ctrl_V
2799 || VIsual_mode == 'v')
2800 && virtual_active()
2801 && tocol != MAXCOL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002802 && wlv.vcol < tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002803 && (
2804#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002805 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002806#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002807 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002808 {
2809 c = ' ';
2810 --ptr; // put it back at the NUL
2811 }
2812#if defined(LINE_ATTR)
2813 else if ((
2814# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002815 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002816# endif
2817# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002818 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002819# endif
2820 line_attr != 0
2821 ) && (
2822# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002823 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002824# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002825 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002826# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002827 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002828# endif
2829 < wp->w_width)))
2830 {
2831 // Highlight until the right side of the window
2832 c = ' ';
2833 --ptr; // put it back at the NUL
2834
2835 // Remember we do the char for line highlighting.
2836 ++did_line_attr;
2837
2838 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01002839 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002840 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002841 || (wp->w_p_list &&
2842 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002843 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002844# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002845 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002846 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002847 wlv.diff_hlf = HLF_CHD;
2848 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002849 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002850 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002851 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2852 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01002853 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002854 || (wlv.vcol >= left_curline_col
2855 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002856 wlv.char_attr = hl_combine_attr(
2857 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002858 }
2859 }
2860# endif
2861# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002862 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002863 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002864 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002865 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2866 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002867 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002868 if (!wlv.cul_screenline
2869 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002870 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002871 wlv.char_attr = hl_combine_attr(
2872 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002873 }
2874 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002875 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2876 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002877 }
2878# endif
2879 }
2880#endif
2881 }
2882
2883#ifdef FEAT_CONCEAL
2884 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01002885 && (wp != curwin || lnum != wp->w_cursor.lnum
2886 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002887 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2888 && !(lnum_in_visual_area
2889 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2890 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002891 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01002892 if (((prev_syntax_id != syntax_seqnr
2893 && (syntax_flags & HL_CONCEAL) != 0)
2894 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002895 && (syn_get_sub_char() != NUL
2896 || (has_match_conc && match_conc)
2897 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002898 && wp->w_p_cole != 3)
2899 {
2900 // First time at this concealed item: display one
2901 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002902 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002903 c = match_conc;
2904 else if (syn_get_sub_char() != NUL)
2905 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01002906 else if (wp->w_lcs_chars.conceal != NUL)
2907 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002908 else
2909 c = ' ';
2910
2911 prev_syntax_id = syntax_seqnr;
2912
Bram Moolenaar1306b362022-08-06 15:59:06 +01002913 if (wlv.n_extra > 0)
2914 wlv.vcol_off += wlv.n_extra;
2915 wlv.vcol += wlv.n_extra;
2916 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002917 {
2918# ifdef FEAT_RIGHTLEFT
2919 if (wp->w_p_rl)
2920 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002921 wlv.col -= wlv.n_extra;
2922 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002923 }
2924 else
2925# endif
2926 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002927 wlv.boguscols += wlv.n_extra;
2928 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002929 }
2930 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002931 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002932 n_attr = 0;
2933 }
2934 else if (n_skip == 0)
2935 {
2936 is_concealing = TRUE;
2937 n_skip = 1;
2938 }
2939 mb_c = c;
2940 if (enc_utf8 && utf_char2len(c) > 1)
2941 {
2942 mb_utf8 = TRUE;
2943 u8cc[0] = 0;
2944 c = 0xc0;
2945 }
2946 else
2947 mb_utf8 = FALSE; // don't draw as UTF-8
2948 }
2949 else
2950 {
2951 prev_syntax_id = 0;
2952 is_concealing = FALSE;
2953 }
2954
2955 if (n_skip > 0 && did_decrement_ptr)
2956 // not showing the '>', put pointer back to avoid getting stuck
2957 ++ptr;
2958
2959#endif // FEAT_CONCEAL
2960 }
2961
2962#ifdef FEAT_CONCEAL
2963 // In the cursor line and we may be concealing characters: correct
2964 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002965 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002966 && wp == curwin && lnum == wp->w_cursor.lnum
2967 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002968 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002969 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002970# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002971 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002972 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002973 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002974# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002975 wp->w_wcol = wlv.col - wlv.boguscols;
2976 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002977 did_wcol = TRUE;
2978 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002979# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01002980 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002981# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002982 }
2983#endif
2984
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002985 // Use "extra_attr", but don't override visual selection highlighting.
2986 // Don't use "extra_attr" until n_attr_skip is zero.
2987 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01002988 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002989 && !attr_pri)
2990 {
2991#ifdef LINE_ATTR
2992 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01002993 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002994 else
2995#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002996 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002997 }
2998
2999#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3000 // XIM don't send preedit_start and preedit_end, but they send
3001 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3002 // im_is_preediting() here.
3003 if (p_imst == IM_ON_THE_SPOT
3004 && xic != NULL
3005 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003006 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003007 && !p_imdisable
3008 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003009 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003010 {
3011 colnr_T tcol;
3012
3013 if (preedit_end_col == MAXCOL)
3014 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3015 else
3016 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003017 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003018 {
3019 if (feedback_old_attr < 0)
3020 {
3021 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003022 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003023 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003024 wlv.char_attr = im_get_feedback_attr(feedback_col);
3025 if (wlv.char_attr < 0)
3026 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003027 feedback_col++;
3028 }
3029 else if (feedback_old_attr >= 0)
3030 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003031 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003032 feedback_old_attr = -1;
3033 feedback_col = 0;
3034 }
3035 }
3036#endif
3037 // Handle the case where we are in column 0 but not on the first
3038 // character of the line and the user wants us to show us a
3039 // special character (via 'listchars' option "precedes:<char>".
3040 if (lcs_prec_todo != NUL
3041 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003042 && (wp->w_p_wrap ?
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003043 (wp->w_skipcol > 0 && wlv.row == 0) :
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003044 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003045#ifdef FEAT_DIFF
3046 && filler_todo <= 0
3047#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003048 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003049 && c != NUL)
3050 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003051 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003052 lcs_prec_todo = NUL;
3053 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3054 {
3055 // Double-width character being overwritten by the "precedes"
3056 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003057 wlv.c_extra = MB_FILLER_CHAR;
3058 wlv.c_final = NUL;
3059 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003060 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003061 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003062 }
3063 mb_c = c;
3064 if (enc_utf8 && utf_char2len(c) > 1)
3065 {
3066 mb_utf8 = TRUE;
3067 u8cc[0] = 0;
3068 c = 0xc0;
3069 }
3070 else
3071 mb_utf8 = FALSE; // don't draw as UTF-8
3072 if (!attr_pri)
3073 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003074 saved_attr3 = wlv.char_attr; // save current attr
3075 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003076 n_attr3 = 1;
3077 }
3078 }
3079
3080 // At end of the text line or just after the last character.
3081 if ((c == NUL
3082#if defined(LINE_ATTR)
3083 || did_line_attr == 1
3084#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003085 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003086 {
3087#ifdef FEAT_SEARCH_EXTRA
3088 // flag to indicate whether prevcol equals startcol of search_hl or
3089 // one of the matches
3090 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3091 (long)(ptr - line) - (c == NUL));
3092#endif
3093 // Invert at least one char, used for Visual and empty line or
3094 // highlight match at end of line. If it's beyond the last
3095 // char on the screen, just overwrite that one (tricky!) Not
3096 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003097 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003098 && ((area_attr != 0 && wlv.vcol == fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003099 && (VIsual_mode != Ctrl_V
3100 || lnum == VIsual.lnum
3101 || lnum == curwin->w_cursor.lnum)
3102 && c == NUL)
3103#ifdef FEAT_SEARCH_EXTRA
3104 // highlight 'hlsearch' match at end of line
3105 || (prevcol_hl_flag
3106# ifdef FEAT_SYN_HL
3107 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3108 && !(wp == curwin && VIsual_active))
3109# endif
3110# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003111 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003112# endif
3113# if defined(LINE_ATTR)
3114 && did_line_attr <= 1
3115# endif
3116 )
3117#endif
3118 ))
3119 {
3120 int n = 0;
3121
3122#ifdef FEAT_RIGHTLEFT
3123 if (wp->w_p_rl)
3124 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003125 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003126 n = 1;
3127 }
3128 else
3129#endif
3130 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003131 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003132 n = -1;
3133 }
3134 if (n != 0)
3135 {
3136 // At the window boundary, highlight the last character
3137 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003138 wlv.off += n;
3139 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003140 }
3141 else
3142 {
3143 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003144 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003145 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003146 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003147 }
3148#ifdef FEAT_SEARCH_EXTRA
3149 if (area_attr == 0)
3150 {
3151 // Use attributes from match with highest priority among
3152 // 'search_hl' and the match list.
3153 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003154 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003155 }
3156#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003157 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003158 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003159#ifdef FEAT_RIGHTLEFT
3160 if (wp->w_p_rl)
3161 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003162 --wlv.col;
3163 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003164 }
3165 else
3166#endif
3167 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003168 ++wlv.col;
3169 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003170 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003171 ++wlv.vcol;
3172 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003173 }
3174 }
3175
3176 // At end of the text line.
3177 if (c == NUL)
3178 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003179 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003180
3181 // Update w_cline_height and w_cline_folded if the cursor line was
3182 // updated (saves a call to plines() later).
3183 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3184 {
3185 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003186 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003187#ifdef FEAT_FOLDING
3188 curwin->w_cline_folded = FALSE;
3189#endif
3190 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3191 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003192 break;
3193 }
3194
3195 // Show "extends" character from 'listchars' if beyond the line end and
3196 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003197 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003198 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003199 && wp->w_p_list
3200 && !wp->w_p_wrap
3201#ifdef FEAT_DIFF
3202 && filler_todo <= 0
3203#endif
3204 && (
3205#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003206 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003207#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003208 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003209 && (*ptr != NUL
3210 || (wp->w_p_list && lcs_eol_one > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003211 || (wlv.n_extra && (wlv.c_extra != NUL
3212 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003213 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003214 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003215 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003216 mb_c = c;
3217 if (enc_utf8 && utf_char2len(c) > 1)
3218 {
3219 mb_utf8 = TRUE;
3220 u8cc[0] = 0;
3221 c = 0xc0;
3222 }
3223 else
3224 mb_utf8 = FALSE;
3225 }
3226
3227#ifdef FEAT_SYN_HL
3228 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003229 if (wlv.draw_color_col)
3230 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003231
3232 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3233 // highlight the cursor position itself.
3234 // Also highlight the 'colorcolumn' if it is different than
3235 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003236 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3237 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003238 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003239 if (((wlv.draw_state == WL_LINE
3240 || wlv.draw_state == WL_BRI
3241 || wlv.draw_state == WL_SBR)
3242 && !lnum_in_visual_area
3243 && search_attr == 0
3244 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003245# ifdef FEAT_DIFF
3246 && filler_todo <= 0
3247# endif
3248 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003249 {
3250 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3251 && lnum != wp->w_cursor.lnum)
3252 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003253 vcol_save_attr = wlv.char_attr;
3254 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3255 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003256 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003257 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003258 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003259 vcol_save_attr = wlv.char_attr;
3260 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003261 }
3262 }
3263#endif
3264
3265 // Store character to be displayed.
3266 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003267 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003268 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003269 {
3270 // Store the character.
3271#if defined(FEAT_RIGHTLEFT)
3272 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3273 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003274 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003275 --wlv.off;
3276 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003277 }
3278#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003279 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003280 if (enc_dbcs == DBCS_JPNU)
3281 {
3282 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003283 ScreenLines[wlv.off] = 0x8e;
3284 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003285 }
3286 else if (enc_utf8)
3287 {
3288 if (mb_utf8)
3289 {
3290 int i;
3291
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003292 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003293 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003294 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003295 for (i = 0; i < Screen_mco; ++i)
3296 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003297 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003298 if (u8cc[i] == 0)
3299 break;
3300 }
3301 }
3302 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003303 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003304 }
3305 if (multi_attr)
3306 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003307 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003308 multi_attr = 0;
3309 }
3310 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003311 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003312
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003313 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003314
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003315 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3316 {
3317 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003318 ++wlv.off;
3319 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003320 if (enc_utf8)
3321 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003322 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003323 else
3324 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003325 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003326 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003327#ifdef FEAT_DIFF
3328 && filler_todo <= 0
3329#endif
3330 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003331 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003332 // When "tocol" is halfway a character, set it to the end of
3333 // the character, otherwise highlighting won't stop.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003334 if (tocol == wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003335 ++tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003336
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003337 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003338
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003339#ifdef FEAT_RIGHTLEFT
3340 if (wp->w_p_rl)
3341 {
3342 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003343 --wlv.off;
3344 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003345 }
3346#endif
3347 }
3348#ifdef FEAT_RIGHTLEFT
3349 if (wp->w_p_rl)
3350 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003351 --wlv.off;
3352 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003353 }
3354 else
3355#endif
3356 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003357 ++wlv.off;
3358 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003359 }
3360 }
3361#ifdef FEAT_CONCEAL
3362 else if (wp->w_p_cole > 0 && is_concealing)
3363 {
3364 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003365 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003366 if (wlv.n_extra > 0)
3367 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003368 if (wp->w_p_wrap)
3369 {
3370 // Special voodoo required if 'wrap' is on.
3371 //
3372 // Advance the column indicator to force the line
3373 // drawing to wrap early. This will make the line
3374 // take up the same screen space when parts are concealed,
3375 // so that cursor line computations aren't messed up.
3376 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003377 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003378 // trailing junk to be written out of the screen line
3379 // we are building, 'boguscols' keeps track of the number
3380 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003381 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003382 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003383 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003384# ifdef FEAT_RIGHTLEFT
3385 if (wp->w_p_rl)
3386 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003387 wlv.col -= wlv.n_extra;
3388 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003389 }
3390 else
3391# endif
3392 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003393 wlv.col += wlv.n_extra;
3394 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003395 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003396 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003397 n_attr = 0;
3398 }
3399
3400
3401 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3402 {
3403 // Need to fill two screen columns.
3404# ifdef FEAT_RIGHTLEFT
3405 if (wp->w_p_rl)
3406 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003407 --wlv.boguscols;
3408 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003409 }
3410 else
3411# endif
3412 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003413 ++wlv.boguscols;
3414 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003415 }
3416 }
3417
3418# ifdef FEAT_RIGHTLEFT
3419 if (wp->w_p_rl)
3420 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003421 --wlv.boguscols;
3422 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003423 }
3424 else
3425# endif
3426 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003427 ++wlv.boguscols;
3428 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003429 }
3430 }
3431 else
3432 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003433 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003434 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003435 wlv.vcol += wlv.n_extra;
3436 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003437 n_attr = 0;
3438 }
3439 }
3440
3441 }
3442#endif // FEAT_CONCEAL
3443 else
3444 --n_skip;
3445
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003446 // Only advance the "wlv.vcol" when after the 'number' or
3447 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003448 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003449#ifdef FEAT_DIFF
3450 && filler_todo <= 0
3451#endif
3452 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003453 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003454
3455#ifdef FEAT_SYN_HL
3456 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003457 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003458#endif
3459
3460 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003461 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3462 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003463
3464 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003465 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003466 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003467 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003468 if (n_attr_skip > 0)
3469 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003470
3471 // At end of screen line and there is more to come: Display the line
3472 // so far. If there is no more to display it is caught above.
3473 if ((
3474#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003475 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003476#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003477 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003478 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003479 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003480#ifdef FEAT_DIFF
3481 || filler_todo > 0
3482#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003483#ifdef FEAT_PROP_POPUP
3484 || text_prop_follows
3485#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003486 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003487 && wlv.p_extra != at_end_str)
3488 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3489 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003490 )
3491 {
3492#ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003493 screen_line(wp, wlv.screen_row, wp->w_wincol,
3494 wlv.col - wlv.boguscols,
3495 wp->w_width, wlv.screen_line_flags);
3496 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003497#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003498 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col,
3499 wp->w_width, wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003500#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003501 ++wlv.row;
3502 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003503
3504 // When not wrapping and finished diff lines, or when displayed
3505 // '$' and highlighting until last column, break here.
3506 if ((!wp->w_p_wrap
3507#ifdef FEAT_DIFF
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003508 && filler_todo <= 0
3509#endif
3510#ifdef FEAT_PROP_POPUP
3511 && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003512#endif
3513 ) || lcs_eol_one == -1)
3514 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003515#ifdef FEAT_PROP_POPUP
Bram Moolenaar83bf11a2022-08-06 22:23:40 +01003516 if (!wp->w_p_wrap && text_prop_follows)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003517 {
3518 // do not output more of the line, only the "below" prop
3519 ptr += STRLEN(ptr);
3520# ifdef FEAT_LINEBREAK
3521 dont_use_showbreak = TRUE;
3522# endif
3523 }
3524#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003525
3526 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003527 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003528#ifdef FEAT_DIFF
3529 && filler_todo <= 0
3530#endif
3531 )
3532 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003533 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3534 draw_vsep_win(wp, wlv.row);
3535 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003536 }
3537
3538 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003539 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003540 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003541 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003542 break;
3543 }
3544
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003545 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003546#ifdef FEAT_DIFF
3547 && filler_todo <= 0
3548#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003549#ifdef FEAT_PROP_POPUP
3550 && !text_prop_follows
3551#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003552 && wp->w_width == Columns)
3553 {
3554 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003555 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003556
3557 // Special trick to make copy/paste of wrapped lines work with
3558 // xterm/screen: write an extra character beyond the end of
3559 // the line. This will work with all terminal types
3560 // (regardless of the xn,am settings).
3561 // Only do this on a fast tty.
3562 // Only do this if the cursor is on the current line
3563 // (something has been written in it).
3564 // Don't do this for the GUI.
3565 // Don't do this for double-width characters.
3566 // Don't do this for a window not at the right screen border.
3567 if (p_tf
3568#ifdef FEAT_GUI
3569 && !gui.in_use
3570#endif
3571 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003572 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3573 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003574 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003575 || (*mb_off2cells)(
3576 LineOffset[wlv.screen_row - 1]
3577 + (int)Columns - 2,
3578 LineOffset[wlv.screen_row]
3579 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003580 {
3581 // First make sure we are at the end of the screen line,
3582 // then output the same character again to let the
3583 // terminal know about the wrap. If the terminal doesn't
3584 // auto-wrap, we overwrite the character.
3585 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003586 screen_char(LineOffset[wlv.screen_row - 1]
3587 + (unsigned)Columns - 1,
3588 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003589
3590 // When there is a multi-byte character, just output a
3591 // space to keep it simple.
3592 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003593 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003594 out_char(' ');
3595 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003596 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003597 + (Columns - 1)]);
3598 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003599 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003600 screen_start(); // don't know where cursor is now
3601 }
3602 }
3603
Bram Moolenaar1306b362022-08-06 15:59:06 +01003604 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003605
Bram Moolenaareed9d462021-02-15 20:38:25 +01003606 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003607#ifdef FEAT_LINEBREAK
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003608 if (!dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003609# ifdef FEAT_DIFF
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003610 && filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003611# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003612 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003613 need_showbreak = TRUE;
3614#endif
3615#ifdef FEAT_DIFF
3616 --filler_todo;
3617 // When the filler lines are actually below the last line of the
3618 // file, don't draw the line itself, break here.
3619 if (filler_todo == 0 && wp->w_botfill)
3620 break;
3621#endif
3622 }
3623
3624 } // for every character in the line
3625
3626#ifdef FEAT_SPELL
3627 // After an empty line check first word for capital.
3628 if (*skipwhite(line) == NUL)
3629 {
3630 capcol_lnum = lnum + 1;
3631 cap_col = 0;
3632 }
3633#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003634#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003635 vim_free(text_props);
3636 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003637 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003638#endif
3639
3640 vim_free(p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003641 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003642}