blob: 47b8cdc94b3e8e8fa0832fc7e24f675a9586b6d6 [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 Moolenaar4d2031f2022-08-05 20:03:55 +0100351 int text_prop_flags = 0;
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;
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001508 text_prop_flags = 0;
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 Moolenaar4d2031f2022-08-05 20:03:55 +01001538 text_prop_flags = pt->pt_flags;
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);
Bram Moolenaar398649e2022-08-04 15:03:48 +01001557 int wrap = (text_props[used_tpi].tp_flags
1558 & TP_FLAG_WRAP);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001559
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001560 p_extra = p;
Bram Moolenaar711483c2022-07-30 21:33:46 +01001561 c_extra = NUL;
1562 c_final = NUL;
Mike Williams04947892022-07-26 16:03:42 +01001563 n_extra = (int)STRLEN(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001564 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001565 n_attr = mb_charlen(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001566 text_prop_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001567 if (*ptr == NUL)
1568 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001569 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001570
Bram Moolenaar398649e2022-08-04 15:03:48 +01001571 // Keep in sync with where
1572 // textprop_size_after_trunc() is called in
1573 // win_lbr_chartabsize().
1574 if ((right || below || !wrap) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001575 {
1576 int added = wp->w_width - col;
Bram Moolenaar398649e2022-08-04 15:03:48 +01001577 int n_used = n_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001578 char_u *l;
Bram Moolenaar398649e2022-08-04 15:03:48 +01001579 int strsize = wrap
1580 ? vim_strsize(p_extra)
1581 : textprop_size_after_trunc(wp,
1582 below, added, p_extra, &n_used);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001583
Bram Moolenaar398649e2022-08-04 15:03:48 +01001584 if (wrap || right || below || n_used < n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001585 {
Bram Moolenaar398649e2022-08-04 15:03:48 +01001586 // Right-align: fill with spaces
1587 if (right)
1588 added -= strsize;
1589 if (added < 0 || (below && col == 0)
1590 || (!below && n_used < n_extra))
1591 added = 0;
1592 // add 1 for NUL, 2 for when '…' is used
1593 l = alloc(n_used + added + 3);
1594 if (l != NULL)
1595 {
1596 vim_memset(l, ' ', added);
1597 vim_strncpy(l + added, p_extra, n_used);
1598 if (n_used < n_extra)
1599 {
1600 char_u *lp = l + added + n_used - 1;
1601
1602 if (has_mbyte)
1603 {
1604 // change last character to '…'
1605 lp -= (*mb_head_off)(l, lp);
1606 STRCPY(lp, "…");
1607 n_used = lp - l + 3;
1608 }
1609 else
1610 // change last character to '>'
1611 *lp = '>';
1612 }
1613 vim_free(p_extra_free);
1614 p_extra = p_extra_free = l;
1615 n_extra = n_used + added;
1616 n_attr_skip = added;
1617 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001618 }
1619 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001620 }
1621 // reset the ID in the copy to avoid it being used
1622 // again
1623 text_props[used_tpi].tp_id = -MAXCOL;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001624
1625 // If another text prop follows the condition below at
1626 // the last window column must know.
1627 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001628 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001629 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001630 else if (text_prop_next < text_prop_count
1631 && text_props[text_prop_next].tp_col == MAXCOL
1632 && *ptr != NUL
1633 && ptr[mb_ptr2len(ptr)] == NUL)
1634 // When at last-but-one character and a text property
1635 // follows after it, we may need to flush the line after
1636 // displaying that character.
1637 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001638 }
1639#endif
1640
Bram Moolenaara74fda62019-10-19 17:38:03 +02001641#ifdef FEAT_SYN_HL
Bram Moolenaara74fda62019-10-19 17:38:03 +02001642 if (extra_check && n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001643 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001644 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001645# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001646 if (get_term_attr)
Bram Moolenaar219c7d02020-02-01 21:57:29 +01001647 syntax_attr = term_get_attr(wp, lnum, vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001648# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001649 // Get syntax attribute.
1650 if (has_syntax)
1651 {
1652 // Get the syntax attribute for the character. If there
1653 // is an error, disable syntax highlighting.
1654 save_did_emsg = did_emsg;
1655 did_emsg = FALSE;
1656
1657 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001658 if (v == prev_syntax_col)
1659 // at same column again
1660 syntax_attr = prev_syntax_attr;
1661 else
1662 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001663# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001664 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001665# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001666 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001667# ifdef FEAT_SPELL
1668 has_spell ? &can_spell :
1669# endif
1670 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001671 prev_syntax_col = v;
1672 prev_syntax_attr = syntax_attr;
1673 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001674
Bram Moolenaar34390282019-10-16 14:38:26 +02001675 if (did_emsg)
1676 {
1677 wp->w_s->b_syn_error = TRUE;
1678 has_syntax = FALSE;
1679 syntax_attr = 0;
1680 }
1681 else
1682 did_emsg = save_did_emsg;
1683# ifdef SYN_TIME_LIMIT
1684 if (wp->w_s->b_syn_slow)
1685 has_syntax = FALSE;
1686# endif
1687
1688 // Need to get the line again, a multi-line regexp may
1689 // have made it invalid.
1690 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1691 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001692 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001693# ifdef FEAT_CONCEAL
1694 // no concealing past the end of the line, it interferes
1695 // with line highlighting
1696 if (*ptr == NUL)
1697 syntax_flags = 0;
1698 else
1699 syntax_flags = get_syntax_info(&syntax_seqnr);
1700# endif
1701 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001702 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001703# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001704 // Combine text property highlight into syntax highlight.
1705 if (text_prop_type != NULL)
1706 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001707 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01001708 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1709 else
1710 syntax_attr = text_prop_attr;
1711 }
1712# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001713#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001714
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001715 // Decide which of the highlight attributes to use.
1716 attr_pri = TRUE;
1717#ifdef LINE_ATTR
1718 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001719 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001720 char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02001721 if (!highlight_match)
1722 // let search highlight show in Visual area if possible
1723 char_attr = hl_combine_attr(search_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001724# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001725 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001726# endif
1727 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001728 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001729 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001730 char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001731# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001732 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001733# endif
1734 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001735 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
1736 || vcol < fromcol || vcol_prev < fromcol_prev
1737 || vcol >= tocol))
1738 {
1739 // Use line_attr when not in the Visual or 'incsearch' area
1740 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001741# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001742 char_attr = hl_combine_attr(syntax_attr, line_attr);
1743# else
1744 char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001745# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001746 attr_pri = FALSE;
1747 }
1748#else
1749 if (area_attr != 0)
1750 char_attr = area_attr;
1751 else if (search_attr != 0)
1752 char_attr = search_attr;
1753#endif
1754 else
1755 {
1756 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001757#ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001758 char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001759#else
Bram Moolenaardbd43162019-11-09 21:28:14 +01001760 char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001761#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001762 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001763#ifdef FEAT_PROP_POPUP
1764 // override with text property highlight when "override" is TRUE
1765 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
1766 char_attr = hl_combine_attr(char_attr, text_prop_attr);
1767#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001768 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001769
1770 // combine attribute with 'wincolor'
1771 if (win_attr != 0)
1772 {
1773 if (char_attr == 0)
1774 char_attr = win_attr;
1775 else
1776 char_attr = hl_combine_attr(win_attr, char_attr);
1777 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001778
1779 // Get the next character to put on the screen.
1780
1781 // The "p_extra" points to the extra stuff that is inserted to
1782 // represent special characters (non-printable stuff) and other
1783 // things. When all characters are the same, c_extra is used.
1784 // If c_final is set, it will compulsorily be used at the end.
1785 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
1786 // "p_extra[n_extra]".
1787 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
1788 if (n_extra > 0)
1789 {
1790 if (c_extra != NUL || (n_extra == 1 && c_final != NUL))
1791 {
1792 c = (n_extra == 1 && c_final != NUL) ? c_final : c_extra;
1793 mb_c = c; // doesn't handle non-utf-8 multi-byte!
1794 if (enc_utf8 && utf_char2len(c) > 1)
1795 {
1796 mb_utf8 = TRUE;
1797 u8cc[0] = 0;
1798 c = 0xc0;
1799 }
1800 else
1801 mb_utf8 = FALSE;
1802 }
1803 else
1804 {
1805 c = *p_extra;
1806 if (has_mbyte)
1807 {
1808 mb_c = c;
1809 if (enc_utf8)
1810 {
1811 // If the UTF-8 character is more than one byte:
1812 // Decode it into "mb_c".
1813 mb_l = utfc_ptr2len(p_extra);
1814 mb_utf8 = FALSE;
1815 if (mb_l > n_extra)
1816 mb_l = 1;
1817 else if (mb_l > 1)
1818 {
1819 mb_c = utfc_ptr2char(p_extra, u8cc);
1820 mb_utf8 = TRUE;
1821 c = 0xc0;
1822 }
1823 }
1824 else
1825 {
1826 // if this is a DBCS character, put it in "mb_c"
1827 mb_l = MB_BYTE2LEN(c);
1828 if (mb_l >= n_extra)
1829 mb_l = 1;
1830 else if (mb_l > 1)
1831 mb_c = (c << 8) + p_extra[1];
1832 }
1833 if (mb_l == 0) // at the NUL at end-of-line
1834 mb_l = 1;
1835
1836 // If a double-width char doesn't fit display a '>' in the
1837 // last column.
1838 if ((
1839# ifdef FEAT_RIGHTLEFT
1840 wp->w_p_rl ? (col <= 0) :
1841# endif
1842 (col >= wp->w_width - 1))
1843 && (*mb_char2cells)(mb_c) == 2)
1844 {
1845 c = '>';
1846 mb_c = c;
1847 mb_l = 1;
1848 mb_utf8 = FALSE;
1849 multi_attr = HL_ATTR(HLF_AT);
1850#ifdef FEAT_SYN_HL
1851 if (cul_attr)
1852 multi_attr = hl_combine_attr(multi_attr, cul_attr);
1853#endif
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001854 multi_attr = hl_combine_attr(win_attr, multi_attr);
1855
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001856 // put the pointer back to output the double-width
1857 // character at the start of the next line.
1858 ++n_extra;
1859 --p_extra;
1860 }
1861 else
1862 {
1863 n_extra -= mb_l - 1;
1864 p_extra += mb_l - 1;
1865 }
1866 }
1867 ++p_extra;
1868 }
1869 --n_extra;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001870#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001871 if (n_extra <= 0)
1872 in_linebreak = FALSE;
1873#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001874 }
1875 else
1876 {
1877#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01001878 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001879#endif
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001880 VIM_CLEAR(p_extra_free);
Bram Moolenaarb9081882022-07-09 04:56:24 +01001881 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001882
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001883 // Get a character from the line itself.
1884 c = *ptr;
1885#ifdef FEAT_LINEBREAK
1886 c0 = *ptr;
1887#endif
1888 if (has_mbyte)
1889 {
1890 mb_c = c;
1891 if (enc_utf8)
1892 {
1893 // If the UTF-8 character is more than one byte: Decode it
1894 // into "mb_c".
1895 mb_l = utfc_ptr2len(ptr);
1896 mb_utf8 = FALSE;
1897 if (mb_l > 1)
1898 {
1899 mb_c = utfc_ptr2char(ptr, u8cc);
1900 // Overlong encoded ASCII or ASCII with composing char
1901 // is displayed normally, except a NUL.
1902 if (mb_c < 0x80)
1903 {
1904 c = mb_c;
1905#ifdef FEAT_LINEBREAK
1906 c0 = mb_c;
1907#endif
1908 }
1909 mb_utf8 = TRUE;
1910
1911 // At start of the line we can have a composing char.
1912 // Draw it as a space with a composing char.
1913 if (utf_iscomposing(mb_c))
1914 {
1915 int i;
1916
1917 for (i = Screen_mco - 1; i > 0; --i)
1918 u8cc[i] = u8cc[i - 1];
1919 u8cc[0] = mb_c;
1920 mb_c = ' ';
1921 }
1922 }
1923
1924 if ((mb_l == 1 && c >= 0x80)
1925 || (mb_l >= 1 && mb_c == 0)
1926 || (mb_l > 1 && (!vim_isprintc(mb_c))))
1927 {
1928 // Illegal UTF-8 byte: display as <xx>.
1929 // Non-BMP character : display as ? or fullwidth ?.
1930 transchar_hex(extra, mb_c);
1931# ifdef FEAT_RIGHTLEFT
1932 if (wp->w_p_rl) // reverse
1933 rl_mirror(extra);
1934# endif
1935 p_extra = extra;
1936 c = *p_extra;
1937 mb_c = mb_ptr2char_adv(&p_extra);
1938 mb_utf8 = (c >= 0x80);
1939 n_extra = (int)STRLEN(p_extra);
1940 c_extra = NUL;
1941 c_final = NUL;
1942 if (area_attr == 0 && search_attr == 0)
1943 {
1944 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001945 extra_attr = hl_combine_attr(
1946 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001947 saved_attr2 = char_attr; // save current attr
1948 }
1949 }
1950 else if (mb_l == 0) // at the NUL at end-of-line
1951 mb_l = 1;
1952#ifdef FEAT_ARABIC
1953 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
1954 {
1955 // Do Arabic shaping.
1956 int pc, pc1, nc;
1957 int pcc[MAX_MCO];
1958
1959 // The idea of what is the previous and next
1960 // character depends on 'rightleft'.
1961 if (wp->w_p_rl)
1962 {
1963 pc = prev_c;
1964 pc1 = prev_c1;
1965 nc = utf_ptr2char(ptr + mb_l);
1966 prev_c1 = u8cc[0];
1967 }
1968 else
1969 {
1970 pc = utfc_ptr2char(ptr + mb_l, pcc);
1971 nc = prev_c;
1972 pc1 = pcc[0];
1973 }
1974 prev_c = mb_c;
1975
1976 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
1977 }
1978 else
1979 prev_c = mb_c;
1980#endif
1981 }
1982 else // enc_dbcs
1983 {
1984 mb_l = MB_BYTE2LEN(c);
1985 if (mb_l == 0) // at the NUL at end-of-line
1986 mb_l = 1;
1987 else if (mb_l > 1)
1988 {
1989 // We assume a second byte below 32 is illegal.
1990 // Hopefully this is OK for all double-byte encodings!
1991 if (ptr[1] >= 32)
1992 mb_c = (c << 8) + ptr[1];
1993 else
1994 {
1995 if (ptr[1] == NUL)
1996 {
1997 // head byte at end of line
1998 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02001999 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002000 }
2001 else
2002 {
2003 // illegal tail byte
2004 mb_l = 2;
2005 STRCPY(extra, "XX");
2006 }
2007 p_extra = extra;
2008 n_extra = (int)STRLEN(extra) - 1;
2009 c_extra = NUL;
2010 c_final = NUL;
2011 c = *p_extra++;
2012 if (area_attr == 0 && search_attr == 0)
2013 {
2014 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002015 extra_attr = hl_combine_attr(
2016 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002017 saved_attr2 = char_attr; // save current attr
2018 }
2019 mb_c = c;
2020 }
2021 }
2022 }
2023 // If a double-width char doesn't fit display a '>' in the
2024 // last column; the character is displayed at the start of the
2025 // next line.
2026 if ((
2027# ifdef FEAT_RIGHTLEFT
2028 wp->w_p_rl ? (col <= 0) :
2029# endif
2030 (col >= wp->w_width - 1))
2031 && (*mb_char2cells)(mb_c) == 2)
2032 {
2033 c = '>';
2034 mb_c = c;
2035 mb_utf8 = FALSE;
2036 mb_l = 1;
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002037 multi_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002038 // Put pointer back so that the character will be
2039 // displayed at the start of the next line.
2040 --ptr;
2041#ifdef FEAT_CONCEAL
2042 did_decrement_ptr = TRUE;
2043#endif
2044 }
2045 else if (*ptr != NUL)
2046 ptr += mb_l - 1;
2047
2048 // If a double-width char doesn't fit at the left side display
2049 // a '<' in the first column. Don't do this for unprintable
2050 // characters.
2051 if (n_skip > 0 && mb_l > 1 && n_extra == 0)
2052 {
2053 n_extra = 1;
2054 c_extra = MB_FILLER_CHAR;
2055 c_final = NUL;
2056 c = ' ';
2057 if (area_attr == 0 && search_attr == 0)
2058 {
2059 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002060 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002061 saved_attr2 = char_attr; // save current attr
2062 }
2063 mb_c = c;
2064 mb_utf8 = FALSE;
2065 mb_l = 1;
2066 }
2067
2068 }
2069 ++ptr;
2070
2071 if (extra_check)
2072 {
2073#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002074 // Check spelling (unless at the end of the line).
2075 // Only do this when there is no syntax highlighting, the
2076 // @Spell cluster is not used or the current syntax item
2077 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002078 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002079 if (has_spell && v >= word_end && v > cur_checked_col)
2080 {
2081 spell_attr = 0;
2082 if (c != 0 && (
2083# ifdef FEAT_SYN_HL
2084 !has_syntax ||
2085# endif
2086 can_spell))
2087 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002088 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002089 int len;
2090 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002091
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002092 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002093 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002094
2095 // Use nextline[] if possible, it has the start of the
2096 // next line concatenated.
2097 if ((prev_ptr - line) - nextlinecol >= 0)
2098 p = nextline + (prev_ptr - line) - nextlinecol;
2099 else
2100 p = prev_ptr;
2101 cap_col -= (int)(prev_ptr - line);
2102 len = spell_check(wp, p, &spell_hlf, &cap_col,
2103 nochange);
2104 word_end = v + len;
2105
2106 // In Insert mode only highlight a word that
2107 // doesn't touch the cursor.
2108 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002109 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002110 && wp->w_cursor.lnum == lnum
2111 && wp->w_cursor.col >=
2112 (colnr_T)(prev_ptr - line)
2113 && wp->w_cursor.col < (colnr_T)word_end)
2114 {
2115 spell_hlf = HLF_COUNT;
2116 spell_redraw_lnum = lnum;
2117 }
2118
2119 if (spell_hlf == HLF_COUNT && p != prev_ptr
2120 && (p - nextline) + len > nextline_idx)
2121 {
2122 // Remember that the good word continues at the
2123 // start of the next line.
2124 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002125 checked_col = (int)((p - nextline)
2126 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002127 }
2128
2129 // Turn index into actual attributes.
2130 if (spell_hlf != HLF_COUNT)
2131 spell_attr = highlight_attr[spell_hlf];
2132
2133 if (cap_col > 0)
2134 {
2135 if (p != prev_ptr
2136 && (p - nextline) + cap_col >= nextline_idx)
2137 {
2138 // Remember that the word in the next line
2139 // must start with a capital.
2140 capcol_lnum = lnum + 1;
2141 cap_col = (int)((p - nextline) + cap_col
2142 - nextline_idx);
2143 }
2144 else
2145 // Compute the actual column.
2146 cap_col += (int)(prev_ptr - line);
2147 }
2148 }
2149 }
2150 if (spell_attr != 0)
2151 {
2152 if (!attr_pri)
2153 char_attr = hl_combine_attr(char_attr, spell_attr);
2154 else
2155 char_attr = hl_combine_attr(spell_attr, char_attr);
2156 }
2157#endif
2158#ifdef FEAT_LINEBREAK
2159 // Found last space before word: check for line break.
2160 if (wp->w_p_lbr && c0 == c
2161 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2162 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002163 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2164 : 0;
2165 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002166 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002167
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002168 init_chartabsize_arg(&cts, wp, lnum, vcol, line, p);
2169 n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002170
2171 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002172 // space for it again.
Bram Moolenaara06e3452021-05-29 17:56:37 +02002173 if (vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002174 {
Bram Moolenaara06e3452021-05-29 17:56:37 +02002175 n_extra -= MB_CHARLEN(get_showbreak_value(wp));
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002176 if (n_extra < 0)
2177 n_extra = 0;
2178 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002179 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002180 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002181 // line break, but for TABs the highlighting should
2182 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002183 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002184
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002185 if (c == TAB && n_extra + col > wp->w_width)
2186# ifdef FEAT_VARTABS
2187 n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts,
2188 wp->w_buffer->b_p_vts_array) - 1;
2189# else
2190 n_extra = (int)wp->w_buffer->b_p_ts
2191 - vcol % (int)wp->w_buffer->b_p_ts - 1;
2192# endif
2193
2194 c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2195 c_final = NUL;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002196# if defined(FEAT_PROP_POPUP)
Bram Moolenaar42eba042021-11-30 20:22:49 +00002197 if (n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002198 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002199# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002200 if (VIM_ISWHITE(c))
2201 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002202# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002203 if (c == TAB)
2204 // See "Tab alignment" below.
2205 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002206# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002207 if (!wp->w_p_list)
2208 c = ' ';
2209 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002210 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002211 }
2212#endif
2213
zeertzjqf14b8ba2021-09-10 16:58:30 +02002214 in_multispace = c == ' '
2215 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2216 if (!in_multispace)
2217 multispace_pos = 0;
2218
Bram Moolenaareed9d462021-02-15 20:38:25 +01002219 // 'list': Change char 160 to 'nbsp' and space to 'space'
2220 // setting in 'listchars'. But not when the character is
2221 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002222 if (wp->w_p_list
2223 && ((((c == 160 && mb_l == 1)
2224 || (mb_utf8
2225 && ((mb_c == 160 && mb_l == 2)
2226 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002227 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002228 || (c == ' '
2229 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002230 && (wp->w_lcs_chars.space
2231 || (in_multispace
2232 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002233 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002234 && ptr - line <= trailcol)))
2235 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002236 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2237 {
2238 c = wp->w_lcs_chars.multispace[multispace_pos++];
2239 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2240 multispace_pos = 0;
2241 }
2242 else
2243 c = (c == ' ') ? wp->w_lcs_chars.space
2244 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002245 if (area_attr == 0 && search_attr == 0)
2246 {
2247 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002248 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002249 saved_attr2 = char_attr; // save current attr
2250 }
2251 mb_c = c;
2252 if (enc_utf8 && utf_char2len(c) > 1)
2253 {
2254 mb_utf8 = TRUE;
2255 u8cc[0] = 0;
2256 c = 0xc0;
2257 }
2258 else
2259 mb_utf8 = FALSE;
2260 }
2261
zeertzjq2e7cba32022-06-10 15:30:32 +01002262 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2263 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002264 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002265 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2266 && wp->w_lcs_chars.leadmultispace != NULL)
2267 {
2268 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002269 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2270 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002271 multispace_pos = 0;
2272 }
2273
2274 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2275 c = wp->w_lcs_chars.trail;
2276
2277 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2278 c = wp->w_lcs_chars.lead;
2279
zeertzjq2e7cba32022-06-10 15:30:32 +01002280 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002281 c = wp->w_lcs_chars.space;
2282
2283
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002284 if (!attr_pri)
2285 {
2286 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002287 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002288 saved_attr2 = char_attr; // save current attr
2289 }
2290 mb_c = c;
2291 if (enc_utf8 && utf_char2len(c) > 1)
2292 {
2293 mb_utf8 = TRUE;
2294 u8cc[0] = 0;
2295 c = 0xc0;
2296 }
2297 else
2298 mb_utf8 = FALSE;
2299 }
2300 }
2301
2302 // Handling of non-printable characters.
2303 if (!vim_isprintc(c))
2304 {
2305 // when getting a character from the file, we may have to
2306 // turn it into something else on the way to putting it
2307 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002308 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002309 {
2310 int tab_len = 0;
2311 long vcol_adjusted = vcol; // removed showbreak length
2312#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002313 char_u *sbr = get_showbreak_value(wp);
2314
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002315 // only adjust the tab_len, when at the first column
2316 // after the showbreak value was drawn
Bram Moolenaaree857022019-11-09 23:26:40 +01002317 if (*sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap)
2318 vcol_adjusted = vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002319#endif
2320 // tab amount depends on current column
2321#ifdef FEAT_VARTABS
2322 tab_len = tabstop_padding(vcol_adjusted,
2323 wp->w_buffer->b_p_ts,
2324 wp->w_buffer->b_p_vts_array) - 1;
2325#else
2326 tab_len = (int)wp->w_buffer->b_p_ts
2327 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2328#endif
2329
2330#ifdef FEAT_LINEBREAK
2331 if (!wp->w_p_lbr || !wp->w_p_list)
2332#endif
2333 // tab amount depends on current column
2334 n_extra = tab_len;
2335#ifdef FEAT_LINEBREAK
2336 else
2337 {
2338 char_u *p;
2339 int len;
2340 int i;
2341 int saved_nextra = n_extra;
2342
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002343# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002344 if (vcol_off > 0)
2345 // there are characters to conceal
2346 tab_len += vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002347
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002348 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002349 if (wp->w_p_list && wp->w_lcs_chars.tab1
2350 && old_boguscols > 0
2351 && n_extra > tab_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002352 tab_len += n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002353# endif
2354 // If n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002355 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002356 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002357 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002358 if (wp->w_lcs_chars.tab3)
2359 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002360 if (n_extra > 0)
2361 len += n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002362 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002363 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002364 if (p == NULL)
2365 n_extra = 0;
2366 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002367 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002368 vim_memset(p, ' ', len);
2369 p[len] = NUL;
2370 vim_free(p_extra_free);
2371 p_extra_free = p;
2372 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002373 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002374 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002375
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002376 if (*p == NUL)
2377 {
2378 tab_len = i;
2379 break;
2380 }
2381
2382 // if tab3 is given, use it for the last char
2383 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2384 lcs = wp->w_lcs_chars.tab3;
2385 p += mb_char2bytes(lcs, p);
2386 n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002387 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002388 }
2389 p_extra = p_extra_free;
2390# ifdef FEAT_CONCEAL
2391 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2392 // macro below, so need to adjust for that here
2393 if (vcol_off > 0)
2394 n_extra -= vcol_off;
2395# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002396 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002397 }
2398#endif
2399#ifdef FEAT_CONCEAL
2400 {
2401 int vc_saved = vcol_off;
2402
2403 // Tab alignment should be identical regardless of
2404 // 'conceallevel' value. So tab compensates of all
2405 // previous concealed characters, and thus resets
2406 // vcol_off and boguscols accumulated so far in the
2407 // line. Note that the tab can be longer than
2408 // 'tabstop' when there are concealed characters.
2409 FIX_FOR_BOGUSCOLS;
2410
2411 // Make sure, the highlighting for the tab char will be
2412 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002413 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002414 if (n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002415 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002416 tab_len += vc_saved;
2417 }
2418#endif
2419 mb_utf8 = FALSE; // don't draw as UTF-8
2420 if (wp->w_p_list)
2421 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002422 c = (n_extra == 0 && wp->w_lcs_chars.tab3)
2423 ? wp->w_lcs_chars.tab3
2424 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002425#ifdef FEAT_LINEBREAK
2426 if (wp->w_p_lbr)
2427 c_extra = NUL; // using p_extra from above
2428 else
2429#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01002430 c_extra = wp->w_lcs_chars.tab2;
2431 c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002432 n_attr = tab_len + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002433 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002434 saved_attr2 = char_attr; // save current attr
2435 mb_c = c;
2436 if (enc_utf8 && utf_char2len(c) > 1)
2437 {
2438 mb_utf8 = TRUE;
2439 u8cc[0] = 0;
2440 c = 0xc0;
2441 }
2442 }
2443 else
2444 {
2445 c_final = NUL;
2446 c_extra = ' ';
2447 c = ' ';
2448 }
2449 }
2450 else if (c == NUL
2451 && (wp->w_p_list
2452 || ((fromcol >= 0 || fromcol_prev >= 0)
2453 && tocol > vcol
2454 && VIsual_mode != Ctrl_V
2455 && (
2456# ifdef FEAT_RIGHTLEFT
2457 wp->w_p_rl ? (col >= 0) :
2458# endif
2459 (col < wp->w_width))
2460 && !(noinvcur
2461 && lnum == wp->w_cursor.lnum
2462 && (colnr_T)vcol == wp->w_virtcol)))
2463 && lcs_eol_one > 0)
2464 {
2465 // Display a '$' after the line or highlight an extra
2466 // character if the line break is included.
2467#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2468 // For a diff line the highlighting continues after the
2469 // "$".
2470 if (
2471# ifdef FEAT_DIFF
2472 diff_hlf == (hlf_T)0
2473# ifdef LINE_ATTR
2474 &&
2475# endif
2476# endif
2477# ifdef LINE_ATTR
2478 line_attr == 0
2479# endif
2480 )
2481#endif
2482 {
2483 // In virtualedit, visual selections may extend
2484 // beyond end of line.
2485 if (area_highlighting && virtual_active()
2486 && tocol != MAXCOL && vcol < tocol)
2487 n_extra = 0;
2488 else
2489 {
2490 p_extra = at_end_str;
2491 n_extra = 1;
2492 c_extra = NUL;
2493 c_final = NUL;
2494 }
2495 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002496 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2497 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002498 else
2499 c = ' ';
2500 lcs_eol_one = -1;
2501 --ptr; // put it back at the NUL
2502 if (!attr_pri)
2503 {
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002504 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002505 n_attr = 1;
2506 }
2507 mb_c = c;
2508 if (enc_utf8 && utf_char2len(c) > 1)
2509 {
2510 mb_utf8 = TRUE;
2511 u8cc[0] = 0;
2512 c = 0xc0;
2513 }
2514 else
2515 mb_utf8 = FALSE; // don't draw as UTF-8
2516 }
2517 else if (c != NUL)
2518 {
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002519 p_extra = transchar_buf(wp->w_buffer, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002520 if (n_extra == 0)
2521 n_extra = byte2cells(c) - 1;
2522#ifdef FEAT_RIGHTLEFT
2523 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
2524 rl_mirror(p_extra); // reverse "<12>"
2525#endif
2526 c_extra = NUL;
2527 c_final = NUL;
2528#ifdef FEAT_LINEBREAK
2529 if (wp->w_p_lbr)
2530 {
2531 char_u *p;
2532
2533 c = *p_extra;
2534 p = alloc(n_extra + 1);
2535 vim_memset(p, ' ', n_extra);
2536 STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1);
2537 p[n_extra] = NUL;
2538 vim_free(p_extra_free);
2539 p_extra_free = p_extra = p;
2540 }
2541 else
2542#endif
2543 {
2544 n_extra = byte2cells(c) - 1;
2545 c = *p_extra++;
2546 }
2547 if (!attr_pri)
2548 {
2549 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002550 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002551 saved_attr2 = char_attr; // save current attr
2552 }
2553 mb_utf8 = FALSE; // don't draw as UTF-8
2554 }
2555 else if (VIsual_active
2556 && (VIsual_mode == Ctrl_V
2557 || VIsual_mode == 'v')
2558 && virtual_active()
2559 && tocol != MAXCOL
2560 && vcol < tocol
2561 && (
2562#ifdef FEAT_RIGHTLEFT
2563 wp->w_p_rl ? (col >= 0) :
2564#endif
2565 (col < wp->w_width)))
2566 {
2567 c = ' ';
2568 --ptr; // put it back at the NUL
2569 }
2570#if defined(LINE_ATTR)
2571 else if ((
2572# ifdef FEAT_DIFF
2573 diff_hlf != (hlf_T)0 ||
2574# endif
2575# ifdef FEAT_TERMINAL
2576 win_attr != 0 ||
2577# endif
2578 line_attr != 0
2579 ) && (
2580# ifdef FEAT_RIGHTLEFT
2581 wp->w_p_rl ? (col >= 0) :
2582# endif
2583 (col
2584# ifdef FEAT_CONCEAL
2585 - boguscols
2586# endif
2587 < wp->w_width)))
2588 {
2589 // Highlight until the right side of the window
2590 c = ' ';
2591 --ptr; // put it back at the NUL
2592
2593 // Remember we do the char for line highlighting.
2594 ++did_line_attr;
2595
2596 // don't do search HL for the rest of the line
2597 if (line_attr != 0 && char_attr == search_attr
2598 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002599 || (wp->w_p_list &&
2600 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002601 char_attr = line_attr;
2602# ifdef FEAT_DIFF
2603 if (diff_hlf == HLF_TXD)
2604 {
2605 diff_hlf = HLF_CHD;
2606 if (vi_attr == 0 || char_attr != vi_attr)
2607 {
2608 char_attr = HL_ATTR(diff_hlf);
2609 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2610 && wp->w_p_culopt_flags != CULOPT_NBR
2611 && (!cul_screenline
2612 || (vcol >= left_curline_col
2613 && vcol <= right_curline_col)))
2614 char_attr = hl_combine_attr(
2615 char_attr, HL_ATTR(HLF_CUL));
2616 }
2617 }
2618# endif
2619# ifdef FEAT_TERMINAL
2620 if (win_attr != 0)
2621 {
2622 char_attr = win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002623 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2624 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002625 {
2626 if (!cul_screenline || (vcol >= left_curline_col
2627 && vcol <= right_curline_col))
2628 char_attr = hl_combine_attr(
2629 char_attr, HL_ATTR(HLF_CUL));
2630 }
2631 else if (line_attr)
2632 char_attr = hl_combine_attr(char_attr, line_attr);
2633 }
2634# endif
2635 }
2636#endif
2637 }
2638
2639#ifdef FEAT_CONCEAL
2640 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01002641 && (wp != curwin || lnum != wp->w_cursor.lnum
2642 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002643 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2644 && !(lnum_in_visual_area
2645 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2646 {
2647 char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01002648 if (((prev_syntax_id != syntax_seqnr
2649 && (syntax_flags & HL_CONCEAL) != 0)
2650 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002651 && (syn_get_sub_char() != NUL
2652 || (has_match_conc && match_conc)
2653 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002654 && wp->w_p_cole != 3)
2655 {
2656 // First time at this concealed item: display one
2657 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002658 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002659 c = match_conc;
2660 else if (syn_get_sub_char() != NUL)
2661 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01002662 else if (wp->w_lcs_chars.conceal != NUL)
2663 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002664 else
2665 c = ' ';
2666
2667 prev_syntax_id = syntax_seqnr;
2668
2669 if (n_extra > 0)
2670 vcol_off += n_extra;
2671 vcol += n_extra;
2672 if (wp->w_p_wrap && n_extra > 0)
2673 {
2674# ifdef FEAT_RIGHTLEFT
2675 if (wp->w_p_rl)
2676 {
2677 col -= n_extra;
2678 boguscols -= n_extra;
2679 }
2680 else
2681# endif
2682 {
2683 boguscols += n_extra;
2684 col += n_extra;
2685 }
2686 }
2687 n_extra = 0;
2688 n_attr = 0;
2689 }
2690 else if (n_skip == 0)
2691 {
2692 is_concealing = TRUE;
2693 n_skip = 1;
2694 }
2695 mb_c = c;
2696 if (enc_utf8 && utf_char2len(c) > 1)
2697 {
2698 mb_utf8 = TRUE;
2699 u8cc[0] = 0;
2700 c = 0xc0;
2701 }
2702 else
2703 mb_utf8 = FALSE; // don't draw as UTF-8
2704 }
2705 else
2706 {
2707 prev_syntax_id = 0;
2708 is_concealing = FALSE;
2709 }
2710
2711 if (n_skip > 0 && did_decrement_ptr)
2712 // not showing the '>', put pointer back to avoid getting stuck
2713 ++ptr;
2714
2715#endif // FEAT_CONCEAL
2716 }
2717
2718#ifdef FEAT_CONCEAL
2719 // In the cursor line and we may be concealing characters: correct
2720 // the cursor column when we reach its position.
2721 if (!did_wcol && draw_state == WL_LINE
2722 && wp == curwin && lnum == wp->w_cursor.lnum
2723 && conceal_cursor_line(wp)
2724 && (int)wp->w_virtcol <= vcol + n_skip)
2725 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002726# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002727 if (wp->w_p_rl)
2728 wp->w_wcol = wp->w_width - col + boguscols - 1;
2729 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002730# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002731 wp->w_wcol = col - boguscols;
2732 wp->w_wrow = row;
2733 did_wcol = TRUE;
2734 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002735# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01002736 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002737# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002738 }
2739#endif
2740
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002741 // Use "extra_attr", but don't override visual selection highlighting.
2742 // Don't use "extra_attr" until n_attr_skip is zero.
2743 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002744 && draw_state == WL_LINE
2745 && !attr_pri)
2746 {
2747#ifdef LINE_ATTR
2748 if (line_attr)
2749 char_attr = hl_combine_attr(extra_attr, line_attr);
2750 else
2751#endif
2752 char_attr = extra_attr;
2753 }
2754
2755#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2756 // XIM don't send preedit_start and preedit_end, but they send
2757 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
2758 // im_is_preediting() here.
2759 if (p_imst == IM_ON_THE_SPOT
2760 && xic != NULL
2761 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01002762 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002763 && !p_imdisable
2764 && im_is_preediting()
2765 && draw_state == WL_LINE)
2766 {
2767 colnr_T tcol;
2768
2769 if (preedit_end_col == MAXCOL)
2770 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
2771 else
2772 tcol = preedit_end_col;
2773 if ((long)preedit_start_col <= vcol && vcol < (long)tcol)
2774 {
2775 if (feedback_old_attr < 0)
2776 {
2777 feedback_col = 0;
2778 feedback_old_attr = char_attr;
2779 }
2780 char_attr = im_get_feedback_attr(feedback_col);
2781 if (char_attr < 0)
2782 char_attr = feedback_old_attr;
2783 feedback_col++;
2784 }
2785 else if (feedback_old_attr >= 0)
2786 {
2787 char_attr = feedback_old_attr;
2788 feedback_old_attr = -1;
2789 feedback_col = 0;
2790 }
2791 }
2792#endif
2793 // Handle the case where we are in column 0 but not on the first
2794 // character of the line and the user wants us to show us a
2795 // special character (via 'listchars' option "precedes:<char>".
2796 if (lcs_prec_todo != NUL
2797 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02002798 && (wp->w_p_wrap ?
2799 (wp->w_skipcol > 0 && row == 0) :
2800 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002801#ifdef FEAT_DIFF
2802 && filler_todo <= 0
2803#endif
2804 && draw_state > WL_NR
2805 && c != NUL)
2806 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002807 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002808 lcs_prec_todo = NUL;
2809 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2810 {
2811 // Double-width character being overwritten by the "precedes"
2812 // character, need to fill up half the character.
2813 c_extra = MB_FILLER_CHAR;
2814 c_final = NUL;
2815 n_extra = 1;
2816 n_attr = 2;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002817 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002818 }
2819 mb_c = c;
2820 if (enc_utf8 && utf_char2len(c) > 1)
2821 {
2822 mb_utf8 = TRUE;
2823 u8cc[0] = 0;
2824 c = 0xc0;
2825 }
2826 else
2827 mb_utf8 = FALSE; // don't draw as UTF-8
2828 if (!attr_pri)
2829 {
2830 saved_attr3 = char_attr; // save current attr
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002831 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002832 n_attr3 = 1;
2833 }
2834 }
2835
2836 // At end of the text line or just after the last character.
2837 if ((c == NUL
2838#if defined(LINE_ATTR)
2839 || did_line_attr == 1
2840#endif
2841 ) && eol_hl_off == 0)
2842 {
2843#ifdef FEAT_SEARCH_EXTRA
2844 // flag to indicate whether prevcol equals startcol of search_hl or
2845 // one of the matches
2846 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
2847 (long)(ptr - line) - (c == NUL));
2848#endif
2849 // Invert at least one char, used for Visual and empty line or
2850 // highlight match at end of line. If it's beyond the last
2851 // char on the screen, just overwrite that one (tricky!) Not
2852 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002853 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002854 && ((area_attr != 0 && vcol == fromcol
2855 && (VIsual_mode != Ctrl_V
2856 || lnum == VIsual.lnum
2857 || lnum == curwin->w_cursor.lnum)
2858 && c == NUL)
2859#ifdef FEAT_SEARCH_EXTRA
2860 // highlight 'hlsearch' match at end of line
2861 || (prevcol_hl_flag
2862# ifdef FEAT_SYN_HL
2863 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
2864 && !(wp == curwin && VIsual_active))
2865# endif
2866# ifdef FEAT_DIFF
2867 && diff_hlf == (hlf_T)0
2868# endif
2869# if defined(LINE_ATTR)
2870 && did_line_attr <= 1
2871# endif
2872 )
2873#endif
2874 ))
2875 {
2876 int n = 0;
2877
2878#ifdef FEAT_RIGHTLEFT
2879 if (wp->w_p_rl)
2880 {
2881 if (col < 0)
2882 n = 1;
2883 }
2884 else
2885#endif
2886 {
2887 if (col >= wp->w_width)
2888 n = -1;
2889 }
2890 if (n != 0)
2891 {
2892 // At the window boundary, highlight the last character
2893 // instead (better than nothing).
2894 off += n;
2895 col += n;
2896 }
2897 else
2898 {
2899 // Add a blank character to highlight.
2900 ScreenLines[off] = ' ';
2901 if (enc_utf8)
2902 ScreenLinesUC[off] = 0;
2903 }
2904#ifdef FEAT_SEARCH_EXTRA
2905 if (area_attr == 0)
2906 {
2907 // Use attributes from match with highest priority among
2908 // 'search_hl' and the match list.
2909 get_search_match_hl(wp, &screen_search_hl,
2910 (long)(ptr - line), &char_attr);
2911 }
2912#endif
2913 ScreenAttrs[off] = char_attr;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002914 ScreenCols[off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002915#ifdef FEAT_RIGHTLEFT
2916 if (wp->w_p_rl)
2917 {
2918 --col;
2919 --off;
2920 }
2921 else
2922#endif
2923 {
2924 ++col;
2925 ++off;
2926 }
2927 ++vcol;
2928 eol_hl_off = 1;
2929 }
2930 }
2931
2932 // At end of the text line.
2933 if (c == NUL)
2934 {
2935#ifdef FEAT_SYN_HL
2936 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
2937 if (wp->w_p_wrap)
2938 v = wp->w_skipcol;
2939 else
2940 v = wp->w_leftcol;
2941
2942 // check if line ends before left margin
2943 if (vcol < v + col - win_col_off(wp))
2944 vcol = v + col - win_col_off(wp);
2945#ifdef FEAT_CONCEAL
2946 // Get rid of the boguscols now, we want to draw until the right
2947 // edge for 'cursorcolumn'.
2948 col -= boguscols;
2949 boguscols = 0;
2950#endif
2951
2952 if (draw_color_col)
2953 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2954
2955 if (((wp->w_p_cuc
2956 && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off
2957 && (int)wp->w_virtcol <
=?UTF-8?q?Dundar=20G=C3=B6c?=d5cec1f2022-01-29 15:19:23 +00002958 (long)wp->w_width * (row - startrow + 1) + v
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002959 && lnum != wp->w_cursor.lnum)
2960 || draw_color_col
2961 || win_attr != 0)
2962# ifdef FEAT_RIGHTLEFT
2963 && !wp->w_p_rl
2964# endif
2965 )
2966 {
2967 int rightmost_vcol = 0;
2968 int i;
2969
2970 if (wp->w_p_cuc)
2971 rightmost_vcol = wp->w_virtcol;
2972 if (draw_color_col)
2973 // determine rightmost colorcolumn to possibly draw
2974 for (i = 0; color_cols[i] >= 0; ++i)
2975 if (rightmost_vcol < color_cols[i])
2976 rightmost_vcol = color_cols[i];
2977
2978 while (col < wp->w_width)
2979 {
2980 ScreenLines[off] = ' ';
2981 if (enc_utf8)
2982 ScreenLinesUC[off] = 0;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002983 ScreenCols[off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002984 ++col;
2985 if (draw_color_col)
2986 draw_color_col = advance_color_col(VCOL_HLC,
2987 &color_cols);
2988
2989 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
2990 ScreenAttrs[off++] = HL_ATTR(HLF_CUC);
2991 else if (draw_color_col && VCOL_HLC == *color_cols)
2992 ScreenAttrs[off++] = HL_ATTR(HLF_MC);
2993 else
2994 ScreenAttrs[off++] = win_attr;
2995
2996 if (VCOL_HLC >= rightmost_vcol && win_attr == 0)
2997 break;
2998
2999 ++vcol;
3000 }
3001 }
3002#endif
3003
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01003004 screen_line(wp, screen_row, wp->w_wincol, col,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00003005 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003006 row++;
3007
3008 // Update w_cline_height and w_cline_folded if the cursor line was
3009 // updated (saves a call to plines() later).
3010 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3011 {
3012 curwin->w_cline_row = startrow;
3013 curwin->w_cline_height = row - startrow;
3014#ifdef FEAT_FOLDING
3015 curwin->w_cline_folded = FALSE;
3016#endif
3017 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3018 }
3019
3020 break;
3021 }
3022
3023 // Show "extends" character from 'listchars' if beyond the line end and
3024 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003025 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003026 && draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003027 && wp->w_p_list
3028 && !wp->w_p_wrap
3029#ifdef FEAT_DIFF
3030 && filler_todo <= 0
3031#endif
3032 && (
3033#ifdef FEAT_RIGHTLEFT
3034 wp->w_p_rl ? col == 0 :
3035#endif
3036 col == wp->w_width - 1)
3037 && (*ptr != NUL
3038 || (wp->w_p_list && lcs_eol_one > 0)
3039 || (n_extra && (c_extra != NUL || *p_extra != NUL))))
3040 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003041 c = wp->w_lcs_chars.ext;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01003042 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003043 mb_c = c;
3044 if (enc_utf8 && utf_char2len(c) > 1)
3045 {
3046 mb_utf8 = TRUE;
3047 u8cc[0] = 0;
3048 c = 0xc0;
3049 }
3050 else
3051 mb_utf8 = FALSE;
3052 }
3053
3054#ifdef FEAT_SYN_HL
3055 // advance to the next 'colorcolumn'
3056 if (draw_color_col)
3057 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
3058
3059 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3060 // highlight the cursor position itself.
3061 // Also highlight the 'colorcolumn' if it is different than
3062 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003063 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3064 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003065 vcol_save_attr = -1;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003066 if (((draw_state == WL_LINE ||
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003067 draw_state == WL_BRI ||
3068 draw_state == WL_SBR) && !lnum_in_visual_area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003069 && search_attr == 0 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003070# ifdef FEAT_DIFF
3071 && filler_todo <= 0
3072# endif
3073 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003074 {
3075 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3076 && lnum != wp->w_cursor.lnum)
3077 {
3078 vcol_save_attr = char_attr;
3079 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUC));
3080 }
3081 else if (draw_color_col && VCOL_HLC == *color_cols)
3082 {
3083 vcol_save_attr = char_attr;
3084 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_MC));
3085 }
3086 }
3087#endif
3088
3089 // Store character to be displayed.
3090 // Skip characters that are left of the screen for 'nowrap'.
3091 vcol_prev = vcol;
3092 if (draw_state < WL_LINE || n_skip <= 0)
3093 {
3094 // Store the character.
3095#if defined(FEAT_RIGHTLEFT)
3096 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3097 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003098 // A double-wide character is: put first half in left cell.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003099 --off;
3100 --col;
3101 }
3102#endif
3103 ScreenLines[off] = c;
3104 if (enc_dbcs == DBCS_JPNU)
3105 {
3106 if ((mb_c & 0xff00) == 0x8e00)
3107 ScreenLines[off] = 0x8e;
3108 ScreenLines2[off] = mb_c & 0xff;
3109 }
3110 else if (enc_utf8)
3111 {
3112 if (mb_utf8)
3113 {
3114 int i;
3115
3116 ScreenLinesUC[off] = mb_c;
3117 if ((c & 0xff) == 0)
3118 ScreenLines[off] = 0x80; // avoid storing zero
3119 for (i = 0; i < Screen_mco; ++i)
3120 {
3121 ScreenLinesC[i][off] = u8cc[i];
3122 if (u8cc[i] == 0)
3123 break;
3124 }
3125 }
3126 else
3127 ScreenLinesUC[off] = 0;
3128 }
3129 if (multi_attr)
3130 {
3131 ScreenAttrs[off] = multi_attr;
3132 multi_attr = 0;
3133 }
3134 else
3135 ScreenAttrs[off] = char_attr;
3136
Bram Moolenaarb9081882022-07-09 04:56:24 +01003137 ScreenCols[off] = (colnr_T)(prev_ptr - line);
3138
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003139 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3140 {
3141 // Need to fill two screen columns.
3142 ++off;
3143 ++col;
3144 if (enc_utf8)
3145 // UTF-8: Put a 0 in the second screen char.
3146 ScreenLines[off] = 0;
3147 else
3148 // DBCS: Put second byte in the second screen char.
3149 ScreenLines[off] = mb_c & 0xff;
3150 if (draw_state > WL_NR
3151#ifdef FEAT_DIFF
3152 && filler_todo <= 0
3153#endif
3154 )
3155 ++vcol;
3156 // When "tocol" is halfway a character, set it to the end of
3157 // the character, otherwise highlighting won't stop.
3158 if (tocol == vcol)
3159 ++tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003160
3161 ScreenCols[off] = (colnr_T)(prev_ptr - line);
3162
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003163#ifdef FEAT_RIGHTLEFT
3164 if (wp->w_p_rl)
3165 {
3166 // now it's time to backup one cell
3167 --off;
3168 --col;
3169 }
3170#endif
3171 }
3172#ifdef FEAT_RIGHTLEFT
3173 if (wp->w_p_rl)
3174 {
3175 --off;
3176 --col;
3177 }
3178 else
3179#endif
3180 {
3181 ++off;
3182 ++col;
3183 }
3184 }
3185#ifdef FEAT_CONCEAL
3186 else if (wp->w_p_cole > 0 && is_concealing)
3187 {
3188 --n_skip;
3189 ++vcol_off;
3190 if (n_extra > 0)
3191 vcol_off += n_extra;
3192 if (wp->w_p_wrap)
3193 {
3194 // Special voodoo required if 'wrap' is on.
3195 //
3196 // Advance the column indicator to force the line
3197 // drawing to wrap early. This will make the line
3198 // take up the same screen space when parts are concealed,
3199 // so that cursor line computations aren't messed up.
3200 //
3201 // To avoid the fictitious advance of 'col' causing
3202 // trailing junk to be written out of the screen line
3203 // we are building, 'boguscols' keeps track of the number
3204 // of bad columns we have advanced.
3205 if (n_extra > 0)
3206 {
3207 vcol += n_extra;
3208# ifdef FEAT_RIGHTLEFT
3209 if (wp->w_p_rl)
3210 {
3211 col -= n_extra;
3212 boguscols -= n_extra;
3213 }
3214 else
3215# endif
3216 {
3217 col += n_extra;
3218 boguscols += n_extra;
3219 }
3220 n_extra = 0;
3221 n_attr = 0;
3222 }
3223
3224
3225 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3226 {
3227 // Need to fill two screen columns.
3228# ifdef FEAT_RIGHTLEFT
3229 if (wp->w_p_rl)
3230 {
3231 --boguscols;
3232 --col;
3233 }
3234 else
3235# endif
3236 {
3237 ++boguscols;
3238 ++col;
3239 }
3240 }
3241
3242# ifdef FEAT_RIGHTLEFT
3243 if (wp->w_p_rl)
3244 {
3245 --boguscols;
3246 --col;
3247 }
3248 else
3249# endif
3250 {
3251 ++boguscols;
3252 ++col;
3253 }
3254 }
3255 else
3256 {
3257 if (n_extra > 0)
3258 {
3259 vcol += n_extra;
3260 n_extra = 0;
3261 n_attr = 0;
3262 }
3263 }
3264
3265 }
3266#endif // FEAT_CONCEAL
3267 else
3268 --n_skip;
3269
3270 // Only advance the "vcol" when after the 'number' or 'relativenumber'
3271 // column.
3272 if (draw_state > WL_NR
3273#ifdef FEAT_DIFF
3274 && filler_todo <= 0
3275#endif
3276 )
3277 ++vcol;
3278
3279#ifdef FEAT_SYN_HL
3280 if (vcol_save_attr >= 0)
3281 char_attr = vcol_save_attr;
3282#endif
3283
3284 // restore attributes after "predeces" in 'listchars'
3285 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3286 char_attr = saved_attr3;
3287
3288 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003289 if (n_attr > 0 && draw_state == WL_LINE
3290 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003291 char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003292 if (n_attr_skip > 0)
3293 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003294
3295 // At end of screen line and there is more to come: Display the line
3296 // so far. If there is no more to display it is caught above.
3297 if ((
3298#ifdef FEAT_RIGHTLEFT
3299 wp->w_p_rl ? (col < 0) :
3300#endif
3301 (col >= wp->w_width))
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003302 && (draw_state != WL_LINE
3303 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003304#ifdef FEAT_DIFF
3305 || filler_todo > 0
3306#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003307#ifdef FEAT_PROP_POPUP
3308 || text_prop_follows
3309#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003310 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
3311 && p_extra != at_end_str)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003312 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL)))
3313 )
3314 {
3315#ifdef FEAT_CONCEAL
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01003316 screen_line(wp, screen_row, wp->w_wincol, col - boguscols,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00003317 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003318 boguscols = 0;
3319#else
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01003320 screen_line(wp, screen_row, wp->w_wincol, col,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00003321 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003322#endif
3323 ++row;
3324 ++screen_row;
3325
3326 // When not wrapping and finished diff lines, or when displayed
3327 // '$' and highlighting until last column, break here.
3328 if ((!wp->w_p_wrap
3329#ifdef FEAT_DIFF
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003330 && filler_todo <= 0
3331#endif
3332#ifdef FEAT_PROP_POPUP
3333 && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003334#endif
3335 ) || lcs_eol_one == -1)
3336 break;
3337
3338 // When the window is too narrow draw all "@" lines.
3339 if (draw_state != WL_LINE
3340#ifdef FEAT_DIFF
3341 && filler_todo <= 0
3342#endif
3343 )
3344 {
3345 win_draw_end(wp, '@', ' ', TRUE, row, wp->w_height, HLF_AT);
3346 draw_vsep_win(wp, row);
3347 row = endrow;
3348 }
3349
3350 // When line got too long for screen break here.
3351 if (row == endrow)
3352 {
3353 ++row;
3354 break;
3355 }
3356
3357 if (screen_cur_row == screen_row - 1
3358#ifdef FEAT_DIFF
3359 && filler_todo <= 0
3360#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003361#ifdef FEAT_PROP_POPUP
3362 && !text_prop_follows
3363#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003364 && wp->w_width == Columns)
3365 {
3366 // Remember that the line wraps, used for modeless copy.
3367 LineWraps[screen_row - 1] = TRUE;
3368
3369 // Special trick to make copy/paste of wrapped lines work with
3370 // xterm/screen: write an extra character beyond the end of
3371 // the line. This will work with all terminal types
3372 // (regardless of the xn,am settings).
3373 // Only do this on a fast tty.
3374 // Only do this if the cursor is on the current line
3375 // (something has been written in it).
3376 // Don't do this for the GUI.
3377 // Don't do this for double-width characters.
3378 // Don't do this for a window not at the right screen border.
3379 if (p_tf
3380#ifdef FEAT_GUI
3381 && !gui.in_use
3382#endif
3383 && !(has_mbyte
3384 && ((*mb_off2cells)(LineOffset[screen_row],
3385 LineOffset[screen_row] + screen_Columns)
3386 == 2
3387 || (*mb_off2cells)(LineOffset[screen_row - 1]
3388 + (int)Columns - 2,
3389 LineOffset[screen_row] + screen_Columns)
3390 == 2)))
3391 {
3392 // First make sure we are at the end of the screen line,
3393 // then output the same character again to let the
3394 // terminal know about the wrap. If the terminal doesn't
3395 // auto-wrap, we overwrite the character.
3396 if (screen_cur_col != wp->w_width)
3397 screen_char(LineOffset[screen_row - 1]
3398 + (unsigned)Columns - 1,
3399 screen_row - 1, (int)(Columns - 1));
3400
3401 // When there is a multi-byte character, just output a
3402 // space to keep it simple.
3403 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
3404 screen_row - 1] + (Columns - 1)]) > 1)
3405 out_char(' ');
3406 else
3407 out_char(ScreenLines[LineOffset[screen_row - 1]
3408 + (Columns - 1)]);
3409 // force a redraw of the first char on the next line
3410 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1;
3411 screen_start(); // don't know where cursor is now
3412 }
3413 }
3414
3415 col = 0;
3416 off = (unsigned)(current_ScreenLine - ScreenLines);
3417#ifdef FEAT_RIGHTLEFT
3418 if (wp->w_p_rl)
3419 {
3420 col = wp->w_width - 1; // col is not used if breaking!
3421 off += col;
3422 }
3423#endif
3424
3425 // reset the drawing state for the start of a wrapped line
3426 draw_state = WL_START;
3427 saved_n_extra = n_extra;
3428 saved_p_extra = p_extra;
3429 saved_c_extra = c_extra;
3430 saved_c_final = c_final;
3431#ifdef FEAT_SYN_HL
3432 if (!(cul_screenline
3433# ifdef FEAT_DIFF
Bram Moolenaare7705982020-04-21 22:23:15 +02003434 && diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003435# endif
Bram Moolenaare7705982020-04-21 22:23:15 +02003436 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003437 saved_char_attr = char_attr;
3438 else
3439#endif
3440 saved_char_attr = 0;
3441 n_extra = 0;
Bram Moolenaareed9d462021-02-15 20:38:25 +01003442 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003443#ifdef FEAT_LINEBREAK
3444# ifdef FEAT_DIFF
3445 if (filler_todo <= 0)
3446# endif
3447 need_showbreak = TRUE;
3448#endif
3449#ifdef FEAT_DIFF
3450 --filler_todo;
3451 // When the filler lines are actually below the last line of the
3452 // file, don't draw the line itself, break here.
3453 if (filler_todo == 0 && wp->w_botfill)
3454 break;
3455#endif
3456 }
3457
3458 } // for every character in the line
3459
3460#ifdef FEAT_SPELL
3461 // After an empty line check first word for capital.
3462 if (*skipwhite(line) == NUL)
3463 {
3464 capcol_lnum = lnum + 1;
3465 cap_col = 0;
3466 }
3467#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003468#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003469 vim_free(text_props);
3470 vim_free(text_prop_idxs);
3471#endif
3472
3473 vim_free(p_extra_free);
3474 return row;
3475}