blob: d38cf7347ba959cc885357403b9d48aa25cfc9a7 [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 Moolenaar7f9969c2022-07-25 18:13:54 +01001713 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001714 text_prop_type = pt;
1715 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001716 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001717 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001718 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001719 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001720 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001721 }
1722 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001723 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001724 && -text_prop_id
1725 <= wp->w_buffer->b_textprop_text.ga_len)
1726 {
1727 char_u *p = ((char_u **)wp->w_buffer
1728 ->b_textprop_text.ga_data)[
1729 -text_prop_id - 1];
Bram Moolenaar1306b362022-08-06 15:59:06 +01001730
1731 // reset the ID in the copy to avoid it being used
1732 // again
1733 text_props[used_tpi].tp_id = -MAXCOL;
1734
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001735 if (p != NULL)
1736 {
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001737 int right = (text_props[used_tpi].tp_flags
1738 & TP_FLAG_ALIGN_RIGHT);
1739 int below = (text_props[used_tpi].tp_flags
1740 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaar398649e2022-08-04 15:03:48 +01001741 int wrap = (text_props[used_tpi].tp_flags
1742 & TP_FLAG_WRAP);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001743
Bram Moolenaar1306b362022-08-06 15:59:06 +01001744 wlv.p_extra = p;
1745 wlv.c_extra = NUL;
1746 wlv.c_final = NUL;
1747 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001748 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001749 n_attr = mb_charlen(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001750 text_prop_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001751 if (*ptr == NUL)
1752 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001753 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001754#ifdef FEAT_LINEBREAK
Bram Moolenaarcba69522022-08-06 21:03:53 +01001755 if (below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001756 {
1757 // no 'showbreak' before "below" text property
1758 // or after "right" text property
1759 need_showbreak = FALSE;
1760 dont_use_showbreak = TRUE;
1761 }
1762#endif
Bram Moolenaar398649e2022-08-04 15:03:48 +01001763 // Keep in sync with where
1764 // textprop_size_after_trunc() is called in
1765 // win_lbr_chartabsize().
1766 if ((right || below || !wrap) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001767 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001768 int added = wp->w_width - wlv.col;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001769 int n_used = wlv.n_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001770 char_u *l;
Bram Moolenaar398649e2022-08-04 15:03:48 +01001771 int strsize = wrap
Bram Moolenaar1306b362022-08-06 15:59:06 +01001772 ? vim_strsize(wlv.p_extra)
1773 : textprop_size_after_trunc(wp,
1774 below, added, wlv.p_extra, &n_used);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001775
Bram Moolenaar1306b362022-08-06 15:59:06 +01001776 if (wrap || right || below
1777 || n_used < wlv.n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001778 {
Bram Moolenaar398649e2022-08-04 15:03:48 +01001779 // Right-align: fill with spaces
1780 if (right)
1781 added -= strsize;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001782 if (added < 0
1783 || (below
1784 ? wlv.col == 0 || !wp->w_p_wrap
Bram Moolenaar1306b362022-08-06 15:59:06 +01001785 : n_used < wlv.n_extra))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001786 added = 0;
1787 // add 1 for NUL, 2 for when '…' is used
1788 l = alloc(n_used + added + 3);
1789 if (l != NULL)
1790 {
1791 vim_memset(l, ' ', added);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001792 vim_strncpy(l + added, wlv.p_extra,
1793 n_used);
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001794 if (n_used < wlv.n_extra
1795 && wp->w_p_wrap)
Bram Moolenaar398649e2022-08-04 15:03:48 +01001796 {
1797 char_u *lp = l + added + n_used - 1;
1798
1799 if (has_mbyte)
1800 {
1801 // change last character to '…'
1802 lp -= (*mb_head_off)(l, lp);
1803 STRCPY(lp, "…");
1804 n_used = lp - l + 3;
1805 }
1806 else
1807 // change last character to '>'
1808 *lp = '>';
1809 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001810 vim_free(p_extra_free2);
1811 wlv.p_extra = p_extra_free2 = l;
1812 wlv.n_extra = n_used + added;
Bram Moolenaar398649e2022-08-04 15:03:48 +01001813 n_attr_skip = added;
Bram Moolenaar1d8844a2022-08-10 13:39:35 +01001814 n_attr = mb_charlen(wlv.p_extra);
Bram Moolenaar398649e2022-08-04 15:03:48 +01001815 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001816 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001817
1818 // When 'wrap' is off then for "below" we need
1819 // to start a new line explictly.
Bram Moolenaardb9b96d2022-08-06 17:38:53 +01001820 if (below && wlv.col > win_col_off(wp)
1821 && !wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001822 {
1823 draw_screen_line(wp, &wlv);
1824
1825 // When line got too long for screen break
1826 // here.
1827 if (wlv.row == endrow)
1828 {
1829 ++wlv.row;
1830 break;
1831 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001832 win_line_start(wp, &wlv, TRUE);
1833 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001834 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001835 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001836 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001837
1838 // If another text prop follows the condition below at
1839 // the last window column must know.
1840 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001841 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001842 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001843 else if (text_prop_next < text_prop_count
1844 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001845 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
1846 || (!wp->w_p_wrap
1847 && wlv.col == wp->w_width - 1
1848 && (text_props[text_prop_next].tp_flags
1849 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001850 // When at last-but-one character and a text property
1851 // follows after it, we may need to flush the line after
1852 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001853 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01001854 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001855 }
1856#endif
1857
Bram Moolenaara74fda62019-10-19 17:38:03 +02001858#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001859 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001860 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001861 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001862# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001863 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001864 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001865# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001866 // Get syntax attribute.
1867 if (has_syntax)
1868 {
1869 // Get the syntax attribute for the character. If there
1870 // is an error, disable syntax highlighting.
1871 save_did_emsg = did_emsg;
1872 did_emsg = FALSE;
1873
1874 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001875 if (v == prev_syntax_col)
1876 // at same column again
1877 syntax_attr = prev_syntax_attr;
1878 else
1879 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001880# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001881 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001882# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001883 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001884# ifdef FEAT_SPELL
1885 has_spell ? &can_spell :
1886# endif
1887 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001888 prev_syntax_col = v;
1889 prev_syntax_attr = syntax_attr;
1890 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001891
Bram Moolenaar34390282019-10-16 14:38:26 +02001892 if (did_emsg)
1893 {
1894 wp->w_s->b_syn_error = TRUE;
1895 has_syntax = FALSE;
1896 syntax_attr = 0;
1897 }
1898 else
1899 did_emsg = save_did_emsg;
1900# ifdef SYN_TIME_LIMIT
1901 if (wp->w_s->b_syn_slow)
1902 has_syntax = FALSE;
1903# endif
1904
1905 // Need to get the line again, a multi-line regexp may
1906 // have made it invalid.
1907 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1908 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001909 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001910# ifdef FEAT_CONCEAL
1911 // no concealing past the end of the line, it interferes
1912 // with line highlighting
1913 if (*ptr == NUL)
1914 syntax_flags = 0;
1915 else
1916 syntax_flags = get_syntax_info(&syntax_seqnr);
1917# endif
1918 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001919 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001920# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001921 // Combine text property highlight into syntax highlight.
1922 if (text_prop_type != NULL)
1923 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001924 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01001925 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1926 else
1927 syntax_attr = text_prop_attr;
1928 }
1929# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001930#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001931
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001932 // Decide which of the highlight attributes to use.
1933 attr_pri = TRUE;
1934#ifdef LINE_ATTR
1935 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001936 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001937 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02001938 if (!highlight_match)
1939 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01001940 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001941# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001942 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001943# endif
1944 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001945 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001946 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001947 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001948# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001949 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001950# endif
1951 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001952 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001953 || wlv.vcol < fromcol || vcol_prev < fromcol_prev
1954 || wlv.vcol >= tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001955 {
1956 // Use line_attr when not in the Visual or 'incsearch' area
1957 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001958# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001959 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01001960# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001961 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001962# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001963 attr_pri = FALSE;
1964 }
1965#else
1966 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001967 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001968 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001969 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001970#endif
1971 else
1972 {
1973 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001974#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001975 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001976#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001977 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001978#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001979 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001980#ifdef FEAT_PROP_POPUP
1981 // override with text property highlight when "override" is TRUE
1982 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001983 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001984#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001985 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001986
1987 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001988 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001989 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001990 if (wlv.char_attr == 0)
1991 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001992 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001993 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001994 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001995
1996 // Get the next character to put on the screen.
1997
1998 // The "p_extra" points to the extra stuff that is inserted to
1999 // represent special characters (non-printable stuff) and other
2000 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002001 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002002 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2003 // "p_extra[n_extra]".
2004 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002005 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002006 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002007 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002008 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002009 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2010 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002011 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2012 if (enc_utf8 && utf_char2len(c) > 1)
2013 {
2014 mb_utf8 = TRUE;
2015 u8cc[0] = 0;
2016 c = 0xc0;
2017 }
2018 else
2019 mb_utf8 = FALSE;
2020 }
2021 else
2022 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002023 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002024 if (has_mbyte)
2025 {
2026 mb_c = c;
2027 if (enc_utf8)
2028 {
2029 // If the UTF-8 character is more than one byte:
2030 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002031 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002032 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002033 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002034 mb_l = 1;
2035 else if (mb_l > 1)
2036 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002037 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002038 mb_utf8 = TRUE;
2039 c = 0xc0;
2040 }
2041 }
2042 else
2043 {
2044 // if this is a DBCS character, put it in "mb_c"
2045 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002046 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002047 mb_l = 1;
2048 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002049 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002050 }
2051 if (mb_l == 0) // at the NUL at end-of-line
2052 mb_l = 1;
2053
2054 // If a double-width char doesn't fit display a '>' in the
2055 // last column.
2056 if ((
2057# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002058 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002059# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002060 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002061 && (*mb_char2cells)(mb_c) == 2)
2062 {
2063 c = '>';
2064 mb_c = c;
2065 mb_l = 1;
2066 mb_utf8 = FALSE;
2067 multi_attr = HL_ATTR(HLF_AT);
2068#ifdef FEAT_SYN_HL
2069 if (cul_attr)
2070 multi_attr = hl_combine_attr(multi_attr, cul_attr);
2071#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002072 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002073
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002074 // put the pointer back to output the double-width
2075 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002076 ++wlv.n_extra;
2077 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002078 }
2079 else
2080 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002081 wlv.n_extra -= mb_l - 1;
2082 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002083 }
2084 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002085 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002086 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002087 --wlv.n_extra;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002088#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002089 if (wlv.n_extra <= 0)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002090 in_linebreak = FALSE;
2091#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002092 }
2093 else
2094 {
2095#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002096 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002097#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002098 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002099
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002100 // Get a character from the line itself.
2101 c = *ptr;
2102#ifdef FEAT_LINEBREAK
2103 c0 = *ptr;
2104#endif
2105 if (has_mbyte)
2106 {
2107 mb_c = c;
2108 if (enc_utf8)
2109 {
2110 // If the UTF-8 character is more than one byte: Decode it
2111 // into "mb_c".
2112 mb_l = utfc_ptr2len(ptr);
2113 mb_utf8 = FALSE;
2114 if (mb_l > 1)
2115 {
2116 mb_c = utfc_ptr2char(ptr, u8cc);
2117 // Overlong encoded ASCII or ASCII with composing char
2118 // is displayed normally, except a NUL.
2119 if (mb_c < 0x80)
2120 {
2121 c = mb_c;
2122#ifdef FEAT_LINEBREAK
2123 c0 = mb_c;
2124#endif
2125 }
2126 mb_utf8 = TRUE;
2127
2128 // At start of the line we can have a composing char.
2129 // Draw it as a space with a composing char.
2130 if (utf_iscomposing(mb_c))
2131 {
2132 int i;
2133
2134 for (i = Screen_mco - 1; i > 0; --i)
2135 u8cc[i] = u8cc[i - 1];
2136 u8cc[0] = mb_c;
2137 mb_c = ' ';
2138 }
2139 }
2140
2141 if ((mb_l == 1 && c >= 0x80)
2142 || (mb_l >= 1 && mb_c == 0)
2143 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2144 {
2145 // Illegal UTF-8 byte: display as <xx>.
2146 // Non-BMP character : display as ? or fullwidth ?.
2147 transchar_hex(extra, mb_c);
2148# ifdef FEAT_RIGHTLEFT
2149 if (wp->w_p_rl) // reverse
2150 rl_mirror(extra);
2151# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002152 wlv.p_extra = extra;
2153 c = *wlv.p_extra;
2154 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002155 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002156 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2157 wlv.c_extra = NUL;
2158 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002159 if (area_attr == 0 && search_attr == 0)
2160 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002161 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002162 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002163 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002164 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002165 }
2166 }
2167 else if (mb_l == 0) // at the NUL at end-of-line
2168 mb_l = 1;
2169#ifdef FEAT_ARABIC
2170 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2171 {
2172 // Do Arabic shaping.
2173 int pc, pc1, nc;
2174 int pcc[MAX_MCO];
2175
2176 // The idea of what is the previous and next
2177 // character depends on 'rightleft'.
2178 if (wp->w_p_rl)
2179 {
2180 pc = prev_c;
2181 pc1 = prev_c1;
2182 nc = utf_ptr2char(ptr + mb_l);
2183 prev_c1 = u8cc[0];
2184 }
2185 else
2186 {
2187 pc = utfc_ptr2char(ptr + mb_l, pcc);
2188 nc = prev_c;
2189 pc1 = pcc[0];
2190 }
2191 prev_c = mb_c;
2192
2193 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2194 }
2195 else
2196 prev_c = mb_c;
2197#endif
2198 }
2199 else // enc_dbcs
2200 {
2201 mb_l = MB_BYTE2LEN(c);
2202 if (mb_l == 0) // at the NUL at end-of-line
2203 mb_l = 1;
2204 else if (mb_l > 1)
2205 {
2206 // We assume a second byte below 32 is illegal.
2207 // Hopefully this is OK for all double-byte encodings!
2208 if (ptr[1] >= 32)
2209 mb_c = (c << 8) + ptr[1];
2210 else
2211 {
2212 if (ptr[1] == NUL)
2213 {
2214 // head byte at end of line
2215 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002216 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002217 }
2218 else
2219 {
2220 // illegal tail byte
2221 mb_l = 2;
2222 STRCPY(extra, "XX");
2223 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002224 wlv.p_extra = extra;
2225 wlv.n_extra = (int)STRLEN(extra) - 1;
2226 wlv.c_extra = NUL;
2227 wlv.c_final = NUL;
2228 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002229 if (area_attr == 0 && search_attr == 0)
2230 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002231 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002232 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002233 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002234 // save current attr
2235 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002236 }
2237 mb_c = c;
2238 }
2239 }
2240 }
2241 // If a double-width char doesn't fit display a '>' in the
2242 // last column; the character is displayed at the start of the
2243 // next line.
2244 if ((
2245# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002246 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002247# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002248 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002249 && (*mb_char2cells)(mb_c) == 2)
2250 {
2251 c = '>';
2252 mb_c = c;
2253 mb_utf8 = FALSE;
2254 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002255 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002256 // Put pointer back so that the character will be
2257 // displayed at the start of the next line.
2258 --ptr;
2259#ifdef FEAT_CONCEAL
2260 did_decrement_ptr = TRUE;
2261#endif
2262 }
2263 else if (*ptr != NUL)
2264 ptr += mb_l - 1;
2265
2266 // If a double-width char doesn't fit at the left side display
2267 // a '<' in the first column. Don't do this for unprintable
2268 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002269 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002270 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002271 wlv.n_extra = 1;
2272 wlv.c_extra = MB_FILLER_CHAR;
2273 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002274 c = ' ';
2275 if (area_attr == 0 && search_attr == 0)
2276 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002277 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002278 extra_attr = hl_combine_attr(
2279 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002280 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002281 }
2282 mb_c = c;
2283 mb_utf8 = FALSE;
2284 mb_l = 1;
2285 }
2286
2287 }
2288 ++ptr;
2289
2290 if (extra_check)
2291 {
2292#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002293 // Check spelling (unless at the end of the line).
2294 // Only do this when there is no syntax highlighting, the
2295 // @Spell cluster is not used or the current syntax item
2296 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002297 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002298 if (has_spell && v >= word_end && v > cur_checked_col)
2299 {
2300 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002301 // do not calculate cap_col at the end of the line or when
2302 // only white space is following
2303 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002304# ifdef FEAT_SYN_HL
2305 !has_syntax ||
2306# endif
2307 can_spell))
2308 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002309 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002310 int len;
2311 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002312
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002313 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002314 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002315
2316 // Use nextline[] if possible, it has the start of the
2317 // next line concatenated.
2318 if ((prev_ptr - line) - nextlinecol >= 0)
2319 p = nextline + (prev_ptr - line) - nextlinecol;
2320 else
2321 p = prev_ptr;
2322 cap_col -= (int)(prev_ptr - line);
2323 len = spell_check(wp, p, &spell_hlf, &cap_col,
2324 nochange);
2325 word_end = v + len;
2326
2327 // In Insert mode only highlight a word that
2328 // doesn't touch the cursor.
2329 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002330 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002331 && wp->w_cursor.lnum == lnum
2332 && wp->w_cursor.col >=
2333 (colnr_T)(prev_ptr - line)
2334 && wp->w_cursor.col < (colnr_T)word_end)
2335 {
2336 spell_hlf = HLF_COUNT;
2337 spell_redraw_lnum = lnum;
2338 }
2339
2340 if (spell_hlf == HLF_COUNT && p != prev_ptr
2341 && (p - nextline) + len > nextline_idx)
2342 {
2343 // Remember that the good word continues at the
2344 // start of the next line.
2345 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002346 checked_col = (int)((p - nextline)
2347 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002348 }
2349
2350 // Turn index into actual attributes.
2351 if (spell_hlf != HLF_COUNT)
2352 spell_attr = highlight_attr[spell_hlf];
2353
2354 if (cap_col > 0)
2355 {
2356 if (p != prev_ptr
2357 && (p - nextline) + cap_col >= nextline_idx)
2358 {
2359 // Remember that the word in the next line
2360 // must start with a capital.
2361 capcol_lnum = lnum + 1;
2362 cap_col = (int)((p - nextline) + cap_col
2363 - nextline_idx);
2364 }
2365 else
2366 // Compute the actual column.
2367 cap_col += (int)(prev_ptr - line);
2368 }
2369 }
2370 }
2371 if (spell_attr != 0)
2372 {
2373 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002374 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2375 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002376 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002377 wlv.char_attr = hl_combine_attr(spell_attr,
2378 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002379 }
2380#endif
2381#ifdef FEAT_LINEBREAK
2382 // Found last space before word: check for line break.
2383 if (wp->w_p_lbr && c0 == c
2384 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2385 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002386 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2387 : 0;
2388 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002389 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002390
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002391 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002392# ifdef FEAT_PROP_POPUP
2393 // do not want virtual text counted here
2394 cts.cts_has_prop_with_text = FALSE;
2395# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002396 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002397 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002398
2399 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002400 // space for it again.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002401 if (wlv.vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002402 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002403 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2404 if (wlv.n_extra < 0)
2405 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002406 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002407 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002408 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002409 // line break, but for TABs the highlighting should
2410 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002411 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002412
Bram Moolenaar1306b362022-08-06 15:59:06 +01002413 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002414# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002415 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002416 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002417 wp->w_buffer->b_p_vts_array) - 1;
2418# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002419 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002420 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002421# endif
2422
Bram Moolenaar1306b362022-08-06 15:59:06 +01002423 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2424 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002425# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002426 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002427 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002428# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002429 if (VIM_ISWHITE(c))
2430 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002431# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002432 if (c == TAB)
2433 // See "Tab alignment" below.
2434 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002435# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002436 if (!wp->w_p_list)
2437 c = ' ';
2438 }
2439 }
2440#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002441 in_multispace = c == ' '
2442 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2443 if (!in_multispace)
2444 multispace_pos = 0;
2445
Bram Moolenaareed9d462021-02-15 20:38:25 +01002446 // 'list': Change char 160 to 'nbsp' and space to 'space'
2447 // setting in 'listchars'. But not when the character is
2448 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002449 if (wp->w_p_list
2450 && ((((c == 160 && mb_l == 1)
2451 || (mb_utf8
2452 && ((mb_c == 160 && mb_l == 2)
2453 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002454 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002455 || (c == ' '
2456 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002457 && (wp->w_lcs_chars.space
2458 || (in_multispace
2459 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002460 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002461 && ptr - line <= trailcol)))
2462 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002463 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2464 {
2465 c = wp->w_lcs_chars.multispace[multispace_pos++];
2466 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2467 multispace_pos = 0;
2468 }
2469 else
2470 c = (c == ' ') ? wp->w_lcs_chars.space
2471 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002472 if (area_attr == 0 && search_attr == 0)
2473 {
2474 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002475 extra_attr = hl_combine_attr(wlv.win_attr,
2476 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002477 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002478 }
2479 mb_c = c;
2480 if (enc_utf8 && utf_char2len(c) > 1)
2481 {
2482 mb_utf8 = TRUE;
2483 u8cc[0] = 0;
2484 c = 0xc0;
2485 }
2486 else
2487 mb_utf8 = FALSE;
2488 }
2489
zeertzjq2e7cba32022-06-10 15:30:32 +01002490 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2491 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002492 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002493 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2494 && wp->w_lcs_chars.leadmultispace != NULL)
2495 {
2496 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002497 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2498 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002499 multispace_pos = 0;
2500 }
2501
2502 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2503 c = wp->w_lcs_chars.trail;
2504
2505 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2506 c = wp->w_lcs_chars.lead;
2507
zeertzjq2e7cba32022-06-10 15:30:32 +01002508 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002509 c = wp->w_lcs_chars.space;
2510
2511
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002512 if (!attr_pri)
2513 {
2514 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002515 extra_attr = hl_combine_attr(wlv.win_attr,
2516 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002517 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002518 }
2519 mb_c = c;
2520 if (enc_utf8 && utf_char2len(c) > 1)
2521 {
2522 mb_utf8 = TRUE;
2523 u8cc[0] = 0;
2524 c = 0xc0;
2525 }
2526 else
2527 mb_utf8 = FALSE;
2528 }
2529 }
2530
2531 // Handling of non-printable characters.
2532 if (!vim_isprintc(c))
2533 {
2534 // when getting a character from the file, we may have to
2535 // turn it into something else on the way to putting it
2536 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002537 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002538 {
2539 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002540 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002541#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002542 char_u *sbr = get_showbreak_value(wp);
2543
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002544 // only adjust the tab_len, when at the first column
2545 // after the showbreak value was drawn
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002546 if (*sbr != NUL && wlv.vcol == vcol_sbr && wp->w_p_wrap)
2547 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002548#endif
2549 // tab amount depends on current column
2550#ifdef FEAT_VARTABS
2551 tab_len = tabstop_padding(vcol_adjusted,
2552 wp->w_buffer->b_p_ts,
2553 wp->w_buffer->b_p_vts_array) - 1;
2554#else
2555 tab_len = (int)wp->w_buffer->b_p_ts
2556 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2557#endif
2558
2559#ifdef FEAT_LINEBREAK
2560 if (!wp->w_p_lbr || !wp->w_p_list)
2561#endif
2562 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002563 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002564#ifdef FEAT_LINEBREAK
2565 else
2566 {
2567 char_u *p;
2568 int len;
2569 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002570 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002571
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002572# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002573 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002574 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002575 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002576
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002577 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002578 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002579 && old_boguscols > 0
2580 && wlv.n_extra > tab_len)
2581 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002582# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002583 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002584 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002585 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002586 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002587 if (wp->w_lcs_chars.tab3)
2588 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002589 if (wlv.n_extra > 0)
2590 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002591 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002592 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002593 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002594 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002595 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002596 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002597 vim_memset(p, ' ', len);
2598 p[len] = NUL;
2599 vim_free(p_extra_free);
2600 p_extra_free = p;
2601 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002602 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002603 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002604
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002605 if (*p == NUL)
2606 {
2607 tab_len = i;
2608 break;
2609 }
2610
2611 // if tab3 is given, use it for the last char
2612 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2613 lcs = wp->w_lcs_chars.tab3;
2614 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002615 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002616 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002617 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002618 wlv.p_extra = p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002619# ifdef FEAT_CONCEAL
2620 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2621 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002622 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002623 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002624# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002625 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002626 }
2627#endif
2628#ifdef FEAT_CONCEAL
2629 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002630 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002631
2632 // Tab alignment should be identical regardless of
2633 // 'conceallevel' value. So tab compensates of all
2634 // previous concealed characters, and thus resets
2635 // vcol_off and boguscols accumulated so far in the
2636 // line. Note that the tab can be longer than
2637 // 'tabstop' when there are concealed characters.
2638 FIX_FOR_BOGUSCOLS;
2639
2640 // Make sure, the highlighting for the tab char will be
2641 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002642 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002643 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002644 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002645 tab_len += vc_saved;
2646 }
2647#endif
2648 mb_utf8 = FALSE; // don't draw as UTF-8
2649 if (wp->w_p_list)
2650 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002651 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002652 ? wp->w_lcs_chars.tab3
2653 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002654#ifdef FEAT_LINEBREAK
2655 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002656 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002657 else
2658#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002659 wlv.c_extra = wp->w_lcs_chars.tab2;
2660 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002661 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002662 extra_attr = hl_combine_attr(wlv.win_attr,
2663 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002664 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002665 mb_c = c;
2666 if (enc_utf8 && utf_char2len(c) > 1)
2667 {
2668 mb_utf8 = TRUE;
2669 u8cc[0] = 0;
2670 c = 0xc0;
2671 }
2672 }
2673 else
2674 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002675 wlv.c_final = NUL;
2676 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002677 c = ' ';
2678 }
2679 }
2680 else if (c == NUL
2681 && (wp->w_p_list
2682 || ((fromcol >= 0 || fromcol_prev >= 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002683 && tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002684 && VIsual_mode != Ctrl_V
2685 && (
2686# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002687 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002688# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002689 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002690 && !(noinvcur
2691 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002692 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002693 && lcs_eol_one > 0)
2694 {
2695 // Display a '$' after the line or highlight an extra
2696 // character if the line break is included.
2697#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2698 // For a diff line the highlighting continues after the
2699 // "$".
2700 if (
2701# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002702 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002703# ifdef LINE_ATTR
2704 &&
2705# endif
2706# endif
2707# ifdef LINE_ATTR
2708 line_attr == 0
2709# endif
2710 )
2711#endif
2712 {
2713 // In virtualedit, visual selections may extend
2714 // beyond end of line.
2715 if (area_highlighting && virtual_active()
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002716 && tocol != MAXCOL && wlv.vcol < tocol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002717 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002718 else
2719 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002720 wlv.p_extra = at_end_str;
2721 wlv.n_extra = 1;
2722 wlv.c_extra = NUL;
2723 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002724 }
2725 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002726 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2727 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002728 else
2729 c = ' ';
2730 lcs_eol_one = -1;
2731 --ptr; // put it back at the NUL
2732 if (!attr_pri)
2733 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002734 extra_attr = hl_combine_attr(wlv.win_attr,
2735 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002736 n_attr = 1;
2737 }
2738 mb_c = c;
2739 if (enc_utf8 && utf_char2len(c) > 1)
2740 {
2741 mb_utf8 = TRUE;
2742 u8cc[0] = 0;
2743 c = 0xc0;
2744 }
2745 else
2746 mb_utf8 = FALSE; // don't draw as UTF-8
2747 }
2748 else if (c != NUL)
2749 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002750 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2751 if (wlv.n_extra == 0)
2752 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002753#ifdef FEAT_RIGHTLEFT
2754 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002755 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002756#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002757 wlv.c_extra = NUL;
2758 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002759#ifdef FEAT_LINEBREAK
2760 if (wp->w_p_lbr)
2761 {
2762 char_u *p;
2763
Bram Moolenaar1306b362022-08-06 15:59:06 +01002764 c = *wlv.p_extra;
2765 p = alloc(wlv.n_extra + 1);
2766 vim_memset(p, ' ', wlv.n_extra);
2767 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2768 p[wlv.n_extra] = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002769 vim_free(p_extra_free);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002770 p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002771 }
2772 else
2773#endif
2774 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002775 wlv.n_extra = byte2cells(c) - 1;
2776 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002777 }
2778 if (!attr_pri)
2779 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002780 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002781 extra_attr = hl_combine_attr(wlv.win_attr,
2782 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002783 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002784 }
2785 mb_utf8 = FALSE; // don't draw as UTF-8
2786 }
2787 else if (VIsual_active
2788 && (VIsual_mode == Ctrl_V
2789 || VIsual_mode == 'v')
2790 && virtual_active()
2791 && tocol != MAXCOL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002792 && wlv.vcol < tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002793 && (
2794#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002795 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002796#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002797 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002798 {
2799 c = ' ';
2800 --ptr; // put it back at the NUL
2801 }
2802#if defined(LINE_ATTR)
2803 else if ((
2804# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002805 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002806# endif
2807# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002808 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002809# endif
2810 line_attr != 0
2811 ) && (
2812# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002813 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002814# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002815 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002816# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002817 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002818# endif
2819 < wp->w_width)))
2820 {
2821 // Highlight until the right side of the window
2822 c = ' ';
2823 --ptr; // put it back at the NUL
2824
2825 // Remember we do the char for line highlighting.
2826 ++did_line_attr;
2827
2828 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01002829 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002830 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002831 || (wp->w_p_list &&
2832 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002833 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002834# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002835 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002836 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002837 wlv.diff_hlf = HLF_CHD;
2838 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002839 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002840 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002841 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2842 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01002843 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002844 || (wlv.vcol >= left_curline_col
2845 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002846 wlv.char_attr = hl_combine_attr(
2847 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002848 }
2849 }
2850# endif
2851# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002852 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002853 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002854 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002855 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2856 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002857 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002858 if (!wlv.cul_screenline
2859 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002860 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002861 wlv.char_attr = hl_combine_attr(
2862 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002863 }
2864 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002865 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2866 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002867 }
2868# endif
2869 }
2870#endif
2871 }
2872
2873#ifdef FEAT_CONCEAL
2874 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01002875 && (wp != curwin || lnum != wp->w_cursor.lnum
2876 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002877 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2878 && !(lnum_in_visual_area
2879 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2880 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002881 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01002882 if (((prev_syntax_id != syntax_seqnr
2883 && (syntax_flags & HL_CONCEAL) != 0)
2884 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002885 && (syn_get_sub_char() != NUL
2886 || (has_match_conc && match_conc)
2887 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002888 && wp->w_p_cole != 3)
2889 {
2890 // First time at this concealed item: display one
2891 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002892 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002893 c = match_conc;
2894 else if (syn_get_sub_char() != NUL)
2895 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01002896 else if (wp->w_lcs_chars.conceal != NUL)
2897 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002898 else
2899 c = ' ';
2900
2901 prev_syntax_id = syntax_seqnr;
2902
Bram Moolenaar1306b362022-08-06 15:59:06 +01002903 if (wlv.n_extra > 0)
2904 wlv.vcol_off += wlv.n_extra;
2905 wlv.vcol += wlv.n_extra;
2906 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002907 {
2908# ifdef FEAT_RIGHTLEFT
2909 if (wp->w_p_rl)
2910 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002911 wlv.col -= wlv.n_extra;
2912 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002913 }
2914 else
2915# endif
2916 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002917 wlv.boguscols += wlv.n_extra;
2918 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002919 }
2920 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002921 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002922 n_attr = 0;
2923 }
2924 else if (n_skip == 0)
2925 {
2926 is_concealing = TRUE;
2927 n_skip = 1;
2928 }
2929 mb_c = c;
2930 if (enc_utf8 && utf_char2len(c) > 1)
2931 {
2932 mb_utf8 = TRUE;
2933 u8cc[0] = 0;
2934 c = 0xc0;
2935 }
2936 else
2937 mb_utf8 = FALSE; // don't draw as UTF-8
2938 }
2939 else
2940 {
2941 prev_syntax_id = 0;
2942 is_concealing = FALSE;
2943 }
2944
2945 if (n_skip > 0 && did_decrement_ptr)
2946 // not showing the '>', put pointer back to avoid getting stuck
2947 ++ptr;
2948
2949#endif // FEAT_CONCEAL
2950 }
2951
2952#ifdef FEAT_CONCEAL
2953 // In the cursor line and we may be concealing characters: correct
2954 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002955 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002956 && wp == curwin && lnum == wp->w_cursor.lnum
2957 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002958 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002959 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002960# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002961 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002962 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002963 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002964# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002965 wp->w_wcol = wlv.col - wlv.boguscols;
2966 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002967 did_wcol = TRUE;
2968 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002969# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01002970 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002971# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002972 }
2973#endif
2974
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002975 // Use "extra_attr", but don't override visual selection highlighting.
2976 // Don't use "extra_attr" until n_attr_skip is zero.
2977 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01002978 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002979 && !attr_pri)
2980 {
2981#ifdef LINE_ATTR
2982 if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002983 wlv.char_attr = hl_combine_attr(extra_attr, line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002984 else
2985#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002986 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002987 }
2988
2989#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2990 // XIM don't send preedit_start and preedit_end, but they send
2991 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
2992 // im_is_preediting() here.
2993 if (p_imst == IM_ON_THE_SPOT
2994 && xic != NULL
2995 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01002996 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002997 && !p_imdisable
2998 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01002999 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003000 {
3001 colnr_T tcol;
3002
3003 if (preedit_end_col == MAXCOL)
3004 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3005 else
3006 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003007 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003008 {
3009 if (feedback_old_attr < 0)
3010 {
3011 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003012 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003013 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003014 wlv.char_attr = im_get_feedback_attr(feedback_col);
3015 if (wlv.char_attr < 0)
3016 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003017 feedback_col++;
3018 }
3019 else if (feedback_old_attr >= 0)
3020 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003021 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003022 feedback_old_attr = -1;
3023 feedback_col = 0;
3024 }
3025 }
3026#endif
3027 // Handle the case where we are in column 0 but not on the first
3028 // character of the line and the user wants us to show us a
3029 // special character (via 'listchars' option "precedes:<char>".
3030 if (lcs_prec_todo != NUL
3031 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003032 && (wp->w_p_wrap ?
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003033 (wp->w_skipcol > 0 && wlv.row == 0) :
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003034 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003035#ifdef FEAT_DIFF
3036 && filler_todo <= 0
3037#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003038 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003039 && c != NUL)
3040 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003041 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003042 lcs_prec_todo = NUL;
3043 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3044 {
3045 // Double-width character being overwritten by the "precedes"
3046 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003047 wlv.c_extra = MB_FILLER_CHAR;
3048 wlv.c_final = NUL;
3049 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003050 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003051 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003052 }
3053 mb_c = c;
3054 if (enc_utf8 && utf_char2len(c) > 1)
3055 {
3056 mb_utf8 = TRUE;
3057 u8cc[0] = 0;
3058 c = 0xc0;
3059 }
3060 else
3061 mb_utf8 = FALSE; // don't draw as UTF-8
3062 if (!attr_pri)
3063 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003064 saved_attr3 = wlv.char_attr; // save current attr
3065 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003066 n_attr3 = 1;
3067 }
3068 }
3069
3070 // At end of the text line or just after the last character.
3071 if ((c == NUL
3072#if defined(LINE_ATTR)
3073 || did_line_attr == 1
3074#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003075 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003076 {
3077#ifdef FEAT_SEARCH_EXTRA
3078 // flag to indicate whether prevcol equals startcol of search_hl or
3079 // one of the matches
3080 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3081 (long)(ptr - line) - (c == NUL));
3082#endif
3083 // Invert at least one char, used for Visual and empty line or
3084 // highlight match at end of line. If it's beyond the last
3085 // char on the screen, just overwrite that one (tricky!) Not
3086 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003087 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003088 && ((area_attr != 0 && wlv.vcol == fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003089 && (VIsual_mode != Ctrl_V
3090 || lnum == VIsual.lnum
3091 || lnum == curwin->w_cursor.lnum)
3092 && c == NUL)
3093#ifdef FEAT_SEARCH_EXTRA
3094 // highlight 'hlsearch' match at end of line
3095 || (prevcol_hl_flag
3096# ifdef FEAT_SYN_HL
3097 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3098 && !(wp == curwin && VIsual_active))
3099# endif
3100# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003101 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003102# endif
3103# if defined(LINE_ATTR)
3104 && did_line_attr <= 1
3105# endif
3106 )
3107#endif
3108 ))
3109 {
3110 int n = 0;
3111
3112#ifdef FEAT_RIGHTLEFT
3113 if (wp->w_p_rl)
3114 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003115 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003116 n = 1;
3117 }
3118 else
3119#endif
3120 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003121 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003122 n = -1;
3123 }
3124 if (n != 0)
3125 {
3126 // At the window boundary, highlight the last character
3127 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003128 wlv.off += n;
3129 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003130 }
3131 else
3132 {
3133 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003134 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003135 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003136 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003137 }
3138#ifdef FEAT_SEARCH_EXTRA
3139 if (area_attr == 0)
3140 {
3141 // Use attributes from match with highest priority among
3142 // 'search_hl' and the match list.
3143 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003144 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003145 }
3146#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003147 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003148 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003149#ifdef FEAT_RIGHTLEFT
3150 if (wp->w_p_rl)
3151 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003152 --wlv.col;
3153 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003154 }
3155 else
3156#endif
3157 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003158 ++wlv.col;
3159 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003160 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003161 ++wlv.vcol;
3162 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003163 }
3164 }
3165
3166 // At end of the text line.
3167 if (c == NUL)
3168 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003169 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003170
3171 // Update w_cline_height and w_cline_folded if the cursor line was
3172 // updated (saves a call to plines() later).
3173 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3174 {
3175 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003176 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003177#ifdef FEAT_FOLDING
3178 curwin->w_cline_folded = FALSE;
3179#endif
3180 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3181 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003182 break;
3183 }
3184
3185 // Show "extends" character from 'listchars' if beyond the line end and
3186 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003187 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003188 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003189 && wp->w_p_list
3190 && !wp->w_p_wrap
3191#ifdef FEAT_DIFF
3192 && filler_todo <= 0
3193#endif
3194 && (
3195#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003196 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003197#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003198 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003199 && (*ptr != NUL
3200 || (wp->w_p_list && lcs_eol_one > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003201 || (wlv.n_extra && (wlv.c_extra != NUL
3202 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003203 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003204 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003205 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003206 mb_c = c;
3207 if (enc_utf8 && utf_char2len(c) > 1)
3208 {
3209 mb_utf8 = TRUE;
3210 u8cc[0] = 0;
3211 c = 0xc0;
3212 }
3213 else
3214 mb_utf8 = FALSE;
3215 }
3216
3217#ifdef FEAT_SYN_HL
3218 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003219 if (wlv.draw_color_col)
3220 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003221
3222 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3223 // highlight the cursor position itself.
3224 // Also highlight the 'colorcolumn' if it is different than
3225 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003226 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3227 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003228 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003229 if (((wlv.draw_state == WL_LINE
3230 || wlv.draw_state == WL_BRI
3231 || wlv.draw_state == WL_SBR)
3232 && !lnum_in_visual_area
3233 && search_attr == 0
3234 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003235# ifdef FEAT_DIFF
3236 && filler_todo <= 0
3237# endif
3238 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003239 {
3240 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3241 && lnum != wp->w_cursor.lnum)
3242 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003243 vcol_save_attr = wlv.char_attr;
3244 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3245 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003246 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003247 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003248 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003249 vcol_save_attr = wlv.char_attr;
3250 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003251 }
3252 }
3253#endif
3254
3255 // Store character to be displayed.
3256 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003257 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003258 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003259 {
3260 // Store the character.
3261#if defined(FEAT_RIGHTLEFT)
3262 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3263 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003264 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003265 --wlv.off;
3266 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003267 }
3268#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003269 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003270 if (enc_dbcs == DBCS_JPNU)
3271 {
3272 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003273 ScreenLines[wlv.off] = 0x8e;
3274 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003275 }
3276 else if (enc_utf8)
3277 {
3278 if (mb_utf8)
3279 {
3280 int i;
3281
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003282 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003283 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003284 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003285 for (i = 0; i < Screen_mco; ++i)
3286 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003287 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003288 if (u8cc[i] == 0)
3289 break;
3290 }
3291 }
3292 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003293 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003294 }
3295 if (multi_attr)
3296 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003297 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003298 multi_attr = 0;
3299 }
3300 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003301 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003302
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003303 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003304
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003305 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3306 {
3307 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003308 ++wlv.off;
3309 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003310 if (enc_utf8)
3311 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003312 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003313 else
3314 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003315 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003316 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003317#ifdef FEAT_DIFF
3318 && filler_todo <= 0
3319#endif
3320 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003321 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003322 // When "tocol" is halfway a character, set it to the end of
3323 // the character, otherwise highlighting won't stop.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003324 if (tocol == wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003325 ++tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003326
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003327 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003328
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003329#ifdef FEAT_RIGHTLEFT
3330 if (wp->w_p_rl)
3331 {
3332 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003333 --wlv.off;
3334 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003335 }
3336#endif
3337 }
3338#ifdef FEAT_RIGHTLEFT
3339 if (wp->w_p_rl)
3340 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003341 --wlv.off;
3342 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003343 }
3344 else
3345#endif
3346 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003347 ++wlv.off;
3348 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003349 }
3350 }
3351#ifdef FEAT_CONCEAL
3352 else if (wp->w_p_cole > 0 && is_concealing)
3353 {
3354 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003355 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003356 if (wlv.n_extra > 0)
3357 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003358 if (wp->w_p_wrap)
3359 {
3360 // Special voodoo required if 'wrap' is on.
3361 //
3362 // Advance the column indicator to force the line
3363 // drawing to wrap early. This will make the line
3364 // take up the same screen space when parts are concealed,
3365 // so that cursor line computations aren't messed up.
3366 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003367 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003368 // trailing junk to be written out of the screen line
3369 // we are building, 'boguscols' keeps track of the number
3370 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003371 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003372 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003373 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003374# ifdef FEAT_RIGHTLEFT
3375 if (wp->w_p_rl)
3376 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003377 wlv.col -= wlv.n_extra;
3378 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003379 }
3380 else
3381# endif
3382 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003383 wlv.col += wlv.n_extra;
3384 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003385 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003386 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003387 n_attr = 0;
3388 }
3389
3390
3391 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3392 {
3393 // Need to fill two screen columns.
3394# ifdef FEAT_RIGHTLEFT
3395 if (wp->w_p_rl)
3396 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003397 --wlv.boguscols;
3398 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003399 }
3400 else
3401# endif
3402 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003403 ++wlv.boguscols;
3404 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003405 }
3406 }
3407
3408# ifdef FEAT_RIGHTLEFT
3409 if (wp->w_p_rl)
3410 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003411 --wlv.boguscols;
3412 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003413 }
3414 else
3415# endif
3416 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003417 ++wlv.boguscols;
3418 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003419 }
3420 }
3421 else
3422 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003423 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003424 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003425 wlv.vcol += wlv.n_extra;
3426 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003427 n_attr = 0;
3428 }
3429 }
3430
3431 }
3432#endif // FEAT_CONCEAL
3433 else
3434 --n_skip;
3435
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003436 // Only advance the "wlv.vcol" when after the 'number' or
3437 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003438 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003439#ifdef FEAT_DIFF
3440 && filler_todo <= 0
3441#endif
3442 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003443 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003444
3445#ifdef FEAT_SYN_HL
3446 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003447 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003448#endif
3449
3450 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003451 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3452 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003453
3454 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003455 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003456 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003457 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003458 if (n_attr_skip > 0)
3459 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003460
3461 // At end of screen line and there is more to come: Display the line
3462 // so far. If there is no more to display it is caught above.
3463 if ((
3464#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003465 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003466#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003467 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003468 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003469 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003470#ifdef FEAT_DIFF
3471 || filler_todo > 0
3472#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003473#ifdef FEAT_PROP_POPUP
3474 || text_prop_follows
3475#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003476 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003477 && wlv.p_extra != at_end_str)
3478 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3479 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003480 )
3481 {
3482#ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003483 screen_line(wp, wlv.screen_row, wp->w_wincol,
3484 wlv.col - wlv.boguscols,
3485 wp->w_width, wlv.screen_line_flags);
3486 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003487#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003488 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col,
3489 wp->w_width, wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003490#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003491 ++wlv.row;
3492 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003493
3494 // When not wrapping and finished diff lines, or when displayed
3495 // '$' and highlighting until last column, break here.
3496 if ((!wp->w_p_wrap
3497#ifdef FEAT_DIFF
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003498 && filler_todo <= 0
3499#endif
3500#ifdef FEAT_PROP_POPUP
3501 && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003502#endif
3503 ) || lcs_eol_one == -1)
3504 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003505#ifdef FEAT_PROP_POPUP
Bram Moolenaar83bf11a2022-08-06 22:23:40 +01003506 if (!wp->w_p_wrap && text_prop_follows)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003507 {
3508 // do not output more of the line, only the "below" prop
3509 ptr += STRLEN(ptr);
3510# ifdef FEAT_LINEBREAK
3511 dont_use_showbreak = TRUE;
3512# endif
3513 }
3514#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003515
3516 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003517 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003518#ifdef FEAT_DIFF
3519 && filler_todo <= 0
3520#endif
3521 )
3522 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003523 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3524 draw_vsep_win(wp, wlv.row);
3525 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003526 }
3527
3528 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003529 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003530 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003531 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003532 break;
3533 }
3534
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003535 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003536#ifdef FEAT_DIFF
3537 && filler_todo <= 0
3538#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003539#ifdef FEAT_PROP_POPUP
3540 && !text_prop_follows
3541#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003542 && wp->w_width == Columns)
3543 {
3544 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003545 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003546
3547 // Special trick to make copy/paste of wrapped lines work with
3548 // xterm/screen: write an extra character beyond the end of
3549 // the line. This will work with all terminal types
3550 // (regardless of the xn,am settings).
3551 // Only do this on a fast tty.
3552 // Only do this if the cursor is on the current line
3553 // (something has been written in it).
3554 // Don't do this for the GUI.
3555 // Don't do this for double-width characters.
3556 // Don't do this for a window not at the right screen border.
3557 if (p_tf
3558#ifdef FEAT_GUI
3559 && !gui.in_use
3560#endif
3561 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003562 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3563 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003564 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003565 || (*mb_off2cells)(
3566 LineOffset[wlv.screen_row - 1]
3567 + (int)Columns - 2,
3568 LineOffset[wlv.screen_row]
3569 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003570 {
3571 // First make sure we are at the end of the screen line,
3572 // then output the same character again to let the
3573 // terminal know about the wrap. If the terminal doesn't
3574 // auto-wrap, we overwrite the character.
3575 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003576 screen_char(LineOffset[wlv.screen_row - 1]
3577 + (unsigned)Columns - 1,
3578 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003579
3580 // When there is a multi-byte character, just output a
3581 // space to keep it simple.
3582 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003583 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003584 out_char(' ');
3585 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003586 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003587 + (Columns - 1)]);
3588 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003589 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003590 screen_start(); // don't know where cursor is now
3591 }
3592 }
3593
Bram Moolenaar1306b362022-08-06 15:59:06 +01003594 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003595
Bram Moolenaareed9d462021-02-15 20:38:25 +01003596 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003597#ifdef FEAT_LINEBREAK
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003598 if (!dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003599# ifdef FEAT_DIFF
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003600 && filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003601# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003602 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003603 need_showbreak = TRUE;
3604#endif
3605#ifdef FEAT_DIFF
3606 --filler_todo;
3607 // When the filler lines are actually below the last line of the
3608 // file, don't draw the line itself, break here.
3609 if (filler_todo == 0 && wp->w_botfill)
3610 break;
3611#endif
3612 }
3613
3614 } // for every character in the line
3615
3616#ifdef FEAT_SPELL
3617 // After an empty line check first word for capital.
3618 if (*skipwhite(line) == NUL)
3619 {
3620 capcol_lnum = lnum + 1;
3621 cap_col = 0;
3622 }
3623#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003624#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003625 vim_free(text_props);
3626 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003627 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003628#endif
3629
3630 vim_free(p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003631 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003632}