blob: 2b482bb2db3428c6a009fcac070878b2d73059bf [file] [log] [blame]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * drawline.c: Functions for drawing window lines on the screen.
12 * This is the middle level, drawscreen. is the higher level and screen.c the
13 * lower level.
14 */
15
16#include "vim.h"
17
18#ifdef FEAT_SYN_HL
19/*
20 * Advance **color_cols and return TRUE when there are columns to draw.
21 */
22 static int
23advance_color_col(int vcol, int **color_cols)
24{
25 while (**color_cols >= 0 && vcol > **color_cols)
26 ++*color_cols;
27 return (**color_cols >= 0);
28}
29#endif
30
31#ifdef FEAT_SYN_HL
32/*
33 * Used when 'cursorlineopt' contains "screenline": compute the margins between
34 * which the highlighting is used.
35 */
36 static void
37margin_columns_win(win_T *wp, int *left_col, int *right_col)
38{
39 // cache previous calculations depending on w_virtcol
40 static int saved_w_virtcol;
41 static win_T *prev_wp;
42 static int prev_left_col;
43 static int prev_right_col;
44 static int prev_col_off;
45
46 int cur_col_off = win_col_off(wp);
47 int width1;
48 int width2;
49
50 if (saved_w_virtcol == wp->w_virtcol
51 && prev_wp == wp && prev_col_off == cur_col_off)
52 {
53 *right_col = prev_right_col;
54 *left_col = prev_left_col;
55 return;
56 }
57
58 width1 = wp->w_width - cur_col_off;
59 width2 = width1 + win_col_off2(wp);
60
61 *left_col = 0;
62 *right_col = width1;
63
64 if (wp->w_virtcol >= (colnr_T)width1)
65 *right_col = width1 + ((wp->w_virtcol - width1) / width2 + 1) * width2;
66 if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0)
67 *left_col = (wp->w_virtcol - width1) / width2 * width2 + width1;
68
69 // cache values
70 prev_left_col = *left_col;
71 prev_right_col = *right_col;
72 prev_wp = wp;
73 saved_w_virtcol = wp->w_virtcol;
74 prev_col_off = cur_col_off;
75}
76#endif
77
Bram Moolenaar1306b362022-08-06 15:59:06 +010078// structure with variables passed between win_line() and other functions
79typedef struct {
80 int draw_state; // what to draw next
81
82 linenr_T lnum; // line number to be drawn
83
84 int startrow; // first row in the window to be drawn
85 int row; // row in the window, excl w_winrow
86 int screen_row; // row on the screen, incl w_winrow
87
88 long vcol; // virtual column, before wrapping
89 int col; // visual column on screen, after wrapping
90#ifdef FEAT_CONCEAL
91 int boguscols; // nonexistent columns added to "col" to force
92 // wrapping
93 int vcol_off; // offset for concealed characters
94#endif
95#ifdef FEAT_SYN_HL
96 int draw_color_col; // highlight colorcolumn
97 int *color_cols; // pointer to according columns array
98#endif
99 int eol_hl_off; // 1 if highlighted char after EOL
100
101 unsigned off; // offset in ScreenLines/ScreenAttrs
102
103 int win_attr; // background for the whole window, except
104 // margins and "~" lines.
105
106 int screen_line_flags; // flags for screen_line()
107
108 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
109 int cul_screenline;
110
111 int char_attr; // attributes for the next character
112
113 int n_extra; // number of extra bytes
114 char_u *p_extra; // string of extra chars, plus NUL, only used
115 // when c_extra and c_final are NUL
116 int c_extra; // extra chars, all the same
117 int c_final; // final char, mandatory if set
118
119 // saved "extra" items for when draw_state becomes WL_LINE (again)
120 int saved_n_extra;
121 char_u *saved_p_extra;
122 int saved_c_extra;
123 int saved_c_final;
124 int saved_char_attr;
125
126#ifdef FEAT_DIFF
127 hlf_T diff_hlf; // type of diff highlighting
128#endif
129} winlinevars_T;
130
131// draw_state values for items that are drawn in sequence:
132#define WL_START 0 // nothing done yet, must be zero
133#ifdef FEAT_CMDWIN
134# define WL_CMDLINE (WL_START + 1) // cmdline window column
135#else
136# define WL_CMDLINE WL_START
137#endif
138#ifdef FEAT_FOLDING
139# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
140#else
141# define WL_FOLD WL_CMDLINE
142#endif
143#ifdef FEAT_SIGNS
144# define WL_SIGN (WL_FOLD + 1) // column for signs
145#else
146# define WL_SIGN WL_FOLD // column for signs
147#endif
148#define WL_NR (WL_SIGN + 1) // line number
149#ifdef FEAT_LINEBREAK
150# define WL_BRI (WL_NR + 1) // 'breakindent'
151#else
152# define WL_BRI WL_NR
153#endif
154#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
155# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
156#else
157# define WL_SBR WL_BRI
158#endif
159#define WL_LINE (WL_SBR + 1) // text in the line
160
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200161#ifdef FEAT_SIGNS
162/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000163 * Return TRUE if CursorLineSign highlight is to be used.
164 */
165 static int
166use_cursor_line_sign(win_T *wp, linenr_T lnum)
167{
168 return wp->w_p_cul
169 && lnum == wp->w_cursor.lnum
170 && (wp->w_p_culopt_flags & CULOPT_NBR);
171}
172
173/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200174 * Get information needed to display the sign in line 'lnum' in window 'wp'.
175 * If 'nrcol' is TRUE, the sign is going to be displayed in the number column.
176 * Otherwise the sign is going to be displayed in the sign column.
177 */
178 static void
179get_sign_display_info(
180 int nrcol,
181 win_T *wp,
Bram Moolenaare413ea02021-11-24 16:20:13 +0000182 linenr_T lnum,
Bram Moolenaar1306b362022-08-06 15:59:06 +0100183 winlinevars_T *wlv,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200184 sign_attrs_T *sattr,
185 int wcr_attr,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200186 int filler_lines UNUSED,
187 int filler_todo UNUSED,
Bram Moolenaar1306b362022-08-06 15:59:06 +0100188 char_u *extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200189{
190 int text_sign;
191# ifdef FEAT_SIGN_ICONS
192 int icon_sign;
193# endif
194
195 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100196 wlv->c_extra = ' ';
197 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200198 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100199 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200200 else
201 {
Bram Moolenaare413ea02021-11-24 16:20:13 +0000202 if (use_cursor_line_sign(wp, lnum))
Bram Moolenaar1306b362022-08-06 15:59:06 +0100203 wlv->char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000204 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100205 wlv->char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_SC));
206 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200207 }
208
Bram Moolenaar1306b362022-08-06 15:59:06 +0100209 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200210#ifdef FEAT_DIFF
211 + filler_lines && filler_todo <= 0
212#endif
213 )
214 {
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200215 text_sign = (sattr->sat_text != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200216# ifdef FEAT_SIGN_ICONS
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200217 icon_sign = (sattr->sat_icon != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200218 if (gui.in_use && icon_sign != 0)
219 {
220 // Use the image in this position.
221 if (nrcol)
222 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100223 wlv->c_extra = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200224 sprintf((char *)extra, "%-*c ", number_width(wp), SIGN_BYTE);
Bram Moolenaar1306b362022-08-06 15:59:06 +0100225 wlv->p_extra = extra;
226 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200227 }
228 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100229 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200230# ifdef FEAT_NETBEANS_INTG
231 if (netbeans_active() && (buf_signcount(wp->w_buffer, lnum) > 1))
232 {
233 if (nrcol)
234 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100235 wlv->c_extra = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200236 sprintf((char *)extra, "%-*c ", number_width(wp),
237 MULTISIGN_BYTE);
Bram Moolenaar1306b362022-08-06 15:59:06 +0100238 wlv->p_extra = extra;
239 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200240 }
241 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100242 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200243 }
244# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100245 wlv->c_final = NUL;
246 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200247 }
248 else
249# endif
250 if (text_sign != 0)
251 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100252 wlv->p_extra = sattr->sat_text;
253 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200254 {
255 if (nrcol)
256 {
257 int n, width = number_width(wp) - 2;
258
259 for (n = 0; n < width; n++)
260 extra[n] = ' ';
261 extra[n] = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100262 STRCAT(extra, wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200263 STRCAT(extra, " ");
Bram Moolenaar1306b362022-08-06 15:59:06 +0100264 wlv->p_extra = extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200265 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100266 wlv->c_extra = NUL;
267 wlv->c_final = NUL;
268 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200269 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000270
271 if (use_cursor_line_sign(wp, lnum) && sattr->sat_culhl > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100272 wlv->char_attr = sattr->sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000273 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100274 wlv->char_attr = sattr->sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200275 }
276 }
277}
278#endif
279
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100280#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200281static textprop_T *current_text_props = NULL;
282static buf_T *current_buf = NULL;
283
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100284/*
285 * Function passed to qsort() to sort text properties.
286 * Return 1 if "s1" has priority over "s2", -1 if the other way around, zero if
287 * both have the same priority.
288 */
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200289 static int
290text_prop_compare(const void *s1, const void *s2)
291{
292 int idx1, idx2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100293 textprop_T *tp1, *tp2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200294 proptype_T *pt1, *pt2;
295 colnr_T col1, col2;
296
297 idx1 = *(int *)s1;
298 idx2 = *(int *)s2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100299 tp1 = &current_text_props[idx1];
300 tp2 = &current_text_props[idx2];
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100301 col1 = tp1->tp_col;
302 col2 = tp2->tp_col;
303 if (col1 == MAXCOL && col2 == MAXCOL)
304 {
305 int flags1 = 0;
306 int flags2 = 0;
307
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100308 // both props add text are after the line, order on 0: after (default),
309 // 1: right, 2: below (comes last)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100310 if (tp1->tp_flags & TP_FLAG_ALIGN_RIGHT)
311 flags1 = 1;
312 if (tp1->tp_flags & TP_FLAG_ALIGN_BELOW)
313 flags1 = 2;
314 if (tp2->tp_flags & TP_FLAG_ALIGN_RIGHT)
315 flags2 = 1;
316 if (tp2->tp_flags & TP_FLAG_ALIGN_BELOW)
317 flags2 = 2;
318 if (flags1 != flags2)
319 return flags1 < flags2 ? 1 : -1;
320 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100321
322 // property that inserts text has priority over one that doesn't
323 if ((tp1->tp_id < 0) != (tp2->tp_id < 0))
324 return tp1->tp_id < 0 ? 1 : -1;
325
326 // check highest priority, defined by the type
Bram Moolenaardb9b96d2022-08-06 17:38:53 +0100327 pt1 = text_prop_type_by_id(current_buf, tp1->tp_type);
328 pt2 = text_prop_type_by_id(current_buf, tp2->tp_type);
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100329 if (pt1 != pt2)
330 {
331 if (pt1 == NULL)
332 return -1;
333 if (pt2 == NULL)
334 return 1;
335 if (pt1->pt_priority != pt2->pt_priority)
336 return pt1->pt_priority > pt2->pt_priority ? 1 : -1;
337 }
338
339 // same priority, one that starts first wins
340 if (col1 != col2)
341 return col1 < col2 ? 1 : -1;
342 return 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200343}
344#endif
345
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100346/*
347 * Called when finished with the line: draw the screen line and handle any
348 * highlighting until the right of the window.
349 */
350 static void
351draw_screen_line(win_T *wp, winlinevars_T *wlv)
352{
353#ifdef FEAT_SYN_HL
354 long v;
355
356 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
357 if (wp->w_p_wrap)
358 v = wp->w_skipcol;
359 else
360 v = wp->w_leftcol;
361
362 // check if line ends before left margin
363 if (wlv->vcol < v + wlv->col - win_col_off(wp))
364 wlv->vcol = v + wlv->col - win_col_off(wp);
365# ifdef FEAT_CONCEAL
366 // Get rid of the boguscols now, we want to draw until the right
367 // edge for 'cursorcolumn'.
368 wlv->col -= wlv->boguscols;
369 wlv->boguscols = 0;
370# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
371# else
372# define VCOL_HLC (wlv->vcol)
373# endif
374
375 if (wlv->draw_color_col)
376 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
377
378 if (((wp->w_p_cuc
379 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
380 && (int)wp->w_virtcol <
381 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
382 && wlv->lnum != wp->w_cursor.lnum)
383 || wlv->draw_color_col
384 || wlv->win_attr != 0)
385# ifdef FEAT_RIGHTLEFT
386 && !wp->w_p_rl
387# endif
388 )
389 {
390 int rightmost_vcol = 0;
391 int i;
392
393 if (wp->w_p_cuc)
394 rightmost_vcol = wp->w_virtcol;
395 if (wlv->draw_color_col)
396 // determine rightmost colorcolumn to possibly draw
397 for (i = 0; wlv->color_cols[i] >= 0; ++i)
398 if (rightmost_vcol < wlv->color_cols[i])
399 rightmost_vcol = wlv->color_cols[i];
400
401 while (wlv->col < wp->w_width)
402 {
403 ScreenLines[wlv->off] = ' ';
404 if (enc_utf8)
405 ScreenLinesUC[wlv->off] = 0;
406 ScreenCols[wlv->off] = MAXCOL;
407 ++wlv->col;
408 if (wlv->draw_color_col)
409 wlv->draw_color_col = advance_color_col(
410 VCOL_HLC, &wlv->color_cols);
411
412 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
413 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
414 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
415 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
416 else
417 ScreenAttrs[wlv->off++] = wlv->win_attr;
418
419 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
420 break;
421
422 ++wlv->vcol;
423 }
424 }
425#endif
426
427 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
428 wp->w_width, wlv->screen_line_flags);
429 ++wlv->row;
430 ++wlv->screen_row;
431}
432#undef VCOL_HLC
433
434/*
435 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100436 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100437 */
438 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100439win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100440{
441 wlv->col = 0;
442 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
443
444#ifdef FEAT_RIGHTLEFT
445 if (wp->w_p_rl)
446 {
447 // Rightleft window: process the text in the normal direction, but put
448 // it in current_ScreenLine[] from right to left. Start at the
449 // rightmost column of the window.
450 wlv->col = wp->w_width - 1;
451 wlv->off += wlv->col;
452 wlv->screen_line_flags |= SLF_RIGHTLEFT;
453 }
454#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100455 if (save_extra)
456 {
457 // reset the drawing state for the start of a wrapped line
458 wlv->draw_state = WL_START;
459 wlv->saved_n_extra = wlv->n_extra;
460 wlv->saved_p_extra = wlv->p_extra;
461 wlv->saved_c_extra = wlv->c_extra;
462 wlv->saved_c_final = wlv->c_final;
463#ifdef FEAT_SYN_HL
464 if (!(wlv->cul_screenline
465# ifdef FEAT_DIFF
466 && wlv->diff_hlf == (hlf_T)0
467# endif
468 ))
469 wlv->saved_char_attr = wlv->char_attr;
470 else
471#endif
472 wlv->saved_char_attr = 0;
473 wlv->n_extra = 0;
474 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100475}
476
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200477/*
478 * Display line "lnum" of window 'wp' on the screen.
479 * Start at row "startrow", stop when "endrow" is reached.
480 * wp->w_virtcol needs to be valid.
481 *
482 * Return the number of last row the line occupies.
483 */
484 int
485win_line(
486 win_T *wp,
487 linenr_T lnum,
488 int startrow,
489 int endrow,
490 int nochange UNUSED, // not updating for changed text
491 int number_only) // only update the number column
492{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100493 winlinevars_T wlv; // variables passed between functions
494
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200495 int c = 0; // init for GCC
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200496#ifdef FEAT_LINEBREAK
497 long vcol_sbr = -1; // virtual column after showbreak
498#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100499 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200500 char_u *line; // current line
501 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200502
503 char_u extra[21]; // "%ld " and 'fdc' must fit in here
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200504 char_u *p_extra_free = NULL; // p_extra needs to be freed
Bram Moolenaar1306b362022-08-06 15:59:06 +0100505#ifdef FEAT_PROP_POPUP
506 char_u *p_extra_free2 = NULL; // another p_extra to be freed
507#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200508 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000509#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000510 int in_linebreak = FALSE; // n_extra set for showing linebreak
511#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200512 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100513 // displaying eol at end-of-line
514 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000515 int lcs_prec_todo = wp->w_lcs_chars.prec;
516 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200517
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100518 int n_attr = 0; // chars with special attr
519 int n_attr_skip = 0; // chars to skip before using extra_attr
520 int saved_attr2 = 0; // char_attr saved for n_attr
521 int n_attr3 = 0; // chars with overruling special attr
522 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200523
524 int n_skip = 0; // nr of chars to skip for 'nowrap'
525
526 int fromcol = -10; // start of inverting
527 int tocol = MAXCOL; // end of inverting
528 int fromcol_prev = -2; // start of inverting after cursor
529 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200530 int lnum_in_visual_area = FALSE;
531 pos_T pos;
532 long v;
533
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200534 int attr_pri = FALSE; // char_attr has priority
535 int area_highlighting = FALSE; // Visual or incsearch highlighting
536 // in this line
537 int vi_attr = 0; // attributes for Visual and incsearch
538 // highlighting
539 int wcr_attr = 0; // attributes from 'wincolor'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200540 int area_attr = 0; // attributes desired by highlighting
541 int search_attr = 0; // attributes desired by 'hlsearch'
542#ifdef FEAT_SYN_HL
543 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
544 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200545 int prev_syntax_col = -1; // column of prev_syntax_attr
546 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200547 int has_syntax = FALSE; // this buffer has syntax highl.
548 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200549#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100550#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200551 int text_prop_count;
552 int text_prop_next = 0; // next text property to use
553 textprop_T *text_props = NULL;
554 int *text_prop_idxs = NULL;
555 int text_props_active = 0;
556 proptype_T *text_prop_type = NULL;
557 int text_prop_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100558 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100559 int text_prop_flags = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100560 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200561#endif
562#ifdef FEAT_SPELL
563 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000564 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200565# define SPWORDLEN 150
566 char_u nextline[SPWORDLEN * 2];// text with start of the next line
567 int nextlinecol = 0; // column where nextline[] starts
568 int nextline_idx = 0; // index in nextline[] where next line
569 // starts
570 int spell_attr = 0; // attributes desired by spelling
571 int word_end = 0; // last byte with same spell_attr
572 static linenr_T checked_lnum = 0; // line number for "checked_col"
573 static int checked_col = 0; // column in "checked_lnum" up to which
574 // there are no spell errors
575 static int cap_col = -1; // column to check for Cap word
576 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
577 int cur_checked_col = 0; // checked column for current line
578#endif
579 int extra_check = 0; // has extra highlighting
580 int multi_attr = 0; // attributes desired by multibyte
581 int mb_l = 1; // multi-byte byte length
582 int mb_c = 0; // decoded multi-byte character
583 int mb_utf8 = FALSE; // screen char is UTF-8 char
584 int u8cc[MAX_MCO]; // composing UTF-8 chars
585#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
586 int filler_lines = 0; // nr of filler lines to be drawn
587 int filler_todo = 0; // nr of filler lines still to do + 1
Bram Moolenaar936dc602022-03-06 20:47:01 +0000588#else
589# define filler_lines 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200590#endif
591#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200592 int change_start = MAXCOL; // first col of changed area
593 int change_end = -1; // last col of changed area
594#endif
595 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100596 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200597 int in_multispace = FALSE; // in multiple consecutive spaces
598 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200599#ifdef FEAT_LINEBREAK
600 int need_showbreak = FALSE; // overlong line, skipping first x
601 // chars
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +0100602 int dont_use_showbreak = FALSE; // do not use 'showbreak'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200603#endif
604#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
605 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
606# define LINE_ATTR
607 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +0100608 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200609#endif
610#ifdef FEAT_SIGNS
611 int sign_present = FALSE;
612 sign_attrs_T sattr;
James McCoya80aad72021-12-22 19:45:28 +0000613 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200614#endif
615#ifdef FEAT_ARABIC
616 int prev_c = 0; // previous Arabic character
617 int prev_c1 = 0; // first composing char for prev_c
618#endif
619#if defined(LINE_ATTR)
620 int did_line_attr = 0;
621#endif
622#ifdef FEAT_TERMINAL
623 int get_term_attr = FALSE;
624#endif
625#ifdef FEAT_SYN_HL
626 int cul_attr = 0; // set when 'cursorline' active
627
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200628 // margin columns for the screen line, needed for when 'cursorlineopt'
629 // contains "screenline"
630 int left_curline_col = 0;
631 int right_curline_col = 0;
632#endif
633
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200634#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
635 int feedback_col = 0;
636 int feedback_old_attr = -1;
637#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200638
639#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
640 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000641 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200642#endif
643#ifdef FEAT_CONCEAL
644 int syntax_flags = 0;
645 int syntax_seqnr = 0;
646 int prev_syntax_id = 0;
647 int conceal_attr = HL_ATTR(HLF_CONCEAL);
648 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200649 int did_wcol = FALSE;
650 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100651# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200652# define FIX_FOR_BOGUSCOLS \
653 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +0100654 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100655 wlv.vcol -= wlv.vcol_off; \
656 wlv.vcol_off = 0; \
657 wlv.col -= wlv.boguscols; \
658 old_boguscols = wlv.boguscols; \
659 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200660 }
661#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100662# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200663#endif
664
665 if (startrow > endrow) // past the end already!
666 return startrow;
667
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100668 CLEAR_FIELD(wlv);
669
670 wlv.lnum = lnum;
671 wlv.startrow = startrow;
672 wlv.row = startrow;
673 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200674
675 if (!number_only)
676 {
677 // To speed up the loop below, set extra_check when there is linebreak,
678 // trailing white space and/or syntax processing to be done.
679#ifdef FEAT_LINEBREAK
680 extra_check = wp->w_p_lbr;
681#endif
682#ifdef FEAT_SYN_HL
683 if (syntax_present(wp) && !wp->w_s->b_syn_error
684# ifdef SYN_TIME_LIMIT
685 && !wp->w_s->b_syn_slow
686# endif
687 )
688 {
689 // Prepare for syntax highlighting in this line. When there is an
690 // error, stop syntax highlighting.
691 save_did_emsg = did_emsg;
692 did_emsg = FALSE;
693 syntax_start(wp, lnum);
694 if (did_emsg)
695 wp->w_s->b_syn_error = TRUE;
696 else
697 {
698 did_emsg = save_did_emsg;
699#ifdef SYN_TIME_LIMIT
700 if (!wp->w_s->b_syn_slow)
701#endif
702 {
703 has_syntax = TRUE;
704 extra_check = TRUE;
705 }
706 }
707 }
708
709 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100710 wlv.color_cols = wp->w_p_cc_cols;
711 if (wlv.color_cols != NULL)
712 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200713#endif
714
715#ifdef FEAT_TERMINAL
716 if (term_show_buffer(wp->w_buffer))
717 {
718 extra_check = TRUE;
719 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100720 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200721 }
722#endif
723
724#ifdef FEAT_SPELL
725 if (wp->w_p_spell
726 && *wp->w_s->b_p_spl != NUL
727 && wp->w_s->b_langp.ga_len > 0
728 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
729 {
730 // Prepare for spell checking.
731 has_spell = TRUE;
732 extra_check = TRUE;
733
734 // Get the start of the next line, so that words that wrap to the
735 // next line are found too: "et<line-break>al.".
736 // Trick: skip a few chars for C/shell/Vim comments
737 nextline[SPWORDLEN] = NUL;
738 if (lnum < wp->w_buffer->b_ml.ml_line_count)
739 {
740 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
741 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
742 }
743
744 // When a word wrapped from the previous line the start of the
745 // current line is valid.
746 if (lnum == checked_lnum)
747 cur_checked_col = checked_col;
748 checked_lnum = 0;
749
750 // When there was a sentence end in the previous line may require a
751 // word starting with capital in this line. In line 1 always check
752 // the first word.
753 if (lnum != capcol_lnum)
754 cap_col = -1;
755 if (lnum == 1)
756 cap_col = 0;
757 capcol_lnum = 0;
758 }
759#endif
760
761 // handle Visual active in this window
762 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
763 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100764 pos_T *top, *bot;
765
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200766 if (LTOREQ_POS(curwin->w_cursor, VIsual))
767 {
768 // Visual is after curwin->w_cursor
769 top = &curwin->w_cursor;
770 bot = &VIsual;
771 }
772 else
773 {
774 // Visual is before curwin->w_cursor
775 top = &VIsual;
776 bot = &curwin->w_cursor;
777 }
778 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
779 if (VIsual_mode == Ctrl_V)
780 {
781 // block mode
782 if (lnum_in_visual_area)
783 {
784 fromcol = wp->w_old_cursor_fcol;
785 tocol = wp->w_old_cursor_lcol;
786 }
787 }
788 else
789 {
790 // non-block mode
791 if (lnum > top->lnum && lnum <= bot->lnum)
792 fromcol = 0;
793 else if (lnum == top->lnum)
794 {
795 if (VIsual_mode == 'V') // linewise
796 fromcol = 0;
797 else
798 {
799 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
800 if (gchar_pos(top) == NUL)
801 tocol = fromcol + 1;
802 }
803 }
804 if (VIsual_mode != 'V' && lnum == bot->lnum)
805 {
806 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
807 {
808 fromcol = -10;
809 tocol = MAXCOL;
810 }
811 else if (bot->col == MAXCOL)
812 tocol = MAXCOL;
813 else
814 {
815 pos = *bot;
816 if (*p_sel == 'e')
817 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
818 else
819 {
820 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
821 ++tocol;
822 }
823 }
824 }
825 }
826
827 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200828 if (!highlight_match && lnum == curwin->w_cursor.lnum
829 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200830#ifdef FEAT_GUI
831 && !gui.in_use
832#endif
833 )
834 noinvcur = TRUE;
835
836 // if inverting in this line set area_highlighting
837 if (fromcol >= 0)
838 {
839 area_highlighting = TRUE;
840 vi_attr = HL_ATTR(HLF_V);
841#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
842 if ((clip_star.available && !clip_star.owned
843 && clip_isautosel_star())
844 || (clip_plus.available && !clip_plus.owned
845 && clip_isautosel_plus()))
846 vi_attr = HL_ATTR(HLF_VNC);
847#endif
848 }
849 }
850
851 // handle 'incsearch' and ":s///c" highlighting
852 else if (highlight_match
853 && wp == curwin
854 && lnum >= curwin->w_cursor.lnum
855 && lnum <= curwin->w_cursor.lnum + search_match_lines)
856 {
857 if (lnum == curwin->w_cursor.lnum)
858 getvcol(curwin, &(curwin->w_cursor),
859 (colnr_T *)&fromcol, NULL, NULL);
860 else
861 fromcol = 0;
862 if (lnum == curwin->w_cursor.lnum + search_match_lines)
863 {
864 pos.lnum = lnum;
865 pos.col = search_match_endcol;
866 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
867 }
868 else
869 tocol = MAXCOL;
870 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100871 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200872 tocol = fromcol + 1;
873 area_highlighting = TRUE;
874 vi_attr = HL_ATTR(HLF_I);
875 }
876 }
877
878#ifdef FEAT_DIFF
879 filler_lines = diff_check(wp, lnum);
880 if (filler_lines < 0)
881 {
882 if (filler_lines == -1)
883 {
884 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +0100885 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200886 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100887 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200888 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100889 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200890 }
891 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100892 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200893 filler_lines = 0;
894 area_highlighting = TRUE;
895 }
896 if (lnum == wp->w_topline)
897 filler_lines = wp->w_topfill;
898 filler_todo = filler_lines;
899#endif
900
901#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +0100902 sign_present = buf_get_signattrs(wp, lnum, &sattr);
James McCoya80aad72021-12-22 19:45:28 +0000903 if (sign_present)
904 num_attr = sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200905#endif
906
907#ifdef LINE_ATTR
908# ifdef FEAT_SIGNS
909 // If this line has a sign with line highlighting set line_attr.
910 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200911 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200912# endif
913# if defined(FEAT_QUICKFIX)
914 // Highlight the current line in the quickfix window.
915 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
916 line_attr = HL_ATTR(HLF_QFL);
917# endif
918 if (line_attr != 0)
919 area_highlighting = TRUE;
920#endif
921
922 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
923 ptr = line;
924
925#ifdef FEAT_SPELL
926 if (has_spell && !number_only)
927 {
928 // For checking first word with a capital skip white space.
929 if (cap_col == 0)
930 cap_col = getwhitecols(line);
931
932 // To be able to spell-check over line boundaries copy the end of the
933 // current line into nextline[]. Above the start of the next line was
934 // copied to nextline[SPWORDLEN].
935 if (nextline[SPWORDLEN] == NUL)
936 {
937 // No next line or it is empty.
938 nextlinecol = MAXCOL;
939 nextline_idx = 0;
940 }
941 else
942 {
943 v = (long)STRLEN(line);
944 if (v < SPWORDLEN)
945 {
946 // Short line, use it completely and append the start of the
947 // next line.
948 nextlinecol = 0;
949 mch_memmove(nextline, line, (size_t)v);
950 STRMOVE(nextline + v, nextline + SPWORDLEN);
951 nextline_idx = v + 1;
952 }
953 else
954 {
955 // Long line, use only the last SPWORDLEN bytes.
956 nextlinecol = v - SPWORDLEN;
957 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
958 nextline_idx = SPWORDLEN + 1;
959 }
960 }
961 }
962#endif
963
964 if (wp->w_p_list)
965 {
Bram Moolenaareed9d462021-02-15 20:38:25 +0100966 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +0200967 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100968 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +0100969 || wp->w_lcs_chars.trail
970 || wp->w_lcs_chars.lead
971 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200972 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100973
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200974 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100975 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200976 {
977 trailcol = (colnr_T)STRLEN(ptr);
978 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
979 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +0100980 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200981 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100982 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100983 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100984 {
985 leadcol = 0;
986 while (VIM_ISWHITE(ptr[leadcol]))
987 ++leadcol;
988 if (ptr[leadcol] == NUL)
989 // in a line full of spaces all of them are treated as trailing
990 leadcol = (colnr_T)0;
991 else
992 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +0100993 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100994 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200995 }
996
997 wcr_attr = get_wcr_attr(wp);
998 if (wcr_attr != 0)
999 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001000 wlv.win_attr = wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001001 area_highlighting = TRUE;
1002 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001003
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001004#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001005 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001006 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001007#endif
1008
1009 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1010 // first character to be displayed.
1011 if (wp->w_p_wrap)
1012 v = wp->w_skipcol;
1013 else
1014 v = wp->w_leftcol;
1015 if (v > 0 && !number_only)
1016 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001017 char_u *prev_ptr = ptr;
1018 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001019 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001020
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001021 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001022 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001023 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001024 charsize = win_lbr_chartabsize(&cts, NULL);
1025 cts.cts_vcol += charsize;
1026 prev_ptr = cts.cts_ptr;
1027 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001028 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001029 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001030 ptr = cts.cts_ptr;
1031 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001032
1033 // When:
1034 // - 'cuc' is set, or
1035 // - 'colorcolumn' is set, or
1036 // - 'virtualedit' is set, or
1037 // - the visual mode is active,
1038 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001039 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001040#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001041 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001042#endif
1043 virtual_active() ||
1044 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001045 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001046
1047 // Handle a character that's not completely on the screen: Put ptr at
1048 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001049 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001050 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001051 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001052 ptr = prev_ptr;
1053 // If the character fits on the screen, don't need to skip it.
1054 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001055 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1056 && wlv.col == 0)
1057 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001058 }
1059
1060 // Adjust for when the inverted text is before the screen,
1061 // and when the start of the inverted text is before the screen.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001062 if (tocol <= wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001063 fromcol = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001064 else if (fromcol >= 0 && fromcol < wlv.vcol)
1065 fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001066
1067#ifdef FEAT_LINEBREAK
1068 // When w_skipcol is non-zero, first line needs 'showbreak'
1069 if (wp->w_p_wrap)
1070 need_showbreak = TRUE;
1071#endif
1072#ifdef FEAT_SPELL
1073 // When spell checking a word we need to figure out the start of the
1074 // word and if it's badly spelled or not.
1075 if (has_spell)
1076 {
1077 int len;
1078 colnr_T linecol = (colnr_T)(ptr - line);
1079 hlf_T spell_hlf = HLF_COUNT;
1080
1081 pos = wp->w_cursor;
1082 wp->w_cursor.lnum = lnum;
1083 wp->w_cursor.col = linecol;
1084 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1085
1086 // spell_move_to() may call ml_get() and make "line" invalid
1087 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1088 ptr = line + linecol;
1089
1090 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1091 {
1092 // no bad word found at line start, don't check until end of a
1093 // word
1094 spell_hlf = HLF_COUNT;
1095 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1096 }
1097 else
1098 {
1099 // bad word found, use attributes until end of word
1100 word_end = wp->w_cursor.col + len + 1;
1101
1102 // Turn index into actual attributes.
1103 if (spell_hlf != HLF_COUNT)
1104 spell_attr = highlight_attr[spell_hlf];
1105 }
1106 wp->w_cursor = pos;
1107
1108# ifdef FEAT_SYN_HL
1109 // Need to restart syntax highlighting for this line.
1110 if (has_syntax)
1111 syntax_start(wp, lnum);
1112# endif
1113 }
1114#endif
1115 }
1116
1117 // Correct highlighting for cursor that can't be disabled.
1118 // Avoids having to check this for each character.
1119 if (fromcol >= 0)
1120 {
1121 if (noinvcur)
1122 {
1123 if ((colnr_T)fromcol == wp->w_virtcol)
1124 {
1125 // highlighting starts at cursor, let it start just after the
1126 // cursor
1127 fromcol_prev = fromcol;
1128 fromcol = -1;
1129 }
1130 else if ((colnr_T)fromcol < wp->w_virtcol)
1131 // restart highlighting after the cursor
1132 fromcol_prev = wp->w_virtcol;
1133 }
1134 if (fromcol >= tocol)
1135 fromcol = -1;
1136 }
1137
1138#ifdef FEAT_SEARCH_EXTRA
1139 if (!number_only)
1140 {
1141 v = (long)(ptr - line);
1142 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1143 &line, &screen_search_hl,
1144 &search_attr);
1145 ptr = line + v; // "line" may have been updated
1146 }
1147#endif
1148
1149#ifdef FEAT_SYN_HL
1150 // Cursor line highlighting for 'cursorline' in the current window.
1151 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1152 {
1153 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001154 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001155 if (!(wp == curwin && VIsual_active)
1156 && wp->w_p_culopt_flags != CULOPT_NBR)
1157 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001158 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001159 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1160
1161 // Only set line_attr here when "screenline" is not present in
1162 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001163 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001164 {
1165 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001166# ifdef FEAT_SIGNS
1167 // Combine the 'cursorline' and sign highlighting, depending on
1168 // the sign priority.
1169 if (sign_present && sattr.sat_linehl > 0)
1170 {
1171 if (sattr.sat_priority >= 100)
1172 line_attr = hl_combine_attr(cul_attr, line_attr);
1173 else
1174 line_attr = hl_combine_attr(line_attr, cul_attr);
1175 }
1176 else
1177# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001178# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001179 // let the line attribute overrule 'cursorline', otherwise
1180 // it disappears when both have background set;
1181 // 'cursorline' can use underline or bold to make it show
1182 line_attr = hl_combine_attr(cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001183# else
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001184 line_attr = cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001185# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001186 }
1187 else
1188 {
1189 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001190 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1191 }
1192 area_highlighting = TRUE;
1193 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001194 }
1195#endif
1196
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001197#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001198 {
1199 char_u *prop_start;
1200
1201 text_prop_count = get_text_props(wp->w_buffer, lnum,
1202 &prop_start, FALSE);
1203 if (text_prop_count > 0)
1204 {
1205 // Make a copy of the properties, so that they are properly
1206 // aligned.
1207 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1208 if (text_props != NULL)
1209 mch_memmove(text_props, prop_start,
1210 text_prop_count * sizeof(textprop_T));
1211
1212 // Allocate an array for the indexes.
1213 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1214 area_highlighting = TRUE;
1215 extra_check = TRUE;
1216 }
1217 }
1218#endif
1219
Bram Moolenaar1306b362022-08-06 15:59:06 +01001220 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001221
1222 // Repeat for the whole displayed line.
1223 for (;;)
1224 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001225 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001226#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001227 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001228#endif
1229#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001230 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001231#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001232
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001233 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001234 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001235 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001236#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001237 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001238 {
1239 cul_attr = 0;
1240 line_attr = line_attr_save;
1241 }
1242#endif
1243
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001244#ifdef FEAT_CMDWIN
Bram Moolenaar1306b362022-08-06 15:59:06 +01001245 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001246 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001247 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001248 if (cmdwin_type != 0 && wp == curwin)
1249 {
1250 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001251 wlv.n_extra = 1;
1252 wlv.c_extra = cmdwin_type;
1253 wlv.c_final = NUL;
1254 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001255 }
1256 }
1257#endif
1258
1259#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001260 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001261 {
1262 int fdc = compute_foldcolumn(wp, 0);
1263
Bram Moolenaar1306b362022-08-06 15:59:06 +01001264 wlv.draw_state = WL_FOLD;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001265 if (fdc > 0)
1266 {
1267 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1268 // already be in use.
1269 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001270 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001271 if (p_extra_free != NULL)
1272 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001273 wlv.n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001274 FALSE, lnum);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001275 p_extra_free[wlv.n_extra] = NUL;
1276 wlv.p_extra = p_extra_free;
1277 wlv.c_extra = NUL;
1278 wlv.c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001279 if (use_cursor_line_sign(wp, lnum))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001280 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001281 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1282 else
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_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001285 }
1286 }
1287 }
1288#endif
1289
1290#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001291 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001292 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001293 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001294 // Show the sign column when there are any signs in this
1295 // buffer or when using Netbeans.
1296 if (signcolumn_on(wp))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001297 get_sign_display_info(FALSE, wp, lnum, &wlv, &sattr,
1298 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001299 }
1300#endif
1301
Bram Moolenaar1306b362022-08-06 15:59:06 +01001302 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001303 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001304 wlv.draw_state = WL_NR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001305 // Display the absolute or relative line number. After the
1306 // first fill with blanks when the 'n' flag isn't in 'cpo'
1307 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001308 && (wlv.row == startrow + filler_lines
1309 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001310 {
1311#ifdef FEAT_SIGNS
1312 // If 'signcolumn' is set to 'number' and a sign is present
1313 // in 'lnum', then display the sign instead of the line
1314 // number.
1315 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1316 && sign_present)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001317 get_sign_display_info(TRUE, wp, lnum, &wlv, &sattr,
1318 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001319 else
1320#endif
1321 {
1322 // Draw the line number (empty space after wrapping).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001323 if (wlv.row == startrow + filler_lines)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001324 {
1325 long num;
1326 char *fmt = "%*ld ";
1327
1328 if (wp->w_p_nu && !wp->w_p_rnu)
1329 // 'number' + 'norelativenumber'
1330 num = (long)lnum;
1331 else
1332 {
1333 // 'relativenumber', don't use negative numbers
1334 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1335 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1336 {
1337 // 'number' + 'relativenumber'
1338 num = lnum;
1339 fmt = "%-*ld ";
1340 }
1341 }
1342
1343 sprintf((char *)extra, fmt,
1344 number_width(wp), num);
1345 if (wp->w_skipcol > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001346 for (wlv.p_extra = extra; *wlv.p_extra == ' ';
1347 ++wlv.p_extra)
1348 *wlv.p_extra = '-';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001349#ifdef FEAT_RIGHTLEFT
1350 if (wp->w_p_rl) // reverse line numbers
1351 {
1352 char_u *p1, *p2;
1353 int t;
1354
1355 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001356 p2 = skipwhite(extra);
1357 p2 = skiptowhite(p2) - 1;
1358 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001359 {
1360 t = *p1;
1361 *p1 = *p2;
1362 *p2 = t;
1363 }
1364 }
1365#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001366 wlv.p_extra = extra;
1367 wlv.c_extra = NUL;
1368 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001369 }
1370 else
1371 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001372 wlv.c_extra = ' ';
1373 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001374 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001375 wlv.n_extra = number_width(wp) + 1;
1376 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001377#ifdef FEAT_SYN_HL
1378 // When 'cursorline' is set highlight the line number of
1379 // the current line differently.
zeertzjq754d2b42022-03-13 13:40:45 +00001380 // When 'cursorlineopt' does not have "line" only
1381 // highlight the line number itself.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001382 // TODO: Can we use CursorLine instead of CursorLineNr
1383 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001384 if (wp->w_p_cul
1385 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001386 && (wp->w_p_culopt_flags & CULOPT_NBR)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001387 && (wlv.row == startrow + filler_lines
1388 || (wlv.row > startrow + filler_lines
zeertzjq754d2b42022-03-13 13:40:45 +00001389 && (wp->w_p_culopt_flags & CULOPT_LINE))))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001390 wlv.char_attr = hl_combine_attr(wcr_attr,
1391 HL_ATTR(HLF_CLN));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001392#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001393 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1394 && HL_ATTR(HLF_LNA) != 0)
1395 // Use LineNrAbove
Bram Moolenaar1306b362022-08-06 15:59:06 +01001396 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001397 HL_ATTR(HLF_LNA));
1398 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1399 && HL_ATTR(HLF_LNB) != 0)
1400 // Use LineNrBelow
Bram Moolenaar1306b362022-08-06 15:59:06 +01001401 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001402 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001403 }
James McCoya80aad72021-12-22 19:45:28 +00001404#ifdef FEAT_SIGNS
1405 if (num_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001406 wlv.char_attr = num_attr;
James McCoya80aad72021-12-22 19:45:28 +00001407#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001408 }
1409 }
1410
1411#ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001412 if (wp->w_briopt_sbr && wlv.draw_state == WL_BRI - 1
1413 && wlv.n_extra == 0
1414 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001415 // draw indent after showbreak value
Bram Moolenaar1306b362022-08-06 15:59:06 +01001416 wlv.draw_state = WL_BRI;
1417 else if (wp->w_briopt_sbr && wlv.draw_state == WL_SBR
1418 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001419 // After the showbreak, draw the breakindent
Bram Moolenaar1306b362022-08-06 15:59:06 +01001420 wlv.draw_state = WL_BRI - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001421
1422 // draw 'breakindent': indent wrapped text accordingly
Bram Moolenaar1306b362022-08-06 15:59:06 +01001423 if (wlv.draw_state == WL_BRI - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001424 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001425 wlv.draw_state = WL_BRI;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001426 // if need_showbreak is set, breakindent also applies
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001427 if (wp->w_p_bri && (wlv.row != startrow || need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001428# ifdef FEAT_DIFF
1429 && filler_lines == 0
1430# endif
Bram Moolenaar73c38422022-08-07 11:53:40 +01001431# ifdef FEAT_PROP_POPUP
1432 && !dont_use_showbreak
1433# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001434 )
1435 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001436 wlv.char_attr = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001437# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01001438 if (wlv.diff_hlf != (hlf_T)0)
1439 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001440# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001441 wlv.p_extra = NULL;
1442 wlv.c_extra = ' ';
1443 wlv.c_final = NUL;
1444 wlv.n_extra = get_breakindent_win(wp,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001445 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001446 if (wlv.row == startrow)
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001447 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001448 wlv.n_extra -= win_col_off2(wp);
1449 if (wlv.n_extra < 0)
1450 wlv.n_extra = 0;
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001451 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001452 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001453 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001454 // Correct end of highlighted area for 'breakindent',
1455 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001456 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001457 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001458 }
1459 }
1460#endif
1461
1462#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001463 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001464 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001465 char_u *sbr;
1466
Bram Moolenaar1306b362022-08-06 15:59:06 +01001467 wlv.draw_state = WL_SBR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001468# ifdef FEAT_DIFF
1469 if (filler_todo > 0)
1470 {
1471 // Draw "deleted" diff line(s).
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001472 if (char2cells(wp->w_fill_chars.diff) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001473 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001474 wlv.c_extra = '-';
1475 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001476 }
1477 else
1478 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001479 wlv.c_extra = wp->w_fill_chars.diff;
1480 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001481 }
1482# ifdef FEAT_RIGHTLEFT
1483 if (wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001484 wlv.n_extra = wlv.col + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001485 else
1486# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001487 wlv.n_extra = wp->w_width - wlv.col;
1488 wlv.char_attr = HL_ATTR(HLF_DED);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001489 }
1490# endif
1491# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001492 sbr = get_showbreak_value(wp);
1493 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001494 {
1495 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001496 wlv.p_extra = sbr;
1497 wlv.c_extra = NUL;
1498 wlv.c_final = NUL;
1499 wlv.n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001500 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1501 need_showbreak = FALSE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001502 vcol_sbr = wlv.vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001503 // Correct end of highlighted area for 'showbreak',
1504 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001505 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001506 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001507 // combine 'showbreak' with 'wincolor'
Bram Moolenaar1306b362022-08-06 15:59:06 +01001508 wlv.char_attr = hl_combine_attr(wlv.win_attr,
1509 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001510# ifdef FEAT_SYN_HL
1511 // combine 'showbreak' with 'cursorline'
1512 if (cul_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001513 wlv.char_attr = hl_combine_attr(wlv.char_attr,
1514 cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001515# endif
1516 }
1517# endif
1518 }
1519#endif
1520
Bram Moolenaar1306b362022-08-06 15:59:06 +01001521 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001522 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001523 wlv.draw_state = WL_LINE;
1524 if (wlv.saved_n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001525 {
1526 // Continue item from end of wrapped line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001527 wlv.n_extra = wlv.saved_n_extra;
1528 wlv.c_extra = wlv.saved_c_extra;
1529 wlv.c_final = wlv.saved_c_final;
1530 wlv.p_extra = wlv.saved_p_extra;
1531 wlv.char_attr = wlv.saved_char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001532 }
1533 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001534 wlv.char_attr = wlv.win_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001535 }
1536 }
1537#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001538 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001539 && wlv.vcol >= left_curline_col
1540 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001541 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001542 cul_attr = HL_ATTR(HLF_CUL);
1543 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001544 }
1545#endif
1546
1547 // When still displaying '$' of change command, stop at cursor.
1548 // When only displaying the (relative) line number and that's done,
1549 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001550 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001551 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001552 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001553#ifdef FEAT_DIFF
1554 && filler_todo <= 0
1555#endif
1556 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001557 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001558 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col, -wp->w_width,
1559 wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001560 // Pretend we have finished updating the window. Except when
1561 // 'cursorcolumn' is set.
1562#ifdef FEAT_SYN_HL
1563 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001564 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001565 else
1566#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001567 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001568 break;
1569 }
1570
Bram Moolenaar1306b362022-08-06 15:59:06 +01001571 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001572 {
1573 // handle Visual or match highlighting in this line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001574 if (wlv.vcol == fromcol
Bram Moolenaar1306b362022-08-06 15:59:06 +01001575 || (has_mbyte && wlv.vcol + 1 == fromcol && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001576 && (*mb_ptr2cells)(ptr) > 1)
1577 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001578 && vcol_prev < wlv.vcol // not at margin
1579 && wlv.vcol < tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001580 area_attr = vi_attr; // start highlighting
1581 else if (area_attr != 0
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001582 && (wlv.vcol == tocol
1583 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001584 area_attr = 0; // stop highlighting
1585
1586#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaar1306b362022-08-06 15:59:06 +01001587 if (!wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001588 {
1589 // Check for start/end of 'hlsearch' and other matches.
1590 // After end, check for start/end of next match.
1591 // When another match, have to check for start again.
1592 v = (long)(ptr - line);
1593 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1594 &screen_search_hl, &has_match_conc,
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001595 &match_conc, did_line_attr, lcs_eol_one,
1596 &on_last_col);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001597 ptr = line + v; // "line" may have been changed
Bram Moolenaarb9081882022-07-09 04:56:24 +01001598 prev_ptr = ptr;
Bram Moolenaarfc838d62020-06-25 22:23:48 +02001599
1600 // Do not allow a conceal over EOL otherwise EOL will be missed
1601 // and bad things happen.
1602 if (*ptr == NUL)
1603 has_match_conc = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001604 }
1605#endif
1606
1607#ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01001608 if (wlv.diff_hlf != (hlf_T)0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001609 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001610 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
1611 && wlv.n_extra == 0)
1612 wlv.diff_hlf = HLF_TXD; // changed text
1613 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
1614 && wlv.n_extra == 0)
1615 wlv.diff_hlf = HLF_CHD; // changed line
1616 line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001617 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1618 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01001619 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001620 && wlv.vcol <= right_curline_col)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001621 line_attr = hl_combine_attr(
1622 line_attr, HL_ATTR(HLF_CUL));
1623 }
1624#endif
1625
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001626#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001627 if (text_props != NULL)
1628 {
1629 int pi;
1630 int bcol = (int)(ptr - line);
1631
Bram Moolenaar1306b362022-08-06 15:59:06 +01001632 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001633# ifdef FEAT_LINEBREAK
1634 && !in_linebreak
1635# endif
1636 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001637 --bcol; // still working on the previous char, e.g. Tab
1638
1639 // Check if any active property ends.
1640 for (pi = 0; pi < text_props_active; ++pi)
1641 {
1642 int tpi = text_prop_idxs[pi];
1643
1644 if (bcol >= text_props[tpi].tp_col - 1
1645 + text_props[tpi].tp_len)
1646 {
1647 if (pi + 1 < text_props_active)
1648 mch_memmove(text_prop_idxs + pi,
1649 text_prop_idxs + pi + 1,
1650 sizeof(int)
1651 * (text_props_active - (pi + 1)));
1652 --text_props_active;
1653 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001654# ifdef FEAT_LINEBREAK
1655 // not exactly right but should work in most cases
1656 if (in_linebreak && syntax_attr == text_prop_attr)
1657 syntax_attr = 0;
1658# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001659 }
1660 }
1661
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001662# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001663 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001664 // not on the next char yet, don't start another prop
1665 --bcol;
1666# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001667 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001668 // With 'nowrap' and not in the first screen line only "below"
1669 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001670 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001671 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001672 ? (*ptr == NUL
1673 && (wp->w_p_wrap
1674 || wlv.row == startrow
1675 || (text_props[text_prop_next].tp_flags
1676 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001677 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001678 {
1679 if (bcol <= text_props[text_prop_next].tp_col - 1
1680 + text_props[text_prop_next].tp_len)
1681 text_prop_idxs[text_props_active++] = text_prop_next;
1682 ++text_prop_next;
1683 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001684
1685 text_prop_attr = 0;
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001686 text_prop_flags = 0;
Bram Moolenaar053f7122019-09-23 22:17:15 +02001687 text_prop_type = NULL;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001688 text_prop_id = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001689 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001690 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001691 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001692 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001693 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001694
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001695 // Sort the properties on priority and/or starting last.
1696 // Then combine the attributes, highest priority last.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001697 text_prop_follows = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001698 current_text_props = text_props;
1699 current_buf = wp->w_buffer;
1700 qsort((void *)text_prop_idxs, (size_t)text_props_active,
1701 sizeof(int), text_prop_compare);
1702
1703 for (pi = 0; pi < text_props_active; ++pi)
1704 {
1705 int tpi = text_prop_idxs[pi];
1706 proptype_T *pt = text_prop_type_by_id(
1707 wp->w_buffer, text_props[tpi].tp_type);
1708
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001709 if (pt != NULL && (pt->pt_hl_id > 0
1710 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001711 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001712 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001713 if (pt->pt_hl_id > 0)
1714 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001715 text_prop_type = pt;
1716 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001717 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001718 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001719 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001720 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001721 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001722 }
1723 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001724 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001725 && -text_prop_id
1726 <= wp->w_buffer->b_textprop_text.ga_len)
1727 {
1728 char_u *p = ((char_u **)wp->w_buffer
1729 ->b_textprop_text.ga_data)[
1730 -text_prop_id - 1];
Bram Moolenaar1306b362022-08-06 15:59:06 +01001731
1732 // reset the ID in the copy to avoid it being used
1733 // again
1734 text_props[used_tpi].tp_id = -MAXCOL;
1735
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001736 if (p != NULL)
1737 {
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001738 int right = (text_props[used_tpi].tp_flags
1739 & TP_FLAG_ALIGN_RIGHT);
1740 int below = (text_props[used_tpi].tp_flags
1741 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaar398649e2022-08-04 15:03:48 +01001742 int wrap = (text_props[used_tpi].tp_flags
1743 & TP_FLAG_WRAP);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001744
Bram Moolenaar1306b362022-08-06 15:59:06 +01001745 wlv.p_extra = p;
1746 wlv.c_extra = NUL;
1747 wlv.c_final = NUL;
1748 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001749 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001750 n_attr = mb_charlen(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001751 text_prop_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001752 if (*ptr == NUL)
1753 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001754 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001755#ifdef FEAT_LINEBREAK
Bram Moolenaarcba69522022-08-06 21:03:53 +01001756 if (below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001757 {
1758 // no 'showbreak' before "below" text property
1759 // or after "right" text property
1760 need_showbreak = FALSE;
1761 dont_use_showbreak = TRUE;
1762 }
1763#endif
Bram Moolenaar398649e2022-08-04 15:03:48 +01001764 // Keep in sync with where
1765 // textprop_size_after_trunc() is called in
1766 // win_lbr_chartabsize().
1767 if ((right || below || !wrap) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001768 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001769 int added = wp->w_width - wlv.col;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001770 int n_used = wlv.n_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001771 char_u *l;
Bram Moolenaar398649e2022-08-04 15:03:48 +01001772 int strsize = wrap
Bram Moolenaar1306b362022-08-06 15:59:06 +01001773 ? vim_strsize(wlv.p_extra)
1774 : textprop_size_after_trunc(wp,
1775 below, added, wlv.p_extra, &n_used);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001776
Bram Moolenaar1306b362022-08-06 15:59:06 +01001777 if (wrap || right || below
1778 || n_used < wlv.n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001779 {
Bram Moolenaar398649e2022-08-04 15:03:48 +01001780 // Right-align: fill with spaces
1781 if (right)
1782 added -= strsize;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001783 if (added < 0
1784 || (below
1785 ? wlv.col == 0 || !wp->w_p_wrap
Bram Moolenaar1306b362022-08-06 15:59:06 +01001786 : n_used < wlv.n_extra))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001787 added = 0;
1788 // add 1 for NUL, 2 for when '…' is used
1789 l = alloc(n_used + added + 3);
1790 if (l != NULL)
1791 {
1792 vim_memset(l, ' ', added);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001793 vim_strncpy(l + added, wlv.p_extra,
1794 n_used);
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001795 if (n_used < wlv.n_extra
1796 && wp->w_p_wrap)
Bram Moolenaar398649e2022-08-04 15:03:48 +01001797 {
1798 char_u *lp = l + added + n_used - 1;
1799
1800 if (has_mbyte)
1801 {
1802 // change last character to '…'
1803 lp -= (*mb_head_off)(l, lp);
1804 STRCPY(lp, "…");
1805 n_used = lp - l + 3;
1806 }
1807 else
1808 // change last character to '>'
1809 *lp = '>';
1810 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001811 vim_free(p_extra_free2);
1812 wlv.p_extra = p_extra_free2 = l;
1813 wlv.n_extra = n_used + added;
Bram Moolenaar398649e2022-08-04 15:03:48 +01001814 n_attr_skip = added;
Bram Moolenaar1d8844a2022-08-10 13:39:35 +01001815 n_attr = mb_charlen(wlv.p_extra);
Bram Moolenaar398649e2022-08-04 15:03:48 +01001816 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001817 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001818
1819 // When 'wrap' is off then for "below" we need
1820 // to start a new line explictly.
Bram Moolenaardb9b96d2022-08-06 17:38:53 +01001821 if (below && wlv.col > win_col_off(wp)
1822 && !wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001823 {
1824 draw_screen_line(wp, &wlv);
1825
1826 // When line got too long for screen break
1827 // here.
1828 if (wlv.row == endrow)
1829 {
1830 ++wlv.row;
1831 break;
1832 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001833 win_line_start(wp, &wlv, TRUE);
1834 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001835 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001836 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001837 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001838
1839 // If another text prop follows the condition below at
1840 // the last window column must know.
1841 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001842 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001843 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001844 else if (text_prop_next < text_prop_count
1845 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001846 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
1847 || (!wp->w_p_wrap
1848 && wlv.col == wp->w_width - 1
1849 && (text_props[text_prop_next].tp_flags
1850 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001851 // When at last-but-one character and a text property
1852 // follows after it, we may need to flush the line after
1853 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001854 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01001855 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001856 }
1857#endif
1858
Bram Moolenaara74fda62019-10-19 17:38:03 +02001859#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001860 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001861 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001862 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001863# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001864 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001865 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001866# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001867 // Get syntax attribute.
1868 if (has_syntax)
1869 {
1870 // Get the syntax attribute for the character. If there
1871 // is an error, disable syntax highlighting.
1872 save_did_emsg = did_emsg;
1873 did_emsg = FALSE;
1874
1875 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001876 if (v == prev_syntax_col)
1877 // at same column again
1878 syntax_attr = prev_syntax_attr;
1879 else
1880 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001881# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001882 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001883# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001884 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001885# ifdef FEAT_SPELL
1886 has_spell ? &can_spell :
1887# endif
1888 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001889 prev_syntax_col = v;
1890 prev_syntax_attr = syntax_attr;
1891 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001892
Bram Moolenaar34390282019-10-16 14:38:26 +02001893 if (did_emsg)
1894 {
1895 wp->w_s->b_syn_error = TRUE;
1896 has_syntax = FALSE;
1897 syntax_attr = 0;
1898 }
1899 else
1900 did_emsg = save_did_emsg;
1901# ifdef SYN_TIME_LIMIT
1902 if (wp->w_s->b_syn_slow)
1903 has_syntax = FALSE;
1904# endif
1905
1906 // Need to get the line again, a multi-line regexp may
1907 // have made it invalid.
1908 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1909 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001910 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001911# ifdef FEAT_CONCEAL
1912 // no concealing past the end of the line, it interferes
1913 // with line highlighting
1914 if (*ptr == NUL)
1915 syntax_flags = 0;
1916 else
1917 syntax_flags = get_syntax_info(&syntax_seqnr);
1918# endif
1919 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001920 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001921# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001922 // Combine text property highlight into syntax highlight.
1923 if (text_prop_type != NULL)
1924 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001925 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01001926 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1927 else
1928 syntax_attr = text_prop_attr;
1929 }
1930# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001931#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001932
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001933 // Decide which of the highlight attributes to use.
1934 attr_pri = TRUE;
1935#ifdef LINE_ATTR
1936 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001937 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001938 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02001939 if (!highlight_match)
1940 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01001941 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001942# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001943 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001944# endif
1945 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001946 else if (search_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, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001949# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001950 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001951# endif
1952 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001953 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001954 || wlv.vcol < fromcol || vcol_prev < fromcol_prev
1955 || wlv.vcol >= tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001956 {
1957 // Use line_attr when not in the Visual or 'incsearch' area
1958 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001959# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001960 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01001961# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001962 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001963# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001964 attr_pri = FALSE;
1965 }
1966#else
1967 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001968 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001969 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001970 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001971#endif
1972 else
1973 {
1974 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001975#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001976 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001977#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001978 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001979#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001980 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001981#ifdef FEAT_PROP_POPUP
1982 // override with text property highlight when "override" is TRUE
1983 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001984 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001985#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001986 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001987
1988 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001989 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001990 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001991 if (wlv.char_attr == 0)
1992 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001993 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001994 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001995 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001996
1997 // Get the next character to put on the screen.
1998
1999 // The "p_extra" points to the extra stuff that is inserted to
2000 // represent special characters (non-printable stuff) and other
2001 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002002 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002003 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2004 // "p_extra[n_extra]".
2005 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002006 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002007 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002008 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002009 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002010 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2011 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002012 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2013 if (enc_utf8 && utf_char2len(c) > 1)
2014 {
2015 mb_utf8 = TRUE;
2016 u8cc[0] = 0;
2017 c = 0xc0;
2018 }
2019 else
2020 mb_utf8 = FALSE;
2021 }
2022 else
2023 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002024 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002025 if (has_mbyte)
2026 {
2027 mb_c = c;
2028 if (enc_utf8)
2029 {
2030 // If the UTF-8 character is more than one byte:
2031 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002032 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002033 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002034 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002035 mb_l = 1;
2036 else if (mb_l > 1)
2037 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002038 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002039 mb_utf8 = TRUE;
2040 c = 0xc0;
2041 }
2042 }
2043 else
2044 {
2045 // if this is a DBCS character, put it in "mb_c"
2046 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002047 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002048 mb_l = 1;
2049 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002050 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002051 }
2052 if (mb_l == 0) // at the NUL at end-of-line
2053 mb_l = 1;
2054
2055 // If a double-width char doesn't fit display a '>' in the
2056 // last column.
2057 if ((
2058# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002059 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002060# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002061 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002062 && (*mb_char2cells)(mb_c) == 2)
2063 {
2064 c = '>';
2065 mb_c = c;
2066 mb_l = 1;
2067 mb_utf8 = FALSE;
2068 multi_attr = HL_ATTR(HLF_AT);
2069#ifdef FEAT_SYN_HL
2070 if (cul_attr)
2071 multi_attr = hl_combine_attr(multi_attr, cul_attr);
2072#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002073 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002074
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002075 // put the pointer back to output the double-width
2076 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002077 ++wlv.n_extra;
2078 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002079 }
2080 else
2081 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002082 wlv.n_extra -= mb_l - 1;
2083 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002084 }
2085 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002086 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002087 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002088 --wlv.n_extra;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002089#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002090 if (wlv.n_extra <= 0)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002091 in_linebreak = FALSE;
2092#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002093 }
2094 else
2095 {
2096#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002097 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002098#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002099 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002100
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002101 // Get a character from the line itself.
2102 c = *ptr;
2103#ifdef FEAT_LINEBREAK
2104 c0 = *ptr;
2105#endif
2106 if (has_mbyte)
2107 {
2108 mb_c = c;
2109 if (enc_utf8)
2110 {
2111 // If the UTF-8 character is more than one byte: Decode it
2112 // into "mb_c".
2113 mb_l = utfc_ptr2len(ptr);
2114 mb_utf8 = FALSE;
2115 if (mb_l > 1)
2116 {
2117 mb_c = utfc_ptr2char(ptr, u8cc);
2118 // Overlong encoded ASCII or ASCII with composing char
2119 // is displayed normally, except a NUL.
2120 if (mb_c < 0x80)
2121 {
2122 c = mb_c;
2123#ifdef FEAT_LINEBREAK
2124 c0 = mb_c;
2125#endif
2126 }
2127 mb_utf8 = TRUE;
2128
2129 // At start of the line we can have a composing char.
2130 // Draw it as a space with a composing char.
2131 if (utf_iscomposing(mb_c))
2132 {
2133 int i;
2134
2135 for (i = Screen_mco - 1; i > 0; --i)
2136 u8cc[i] = u8cc[i - 1];
2137 u8cc[0] = mb_c;
2138 mb_c = ' ';
2139 }
2140 }
2141
2142 if ((mb_l == 1 && c >= 0x80)
2143 || (mb_l >= 1 && mb_c == 0)
2144 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2145 {
2146 // Illegal UTF-8 byte: display as <xx>.
2147 // Non-BMP character : display as ? or fullwidth ?.
2148 transchar_hex(extra, mb_c);
2149# ifdef FEAT_RIGHTLEFT
2150 if (wp->w_p_rl) // reverse
2151 rl_mirror(extra);
2152# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002153 wlv.p_extra = extra;
2154 c = *wlv.p_extra;
2155 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002156 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002157 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2158 wlv.c_extra = NUL;
2159 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002160 if (area_attr == 0 && search_attr == 0)
2161 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002162 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002163 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002164 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002165 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002166 }
2167 }
2168 else if (mb_l == 0) // at the NUL at end-of-line
2169 mb_l = 1;
2170#ifdef FEAT_ARABIC
2171 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2172 {
2173 // Do Arabic shaping.
2174 int pc, pc1, nc;
2175 int pcc[MAX_MCO];
2176
2177 // The idea of what is the previous and next
2178 // character depends on 'rightleft'.
2179 if (wp->w_p_rl)
2180 {
2181 pc = prev_c;
2182 pc1 = prev_c1;
2183 nc = utf_ptr2char(ptr + mb_l);
2184 prev_c1 = u8cc[0];
2185 }
2186 else
2187 {
2188 pc = utfc_ptr2char(ptr + mb_l, pcc);
2189 nc = prev_c;
2190 pc1 = pcc[0];
2191 }
2192 prev_c = mb_c;
2193
2194 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2195 }
2196 else
2197 prev_c = mb_c;
2198#endif
2199 }
2200 else // enc_dbcs
2201 {
2202 mb_l = MB_BYTE2LEN(c);
2203 if (mb_l == 0) // at the NUL at end-of-line
2204 mb_l = 1;
2205 else if (mb_l > 1)
2206 {
2207 // We assume a second byte below 32 is illegal.
2208 // Hopefully this is OK for all double-byte encodings!
2209 if (ptr[1] >= 32)
2210 mb_c = (c << 8) + ptr[1];
2211 else
2212 {
2213 if (ptr[1] == NUL)
2214 {
2215 // head byte at end of line
2216 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002217 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002218 }
2219 else
2220 {
2221 // illegal tail byte
2222 mb_l = 2;
2223 STRCPY(extra, "XX");
2224 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002225 wlv.p_extra = extra;
2226 wlv.n_extra = (int)STRLEN(extra) - 1;
2227 wlv.c_extra = NUL;
2228 wlv.c_final = NUL;
2229 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002230 if (area_attr == 0 && search_attr == 0)
2231 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002232 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002233 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002234 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002235 // save current attr
2236 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002237 }
2238 mb_c = c;
2239 }
2240 }
2241 }
2242 // If a double-width char doesn't fit display a '>' in the
2243 // last column; the character is displayed at the start of the
2244 // next line.
2245 if ((
2246# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002247 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002248# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002249 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002250 && (*mb_char2cells)(mb_c) == 2)
2251 {
2252 c = '>';
2253 mb_c = c;
2254 mb_utf8 = FALSE;
2255 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002256 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002257 // Put pointer back so that the character will be
2258 // displayed at the start of the next line.
2259 --ptr;
2260#ifdef FEAT_CONCEAL
2261 did_decrement_ptr = TRUE;
2262#endif
2263 }
2264 else if (*ptr != NUL)
2265 ptr += mb_l - 1;
2266
2267 // If a double-width char doesn't fit at the left side display
2268 // a '<' in the first column. Don't do this for unprintable
2269 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002270 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002271 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002272 wlv.n_extra = 1;
2273 wlv.c_extra = MB_FILLER_CHAR;
2274 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002275 c = ' ';
2276 if (area_attr == 0 && search_attr == 0)
2277 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002278 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002279 extra_attr = hl_combine_attr(
2280 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002281 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002282 }
2283 mb_c = c;
2284 mb_utf8 = FALSE;
2285 mb_l = 1;
2286 }
2287
2288 }
2289 ++ptr;
2290
2291 if (extra_check)
2292 {
2293#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002294 // Check spelling (unless at the end of the line).
2295 // Only do this when there is no syntax highlighting, the
2296 // @Spell cluster is not used or the current syntax item
2297 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002298 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002299 if (has_spell && v >= word_end && v > cur_checked_col)
2300 {
2301 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002302 // do not calculate cap_col at the end of the line or when
2303 // only white space is following
2304 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002305# ifdef FEAT_SYN_HL
2306 !has_syntax ||
2307# endif
2308 can_spell))
2309 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002310 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002311 int len;
2312 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002313
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002314 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002315 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002316
2317 // Use nextline[] if possible, it has the start of the
2318 // next line concatenated.
2319 if ((prev_ptr - line) - nextlinecol >= 0)
2320 p = nextline + (prev_ptr - line) - nextlinecol;
2321 else
2322 p = prev_ptr;
2323 cap_col -= (int)(prev_ptr - line);
2324 len = spell_check(wp, p, &spell_hlf, &cap_col,
2325 nochange);
2326 word_end = v + len;
2327
2328 // In Insert mode only highlight a word that
2329 // doesn't touch the cursor.
2330 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002331 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002332 && wp->w_cursor.lnum == lnum
2333 && wp->w_cursor.col >=
2334 (colnr_T)(prev_ptr - line)
2335 && wp->w_cursor.col < (colnr_T)word_end)
2336 {
2337 spell_hlf = HLF_COUNT;
2338 spell_redraw_lnum = lnum;
2339 }
2340
2341 if (spell_hlf == HLF_COUNT && p != prev_ptr
2342 && (p - nextline) + len > nextline_idx)
2343 {
2344 // Remember that the good word continues at the
2345 // start of the next line.
2346 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002347 checked_col = (int)((p - nextline)
2348 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002349 }
2350
2351 // Turn index into actual attributes.
2352 if (spell_hlf != HLF_COUNT)
2353 spell_attr = highlight_attr[spell_hlf];
2354
2355 if (cap_col > 0)
2356 {
2357 if (p != prev_ptr
2358 && (p - nextline) + cap_col >= nextline_idx)
2359 {
2360 // Remember that the word in the next line
2361 // must start with a capital.
2362 capcol_lnum = lnum + 1;
2363 cap_col = (int)((p - nextline) + cap_col
2364 - nextline_idx);
2365 }
2366 else
2367 // Compute the actual column.
2368 cap_col += (int)(prev_ptr - line);
2369 }
2370 }
2371 }
2372 if (spell_attr != 0)
2373 {
2374 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002375 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2376 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002377 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002378 wlv.char_attr = hl_combine_attr(spell_attr,
2379 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002380 }
2381#endif
2382#ifdef FEAT_LINEBREAK
2383 // Found last space before word: check for line break.
2384 if (wp->w_p_lbr && c0 == c
2385 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2386 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002387 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2388 : 0;
2389 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002390 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002391
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002392 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002393# ifdef FEAT_PROP_POPUP
2394 // do not want virtual text counted here
2395 cts.cts_has_prop_with_text = FALSE;
2396# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002397 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002398 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002399
2400 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002401 // space for it again.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002402 if (wlv.vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002403 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002404 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2405 if (wlv.n_extra < 0)
2406 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002407 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002408 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002409 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002410 // line break, but for TABs the highlighting should
2411 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002412 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002413
Bram Moolenaar1306b362022-08-06 15:59:06 +01002414 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002415# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002416 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002417 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002418 wp->w_buffer->b_p_vts_array) - 1;
2419# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002420 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002421 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002422# endif
2423
Bram Moolenaar1306b362022-08-06 15:59:06 +01002424 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2425 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002426# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002427 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002428 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002429# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002430 if (VIM_ISWHITE(c))
2431 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002432# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002433 if (c == TAB)
2434 // See "Tab alignment" below.
2435 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002436# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002437 if (!wp->w_p_list)
2438 c = ' ';
2439 }
2440 }
2441#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002442 in_multispace = c == ' '
2443 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2444 if (!in_multispace)
2445 multispace_pos = 0;
2446
Bram Moolenaareed9d462021-02-15 20:38:25 +01002447 // 'list': Change char 160 to 'nbsp' and space to 'space'
2448 // setting in 'listchars'. But not when the character is
2449 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002450 if (wp->w_p_list
2451 && ((((c == 160 && mb_l == 1)
2452 || (mb_utf8
2453 && ((mb_c == 160 && mb_l == 2)
2454 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002455 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002456 || (c == ' '
2457 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002458 && (wp->w_lcs_chars.space
2459 || (in_multispace
2460 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002461 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002462 && ptr - line <= trailcol)))
2463 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002464 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2465 {
2466 c = wp->w_lcs_chars.multispace[multispace_pos++];
2467 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2468 multispace_pos = 0;
2469 }
2470 else
2471 c = (c == ' ') ? wp->w_lcs_chars.space
2472 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002473 if (area_attr == 0 && search_attr == 0)
2474 {
2475 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002476 extra_attr = hl_combine_attr(wlv.win_attr,
2477 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002478 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002479 }
2480 mb_c = c;
2481 if (enc_utf8 && utf_char2len(c) > 1)
2482 {
2483 mb_utf8 = TRUE;
2484 u8cc[0] = 0;
2485 c = 0xc0;
2486 }
2487 else
2488 mb_utf8 = FALSE;
2489 }
2490
zeertzjq2e7cba32022-06-10 15:30:32 +01002491 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2492 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002493 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002494 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2495 && wp->w_lcs_chars.leadmultispace != NULL)
2496 {
2497 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002498 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2499 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002500 multispace_pos = 0;
2501 }
2502
2503 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2504 c = wp->w_lcs_chars.trail;
2505
2506 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2507 c = wp->w_lcs_chars.lead;
2508
zeertzjq2e7cba32022-06-10 15:30:32 +01002509 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002510 c = wp->w_lcs_chars.space;
2511
2512
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002513 if (!attr_pri)
2514 {
2515 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002516 extra_attr = hl_combine_attr(wlv.win_attr,
2517 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002518 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002519 }
2520 mb_c = c;
2521 if (enc_utf8 && utf_char2len(c) > 1)
2522 {
2523 mb_utf8 = TRUE;
2524 u8cc[0] = 0;
2525 c = 0xc0;
2526 }
2527 else
2528 mb_utf8 = FALSE;
2529 }
2530 }
2531
2532 // Handling of non-printable characters.
2533 if (!vim_isprintc(c))
2534 {
2535 // when getting a character from the file, we may have to
2536 // turn it into something else on the way to putting it
2537 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002538 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002539 {
2540 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002541 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002542#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002543 char_u *sbr = get_showbreak_value(wp);
2544
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002545 // only adjust the tab_len, when at the first column
2546 // after the showbreak value was drawn
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002547 if (*sbr != NUL && wlv.vcol == vcol_sbr && wp->w_p_wrap)
2548 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002549#endif
2550 // tab amount depends on current column
2551#ifdef FEAT_VARTABS
2552 tab_len = tabstop_padding(vcol_adjusted,
2553 wp->w_buffer->b_p_ts,
2554 wp->w_buffer->b_p_vts_array) - 1;
2555#else
2556 tab_len = (int)wp->w_buffer->b_p_ts
2557 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2558#endif
2559
2560#ifdef FEAT_LINEBREAK
2561 if (!wp->w_p_lbr || !wp->w_p_list)
2562#endif
2563 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002564 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002565#ifdef FEAT_LINEBREAK
2566 else
2567 {
2568 char_u *p;
2569 int len;
2570 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002571 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002572
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002573# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002574 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002575 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002576 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002577
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002578 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002579 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002580 && old_boguscols > 0
2581 && wlv.n_extra > tab_len)
2582 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002583# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002584 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002585 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002586 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002587 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002588 if (wp->w_lcs_chars.tab3)
2589 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002590 if (wlv.n_extra > 0)
2591 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002592 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002593 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002594 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002595 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002596 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002597 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002598 vim_memset(p, ' ', len);
2599 p[len] = NUL;
2600 vim_free(p_extra_free);
2601 p_extra_free = p;
2602 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002603 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002604 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002605
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002606 if (*p == NUL)
2607 {
2608 tab_len = i;
2609 break;
2610 }
2611
2612 // if tab3 is given, use it for the last char
2613 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2614 lcs = wp->w_lcs_chars.tab3;
2615 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002616 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002617 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002618 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002619 wlv.p_extra = p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002620# ifdef FEAT_CONCEAL
2621 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2622 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002623 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002624 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002625# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002626 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002627 }
2628#endif
2629#ifdef FEAT_CONCEAL
2630 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002631 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002632
2633 // Tab alignment should be identical regardless of
2634 // 'conceallevel' value. So tab compensates of all
2635 // previous concealed characters, and thus resets
2636 // vcol_off and boguscols accumulated so far in the
2637 // line. Note that the tab can be longer than
2638 // 'tabstop' when there are concealed characters.
2639 FIX_FOR_BOGUSCOLS;
2640
2641 // Make sure, the highlighting for the tab char will be
2642 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002643 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002644 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002645 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002646 tab_len += vc_saved;
2647 }
2648#endif
2649 mb_utf8 = FALSE; // don't draw as UTF-8
2650 if (wp->w_p_list)
2651 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002652 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002653 ? wp->w_lcs_chars.tab3
2654 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002655#ifdef FEAT_LINEBREAK
2656 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002657 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002658 else
2659#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002660 wlv.c_extra = wp->w_lcs_chars.tab2;
2661 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002662 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002663 extra_attr = hl_combine_attr(wlv.win_attr,
2664 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002665 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002666 mb_c = c;
2667 if (enc_utf8 && utf_char2len(c) > 1)
2668 {
2669 mb_utf8 = TRUE;
2670 u8cc[0] = 0;
2671 c = 0xc0;
2672 }
2673 }
2674 else
2675 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002676 wlv.c_final = NUL;
2677 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002678 c = ' ';
2679 }
2680 }
2681 else if (c == NUL
2682 && (wp->w_p_list
2683 || ((fromcol >= 0 || fromcol_prev >= 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002684 && tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002685 && VIsual_mode != Ctrl_V
2686 && (
2687# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002688 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002689# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002690 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002691 && !(noinvcur
2692 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002693 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002694 && lcs_eol_one > 0)
2695 {
2696 // Display a '$' after the line or highlight an extra
2697 // character if the line break is included.
2698#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2699 // For a diff line the highlighting continues after the
2700 // "$".
2701 if (
2702# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002703 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002704# ifdef LINE_ATTR
2705 &&
2706# endif
2707# endif
2708# ifdef LINE_ATTR
2709 line_attr == 0
2710# endif
2711 )
2712#endif
2713 {
2714 // In virtualedit, visual selections may extend
2715 // beyond end of line.
2716 if (area_highlighting && virtual_active()
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002717 && tocol != MAXCOL && wlv.vcol < tocol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002718 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002719 else
2720 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002721 wlv.p_extra = at_end_str;
2722 wlv.n_extra = 1;
2723 wlv.c_extra = NUL;
2724 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002725 }
2726 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002727 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2728 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002729 else
2730 c = ' ';
2731 lcs_eol_one = -1;
2732 --ptr; // put it back at the NUL
2733 if (!attr_pri)
2734 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002735 extra_attr = hl_combine_attr(wlv.win_attr,
2736 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002737 n_attr = 1;
2738 }
2739 mb_c = c;
2740 if (enc_utf8 && utf_char2len(c) > 1)
2741 {
2742 mb_utf8 = TRUE;
2743 u8cc[0] = 0;
2744 c = 0xc0;
2745 }
2746 else
2747 mb_utf8 = FALSE; // don't draw as UTF-8
2748 }
2749 else if (c != NUL)
2750 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002751 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2752 if (wlv.n_extra == 0)
2753 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002754#ifdef FEAT_RIGHTLEFT
2755 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002756 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002757#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002758 wlv.c_extra = NUL;
2759 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002760#ifdef FEAT_LINEBREAK
2761 if (wp->w_p_lbr)
2762 {
2763 char_u *p;
2764
Bram Moolenaar1306b362022-08-06 15:59:06 +01002765 c = *wlv.p_extra;
2766 p = alloc(wlv.n_extra + 1);
2767 vim_memset(p, ' ', wlv.n_extra);
2768 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2769 p[wlv.n_extra] = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002770 vim_free(p_extra_free);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002771 p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002772 }
2773 else
2774#endif
2775 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002776 wlv.n_extra = byte2cells(c) - 1;
2777 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002778 }
2779 if (!attr_pri)
2780 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002781 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002782 extra_attr = hl_combine_attr(wlv.win_attr,
2783 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002784 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002785 }
2786 mb_utf8 = FALSE; // don't draw as UTF-8
2787 }
2788 else if (VIsual_active
2789 && (VIsual_mode == Ctrl_V
2790 || VIsual_mode == 'v')
2791 && virtual_active()
2792 && tocol != MAXCOL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002793 && wlv.vcol < tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002794 && (
2795#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002796 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002797#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002798 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002799 {
2800 c = ' ';
2801 --ptr; // put it back at the NUL
2802 }
2803#if defined(LINE_ATTR)
2804 else if ((
2805# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002806 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002807# endif
2808# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002809 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002810# endif
2811 line_attr != 0
2812 ) && (
2813# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002814 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002815# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002816 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002817# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002818 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002819# endif
2820 < wp->w_width)))
2821 {
2822 // Highlight until the right side of the window
2823 c = ' ';
2824 --ptr; // put it back at the NUL
2825
2826 // Remember we do the char for line highlighting.
2827 ++did_line_attr;
2828
2829 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01002830 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002831 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002832 || (wp->w_p_list &&
2833 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002834 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002835# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002836 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002837 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002838 wlv.diff_hlf = HLF_CHD;
2839 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002840 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002841 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002842 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2843 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01002844 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002845 || (wlv.vcol >= left_curline_col
2846 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002847 wlv.char_attr = hl_combine_attr(
2848 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002849 }
2850 }
2851# endif
2852# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002853 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002854 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002855 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002856 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2857 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002858 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002859 if (!wlv.cul_screenline
2860 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002861 && 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 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002866 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2867 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002868 }
2869# endif
2870 }
2871#endif
2872 }
2873
2874#ifdef FEAT_CONCEAL
2875 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01002876 && (wp != curwin || lnum != wp->w_cursor.lnum
2877 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002878 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2879 && !(lnum_in_visual_area
2880 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2881 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002882 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01002883 if (((prev_syntax_id != syntax_seqnr
2884 && (syntax_flags & HL_CONCEAL) != 0)
2885 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002886 && (syn_get_sub_char() != NUL
2887 || (has_match_conc && match_conc)
2888 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002889 && wp->w_p_cole != 3)
2890 {
2891 // First time at this concealed item: display one
2892 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002893 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002894 c = match_conc;
2895 else if (syn_get_sub_char() != NUL)
2896 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01002897 else if (wp->w_lcs_chars.conceal != NUL)
2898 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002899 else
2900 c = ' ';
2901
2902 prev_syntax_id = syntax_seqnr;
2903
Bram Moolenaar1306b362022-08-06 15:59:06 +01002904 if (wlv.n_extra > 0)
2905 wlv.vcol_off += wlv.n_extra;
2906 wlv.vcol += wlv.n_extra;
2907 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002908 {
2909# ifdef FEAT_RIGHTLEFT
2910 if (wp->w_p_rl)
2911 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002912 wlv.col -= wlv.n_extra;
2913 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002914 }
2915 else
2916# endif
2917 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002918 wlv.boguscols += wlv.n_extra;
2919 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002920 }
2921 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002922 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002923 n_attr = 0;
2924 }
2925 else if (n_skip == 0)
2926 {
2927 is_concealing = TRUE;
2928 n_skip = 1;
2929 }
2930 mb_c = c;
2931 if (enc_utf8 && utf_char2len(c) > 1)
2932 {
2933 mb_utf8 = TRUE;
2934 u8cc[0] = 0;
2935 c = 0xc0;
2936 }
2937 else
2938 mb_utf8 = FALSE; // don't draw as UTF-8
2939 }
2940 else
2941 {
2942 prev_syntax_id = 0;
2943 is_concealing = FALSE;
2944 }
2945
2946 if (n_skip > 0 && did_decrement_ptr)
2947 // not showing the '>', put pointer back to avoid getting stuck
2948 ++ptr;
2949
2950#endif // FEAT_CONCEAL
2951 }
2952
2953#ifdef FEAT_CONCEAL
2954 // In the cursor line and we may be concealing characters: correct
2955 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002956 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002957 && wp == curwin && lnum == wp->w_cursor.lnum
2958 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002959 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002960 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002961# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002962 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002963 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002964 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002965# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002966 wp->w_wcol = wlv.col - wlv.boguscols;
2967 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002968 did_wcol = TRUE;
2969 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002970# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01002971 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002972# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002973 }
2974#endif
2975
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002976 // Use "extra_attr", but don't override visual selection highlighting.
2977 // Don't use "extra_attr" until n_attr_skip is zero.
2978 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01002979 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002980 && !attr_pri)
2981 {
2982#ifdef LINE_ATTR
2983 if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002984 wlv.char_attr = hl_combine_attr(extra_attr, line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002985 else
2986#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002987 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002988 }
2989
2990#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2991 // XIM don't send preedit_start and preedit_end, but they send
2992 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
2993 // im_is_preediting() here.
2994 if (p_imst == IM_ON_THE_SPOT
2995 && xic != NULL
2996 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01002997 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002998 && !p_imdisable
2999 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003000 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003001 {
3002 colnr_T tcol;
3003
3004 if (preedit_end_col == MAXCOL)
3005 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3006 else
3007 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003008 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003009 {
3010 if (feedback_old_attr < 0)
3011 {
3012 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003013 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003014 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003015 wlv.char_attr = im_get_feedback_attr(feedback_col);
3016 if (wlv.char_attr < 0)
3017 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003018 feedback_col++;
3019 }
3020 else if (feedback_old_attr >= 0)
3021 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003022 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003023 feedback_old_attr = -1;
3024 feedback_col = 0;
3025 }
3026 }
3027#endif
3028 // Handle the case where we are in column 0 but not on the first
3029 // character of the line and the user wants us to show us a
3030 // special character (via 'listchars' option "precedes:<char>".
3031 if (lcs_prec_todo != NUL
3032 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003033 && (wp->w_p_wrap ?
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003034 (wp->w_skipcol > 0 && wlv.row == 0) :
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003035 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003036#ifdef FEAT_DIFF
3037 && filler_todo <= 0
3038#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003039 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003040 && c != NUL)
3041 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003042 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003043 lcs_prec_todo = NUL;
3044 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3045 {
3046 // Double-width character being overwritten by the "precedes"
3047 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003048 wlv.c_extra = MB_FILLER_CHAR;
3049 wlv.c_final = NUL;
3050 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003051 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003052 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003053 }
3054 mb_c = c;
3055 if (enc_utf8 && utf_char2len(c) > 1)
3056 {
3057 mb_utf8 = TRUE;
3058 u8cc[0] = 0;
3059 c = 0xc0;
3060 }
3061 else
3062 mb_utf8 = FALSE; // don't draw as UTF-8
3063 if (!attr_pri)
3064 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003065 saved_attr3 = wlv.char_attr; // save current attr
3066 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003067 n_attr3 = 1;
3068 }
3069 }
3070
3071 // At end of the text line or just after the last character.
3072 if ((c == NUL
3073#if defined(LINE_ATTR)
3074 || did_line_attr == 1
3075#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003076 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003077 {
3078#ifdef FEAT_SEARCH_EXTRA
3079 // flag to indicate whether prevcol equals startcol of search_hl or
3080 // one of the matches
3081 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3082 (long)(ptr - line) - (c == NUL));
3083#endif
3084 // Invert at least one char, used for Visual and empty line or
3085 // highlight match at end of line. If it's beyond the last
3086 // char on the screen, just overwrite that one (tricky!) Not
3087 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003088 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003089 && ((area_attr != 0 && wlv.vcol == fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003090 && (VIsual_mode != Ctrl_V
3091 || lnum == VIsual.lnum
3092 || lnum == curwin->w_cursor.lnum)
3093 && c == NUL)
3094#ifdef FEAT_SEARCH_EXTRA
3095 // highlight 'hlsearch' match at end of line
3096 || (prevcol_hl_flag
3097# ifdef FEAT_SYN_HL
3098 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3099 && !(wp == curwin && VIsual_active))
3100# endif
3101# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003102 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003103# endif
3104# if defined(LINE_ATTR)
3105 && did_line_attr <= 1
3106# endif
3107 )
3108#endif
3109 ))
3110 {
3111 int n = 0;
3112
3113#ifdef FEAT_RIGHTLEFT
3114 if (wp->w_p_rl)
3115 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003116 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003117 n = 1;
3118 }
3119 else
3120#endif
3121 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003122 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003123 n = -1;
3124 }
3125 if (n != 0)
3126 {
3127 // At the window boundary, highlight the last character
3128 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003129 wlv.off += n;
3130 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003131 }
3132 else
3133 {
3134 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003135 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003136 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003137 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003138 }
3139#ifdef FEAT_SEARCH_EXTRA
3140 if (area_attr == 0)
3141 {
3142 // Use attributes from match with highest priority among
3143 // 'search_hl' and the match list.
3144 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003145 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003146 }
3147#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003148 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003149 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003150#ifdef FEAT_RIGHTLEFT
3151 if (wp->w_p_rl)
3152 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003153 --wlv.col;
3154 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003155 }
3156 else
3157#endif
3158 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003159 ++wlv.col;
3160 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003161 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003162 ++wlv.vcol;
3163 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003164 }
3165 }
3166
3167 // At end of the text line.
3168 if (c == NUL)
3169 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003170 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003171
3172 // Update w_cline_height and w_cline_folded if the cursor line was
3173 // updated (saves a call to plines() later).
3174 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3175 {
3176 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003177 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003178#ifdef FEAT_FOLDING
3179 curwin->w_cline_folded = FALSE;
3180#endif
3181 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3182 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003183 break;
3184 }
3185
3186 // Show "extends" character from 'listchars' if beyond the line end and
3187 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003188 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003189 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003190 && wp->w_p_list
3191 && !wp->w_p_wrap
3192#ifdef FEAT_DIFF
3193 && filler_todo <= 0
3194#endif
3195 && (
3196#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003197 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003198#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003199 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003200 && (*ptr != NUL
3201 || (wp->w_p_list && lcs_eol_one > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003202 || (wlv.n_extra && (wlv.c_extra != NUL
3203 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003204 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003205 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003206 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003207 mb_c = c;
3208 if (enc_utf8 && utf_char2len(c) > 1)
3209 {
3210 mb_utf8 = TRUE;
3211 u8cc[0] = 0;
3212 c = 0xc0;
3213 }
3214 else
3215 mb_utf8 = FALSE;
3216 }
3217
3218#ifdef FEAT_SYN_HL
3219 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003220 if (wlv.draw_color_col)
3221 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003222
3223 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3224 // highlight the cursor position itself.
3225 // Also highlight the 'colorcolumn' if it is different than
3226 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003227 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3228 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003229 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003230 if (((wlv.draw_state == WL_LINE
3231 || wlv.draw_state == WL_BRI
3232 || wlv.draw_state == WL_SBR)
3233 && !lnum_in_visual_area
3234 && search_attr == 0
3235 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003236# ifdef FEAT_DIFF
3237 && filler_todo <= 0
3238# endif
3239 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003240 {
3241 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3242 && lnum != wp->w_cursor.lnum)
3243 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003244 vcol_save_attr = wlv.char_attr;
3245 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3246 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003247 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003248 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003249 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003250 vcol_save_attr = wlv.char_attr;
3251 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003252 }
3253 }
3254#endif
3255
3256 // Store character to be displayed.
3257 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003258 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003259 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003260 {
3261 // Store the character.
3262#if defined(FEAT_RIGHTLEFT)
3263 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3264 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003265 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003266 --wlv.off;
3267 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003268 }
3269#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003270 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003271 if (enc_dbcs == DBCS_JPNU)
3272 {
3273 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003274 ScreenLines[wlv.off] = 0x8e;
3275 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003276 }
3277 else if (enc_utf8)
3278 {
3279 if (mb_utf8)
3280 {
3281 int i;
3282
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003283 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003284 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003285 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003286 for (i = 0; i < Screen_mco; ++i)
3287 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003288 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003289 if (u8cc[i] == 0)
3290 break;
3291 }
3292 }
3293 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003294 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003295 }
3296 if (multi_attr)
3297 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003298 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003299 multi_attr = 0;
3300 }
3301 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003302 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003303
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003304 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003305
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003306 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3307 {
3308 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003309 ++wlv.off;
3310 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003311 if (enc_utf8)
3312 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003313 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003314 else
3315 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003316 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003317 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003318#ifdef FEAT_DIFF
3319 && filler_todo <= 0
3320#endif
3321 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003322 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003323 // When "tocol" is halfway a character, set it to the end of
3324 // the character, otherwise highlighting won't stop.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003325 if (tocol == wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003326 ++tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003327
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003328 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003329
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003330#ifdef FEAT_RIGHTLEFT
3331 if (wp->w_p_rl)
3332 {
3333 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003334 --wlv.off;
3335 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003336 }
3337#endif
3338 }
3339#ifdef FEAT_RIGHTLEFT
3340 if (wp->w_p_rl)
3341 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003342 --wlv.off;
3343 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003344 }
3345 else
3346#endif
3347 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003348 ++wlv.off;
3349 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003350 }
3351 }
3352#ifdef FEAT_CONCEAL
3353 else if (wp->w_p_cole > 0 && is_concealing)
3354 {
3355 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003356 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003357 if (wlv.n_extra > 0)
3358 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003359 if (wp->w_p_wrap)
3360 {
3361 // Special voodoo required if 'wrap' is on.
3362 //
3363 // Advance the column indicator to force the line
3364 // drawing to wrap early. This will make the line
3365 // take up the same screen space when parts are concealed,
3366 // so that cursor line computations aren't messed up.
3367 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003368 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003369 // trailing junk to be written out of the screen line
3370 // we are building, 'boguscols' keeps track of the number
3371 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003372 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003373 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003374 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003375# ifdef FEAT_RIGHTLEFT
3376 if (wp->w_p_rl)
3377 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003378 wlv.col -= wlv.n_extra;
3379 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003380 }
3381 else
3382# endif
3383 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003384 wlv.col += wlv.n_extra;
3385 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003386 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003387 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003388 n_attr = 0;
3389 }
3390
3391
3392 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3393 {
3394 // Need to fill two screen columns.
3395# ifdef FEAT_RIGHTLEFT
3396 if (wp->w_p_rl)
3397 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003398 --wlv.boguscols;
3399 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003400 }
3401 else
3402# endif
3403 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003404 ++wlv.boguscols;
3405 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003406 }
3407 }
3408
3409# ifdef FEAT_RIGHTLEFT
3410 if (wp->w_p_rl)
3411 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003412 --wlv.boguscols;
3413 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003414 }
3415 else
3416# endif
3417 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003418 ++wlv.boguscols;
3419 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003420 }
3421 }
3422 else
3423 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003424 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003425 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003426 wlv.vcol += wlv.n_extra;
3427 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003428 n_attr = 0;
3429 }
3430 }
3431
3432 }
3433#endif // FEAT_CONCEAL
3434 else
3435 --n_skip;
3436
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003437 // Only advance the "wlv.vcol" when after the 'number' or
3438 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003439 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003440#ifdef FEAT_DIFF
3441 && filler_todo <= 0
3442#endif
3443 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003444 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003445
3446#ifdef FEAT_SYN_HL
3447 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003448 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003449#endif
3450
3451 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003452 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3453 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003454
3455 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003456 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003457 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003458 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003459 if (n_attr_skip > 0)
3460 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003461
3462 // At end of screen line and there is more to come: Display the line
3463 // so far. If there is no more to display it is caught above.
3464 if ((
3465#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003466 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003467#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003468 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003469 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003470 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003471#ifdef FEAT_DIFF
3472 || filler_todo > 0
3473#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003474#ifdef FEAT_PROP_POPUP
3475 || text_prop_follows
3476#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003477 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003478 && wlv.p_extra != at_end_str)
3479 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3480 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003481 )
3482 {
3483#ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003484 screen_line(wp, wlv.screen_row, wp->w_wincol,
3485 wlv.col - wlv.boguscols,
3486 wp->w_width, wlv.screen_line_flags);
3487 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003488#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003489 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col,
3490 wp->w_width, wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003491#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003492 ++wlv.row;
3493 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003494
3495 // When not wrapping and finished diff lines, or when displayed
3496 // '$' and highlighting until last column, break here.
3497 if ((!wp->w_p_wrap
3498#ifdef FEAT_DIFF
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003499 && filler_todo <= 0
3500#endif
3501#ifdef FEAT_PROP_POPUP
3502 && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003503#endif
3504 ) || lcs_eol_one == -1)
3505 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003506#ifdef FEAT_PROP_POPUP
Bram Moolenaar83bf11a2022-08-06 22:23:40 +01003507 if (!wp->w_p_wrap && text_prop_follows)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003508 {
3509 // do not output more of the line, only the "below" prop
3510 ptr += STRLEN(ptr);
3511# ifdef FEAT_LINEBREAK
3512 dont_use_showbreak = TRUE;
3513# endif
3514 }
3515#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003516
3517 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003518 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003519#ifdef FEAT_DIFF
3520 && filler_todo <= 0
3521#endif
3522 )
3523 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003524 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3525 draw_vsep_win(wp, wlv.row);
3526 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003527 }
3528
3529 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003530 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003531 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003532 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003533 break;
3534 }
3535
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003536 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003537#ifdef FEAT_DIFF
3538 && filler_todo <= 0
3539#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003540#ifdef FEAT_PROP_POPUP
3541 && !text_prop_follows
3542#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003543 && wp->w_width == Columns)
3544 {
3545 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003546 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003547
3548 // Special trick to make copy/paste of wrapped lines work with
3549 // xterm/screen: write an extra character beyond the end of
3550 // the line. This will work with all terminal types
3551 // (regardless of the xn,am settings).
3552 // Only do this on a fast tty.
3553 // Only do this if the cursor is on the current line
3554 // (something has been written in it).
3555 // Don't do this for the GUI.
3556 // Don't do this for double-width characters.
3557 // Don't do this for a window not at the right screen border.
3558 if (p_tf
3559#ifdef FEAT_GUI
3560 && !gui.in_use
3561#endif
3562 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003563 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3564 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003565 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003566 || (*mb_off2cells)(
3567 LineOffset[wlv.screen_row - 1]
3568 + (int)Columns - 2,
3569 LineOffset[wlv.screen_row]
3570 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003571 {
3572 // First make sure we are at the end of the screen line,
3573 // then output the same character again to let the
3574 // terminal know about the wrap. If the terminal doesn't
3575 // auto-wrap, we overwrite the character.
3576 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003577 screen_char(LineOffset[wlv.screen_row - 1]
3578 + (unsigned)Columns - 1,
3579 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003580
3581 // When there is a multi-byte character, just output a
3582 // space to keep it simple.
3583 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003584 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003585 out_char(' ');
3586 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003587 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003588 + (Columns - 1)]);
3589 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003590 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003591 screen_start(); // don't know where cursor is now
3592 }
3593 }
3594
Bram Moolenaar1306b362022-08-06 15:59:06 +01003595 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003596
Bram Moolenaareed9d462021-02-15 20:38:25 +01003597 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003598#ifdef FEAT_LINEBREAK
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003599 if (!dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003600# ifdef FEAT_DIFF
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003601 && filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003602# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003603 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003604 need_showbreak = TRUE;
3605#endif
3606#ifdef FEAT_DIFF
3607 --filler_todo;
3608 // When the filler lines are actually below the last line of the
3609 // file, don't draw the line itself, break here.
3610 if (filler_todo == 0 && wp->w_botfill)
3611 break;
3612#endif
3613 }
3614
3615 } // for every character in the line
3616
3617#ifdef FEAT_SPELL
3618 // After an empty line check first word for capital.
3619 if (*skipwhite(line) == NUL)
3620 {
3621 capcol_lnum = lnum + 1;
3622 cap_col = 0;
3623 }
3624#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003625#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003626 vim_free(text_props);
3627 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003628 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003629#endif
3630
3631 vim_free(p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003632 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003633}