blob: 19070228c2aaf3f96b2a83f6ba36b1029b6cdd9a [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;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +0100557 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200558 int text_prop_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100559 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100560 int text_prop_flags = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100561 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +0100562 int saved_search_attr = 0; // search_attr to be used when n_extra
563 // goes to zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200564#endif
565#ifdef FEAT_SPELL
566 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000567 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200568# define SPWORDLEN 150
569 char_u nextline[SPWORDLEN * 2];// text with start of the next line
570 int nextlinecol = 0; // column where nextline[] starts
571 int nextline_idx = 0; // index in nextline[] where next line
572 // starts
573 int spell_attr = 0; // attributes desired by spelling
574 int word_end = 0; // last byte with same spell_attr
575 static linenr_T checked_lnum = 0; // line number for "checked_col"
576 static int checked_col = 0; // column in "checked_lnum" up to which
577 // there are no spell errors
578 static int cap_col = -1; // column to check for Cap word
579 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
580 int cur_checked_col = 0; // checked column for current line
581#endif
582 int extra_check = 0; // has extra highlighting
583 int multi_attr = 0; // attributes desired by multibyte
584 int mb_l = 1; // multi-byte byte length
585 int mb_c = 0; // decoded multi-byte character
586 int mb_utf8 = FALSE; // screen char is UTF-8 char
587 int u8cc[MAX_MCO]; // composing UTF-8 chars
588#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
589 int filler_lines = 0; // nr of filler lines to be drawn
590 int filler_todo = 0; // nr of filler lines still to do + 1
Bram Moolenaar936dc602022-03-06 20:47:01 +0000591#else
592# define filler_lines 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200593#endif
594#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200595 int change_start = MAXCOL; // first col of changed area
596 int change_end = -1; // last col of changed area
597#endif
598 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100599 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200600 int in_multispace = FALSE; // in multiple consecutive spaces
601 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200602#ifdef FEAT_LINEBREAK
603 int need_showbreak = FALSE; // overlong line, skipping first x
604 // chars
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +0100605 int dont_use_showbreak = FALSE; // do not use 'showbreak'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200606#endif
607#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
608 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
609# define LINE_ATTR
610 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +0100611 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200612#endif
613#ifdef FEAT_SIGNS
614 int sign_present = FALSE;
615 sign_attrs_T sattr;
James McCoya80aad72021-12-22 19:45:28 +0000616 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200617#endif
618#ifdef FEAT_ARABIC
619 int prev_c = 0; // previous Arabic character
620 int prev_c1 = 0; // first composing char for prev_c
621#endif
622#if defined(LINE_ATTR)
623 int did_line_attr = 0;
624#endif
625#ifdef FEAT_TERMINAL
626 int get_term_attr = FALSE;
627#endif
628#ifdef FEAT_SYN_HL
629 int cul_attr = 0; // set when 'cursorline' active
630
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200631 // margin columns for the screen line, needed for when 'cursorlineopt'
632 // contains "screenline"
633 int left_curline_col = 0;
634 int right_curline_col = 0;
635#endif
636
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200637#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
638 int feedback_col = 0;
639 int feedback_old_attr = -1;
640#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200641
642#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
643 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000644 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200645#endif
646#ifdef FEAT_CONCEAL
647 int syntax_flags = 0;
648 int syntax_seqnr = 0;
649 int prev_syntax_id = 0;
650 int conceal_attr = HL_ATTR(HLF_CONCEAL);
651 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200652 int did_wcol = FALSE;
653 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100654# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200655# define FIX_FOR_BOGUSCOLS \
656 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +0100657 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100658 wlv.vcol -= wlv.vcol_off; \
659 wlv.vcol_off = 0; \
660 wlv.col -= wlv.boguscols; \
661 old_boguscols = wlv.boguscols; \
662 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200663 }
664#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100665# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200666#endif
667
668 if (startrow > endrow) // past the end already!
669 return startrow;
670
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100671 CLEAR_FIELD(wlv);
672
673 wlv.lnum = lnum;
674 wlv.startrow = startrow;
675 wlv.row = startrow;
676 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200677
678 if (!number_only)
679 {
680 // To speed up the loop below, set extra_check when there is linebreak,
681 // trailing white space and/or syntax processing to be done.
682#ifdef FEAT_LINEBREAK
683 extra_check = wp->w_p_lbr;
684#endif
685#ifdef FEAT_SYN_HL
686 if (syntax_present(wp) && !wp->w_s->b_syn_error
687# ifdef SYN_TIME_LIMIT
688 && !wp->w_s->b_syn_slow
689# endif
690 )
691 {
692 // Prepare for syntax highlighting in this line. When there is an
693 // error, stop syntax highlighting.
694 save_did_emsg = did_emsg;
695 did_emsg = FALSE;
696 syntax_start(wp, lnum);
697 if (did_emsg)
698 wp->w_s->b_syn_error = TRUE;
699 else
700 {
701 did_emsg = save_did_emsg;
702#ifdef SYN_TIME_LIMIT
703 if (!wp->w_s->b_syn_slow)
704#endif
705 {
706 has_syntax = TRUE;
707 extra_check = TRUE;
708 }
709 }
710 }
711
712 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100713 wlv.color_cols = wp->w_p_cc_cols;
714 if (wlv.color_cols != NULL)
715 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200716#endif
717
718#ifdef FEAT_TERMINAL
719 if (term_show_buffer(wp->w_buffer))
720 {
721 extra_check = TRUE;
722 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100723 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200724 }
725#endif
726
727#ifdef FEAT_SPELL
728 if (wp->w_p_spell
729 && *wp->w_s->b_p_spl != NUL
730 && wp->w_s->b_langp.ga_len > 0
731 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
732 {
733 // Prepare for spell checking.
734 has_spell = TRUE;
735 extra_check = TRUE;
736
737 // Get the start of the next line, so that words that wrap to the
738 // next line are found too: "et<line-break>al.".
739 // Trick: skip a few chars for C/shell/Vim comments
740 nextline[SPWORDLEN] = NUL;
741 if (lnum < wp->w_buffer->b_ml.ml_line_count)
742 {
743 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
744 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
745 }
746
747 // When a word wrapped from the previous line the start of the
748 // current line is valid.
749 if (lnum == checked_lnum)
750 cur_checked_col = checked_col;
751 checked_lnum = 0;
752
753 // When there was a sentence end in the previous line may require a
754 // word starting with capital in this line. In line 1 always check
755 // the first word.
756 if (lnum != capcol_lnum)
757 cap_col = -1;
758 if (lnum == 1)
759 cap_col = 0;
760 capcol_lnum = 0;
761 }
762#endif
763
764 // handle Visual active in this window
765 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
766 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100767 pos_T *top, *bot;
768
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200769 if (LTOREQ_POS(curwin->w_cursor, VIsual))
770 {
771 // Visual is after curwin->w_cursor
772 top = &curwin->w_cursor;
773 bot = &VIsual;
774 }
775 else
776 {
777 // Visual is before curwin->w_cursor
778 top = &VIsual;
779 bot = &curwin->w_cursor;
780 }
781 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
782 if (VIsual_mode == Ctrl_V)
783 {
784 // block mode
785 if (lnum_in_visual_area)
786 {
787 fromcol = wp->w_old_cursor_fcol;
788 tocol = wp->w_old_cursor_lcol;
789 }
790 }
791 else
792 {
793 // non-block mode
794 if (lnum > top->lnum && lnum <= bot->lnum)
795 fromcol = 0;
796 else if (lnum == top->lnum)
797 {
798 if (VIsual_mode == 'V') // linewise
799 fromcol = 0;
800 else
801 {
802 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
803 if (gchar_pos(top) == NUL)
804 tocol = fromcol + 1;
805 }
806 }
807 if (VIsual_mode != 'V' && lnum == bot->lnum)
808 {
809 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
810 {
811 fromcol = -10;
812 tocol = MAXCOL;
813 }
814 else if (bot->col == MAXCOL)
815 tocol = MAXCOL;
816 else
817 {
818 pos = *bot;
819 if (*p_sel == 'e')
820 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
821 else
822 {
823 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
824 ++tocol;
825 }
826 }
827 }
828 }
829
830 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200831 if (!highlight_match && lnum == curwin->w_cursor.lnum
832 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200833#ifdef FEAT_GUI
834 && !gui.in_use
835#endif
836 )
837 noinvcur = TRUE;
838
839 // if inverting in this line set area_highlighting
840 if (fromcol >= 0)
841 {
842 area_highlighting = TRUE;
843 vi_attr = HL_ATTR(HLF_V);
844#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
845 if ((clip_star.available && !clip_star.owned
846 && clip_isautosel_star())
847 || (clip_plus.available && !clip_plus.owned
848 && clip_isautosel_plus()))
849 vi_attr = HL_ATTR(HLF_VNC);
850#endif
851 }
852 }
853
854 // handle 'incsearch' and ":s///c" highlighting
855 else if (highlight_match
856 && wp == curwin
857 && lnum >= curwin->w_cursor.lnum
858 && lnum <= curwin->w_cursor.lnum + search_match_lines)
859 {
860 if (lnum == curwin->w_cursor.lnum)
861 getvcol(curwin, &(curwin->w_cursor),
862 (colnr_T *)&fromcol, NULL, NULL);
863 else
864 fromcol = 0;
865 if (lnum == curwin->w_cursor.lnum + search_match_lines)
866 {
867 pos.lnum = lnum;
868 pos.col = search_match_endcol;
869 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
870 }
871 else
872 tocol = MAXCOL;
873 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100874 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200875 tocol = fromcol + 1;
876 area_highlighting = TRUE;
877 vi_attr = HL_ATTR(HLF_I);
878 }
879 }
880
881#ifdef FEAT_DIFF
882 filler_lines = diff_check(wp, lnum);
883 if (filler_lines < 0)
884 {
885 if (filler_lines == -1)
886 {
887 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +0100888 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200889 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100890 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200891 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100892 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200893 }
894 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100895 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200896 filler_lines = 0;
897 area_highlighting = TRUE;
898 }
899 if (lnum == wp->w_topline)
900 filler_lines = wp->w_topfill;
901 filler_todo = filler_lines;
902#endif
903
904#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +0100905 sign_present = buf_get_signattrs(wp, lnum, &sattr);
James McCoya80aad72021-12-22 19:45:28 +0000906 if (sign_present)
907 num_attr = sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200908#endif
909
910#ifdef LINE_ATTR
911# ifdef FEAT_SIGNS
912 // If this line has a sign with line highlighting set line_attr.
913 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200914 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200915# endif
916# if defined(FEAT_QUICKFIX)
917 // Highlight the current line in the quickfix window.
918 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
919 line_attr = HL_ATTR(HLF_QFL);
920# endif
921 if (line_attr != 0)
922 area_highlighting = TRUE;
923#endif
924
925 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
926 ptr = line;
927
928#ifdef FEAT_SPELL
929 if (has_spell && !number_only)
930 {
931 // For checking first word with a capital skip white space.
932 if (cap_col == 0)
933 cap_col = getwhitecols(line);
934
935 // To be able to spell-check over line boundaries copy the end of the
936 // current line into nextline[]. Above the start of the next line was
937 // copied to nextline[SPWORDLEN].
938 if (nextline[SPWORDLEN] == NUL)
939 {
940 // No next line or it is empty.
941 nextlinecol = MAXCOL;
942 nextline_idx = 0;
943 }
944 else
945 {
946 v = (long)STRLEN(line);
947 if (v < SPWORDLEN)
948 {
949 // Short line, use it completely and append the start of the
950 // next line.
951 nextlinecol = 0;
952 mch_memmove(nextline, line, (size_t)v);
953 STRMOVE(nextline + v, nextline + SPWORDLEN);
954 nextline_idx = v + 1;
955 }
956 else
957 {
958 // Long line, use only the last SPWORDLEN bytes.
959 nextlinecol = v - SPWORDLEN;
960 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
961 nextline_idx = SPWORDLEN + 1;
962 }
963 }
964 }
965#endif
966
967 if (wp->w_p_list)
968 {
Bram Moolenaareed9d462021-02-15 20:38:25 +0100969 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +0200970 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100971 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +0100972 || wp->w_lcs_chars.trail
973 || wp->w_lcs_chars.lead
974 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200975 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100976
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200977 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100978 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200979 {
980 trailcol = (colnr_T)STRLEN(ptr);
981 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
982 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +0100983 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200984 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100985 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100986 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100987 {
988 leadcol = 0;
989 while (VIM_ISWHITE(ptr[leadcol]))
990 ++leadcol;
991 if (ptr[leadcol] == NUL)
992 // in a line full of spaces all of them are treated as trailing
993 leadcol = (colnr_T)0;
994 else
995 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +0100996 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100997 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200998 }
999
1000 wcr_attr = get_wcr_attr(wp);
1001 if (wcr_attr != 0)
1002 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001003 wlv.win_attr = wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001004 area_highlighting = TRUE;
1005 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001006
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001007#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001008 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001009 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001010#endif
1011
1012 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1013 // first character to be displayed.
1014 if (wp->w_p_wrap)
1015 v = wp->w_skipcol;
1016 else
1017 v = wp->w_leftcol;
1018 if (v > 0 && !number_only)
1019 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001020 char_u *prev_ptr = ptr;
1021 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001022 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001023
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001024 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001025 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001026 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001027 charsize = win_lbr_chartabsize(&cts, NULL);
1028 cts.cts_vcol += charsize;
1029 prev_ptr = cts.cts_ptr;
1030 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001031 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001032 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001033 ptr = cts.cts_ptr;
1034 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001035
1036 // When:
1037 // - 'cuc' is set, or
1038 // - 'colorcolumn' is set, or
1039 // - 'virtualedit' is set, or
1040 // - the visual mode is active,
1041 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001042 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001043#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001044 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001045#endif
1046 virtual_active() ||
1047 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001048 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001049
1050 // Handle a character that's not completely on the screen: Put ptr at
1051 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001052 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001053 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001054 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001055 ptr = prev_ptr;
1056 // If the character fits on the screen, don't need to skip it.
1057 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001058 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1059 && wlv.col == 0)
1060 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001061 }
1062
1063 // Adjust for when the inverted text is before the screen,
1064 // and when the start of the inverted text is before the screen.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001065 if (tocol <= wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001066 fromcol = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001067 else if (fromcol >= 0 && fromcol < wlv.vcol)
1068 fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001069
1070#ifdef FEAT_LINEBREAK
1071 // When w_skipcol is non-zero, first line needs 'showbreak'
1072 if (wp->w_p_wrap)
1073 need_showbreak = TRUE;
1074#endif
1075#ifdef FEAT_SPELL
1076 // When spell checking a word we need to figure out the start of the
1077 // word and if it's badly spelled or not.
1078 if (has_spell)
1079 {
1080 int len;
1081 colnr_T linecol = (colnr_T)(ptr - line);
1082 hlf_T spell_hlf = HLF_COUNT;
1083
1084 pos = wp->w_cursor;
1085 wp->w_cursor.lnum = lnum;
1086 wp->w_cursor.col = linecol;
1087 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1088
1089 // spell_move_to() may call ml_get() and make "line" invalid
1090 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1091 ptr = line + linecol;
1092
1093 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1094 {
1095 // no bad word found at line start, don't check until end of a
1096 // word
1097 spell_hlf = HLF_COUNT;
1098 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1099 }
1100 else
1101 {
1102 // bad word found, use attributes until end of word
1103 word_end = wp->w_cursor.col + len + 1;
1104
1105 // Turn index into actual attributes.
1106 if (spell_hlf != HLF_COUNT)
1107 spell_attr = highlight_attr[spell_hlf];
1108 }
1109 wp->w_cursor = pos;
1110
1111# ifdef FEAT_SYN_HL
1112 // Need to restart syntax highlighting for this line.
1113 if (has_syntax)
1114 syntax_start(wp, lnum);
1115# endif
1116 }
1117#endif
1118 }
1119
1120 // Correct highlighting for cursor that can't be disabled.
1121 // Avoids having to check this for each character.
1122 if (fromcol >= 0)
1123 {
1124 if (noinvcur)
1125 {
1126 if ((colnr_T)fromcol == wp->w_virtcol)
1127 {
1128 // highlighting starts at cursor, let it start just after the
1129 // cursor
1130 fromcol_prev = fromcol;
1131 fromcol = -1;
1132 }
1133 else if ((colnr_T)fromcol < wp->w_virtcol)
1134 // restart highlighting after the cursor
1135 fromcol_prev = wp->w_virtcol;
1136 }
1137 if (fromcol >= tocol)
1138 fromcol = -1;
1139 }
1140
1141#ifdef FEAT_SEARCH_EXTRA
1142 if (!number_only)
1143 {
1144 v = (long)(ptr - line);
1145 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1146 &line, &screen_search_hl,
1147 &search_attr);
1148 ptr = line + v; // "line" may have been updated
1149 }
1150#endif
1151
1152#ifdef FEAT_SYN_HL
1153 // Cursor line highlighting for 'cursorline' in the current window.
1154 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1155 {
1156 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001157 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001158 if (!(wp == curwin && VIsual_active)
1159 && wp->w_p_culopt_flags != CULOPT_NBR)
1160 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001161 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001162 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1163
1164 // Only set line_attr here when "screenline" is not present in
1165 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001166 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001167 {
1168 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001169# ifdef FEAT_SIGNS
1170 // Combine the 'cursorline' and sign highlighting, depending on
1171 // the sign priority.
1172 if (sign_present && sattr.sat_linehl > 0)
1173 {
1174 if (sattr.sat_priority >= 100)
1175 line_attr = hl_combine_attr(cul_attr, line_attr);
1176 else
1177 line_attr = hl_combine_attr(line_attr, cul_attr);
1178 }
1179 else
1180# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001181# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001182 // let the line attribute overrule 'cursorline', otherwise
1183 // it disappears when both have background set;
1184 // 'cursorline' can use underline or bold to make it show
1185 line_attr = hl_combine_attr(cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001186# else
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001187 line_attr = cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001188# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001189 }
1190 else
1191 {
1192 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001193 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1194 }
1195 area_highlighting = TRUE;
1196 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001197 }
1198#endif
1199
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001200#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001201 {
1202 char_u *prop_start;
1203
1204 text_prop_count = get_text_props(wp->w_buffer, lnum,
1205 &prop_start, FALSE);
1206 if (text_prop_count > 0)
1207 {
1208 // Make a copy of the properties, so that they are properly
1209 // aligned.
1210 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1211 if (text_props != NULL)
1212 mch_memmove(text_props, prop_start,
1213 text_prop_count * sizeof(textprop_T));
1214
1215 // Allocate an array for the indexes.
1216 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1217 area_highlighting = TRUE;
1218 extra_check = TRUE;
1219 }
1220 }
1221#endif
1222
Bram Moolenaar1306b362022-08-06 15:59:06 +01001223 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001224
1225 // Repeat for the whole displayed line.
1226 for (;;)
1227 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001228 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001229#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001230 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001231#endif
1232#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001233 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001234#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001235
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001236 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001237 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001238 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001239#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001240 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001241 {
1242 cul_attr = 0;
1243 line_attr = line_attr_save;
1244 }
1245#endif
1246
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001247#ifdef FEAT_CMDWIN
Bram Moolenaar1306b362022-08-06 15:59:06 +01001248 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001249 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001250 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001251 if (cmdwin_type != 0 && wp == curwin)
1252 {
1253 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001254 wlv.n_extra = 1;
1255 wlv.c_extra = cmdwin_type;
1256 wlv.c_final = NUL;
1257 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001258 }
1259 }
1260#endif
1261
1262#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001263 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001264 {
1265 int fdc = compute_foldcolumn(wp, 0);
1266
Bram Moolenaar1306b362022-08-06 15:59:06 +01001267 wlv.draw_state = WL_FOLD;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001268 if (fdc > 0)
1269 {
1270 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1271 // already be in use.
1272 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001273 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001274 if (p_extra_free != NULL)
1275 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001276 wlv.n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001277 FALSE, lnum);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001278 p_extra_free[wlv.n_extra] = NUL;
1279 wlv.p_extra = p_extra_free;
1280 wlv.c_extra = NUL;
1281 wlv.c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001282 if (use_cursor_line_sign(wp, lnum))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001283 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001284 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1285 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001286 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001287 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001288 }
1289 }
1290 }
1291#endif
1292
1293#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001294 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001295 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001296 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001297 // Show the sign column when there are any signs in this
1298 // buffer or when using Netbeans.
1299 if (signcolumn_on(wp))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001300 get_sign_display_info(FALSE, wp, lnum, &wlv, &sattr,
1301 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001302 }
1303#endif
1304
Bram Moolenaar1306b362022-08-06 15:59:06 +01001305 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001306 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001307 wlv.draw_state = WL_NR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001308 // Display the absolute or relative line number. After the
1309 // first fill with blanks when the 'n' flag isn't in 'cpo'
1310 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001311 && (wlv.row == startrow + filler_lines
1312 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001313 {
1314#ifdef FEAT_SIGNS
1315 // If 'signcolumn' is set to 'number' and a sign is present
1316 // in 'lnum', then display the sign instead of the line
1317 // number.
1318 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1319 && sign_present)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001320 get_sign_display_info(TRUE, wp, lnum, &wlv, &sattr,
1321 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001322 else
1323#endif
1324 {
1325 // Draw the line number (empty space after wrapping).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001326 if (wlv.row == startrow + filler_lines)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001327 {
1328 long num;
1329 char *fmt = "%*ld ";
1330
1331 if (wp->w_p_nu && !wp->w_p_rnu)
1332 // 'number' + 'norelativenumber'
1333 num = (long)lnum;
1334 else
1335 {
1336 // 'relativenumber', don't use negative numbers
1337 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1338 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1339 {
1340 // 'number' + 'relativenumber'
1341 num = lnum;
1342 fmt = "%-*ld ";
1343 }
1344 }
1345
1346 sprintf((char *)extra, fmt,
1347 number_width(wp), num);
1348 if (wp->w_skipcol > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001349 for (wlv.p_extra = extra; *wlv.p_extra == ' ';
1350 ++wlv.p_extra)
1351 *wlv.p_extra = '-';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001352#ifdef FEAT_RIGHTLEFT
1353 if (wp->w_p_rl) // reverse line numbers
1354 {
1355 char_u *p1, *p2;
1356 int t;
1357
1358 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001359 p2 = skipwhite(extra);
1360 p2 = skiptowhite(p2) - 1;
1361 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001362 {
1363 t = *p1;
1364 *p1 = *p2;
1365 *p2 = t;
1366 }
1367 }
1368#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001369 wlv.p_extra = extra;
1370 wlv.c_extra = NUL;
1371 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001372 }
1373 else
1374 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001375 wlv.c_extra = ' ';
1376 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001377 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001378 wlv.n_extra = number_width(wp) + 1;
1379 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001380#ifdef FEAT_SYN_HL
1381 // When 'cursorline' is set highlight the line number of
1382 // the current line differently.
zeertzjq754d2b42022-03-13 13:40:45 +00001383 // When 'cursorlineopt' does not have "line" only
1384 // highlight the line number itself.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001385 // TODO: Can we use CursorLine instead of CursorLineNr
1386 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001387 if (wp->w_p_cul
1388 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001389 && (wp->w_p_culopt_flags & CULOPT_NBR)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001390 && (wlv.row == startrow + filler_lines
1391 || (wlv.row > startrow + filler_lines
zeertzjq754d2b42022-03-13 13:40:45 +00001392 && (wp->w_p_culopt_flags & CULOPT_LINE))))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001393 wlv.char_attr = hl_combine_attr(wcr_attr,
1394 HL_ATTR(HLF_CLN));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001395#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001396 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1397 && HL_ATTR(HLF_LNA) != 0)
1398 // Use LineNrAbove
Bram Moolenaar1306b362022-08-06 15:59:06 +01001399 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001400 HL_ATTR(HLF_LNA));
1401 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1402 && HL_ATTR(HLF_LNB) != 0)
1403 // Use LineNrBelow
Bram Moolenaar1306b362022-08-06 15:59:06 +01001404 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001405 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001406 }
James McCoya80aad72021-12-22 19:45:28 +00001407#ifdef FEAT_SIGNS
1408 if (num_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001409 wlv.char_attr = num_attr;
James McCoya80aad72021-12-22 19:45:28 +00001410#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001411 }
1412 }
1413
1414#ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001415 if (wp->w_briopt_sbr && wlv.draw_state == WL_BRI - 1
1416 && wlv.n_extra == 0
1417 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001418 // draw indent after showbreak value
Bram Moolenaar1306b362022-08-06 15:59:06 +01001419 wlv.draw_state = WL_BRI;
1420 else if (wp->w_briopt_sbr && wlv.draw_state == WL_SBR
1421 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001422 // After the showbreak, draw the breakindent
Bram Moolenaar1306b362022-08-06 15:59:06 +01001423 wlv.draw_state = WL_BRI - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001424
1425 // draw 'breakindent': indent wrapped text accordingly
Bram Moolenaar1306b362022-08-06 15:59:06 +01001426 if (wlv.draw_state == WL_BRI - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001427 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001428 wlv.draw_state = WL_BRI;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001429 // if need_showbreak is set, breakindent also applies
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001430 if (wp->w_p_bri && (wlv.row != startrow || need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001431# ifdef FEAT_DIFF
1432 && filler_lines == 0
1433# endif
Bram Moolenaar73c38422022-08-07 11:53:40 +01001434# ifdef FEAT_PROP_POPUP
1435 && !dont_use_showbreak
1436# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001437 )
1438 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001439 wlv.char_attr = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001440# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01001441 if (wlv.diff_hlf != (hlf_T)0)
1442 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001443# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001444 wlv.p_extra = NULL;
1445 wlv.c_extra = ' ';
1446 wlv.c_final = NUL;
1447 wlv.n_extra = get_breakindent_win(wp,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001448 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001449 if (wlv.row == startrow)
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001450 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001451 wlv.n_extra -= win_col_off2(wp);
1452 if (wlv.n_extra < 0)
1453 wlv.n_extra = 0;
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001454 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001455 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001456 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001457 // Correct end of highlighted area for 'breakindent',
1458 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001459 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001460 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001461 }
1462 }
1463#endif
1464
1465#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001466 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001467 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001468 char_u *sbr;
1469
Bram Moolenaar1306b362022-08-06 15:59:06 +01001470 wlv.draw_state = WL_SBR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001471# ifdef FEAT_DIFF
1472 if (filler_todo > 0)
1473 {
1474 // Draw "deleted" diff line(s).
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001475 if (char2cells(wp->w_fill_chars.diff) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001476 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001477 wlv.c_extra = '-';
1478 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001479 }
1480 else
1481 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001482 wlv.c_extra = wp->w_fill_chars.diff;
1483 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001484 }
1485# ifdef FEAT_RIGHTLEFT
1486 if (wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001487 wlv.n_extra = wlv.col + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001488 else
1489# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001490 wlv.n_extra = wp->w_width - wlv.col;
1491 wlv.char_attr = HL_ATTR(HLF_DED);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001492 }
1493# endif
1494# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001495 sbr = get_showbreak_value(wp);
1496 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001497 {
1498 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001499 wlv.p_extra = sbr;
1500 wlv.c_extra = NUL;
1501 wlv.c_final = NUL;
1502 wlv.n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001503 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1504 need_showbreak = FALSE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001505 vcol_sbr = wlv.vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001506 // Correct end of highlighted area for 'showbreak',
1507 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001508 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001509 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001510 // combine 'showbreak' with 'wincolor'
Bram Moolenaar1306b362022-08-06 15:59:06 +01001511 wlv.char_attr = hl_combine_attr(wlv.win_attr,
1512 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001513# ifdef FEAT_SYN_HL
1514 // combine 'showbreak' with 'cursorline'
1515 if (cul_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001516 wlv.char_attr = hl_combine_attr(wlv.char_attr,
1517 cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001518# endif
1519 }
1520# endif
1521 }
1522#endif
1523
Bram Moolenaar1306b362022-08-06 15:59:06 +01001524 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001525 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001526 wlv.draw_state = WL_LINE;
1527 if (wlv.saved_n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001528 {
1529 // Continue item from end of wrapped line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001530 wlv.n_extra = wlv.saved_n_extra;
1531 wlv.c_extra = wlv.saved_c_extra;
1532 wlv.c_final = wlv.saved_c_final;
1533 wlv.p_extra = wlv.saved_p_extra;
1534 wlv.char_attr = wlv.saved_char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001535 }
1536 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001537 wlv.char_attr = wlv.win_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001538 }
1539 }
1540#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001541 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001542 && wlv.vcol >= left_curline_col
1543 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001544 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001545 cul_attr = HL_ATTR(HLF_CUL);
1546 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001547 }
1548#endif
1549
1550 // When still displaying '$' of change command, stop at cursor.
1551 // When only displaying the (relative) line number and that's done,
1552 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001553 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001554 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001555 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001556#ifdef FEAT_DIFF
1557 && filler_todo <= 0
1558#endif
1559 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001560 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001561 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col, -wp->w_width,
1562 wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001563 // Pretend we have finished updating the window. Except when
1564 // 'cursorcolumn' is set.
1565#ifdef FEAT_SYN_HL
1566 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001567 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001568 else
1569#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001570 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001571 break;
1572 }
1573
Bram Moolenaar1306b362022-08-06 15:59:06 +01001574 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001575 {
1576 // handle Visual or match highlighting in this line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001577 if (wlv.vcol == fromcol
Bram Moolenaar1306b362022-08-06 15:59:06 +01001578 || (has_mbyte && wlv.vcol + 1 == fromcol && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001579 && (*mb_ptr2cells)(ptr) > 1)
1580 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001581 && vcol_prev < wlv.vcol // not at margin
1582 && wlv.vcol < tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001583 area_attr = vi_attr; // start highlighting
1584 else if (area_attr != 0
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001585 && (wlv.vcol == tocol
1586 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001587 area_attr = 0; // stop highlighting
1588
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001589#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001590 if (text_props != NULL)
1591 {
1592 int pi;
1593 int bcol = (int)(ptr - line);
1594
Bram Moolenaar1306b362022-08-06 15:59:06 +01001595 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001596# ifdef FEAT_LINEBREAK
1597 && !in_linebreak
1598# endif
1599 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001600 --bcol; // still working on the previous char, e.g. Tab
1601
1602 // Check if any active property ends.
1603 for (pi = 0; pi < text_props_active; ++pi)
1604 {
1605 int tpi = text_prop_idxs[pi];
1606
1607 if (bcol >= text_props[tpi].tp_col - 1
1608 + text_props[tpi].tp_len)
1609 {
1610 if (pi + 1 < text_props_active)
1611 mch_memmove(text_prop_idxs + pi,
1612 text_prop_idxs + pi + 1,
1613 sizeof(int)
1614 * (text_props_active - (pi + 1)));
1615 --text_props_active;
1616 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001617# ifdef FEAT_LINEBREAK
1618 // not exactly right but should work in most cases
1619 if (in_linebreak && syntax_attr == text_prop_attr)
1620 syntax_attr = 0;
1621# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001622 }
1623 }
1624
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001625# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001626 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001627 // not on the next char yet, don't start another prop
1628 --bcol;
1629# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001630 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001631 // With 'nowrap' and not in the first screen line only "below"
1632 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001633 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001634 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001635 ? (*ptr == NUL
1636 && (wp->w_p_wrap
1637 || wlv.row == startrow
1638 || (text_props[text_prop_next].tp_flags
1639 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001640 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001641 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001642 if (text_props[text_prop_next].tp_col == MAXCOL
1643 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001644 + text_props[text_prop_next].tp_len)
1645 text_prop_idxs[text_props_active++] = text_prop_next;
1646 ++text_prop_next;
1647 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001648
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001649 if (wlv.n_extra == 0 || !extra_for_textprop)
1650 {
1651 text_prop_attr = 0;
1652 text_prop_flags = 0;
1653 text_prop_type = NULL;
1654 text_prop_id = 0;
1655 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001656 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001657 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001658 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001659 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001660 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001661
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001662 // Sort the properties on priority and/or starting last.
1663 // Then combine the attributes, highest priority last.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001664 text_prop_follows = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001665 current_text_props = text_props;
1666 current_buf = wp->w_buffer;
1667 qsort((void *)text_prop_idxs, (size_t)text_props_active,
1668 sizeof(int), text_prop_compare);
1669
1670 for (pi = 0; pi < text_props_active; ++pi)
1671 {
1672 int tpi = text_prop_idxs[pi];
1673 proptype_T *pt = text_prop_type_by_id(
1674 wp->w_buffer, text_props[tpi].tp_type);
1675
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001676 if (pt != NULL && (pt->pt_hl_id > 0
1677 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001678 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001679 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001680 if (pt->pt_hl_id > 0)
1681 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001682 text_prop_type = pt;
1683 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001684 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001685 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001686 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001687 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001688 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001689 }
1690 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001691 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001692 && -text_prop_id
1693 <= wp->w_buffer->b_textprop_text.ga_len)
1694 {
1695 char_u *p = ((char_u **)wp->w_buffer
1696 ->b_textprop_text.ga_data)[
1697 -text_prop_id - 1];
Bram Moolenaar1306b362022-08-06 15:59:06 +01001698
1699 // reset the ID in the copy to avoid it being used
1700 // again
1701 text_props[used_tpi].tp_id = -MAXCOL;
1702
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001703 if (p != NULL)
1704 {
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001705 int right = (text_props[used_tpi].tp_flags
1706 & TP_FLAG_ALIGN_RIGHT);
1707 int below = (text_props[used_tpi].tp_flags
1708 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaar398649e2022-08-04 15:03:48 +01001709 int wrap = (text_props[used_tpi].tp_flags
1710 & TP_FLAG_WRAP);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001711
Bram Moolenaar1306b362022-08-06 15:59:06 +01001712 wlv.p_extra = p;
1713 wlv.c_extra = NUL;
1714 wlv.c_final = NUL;
1715 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001716 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001717 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001718 n_attr = mb_charlen(p);
Bram Moolenaare38fc862022-08-11 17:24:50 +01001719 saved_search_attr = search_attr;
1720 search_attr = 0; // restore when n_extra is zero
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001721 text_prop_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001722 if (*ptr == NUL)
1723 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001724 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001725#ifdef FEAT_LINEBREAK
Bram Moolenaarcba69522022-08-06 21:03:53 +01001726 if (below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001727 {
1728 // no 'showbreak' before "below" text property
1729 // or after "right" text property
1730 need_showbreak = FALSE;
1731 dont_use_showbreak = TRUE;
1732 }
1733#endif
Bram Moolenaar398649e2022-08-04 15:03:48 +01001734 // Keep in sync with where
1735 // textprop_size_after_trunc() is called in
1736 // win_lbr_chartabsize().
1737 if ((right || below || !wrap) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001738 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001739 int added = wp->w_width - wlv.col;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001740 int n_used = wlv.n_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001741 char_u *l;
Bram Moolenaar398649e2022-08-04 15:03:48 +01001742 int strsize = wrap
Bram Moolenaar1306b362022-08-06 15:59:06 +01001743 ? vim_strsize(wlv.p_extra)
1744 : textprop_size_after_trunc(wp,
1745 below, added, wlv.p_extra, &n_used);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001746
Bram Moolenaar1306b362022-08-06 15:59:06 +01001747 if (wrap || right || below
1748 || n_used < wlv.n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001749 {
Bram Moolenaar398649e2022-08-04 15:03:48 +01001750 // Right-align: fill with spaces
1751 if (right)
1752 added -= strsize;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001753 if (added < 0
1754 || (below
1755 ? wlv.col == 0 || !wp->w_p_wrap
Bram Moolenaar1306b362022-08-06 15:59:06 +01001756 : n_used < wlv.n_extra))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001757 added = 0;
1758 // add 1 for NUL, 2 for when '…' is used
1759 l = alloc(n_used + added + 3);
1760 if (l != NULL)
1761 {
1762 vim_memset(l, ' ', added);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001763 vim_strncpy(l + added, wlv.p_extra,
1764 n_used);
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001765 if (n_used < wlv.n_extra
1766 && wp->w_p_wrap)
Bram Moolenaar398649e2022-08-04 15:03:48 +01001767 {
1768 char_u *lp = l + added + n_used - 1;
1769
1770 if (has_mbyte)
1771 {
1772 // change last character to '…'
1773 lp -= (*mb_head_off)(l, lp);
1774 STRCPY(lp, "…");
1775 n_used = lp - l + 3;
1776 }
1777 else
1778 // change last character to '>'
1779 *lp = '>';
1780 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001781 vim_free(p_extra_free2);
1782 wlv.p_extra = p_extra_free2 = l;
1783 wlv.n_extra = n_used + added;
Bram Moolenaar398649e2022-08-04 15:03:48 +01001784 n_attr_skip = added;
Bram Moolenaar1d8844a2022-08-10 13:39:35 +01001785 n_attr = mb_charlen(wlv.p_extra);
Bram Moolenaar398649e2022-08-04 15:03:48 +01001786 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001787 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001788
1789 // When 'wrap' is off then for "below" we need
1790 // to start a new line explictly.
Bram Moolenaardb9b96d2022-08-06 17:38:53 +01001791 if (below && wlv.col > win_col_off(wp)
1792 && !wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001793 {
1794 draw_screen_line(wp, &wlv);
1795
1796 // When line got too long for screen break
1797 // here.
1798 if (wlv.row == endrow)
1799 {
1800 ++wlv.row;
1801 break;
1802 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001803 win_line_start(wp, &wlv, TRUE);
1804 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001805 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001806 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001807 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001808
1809 // If another text prop follows the condition below at
1810 // the last window column must know.
1811 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001812 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001813 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001814 else if (text_prop_next < text_prop_count
1815 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001816 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
1817 || (!wp->w_p_wrap
1818 && wlv.col == wp->w_width - 1
1819 && (text_props[text_prop_next].tp_flags
1820 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001821 // When at last-but-one character and a text property
1822 // follows after it, we may need to flush the line after
1823 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001824 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01001825 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001826 }
1827#endif
1828
Bram Moolenaare38fc862022-08-11 17:24:50 +01001829#ifdef FEAT_SEARCH_EXTRA
1830 if (wlv.n_extra == 0)
1831 {
1832 // Check for start/end of 'hlsearch' and other matches.
1833 // After end, check for start/end of next match.
1834 // When another match, have to check for start again.
1835 v = (long)(ptr - line);
1836 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1837 &screen_search_hl, &has_match_conc,
1838 &match_conc, did_line_attr, lcs_eol_one,
1839 &on_last_col);
1840 ptr = line + v; // "line" may have been changed
1841 prev_ptr = ptr;
1842
1843 // Do not allow a conceal over EOL otherwise EOL will be missed
1844 // and bad things happen.
1845 if (*ptr == NUL)
1846 has_match_conc = 0;
1847 }
1848#endif
1849
1850#ifdef FEAT_DIFF
1851 if (wlv.diff_hlf != (hlf_T)0)
1852 {
1853 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
1854 && wlv.n_extra == 0)
1855 wlv.diff_hlf = HLF_TXD; // changed text
1856 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
1857 && wlv.n_extra == 0)
1858 wlv.diff_hlf = HLF_CHD; // changed line
1859 line_attr = HL_ATTR(wlv.diff_hlf);
1860 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1861 && wp->w_p_culopt_flags != CULOPT_NBR
1862 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
1863 && wlv.vcol <= right_curline_col)))
1864 line_attr = hl_combine_attr(
1865 line_attr, HL_ATTR(HLF_CUL));
1866 }
1867#endif
1868
Bram Moolenaara74fda62019-10-19 17:38:03 +02001869#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001870 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001871 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001872 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001873# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001874 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001875 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001876# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001877 // Get syntax attribute.
1878 if (has_syntax)
1879 {
1880 // Get the syntax attribute for the character. If there
1881 // is an error, disable syntax highlighting.
1882 save_did_emsg = did_emsg;
1883 did_emsg = FALSE;
1884
1885 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001886 if (v == prev_syntax_col)
1887 // at same column again
1888 syntax_attr = prev_syntax_attr;
1889 else
1890 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001891# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001892 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001893# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001894 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001895# ifdef FEAT_SPELL
1896 has_spell ? &can_spell :
1897# endif
1898 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001899 prev_syntax_col = v;
1900 prev_syntax_attr = syntax_attr;
1901 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001902
Bram Moolenaar34390282019-10-16 14:38:26 +02001903 if (did_emsg)
1904 {
1905 wp->w_s->b_syn_error = TRUE;
1906 has_syntax = FALSE;
1907 syntax_attr = 0;
1908 }
1909 else
1910 did_emsg = save_did_emsg;
1911# ifdef SYN_TIME_LIMIT
1912 if (wp->w_s->b_syn_slow)
1913 has_syntax = FALSE;
1914# endif
1915
1916 // Need to get the line again, a multi-line regexp may
1917 // have made it invalid.
1918 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1919 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001920 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001921# ifdef FEAT_CONCEAL
1922 // no concealing past the end of the line, it interferes
1923 // with line highlighting
1924 if (*ptr == NUL)
1925 syntax_flags = 0;
1926 else
1927 syntax_flags = get_syntax_info(&syntax_seqnr);
1928# endif
1929 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001930 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001931# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001932 // Combine text property highlight into syntax highlight.
1933 if (text_prop_type != NULL)
1934 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001935 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01001936 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1937 else
1938 syntax_attr = text_prop_attr;
1939 }
1940# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001941#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001942
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001943 // Decide which of the highlight attributes to use.
1944 attr_pri = TRUE;
1945#ifdef LINE_ATTR
1946 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001947 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001948 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02001949 if (!highlight_match)
1950 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01001951 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001952# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001953 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001954# endif
1955 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001956 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001957 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001958 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001959# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001960 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001961# endif
1962 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001963 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001964 || wlv.vcol < fromcol || vcol_prev < fromcol_prev
1965 || wlv.vcol >= tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001966 {
1967 // Use line_attr when not in the Visual or 'incsearch' area
1968 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001969# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001970 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01001971# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001972 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001973# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001974 attr_pri = FALSE;
1975 }
1976#else
1977 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001978 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001979 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001980 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001981#endif
1982 else
1983 {
1984 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001985#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001986 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001987#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001988 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001989#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001990 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001991#ifdef FEAT_PROP_POPUP
1992 // override with text property highlight when "override" is TRUE
1993 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001994 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001995#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001996 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001997
1998 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001999 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002000 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002001 if (wlv.char_attr == 0)
2002 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002003 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002004 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002005 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002006
2007 // Get the next character to put on the screen.
2008
2009 // The "p_extra" points to the extra stuff that is inserted to
2010 // represent special characters (non-printable stuff) and other
2011 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002012 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002013 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2014 // "p_extra[n_extra]".
2015 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002016 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002017 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002018 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002019 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002020 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2021 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002022 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2023 if (enc_utf8 && utf_char2len(c) > 1)
2024 {
2025 mb_utf8 = TRUE;
2026 u8cc[0] = 0;
2027 c = 0xc0;
2028 }
2029 else
2030 mb_utf8 = FALSE;
2031 }
2032 else
2033 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002034 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002035 if (has_mbyte)
2036 {
2037 mb_c = c;
2038 if (enc_utf8)
2039 {
2040 // If the UTF-8 character is more than one byte:
2041 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002042 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002043 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002044 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002045 mb_l = 1;
2046 else if (mb_l > 1)
2047 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002048 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002049 mb_utf8 = TRUE;
2050 c = 0xc0;
2051 }
2052 }
2053 else
2054 {
2055 // if this is a DBCS character, put it in "mb_c"
2056 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002057 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002058 mb_l = 1;
2059 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002060 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002061 }
2062 if (mb_l == 0) // at the NUL at end-of-line
2063 mb_l = 1;
2064
2065 // If a double-width char doesn't fit display a '>' in the
2066 // last column.
2067 if ((
2068# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002069 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002070# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002071 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002072 && (*mb_char2cells)(mb_c) == 2)
2073 {
2074 c = '>';
2075 mb_c = c;
2076 mb_l = 1;
2077 mb_utf8 = FALSE;
2078 multi_attr = HL_ATTR(HLF_AT);
2079#ifdef FEAT_SYN_HL
2080 if (cul_attr)
2081 multi_attr = hl_combine_attr(multi_attr, cul_attr);
2082#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002083 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002084
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002085 // put the pointer back to output the double-width
2086 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002087 ++wlv.n_extra;
2088 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002089 }
2090 else
2091 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002092 wlv.n_extra -= mb_l - 1;
2093 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002094 }
2095 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002096 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002097 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002098 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002099#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002100 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002101 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002102 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002103 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002104 if (search_attr == 0)
2105 search_attr = saved_search_attr;
2106 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002107#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002108 }
2109 else
2110 {
2111#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002112 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002113#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002114 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002115
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002116 // Get a character from the line itself.
2117 c = *ptr;
2118#ifdef FEAT_LINEBREAK
2119 c0 = *ptr;
2120#endif
2121 if (has_mbyte)
2122 {
2123 mb_c = c;
2124 if (enc_utf8)
2125 {
2126 // If the UTF-8 character is more than one byte: Decode it
2127 // into "mb_c".
2128 mb_l = utfc_ptr2len(ptr);
2129 mb_utf8 = FALSE;
2130 if (mb_l > 1)
2131 {
2132 mb_c = utfc_ptr2char(ptr, u8cc);
2133 // Overlong encoded ASCII or ASCII with composing char
2134 // is displayed normally, except a NUL.
2135 if (mb_c < 0x80)
2136 {
2137 c = mb_c;
2138#ifdef FEAT_LINEBREAK
2139 c0 = mb_c;
2140#endif
2141 }
2142 mb_utf8 = TRUE;
2143
2144 // At start of the line we can have a composing char.
2145 // Draw it as a space with a composing char.
2146 if (utf_iscomposing(mb_c))
2147 {
2148 int i;
2149
2150 for (i = Screen_mco - 1; i > 0; --i)
2151 u8cc[i] = u8cc[i - 1];
2152 u8cc[0] = mb_c;
2153 mb_c = ' ';
2154 }
2155 }
2156
2157 if ((mb_l == 1 && c >= 0x80)
2158 || (mb_l >= 1 && mb_c == 0)
2159 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2160 {
2161 // Illegal UTF-8 byte: display as <xx>.
2162 // Non-BMP character : display as ? or fullwidth ?.
2163 transchar_hex(extra, mb_c);
2164# ifdef FEAT_RIGHTLEFT
2165 if (wp->w_p_rl) // reverse
2166 rl_mirror(extra);
2167# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002168 wlv.p_extra = extra;
2169 c = *wlv.p_extra;
2170 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002171 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002172 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2173 wlv.c_extra = NUL;
2174 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002175 if (area_attr == 0 && search_attr == 0)
2176 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002177 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002178 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002179 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002180 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002181 }
2182 }
2183 else if (mb_l == 0) // at the NUL at end-of-line
2184 mb_l = 1;
2185#ifdef FEAT_ARABIC
2186 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2187 {
2188 // Do Arabic shaping.
2189 int pc, pc1, nc;
2190 int pcc[MAX_MCO];
2191
2192 // The idea of what is the previous and next
2193 // character depends on 'rightleft'.
2194 if (wp->w_p_rl)
2195 {
2196 pc = prev_c;
2197 pc1 = prev_c1;
2198 nc = utf_ptr2char(ptr + mb_l);
2199 prev_c1 = u8cc[0];
2200 }
2201 else
2202 {
2203 pc = utfc_ptr2char(ptr + mb_l, pcc);
2204 nc = prev_c;
2205 pc1 = pcc[0];
2206 }
2207 prev_c = mb_c;
2208
2209 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2210 }
2211 else
2212 prev_c = mb_c;
2213#endif
2214 }
2215 else // enc_dbcs
2216 {
2217 mb_l = MB_BYTE2LEN(c);
2218 if (mb_l == 0) // at the NUL at end-of-line
2219 mb_l = 1;
2220 else if (mb_l > 1)
2221 {
2222 // We assume a second byte below 32 is illegal.
2223 // Hopefully this is OK for all double-byte encodings!
2224 if (ptr[1] >= 32)
2225 mb_c = (c << 8) + ptr[1];
2226 else
2227 {
2228 if (ptr[1] == NUL)
2229 {
2230 // head byte at end of line
2231 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002232 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002233 }
2234 else
2235 {
2236 // illegal tail byte
2237 mb_l = 2;
2238 STRCPY(extra, "XX");
2239 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002240 wlv.p_extra = extra;
2241 wlv.n_extra = (int)STRLEN(extra) - 1;
2242 wlv.c_extra = NUL;
2243 wlv.c_final = NUL;
2244 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002245 if (area_attr == 0 && search_attr == 0)
2246 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002247 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002248 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002249 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002250 // save current attr
2251 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002252 }
2253 mb_c = c;
2254 }
2255 }
2256 }
2257 // If a double-width char doesn't fit display a '>' in the
2258 // last column; the character is displayed at the start of the
2259 // next line.
2260 if ((
2261# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002262 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002263# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002264 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002265 && (*mb_char2cells)(mb_c) == 2)
2266 {
2267 c = '>';
2268 mb_c = c;
2269 mb_utf8 = FALSE;
2270 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002271 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002272 // Put pointer back so that the character will be
2273 // displayed at the start of the next line.
2274 --ptr;
2275#ifdef FEAT_CONCEAL
2276 did_decrement_ptr = TRUE;
2277#endif
2278 }
2279 else if (*ptr != NUL)
2280 ptr += mb_l - 1;
2281
2282 // If a double-width char doesn't fit at the left side display
2283 // a '<' in the first column. Don't do this for unprintable
2284 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002285 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002286 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002287 wlv.n_extra = 1;
2288 wlv.c_extra = MB_FILLER_CHAR;
2289 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002290 c = ' ';
2291 if (area_attr == 0 && search_attr == 0)
2292 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002293 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002294 extra_attr = hl_combine_attr(
2295 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002296 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002297 }
2298 mb_c = c;
2299 mb_utf8 = FALSE;
2300 mb_l = 1;
2301 }
2302
2303 }
2304 ++ptr;
2305
2306 if (extra_check)
2307 {
2308#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002309 // Check spelling (unless at the end of the line).
2310 // Only do this when there is no syntax highlighting, the
2311 // @Spell cluster is not used or the current syntax item
2312 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002313 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002314 if (has_spell && v >= word_end && v > cur_checked_col)
2315 {
2316 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002317 // do not calculate cap_col at the end of the line or when
2318 // only white space is following
2319 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002320# ifdef FEAT_SYN_HL
2321 !has_syntax ||
2322# endif
2323 can_spell))
2324 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002325 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002326 int len;
2327 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002328
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002329 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002330 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002331
2332 // Use nextline[] if possible, it has the start of the
2333 // next line concatenated.
2334 if ((prev_ptr - line) - nextlinecol >= 0)
2335 p = nextline + (prev_ptr - line) - nextlinecol;
2336 else
2337 p = prev_ptr;
2338 cap_col -= (int)(prev_ptr - line);
2339 len = spell_check(wp, p, &spell_hlf, &cap_col,
2340 nochange);
2341 word_end = v + len;
2342
2343 // In Insert mode only highlight a word that
2344 // doesn't touch the cursor.
2345 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002346 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002347 && wp->w_cursor.lnum == lnum
2348 && wp->w_cursor.col >=
2349 (colnr_T)(prev_ptr - line)
2350 && wp->w_cursor.col < (colnr_T)word_end)
2351 {
2352 spell_hlf = HLF_COUNT;
2353 spell_redraw_lnum = lnum;
2354 }
2355
2356 if (spell_hlf == HLF_COUNT && p != prev_ptr
2357 && (p - nextline) + len > nextline_idx)
2358 {
2359 // Remember that the good word continues at the
2360 // start of the next line.
2361 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002362 checked_col = (int)((p - nextline)
2363 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002364 }
2365
2366 // Turn index into actual attributes.
2367 if (spell_hlf != HLF_COUNT)
2368 spell_attr = highlight_attr[spell_hlf];
2369
2370 if (cap_col > 0)
2371 {
2372 if (p != prev_ptr
2373 && (p - nextline) + cap_col >= nextline_idx)
2374 {
2375 // Remember that the word in the next line
2376 // must start with a capital.
2377 capcol_lnum = lnum + 1;
2378 cap_col = (int)((p - nextline) + cap_col
2379 - nextline_idx);
2380 }
2381 else
2382 // Compute the actual column.
2383 cap_col += (int)(prev_ptr - line);
2384 }
2385 }
2386 }
2387 if (spell_attr != 0)
2388 {
2389 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002390 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2391 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002392 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002393 wlv.char_attr = hl_combine_attr(spell_attr,
2394 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002395 }
2396#endif
2397#ifdef FEAT_LINEBREAK
2398 // Found last space before word: check for line break.
2399 if (wp->w_p_lbr && c0 == c
2400 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2401 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002402 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2403 : 0;
2404 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002405 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002406
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002407 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002408# ifdef FEAT_PROP_POPUP
2409 // do not want virtual text counted here
2410 cts.cts_has_prop_with_text = FALSE;
2411# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002412 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002413 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002414
2415 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002416 // space for it again.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002417 if (wlv.vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002418 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002419 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2420 if (wlv.n_extra < 0)
2421 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002422 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002423 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002424 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002425 // line break, but for TABs the highlighting should
2426 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002427 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002428
Bram Moolenaar1306b362022-08-06 15:59:06 +01002429 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002430# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002431 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002432 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002433 wp->w_buffer->b_p_vts_array) - 1;
2434# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002435 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002436 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002437# endif
2438
Bram Moolenaar1306b362022-08-06 15:59:06 +01002439 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2440 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002441# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002442 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002443 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002444# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002445 if (VIM_ISWHITE(c))
2446 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002447# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002448 if (c == TAB)
2449 // See "Tab alignment" below.
2450 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002451# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002452 if (!wp->w_p_list)
2453 c = ' ';
2454 }
2455 }
2456#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002457 in_multispace = c == ' '
2458 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2459 if (!in_multispace)
2460 multispace_pos = 0;
2461
Bram Moolenaareed9d462021-02-15 20:38:25 +01002462 // 'list': Change char 160 to 'nbsp' and space to 'space'
2463 // setting in 'listchars'. But not when the character is
2464 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002465 if (wp->w_p_list
2466 && ((((c == 160 && mb_l == 1)
2467 || (mb_utf8
2468 && ((mb_c == 160 && mb_l == 2)
2469 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002470 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002471 || (c == ' '
2472 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002473 && (wp->w_lcs_chars.space
2474 || (in_multispace
2475 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002476 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002477 && ptr - line <= trailcol)))
2478 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002479 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2480 {
2481 c = wp->w_lcs_chars.multispace[multispace_pos++];
2482 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2483 multispace_pos = 0;
2484 }
2485 else
2486 c = (c == ' ') ? wp->w_lcs_chars.space
2487 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002488 if (area_attr == 0 && search_attr == 0)
2489 {
2490 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002491 extra_attr = hl_combine_attr(wlv.win_attr,
2492 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002493 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002494 }
2495 mb_c = c;
2496 if (enc_utf8 && utf_char2len(c) > 1)
2497 {
2498 mb_utf8 = TRUE;
2499 u8cc[0] = 0;
2500 c = 0xc0;
2501 }
2502 else
2503 mb_utf8 = FALSE;
2504 }
2505
zeertzjq2e7cba32022-06-10 15:30:32 +01002506 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2507 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002508 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002509 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2510 && wp->w_lcs_chars.leadmultispace != NULL)
2511 {
2512 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002513 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2514 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002515 multispace_pos = 0;
2516 }
2517
2518 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2519 c = wp->w_lcs_chars.trail;
2520
2521 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2522 c = wp->w_lcs_chars.lead;
2523
zeertzjq2e7cba32022-06-10 15:30:32 +01002524 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002525 c = wp->w_lcs_chars.space;
2526
2527
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002528 if (!attr_pri)
2529 {
2530 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002531 extra_attr = hl_combine_attr(wlv.win_attr,
2532 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002533 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002534 }
2535 mb_c = c;
2536 if (enc_utf8 && utf_char2len(c) > 1)
2537 {
2538 mb_utf8 = TRUE;
2539 u8cc[0] = 0;
2540 c = 0xc0;
2541 }
2542 else
2543 mb_utf8 = FALSE;
2544 }
2545 }
2546
2547 // Handling of non-printable characters.
2548 if (!vim_isprintc(c))
2549 {
2550 // when getting a character from the file, we may have to
2551 // turn it into something else on the way to putting it
2552 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002553 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002554 {
2555 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002556 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002557#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002558 char_u *sbr = get_showbreak_value(wp);
2559
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002560 // only adjust the tab_len, when at the first column
2561 // after the showbreak value was drawn
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002562 if (*sbr != NUL && wlv.vcol == vcol_sbr && wp->w_p_wrap)
2563 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002564#endif
2565 // tab amount depends on current column
2566#ifdef FEAT_VARTABS
2567 tab_len = tabstop_padding(vcol_adjusted,
2568 wp->w_buffer->b_p_ts,
2569 wp->w_buffer->b_p_vts_array) - 1;
2570#else
2571 tab_len = (int)wp->w_buffer->b_p_ts
2572 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2573#endif
2574
2575#ifdef FEAT_LINEBREAK
2576 if (!wp->w_p_lbr || !wp->w_p_list)
2577#endif
2578 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002579 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002580#ifdef FEAT_LINEBREAK
2581 else
2582 {
2583 char_u *p;
2584 int len;
2585 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002586 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002587
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002588# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002589 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002590 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002591 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002592
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002593 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002594 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002595 && old_boguscols > 0
2596 && wlv.n_extra > tab_len)
2597 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002598# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002599 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002600 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002601 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002602 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002603 if (wp->w_lcs_chars.tab3)
2604 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002605 if (wlv.n_extra > 0)
2606 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002607 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002608 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002609 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002610 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002611 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002612 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002613 vim_memset(p, ' ', len);
2614 p[len] = NUL;
2615 vim_free(p_extra_free);
2616 p_extra_free = p;
2617 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002618 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002619 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002620
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002621 if (*p == NUL)
2622 {
2623 tab_len = i;
2624 break;
2625 }
2626
2627 // if tab3 is given, use it for the last char
2628 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2629 lcs = wp->w_lcs_chars.tab3;
2630 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002631 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002632 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002633 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002634 wlv.p_extra = p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002635# ifdef FEAT_CONCEAL
2636 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2637 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002638 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002639 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002640# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002641 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002642 }
2643#endif
2644#ifdef FEAT_CONCEAL
2645 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002646 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002647
2648 // Tab alignment should be identical regardless of
2649 // 'conceallevel' value. So tab compensates of all
2650 // previous concealed characters, and thus resets
2651 // vcol_off and boguscols accumulated so far in the
2652 // line. Note that the tab can be longer than
2653 // 'tabstop' when there are concealed characters.
2654 FIX_FOR_BOGUSCOLS;
2655
2656 // Make sure, the highlighting for the tab char will be
2657 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002658 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002659 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002660 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002661 tab_len += vc_saved;
2662 }
2663#endif
2664 mb_utf8 = FALSE; // don't draw as UTF-8
2665 if (wp->w_p_list)
2666 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002667 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002668 ? wp->w_lcs_chars.tab3
2669 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002670#ifdef FEAT_LINEBREAK
2671 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002672 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002673 else
2674#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002675 wlv.c_extra = wp->w_lcs_chars.tab2;
2676 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002677 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002678 extra_attr = hl_combine_attr(wlv.win_attr,
2679 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002680 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002681 mb_c = c;
2682 if (enc_utf8 && utf_char2len(c) > 1)
2683 {
2684 mb_utf8 = TRUE;
2685 u8cc[0] = 0;
2686 c = 0xc0;
2687 }
2688 }
2689 else
2690 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002691 wlv.c_final = NUL;
2692 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002693 c = ' ';
2694 }
2695 }
2696 else if (c == NUL
2697 && (wp->w_p_list
2698 || ((fromcol >= 0 || fromcol_prev >= 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002699 && tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002700 && VIsual_mode != Ctrl_V
2701 && (
2702# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002703 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002704# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002705 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002706 && !(noinvcur
2707 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002708 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002709 && lcs_eol_one > 0)
2710 {
2711 // Display a '$' after the line or highlight an extra
2712 // character if the line break is included.
2713#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2714 // For a diff line the highlighting continues after the
2715 // "$".
2716 if (
2717# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002718 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002719# ifdef LINE_ATTR
2720 &&
2721# endif
2722# endif
2723# ifdef LINE_ATTR
2724 line_attr == 0
2725# endif
2726 )
2727#endif
2728 {
2729 // In virtualedit, visual selections may extend
2730 // beyond end of line.
2731 if (area_highlighting && virtual_active()
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002732 && tocol != MAXCOL && wlv.vcol < tocol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002733 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002734 else
2735 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002736 wlv.p_extra = at_end_str;
2737 wlv.n_extra = 1;
2738 wlv.c_extra = NUL;
2739 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002740 }
2741 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002742 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2743 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002744 else
2745 c = ' ';
2746 lcs_eol_one = -1;
2747 --ptr; // put it back at the NUL
2748 if (!attr_pri)
2749 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002750 extra_attr = hl_combine_attr(wlv.win_attr,
2751 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002752 n_attr = 1;
2753 }
2754 mb_c = c;
2755 if (enc_utf8 && utf_char2len(c) > 1)
2756 {
2757 mb_utf8 = TRUE;
2758 u8cc[0] = 0;
2759 c = 0xc0;
2760 }
2761 else
2762 mb_utf8 = FALSE; // don't draw as UTF-8
2763 }
2764 else if (c != NUL)
2765 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002766 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2767 if (wlv.n_extra == 0)
2768 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002769#ifdef FEAT_RIGHTLEFT
2770 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002771 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002772#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002773 wlv.c_extra = NUL;
2774 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002775#ifdef FEAT_LINEBREAK
2776 if (wp->w_p_lbr)
2777 {
2778 char_u *p;
2779
Bram Moolenaar1306b362022-08-06 15:59:06 +01002780 c = *wlv.p_extra;
2781 p = alloc(wlv.n_extra + 1);
2782 vim_memset(p, ' ', wlv.n_extra);
2783 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2784 p[wlv.n_extra] = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002785 vim_free(p_extra_free);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002786 p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002787 }
2788 else
2789#endif
2790 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002791 wlv.n_extra = byte2cells(c) - 1;
2792 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002793 }
2794 if (!attr_pri)
2795 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002796 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002797 extra_attr = hl_combine_attr(wlv.win_attr,
2798 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002799 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002800 }
2801 mb_utf8 = FALSE; // don't draw as UTF-8
2802 }
2803 else if (VIsual_active
2804 && (VIsual_mode == Ctrl_V
2805 || VIsual_mode == 'v')
2806 && virtual_active()
2807 && tocol != MAXCOL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002808 && wlv.vcol < tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002809 && (
2810#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002811 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002812#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002813 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002814 {
2815 c = ' ';
2816 --ptr; // put it back at the NUL
2817 }
2818#if defined(LINE_ATTR)
2819 else if ((
2820# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002821 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002822# endif
2823# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002824 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002825# endif
2826 line_attr != 0
2827 ) && (
2828# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002829 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002830# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002831 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002832# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002833 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002834# endif
2835 < wp->w_width)))
2836 {
2837 // Highlight until the right side of the window
2838 c = ' ';
2839 --ptr; // put it back at the NUL
2840
2841 // Remember we do the char for line highlighting.
2842 ++did_line_attr;
2843
2844 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01002845 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002846 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002847 || (wp->w_p_list &&
2848 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002849 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002850# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002851 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002852 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002853 wlv.diff_hlf = HLF_CHD;
2854 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002855 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002856 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002857 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2858 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01002859 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002860 || (wlv.vcol >= left_curline_col
2861 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002862 wlv.char_attr = hl_combine_attr(
2863 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002864 }
2865 }
2866# endif
2867# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002868 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002869 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002870 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002871 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2872 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002873 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002874 if (!wlv.cul_screenline
2875 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002876 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002877 wlv.char_attr = hl_combine_attr(
2878 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002879 }
2880 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002881 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2882 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002883 }
2884# endif
2885 }
2886#endif
2887 }
2888
2889#ifdef FEAT_CONCEAL
2890 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01002891 && (wp != curwin || lnum != wp->w_cursor.lnum
2892 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002893 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2894 && !(lnum_in_visual_area
2895 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2896 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002897 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01002898 if (((prev_syntax_id != syntax_seqnr
2899 && (syntax_flags & HL_CONCEAL) != 0)
2900 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002901 && (syn_get_sub_char() != NUL
2902 || (has_match_conc && match_conc)
2903 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002904 && wp->w_p_cole != 3)
2905 {
2906 // First time at this concealed item: display one
2907 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002908 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002909 c = match_conc;
2910 else if (syn_get_sub_char() != NUL)
2911 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01002912 else if (wp->w_lcs_chars.conceal != NUL)
2913 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002914 else
2915 c = ' ';
2916
2917 prev_syntax_id = syntax_seqnr;
2918
Bram Moolenaar1306b362022-08-06 15:59:06 +01002919 if (wlv.n_extra > 0)
2920 wlv.vcol_off += wlv.n_extra;
2921 wlv.vcol += wlv.n_extra;
2922 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002923 {
2924# ifdef FEAT_RIGHTLEFT
2925 if (wp->w_p_rl)
2926 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002927 wlv.col -= wlv.n_extra;
2928 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002929 }
2930 else
2931# endif
2932 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002933 wlv.boguscols += wlv.n_extra;
2934 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002935 }
2936 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002937 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002938 n_attr = 0;
2939 }
2940 else if (n_skip == 0)
2941 {
2942 is_concealing = TRUE;
2943 n_skip = 1;
2944 }
2945 mb_c = c;
2946 if (enc_utf8 && utf_char2len(c) > 1)
2947 {
2948 mb_utf8 = TRUE;
2949 u8cc[0] = 0;
2950 c = 0xc0;
2951 }
2952 else
2953 mb_utf8 = FALSE; // don't draw as UTF-8
2954 }
2955 else
2956 {
2957 prev_syntax_id = 0;
2958 is_concealing = FALSE;
2959 }
2960
2961 if (n_skip > 0 && did_decrement_ptr)
2962 // not showing the '>', put pointer back to avoid getting stuck
2963 ++ptr;
2964
2965#endif // FEAT_CONCEAL
2966 }
2967
2968#ifdef FEAT_CONCEAL
2969 // In the cursor line and we may be concealing characters: correct
2970 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002971 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002972 && wp == curwin && lnum == wp->w_cursor.lnum
2973 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002974 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002975 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002976# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002977 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002978 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002979 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002980# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002981 wp->w_wcol = wlv.col - wlv.boguscols;
2982 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002983 did_wcol = TRUE;
2984 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002985# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01002986 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002987# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002988 }
2989#endif
2990
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002991 // Use "extra_attr", but don't override visual selection highlighting,
2992 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002993 // Don't use "extra_attr" until n_attr_skip is zero.
2994 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01002995 && wlv.draw_state == WL_LINE
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002996 && (!attr_pri || (text_prop_flags & PT_FLAG_OVERRIDE)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002997 {
2998#ifdef LINE_ATTR
2999 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003000 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003001 else
3002#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003003 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003004 }
3005
3006#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3007 // XIM don't send preedit_start and preedit_end, but they send
3008 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3009 // im_is_preediting() here.
3010 if (p_imst == IM_ON_THE_SPOT
3011 && xic != NULL
3012 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003013 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003014 && !p_imdisable
3015 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003016 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003017 {
3018 colnr_T tcol;
3019
3020 if (preedit_end_col == MAXCOL)
3021 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3022 else
3023 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003024 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003025 {
3026 if (feedback_old_attr < 0)
3027 {
3028 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003029 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003030 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003031 wlv.char_attr = im_get_feedback_attr(feedback_col);
3032 if (wlv.char_attr < 0)
3033 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003034 feedback_col++;
3035 }
3036 else if (feedback_old_attr >= 0)
3037 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003038 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003039 feedback_old_attr = -1;
3040 feedback_col = 0;
3041 }
3042 }
3043#endif
3044 // Handle the case where we are in column 0 but not on the first
3045 // character of the line and the user wants us to show us a
3046 // special character (via 'listchars' option "precedes:<char>".
3047 if (lcs_prec_todo != NUL
3048 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003049 && (wp->w_p_wrap ?
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003050 (wp->w_skipcol > 0 && wlv.row == 0) :
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003051 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003052#ifdef FEAT_DIFF
3053 && filler_todo <= 0
3054#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003055 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003056 && c != NUL)
3057 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003058 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003059 lcs_prec_todo = NUL;
3060 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3061 {
3062 // Double-width character being overwritten by the "precedes"
3063 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003064 wlv.c_extra = MB_FILLER_CHAR;
3065 wlv.c_final = NUL;
3066 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003067 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003068 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003069 }
3070 mb_c = c;
3071 if (enc_utf8 && utf_char2len(c) > 1)
3072 {
3073 mb_utf8 = TRUE;
3074 u8cc[0] = 0;
3075 c = 0xc0;
3076 }
3077 else
3078 mb_utf8 = FALSE; // don't draw as UTF-8
3079 if (!attr_pri)
3080 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003081 saved_attr3 = wlv.char_attr; // save current attr
3082 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003083 n_attr3 = 1;
3084 }
3085 }
3086
3087 // At end of the text line or just after the last character.
3088 if ((c == NUL
3089#if defined(LINE_ATTR)
3090 || did_line_attr == 1
3091#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003092 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003093 {
3094#ifdef FEAT_SEARCH_EXTRA
3095 // flag to indicate whether prevcol equals startcol of search_hl or
3096 // one of the matches
3097 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3098 (long)(ptr - line) - (c == NUL));
3099#endif
3100 // Invert at least one char, used for Visual and empty line or
3101 // highlight match at end of line. If it's beyond the last
3102 // char on the screen, just overwrite that one (tricky!) Not
3103 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003104 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003105 && ((area_attr != 0 && wlv.vcol == fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003106 && (VIsual_mode != Ctrl_V
3107 || lnum == VIsual.lnum
3108 || lnum == curwin->w_cursor.lnum)
3109 && c == NUL)
3110#ifdef FEAT_SEARCH_EXTRA
3111 // highlight 'hlsearch' match at end of line
3112 || (prevcol_hl_flag
3113# ifdef FEAT_SYN_HL
3114 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3115 && !(wp == curwin && VIsual_active))
3116# endif
3117# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003118 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003119# endif
3120# if defined(LINE_ATTR)
3121 && did_line_attr <= 1
3122# endif
3123 )
3124#endif
3125 ))
3126 {
3127 int n = 0;
3128
3129#ifdef FEAT_RIGHTLEFT
3130 if (wp->w_p_rl)
3131 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003132 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003133 n = 1;
3134 }
3135 else
3136#endif
3137 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003138 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003139 n = -1;
3140 }
3141 if (n != 0)
3142 {
3143 // At the window boundary, highlight the last character
3144 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003145 wlv.off += n;
3146 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003147 }
3148 else
3149 {
3150 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003151 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003152 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003153 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003154 }
3155#ifdef FEAT_SEARCH_EXTRA
3156 if (area_attr == 0)
3157 {
3158 // Use attributes from match with highest priority among
3159 // 'search_hl' and the match list.
3160 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003161 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003162 }
3163#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003164 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003165 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003166#ifdef FEAT_RIGHTLEFT
3167 if (wp->w_p_rl)
3168 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003169 --wlv.col;
3170 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003171 }
3172 else
3173#endif
3174 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003175 ++wlv.col;
3176 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003177 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003178 ++wlv.vcol;
3179 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003180 }
3181 }
3182
3183 // At end of the text line.
3184 if (c == NUL)
3185 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003186 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003187
3188 // Update w_cline_height and w_cline_folded if the cursor line was
3189 // updated (saves a call to plines() later).
3190 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3191 {
3192 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003193 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003194#ifdef FEAT_FOLDING
3195 curwin->w_cline_folded = FALSE;
3196#endif
3197 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3198 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003199 break;
3200 }
3201
3202 // Show "extends" character from 'listchars' if beyond the line end and
3203 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003204 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003205 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003206 && wp->w_p_list
3207 && !wp->w_p_wrap
3208#ifdef FEAT_DIFF
3209 && filler_todo <= 0
3210#endif
3211 && (
3212#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003213 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003214#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003215 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003216 && (*ptr != NUL
3217 || (wp->w_p_list && lcs_eol_one > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003218 || (wlv.n_extra && (wlv.c_extra != NUL
3219 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003220 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003221 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003222 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003223 mb_c = c;
3224 if (enc_utf8 && utf_char2len(c) > 1)
3225 {
3226 mb_utf8 = TRUE;
3227 u8cc[0] = 0;
3228 c = 0xc0;
3229 }
3230 else
3231 mb_utf8 = FALSE;
3232 }
3233
3234#ifdef FEAT_SYN_HL
3235 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003236 if (wlv.draw_color_col)
3237 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003238
3239 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3240 // highlight the cursor position itself.
3241 // Also highlight the 'colorcolumn' if it is different than
3242 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003243 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3244 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003245 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003246 if (((wlv.draw_state == WL_LINE
3247 || wlv.draw_state == WL_BRI
3248 || wlv.draw_state == WL_SBR)
3249 && !lnum_in_visual_area
3250 && search_attr == 0
3251 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003252# ifdef FEAT_DIFF
3253 && filler_todo <= 0
3254# endif
3255 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003256 {
3257 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3258 && lnum != wp->w_cursor.lnum)
3259 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003260 vcol_save_attr = wlv.char_attr;
3261 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3262 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003263 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003264 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003265 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003266 vcol_save_attr = wlv.char_attr;
3267 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003268 }
3269 }
3270#endif
3271
3272 // Store character to be displayed.
3273 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003274 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003275 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003276 {
3277 // Store the character.
3278#if defined(FEAT_RIGHTLEFT)
3279 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3280 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003281 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003282 --wlv.off;
3283 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003284 }
3285#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003286 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003287 if (enc_dbcs == DBCS_JPNU)
3288 {
3289 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003290 ScreenLines[wlv.off] = 0x8e;
3291 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003292 }
3293 else if (enc_utf8)
3294 {
3295 if (mb_utf8)
3296 {
3297 int i;
3298
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003299 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003300 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003301 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003302 for (i = 0; i < Screen_mco; ++i)
3303 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003304 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003305 if (u8cc[i] == 0)
3306 break;
3307 }
3308 }
3309 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003310 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003311 }
3312 if (multi_attr)
3313 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003314 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003315 multi_attr = 0;
3316 }
3317 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003318 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003319
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003320 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003321
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003322 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3323 {
3324 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003325 ++wlv.off;
3326 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003327 if (enc_utf8)
3328 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003329 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003330 else
3331 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003332 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003333 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003334#ifdef FEAT_DIFF
3335 && filler_todo <= 0
3336#endif
3337 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003338 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003339 // When "tocol" is halfway a character, set it to the end of
3340 // the character, otherwise highlighting won't stop.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003341 if (tocol == wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003342 ++tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003343
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003344 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003345
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003346#ifdef FEAT_RIGHTLEFT
3347 if (wp->w_p_rl)
3348 {
3349 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003350 --wlv.off;
3351 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003352 }
3353#endif
3354 }
3355#ifdef FEAT_RIGHTLEFT
3356 if (wp->w_p_rl)
3357 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003358 --wlv.off;
3359 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003360 }
3361 else
3362#endif
3363 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003364 ++wlv.off;
3365 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003366 }
3367 }
3368#ifdef FEAT_CONCEAL
3369 else if (wp->w_p_cole > 0 && is_concealing)
3370 {
3371 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003372 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003373 if (wlv.n_extra > 0)
3374 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003375 if (wp->w_p_wrap)
3376 {
3377 // Special voodoo required if 'wrap' is on.
3378 //
3379 // Advance the column indicator to force the line
3380 // drawing to wrap early. This will make the line
3381 // take up the same screen space when parts are concealed,
3382 // so that cursor line computations aren't messed up.
3383 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003384 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003385 // trailing junk to be written out of the screen line
3386 // we are building, 'boguscols' keeps track of the number
3387 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003388 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003389 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003390 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003391# ifdef FEAT_RIGHTLEFT
3392 if (wp->w_p_rl)
3393 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003394 wlv.col -= wlv.n_extra;
3395 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003396 }
3397 else
3398# endif
3399 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003400 wlv.col += wlv.n_extra;
3401 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003402 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003403 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003404 n_attr = 0;
3405 }
3406
3407
3408 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3409 {
3410 // Need to fill two screen columns.
3411# ifdef FEAT_RIGHTLEFT
3412 if (wp->w_p_rl)
3413 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003414 --wlv.boguscols;
3415 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003416 }
3417 else
3418# endif
3419 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003420 ++wlv.boguscols;
3421 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003422 }
3423 }
3424
3425# ifdef FEAT_RIGHTLEFT
3426 if (wp->w_p_rl)
3427 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003428 --wlv.boguscols;
3429 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003430 }
3431 else
3432# endif
3433 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003434 ++wlv.boguscols;
3435 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003436 }
3437 }
3438 else
3439 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003440 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003441 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003442 wlv.vcol += wlv.n_extra;
3443 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003444 n_attr = 0;
3445 }
3446 }
3447
3448 }
3449#endif // FEAT_CONCEAL
3450 else
3451 --n_skip;
3452
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003453 // Only advance the "wlv.vcol" when after the 'number' or
3454 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003455 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003456#ifdef FEAT_DIFF
3457 && filler_todo <= 0
3458#endif
3459 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003460 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003461
3462#ifdef FEAT_SYN_HL
3463 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003464 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003465#endif
3466
3467 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003468 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3469 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003470
3471 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003472 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003473 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003474 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003475 if (n_attr_skip > 0)
3476 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003477
3478 // At end of screen line and there is more to come: Display the line
3479 // so far. If there is no more to display it is caught above.
3480 if ((
3481#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003482 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003483#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003484 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003485 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003486 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003487#ifdef FEAT_DIFF
3488 || filler_todo > 0
3489#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003490#ifdef FEAT_PROP_POPUP
3491 || text_prop_follows
3492#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003493 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003494 && wlv.p_extra != at_end_str)
3495 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3496 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003497 )
3498 {
3499#ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003500 screen_line(wp, wlv.screen_row, wp->w_wincol,
3501 wlv.col - wlv.boguscols,
3502 wp->w_width, wlv.screen_line_flags);
3503 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003504#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003505 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col,
3506 wp->w_width, wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003507#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003508 ++wlv.row;
3509 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003510
3511 // When not wrapping and finished diff lines, or when displayed
3512 // '$' and highlighting until last column, break here.
3513 if ((!wp->w_p_wrap
3514#ifdef FEAT_DIFF
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003515 && filler_todo <= 0
3516#endif
3517#ifdef FEAT_PROP_POPUP
3518 && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003519#endif
3520 ) || lcs_eol_one == -1)
3521 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003522#ifdef FEAT_PROP_POPUP
Bram Moolenaar83bf11a2022-08-06 22:23:40 +01003523 if (!wp->w_p_wrap && text_prop_follows)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003524 {
3525 // do not output more of the line, only the "below" prop
3526 ptr += STRLEN(ptr);
3527# ifdef FEAT_LINEBREAK
3528 dont_use_showbreak = TRUE;
3529# endif
3530 }
3531#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003532
3533 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003534 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003535#ifdef FEAT_DIFF
3536 && filler_todo <= 0
3537#endif
3538 )
3539 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003540 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3541 draw_vsep_win(wp, wlv.row);
3542 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003543 }
3544
3545 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003546 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003547 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003548 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003549 break;
3550 }
3551
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003552 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003553#ifdef FEAT_DIFF
3554 && filler_todo <= 0
3555#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003556#ifdef FEAT_PROP_POPUP
3557 && !text_prop_follows
3558#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003559 && wp->w_width == Columns)
3560 {
3561 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003562 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003563
3564 // Special trick to make copy/paste of wrapped lines work with
3565 // xterm/screen: write an extra character beyond the end of
3566 // the line. This will work with all terminal types
3567 // (regardless of the xn,am settings).
3568 // Only do this on a fast tty.
3569 // Only do this if the cursor is on the current line
3570 // (something has been written in it).
3571 // Don't do this for the GUI.
3572 // Don't do this for double-width characters.
3573 // Don't do this for a window not at the right screen border.
3574 if (p_tf
3575#ifdef FEAT_GUI
3576 && !gui.in_use
3577#endif
3578 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003579 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3580 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003581 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003582 || (*mb_off2cells)(
3583 LineOffset[wlv.screen_row - 1]
3584 + (int)Columns - 2,
3585 LineOffset[wlv.screen_row]
3586 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003587 {
3588 // First make sure we are at the end of the screen line,
3589 // then output the same character again to let the
3590 // terminal know about the wrap. If the terminal doesn't
3591 // auto-wrap, we overwrite the character.
3592 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003593 screen_char(LineOffset[wlv.screen_row - 1]
3594 + (unsigned)Columns - 1,
3595 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003596
3597 // When there is a multi-byte character, just output a
3598 // space to keep it simple.
3599 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003600 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003601 out_char(' ');
3602 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003603 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003604 + (Columns - 1)]);
3605 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003606 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003607 screen_start(); // don't know where cursor is now
3608 }
3609 }
3610
Bram Moolenaar1306b362022-08-06 15:59:06 +01003611 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003612
Bram Moolenaareed9d462021-02-15 20:38:25 +01003613 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003614#ifdef FEAT_LINEBREAK
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003615 if (!dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003616# ifdef FEAT_DIFF
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003617 && filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003618# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003619 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003620 need_showbreak = TRUE;
3621#endif
3622#ifdef FEAT_DIFF
3623 --filler_todo;
3624 // When the filler lines are actually below the last line of the
3625 // file, don't draw the line itself, break here.
3626 if (filler_todo == 0 && wp->w_botfill)
3627 break;
3628#endif
3629 }
3630
3631 } // for every character in the line
3632
3633#ifdef FEAT_SPELL
3634 // After an empty line check first word for capital.
3635 if (*skipwhite(line) == NUL)
3636 {
3637 capcol_lnum = lnum + 1;
3638 cap_col = 0;
3639 }
3640#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003641#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003642 vim_free(text_props);
3643 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003644 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003645#endif
3646
3647 vim_free(p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003648 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003649}