blob: af8c053b7c747f10287f2ff470c5c8d9c5c7f845 [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
78#ifdef FEAT_SIGNS
79/*
Bram Moolenaare413ea02021-11-24 16:20:13 +000080 * Return TRUE if CursorLineSign highlight is to be used.
81 */
82 static int
83use_cursor_line_sign(win_T *wp, linenr_T lnum)
84{
85 return wp->w_p_cul
86 && lnum == wp->w_cursor.lnum
87 && (wp->w_p_culopt_flags & CULOPT_NBR);
88}
89
90/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020091 * Get information needed to display the sign in line 'lnum' in window 'wp'.
92 * If 'nrcol' is TRUE, the sign is going to be displayed in the number column.
93 * Otherwise the sign is going to be displayed in the sign column.
94 */
95 static void
96get_sign_display_info(
97 int nrcol,
98 win_T *wp,
Bram Moolenaare413ea02021-11-24 16:20:13 +000099 linenr_T lnum,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200100 sign_attrs_T *sattr,
101 int wcr_attr,
102 int row,
103 int startrow,
104 int filler_lines UNUSED,
105 int filler_todo UNUSED,
106 int *c_extrap,
107 int *c_finalp,
108 char_u *extra,
109 char_u **pp_extra,
110 int *n_extrap,
111 int *char_attrp)
112{
113 int text_sign;
114# ifdef FEAT_SIGN_ICONS
115 int icon_sign;
116# endif
117
118 // Draw two cells with the sign value or blank.
119 *c_extrap = ' ';
120 *c_finalp = NUL;
121 if (nrcol)
122 *n_extrap = number_width(wp) + 1;
123 else
124 {
Bram Moolenaare413ea02021-11-24 16:20:13 +0000125 if (use_cursor_line_sign(wp, lnum))
126 *char_attrp = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLS));
127 else
128 *char_attrp = hl_combine_attr(wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200129 *n_extrap = 2;
130 }
131
132 if (row == startrow
133#ifdef FEAT_DIFF
134 + filler_lines && filler_todo <= 0
135#endif
136 )
137 {
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200138 text_sign = (sattr->sat_text != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200139# ifdef FEAT_SIGN_ICONS
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200140 icon_sign = (sattr->sat_icon != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200141 if (gui.in_use && icon_sign != 0)
142 {
143 // Use the image in this position.
144 if (nrcol)
145 {
146 *c_extrap = NUL;
147 sprintf((char *)extra, "%-*c ", number_width(wp), SIGN_BYTE);
148 *pp_extra = extra;
149 *n_extrap = (int)STRLEN(*pp_extra);
150 }
151 else
152 *c_extrap = SIGN_BYTE;
153# ifdef FEAT_NETBEANS_INTG
154 if (netbeans_active() && (buf_signcount(wp->w_buffer, lnum) > 1))
155 {
156 if (nrcol)
157 {
158 *c_extrap = NUL;
159 sprintf((char *)extra, "%-*c ", number_width(wp),
160 MULTISIGN_BYTE);
161 *pp_extra = extra;
162 *n_extrap = (int)STRLEN(*pp_extra);
163 }
164 else
165 *c_extrap = MULTISIGN_BYTE;
166 }
167# endif
168 *c_finalp = NUL;
169 *char_attrp = icon_sign;
170 }
171 else
172# endif
173 if (text_sign != 0)
174 {
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200175 *pp_extra = sattr->sat_text;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200176 if (*pp_extra != NULL)
177 {
178 if (nrcol)
179 {
180 int n, width = number_width(wp) - 2;
181
182 for (n = 0; n < width; n++)
183 extra[n] = ' ';
184 extra[n] = 0;
185 STRCAT(extra, *pp_extra);
186 STRCAT(extra, " ");
187 *pp_extra = extra;
188 }
189 *c_extrap = NUL;
190 *c_finalp = NUL;
191 *n_extrap = (int)STRLEN(*pp_extra);
192 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000193
194 if (use_cursor_line_sign(wp, lnum) && sattr->sat_culhl > 0)
195 *char_attrp = sattr->sat_culhl;
196 else
197 *char_attrp = sattr->sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200198 }
199 }
200}
201#endif
202
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100203#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200204static textprop_T *current_text_props = NULL;
205static buf_T *current_buf = NULL;
206
207 static int
208text_prop_compare(const void *s1, const void *s2)
209{
210 int idx1, idx2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100211 textprop_T *tp1, *tp2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200212 proptype_T *pt1, *pt2;
213 colnr_T col1, col2;
214
215 idx1 = *(int *)s1;
216 idx2 = *(int *)s2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100217 tp1 = &current_text_props[idx1];
218 tp2 = &current_text_props[idx2];
219 pt1 = text_prop_type_by_id(current_buf, tp1->tp_type);
220 pt2 = text_prop_type_by_id(current_buf, tp2->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200221 if (pt1 == pt2)
222 return 0;
223 if (pt1 == NULL)
224 return -1;
225 if (pt2 == NULL)
226 return 1;
227 if (pt1->pt_priority != pt2->pt_priority)
228 return pt1->pt_priority > pt2->pt_priority ? 1 : -1;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100229 col1 = tp1->tp_col;
230 col2 = tp2->tp_col;
231 if (col1 == MAXCOL && col2 == MAXCOL)
232 {
233 int flags1 = 0;
234 int flags2 = 0;
235
236 // order on 0: after, 1: right, 2: below
237 if (tp1->tp_flags & TP_FLAG_ALIGN_RIGHT)
238 flags1 = 1;
239 if (tp1->tp_flags & TP_FLAG_ALIGN_BELOW)
240 flags1 = 2;
241 if (tp2->tp_flags & TP_FLAG_ALIGN_RIGHT)
242 flags2 = 1;
243 if (tp2->tp_flags & TP_FLAG_ALIGN_BELOW)
244 flags2 = 2;
245 if (flags1 != flags2)
246 return flags1 < flags2 ? 1 : -1;
247 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200248 return col1 == col2 ? 0 : col1 > col2 ? 1 : -1;
249}
250#endif
251
252/*
253 * Display line "lnum" of window 'wp' on the screen.
254 * Start at row "startrow", stop when "endrow" is reached.
255 * wp->w_virtcol needs to be valid.
256 *
257 * Return the number of last row the line occupies.
258 */
259 int
260win_line(
261 win_T *wp,
262 linenr_T lnum,
263 int startrow,
264 int endrow,
265 int nochange UNUSED, // not updating for changed text
266 int number_only) // only update the number column
267{
268 int col = 0; // visual column on screen
269 unsigned off; // offset in ScreenLines/ScreenAttrs
270 int c = 0; // init for GCC
271 long vcol = 0; // virtual column (for tabs)
272#ifdef FEAT_LINEBREAK
273 long vcol_sbr = -1; // virtual column after showbreak
274#endif
275 long vcol_prev = -1; // "vcol" of previous character
276 char_u *line; // current line
277 char_u *ptr; // current position in "line"
278 int row; // row in the window, excl w_winrow
279 int screen_row; // row on the screen, incl w_winrow
280
281 char_u extra[21]; // "%ld " and 'fdc' must fit in here
282 int n_extra = 0; // number of extra chars
283 char_u *p_extra = NULL; // string of extra chars, plus NUL
284 char_u *p_extra_free = NULL; // p_extra needs to be freed
285 int c_extra = NUL; // extra chars, all the same
286 int c_final = NUL; // final char, mandatory if set
287 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000288#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000289 int in_linebreak = FALSE; // n_extra set for showing linebreak
290#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200291 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100292 // displaying eol at end-of-line
293 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000294 int lcs_prec_todo = wp->w_lcs_chars.prec;
295 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200296
297 // saved "extra" items for when draw_state becomes WL_LINE (again)
298 int saved_n_extra = 0;
299 char_u *saved_p_extra = NULL;
300 int saved_c_extra = 0;
301 int saved_c_final = 0;
302 int saved_char_attr = 0;
303
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100304 int n_attr = 0; // chars with special attr
305 int n_attr_skip = 0; // chars to skip before using extra_attr
306 int saved_attr2 = 0; // char_attr saved for n_attr
307 int n_attr3 = 0; // chars with overruling special attr
308 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200309
310 int n_skip = 0; // nr of chars to skip for 'nowrap'
311
312 int fromcol = -10; // start of inverting
313 int tocol = MAXCOL; // end of inverting
314 int fromcol_prev = -2; // start of inverting after cursor
315 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200316 int lnum_in_visual_area = FALSE;
317 pos_T pos;
318 long v;
319
320 int char_attr = 0; // attributes for next character
321 int attr_pri = FALSE; // char_attr has priority
322 int area_highlighting = FALSE; // Visual or incsearch highlighting
323 // in this line
324 int vi_attr = 0; // attributes for Visual and incsearch
325 // highlighting
326 int wcr_attr = 0; // attributes from 'wincolor'
327 int win_attr = 0; // background for whole window, except
328 // margins and "~" lines.
329 int area_attr = 0; // attributes desired by highlighting
330 int search_attr = 0; // attributes desired by 'hlsearch'
331#ifdef FEAT_SYN_HL
332 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
333 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200334 int prev_syntax_col = -1; // column of prev_syntax_attr
335 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200336 int has_syntax = FALSE; // this buffer has syntax highl.
337 int save_did_emsg;
338 int draw_color_col = FALSE; // highlight colorcolumn
339 int *color_cols = NULL; // pointer to according columns array
340#endif
341 int eol_hl_off = 0; // 1 if highlighted char after EOL
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100342#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200343 int text_prop_count;
344 int text_prop_next = 0; // next text property to use
345 textprop_T *text_props = NULL;
346 int *text_prop_idxs = NULL;
347 int text_props_active = 0;
348 proptype_T *text_prop_type = NULL;
349 int text_prop_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100350 int text_prop_id = 0; // active property ID
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200351 int text_prop_combine = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100352 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200353#endif
354#ifdef FEAT_SPELL
355 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000356 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200357# define SPWORDLEN 150
358 char_u nextline[SPWORDLEN * 2];// text with start of the next line
359 int nextlinecol = 0; // column where nextline[] starts
360 int nextline_idx = 0; // index in nextline[] where next line
361 // starts
362 int spell_attr = 0; // attributes desired by spelling
363 int word_end = 0; // last byte with same spell_attr
364 static linenr_T checked_lnum = 0; // line number for "checked_col"
365 static int checked_col = 0; // column in "checked_lnum" up to which
366 // there are no spell errors
367 static int cap_col = -1; // column to check for Cap word
368 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
369 int cur_checked_col = 0; // checked column for current line
370#endif
371 int extra_check = 0; // has extra highlighting
372 int multi_attr = 0; // attributes desired by multibyte
373 int mb_l = 1; // multi-byte byte length
374 int mb_c = 0; // decoded multi-byte character
375 int mb_utf8 = FALSE; // screen char is UTF-8 char
376 int u8cc[MAX_MCO]; // composing UTF-8 chars
377#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
378 int filler_lines = 0; // nr of filler lines to be drawn
379 int filler_todo = 0; // nr of filler lines still to do + 1
Bram Moolenaar936dc602022-03-06 20:47:01 +0000380#else
381# define filler_lines 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200382#endif
383#ifdef FEAT_DIFF
384 hlf_T diff_hlf = (hlf_T)0; // type of diff highlighting
385 int change_start = MAXCOL; // first col of changed area
386 int change_end = -1; // last col of changed area
387#endif
388 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100389 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200390 int in_multispace = FALSE; // in multiple consecutive spaces
391 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200392#ifdef FEAT_LINEBREAK
393 int need_showbreak = FALSE; // overlong line, skipping first x
394 // chars
395#endif
396#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
397 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
398# define LINE_ATTR
399 int line_attr = 0; // attribute for the whole line
400 int line_attr_save;
401#endif
402#ifdef FEAT_SIGNS
403 int sign_present = FALSE;
404 sign_attrs_T sattr;
James McCoya80aad72021-12-22 19:45:28 +0000405 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200406#endif
407#ifdef FEAT_ARABIC
408 int prev_c = 0; // previous Arabic character
409 int prev_c1 = 0; // first composing char for prev_c
410#endif
411#if defined(LINE_ATTR)
412 int did_line_attr = 0;
413#endif
414#ifdef FEAT_TERMINAL
415 int get_term_attr = FALSE;
416#endif
417#ifdef FEAT_SYN_HL
418 int cul_attr = 0; // set when 'cursorline' active
419
420 // 'cursorlineopt' has "screenline" and cursor is in this line
421 int cul_screenline = FALSE;
422
423 // margin columns for the screen line, needed for when 'cursorlineopt'
424 // contains "screenline"
425 int left_curline_col = 0;
426 int right_curline_col = 0;
427#endif
428
429 // draw_state: items that are drawn in sequence:
430#define WL_START 0 // nothing done yet
431#ifdef FEAT_CMDWIN
kylo252ae6f1d82022-02-16 19:24:07 +0000432# define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200433#else
434# define WL_CMDLINE WL_START
435#endif
436#ifdef FEAT_FOLDING
kylo252ae6f1d82022-02-16 19:24:07 +0000437# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200438#else
439# define WL_FOLD WL_CMDLINE
440#endif
441#ifdef FEAT_SIGNS
kylo252ae6f1d82022-02-16 19:24:07 +0000442# define WL_SIGN (WL_FOLD + 1) // column for signs
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200443#else
444# define WL_SIGN WL_FOLD // column for signs
445#endif
kylo252ae6f1d82022-02-16 19:24:07 +0000446#define WL_NR (WL_SIGN + 1) // line number
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200447#ifdef FEAT_LINEBREAK
kylo252ae6f1d82022-02-16 19:24:07 +0000448# define WL_BRI (WL_NR + 1) // 'breakindent'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200449#else
450# define WL_BRI WL_NR
451#endif
452#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
kylo252ae6f1d82022-02-16 19:24:07 +0000453# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200454#else
455# define WL_SBR WL_BRI
456#endif
kylo252ae6f1d82022-02-16 19:24:07 +0000457#define WL_LINE (WL_SBR + 1) // text in the line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200458 int draw_state = WL_START; // what to draw next
459#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
460 int feedback_col = 0;
461 int feedback_old_attr = -1;
462#endif
463 int screen_line_flags = 0;
464
465#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
466 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000467 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200468#endif
469#ifdef FEAT_CONCEAL
470 int syntax_flags = 0;
471 int syntax_seqnr = 0;
472 int prev_syntax_id = 0;
473 int conceal_attr = HL_ATTR(HLF_CONCEAL);
474 int is_concealing = FALSE;
475 int boguscols = 0; // nonexistent columns added to force
476 // wrapping
477 int vcol_off = 0; // offset for concealed characters
478 int did_wcol = FALSE;
479 int old_boguscols = 0;
480# define VCOL_HLC (vcol - vcol_off)
481# define FIX_FOR_BOGUSCOLS \
482 { \
483 n_extra += vcol_off; \
484 vcol -= vcol_off; \
485 vcol_off = 0; \
486 col -= boguscols; \
487 old_boguscols = boguscols; \
488 boguscols = 0; \
489 }
490#else
491# define VCOL_HLC (vcol)
492#endif
493
494 if (startrow > endrow) // past the end already!
495 return startrow;
496
497 row = startrow;
498 screen_row = row + W_WINROW(wp);
499
500 if (!number_only)
501 {
502 // To speed up the loop below, set extra_check when there is linebreak,
503 // trailing white space and/or syntax processing to be done.
504#ifdef FEAT_LINEBREAK
505 extra_check = wp->w_p_lbr;
506#endif
507#ifdef FEAT_SYN_HL
508 if (syntax_present(wp) && !wp->w_s->b_syn_error
509# ifdef SYN_TIME_LIMIT
510 && !wp->w_s->b_syn_slow
511# endif
512 )
513 {
514 // Prepare for syntax highlighting in this line. When there is an
515 // error, stop syntax highlighting.
516 save_did_emsg = did_emsg;
517 did_emsg = FALSE;
518 syntax_start(wp, lnum);
519 if (did_emsg)
520 wp->w_s->b_syn_error = TRUE;
521 else
522 {
523 did_emsg = save_did_emsg;
524#ifdef SYN_TIME_LIMIT
525 if (!wp->w_s->b_syn_slow)
526#endif
527 {
528 has_syntax = TRUE;
529 extra_check = TRUE;
530 }
531 }
532 }
533
534 // Check for columns to display for 'colorcolumn'.
535 color_cols = wp->w_p_cc_cols;
536 if (color_cols != NULL)
537 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
538#endif
539
540#ifdef FEAT_TERMINAL
541 if (term_show_buffer(wp->w_buffer))
542 {
543 extra_check = TRUE;
544 get_term_attr = TRUE;
Bram Moolenaar219c7d02020-02-01 21:57:29 +0100545 win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200546 }
547#endif
548
549#ifdef FEAT_SPELL
550 if (wp->w_p_spell
551 && *wp->w_s->b_p_spl != NUL
552 && wp->w_s->b_langp.ga_len > 0
553 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
554 {
555 // Prepare for spell checking.
556 has_spell = TRUE;
557 extra_check = TRUE;
558
559 // Get the start of the next line, so that words that wrap to the
560 // next line are found too: "et<line-break>al.".
561 // Trick: skip a few chars for C/shell/Vim comments
562 nextline[SPWORDLEN] = NUL;
563 if (lnum < wp->w_buffer->b_ml.ml_line_count)
564 {
565 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
566 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
567 }
568
569 // When a word wrapped from the previous line the start of the
570 // current line is valid.
571 if (lnum == checked_lnum)
572 cur_checked_col = checked_col;
573 checked_lnum = 0;
574
575 // When there was a sentence end in the previous line may require a
576 // word starting with capital in this line. In line 1 always check
577 // the first word.
578 if (lnum != capcol_lnum)
579 cap_col = -1;
580 if (lnum == 1)
581 cap_col = 0;
582 capcol_lnum = 0;
583 }
584#endif
585
586 // handle Visual active in this window
587 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
588 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100589 pos_T *top, *bot;
590
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200591 if (LTOREQ_POS(curwin->w_cursor, VIsual))
592 {
593 // Visual is after curwin->w_cursor
594 top = &curwin->w_cursor;
595 bot = &VIsual;
596 }
597 else
598 {
599 // Visual is before curwin->w_cursor
600 top = &VIsual;
601 bot = &curwin->w_cursor;
602 }
603 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
604 if (VIsual_mode == Ctrl_V)
605 {
606 // block mode
607 if (lnum_in_visual_area)
608 {
609 fromcol = wp->w_old_cursor_fcol;
610 tocol = wp->w_old_cursor_lcol;
611 }
612 }
613 else
614 {
615 // non-block mode
616 if (lnum > top->lnum && lnum <= bot->lnum)
617 fromcol = 0;
618 else if (lnum == top->lnum)
619 {
620 if (VIsual_mode == 'V') // linewise
621 fromcol = 0;
622 else
623 {
624 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
625 if (gchar_pos(top) == NUL)
626 tocol = fromcol + 1;
627 }
628 }
629 if (VIsual_mode != 'V' && lnum == bot->lnum)
630 {
631 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
632 {
633 fromcol = -10;
634 tocol = MAXCOL;
635 }
636 else if (bot->col == MAXCOL)
637 tocol = MAXCOL;
638 else
639 {
640 pos = *bot;
641 if (*p_sel == 'e')
642 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
643 else
644 {
645 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
646 ++tocol;
647 }
648 }
649 }
650 }
651
652 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200653 if (!highlight_match && lnum == curwin->w_cursor.lnum
654 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200655#ifdef FEAT_GUI
656 && !gui.in_use
657#endif
658 )
659 noinvcur = TRUE;
660
661 // if inverting in this line set area_highlighting
662 if (fromcol >= 0)
663 {
664 area_highlighting = TRUE;
665 vi_attr = HL_ATTR(HLF_V);
666#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
667 if ((clip_star.available && !clip_star.owned
668 && clip_isautosel_star())
669 || (clip_plus.available && !clip_plus.owned
670 && clip_isautosel_plus()))
671 vi_attr = HL_ATTR(HLF_VNC);
672#endif
673 }
674 }
675
676 // handle 'incsearch' and ":s///c" highlighting
677 else if (highlight_match
678 && wp == curwin
679 && lnum >= curwin->w_cursor.lnum
680 && lnum <= curwin->w_cursor.lnum + search_match_lines)
681 {
682 if (lnum == curwin->w_cursor.lnum)
683 getvcol(curwin, &(curwin->w_cursor),
684 (colnr_T *)&fromcol, NULL, NULL);
685 else
686 fromcol = 0;
687 if (lnum == curwin->w_cursor.lnum + search_match_lines)
688 {
689 pos.lnum = lnum;
690 pos.col = search_match_endcol;
691 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
692 }
693 else
694 tocol = MAXCOL;
695 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100696 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200697 tocol = fromcol + 1;
698 area_highlighting = TRUE;
699 vi_attr = HL_ATTR(HLF_I);
700 }
701 }
702
703#ifdef FEAT_DIFF
704 filler_lines = diff_check(wp, lnum);
705 if (filler_lines < 0)
706 {
707 if (filler_lines == -1)
708 {
709 if (diff_find_change(wp, lnum, &change_start, &change_end))
710 diff_hlf = HLF_ADD; // added line
711 else if (change_start == 0)
712 diff_hlf = HLF_TXD; // changed text
713 else
714 diff_hlf = HLF_CHD; // changed line
715 }
716 else
717 diff_hlf = HLF_ADD; // added line
718 filler_lines = 0;
719 area_highlighting = TRUE;
720 }
721 if (lnum == wp->w_topline)
722 filler_lines = wp->w_topfill;
723 filler_todo = filler_lines;
724#endif
725
726#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +0100727 sign_present = buf_get_signattrs(wp, lnum, &sattr);
James McCoya80aad72021-12-22 19:45:28 +0000728 if (sign_present)
729 num_attr = sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200730#endif
731
732#ifdef LINE_ATTR
733# ifdef FEAT_SIGNS
734 // If this line has a sign with line highlighting set line_attr.
735 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200736 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200737# endif
738# if defined(FEAT_QUICKFIX)
739 // Highlight the current line in the quickfix window.
740 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
741 line_attr = HL_ATTR(HLF_QFL);
742# endif
743 if (line_attr != 0)
744 area_highlighting = TRUE;
745#endif
746
747 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
748 ptr = line;
749
750#ifdef FEAT_SPELL
751 if (has_spell && !number_only)
752 {
753 // For checking first word with a capital skip white space.
754 if (cap_col == 0)
755 cap_col = getwhitecols(line);
756
757 // To be able to spell-check over line boundaries copy the end of the
758 // current line into nextline[]. Above the start of the next line was
759 // copied to nextline[SPWORDLEN].
760 if (nextline[SPWORDLEN] == NUL)
761 {
762 // No next line or it is empty.
763 nextlinecol = MAXCOL;
764 nextline_idx = 0;
765 }
766 else
767 {
768 v = (long)STRLEN(line);
769 if (v < SPWORDLEN)
770 {
771 // Short line, use it completely and append the start of the
772 // next line.
773 nextlinecol = 0;
774 mch_memmove(nextline, line, (size_t)v);
775 STRMOVE(nextline + v, nextline + SPWORDLEN);
776 nextline_idx = v + 1;
777 }
778 else
779 {
780 // Long line, use only the last SPWORDLEN bytes.
781 nextlinecol = v - SPWORDLEN;
782 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
783 nextline_idx = SPWORDLEN + 1;
784 }
785 }
786 }
787#endif
788
789 if (wp->w_p_list)
790 {
Bram Moolenaareed9d462021-02-15 20:38:25 +0100791 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +0200792 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100793 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +0100794 || wp->w_lcs_chars.trail
795 || wp->w_lcs_chars.lead
796 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200797 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100798
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200799 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100800 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200801 {
802 trailcol = (colnr_T)STRLEN(ptr);
803 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
804 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +0100805 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200806 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100807 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100808 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100809 {
810 leadcol = 0;
811 while (VIM_ISWHITE(ptr[leadcol]))
812 ++leadcol;
813 if (ptr[leadcol] == NUL)
814 // in a line full of spaces all of them are treated as trailing
815 leadcol = (colnr_T)0;
816 else
817 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +0100818 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100819 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200820 }
821
822 wcr_attr = get_wcr_attr(wp);
823 if (wcr_attr != 0)
824 {
825 win_attr = wcr_attr;
826 area_highlighting = TRUE;
827 }
Bram Moolenaar34390282019-10-16 14:38:26 +0200828
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100829#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200830 if (WIN_IS_POPUP(wp))
831 screen_line_flags |= SLF_POPUP;
832#endif
833
834 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
835 // first character to be displayed.
836 if (wp->w_p_wrap)
837 v = wp->w_skipcol;
838 else
839 v = wp->w_leftcol;
840 if (v > 0 && !number_only)
841 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100842 char_u *prev_ptr = ptr;
843 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +0100844 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200845
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100846 init_chartabsize_arg(&cts, wp, lnum, vcol, line, ptr);
847 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200848 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100849 charsize = win_lbr_chartabsize(&cts, NULL);
850 cts.cts_vcol += charsize;
851 prev_ptr = cts.cts_ptr;
852 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200853 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100854 vcol = cts.cts_vcol;
855 ptr = cts.cts_ptr;
856 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200857
858 // When:
859 // - 'cuc' is set, or
860 // - 'colorcolumn' is set, or
861 // - 'virtualedit' is set, or
862 // - the visual mode is active,
863 // the end of the line may be before the start of the displayed part.
864 if (vcol < v && (
865#ifdef FEAT_SYN_HL
866 wp->w_p_cuc || draw_color_col ||
867#endif
868 virtual_active() ||
869 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
870 vcol = v;
871
872 // Handle a character that's not completely on the screen: Put ptr at
873 // that character but skip the first few screen characters.
874 if (vcol > v)
875 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100876 vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200877 ptr = prev_ptr;
878 // If the character fits on the screen, don't need to skip it.
879 // Except for a TAB.
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100880 if (( (*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB) && col == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200881 n_skip = v - vcol;
882 }
883
884 // Adjust for when the inverted text is before the screen,
885 // and when the start of the inverted text is before the screen.
886 if (tocol <= vcol)
887 fromcol = 0;
888 else if (fromcol >= 0 && fromcol < vcol)
889 fromcol = vcol;
890
891#ifdef FEAT_LINEBREAK
892 // When w_skipcol is non-zero, first line needs 'showbreak'
893 if (wp->w_p_wrap)
894 need_showbreak = TRUE;
895#endif
896#ifdef FEAT_SPELL
897 // When spell checking a word we need to figure out the start of the
898 // word and if it's badly spelled or not.
899 if (has_spell)
900 {
901 int len;
902 colnr_T linecol = (colnr_T)(ptr - line);
903 hlf_T spell_hlf = HLF_COUNT;
904
905 pos = wp->w_cursor;
906 wp->w_cursor.lnum = lnum;
907 wp->w_cursor.col = linecol;
908 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
909
910 // spell_move_to() may call ml_get() and make "line" invalid
911 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
912 ptr = line + linecol;
913
914 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
915 {
916 // no bad word found at line start, don't check until end of a
917 // word
918 spell_hlf = HLF_COUNT;
919 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
920 }
921 else
922 {
923 // bad word found, use attributes until end of word
924 word_end = wp->w_cursor.col + len + 1;
925
926 // Turn index into actual attributes.
927 if (spell_hlf != HLF_COUNT)
928 spell_attr = highlight_attr[spell_hlf];
929 }
930 wp->w_cursor = pos;
931
932# ifdef FEAT_SYN_HL
933 // Need to restart syntax highlighting for this line.
934 if (has_syntax)
935 syntax_start(wp, lnum);
936# endif
937 }
938#endif
939 }
940
941 // Correct highlighting for cursor that can't be disabled.
942 // Avoids having to check this for each character.
943 if (fromcol >= 0)
944 {
945 if (noinvcur)
946 {
947 if ((colnr_T)fromcol == wp->w_virtcol)
948 {
949 // highlighting starts at cursor, let it start just after the
950 // cursor
951 fromcol_prev = fromcol;
952 fromcol = -1;
953 }
954 else if ((colnr_T)fromcol < wp->w_virtcol)
955 // restart highlighting after the cursor
956 fromcol_prev = wp->w_virtcol;
957 }
958 if (fromcol >= tocol)
959 fromcol = -1;
960 }
961
962#ifdef FEAT_SEARCH_EXTRA
963 if (!number_only)
964 {
965 v = (long)(ptr - line);
966 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
967 &line, &screen_search_hl,
968 &search_attr);
969 ptr = line + v; // "line" may have been updated
970 }
971#endif
972
973#ifdef FEAT_SYN_HL
974 // Cursor line highlighting for 'cursorline' in the current window.
975 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
976 {
977 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +0000978 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200979 if (!(wp == curwin && VIsual_active)
980 && wp->w_p_culopt_flags != CULOPT_NBR)
981 {
982 cul_screenline = (wp->w_p_wrap
983 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
984
985 // Only set line_attr here when "screenline" is not present in
986 // 'cursorlineopt'. Otherwise it's done later.
987 if (!cul_screenline)
988 {
989 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +0200990# ifdef FEAT_SIGNS
991 // Combine the 'cursorline' and sign highlighting, depending on
992 // the sign priority.
993 if (sign_present && sattr.sat_linehl > 0)
994 {
995 if (sattr.sat_priority >= 100)
996 line_attr = hl_combine_attr(cul_attr, line_attr);
997 else
998 line_attr = hl_combine_attr(line_attr, cul_attr);
999 }
1000 else
1001# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001002# if defined(FEAT_QUICKFIX)
1003 line_attr = hl_combine_attr(line_attr, cul_attr);
1004# else
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001005 line_attr = cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001006# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001007 }
1008 else
1009 {
1010 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001011 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1012 }
1013 area_highlighting = TRUE;
1014 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001015 }
1016#endif
1017
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001018#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001019 {
1020 char_u *prop_start;
1021
1022 text_prop_count = get_text_props(wp->w_buffer, lnum,
1023 &prop_start, FALSE);
1024 if (text_prop_count > 0)
1025 {
1026 // Make a copy of the properties, so that they are properly
1027 // aligned.
1028 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1029 if (text_props != NULL)
1030 mch_memmove(text_props, prop_start,
1031 text_prop_count * sizeof(textprop_T));
1032
1033 // Allocate an array for the indexes.
1034 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1035 area_highlighting = TRUE;
1036 extra_check = TRUE;
1037 }
1038 }
1039#endif
1040
1041 off = (unsigned)(current_ScreenLine - ScreenLines);
1042 col = 0;
1043
1044#ifdef FEAT_RIGHTLEFT
1045 if (wp->w_p_rl)
1046 {
1047 // Rightleft window: process the text in the normal direction, but put
1048 // it in current_ScreenLine[] from right to left. Start at the
1049 // rightmost column of the window.
1050 col = wp->w_width - 1;
1051 off += col;
1052 screen_line_flags |= SLF_RIGHTLEFT;
1053 }
1054#endif
1055
1056 // Repeat for the whole displayed line.
1057 for (;;)
1058 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001059 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001060#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001061 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001062#endif
1063#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001064 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001065#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001066
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001067 // Skip this quickly when working on the text.
1068 if (draw_state != WL_LINE)
1069 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001070#ifdef FEAT_SYN_HL
1071 if (cul_screenline)
1072 {
1073 cul_attr = 0;
1074 line_attr = line_attr_save;
1075 }
1076#endif
1077
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001078#ifdef FEAT_CMDWIN
1079 if (draw_state == WL_CMDLINE - 1 && n_extra == 0)
1080 {
1081 draw_state = WL_CMDLINE;
1082 if (cmdwin_type != 0 && wp == curwin)
1083 {
1084 // Draw the cmdline character.
1085 n_extra = 1;
1086 c_extra = cmdwin_type;
1087 c_final = NUL;
1088 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
1089 }
1090 }
1091#endif
1092
1093#ifdef FEAT_FOLDING
1094 if (draw_state == WL_FOLD - 1 && n_extra == 0)
1095 {
1096 int fdc = compute_foldcolumn(wp, 0);
1097
1098 draw_state = WL_FOLD;
1099 if (fdc > 0)
1100 {
1101 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1102 // already be in use.
1103 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001104 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001105 if (p_extra_free != NULL)
1106 {
Bram Moolenaar9355ae42021-03-08 19:04:05 +01001107 n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001108 FALSE, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001109 p_extra_free[n_extra] = NUL;
1110 p_extra = p_extra_free;
1111 c_extra = NUL;
1112 c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001113 if (use_cursor_line_sign(wp, lnum))
1114 char_attr =
1115 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1116 else
1117 char_attr =
1118 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001119 }
1120 }
1121 }
1122#endif
1123
1124#ifdef FEAT_SIGNS
1125 if (draw_state == WL_SIGN - 1 && n_extra == 0)
1126 {
1127 draw_state = WL_SIGN;
1128 // Show the sign column when there are any signs in this
1129 // buffer or when using Netbeans.
1130 if (signcolumn_on(wp))
1131 get_sign_display_info(FALSE, wp, lnum, &sattr, wcr_attr,
1132 row, startrow, filler_lines, filler_todo, &c_extra,
1133 &c_final, extra, &p_extra, &n_extra, &char_attr);
1134 }
1135#endif
1136
1137 if (draw_state == WL_NR - 1 && n_extra == 0)
1138 {
1139 draw_state = WL_NR;
1140 // Display the absolute or relative line number. After the
1141 // first fill with blanks when the 'n' flag isn't in 'cpo'
1142 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar936dc602022-03-06 20:47:01 +00001143 && (row == startrow + filler_lines
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001144 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
1145 {
1146#ifdef FEAT_SIGNS
1147 // If 'signcolumn' is set to 'number' and a sign is present
1148 // in 'lnum', then display the sign instead of the line
1149 // number.
1150 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1151 && sign_present)
1152 get_sign_display_info(TRUE, wp, lnum, &sattr, wcr_attr,
1153 row, startrow, filler_lines, filler_todo,
1154 &c_extra, &c_final, extra, &p_extra, &n_extra,
1155 &char_attr);
1156 else
1157#endif
1158 {
1159 // Draw the line number (empty space after wrapping).
Bram Moolenaar936dc602022-03-06 20:47:01 +00001160 if (row == startrow + filler_lines)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001161 {
1162 long num;
1163 char *fmt = "%*ld ";
1164
1165 if (wp->w_p_nu && !wp->w_p_rnu)
1166 // 'number' + 'norelativenumber'
1167 num = (long)lnum;
1168 else
1169 {
1170 // 'relativenumber', don't use negative numbers
1171 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1172 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1173 {
1174 // 'number' + 'relativenumber'
1175 num = lnum;
1176 fmt = "%-*ld ";
1177 }
1178 }
1179
1180 sprintf((char *)extra, fmt,
1181 number_width(wp), num);
1182 if (wp->w_skipcol > 0)
1183 for (p_extra = extra; *p_extra == ' '; ++p_extra)
1184 *p_extra = '-';
1185#ifdef FEAT_RIGHTLEFT
1186 if (wp->w_p_rl) // reverse line numbers
1187 {
1188 char_u *p1, *p2;
1189 int t;
1190
1191 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001192 p2 = skipwhite(extra);
1193 p2 = skiptowhite(p2) - 1;
1194 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001195 {
1196 t = *p1;
1197 *p1 = *p2;
1198 *p2 = t;
1199 }
1200 }
1201#endif
1202 p_extra = extra;
1203 c_extra = NUL;
1204 c_final = NUL;
1205 }
1206 else
1207 {
1208 c_extra = ' ';
1209 c_final = NUL;
1210 }
1211 n_extra = number_width(wp) + 1;
1212 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
1213#ifdef FEAT_SYN_HL
1214 // When 'cursorline' is set highlight the line number of
1215 // the current line differently.
zeertzjq754d2b42022-03-13 13:40:45 +00001216 // When 'cursorlineopt' does not have "line" only
1217 // highlight the line number itself.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001218 // TODO: Can we use CursorLine instead of CursorLineNr
1219 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001220 if (wp->w_p_cul
1221 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001222 && (wp->w_p_culopt_flags & CULOPT_NBR)
Bram Moolenaar127969c2022-03-06 19:54:13 +00001223 && (row == startrow + filler_lines
1224 || (row > startrow + filler_lines
zeertzjq754d2b42022-03-13 13:40:45 +00001225 && (wp->w_p_culopt_flags & CULOPT_LINE))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001226 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLN));
1227#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001228 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1229 && HL_ATTR(HLF_LNA) != 0)
1230 // Use LineNrAbove
1231 char_attr = hl_combine_attr(wcr_attr,
1232 HL_ATTR(HLF_LNA));
1233 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1234 && HL_ATTR(HLF_LNB) != 0)
1235 // Use LineNrBelow
1236 char_attr = hl_combine_attr(wcr_attr,
1237 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001238 }
James McCoya80aad72021-12-22 19:45:28 +00001239#ifdef FEAT_SIGNS
1240 if (num_attr)
1241 char_attr = num_attr;
1242#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001243 }
1244 }
1245
1246#ifdef FEAT_LINEBREAK
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001247 if (wp->w_briopt_sbr && draw_state == WL_BRI - 1
Bram Moolenaaree857022019-11-09 23:26:40 +01001248 && n_extra == 0 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001249 // draw indent after showbreak value
1250 draw_state = WL_BRI;
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001251 else if (wp->w_briopt_sbr && draw_state == WL_SBR && n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001252 // After the showbreak, draw the breakindent
1253 draw_state = WL_BRI - 1;
1254
1255 // draw 'breakindent': indent wrapped text accordingly
1256 if (draw_state == WL_BRI - 1 && n_extra == 0)
1257 {
1258 draw_state = WL_BRI;
1259 // if need_showbreak is set, breakindent also applies
Bram Moolenaarfe154992022-03-22 20:42:12 +00001260 if (wp->w_p_bri && (row != startrow || need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001261# ifdef FEAT_DIFF
1262 && filler_lines == 0
1263# endif
1264 )
1265 {
1266 char_attr = 0;
1267# ifdef FEAT_DIFF
1268 if (diff_hlf != (hlf_T)0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001269 char_attr = HL_ATTR(diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001270# endif
1271 p_extra = NULL;
1272 c_extra = ' ';
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001273 c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001274 n_extra = get_breakindent_win(wp,
1275 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001276 if (row == startrow)
1277 {
1278 n_extra -= win_col_off2(wp);
1279 if (n_extra < 0)
1280 n_extra = 0;
1281 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001282 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001283 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001284 // Correct end of highlighted area for 'breakindent',
1285 // required when 'linebreak' is also set.
1286 if (tocol == vcol)
1287 tocol += n_extra;
1288 }
1289 }
1290#endif
1291
1292#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
1293 if (draw_state == WL_SBR - 1 && n_extra == 0)
1294 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001295 char_u *sbr;
1296
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001297 draw_state = WL_SBR;
1298# ifdef FEAT_DIFF
1299 if (filler_todo > 0)
1300 {
1301 // Draw "deleted" diff line(s).
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001302 if (char2cells(wp->w_fill_chars.diff) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001303 {
1304 c_extra = '-';
1305 c_final = NUL;
1306 }
1307 else
1308 {
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001309 c_extra = wp->w_fill_chars.diff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001310 c_final = NUL;
1311 }
1312# ifdef FEAT_RIGHTLEFT
1313 if (wp->w_p_rl)
1314 n_extra = col + 1;
1315 else
1316# endif
1317 n_extra = wp->w_width - col;
1318 char_attr = HL_ATTR(HLF_DED);
1319 }
1320# endif
1321# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001322 sbr = get_showbreak_value(wp);
1323 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001324 {
1325 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaaree857022019-11-09 23:26:40 +01001326 p_extra = sbr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001327 c_extra = NUL;
1328 c_final = NUL;
Bram Moolenaaree857022019-11-09 23:26:40 +01001329 n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001330 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1331 need_showbreak = FALSE;
Bram Moolenaaree857022019-11-09 23:26:40 +01001332 vcol_sbr = vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001333 // Correct end of highlighted area for 'showbreak',
1334 // required when 'linebreak' is also set.
1335 if (tocol == vcol)
1336 tocol += n_extra;
1337 // combine 'showbreak' with 'wincolor'
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001338 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001339# ifdef FEAT_SYN_HL
1340 // combine 'showbreak' with 'cursorline'
1341 if (cul_attr != 0)
1342 char_attr = hl_combine_attr(char_attr, cul_attr);
1343# endif
1344 }
1345# endif
1346 }
1347#endif
1348
1349 if (draw_state == WL_LINE - 1 && n_extra == 0)
1350 {
1351 draw_state = WL_LINE;
1352 if (saved_n_extra)
1353 {
1354 // Continue item from end of wrapped line.
1355 n_extra = saved_n_extra;
1356 c_extra = saved_c_extra;
1357 c_final = saved_c_final;
1358 p_extra = saved_p_extra;
1359 char_attr = saved_char_attr;
1360 }
1361 else
1362 char_attr = win_attr;
1363 }
1364 }
1365#ifdef FEAT_SYN_HL
zeertzjq4f33bc22021-08-05 17:57:02 +02001366 if (cul_screenline && draw_state == WL_LINE
1367 && vcol >= left_curline_col
1368 && vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001369 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001370 cul_attr = HL_ATTR(HLF_CUL);
1371 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001372 }
1373#endif
1374
1375 // When still displaying '$' of change command, stop at cursor.
1376 // When only displaying the (relative) line number and that's done,
1377 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001378 if (((dollar_vcol >= 0 && wp == curwin
1379 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol)
1380 || (number_only && draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001381#ifdef FEAT_DIFF
1382 && filler_todo <= 0
1383#endif
1384 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001385 {
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001386 screen_line(wp, screen_row, wp->w_wincol, col, -wp->w_width,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001387 screen_line_flags);
1388 // Pretend we have finished updating the window. Except when
1389 // 'cursorcolumn' is set.
1390#ifdef FEAT_SYN_HL
1391 if (wp->w_p_cuc)
1392 row = wp->w_cline_row + wp->w_cline_height;
1393 else
1394#endif
1395 row = wp->w_height;
1396 break;
1397 }
1398
Bram Moolenaar34390282019-10-16 14:38:26 +02001399 if (draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001400 {
1401 // handle Visual or match highlighting in this line
1402 if (vcol == fromcol
1403 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0
1404 && (*mb_ptr2cells)(ptr) > 1)
1405 || ((int)vcol_prev == fromcol_prev
1406 && vcol_prev < vcol // not at margin
1407 && vcol < tocol))
1408 area_attr = vi_attr; // start highlighting
1409 else if (area_attr != 0
1410 && (vcol == tocol
1411 || (noinvcur && (colnr_T)vcol == wp->w_virtcol)))
1412 area_attr = 0; // stop highlighting
1413
1414#ifdef FEAT_SEARCH_EXTRA
1415 if (!n_extra)
1416 {
1417 // Check for start/end of 'hlsearch' and other matches.
1418 // After end, check for start/end of next match.
1419 // When another match, have to check for start again.
1420 v = (long)(ptr - line);
1421 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1422 &screen_search_hl, &has_match_conc,
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001423 &match_conc, did_line_attr, lcs_eol_one,
1424 &on_last_col);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001425 ptr = line + v; // "line" may have been changed
Bram Moolenaarb9081882022-07-09 04:56:24 +01001426 prev_ptr = ptr;
Bram Moolenaarfc838d62020-06-25 22:23:48 +02001427
1428 // Do not allow a conceal over EOL otherwise EOL will be missed
1429 // and bad things happen.
1430 if (*ptr == NUL)
1431 has_match_conc = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001432 }
1433#endif
1434
1435#ifdef FEAT_DIFF
1436 if (diff_hlf != (hlf_T)0)
1437 {
1438 if (diff_hlf == HLF_CHD && ptr - line >= change_start
1439 && n_extra == 0)
1440 diff_hlf = HLF_TXD; // changed text
1441 if (diff_hlf == HLF_TXD && ptr - line > change_end
1442 && n_extra == 0)
1443 diff_hlf = HLF_CHD; // changed line
1444 line_attr = HL_ATTR(diff_hlf);
1445 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1446 && wp->w_p_culopt_flags != CULOPT_NBR
1447 && (!cul_screenline || (vcol >= left_curline_col
1448 && vcol <= right_curline_col)))
1449 line_attr = hl_combine_attr(
1450 line_attr, HL_ATTR(HLF_CUL));
1451 }
1452#endif
1453
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001454#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001455 if (text_props != NULL)
1456 {
1457 int pi;
1458 int bcol = (int)(ptr - line);
1459
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001460 if (n_extra > 0
1461# ifdef FEAT_LINEBREAK
1462 && !in_linebreak
1463# endif
1464 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001465 --bcol; // still working on the previous char, e.g. Tab
1466
1467 // Check if any active property ends.
1468 for (pi = 0; pi < text_props_active; ++pi)
1469 {
1470 int tpi = text_prop_idxs[pi];
1471
1472 if (bcol >= text_props[tpi].tp_col - 1
1473 + text_props[tpi].tp_len)
1474 {
1475 if (pi + 1 < text_props_active)
1476 mch_memmove(text_prop_idxs + pi,
1477 text_prop_idxs + pi + 1,
1478 sizeof(int)
1479 * (text_props_active - (pi + 1)));
1480 --text_props_active;
1481 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001482# ifdef FEAT_LINEBREAK
1483 // not exactly right but should work in most cases
1484 if (in_linebreak && syntax_attr == text_prop_attr)
1485 syntax_attr = 0;
1486# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001487 }
1488 }
1489
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001490# ifdef FEAT_LINEBREAK
1491 if (n_extra > 0 && in_linebreak)
1492 // not on the next char yet, don't start another prop
1493 --bcol;
1494# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001495 // Add any text property that starts in this column.
1496 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001497 && (text_props[text_prop_next].tp_col == MAXCOL
1498 ? *ptr == NUL
1499 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001500 {
1501 if (bcol <= text_props[text_prop_next].tp_col - 1
1502 + text_props[text_prop_next].tp_len)
1503 text_prop_idxs[text_props_active++] = text_prop_next;
1504 ++text_prop_next;
1505 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001506
1507 text_prop_attr = 0;
1508 text_prop_combine = FALSE;
Bram Moolenaar053f7122019-09-23 22:17:15 +02001509 text_prop_type = NULL;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001510 text_prop_id = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001511 if (text_props_active > 0 && n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001512 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001513 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001514 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001515 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001516
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001517 // Sort the properties on priority and/or starting last.
1518 // Then combine the attributes, highest priority last.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001519 text_prop_follows = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001520 current_text_props = text_props;
1521 current_buf = wp->w_buffer;
1522 qsort((void *)text_prop_idxs, (size_t)text_props_active,
1523 sizeof(int), text_prop_compare);
1524
1525 for (pi = 0; pi < text_props_active; ++pi)
1526 {
1527 int tpi = text_prop_idxs[pi];
1528 proptype_T *pt = text_prop_type_by_id(
1529 wp->w_buffer, text_props[tpi].tp_type);
1530
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001531 if (pt != NULL && pt->pt_hl_id > 0
1532 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001533 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001534 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001535 text_prop_type = pt;
1536 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001537 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001538 text_prop_combine = pt->pt_flags & PT_FLAG_COMBINE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001539 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001540 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001541 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001542 }
1543 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001544 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001545 && -text_prop_id
1546 <= wp->w_buffer->b_textprop_text.ga_len)
1547 {
1548 char_u *p = ((char_u **)wp->w_buffer
1549 ->b_textprop_text.ga_data)[
1550 -text_prop_id - 1];
1551 if (p != NULL)
1552 {
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001553 int right = (text_props[used_tpi].tp_flags
1554 & TP_FLAG_ALIGN_RIGHT);
1555 int below = (text_props[used_tpi].tp_flags
1556 & TP_FLAG_ALIGN_BELOW);
1557
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001558 p_extra = p;
Bram Moolenaar711483c2022-07-30 21:33:46 +01001559 c_extra = NUL;
1560 c_final = NUL;
Mike Williams04947892022-07-26 16:03:42 +01001561 n_extra = (int)STRLEN(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001562 extra_attr = used_attr;
1563 n_attr = n_extra;
1564 text_prop_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001565 if (*ptr == NUL)
1566 // don't combine char attr after EOL
1567 text_prop_combine = FALSE;
1568
1569 // TODO: truncation if it doesn't fit
1570 if (right || below)
1571 {
1572 int added = wp->w_width - col;
1573 char_u *l;
1574
1575 // Right-align: fill with spaces
1576 // TODO: count screen columns
1577 if (right)
1578 added -= n_extra;
1579 if (added < 0 || (below && col == 0))
1580 added = 0;
1581 l = alloc(n_extra + added + 1);
1582 if (l != NULL)
1583 {
1584 vim_memset(l, ' ', added);
1585 STRCPY(l + added, p);
1586 vim_free(p_extra_free);
1587 p_extra = p_extra_free = l;
1588 n_extra += added;
1589 n_attr_skip = added;
1590 }
1591 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001592
1593 // If the cursor is on or after this position,
1594 // move it forward.
1595 if (wp == curwin
1596 && lnum == curwin->w_cursor.lnum
1597 && curwin->w_cursor.col >= vcol)
1598 curwin->w_cursor.col += n_extra;
1599 }
1600 // reset the ID in the copy to avoid it being used
1601 // again
1602 text_props[used_tpi].tp_id = -MAXCOL;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001603
1604 // If another text prop follows the condition below at
1605 // the last window column must know.
1606 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001607 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001608 }
1609 }
1610#endif
1611
Bram Moolenaara74fda62019-10-19 17:38:03 +02001612#ifdef FEAT_SYN_HL
Bram Moolenaara74fda62019-10-19 17:38:03 +02001613 if (extra_check && n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001614 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001615 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001616# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001617 if (get_term_attr)
Bram Moolenaar219c7d02020-02-01 21:57:29 +01001618 syntax_attr = term_get_attr(wp, lnum, vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001619# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001620 // Get syntax attribute.
1621 if (has_syntax)
1622 {
1623 // Get the syntax attribute for the character. If there
1624 // is an error, disable syntax highlighting.
1625 save_did_emsg = did_emsg;
1626 did_emsg = FALSE;
1627
1628 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001629 if (v == prev_syntax_col)
1630 // at same column again
1631 syntax_attr = prev_syntax_attr;
1632 else
1633 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001634# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001635 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001636# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001637 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001638# ifdef FEAT_SPELL
1639 has_spell ? &can_spell :
1640# endif
1641 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001642 prev_syntax_col = v;
1643 prev_syntax_attr = syntax_attr;
1644 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001645
Bram Moolenaar34390282019-10-16 14:38:26 +02001646 if (did_emsg)
1647 {
1648 wp->w_s->b_syn_error = TRUE;
1649 has_syntax = FALSE;
1650 syntax_attr = 0;
1651 }
1652 else
1653 did_emsg = save_did_emsg;
1654# ifdef SYN_TIME_LIMIT
1655 if (wp->w_s->b_syn_slow)
1656 has_syntax = FALSE;
1657# endif
1658
1659 // Need to get the line again, a multi-line regexp may
1660 // have made it invalid.
1661 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1662 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001663 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001664# ifdef FEAT_CONCEAL
1665 // no concealing past the end of the line, it interferes
1666 // with line highlighting
1667 if (*ptr == NUL)
1668 syntax_flags = 0;
1669 else
1670 syntax_flags = get_syntax_info(&syntax_seqnr);
1671# endif
1672 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001673 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001674# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001675 // Combine text property highlight into syntax highlight.
1676 if (text_prop_type != NULL)
1677 {
1678 if (text_prop_combine)
1679 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1680 else
1681 syntax_attr = text_prop_attr;
1682 }
1683# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001684#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001685
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001686 // Decide which of the highlight attributes to use.
1687 attr_pri = TRUE;
1688#ifdef LINE_ATTR
1689 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001690 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001691 char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02001692 if (!highlight_match)
1693 // let search highlight show in Visual area if possible
1694 char_attr = hl_combine_attr(search_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001695# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001696 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001697# endif
1698 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001699 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001700 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001701 char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001702# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001703 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001704# endif
1705 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001706 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
1707 || vcol < fromcol || vcol_prev < fromcol_prev
1708 || vcol >= tocol))
1709 {
1710 // Use line_attr when not in the Visual or 'incsearch' area
1711 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001712# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001713 char_attr = hl_combine_attr(syntax_attr, line_attr);
1714# else
1715 char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001716# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001717 attr_pri = FALSE;
1718 }
1719#else
1720 if (area_attr != 0)
1721 char_attr = area_attr;
1722 else if (search_attr != 0)
1723 char_attr = search_attr;
1724#endif
1725 else
1726 {
1727 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001728#ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001729 char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001730#else
Bram Moolenaardbd43162019-11-09 21:28:14 +01001731 char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001732#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001733 }
1734 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001735
1736 // combine attribute with 'wincolor'
1737 if (win_attr != 0)
1738 {
1739 if (char_attr == 0)
1740 char_attr = win_attr;
1741 else
1742 char_attr = hl_combine_attr(win_attr, char_attr);
1743 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001744
1745 // Get the next character to put on the screen.
1746
1747 // The "p_extra" points to the extra stuff that is inserted to
1748 // represent special characters (non-printable stuff) and other
1749 // things. When all characters are the same, c_extra is used.
1750 // If c_final is set, it will compulsorily be used at the end.
1751 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
1752 // "p_extra[n_extra]".
1753 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
1754 if (n_extra > 0)
1755 {
1756 if (c_extra != NUL || (n_extra == 1 && c_final != NUL))
1757 {
1758 c = (n_extra == 1 && c_final != NUL) ? c_final : c_extra;
1759 mb_c = c; // doesn't handle non-utf-8 multi-byte!
1760 if (enc_utf8 && utf_char2len(c) > 1)
1761 {
1762 mb_utf8 = TRUE;
1763 u8cc[0] = 0;
1764 c = 0xc0;
1765 }
1766 else
1767 mb_utf8 = FALSE;
1768 }
1769 else
1770 {
1771 c = *p_extra;
1772 if (has_mbyte)
1773 {
1774 mb_c = c;
1775 if (enc_utf8)
1776 {
1777 // If the UTF-8 character is more than one byte:
1778 // Decode it into "mb_c".
1779 mb_l = utfc_ptr2len(p_extra);
1780 mb_utf8 = FALSE;
1781 if (mb_l > n_extra)
1782 mb_l = 1;
1783 else if (mb_l > 1)
1784 {
1785 mb_c = utfc_ptr2char(p_extra, u8cc);
1786 mb_utf8 = TRUE;
1787 c = 0xc0;
1788 }
1789 }
1790 else
1791 {
1792 // if this is a DBCS character, put it in "mb_c"
1793 mb_l = MB_BYTE2LEN(c);
1794 if (mb_l >= n_extra)
1795 mb_l = 1;
1796 else if (mb_l > 1)
1797 mb_c = (c << 8) + p_extra[1];
1798 }
1799 if (mb_l == 0) // at the NUL at end-of-line
1800 mb_l = 1;
1801
1802 // If a double-width char doesn't fit display a '>' in the
1803 // last column.
1804 if ((
1805# ifdef FEAT_RIGHTLEFT
1806 wp->w_p_rl ? (col <= 0) :
1807# endif
1808 (col >= wp->w_width - 1))
1809 && (*mb_char2cells)(mb_c) == 2)
1810 {
1811 c = '>';
1812 mb_c = c;
1813 mb_l = 1;
1814 mb_utf8 = FALSE;
1815 multi_attr = HL_ATTR(HLF_AT);
1816#ifdef FEAT_SYN_HL
1817 if (cul_attr)
1818 multi_attr = hl_combine_attr(multi_attr, cul_attr);
1819#endif
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001820 multi_attr = hl_combine_attr(win_attr, multi_attr);
1821
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001822 // put the pointer back to output the double-width
1823 // character at the start of the next line.
1824 ++n_extra;
1825 --p_extra;
1826 }
1827 else
1828 {
1829 n_extra -= mb_l - 1;
1830 p_extra += mb_l - 1;
1831 }
1832 }
1833 ++p_extra;
1834 }
1835 --n_extra;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001836#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001837 if (n_extra <= 0)
1838 in_linebreak = FALSE;
1839#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001840 }
1841 else
1842 {
1843#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01001844 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001845#endif
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001846 VIM_CLEAR(p_extra_free);
Bram Moolenaarb9081882022-07-09 04:56:24 +01001847 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001848
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001849 // Get a character from the line itself.
1850 c = *ptr;
1851#ifdef FEAT_LINEBREAK
1852 c0 = *ptr;
1853#endif
1854 if (has_mbyte)
1855 {
1856 mb_c = c;
1857 if (enc_utf8)
1858 {
1859 // If the UTF-8 character is more than one byte: Decode it
1860 // into "mb_c".
1861 mb_l = utfc_ptr2len(ptr);
1862 mb_utf8 = FALSE;
1863 if (mb_l > 1)
1864 {
1865 mb_c = utfc_ptr2char(ptr, u8cc);
1866 // Overlong encoded ASCII or ASCII with composing char
1867 // is displayed normally, except a NUL.
1868 if (mb_c < 0x80)
1869 {
1870 c = mb_c;
1871#ifdef FEAT_LINEBREAK
1872 c0 = mb_c;
1873#endif
1874 }
1875 mb_utf8 = TRUE;
1876
1877 // At start of the line we can have a composing char.
1878 // Draw it as a space with a composing char.
1879 if (utf_iscomposing(mb_c))
1880 {
1881 int i;
1882
1883 for (i = Screen_mco - 1; i > 0; --i)
1884 u8cc[i] = u8cc[i - 1];
1885 u8cc[0] = mb_c;
1886 mb_c = ' ';
1887 }
1888 }
1889
1890 if ((mb_l == 1 && c >= 0x80)
1891 || (mb_l >= 1 && mb_c == 0)
1892 || (mb_l > 1 && (!vim_isprintc(mb_c))))
1893 {
1894 // Illegal UTF-8 byte: display as <xx>.
1895 // Non-BMP character : display as ? or fullwidth ?.
1896 transchar_hex(extra, mb_c);
1897# ifdef FEAT_RIGHTLEFT
1898 if (wp->w_p_rl) // reverse
1899 rl_mirror(extra);
1900# endif
1901 p_extra = extra;
1902 c = *p_extra;
1903 mb_c = mb_ptr2char_adv(&p_extra);
1904 mb_utf8 = (c >= 0x80);
1905 n_extra = (int)STRLEN(p_extra);
1906 c_extra = NUL;
1907 c_final = NUL;
1908 if (area_attr == 0 && search_attr == 0)
1909 {
1910 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001911 extra_attr = hl_combine_attr(
1912 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001913 saved_attr2 = char_attr; // save current attr
1914 }
1915 }
1916 else if (mb_l == 0) // at the NUL at end-of-line
1917 mb_l = 1;
1918#ifdef FEAT_ARABIC
1919 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
1920 {
1921 // Do Arabic shaping.
1922 int pc, pc1, nc;
1923 int pcc[MAX_MCO];
1924
1925 // The idea of what is the previous and next
1926 // character depends on 'rightleft'.
1927 if (wp->w_p_rl)
1928 {
1929 pc = prev_c;
1930 pc1 = prev_c1;
1931 nc = utf_ptr2char(ptr + mb_l);
1932 prev_c1 = u8cc[0];
1933 }
1934 else
1935 {
1936 pc = utfc_ptr2char(ptr + mb_l, pcc);
1937 nc = prev_c;
1938 pc1 = pcc[0];
1939 }
1940 prev_c = mb_c;
1941
1942 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
1943 }
1944 else
1945 prev_c = mb_c;
1946#endif
1947 }
1948 else // enc_dbcs
1949 {
1950 mb_l = MB_BYTE2LEN(c);
1951 if (mb_l == 0) // at the NUL at end-of-line
1952 mb_l = 1;
1953 else if (mb_l > 1)
1954 {
1955 // We assume a second byte below 32 is illegal.
1956 // Hopefully this is OK for all double-byte encodings!
1957 if (ptr[1] >= 32)
1958 mb_c = (c << 8) + ptr[1];
1959 else
1960 {
1961 if (ptr[1] == NUL)
1962 {
1963 // head byte at end of line
1964 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02001965 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001966 }
1967 else
1968 {
1969 // illegal tail byte
1970 mb_l = 2;
1971 STRCPY(extra, "XX");
1972 }
1973 p_extra = extra;
1974 n_extra = (int)STRLEN(extra) - 1;
1975 c_extra = NUL;
1976 c_final = NUL;
1977 c = *p_extra++;
1978 if (area_attr == 0 && search_attr == 0)
1979 {
1980 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001981 extra_attr = hl_combine_attr(
1982 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001983 saved_attr2 = char_attr; // save current attr
1984 }
1985 mb_c = c;
1986 }
1987 }
1988 }
1989 // If a double-width char doesn't fit display a '>' in the
1990 // last column; the character is displayed at the start of the
1991 // next line.
1992 if ((
1993# ifdef FEAT_RIGHTLEFT
1994 wp->w_p_rl ? (col <= 0) :
1995# endif
1996 (col >= wp->w_width - 1))
1997 && (*mb_char2cells)(mb_c) == 2)
1998 {
1999 c = '>';
2000 mb_c = c;
2001 mb_utf8 = FALSE;
2002 mb_l = 1;
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002003 multi_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002004 // Put pointer back so that the character will be
2005 // displayed at the start of the next line.
2006 --ptr;
2007#ifdef FEAT_CONCEAL
2008 did_decrement_ptr = TRUE;
2009#endif
2010 }
2011 else if (*ptr != NUL)
2012 ptr += mb_l - 1;
2013
2014 // If a double-width char doesn't fit at the left side display
2015 // a '<' in the first column. Don't do this for unprintable
2016 // characters.
2017 if (n_skip > 0 && mb_l > 1 && n_extra == 0)
2018 {
2019 n_extra = 1;
2020 c_extra = MB_FILLER_CHAR;
2021 c_final = NUL;
2022 c = ' ';
2023 if (area_attr == 0 && search_attr == 0)
2024 {
2025 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002026 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002027 saved_attr2 = char_attr; // save current attr
2028 }
2029 mb_c = c;
2030 mb_utf8 = FALSE;
2031 mb_l = 1;
2032 }
2033
2034 }
2035 ++ptr;
2036
2037 if (extra_check)
2038 {
2039#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002040 // Check spelling (unless at the end of the line).
2041 // Only do this when there is no syntax highlighting, the
2042 // @Spell cluster is not used or the current syntax item
2043 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002044 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002045 if (has_spell && v >= word_end && v > cur_checked_col)
2046 {
2047 spell_attr = 0;
2048 if (c != 0 && (
2049# ifdef FEAT_SYN_HL
2050 !has_syntax ||
2051# endif
2052 can_spell))
2053 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002054 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002055 int len;
2056 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002057
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002058 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002059 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002060
2061 // Use nextline[] if possible, it has the start of the
2062 // next line concatenated.
2063 if ((prev_ptr - line) - nextlinecol >= 0)
2064 p = nextline + (prev_ptr - line) - nextlinecol;
2065 else
2066 p = prev_ptr;
2067 cap_col -= (int)(prev_ptr - line);
2068 len = spell_check(wp, p, &spell_hlf, &cap_col,
2069 nochange);
2070 word_end = v + len;
2071
2072 // In Insert mode only highlight a word that
2073 // doesn't touch the cursor.
2074 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002075 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002076 && wp->w_cursor.lnum == lnum
2077 && wp->w_cursor.col >=
2078 (colnr_T)(prev_ptr - line)
2079 && wp->w_cursor.col < (colnr_T)word_end)
2080 {
2081 spell_hlf = HLF_COUNT;
2082 spell_redraw_lnum = lnum;
2083 }
2084
2085 if (spell_hlf == HLF_COUNT && p != prev_ptr
2086 && (p - nextline) + len > nextline_idx)
2087 {
2088 // Remember that the good word continues at the
2089 // start of the next line.
2090 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002091 checked_col = (int)((p - nextline)
2092 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002093 }
2094
2095 // Turn index into actual attributes.
2096 if (spell_hlf != HLF_COUNT)
2097 spell_attr = highlight_attr[spell_hlf];
2098
2099 if (cap_col > 0)
2100 {
2101 if (p != prev_ptr
2102 && (p - nextline) + cap_col >= nextline_idx)
2103 {
2104 // Remember that the word in the next line
2105 // must start with a capital.
2106 capcol_lnum = lnum + 1;
2107 cap_col = (int)((p - nextline) + cap_col
2108 - nextline_idx);
2109 }
2110 else
2111 // Compute the actual column.
2112 cap_col += (int)(prev_ptr - line);
2113 }
2114 }
2115 }
2116 if (spell_attr != 0)
2117 {
2118 if (!attr_pri)
2119 char_attr = hl_combine_attr(char_attr, spell_attr);
2120 else
2121 char_attr = hl_combine_attr(spell_attr, char_attr);
2122 }
2123#endif
2124#ifdef FEAT_LINEBREAK
2125 // Found last space before word: check for line break.
2126 if (wp->w_p_lbr && c0 == c
2127 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2128 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002129 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2130 : 0;
2131 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002132 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002133
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002134 init_chartabsize_arg(&cts, wp, lnum, vcol, line, p);
2135 n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002136
2137 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002138 // space for it again.
Bram Moolenaara06e3452021-05-29 17:56:37 +02002139 if (vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002140 {
Bram Moolenaara06e3452021-05-29 17:56:37 +02002141 n_extra -= MB_CHARLEN(get_showbreak_value(wp));
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002142 if (n_extra < 0)
2143 n_extra = 0;
2144 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002145 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002146 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002147 // line break, but for TABs the highlighting should
2148 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002149 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002150
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002151 if (c == TAB && n_extra + col > wp->w_width)
2152# ifdef FEAT_VARTABS
2153 n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts,
2154 wp->w_buffer->b_p_vts_array) - 1;
2155# else
2156 n_extra = (int)wp->w_buffer->b_p_ts
2157 - vcol % (int)wp->w_buffer->b_p_ts - 1;
2158# endif
2159
2160 c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2161 c_final = NUL;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002162# if defined(FEAT_PROP_POPUP)
Bram Moolenaar42eba042021-11-30 20:22:49 +00002163 if (n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002164 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002165# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002166 if (VIM_ISWHITE(c))
2167 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002168# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002169 if (c == TAB)
2170 // See "Tab alignment" below.
2171 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002172# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002173 if (!wp->w_p_list)
2174 c = ' ';
2175 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002176 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002177 }
2178#endif
2179
zeertzjqf14b8ba2021-09-10 16:58:30 +02002180 in_multispace = c == ' '
2181 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2182 if (!in_multispace)
2183 multispace_pos = 0;
2184
Bram Moolenaareed9d462021-02-15 20:38:25 +01002185 // 'list': Change char 160 to 'nbsp' and space to 'space'
2186 // setting in 'listchars'. But not when the character is
2187 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002188 if (wp->w_p_list
2189 && ((((c == 160 && mb_l == 1)
2190 || (mb_utf8
2191 && ((mb_c == 160 && mb_l == 2)
2192 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002193 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002194 || (c == ' '
2195 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002196 && (wp->w_lcs_chars.space
2197 || (in_multispace
2198 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002199 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002200 && ptr - line <= trailcol)))
2201 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002202 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2203 {
2204 c = wp->w_lcs_chars.multispace[multispace_pos++];
2205 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2206 multispace_pos = 0;
2207 }
2208 else
2209 c = (c == ' ') ? wp->w_lcs_chars.space
2210 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002211 if (area_attr == 0 && search_attr == 0)
2212 {
2213 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002214 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002215 saved_attr2 = char_attr; // save current attr
2216 }
2217 mb_c = c;
2218 if (enc_utf8 && utf_char2len(c) > 1)
2219 {
2220 mb_utf8 = TRUE;
2221 u8cc[0] = 0;
2222 c = 0xc0;
2223 }
2224 else
2225 mb_utf8 = FALSE;
2226 }
2227
zeertzjq2e7cba32022-06-10 15:30:32 +01002228 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2229 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002230 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002231 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2232 && wp->w_lcs_chars.leadmultispace != NULL)
2233 {
2234 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002235 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2236 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002237 multispace_pos = 0;
2238 }
2239
2240 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2241 c = wp->w_lcs_chars.trail;
2242
2243 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2244 c = wp->w_lcs_chars.lead;
2245
zeertzjq2e7cba32022-06-10 15:30:32 +01002246 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002247 c = wp->w_lcs_chars.space;
2248
2249
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002250 if (!attr_pri)
2251 {
2252 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002253 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002254 saved_attr2 = char_attr; // save current attr
2255 }
2256 mb_c = c;
2257 if (enc_utf8 && utf_char2len(c) > 1)
2258 {
2259 mb_utf8 = TRUE;
2260 u8cc[0] = 0;
2261 c = 0xc0;
2262 }
2263 else
2264 mb_utf8 = FALSE;
2265 }
2266 }
2267
2268 // Handling of non-printable characters.
2269 if (!vim_isprintc(c))
2270 {
2271 // when getting a character from the file, we may have to
2272 // turn it into something else on the way to putting it
2273 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002274 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002275 {
2276 int tab_len = 0;
2277 long vcol_adjusted = vcol; // removed showbreak length
2278#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002279 char_u *sbr = get_showbreak_value(wp);
2280
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002281 // only adjust the tab_len, when at the first column
2282 // after the showbreak value was drawn
Bram Moolenaaree857022019-11-09 23:26:40 +01002283 if (*sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap)
2284 vcol_adjusted = vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002285#endif
2286 // tab amount depends on current column
2287#ifdef FEAT_VARTABS
2288 tab_len = tabstop_padding(vcol_adjusted,
2289 wp->w_buffer->b_p_ts,
2290 wp->w_buffer->b_p_vts_array) - 1;
2291#else
2292 tab_len = (int)wp->w_buffer->b_p_ts
2293 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2294#endif
2295
2296#ifdef FEAT_LINEBREAK
2297 if (!wp->w_p_lbr || !wp->w_p_list)
2298#endif
2299 // tab amount depends on current column
2300 n_extra = tab_len;
2301#ifdef FEAT_LINEBREAK
2302 else
2303 {
2304 char_u *p;
2305 int len;
2306 int i;
2307 int saved_nextra = n_extra;
2308
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002309# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002310 if (vcol_off > 0)
2311 // there are characters to conceal
2312 tab_len += vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002313
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002314 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002315 if (wp->w_p_list && wp->w_lcs_chars.tab1
2316 && old_boguscols > 0
2317 && n_extra > tab_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002318 tab_len += n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002319# endif
2320 // If n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002321 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002322 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002323 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002324 if (wp->w_lcs_chars.tab3)
2325 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002326 if (n_extra > 0)
2327 len += n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002328 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002329 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002330 if (p == NULL)
2331 n_extra = 0;
2332 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002333 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002334 vim_memset(p, ' ', len);
2335 p[len] = NUL;
2336 vim_free(p_extra_free);
2337 p_extra_free = p;
2338 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002339 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002340 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002341
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002342 if (*p == NUL)
2343 {
2344 tab_len = i;
2345 break;
2346 }
2347
2348 // if tab3 is given, use it for the last char
2349 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2350 lcs = wp->w_lcs_chars.tab3;
2351 p += mb_char2bytes(lcs, p);
2352 n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002353 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002354 }
2355 p_extra = p_extra_free;
2356# ifdef FEAT_CONCEAL
2357 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2358 // macro below, so need to adjust for that here
2359 if (vcol_off > 0)
2360 n_extra -= vcol_off;
2361# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002362 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002363 }
2364#endif
2365#ifdef FEAT_CONCEAL
2366 {
2367 int vc_saved = vcol_off;
2368
2369 // Tab alignment should be identical regardless of
2370 // 'conceallevel' value. So tab compensates of all
2371 // previous concealed characters, and thus resets
2372 // vcol_off and boguscols accumulated so far in the
2373 // line. Note that the tab can be longer than
2374 // 'tabstop' when there are concealed characters.
2375 FIX_FOR_BOGUSCOLS;
2376
2377 // Make sure, the highlighting for the tab char will be
2378 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002379 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002380 if (n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002381 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002382 tab_len += vc_saved;
2383 }
2384#endif
2385 mb_utf8 = FALSE; // don't draw as UTF-8
2386 if (wp->w_p_list)
2387 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002388 c = (n_extra == 0 && wp->w_lcs_chars.tab3)
2389 ? wp->w_lcs_chars.tab3
2390 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002391#ifdef FEAT_LINEBREAK
2392 if (wp->w_p_lbr)
2393 c_extra = NUL; // using p_extra from above
2394 else
2395#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01002396 c_extra = wp->w_lcs_chars.tab2;
2397 c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002398 n_attr = tab_len + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002399 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002400 saved_attr2 = char_attr; // save current attr
2401 mb_c = c;
2402 if (enc_utf8 && utf_char2len(c) > 1)
2403 {
2404 mb_utf8 = TRUE;
2405 u8cc[0] = 0;
2406 c = 0xc0;
2407 }
2408 }
2409 else
2410 {
2411 c_final = NUL;
2412 c_extra = ' ';
2413 c = ' ';
2414 }
2415 }
2416 else if (c == NUL
2417 && (wp->w_p_list
2418 || ((fromcol >= 0 || fromcol_prev >= 0)
2419 && tocol > vcol
2420 && VIsual_mode != Ctrl_V
2421 && (
2422# ifdef FEAT_RIGHTLEFT
2423 wp->w_p_rl ? (col >= 0) :
2424# endif
2425 (col < wp->w_width))
2426 && !(noinvcur
2427 && lnum == wp->w_cursor.lnum
2428 && (colnr_T)vcol == wp->w_virtcol)))
2429 && lcs_eol_one > 0)
2430 {
2431 // Display a '$' after the line or highlight an extra
2432 // character if the line break is included.
2433#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2434 // For a diff line the highlighting continues after the
2435 // "$".
2436 if (
2437# ifdef FEAT_DIFF
2438 diff_hlf == (hlf_T)0
2439# ifdef LINE_ATTR
2440 &&
2441# endif
2442# endif
2443# ifdef LINE_ATTR
2444 line_attr == 0
2445# endif
2446 )
2447#endif
2448 {
2449 // In virtualedit, visual selections may extend
2450 // beyond end of line.
2451 if (area_highlighting && virtual_active()
2452 && tocol != MAXCOL && vcol < tocol)
2453 n_extra = 0;
2454 else
2455 {
2456 p_extra = at_end_str;
2457 n_extra = 1;
2458 c_extra = NUL;
2459 c_final = NUL;
2460 }
2461 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002462 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2463 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002464 else
2465 c = ' ';
2466 lcs_eol_one = -1;
2467 --ptr; // put it back at the NUL
2468 if (!attr_pri)
2469 {
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002470 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002471 n_attr = 1;
2472 }
2473 mb_c = c;
2474 if (enc_utf8 && utf_char2len(c) > 1)
2475 {
2476 mb_utf8 = TRUE;
2477 u8cc[0] = 0;
2478 c = 0xc0;
2479 }
2480 else
2481 mb_utf8 = FALSE; // don't draw as UTF-8
2482 }
2483 else if (c != NUL)
2484 {
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002485 p_extra = transchar_buf(wp->w_buffer, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002486 if (n_extra == 0)
2487 n_extra = byte2cells(c) - 1;
2488#ifdef FEAT_RIGHTLEFT
2489 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
2490 rl_mirror(p_extra); // reverse "<12>"
2491#endif
2492 c_extra = NUL;
2493 c_final = NUL;
2494#ifdef FEAT_LINEBREAK
2495 if (wp->w_p_lbr)
2496 {
2497 char_u *p;
2498
2499 c = *p_extra;
2500 p = alloc(n_extra + 1);
2501 vim_memset(p, ' ', n_extra);
2502 STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1);
2503 p[n_extra] = NUL;
2504 vim_free(p_extra_free);
2505 p_extra_free = p_extra = p;
2506 }
2507 else
2508#endif
2509 {
2510 n_extra = byte2cells(c) - 1;
2511 c = *p_extra++;
2512 }
2513 if (!attr_pri)
2514 {
2515 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002516 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002517 saved_attr2 = char_attr; // save current attr
2518 }
2519 mb_utf8 = FALSE; // don't draw as UTF-8
2520 }
2521 else if (VIsual_active
2522 && (VIsual_mode == Ctrl_V
2523 || VIsual_mode == 'v')
2524 && virtual_active()
2525 && tocol != MAXCOL
2526 && vcol < tocol
2527 && (
2528#ifdef FEAT_RIGHTLEFT
2529 wp->w_p_rl ? (col >= 0) :
2530#endif
2531 (col < wp->w_width)))
2532 {
2533 c = ' ';
2534 --ptr; // put it back at the NUL
2535 }
2536#if defined(LINE_ATTR)
2537 else if ((
2538# ifdef FEAT_DIFF
2539 diff_hlf != (hlf_T)0 ||
2540# endif
2541# ifdef FEAT_TERMINAL
2542 win_attr != 0 ||
2543# endif
2544 line_attr != 0
2545 ) && (
2546# ifdef FEAT_RIGHTLEFT
2547 wp->w_p_rl ? (col >= 0) :
2548# endif
2549 (col
2550# ifdef FEAT_CONCEAL
2551 - boguscols
2552# endif
2553 < wp->w_width)))
2554 {
2555 // Highlight until the right side of the window
2556 c = ' ';
2557 --ptr; // put it back at the NUL
2558
2559 // Remember we do the char for line highlighting.
2560 ++did_line_attr;
2561
2562 // don't do search HL for the rest of the line
2563 if (line_attr != 0 && char_attr == search_attr
2564 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002565 || (wp->w_p_list &&
2566 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002567 char_attr = line_attr;
2568# ifdef FEAT_DIFF
2569 if (diff_hlf == HLF_TXD)
2570 {
2571 diff_hlf = HLF_CHD;
2572 if (vi_attr == 0 || char_attr != vi_attr)
2573 {
2574 char_attr = HL_ATTR(diff_hlf);
2575 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2576 && wp->w_p_culopt_flags != CULOPT_NBR
2577 && (!cul_screenline
2578 || (vcol >= left_curline_col
2579 && vcol <= right_curline_col)))
2580 char_attr = hl_combine_attr(
2581 char_attr, HL_ATTR(HLF_CUL));
2582 }
2583 }
2584# endif
2585# ifdef FEAT_TERMINAL
2586 if (win_attr != 0)
2587 {
2588 char_attr = win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002589 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2590 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002591 {
2592 if (!cul_screenline || (vcol >= left_curline_col
2593 && vcol <= right_curline_col))
2594 char_attr = hl_combine_attr(
2595 char_attr, HL_ATTR(HLF_CUL));
2596 }
2597 else if (line_attr)
2598 char_attr = hl_combine_attr(char_attr, line_attr);
2599 }
2600# endif
2601 }
2602#endif
2603 }
2604
2605#ifdef FEAT_CONCEAL
2606 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01002607 && (wp != curwin || lnum != wp->w_cursor.lnum
2608 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002609 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2610 && !(lnum_in_visual_area
2611 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2612 {
2613 char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01002614 if (((prev_syntax_id != syntax_seqnr
2615 && (syntax_flags & HL_CONCEAL) != 0)
2616 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002617 && (syn_get_sub_char() != NUL
2618 || (has_match_conc && match_conc)
2619 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002620 && wp->w_p_cole != 3)
2621 {
2622 // First time at this concealed item: display one
2623 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002624 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002625 c = match_conc;
2626 else if (syn_get_sub_char() != NUL)
2627 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01002628 else if (wp->w_lcs_chars.conceal != NUL)
2629 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002630 else
2631 c = ' ';
2632
2633 prev_syntax_id = syntax_seqnr;
2634
2635 if (n_extra > 0)
2636 vcol_off += n_extra;
2637 vcol += n_extra;
2638 if (wp->w_p_wrap && n_extra > 0)
2639 {
2640# ifdef FEAT_RIGHTLEFT
2641 if (wp->w_p_rl)
2642 {
2643 col -= n_extra;
2644 boguscols -= n_extra;
2645 }
2646 else
2647# endif
2648 {
2649 boguscols += n_extra;
2650 col += n_extra;
2651 }
2652 }
2653 n_extra = 0;
2654 n_attr = 0;
2655 }
2656 else if (n_skip == 0)
2657 {
2658 is_concealing = TRUE;
2659 n_skip = 1;
2660 }
2661 mb_c = c;
2662 if (enc_utf8 && utf_char2len(c) > 1)
2663 {
2664 mb_utf8 = TRUE;
2665 u8cc[0] = 0;
2666 c = 0xc0;
2667 }
2668 else
2669 mb_utf8 = FALSE; // don't draw as UTF-8
2670 }
2671 else
2672 {
2673 prev_syntax_id = 0;
2674 is_concealing = FALSE;
2675 }
2676
2677 if (n_skip > 0 && did_decrement_ptr)
2678 // not showing the '>', put pointer back to avoid getting stuck
2679 ++ptr;
2680
2681#endif // FEAT_CONCEAL
2682 }
2683
2684#ifdef FEAT_CONCEAL
2685 // In the cursor line and we may be concealing characters: correct
2686 // the cursor column when we reach its position.
2687 if (!did_wcol && draw_state == WL_LINE
2688 && wp == curwin && lnum == wp->w_cursor.lnum
2689 && conceal_cursor_line(wp)
2690 && (int)wp->w_virtcol <= vcol + n_skip)
2691 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002692# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002693 if (wp->w_p_rl)
2694 wp->w_wcol = wp->w_width - col + boguscols - 1;
2695 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002696# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002697 wp->w_wcol = col - boguscols;
2698 wp->w_wrow = row;
2699 did_wcol = TRUE;
2700 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002701# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01002702 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002703# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002704 }
2705#endif
2706
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002707 // Use "extra_attr", but don't override visual selection highlighting.
2708 // Don't use "extra_attr" until n_attr_skip is zero.
2709 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002710 && draw_state == WL_LINE
2711 && !attr_pri)
2712 {
2713#ifdef LINE_ATTR
2714 if (line_attr)
2715 char_attr = hl_combine_attr(extra_attr, line_attr);
2716 else
2717#endif
2718 char_attr = extra_attr;
2719 }
2720
2721#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2722 // XIM don't send preedit_start and preedit_end, but they send
2723 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
2724 // im_is_preediting() here.
2725 if (p_imst == IM_ON_THE_SPOT
2726 && xic != NULL
2727 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01002728 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002729 && !p_imdisable
2730 && im_is_preediting()
2731 && draw_state == WL_LINE)
2732 {
2733 colnr_T tcol;
2734
2735 if (preedit_end_col == MAXCOL)
2736 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
2737 else
2738 tcol = preedit_end_col;
2739 if ((long)preedit_start_col <= vcol && vcol < (long)tcol)
2740 {
2741 if (feedback_old_attr < 0)
2742 {
2743 feedback_col = 0;
2744 feedback_old_attr = char_attr;
2745 }
2746 char_attr = im_get_feedback_attr(feedback_col);
2747 if (char_attr < 0)
2748 char_attr = feedback_old_attr;
2749 feedback_col++;
2750 }
2751 else if (feedback_old_attr >= 0)
2752 {
2753 char_attr = feedback_old_attr;
2754 feedback_old_attr = -1;
2755 feedback_col = 0;
2756 }
2757 }
2758#endif
2759 // Handle the case where we are in column 0 but not on the first
2760 // character of the line and the user wants us to show us a
2761 // special character (via 'listchars' option "precedes:<char>".
2762 if (lcs_prec_todo != NUL
2763 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02002764 && (wp->w_p_wrap ?
2765 (wp->w_skipcol > 0 && row == 0) :
2766 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002767#ifdef FEAT_DIFF
2768 && filler_todo <= 0
2769#endif
2770 && draw_state > WL_NR
2771 && c != NUL)
2772 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002773 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002774 lcs_prec_todo = NUL;
2775 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2776 {
2777 // Double-width character being overwritten by the "precedes"
2778 // character, need to fill up half the character.
2779 c_extra = MB_FILLER_CHAR;
2780 c_final = NUL;
2781 n_extra = 1;
2782 n_attr = 2;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002783 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002784 }
2785 mb_c = c;
2786 if (enc_utf8 && utf_char2len(c) > 1)
2787 {
2788 mb_utf8 = TRUE;
2789 u8cc[0] = 0;
2790 c = 0xc0;
2791 }
2792 else
2793 mb_utf8 = FALSE; // don't draw as UTF-8
2794 if (!attr_pri)
2795 {
2796 saved_attr3 = char_attr; // save current attr
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002797 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002798 n_attr3 = 1;
2799 }
2800 }
2801
2802 // At end of the text line or just after the last character.
2803 if ((c == NUL
2804#if defined(LINE_ATTR)
2805 || did_line_attr == 1
2806#endif
2807 ) && eol_hl_off == 0)
2808 {
2809#ifdef FEAT_SEARCH_EXTRA
2810 // flag to indicate whether prevcol equals startcol of search_hl or
2811 // one of the matches
2812 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
2813 (long)(ptr - line) - (c == NUL));
2814#endif
2815 // Invert at least one char, used for Visual and empty line or
2816 // highlight match at end of line. If it's beyond the last
2817 // char on the screen, just overwrite that one (tricky!) Not
2818 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002819 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002820 && ((area_attr != 0 && vcol == fromcol
2821 && (VIsual_mode != Ctrl_V
2822 || lnum == VIsual.lnum
2823 || lnum == curwin->w_cursor.lnum)
2824 && c == NUL)
2825#ifdef FEAT_SEARCH_EXTRA
2826 // highlight 'hlsearch' match at end of line
2827 || (prevcol_hl_flag
2828# ifdef FEAT_SYN_HL
2829 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
2830 && !(wp == curwin && VIsual_active))
2831# endif
2832# ifdef FEAT_DIFF
2833 && diff_hlf == (hlf_T)0
2834# endif
2835# if defined(LINE_ATTR)
2836 && did_line_attr <= 1
2837# endif
2838 )
2839#endif
2840 ))
2841 {
2842 int n = 0;
2843
2844#ifdef FEAT_RIGHTLEFT
2845 if (wp->w_p_rl)
2846 {
2847 if (col < 0)
2848 n = 1;
2849 }
2850 else
2851#endif
2852 {
2853 if (col >= wp->w_width)
2854 n = -1;
2855 }
2856 if (n != 0)
2857 {
2858 // At the window boundary, highlight the last character
2859 // instead (better than nothing).
2860 off += n;
2861 col += n;
2862 }
2863 else
2864 {
2865 // Add a blank character to highlight.
2866 ScreenLines[off] = ' ';
2867 if (enc_utf8)
2868 ScreenLinesUC[off] = 0;
2869 }
2870#ifdef FEAT_SEARCH_EXTRA
2871 if (area_attr == 0)
2872 {
2873 // Use attributes from match with highest priority among
2874 // 'search_hl' and the match list.
2875 get_search_match_hl(wp, &screen_search_hl,
2876 (long)(ptr - line), &char_attr);
2877 }
2878#endif
2879 ScreenAttrs[off] = char_attr;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002880 ScreenCols[off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002881#ifdef FEAT_RIGHTLEFT
2882 if (wp->w_p_rl)
2883 {
2884 --col;
2885 --off;
2886 }
2887 else
2888#endif
2889 {
2890 ++col;
2891 ++off;
2892 }
2893 ++vcol;
2894 eol_hl_off = 1;
2895 }
2896 }
2897
2898 // At end of the text line.
2899 if (c == NUL)
2900 {
2901#ifdef FEAT_SYN_HL
2902 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
2903 if (wp->w_p_wrap)
2904 v = wp->w_skipcol;
2905 else
2906 v = wp->w_leftcol;
2907
2908 // check if line ends before left margin
2909 if (vcol < v + col - win_col_off(wp))
2910 vcol = v + col - win_col_off(wp);
2911#ifdef FEAT_CONCEAL
2912 // Get rid of the boguscols now, we want to draw until the right
2913 // edge for 'cursorcolumn'.
2914 col -= boguscols;
2915 boguscols = 0;
2916#endif
2917
2918 if (draw_color_col)
2919 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2920
2921 if (((wp->w_p_cuc
2922 && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off
2923 && (int)wp->w_virtcol <
=?UTF-8?q?Dundar=20G=C3=B6c?=d5cec1f2022-01-29 15:19:23 +00002924 (long)wp->w_width * (row - startrow + 1) + v
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002925 && lnum != wp->w_cursor.lnum)
2926 || draw_color_col
2927 || win_attr != 0)
2928# ifdef FEAT_RIGHTLEFT
2929 && !wp->w_p_rl
2930# endif
2931 )
2932 {
2933 int rightmost_vcol = 0;
2934 int i;
2935
2936 if (wp->w_p_cuc)
2937 rightmost_vcol = wp->w_virtcol;
2938 if (draw_color_col)
2939 // determine rightmost colorcolumn to possibly draw
2940 for (i = 0; color_cols[i] >= 0; ++i)
2941 if (rightmost_vcol < color_cols[i])
2942 rightmost_vcol = color_cols[i];
2943
2944 while (col < wp->w_width)
2945 {
2946 ScreenLines[off] = ' ';
2947 if (enc_utf8)
2948 ScreenLinesUC[off] = 0;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002949 ScreenCols[off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002950 ++col;
2951 if (draw_color_col)
2952 draw_color_col = advance_color_col(VCOL_HLC,
2953 &color_cols);
2954
2955 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
2956 ScreenAttrs[off++] = HL_ATTR(HLF_CUC);
2957 else if (draw_color_col && VCOL_HLC == *color_cols)
2958 ScreenAttrs[off++] = HL_ATTR(HLF_MC);
2959 else
2960 ScreenAttrs[off++] = win_attr;
2961
2962 if (VCOL_HLC >= rightmost_vcol && win_attr == 0)
2963 break;
2964
2965 ++vcol;
2966 }
2967 }
2968#endif
2969
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01002970 screen_line(wp, screen_row, wp->w_wincol, col,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00002971 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002972 row++;
2973
2974 // Update w_cline_height and w_cline_folded if the cursor line was
2975 // updated (saves a call to plines() later).
2976 if (wp == curwin && lnum == curwin->w_cursor.lnum)
2977 {
2978 curwin->w_cline_row = startrow;
2979 curwin->w_cline_height = row - startrow;
2980#ifdef FEAT_FOLDING
2981 curwin->w_cline_folded = FALSE;
2982#endif
2983 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
2984 }
2985
2986 break;
2987 }
2988
2989 // Show "extends" character from 'listchars' if beyond the line end and
2990 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002991 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar41fb7232021-07-08 12:40:05 +02002992 && draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002993 && wp->w_p_list
2994 && !wp->w_p_wrap
2995#ifdef FEAT_DIFF
2996 && filler_todo <= 0
2997#endif
2998 && (
2999#ifdef FEAT_RIGHTLEFT
3000 wp->w_p_rl ? col == 0 :
3001#endif
3002 col == wp->w_width - 1)
3003 && (*ptr != NUL
3004 || (wp->w_p_list && lcs_eol_one > 0)
3005 || (n_extra && (c_extra != NUL || *p_extra != NUL))))
3006 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003007 c = wp->w_lcs_chars.ext;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01003008 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003009 mb_c = c;
3010 if (enc_utf8 && utf_char2len(c) > 1)
3011 {
3012 mb_utf8 = TRUE;
3013 u8cc[0] = 0;
3014 c = 0xc0;
3015 }
3016 else
3017 mb_utf8 = FALSE;
3018 }
3019
3020#ifdef FEAT_SYN_HL
3021 // advance to the next 'colorcolumn'
3022 if (draw_color_col)
3023 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
3024
3025 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3026 // highlight the cursor position itself.
3027 // Also highlight the 'colorcolumn' if it is different than
3028 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003029 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3030 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003031 vcol_save_attr = -1;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003032 if (((draw_state == WL_LINE ||
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003033 draw_state == WL_BRI ||
3034 draw_state == WL_SBR) && !lnum_in_visual_area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003035 && search_attr == 0 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003036# ifdef FEAT_DIFF
3037 && filler_todo <= 0
3038# endif
3039 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003040 {
3041 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3042 && lnum != wp->w_cursor.lnum)
3043 {
3044 vcol_save_attr = char_attr;
3045 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUC));
3046 }
3047 else if (draw_color_col && VCOL_HLC == *color_cols)
3048 {
3049 vcol_save_attr = char_attr;
3050 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_MC));
3051 }
3052 }
3053#endif
3054
3055 // Store character to be displayed.
3056 // Skip characters that are left of the screen for 'nowrap'.
3057 vcol_prev = vcol;
3058 if (draw_state < WL_LINE || n_skip <= 0)
3059 {
3060 // Store the character.
3061#if defined(FEAT_RIGHTLEFT)
3062 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3063 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003064 // A double-wide character is: put first half in left cell.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003065 --off;
3066 --col;
3067 }
3068#endif
3069 ScreenLines[off] = c;
3070 if (enc_dbcs == DBCS_JPNU)
3071 {
3072 if ((mb_c & 0xff00) == 0x8e00)
3073 ScreenLines[off] = 0x8e;
3074 ScreenLines2[off] = mb_c & 0xff;
3075 }
3076 else if (enc_utf8)
3077 {
3078 if (mb_utf8)
3079 {
3080 int i;
3081
3082 ScreenLinesUC[off] = mb_c;
3083 if ((c & 0xff) == 0)
3084 ScreenLines[off] = 0x80; // avoid storing zero
3085 for (i = 0; i < Screen_mco; ++i)
3086 {
3087 ScreenLinesC[i][off] = u8cc[i];
3088 if (u8cc[i] == 0)
3089 break;
3090 }
3091 }
3092 else
3093 ScreenLinesUC[off] = 0;
3094 }
3095 if (multi_attr)
3096 {
3097 ScreenAttrs[off] = multi_attr;
3098 multi_attr = 0;
3099 }
3100 else
3101 ScreenAttrs[off] = char_attr;
3102
Bram Moolenaarb9081882022-07-09 04:56:24 +01003103 ScreenCols[off] = (colnr_T)(prev_ptr - line);
3104
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003105 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3106 {
3107 // Need to fill two screen columns.
3108 ++off;
3109 ++col;
3110 if (enc_utf8)
3111 // UTF-8: Put a 0 in the second screen char.
3112 ScreenLines[off] = 0;
3113 else
3114 // DBCS: Put second byte in the second screen char.
3115 ScreenLines[off] = mb_c & 0xff;
3116 if (draw_state > WL_NR
3117#ifdef FEAT_DIFF
3118 && filler_todo <= 0
3119#endif
3120 )
3121 ++vcol;
3122 // When "tocol" is halfway a character, set it to the end of
3123 // the character, otherwise highlighting won't stop.
3124 if (tocol == vcol)
3125 ++tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003126
3127 ScreenCols[off] = (colnr_T)(prev_ptr - line);
3128
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003129#ifdef FEAT_RIGHTLEFT
3130 if (wp->w_p_rl)
3131 {
3132 // now it's time to backup one cell
3133 --off;
3134 --col;
3135 }
3136#endif
3137 }
3138#ifdef FEAT_RIGHTLEFT
3139 if (wp->w_p_rl)
3140 {
3141 --off;
3142 --col;
3143 }
3144 else
3145#endif
3146 {
3147 ++off;
3148 ++col;
3149 }
3150 }
3151#ifdef FEAT_CONCEAL
3152 else if (wp->w_p_cole > 0 && is_concealing)
3153 {
3154 --n_skip;
3155 ++vcol_off;
3156 if (n_extra > 0)
3157 vcol_off += n_extra;
3158 if (wp->w_p_wrap)
3159 {
3160 // Special voodoo required if 'wrap' is on.
3161 //
3162 // Advance the column indicator to force the line
3163 // drawing to wrap early. This will make the line
3164 // take up the same screen space when parts are concealed,
3165 // so that cursor line computations aren't messed up.
3166 //
3167 // To avoid the fictitious advance of 'col' causing
3168 // trailing junk to be written out of the screen line
3169 // we are building, 'boguscols' keeps track of the number
3170 // of bad columns we have advanced.
3171 if (n_extra > 0)
3172 {
3173 vcol += n_extra;
3174# ifdef FEAT_RIGHTLEFT
3175 if (wp->w_p_rl)
3176 {
3177 col -= n_extra;
3178 boguscols -= n_extra;
3179 }
3180 else
3181# endif
3182 {
3183 col += n_extra;
3184 boguscols += n_extra;
3185 }
3186 n_extra = 0;
3187 n_attr = 0;
3188 }
3189
3190
3191 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3192 {
3193 // Need to fill two screen columns.
3194# ifdef FEAT_RIGHTLEFT
3195 if (wp->w_p_rl)
3196 {
3197 --boguscols;
3198 --col;
3199 }
3200 else
3201# endif
3202 {
3203 ++boguscols;
3204 ++col;
3205 }
3206 }
3207
3208# ifdef FEAT_RIGHTLEFT
3209 if (wp->w_p_rl)
3210 {
3211 --boguscols;
3212 --col;
3213 }
3214 else
3215# endif
3216 {
3217 ++boguscols;
3218 ++col;
3219 }
3220 }
3221 else
3222 {
3223 if (n_extra > 0)
3224 {
3225 vcol += n_extra;
3226 n_extra = 0;
3227 n_attr = 0;
3228 }
3229 }
3230
3231 }
3232#endif // FEAT_CONCEAL
3233 else
3234 --n_skip;
3235
3236 // Only advance the "vcol" when after the 'number' or 'relativenumber'
3237 // column.
3238 if (draw_state > WL_NR
3239#ifdef FEAT_DIFF
3240 && filler_todo <= 0
3241#endif
3242 )
3243 ++vcol;
3244
3245#ifdef FEAT_SYN_HL
3246 if (vcol_save_attr >= 0)
3247 char_attr = vcol_save_attr;
3248#endif
3249
3250 // restore attributes after "predeces" in 'listchars'
3251 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3252 char_attr = saved_attr3;
3253
3254 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003255 if (n_attr > 0 && draw_state == WL_LINE
3256 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003257 char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003258 if (n_attr_skip > 0)
3259 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003260
3261 // At end of screen line and there is more to come: Display the line
3262 // so far. If there is no more to display it is caught above.
3263 if ((
3264#ifdef FEAT_RIGHTLEFT
3265 wp->w_p_rl ? (col < 0) :
3266#endif
3267 (col >= wp->w_width))
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003268 && (draw_state != WL_LINE
3269 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003270#ifdef FEAT_DIFF
3271 || filler_todo > 0
3272#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003273#ifdef FEAT_PROP_POPUP
3274 || text_prop_follows
3275#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003276 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
3277 && p_extra != at_end_str)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003278 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL)))
3279 )
3280 {
3281#ifdef FEAT_CONCEAL
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01003282 screen_line(wp, screen_row, wp->w_wincol, col - boguscols,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00003283 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003284 boguscols = 0;
3285#else
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01003286 screen_line(wp, screen_row, wp->w_wincol, col,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00003287 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003288#endif
3289 ++row;
3290 ++screen_row;
3291
3292 // When not wrapping and finished diff lines, or when displayed
3293 // '$' and highlighting until last column, break here.
3294 if ((!wp->w_p_wrap
3295#ifdef FEAT_DIFF
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003296 && filler_todo <= 0
3297#endif
3298#ifdef FEAT_PROP_POPUP
3299 && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003300#endif
3301 ) || lcs_eol_one == -1)
3302 break;
3303
3304 // When the window is too narrow draw all "@" lines.
3305 if (draw_state != WL_LINE
3306#ifdef FEAT_DIFF
3307 && filler_todo <= 0
3308#endif
3309 )
3310 {
3311 win_draw_end(wp, '@', ' ', TRUE, row, wp->w_height, HLF_AT);
3312 draw_vsep_win(wp, row);
3313 row = endrow;
3314 }
3315
3316 // When line got too long for screen break here.
3317 if (row == endrow)
3318 {
3319 ++row;
3320 break;
3321 }
3322
3323 if (screen_cur_row == screen_row - 1
3324#ifdef FEAT_DIFF
3325 && filler_todo <= 0
3326#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003327#ifdef FEAT_PROP_POPUP
3328 && !text_prop_follows
3329#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003330 && wp->w_width == Columns)
3331 {
3332 // Remember that the line wraps, used for modeless copy.
3333 LineWraps[screen_row - 1] = TRUE;
3334
3335 // Special trick to make copy/paste of wrapped lines work with
3336 // xterm/screen: write an extra character beyond the end of
3337 // the line. This will work with all terminal types
3338 // (regardless of the xn,am settings).
3339 // Only do this on a fast tty.
3340 // Only do this if the cursor is on the current line
3341 // (something has been written in it).
3342 // Don't do this for the GUI.
3343 // Don't do this for double-width characters.
3344 // Don't do this for a window not at the right screen border.
3345 if (p_tf
3346#ifdef FEAT_GUI
3347 && !gui.in_use
3348#endif
3349 && !(has_mbyte
3350 && ((*mb_off2cells)(LineOffset[screen_row],
3351 LineOffset[screen_row] + screen_Columns)
3352 == 2
3353 || (*mb_off2cells)(LineOffset[screen_row - 1]
3354 + (int)Columns - 2,
3355 LineOffset[screen_row] + screen_Columns)
3356 == 2)))
3357 {
3358 // First make sure we are at the end of the screen line,
3359 // then output the same character again to let the
3360 // terminal know about the wrap. If the terminal doesn't
3361 // auto-wrap, we overwrite the character.
3362 if (screen_cur_col != wp->w_width)
3363 screen_char(LineOffset[screen_row - 1]
3364 + (unsigned)Columns - 1,
3365 screen_row - 1, (int)(Columns - 1));
3366
3367 // When there is a multi-byte character, just output a
3368 // space to keep it simple.
3369 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
3370 screen_row - 1] + (Columns - 1)]) > 1)
3371 out_char(' ');
3372 else
3373 out_char(ScreenLines[LineOffset[screen_row - 1]
3374 + (Columns - 1)]);
3375 // force a redraw of the first char on the next line
3376 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1;
3377 screen_start(); // don't know where cursor is now
3378 }
3379 }
3380
3381 col = 0;
3382 off = (unsigned)(current_ScreenLine - ScreenLines);
3383#ifdef FEAT_RIGHTLEFT
3384 if (wp->w_p_rl)
3385 {
3386 col = wp->w_width - 1; // col is not used if breaking!
3387 off += col;
3388 }
3389#endif
3390
3391 // reset the drawing state for the start of a wrapped line
3392 draw_state = WL_START;
3393 saved_n_extra = n_extra;
3394 saved_p_extra = p_extra;
3395 saved_c_extra = c_extra;
3396 saved_c_final = c_final;
3397#ifdef FEAT_SYN_HL
3398 if (!(cul_screenline
3399# ifdef FEAT_DIFF
Bram Moolenaare7705982020-04-21 22:23:15 +02003400 && diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003401# endif
Bram Moolenaare7705982020-04-21 22:23:15 +02003402 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003403 saved_char_attr = char_attr;
3404 else
3405#endif
3406 saved_char_attr = 0;
3407 n_extra = 0;
Bram Moolenaareed9d462021-02-15 20:38:25 +01003408 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003409#ifdef FEAT_LINEBREAK
3410# ifdef FEAT_DIFF
3411 if (filler_todo <= 0)
3412# endif
3413 need_showbreak = TRUE;
3414#endif
3415#ifdef FEAT_DIFF
3416 --filler_todo;
3417 // When the filler lines are actually below the last line of the
3418 // file, don't draw the line itself, break here.
3419 if (filler_todo == 0 && wp->w_botfill)
3420 break;
3421#endif
3422 }
3423
3424 } // for every character in the line
3425
3426#ifdef FEAT_SPELL
3427 // After an empty line check first word for capital.
3428 if (*skipwhite(line) == NUL)
3429 {
3430 capcol_lnum = lnum + 1;
3431 cap_col = 0;
3432 }
3433#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003434#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003435 vim_free(text_props);
3436 vim_free(text_prop_idxs);
3437#endif
3438
3439 vim_free(p_extra_free);
3440 return row;
3441}