blob: 4630bf03bab04e05723561324a9443dfc3084db7 [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
Bram Moolenaar09ff4b52022-08-01 16:51:02 +0100282 int n_extra = 0; // number of extra bytes
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200283 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;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001563 n_attr = mb_charlen(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001564 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
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001576 if (right)
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001577 added -= vim_strsize(p_extra);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001578 if (added < 0 || (below && col == 0))
1579 added = 0;
1580 l = alloc(n_extra + added + 1);
1581 if (l != NULL)
1582 {
1583 vim_memset(l, ' ', added);
1584 STRCPY(l + added, p);
1585 vim_free(p_extra_free);
1586 p_extra = p_extra_free = l;
1587 n_extra += added;
1588 n_attr_skip = added;
1589 }
1590 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001591 }
1592 // reset the ID in the copy to avoid it being used
1593 // again
1594 text_props[used_tpi].tp_id = -MAXCOL;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001595
1596 // If another text prop follows the condition below at
1597 // the last window column must know.
1598 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001599 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001600 }
1601 }
1602#endif
1603
Bram Moolenaara74fda62019-10-19 17:38:03 +02001604#ifdef FEAT_SYN_HL
Bram Moolenaara74fda62019-10-19 17:38:03 +02001605 if (extra_check && n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001606 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001607 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001608# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001609 if (get_term_attr)
Bram Moolenaar219c7d02020-02-01 21:57:29 +01001610 syntax_attr = term_get_attr(wp, lnum, vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001611# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001612 // Get syntax attribute.
1613 if (has_syntax)
1614 {
1615 // Get the syntax attribute for the character. If there
1616 // is an error, disable syntax highlighting.
1617 save_did_emsg = did_emsg;
1618 did_emsg = FALSE;
1619
1620 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001621 if (v == prev_syntax_col)
1622 // at same column again
1623 syntax_attr = prev_syntax_attr;
1624 else
1625 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001626# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001627 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001628# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001629 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001630# ifdef FEAT_SPELL
1631 has_spell ? &can_spell :
1632# endif
1633 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001634 prev_syntax_col = v;
1635 prev_syntax_attr = syntax_attr;
1636 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001637
Bram Moolenaar34390282019-10-16 14:38:26 +02001638 if (did_emsg)
1639 {
1640 wp->w_s->b_syn_error = TRUE;
1641 has_syntax = FALSE;
1642 syntax_attr = 0;
1643 }
1644 else
1645 did_emsg = save_did_emsg;
1646# ifdef SYN_TIME_LIMIT
1647 if (wp->w_s->b_syn_slow)
1648 has_syntax = FALSE;
1649# endif
1650
1651 // Need to get the line again, a multi-line regexp may
1652 // have made it invalid.
1653 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1654 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001655 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001656# ifdef FEAT_CONCEAL
1657 // no concealing past the end of the line, it interferes
1658 // with line highlighting
1659 if (*ptr == NUL)
1660 syntax_flags = 0;
1661 else
1662 syntax_flags = get_syntax_info(&syntax_seqnr);
1663# endif
1664 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001665 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001666# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001667 // Combine text property highlight into syntax highlight.
1668 if (text_prop_type != NULL)
1669 {
1670 if (text_prop_combine)
1671 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1672 else
1673 syntax_attr = text_prop_attr;
1674 }
1675# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001676#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001677
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001678 // Decide which of the highlight attributes to use.
1679 attr_pri = TRUE;
1680#ifdef LINE_ATTR
1681 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001682 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001683 char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02001684 if (!highlight_match)
1685 // let search highlight show in Visual area if possible
1686 char_attr = hl_combine_attr(search_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001687# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001688 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001689# endif
1690 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001691 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001692 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001693 char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001694# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001695 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001696# endif
1697 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001698 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
1699 || vcol < fromcol || vcol_prev < fromcol_prev
1700 || vcol >= tocol))
1701 {
1702 // Use line_attr when not in the Visual or 'incsearch' area
1703 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001704# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001705 char_attr = hl_combine_attr(syntax_attr, line_attr);
1706# else
1707 char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001708# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001709 attr_pri = FALSE;
1710 }
1711#else
1712 if (area_attr != 0)
1713 char_attr = area_attr;
1714 else if (search_attr != 0)
1715 char_attr = search_attr;
1716#endif
1717 else
1718 {
1719 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001720#ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001721 char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001722#else
Bram Moolenaardbd43162019-11-09 21:28:14 +01001723 char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001724#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001725 }
1726 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001727
1728 // combine attribute with 'wincolor'
1729 if (win_attr != 0)
1730 {
1731 if (char_attr == 0)
1732 char_attr = win_attr;
1733 else
1734 char_attr = hl_combine_attr(win_attr, char_attr);
1735 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001736
1737 // Get the next character to put on the screen.
1738
1739 // The "p_extra" points to the extra stuff that is inserted to
1740 // represent special characters (non-printable stuff) and other
1741 // things. When all characters are the same, c_extra is used.
1742 // If c_final is set, it will compulsorily be used at the end.
1743 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
1744 // "p_extra[n_extra]".
1745 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
1746 if (n_extra > 0)
1747 {
1748 if (c_extra != NUL || (n_extra == 1 && c_final != NUL))
1749 {
1750 c = (n_extra == 1 && c_final != NUL) ? c_final : c_extra;
1751 mb_c = c; // doesn't handle non-utf-8 multi-byte!
1752 if (enc_utf8 && utf_char2len(c) > 1)
1753 {
1754 mb_utf8 = TRUE;
1755 u8cc[0] = 0;
1756 c = 0xc0;
1757 }
1758 else
1759 mb_utf8 = FALSE;
1760 }
1761 else
1762 {
1763 c = *p_extra;
1764 if (has_mbyte)
1765 {
1766 mb_c = c;
1767 if (enc_utf8)
1768 {
1769 // If the UTF-8 character is more than one byte:
1770 // Decode it into "mb_c".
1771 mb_l = utfc_ptr2len(p_extra);
1772 mb_utf8 = FALSE;
1773 if (mb_l > n_extra)
1774 mb_l = 1;
1775 else if (mb_l > 1)
1776 {
1777 mb_c = utfc_ptr2char(p_extra, u8cc);
1778 mb_utf8 = TRUE;
1779 c = 0xc0;
1780 }
1781 }
1782 else
1783 {
1784 // if this is a DBCS character, put it in "mb_c"
1785 mb_l = MB_BYTE2LEN(c);
1786 if (mb_l >= n_extra)
1787 mb_l = 1;
1788 else if (mb_l > 1)
1789 mb_c = (c << 8) + p_extra[1];
1790 }
1791 if (mb_l == 0) // at the NUL at end-of-line
1792 mb_l = 1;
1793
1794 // If a double-width char doesn't fit display a '>' in the
1795 // last column.
1796 if ((
1797# ifdef FEAT_RIGHTLEFT
1798 wp->w_p_rl ? (col <= 0) :
1799# endif
1800 (col >= wp->w_width - 1))
1801 && (*mb_char2cells)(mb_c) == 2)
1802 {
1803 c = '>';
1804 mb_c = c;
1805 mb_l = 1;
1806 mb_utf8 = FALSE;
1807 multi_attr = HL_ATTR(HLF_AT);
1808#ifdef FEAT_SYN_HL
1809 if (cul_attr)
1810 multi_attr = hl_combine_attr(multi_attr, cul_attr);
1811#endif
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001812 multi_attr = hl_combine_attr(win_attr, multi_attr);
1813
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001814 // put the pointer back to output the double-width
1815 // character at the start of the next line.
1816 ++n_extra;
1817 --p_extra;
1818 }
1819 else
1820 {
1821 n_extra -= mb_l - 1;
1822 p_extra += mb_l - 1;
1823 }
1824 }
1825 ++p_extra;
1826 }
1827 --n_extra;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001828#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001829 if (n_extra <= 0)
1830 in_linebreak = FALSE;
1831#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001832 }
1833 else
1834 {
1835#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01001836 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001837#endif
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001838 VIM_CLEAR(p_extra_free);
Bram Moolenaarb9081882022-07-09 04:56:24 +01001839 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001840
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001841 // Get a character from the line itself.
1842 c = *ptr;
1843#ifdef FEAT_LINEBREAK
1844 c0 = *ptr;
1845#endif
1846 if (has_mbyte)
1847 {
1848 mb_c = c;
1849 if (enc_utf8)
1850 {
1851 // If the UTF-8 character is more than one byte: Decode it
1852 // into "mb_c".
1853 mb_l = utfc_ptr2len(ptr);
1854 mb_utf8 = FALSE;
1855 if (mb_l > 1)
1856 {
1857 mb_c = utfc_ptr2char(ptr, u8cc);
1858 // Overlong encoded ASCII or ASCII with composing char
1859 // is displayed normally, except a NUL.
1860 if (mb_c < 0x80)
1861 {
1862 c = mb_c;
1863#ifdef FEAT_LINEBREAK
1864 c0 = mb_c;
1865#endif
1866 }
1867 mb_utf8 = TRUE;
1868
1869 // At start of the line we can have a composing char.
1870 // Draw it as a space with a composing char.
1871 if (utf_iscomposing(mb_c))
1872 {
1873 int i;
1874
1875 for (i = Screen_mco - 1; i > 0; --i)
1876 u8cc[i] = u8cc[i - 1];
1877 u8cc[0] = mb_c;
1878 mb_c = ' ';
1879 }
1880 }
1881
1882 if ((mb_l == 1 && c >= 0x80)
1883 || (mb_l >= 1 && mb_c == 0)
1884 || (mb_l > 1 && (!vim_isprintc(mb_c))))
1885 {
1886 // Illegal UTF-8 byte: display as <xx>.
1887 // Non-BMP character : display as ? or fullwidth ?.
1888 transchar_hex(extra, mb_c);
1889# ifdef FEAT_RIGHTLEFT
1890 if (wp->w_p_rl) // reverse
1891 rl_mirror(extra);
1892# endif
1893 p_extra = extra;
1894 c = *p_extra;
1895 mb_c = mb_ptr2char_adv(&p_extra);
1896 mb_utf8 = (c >= 0x80);
1897 n_extra = (int)STRLEN(p_extra);
1898 c_extra = NUL;
1899 c_final = NUL;
1900 if (area_attr == 0 && search_attr == 0)
1901 {
1902 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001903 extra_attr = hl_combine_attr(
1904 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001905 saved_attr2 = char_attr; // save current attr
1906 }
1907 }
1908 else if (mb_l == 0) // at the NUL at end-of-line
1909 mb_l = 1;
1910#ifdef FEAT_ARABIC
1911 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
1912 {
1913 // Do Arabic shaping.
1914 int pc, pc1, nc;
1915 int pcc[MAX_MCO];
1916
1917 // The idea of what is the previous and next
1918 // character depends on 'rightleft'.
1919 if (wp->w_p_rl)
1920 {
1921 pc = prev_c;
1922 pc1 = prev_c1;
1923 nc = utf_ptr2char(ptr + mb_l);
1924 prev_c1 = u8cc[0];
1925 }
1926 else
1927 {
1928 pc = utfc_ptr2char(ptr + mb_l, pcc);
1929 nc = prev_c;
1930 pc1 = pcc[0];
1931 }
1932 prev_c = mb_c;
1933
1934 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
1935 }
1936 else
1937 prev_c = mb_c;
1938#endif
1939 }
1940 else // enc_dbcs
1941 {
1942 mb_l = MB_BYTE2LEN(c);
1943 if (mb_l == 0) // at the NUL at end-of-line
1944 mb_l = 1;
1945 else if (mb_l > 1)
1946 {
1947 // We assume a second byte below 32 is illegal.
1948 // Hopefully this is OK for all double-byte encodings!
1949 if (ptr[1] >= 32)
1950 mb_c = (c << 8) + ptr[1];
1951 else
1952 {
1953 if (ptr[1] == NUL)
1954 {
1955 // head byte at end of line
1956 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02001957 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001958 }
1959 else
1960 {
1961 // illegal tail byte
1962 mb_l = 2;
1963 STRCPY(extra, "XX");
1964 }
1965 p_extra = extra;
1966 n_extra = (int)STRLEN(extra) - 1;
1967 c_extra = NUL;
1968 c_final = NUL;
1969 c = *p_extra++;
1970 if (area_attr == 0 && search_attr == 0)
1971 {
1972 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001973 extra_attr = hl_combine_attr(
1974 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001975 saved_attr2 = char_attr; // save current attr
1976 }
1977 mb_c = c;
1978 }
1979 }
1980 }
1981 // If a double-width char doesn't fit display a '>' in the
1982 // last column; the character is displayed at the start of the
1983 // next line.
1984 if ((
1985# ifdef FEAT_RIGHTLEFT
1986 wp->w_p_rl ? (col <= 0) :
1987# endif
1988 (col >= wp->w_width - 1))
1989 && (*mb_char2cells)(mb_c) == 2)
1990 {
1991 c = '>';
1992 mb_c = c;
1993 mb_utf8 = FALSE;
1994 mb_l = 1;
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001995 multi_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001996 // Put pointer back so that the character will be
1997 // displayed at the start of the next line.
1998 --ptr;
1999#ifdef FEAT_CONCEAL
2000 did_decrement_ptr = TRUE;
2001#endif
2002 }
2003 else if (*ptr != NUL)
2004 ptr += mb_l - 1;
2005
2006 // If a double-width char doesn't fit at the left side display
2007 // a '<' in the first column. Don't do this for unprintable
2008 // characters.
2009 if (n_skip > 0 && mb_l > 1 && n_extra == 0)
2010 {
2011 n_extra = 1;
2012 c_extra = MB_FILLER_CHAR;
2013 c_final = NUL;
2014 c = ' ';
2015 if (area_attr == 0 && search_attr == 0)
2016 {
2017 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002018 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002019 saved_attr2 = char_attr; // save current attr
2020 }
2021 mb_c = c;
2022 mb_utf8 = FALSE;
2023 mb_l = 1;
2024 }
2025
2026 }
2027 ++ptr;
2028
2029 if (extra_check)
2030 {
2031#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002032 // Check spelling (unless at the end of the line).
2033 // Only do this when there is no syntax highlighting, the
2034 // @Spell cluster is not used or the current syntax item
2035 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002036 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002037 if (has_spell && v >= word_end && v > cur_checked_col)
2038 {
2039 spell_attr = 0;
2040 if (c != 0 && (
2041# ifdef FEAT_SYN_HL
2042 !has_syntax ||
2043# endif
2044 can_spell))
2045 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002046 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002047 int len;
2048 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002049
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002050 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002051 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002052
2053 // Use nextline[] if possible, it has the start of the
2054 // next line concatenated.
2055 if ((prev_ptr - line) - nextlinecol >= 0)
2056 p = nextline + (prev_ptr - line) - nextlinecol;
2057 else
2058 p = prev_ptr;
2059 cap_col -= (int)(prev_ptr - line);
2060 len = spell_check(wp, p, &spell_hlf, &cap_col,
2061 nochange);
2062 word_end = v + len;
2063
2064 // In Insert mode only highlight a word that
2065 // doesn't touch the cursor.
2066 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002067 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002068 && wp->w_cursor.lnum == lnum
2069 && wp->w_cursor.col >=
2070 (colnr_T)(prev_ptr - line)
2071 && wp->w_cursor.col < (colnr_T)word_end)
2072 {
2073 spell_hlf = HLF_COUNT;
2074 spell_redraw_lnum = lnum;
2075 }
2076
2077 if (spell_hlf == HLF_COUNT && p != prev_ptr
2078 && (p - nextline) + len > nextline_idx)
2079 {
2080 // Remember that the good word continues at the
2081 // start of the next line.
2082 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002083 checked_col = (int)((p - nextline)
2084 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002085 }
2086
2087 // Turn index into actual attributes.
2088 if (spell_hlf != HLF_COUNT)
2089 spell_attr = highlight_attr[spell_hlf];
2090
2091 if (cap_col > 0)
2092 {
2093 if (p != prev_ptr
2094 && (p - nextline) + cap_col >= nextline_idx)
2095 {
2096 // Remember that the word in the next line
2097 // must start with a capital.
2098 capcol_lnum = lnum + 1;
2099 cap_col = (int)((p - nextline) + cap_col
2100 - nextline_idx);
2101 }
2102 else
2103 // Compute the actual column.
2104 cap_col += (int)(prev_ptr - line);
2105 }
2106 }
2107 }
2108 if (spell_attr != 0)
2109 {
2110 if (!attr_pri)
2111 char_attr = hl_combine_attr(char_attr, spell_attr);
2112 else
2113 char_attr = hl_combine_attr(spell_attr, char_attr);
2114 }
2115#endif
2116#ifdef FEAT_LINEBREAK
2117 // Found last space before word: check for line break.
2118 if (wp->w_p_lbr && c0 == c
2119 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2120 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002121 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2122 : 0;
2123 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002124 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002125
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002126 init_chartabsize_arg(&cts, wp, lnum, vcol, line, p);
2127 n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002128
2129 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002130 // space for it again.
Bram Moolenaara06e3452021-05-29 17:56:37 +02002131 if (vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002132 {
Bram Moolenaara06e3452021-05-29 17:56:37 +02002133 n_extra -= MB_CHARLEN(get_showbreak_value(wp));
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002134 if (n_extra < 0)
2135 n_extra = 0;
2136 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002137 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002138 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002139 // line break, but for TABs the highlighting should
2140 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002141 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002142
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002143 if (c == TAB && n_extra + col > wp->w_width)
2144# ifdef FEAT_VARTABS
2145 n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts,
2146 wp->w_buffer->b_p_vts_array) - 1;
2147# else
2148 n_extra = (int)wp->w_buffer->b_p_ts
2149 - vcol % (int)wp->w_buffer->b_p_ts - 1;
2150# endif
2151
2152 c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2153 c_final = NUL;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002154# if defined(FEAT_PROP_POPUP)
Bram Moolenaar42eba042021-11-30 20:22:49 +00002155 if (n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002156 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002157# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002158 if (VIM_ISWHITE(c))
2159 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002160# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002161 if (c == TAB)
2162 // See "Tab alignment" below.
2163 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002164# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002165 if (!wp->w_p_list)
2166 c = ' ';
2167 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002168 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002169 }
2170#endif
2171
zeertzjqf14b8ba2021-09-10 16:58:30 +02002172 in_multispace = c == ' '
2173 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2174 if (!in_multispace)
2175 multispace_pos = 0;
2176
Bram Moolenaareed9d462021-02-15 20:38:25 +01002177 // 'list': Change char 160 to 'nbsp' and space to 'space'
2178 // setting in 'listchars'. But not when the character is
2179 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002180 if (wp->w_p_list
2181 && ((((c == 160 && mb_l == 1)
2182 || (mb_utf8
2183 && ((mb_c == 160 && mb_l == 2)
2184 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002185 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002186 || (c == ' '
2187 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002188 && (wp->w_lcs_chars.space
2189 || (in_multispace
2190 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002191 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002192 && ptr - line <= trailcol)))
2193 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002194 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2195 {
2196 c = wp->w_lcs_chars.multispace[multispace_pos++];
2197 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2198 multispace_pos = 0;
2199 }
2200 else
2201 c = (c == ' ') ? wp->w_lcs_chars.space
2202 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002203 if (area_attr == 0 && search_attr == 0)
2204 {
2205 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002206 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002207 saved_attr2 = char_attr; // save current attr
2208 }
2209 mb_c = c;
2210 if (enc_utf8 && utf_char2len(c) > 1)
2211 {
2212 mb_utf8 = TRUE;
2213 u8cc[0] = 0;
2214 c = 0xc0;
2215 }
2216 else
2217 mb_utf8 = FALSE;
2218 }
2219
zeertzjq2e7cba32022-06-10 15:30:32 +01002220 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2221 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002222 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002223 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2224 && wp->w_lcs_chars.leadmultispace != NULL)
2225 {
2226 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002227 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2228 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002229 multispace_pos = 0;
2230 }
2231
2232 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2233 c = wp->w_lcs_chars.trail;
2234
2235 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2236 c = wp->w_lcs_chars.lead;
2237
zeertzjq2e7cba32022-06-10 15:30:32 +01002238 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002239 c = wp->w_lcs_chars.space;
2240
2241
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002242 if (!attr_pri)
2243 {
2244 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002245 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002246 saved_attr2 = char_attr; // save current attr
2247 }
2248 mb_c = c;
2249 if (enc_utf8 && utf_char2len(c) > 1)
2250 {
2251 mb_utf8 = TRUE;
2252 u8cc[0] = 0;
2253 c = 0xc0;
2254 }
2255 else
2256 mb_utf8 = FALSE;
2257 }
2258 }
2259
2260 // Handling of non-printable characters.
2261 if (!vim_isprintc(c))
2262 {
2263 // when getting a character from the file, we may have to
2264 // turn it into something else on the way to putting it
2265 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002266 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002267 {
2268 int tab_len = 0;
2269 long vcol_adjusted = vcol; // removed showbreak length
2270#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002271 char_u *sbr = get_showbreak_value(wp);
2272
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002273 // only adjust the tab_len, when at the first column
2274 // after the showbreak value was drawn
Bram Moolenaaree857022019-11-09 23:26:40 +01002275 if (*sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap)
2276 vcol_adjusted = vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002277#endif
2278 // tab amount depends on current column
2279#ifdef FEAT_VARTABS
2280 tab_len = tabstop_padding(vcol_adjusted,
2281 wp->w_buffer->b_p_ts,
2282 wp->w_buffer->b_p_vts_array) - 1;
2283#else
2284 tab_len = (int)wp->w_buffer->b_p_ts
2285 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2286#endif
2287
2288#ifdef FEAT_LINEBREAK
2289 if (!wp->w_p_lbr || !wp->w_p_list)
2290#endif
2291 // tab amount depends on current column
2292 n_extra = tab_len;
2293#ifdef FEAT_LINEBREAK
2294 else
2295 {
2296 char_u *p;
2297 int len;
2298 int i;
2299 int saved_nextra = n_extra;
2300
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002301# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002302 if (vcol_off > 0)
2303 // there are characters to conceal
2304 tab_len += vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002305
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002306 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002307 if (wp->w_p_list && wp->w_lcs_chars.tab1
2308 && old_boguscols > 0
2309 && n_extra > tab_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002310 tab_len += n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002311# endif
2312 // If n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002313 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002314 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002315 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002316 if (wp->w_lcs_chars.tab3)
2317 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002318 if (n_extra > 0)
2319 len += n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002320 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002321 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002322 if (p == NULL)
2323 n_extra = 0;
2324 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002325 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002326 vim_memset(p, ' ', len);
2327 p[len] = NUL;
2328 vim_free(p_extra_free);
2329 p_extra_free = p;
2330 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002331 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002332 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002333
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002334 if (*p == NUL)
2335 {
2336 tab_len = i;
2337 break;
2338 }
2339
2340 // if tab3 is given, use it for the last char
2341 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2342 lcs = wp->w_lcs_chars.tab3;
2343 p += mb_char2bytes(lcs, p);
2344 n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002345 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002346 }
2347 p_extra = p_extra_free;
2348# ifdef FEAT_CONCEAL
2349 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2350 // macro below, so need to adjust for that here
2351 if (vcol_off > 0)
2352 n_extra -= vcol_off;
2353# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002354 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002355 }
2356#endif
2357#ifdef FEAT_CONCEAL
2358 {
2359 int vc_saved = vcol_off;
2360
2361 // Tab alignment should be identical regardless of
2362 // 'conceallevel' value. So tab compensates of all
2363 // previous concealed characters, and thus resets
2364 // vcol_off and boguscols accumulated so far in the
2365 // line. Note that the tab can be longer than
2366 // 'tabstop' when there are concealed characters.
2367 FIX_FOR_BOGUSCOLS;
2368
2369 // Make sure, the highlighting for the tab char will be
2370 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002371 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002372 if (n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002373 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002374 tab_len += vc_saved;
2375 }
2376#endif
2377 mb_utf8 = FALSE; // don't draw as UTF-8
2378 if (wp->w_p_list)
2379 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002380 c = (n_extra == 0 && wp->w_lcs_chars.tab3)
2381 ? wp->w_lcs_chars.tab3
2382 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002383#ifdef FEAT_LINEBREAK
2384 if (wp->w_p_lbr)
2385 c_extra = NUL; // using p_extra from above
2386 else
2387#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01002388 c_extra = wp->w_lcs_chars.tab2;
2389 c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002390 n_attr = tab_len + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002391 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002392 saved_attr2 = char_attr; // save current attr
2393 mb_c = c;
2394 if (enc_utf8 && utf_char2len(c) > 1)
2395 {
2396 mb_utf8 = TRUE;
2397 u8cc[0] = 0;
2398 c = 0xc0;
2399 }
2400 }
2401 else
2402 {
2403 c_final = NUL;
2404 c_extra = ' ';
2405 c = ' ';
2406 }
2407 }
2408 else if (c == NUL
2409 && (wp->w_p_list
2410 || ((fromcol >= 0 || fromcol_prev >= 0)
2411 && tocol > vcol
2412 && VIsual_mode != Ctrl_V
2413 && (
2414# ifdef FEAT_RIGHTLEFT
2415 wp->w_p_rl ? (col >= 0) :
2416# endif
2417 (col < wp->w_width))
2418 && !(noinvcur
2419 && lnum == wp->w_cursor.lnum
2420 && (colnr_T)vcol == wp->w_virtcol)))
2421 && lcs_eol_one > 0)
2422 {
2423 // Display a '$' after the line or highlight an extra
2424 // character if the line break is included.
2425#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2426 // For a diff line the highlighting continues after the
2427 // "$".
2428 if (
2429# ifdef FEAT_DIFF
2430 diff_hlf == (hlf_T)0
2431# ifdef LINE_ATTR
2432 &&
2433# endif
2434# endif
2435# ifdef LINE_ATTR
2436 line_attr == 0
2437# endif
2438 )
2439#endif
2440 {
2441 // In virtualedit, visual selections may extend
2442 // beyond end of line.
2443 if (area_highlighting && virtual_active()
2444 && tocol != MAXCOL && vcol < tocol)
2445 n_extra = 0;
2446 else
2447 {
2448 p_extra = at_end_str;
2449 n_extra = 1;
2450 c_extra = NUL;
2451 c_final = NUL;
2452 }
2453 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002454 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2455 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002456 else
2457 c = ' ';
2458 lcs_eol_one = -1;
2459 --ptr; // put it back at the NUL
2460 if (!attr_pri)
2461 {
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002462 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002463 n_attr = 1;
2464 }
2465 mb_c = c;
2466 if (enc_utf8 && utf_char2len(c) > 1)
2467 {
2468 mb_utf8 = TRUE;
2469 u8cc[0] = 0;
2470 c = 0xc0;
2471 }
2472 else
2473 mb_utf8 = FALSE; // don't draw as UTF-8
2474 }
2475 else if (c != NUL)
2476 {
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002477 p_extra = transchar_buf(wp->w_buffer, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002478 if (n_extra == 0)
2479 n_extra = byte2cells(c) - 1;
2480#ifdef FEAT_RIGHTLEFT
2481 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
2482 rl_mirror(p_extra); // reverse "<12>"
2483#endif
2484 c_extra = NUL;
2485 c_final = NUL;
2486#ifdef FEAT_LINEBREAK
2487 if (wp->w_p_lbr)
2488 {
2489 char_u *p;
2490
2491 c = *p_extra;
2492 p = alloc(n_extra + 1);
2493 vim_memset(p, ' ', n_extra);
2494 STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1);
2495 p[n_extra] = NUL;
2496 vim_free(p_extra_free);
2497 p_extra_free = p_extra = p;
2498 }
2499 else
2500#endif
2501 {
2502 n_extra = byte2cells(c) - 1;
2503 c = *p_extra++;
2504 }
2505 if (!attr_pri)
2506 {
2507 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002508 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002509 saved_attr2 = char_attr; // save current attr
2510 }
2511 mb_utf8 = FALSE; // don't draw as UTF-8
2512 }
2513 else if (VIsual_active
2514 && (VIsual_mode == Ctrl_V
2515 || VIsual_mode == 'v')
2516 && virtual_active()
2517 && tocol != MAXCOL
2518 && vcol < tocol
2519 && (
2520#ifdef FEAT_RIGHTLEFT
2521 wp->w_p_rl ? (col >= 0) :
2522#endif
2523 (col < wp->w_width)))
2524 {
2525 c = ' ';
2526 --ptr; // put it back at the NUL
2527 }
2528#if defined(LINE_ATTR)
2529 else if ((
2530# ifdef FEAT_DIFF
2531 diff_hlf != (hlf_T)0 ||
2532# endif
2533# ifdef FEAT_TERMINAL
2534 win_attr != 0 ||
2535# endif
2536 line_attr != 0
2537 ) && (
2538# ifdef FEAT_RIGHTLEFT
2539 wp->w_p_rl ? (col >= 0) :
2540# endif
2541 (col
2542# ifdef FEAT_CONCEAL
2543 - boguscols
2544# endif
2545 < wp->w_width)))
2546 {
2547 // Highlight until the right side of the window
2548 c = ' ';
2549 --ptr; // put it back at the NUL
2550
2551 // Remember we do the char for line highlighting.
2552 ++did_line_attr;
2553
2554 // don't do search HL for the rest of the line
2555 if (line_attr != 0 && char_attr == search_attr
2556 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002557 || (wp->w_p_list &&
2558 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002559 char_attr = line_attr;
2560# ifdef FEAT_DIFF
2561 if (diff_hlf == HLF_TXD)
2562 {
2563 diff_hlf = HLF_CHD;
2564 if (vi_attr == 0 || char_attr != vi_attr)
2565 {
2566 char_attr = HL_ATTR(diff_hlf);
2567 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2568 && wp->w_p_culopt_flags != CULOPT_NBR
2569 && (!cul_screenline
2570 || (vcol >= left_curline_col
2571 && vcol <= right_curline_col)))
2572 char_attr = hl_combine_attr(
2573 char_attr, HL_ATTR(HLF_CUL));
2574 }
2575 }
2576# endif
2577# ifdef FEAT_TERMINAL
2578 if (win_attr != 0)
2579 {
2580 char_attr = win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002581 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2582 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002583 {
2584 if (!cul_screenline || (vcol >= left_curline_col
2585 && vcol <= right_curline_col))
2586 char_attr = hl_combine_attr(
2587 char_attr, HL_ATTR(HLF_CUL));
2588 }
2589 else if (line_attr)
2590 char_attr = hl_combine_attr(char_attr, line_attr);
2591 }
2592# endif
2593 }
2594#endif
2595 }
2596
2597#ifdef FEAT_CONCEAL
2598 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01002599 && (wp != curwin || lnum != wp->w_cursor.lnum
2600 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002601 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2602 && !(lnum_in_visual_area
2603 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2604 {
2605 char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01002606 if (((prev_syntax_id != syntax_seqnr
2607 && (syntax_flags & HL_CONCEAL) != 0)
2608 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002609 && (syn_get_sub_char() != NUL
2610 || (has_match_conc && match_conc)
2611 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002612 && wp->w_p_cole != 3)
2613 {
2614 // First time at this concealed item: display one
2615 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002616 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002617 c = match_conc;
2618 else if (syn_get_sub_char() != NUL)
2619 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01002620 else if (wp->w_lcs_chars.conceal != NUL)
2621 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002622 else
2623 c = ' ';
2624
2625 prev_syntax_id = syntax_seqnr;
2626
2627 if (n_extra > 0)
2628 vcol_off += n_extra;
2629 vcol += n_extra;
2630 if (wp->w_p_wrap && n_extra > 0)
2631 {
2632# ifdef FEAT_RIGHTLEFT
2633 if (wp->w_p_rl)
2634 {
2635 col -= n_extra;
2636 boguscols -= n_extra;
2637 }
2638 else
2639# endif
2640 {
2641 boguscols += n_extra;
2642 col += n_extra;
2643 }
2644 }
2645 n_extra = 0;
2646 n_attr = 0;
2647 }
2648 else if (n_skip == 0)
2649 {
2650 is_concealing = TRUE;
2651 n_skip = 1;
2652 }
2653 mb_c = c;
2654 if (enc_utf8 && utf_char2len(c) > 1)
2655 {
2656 mb_utf8 = TRUE;
2657 u8cc[0] = 0;
2658 c = 0xc0;
2659 }
2660 else
2661 mb_utf8 = FALSE; // don't draw as UTF-8
2662 }
2663 else
2664 {
2665 prev_syntax_id = 0;
2666 is_concealing = FALSE;
2667 }
2668
2669 if (n_skip > 0 && did_decrement_ptr)
2670 // not showing the '>', put pointer back to avoid getting stuck
2671 ++ptr;
2672
2673#endif // FEAT_CONCEAL
2674 }
2675
2676#ifdef FEAT_CONCEAL
2677 // In the cursor line and we may be concealing characters: correct
2678 // the cursor column when we reach its position.
2679 if (!did_wcol && draw_state == WL_LINE
2680 && wp == curwin && lnum == wp->w_cursor.lnum
2681 && conceal_cursor_line(wp)
2682 && (int)wp->w_virtcol <= vcol + n_skip)
2683 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002684# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002685 if (wp->w_p_rl)
2686 wp->w_wcol = wp->w_width - col + boguscols - 1;
2687 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002688# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002689 wp->w_wcol = col - boguscols;
2690 wp->w_wrow = row;
2691 did_wcol = TRUE;
2692 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002693# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01002694 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002695# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002696 }
2697#endif
2698
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002699 // Use "extra_attr", but don't override visual selection highlighting.
2700 // Don't use "extra_attr" until n_attr_skip is zero.
2701 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002702 && draw_state == WL_LINE
2703 && !attr_pri)
2704 {
2705#ifdef LINE_ATTR
2706 if (line_attr)
2707 char_attr = hl_combine_attr(extra_attr, line_attr);
2708 else
2709#endif
2710 char_attr = extra_attr;
2711 }
2712
2713#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2714 // XIM don't send preedit_start and preedit_end, but they send
2715 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
2716 // im_is_preediting() here.
2717 if (p_imst == IM_ON_THE_SPOT
2718 && xic != NULL
2719 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01002720 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002721 && !p_imdisable
2722 && im_is_preediting()
2723 && draw_state == WL_LINE)
2724 {
2725 colnr_T tcol;
2726
2727 if (preedit_end_col == MAXCOL)
2728 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
2729 else
2730 tcol = preedit_end_col;
2731 if ((long)preedit_start_col <= vcol && vcol < (long)tcol)
2732 {
2733 if (feedback_old_attr < 0)
2734 {
2735 feedback_col = 0;
2736 feedback_old_attr = char_attr;
2737 }
2738 char_attr = im_get_feedback_attr(feedback_col);
2739 if (char_attr < 0)
2740 char_attr = feedback_old_attr;
2741 feedback_col++;
2742 }
2743 else if (feedback_old_attr >= 0)
2744 {
2745 char_attr = feedback_old_attr;
2746 feedback_old_attr = -1;
2747 feedback_col = 0;
2748 }
2749 }
2750#endif
2751 // Handle the case where we are in column 0 but not on the first
2752 // character of the line and the user wants us to show us a
2753 // special character (via 'listchars' option "precedes:<char>".
2754 if (lcs_prec_todo != NUL
2755 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02002756 && (wp->w_p_wrap ?
2757 (wp->w_skipcol > 0 && row == 0) :
2758 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002759#ifdef FEAT_DIFF
2760 && filler_todo <= 0
2761#endif
2762 && draw_state > WL_NR
2763 && c != NUL)
2764 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002765 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002766 lcs_prec_todo = NUL;
2767 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2768 {
2769 // Double-width character being overwritten by the "precedes"
2770 // character, need to fill up half the character.
2771 c_extra = MB_FILLER_CHAR;
2772 c_final = NUL;
2773 n_extra = 1;
2774 n_attr = 2;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002775 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002776 }
2777 mb_c = c;
2778 if (enc_utf8 && utf_char2len(c) > 1)
2779 {
2780 mb_utf8 = TRUE;
2781 u8cc[0] = 0;
2782 c = 0xc0;
2783 }
2784 else
2785 mb_utf8 = FALSE; // don't draw as UTF-8
2786 if (!attr_pri)
2787 {
2788 saved_attr3 = char_attr; // save current attr
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002789 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002790 n_attr3 = 1;
2791 }
2792 }
2793
2794 // At end of the text line or just after the last character.
2795 if ((c == NUL
2796#if defined(LINE_ATTR)
2797 || did_line_attr == 1
2798#endif
2799 ) && eol_hl_off == 0)
2800 {
2801#ifdef FEAT_SEARCH_EXTRA
2802 // flag to indicate whether prevcol equals startcol of search_hl or
2803 // one of the matches
2804 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
2805 (long)(ptr - line) - (c == NUL));
2806#endif
2807 // Invert at least one char, used for Visual and empty line or
2808 // highlight match at end of line. If it's beyond the last
2809 // char on the screen, just overwrite that one (tricky!) Not
2810 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002811 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002812 && ((area_attr != 0 && vcol == fromcol
2813 && (VIsual_mode != Ctrl_V
2814 || lnum == VIsual.lnum
2815 || lnum == curwin->w_cursor.lnum)
2816 && c == NUL)
2817#ifdef FEAT_SEARCH_EXTRA
2818 // highlight 'hlsearch' match at end of line
2819 || (prevcol_hl_flag
2820# ifdef FEAT_SYN_HL
2821 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
2822 && !(wp == curwin && VIsual_active))
2823# endif
2824# ifdef FEAT_DIFF
2825 && diff_hlf == (hlf_T)0
2826# endif
2827# if defined(LINE_ATTR)
2828 && did_line_attr <= 1
2829# endif
2830 )
2831#endif
2832 ))
2833 {
2834 int n = 0;
2835
2836#ifdef FEAT_RIGHTLEFT
2837 if (wp->w_p_rl)
2838 {
2839 if (col < 0)
2840 n = 1;
2841 }
2842 else
2843#endif
2844 {
2845 if (col >= wp->w_width)
2846 n = -1;
2847 }
2848 if (n != 0)
2849 {
2850 // At the window boundary, highlight the last character
2851 // instead (better than nothing).
2852 off += n;
2853 col += n;
2854 }
2855 else
2856 {
2857 // Add a blank character to highlight.
2858 ScreenLines[off] = ' ';
2859 if (enc_utf8)
2860 ScreenLinesUC[off] = 0;
2861 }
2862#ifdef FEAT_SEARCH_EXTRA
2863 if (area_attr == 0)
2864 {
2865 // Use attributes from match with highest priority among
2866 // 'search_hl' and the match list.
2867 get_search_match_hl(wp, &screen_search_hl,
2868 (long)(ptr - line), &char_attr);
2869 }
2870#endif
2871 ScreenAttrs[off] = char_attr;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002872 ScreenCols[off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002873#ifdef FEAT_RIGHTLEFT
2874 if (wp->w_p_rl)
2875 {
2876 --col;
2877 --off;
2878 }
2879 else
2880#endif
2881 {
2882 ++col;
2883 ++off;
2884 }
2885 ++vcol;
2886 eol_hl_off = 1;
2887 }
2888 }
2889
2890 // At end of the text line.
2891 if (c == NUL)
2892 {
2893#ifdef FEAT_SYN_HL
2894 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
2895 if (wp->w_p_wrap)
2896 v = wp->w_skipcol;
2897 else
2898 v = wp->w_leftcol;
2899
2900 // check if line ends before left margin
2901 if (vcol < v + col - win_col_off(wp))
2902 vcol = v + col - win_col_off(wp);
2903#ifdef FEAT_CONCEAL
2904 // Get rid of the boguscols now, we want to draw until the right
2905 // edge for 'cursorcolumn'.
2906 col -= boguscols;
2907 boguscols = 0;
2908#endif
2909
2910 if (draw_color_col)
2911 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2912
2913 if (((wp->w_p_cuc
2914 && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off
2915 && (int)wp->w_virtcol <
=?UTF-8?q?Dundar=20G=C3=B6c?=d5cec1f2022-01-29 15:19:23 +00002916 (long)wp->w_width * (row - startrow + 1) + v
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002917 && lnum != wp->w_cursor.lnum)
2918 || draw_color_col
2919 || win_attr != 0)
2920# ifdef FEAT_RIGHTLEFT
2921 && !wp->w_p_rl
2922# endif
2923 )
2924 {
2925 int rightmost_vcol = 0;
2926 int i;
2927
2928 if (wp->w_p_cuc)
2929 rightmost_vcol = wp->w_virtcol;
2930 if (draw_color_col)
2931 // determine rightmost colorcolumn to possibly draw
2932 for (i = 0; color_cols[i] >= 0; ++i)
2933 if (rightmost_vcol < color_cols[i])
2934 rightmost_vcol = color_cols[i];
2935
2936 while (col < wp->w_width)
2937 {
2938 ScreenLines[off] = ' ';
2939 if (enc_utf8)
2940 ScreenLinesUC[off] = 0;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002941 ScreenCols[off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002942 ++col;
2943 if (draw_color_col)
2944 draw_color_col = advance_color_col(VCOL_HLC,
2945 &color_cols);
2946
2947 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
2948 ScreenAttrs[off++] = HL_ATTR(HLF_CUC);
2949 else if (draw_color_col && VCOL_HLC == *color_cols)
2950 ScreenAttrs[off++] = HL_ATTR(HLF_MC);
2951 else
2952 ScreenAttrs[off++] = win_attr;
2953
2954 if (VCOL_HLC >= rightmost_vcol && win_attr == 0)
2955 break;
2956
2957 ++vcol;
2958 }
2959 }
2960#endif
2961
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01002962 screen_line(wp, screen_row, wp->w_wincol, col,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00002963 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002964 row++;
2965
2966 // Update w_cline_height and w_cline_folded if the cursor line was
2967 // updated (saves a call to plines() later).
2968 if (wp == curwin && lnum == curwin->w_cursor.lnum)
2969 {
2970 curwin->w_cline_row = startrow;
2971 curwin->w_cline_height = row - startrow;
2972#ifdef FEAT_FOLDING
2973 curwin->w_cline_folded = FALSE;
2974#endif
2975 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
2976 }
2977
2978 break;
2979 }
2980
2981 // Show "extends" character from 'listchars' if beyond the line end and
2982 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002983 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar41fb7232021-07-08 12:40:05 +02002984 && draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002985 && wp->w_p_list
2986 && !wp->w_p_wrap
2987#ifdef FEAT_DIFF
2988 && filler_todo <= 0
2989#endif
2990 && (
2991#ifdef FEAT_RIGHTLEFT
2992 wp->w_p_rl ? col == 0 :
2993#endif
2994 col == wp->w_width - 1)
2995 && (*ptr != NUL
2996 || (wp->w_p_list && lcs_eol_one > 0)
2997 || (n_extra && (c_extra != NUL || *p_extra != NUL))))
2998 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002999 c = wp->w_lcs_chars.ext;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01003000 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003001 mb_c = c;
3002 if (enc_utf8 && utf_char2len(c) > 1)
3003 {
3004 mb_utf8 = TRUE;
3005 u8cc[0] = 0;
3006 c = 0xc0;
3007 }
3008 else
3009 mb_utf8 = FALSE;
3010 }
3011
3012#ifdef FEAT_SYN_HL
3013 // advance to the next 'colorcolumn'
3014 if (draw_color_col)
3015 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
3016
3017 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3018 // highlight the cursor position itself.
3019 // Also highlight the 'colorcolumn' if it is different than
3020 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003021 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3022 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003023 vcol_save_attr = -1;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003024 if (((draw_state == WL_LINE ||
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003025 draw_state == WL_BRI ||
3026 draw_state == WL_SBR) && !lnum_in_visual_area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003027 && search_attr == 0 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003028# ifdef FEAT_DIFF
3029 && filler_todo <= 0
3030# endif
3031 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003032 {
3033 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3034 && lnum != wp->w_cursor.lnum)
3035 {
3036 vcol_save_attr = char_attr;
3037 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUC));
3038 }
3039 else if (draw_color_col && VCOL_HLC == *color_cols)
3040 {
3041 vcol_save_attr = char_attr;
3042 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_MC));
3043 }
3044 }
3045#endif
3046
3047 // Store character to be displayed.
3048 // Skip characters that are left of the screen for 'nowrap'.
3049 vcol_prev = vcol;
3050 if (draw_state < WL_LINE || n_skip <= 0)
3051 {
3052 // Store the character.
3053#if defined(FEAT_RIGHTLEFT)
3054 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3055 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003056 // A double-wide character is: put first half in left cell.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003057 --off;
3058 --col;
3059 }
3060#endif
3061 ScreenLines[off] = c;
3062 if (enc_dbcs == DBCS_JPNU)
3063 {
3064 if ((mb_c & 0xff00) == 0x8e00)
3065 ScreenLines[off] = 0x8e;
3066 ScreenLines2[off] = mb_c & 0xff;
3067 }
3068 else if (enc_utf8)
3069 {
3070 if (mb_utf8)
3071 {
3072 int i;
3073
3074 ScreenLinesUC[off] = mb_c;
3075 if ((c & 0xff) == 0)
3076 ScreenLines[off] = 0x80; // avoid storing zero
3077 for (i = 0; i < Screen_mco; ++i)
3078 {
3079 ScreenLinesC[i][off] = u8cc[i];
3080 if (u8cc[i] == 0)
3081 break;
3082 }
3083 }
3084 else
3085 ScreenLinesUC[off] = 0;
3086 }
3087 if (multi_attr)
3088 {
3089 ScreenAttrs[off] = multi_attr;
3090 multi_attr = 0;
3091 }
3092 else
3093 ScreenAttrs[off] = char_attr;
3094
Bram Moolenaarb9081882022-07-09 04:56:24 +01003095 ScreenCols[off] = (colnr_T)(prev_ptr - line);
3096
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003097 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3098 {
3099 // Need to fill two screen columns.
3100 ++off;
3101 ++col;
3102 if (enc_utf8)
3103 // UTF-8: Put a 0 in the second screen char.
3104 ScreenLines[off] = 0;
3105 else
3106 // DBCS: Put second byte in the second screen char.
3107 ScreenLines[off] = mb_c & 0xff;
3108 if (draw_state > WL_NR
3109#ifdef FEAT_DIFF
3110 && filler_todo <= 0
3111#endif
3112 )
3113 ++vcol;
3114 // When "tocol" is halfway a character, set it to the end of
3115 // the character, otherwise highlighting won't stop.
3116 if (tocol == vcol)
3117 ++tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003118
3119 ScreenCols[off] = (colnr_T)(prev_ptr - line);
3120
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003121#ifdef FEAT_RIGHTLEFT
3122 if (wp->w_p_rl)
3123 {
3124 // now it's time to backup one cell
3125 --off;
3126 --col;
3127 }
3128#endif
3129 }
3130#ifdef FEAT_RIGHTLEFT
3131 if (wp->w_p_rl)
3132 {
3133 --off;
3134 --col;
3135 }
3136 else
3137#endif
3138 {
3139 ++off;
3140 ++col;
3141 }
3142 }
3143#ifdef FEAT_CONCEAL
3144 else if (wp->w_p_cole > 0 && is_concealing)
3145 {
3146 --n_skip;
3147 ++vcol_off;
3148 if (n_extra > 0)
3149 vcol_off += n_extra;
3150 if (wp->w_p_wrap)
3151 {
3152 // Special voodoo required if 'wrap' is on.
3153 //
3154 // Advance the column indicator to force the line
3155 // drawing to wrap early. This will make the line
3156 // take up the same screen space when parts are concealed,
3157 // so that cursor line computations aren't messed up.
3158 //
3159 // To avoid the fictitious advance of 'col' causing
3160 // trailing junk to be written out of the screen line
3161 // we are building, 'boguscols' keeps track of the number
3162 // of bad columns we have advanced.
3163 if (n_extra > 0)
3164 {
3165 vcol += n_extra;
3166# ifdef FEAT_RIGHTLEFT
3167 if (wp->w_p_rl)
3168 {
3169 col -= n_extra;
3170 boguscols -= n_extra;
3171 }
3172 else
3173# endif
3174 {
3175 col += n_extra;
3176 boguscols += n_extra;
3177 }
3178 n_extra = 0;
3179 n_attr = 0;
3180 }
3181
3182
3183 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3184 {
3185 // Need to fill two screen columns.
3186# ifdef FEAT_RIGHTLEFT
3187 if (wp->w_p_rl)
3188 {
3189 --boguscols;
3190 --col;
3191 }
3192 else
3193# endif
3194 {
3195 ++boguscols;
3196 ++col;
3197 }
3198 }
3199
3200# ifdef FEAT_RIGHTLEFT
3201 if (wp->w_p_rl)
3202 {
3203 --boguscols;
3204 --col;
3205 }
3206 else
3207# endif
3208 {
3209 ++boguscols;
3210 ++col;
3211 }
3212 }
3213 else
3214 {
3215 if (n_extra > 0)
3216 {
3217 vcol += n_extra;
3218 n_extra = 0;
3219 n_attr = 0;
3220 }
3221 }
3222
3223 }
3224#endif // FEAT_CONCEAL
3225 else
3226 --n_skip;
3227
3228 // Only advance the "vcol" when after the 'number' or 'relativenumber'
3229 // column.
3230 if (draw_state > WL_NR
3231#ifdef FEAT_DIFF
3232 && filler_todo <= 0
3233#endif
3234 )
3235 ++vcol;
3236
3237#ifdef FEAT_SYN_HL
3238 if (vcol_save_attr >= 0)
3239 char_attr = vcol_save_attr;
3240#endif
3241
3242 // restore attributes after "predeces" in 'listchars'
3243 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3244 char_attr = saved_attr3;
3245
3246 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003247 if (n_attr > 0 && draw_state == WL_LINE
3248 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003249 char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003250 if (n_attr_skip > 0)
3251 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003252
3253 // At end of screen line and there is more to come: Display the line
3254 // so far. If there is no more to display it is caught above.
3255 if ((
3256#ifdef FEAT_RIGHTLEFT
3257 wp->w_p_rl ? (col < 0) :
3258#endif
3259 (col >= wp->w_width))
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003260 && (draw_state != WL_LINE
3261 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003262#ifdef FEAT_DIFF
3263 || filler_todo > 0
3264#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003265#ifdef FEAT_PROP_POPUP
3266 || text_prop_follows
3267#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003268 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
3269 && p_extra != at_end_str)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003270 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL)))
3271 )
3272 {
3273#ifdef FEAT_CONCEAL
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01003274 screen_line(wp, screen_row, wp->w_wincol, col - boguscols,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00003275 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003276 boguscols = 0;
3277#else
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01003278 screen_line(wp, screen_row, wp->w_wincol, col,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00003279 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003280#endif
3281 ++row;
3282 ++screen_row;
3283
3284 // When not wrapping and finished diff lines, or when displayed
3285 // '$' and highlighting until last column, break here.
3286 if ((!wp->w_p_wrap
3287#ifdef FEAT_DIFF
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003288 && filler_todo <= 0
3289#endif
3290#ifdef FEAT_PROP_POPUP
3291 && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003292#endif
3293 ) || lcs_eol_one == -1)
3294 break;
3295
3296 // When the window is too narrow draw all "@" lines.
3297 if (draw_state != WL_LINE
3298#ifdef FEAT_DIFF
3299 && filler_todo <= 0
3300#endif
3301 )
3302 {
3303 win_draw_end(wp, '@', ' ', TRUE, row, wp->w_height, HLF_AT);
3304 draw_vsep_win(wp, row);
3305 row = endrow;
3306 }
3307
3308 // When line got too long for screen break here.
3309 if (row == endrow)
3310 {
3311 ++row;
3312 break;
3313 }
3314
3315 if (screen_cur_row == screen_row - 1
3316#ifdef FEAT_DIFF
3317 && filler_todo <= 0
3318#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003319#ifdef FEAT_PROP_POPUP
3320 && !text_prop_follows
3321#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003322 && wp->w_width == Columns)
3323 {
3324 // Remember that the line wraps, used for modeless copy.
3325 LineWraps[screen_row - 1] = TRUE;
3326
3327 // Special trick to make copy/paste of wrapped lines work with
3328 // xterm/screen: write an extra character beyond the end of
3329 // the line. This will work with all terminal types
3330 // (regardless of the xn,am settings).
3331 // Only do this on a fast tty.
3332 // Only do this if the cursor is on the current line
3333 // (something has been written in it).
3334 // Don't do this for the GUI.
3335 // Don't do this for double-width characters.
3336 // Don't do this for a window not at the right screen border.
3337 if (p_tf
3338#ifdef FEAT_GUI
3339 && !gui.in_use
3340#endif
3341 && !(has_mbyte
3342 && ((*mb_off2cells)(LineOffset[screen_row],
3343 LineOffset[screen_row] + screen_Columns)
3344 == 2
3345 || (*mb_off2cells)(LineOffset[screen_row - 1]
3346 + (int)Columns - 2,
3347 LineOffset[screen_row] + screen_Columns)
3348 == 2)))
3349 {
3350 // First make sure we are at the end of the screen line,
3351 // then output the same character again to let the
3352 // terminal know about the wrap. If the terminal doesn't
3353 // auto-wrap, we overwrite the character.
3354 if (screen_cur_col != wp->w_width)
3355 screen_char(LineOffset[screen_row - 1]
3356 + (unsigned)Columns - 1,
3357 screen_row - 1, (int)(Columns - 1));
3358
3359 // When there is a multi-byte character, just output a
3360 // space to keep it simple.
3361 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
3362 screen_row - 1] + (Columns - 1)]) > 1)
3363 out_char(' ');
3364 else
3365 out_char(ScreenLines[LineOffset[screen_row - 1]
3366 + (Columns - 1)]);
3367 // force a redraw of the first char on the next line
3368 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1;
3369 screen_start(); // don't know where cursor is now
3370 }
3371 }
3372
3373 col = 0;
3374 off = (unsigned)(current_ScreenLine - ScreenLines);
3375#ifdef FEAT_RIGHTLEFT
3376 if (wp->w_p_rl)
3377 {
3378 col = wp->w_width - 1; // col is not used if breaking!
3379 off += col;
3380 }
3381#endif
3382
3383 // reset the drawing state for the start of a wrapped line
3384 draw_state = WL_START;
3385 saved_n_extra = n_extra;
3386 saved_p_extra = p_extra;
3387 saved_c_extra = c_extra;
3388 saved_c_final = c_final;
3389#ifdef FEAT_SYN_HL
3390 if (!(cul_screenline
3391# ifdef FEAT_DIFF
Bram Moolenaare7705982020-04-21 22:23:15 +02003392 && diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003393# endif
Bram Moolenaare7705982020-04-21 22:23:15 +02003394 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003395 saved_char_attr = char_attr;
3396 else
3397#endif
3398 saved_char_attr = 0;
3399 n_extra = 0;
Bram Moolenaareed9d462021-02-15 20:38:25 +01003400 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003401#ifdef FEAT_LINEBREAK
3402# ifdef FEAT_DIFF
3403 if (filler_todo <= 0)
3404# endif
3405 need_showbreak = TRUE;
3406#endif
3407#ifdef FEAT_DIFF
3408 --filler_todo;
3409 // When the filler lines are actually below the last line of the
3410 // file, don't draw the line itself, break here.
3411 if (filler_todo == 0 && wp->w_botfill)
3412 break;
3413#endif
3414 }
3415
3416 } // for every character in the line
3417
3418#ifdef FEAT_SPELL
3419 // After an empty line check first word for capital.
3420 if (*skipwhite(line) == NUL)
3421 {
3422 capcol_lnum = lnum + 1;
3423 cap_col = 0;
3424 }
3425#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003426#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003427 vim_free(text_props);
3428 vim_free(text_prop_idxs);
3429#endif
3430
3431 vim_free(p_extra_free);
3432 return row;
3433}