blob: 747a1e33b05febca6b5e51e7e7938f7f5cc08c66 [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;
211 proptype_T *pt1, *pt2;
212 colnr_T col1, col2;
213
214 idx1 = *(int *)s1;
215 idx2 = *(int *)s2;
216 pt1 = text_prop_type_by_id(current_buf, current_text_props[idx1].tp_type);
217 pt2 = text_prop_type_by_id(current_buf, current_text_props[idx2].tp_type);
218 if (pt1 == pt2)
219 return 0;
220 if (pt1 == NULL)
221 return -1;
222 if (pt2 == NULL)
223 return 1;
224 if (pt1->pt_priority != pt2->pt_priority)
225 return pt1->pt_priority > pt2->pt_priority ? 1 : -1;
226 col1 = current_text_props[idx1].tp_col;
227 col2 = current_text_props[idx2].tp_col;
228 return col1 == col2 ? 0 : col1 > col2 ? 1 : -1;
229}
230#endif
231
232/*
233 * Display line "lnum" of window 'wp' on the screen.
234 * Start at row "startrow", stop when "endrow" is reached.
235 * wp->w_virtcol needs to be valid.
236 *
237 * Return the number of last row the line occupies.
238 */
239 int
240win_line(
241 win_T *wp,
242 linenr_T lnum,
243 int startrow,
244 int endrow,
245 int nochange UNUSED, // not updating for changed text
246 int number_only) // only update the number column
247{
248 int col = 0; // visual column on screen
249 unsigned off; // offset in ScreenLines/ScreenAttrs
250 int c = 0; // init for GCC
251 long vcol = 0; // virtual column (for tabs)
252#ifdef FEAT_LINEBREAK
253 long vcol_sbr = -1; // virtual column after showbreak
254#endif
255 long vcol_prev = -1; // "vcol" of previous character
256 char_u *line; // current line
257 char_u *ptr; // current position in "line"
258 int row; // row in the window, excl w_winrow
259 int screen_row; // row on the screen, incl w_winrow
260
261 char_u extra[21]; // "%ld " and 'fdc' must fit in here
262 int n_extra = 0; // number of extra chars
263 char_u *p_extra = NULL; // string of extra chars, plus NUL
264 char_u *p_extra_free = NULL; // p_extra needs to be freed
265 int c_extra = NUL; // extra chars, all the same
266 int c_final = NUL; // final char, mandatory if set
267 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000268#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000269 int in_linebreak = FALSE; // n_extra set for showing linebreak
270#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200271 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100272 // displaying eol at end-of-line
273 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000274 int lcs_prec_todo = wp->w_lcs_chars.prec;
275 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200276
277 // saved "extra" items for when draw_state becomes WL_LINE (again)
278 int saved_n_extra = 0;
279 char_u *saved_p_extra = NULL;
280 int saved_c_extra = 0;
281 int saved_c_final = 0;
282 int saved_char_attr = 0;
283
284 int n_attr = 0; // chars with special attr
285 int saved_attr2 = 0; // char_attr saved for n_attr
286 int n_attr3 = 0; // chars with overruling special attr
287 int saved_attr3 = 0; // char_attr saved for n_attr3
288
289 int n_skip = 0; // nr of chars to skip for 'nowrap'
290
291 int fromcol = -10; // start of inverting
292 int tocol = MAXCOL; // end of inverting
293 int fromcol_prev = -2; // start of inverting after cursor
294 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200295 int lnum_in_visual_area = FALSE;
296 pos_T pos;
297 long v;
298
299 int char_attr = 0; // attributes for next character
300 int attr_pri = FALSE; // char_attr has priority
301 int area_highlighting = FALSE; // Visual or incsearch highlighting
302 // in this line
303 int vi_attr = 0; // attributes for Visual and incsearch
304 // highlighting
305 int wcr_attr = 0; // attributes from 'wincolor'
306 int win_attr = 0; // background for whole window, except
307 // margins and "~" lines.
308 int area_attr = 0; // attributes desired by highlighting
309 int search_attr = 0; // attributes desired by 'hlsearch'
310#ifdef FEAT_SYN_HL
311 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
312 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200313 int prev_syntax_col = -1; // column of prev_syntax_attr
314 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200315 int has_syntax = FALSE; // this buffer has syntax highl.
316 int save_did_emsg;
317 int draw_color_col = FALSE; // highlight colorcolumn
318 int *color_cols = NULL; // pointer to according columns array
319#endif
320 int eol_hl_off = 0; // 1 if highlighted char after EOL
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100321#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200322 int text_prop_count;
323 int text_prop_next = 0; // next text property to use
324 textprop_T *text_props = NULL;
325 int *text_prop_idxs = NULL;
326 int text_props_active = 0;
327 proptype_T *text_prop_type = NULL;
328 int text_prop_attr = 0;
329 int text_prop_combine = FALSE;
330#endif
331#ifdef FEAT_SPELL
332 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000333 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200334# define SPWORDLEN 150
335 char_u nextline[SPWORDLEN * 2];// text with start of the next line
336 int nextlinecol = 0; // column where nextline[] starts
337 int nextline_idx = 0; // index in nextline[] where next line
338 // starts
339 int spell_attr = 0; // attributes desired by spelling
340 int word_end = 0; // last byte with same spell_attr
341 static linenr_T checked_lnum = 0; // line number for "checked_col"
342 static int checked_col = 0; // column in "checked_lnum" up to which
343 // there are no spell errors
344 static int cap_col = -1; // column to check for Cap word
345 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
346 int cur_checked_col = 0; // checked column for current line
347#endif
348 int extra_check = 0; // has extra highlighting
349 int multi_attr = 0; // attributes desired by multibyte
350 int mb_l = 1; // multi-byte byte length
351 int mb_c = 0; // decoded multi-byte character
352 int mb_utf8 = FALSE; // screen char is UTF-8 char
353 int u8cc[MAX_MCO]; // composing UTF-8 chars
354#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
355 int filler_lines = 0; // nr of filler lines to be drawn
356 int filler_todo = 0; // nr of filler lines still to do + 1
Bram Moolenaar936dc602022-03-06 20:47:01 +0000357#else
358# define filler_lines 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200359#endif
360#ifdef FEAT_DIFF
361 hlf_T diff_hlf = (hlf_T)0; // type of diff highlighting
362 int change_start = MAXCOL; // first col of changed area
363 int change_end = -1; // last col of changed area
364#endif
365 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100366 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200367 int in_multispace = FALSE; // in multiple consecutive spaces
368 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200369#ifdef FEAT_LINEBREAK
370 int need_showbreak = FALSE; // overlong line, skipping first x
371 // chars
372#endif
373#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
374 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
375# define LINE_ATTR
376 int line_attr = 0; // attribute for the whole line
377 int line_attr_save;
378#endif
379#ifdef FEAT_SIGNS
380 int sign_present = FALSE;
381 sign_attrs_T sattr;
James McCoya80aad72021-12-22 19:45:28 +0000382 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200383#endif
384#ifdef FEAT_ARABIC
385 int prev_c = 0; // previous Arabic character
386 int prev_c1 = 0; // first composing char for prev_c
387#endif
388#if defined(LINE_ATTR)
389 int did_line_attr = 0;
390#endif
391#ifdef FEAT_TERMINAL
392 int get_term_attr = FALSE;
393#endif
394#ifdef FEAT_SYN_HL
395 int cul_attr = 0; // set when 'cursorline' active
396
397 // 'cursorlineopt' has "screenline" and cursor is in this line
398 int cul_screenline = FALSE;
399
400 // margin columns for the screen line, needed for when 'cursorlineopt'
401 // contains "screenline"
402 int left_curline_col = 0;
403 int right_curline_col = 0;
404#endif
405
406 // draw_state: items that are drawn in sequence:
407#define WL_START 0 // nothing done yet
408#ifdef FEAT_CMDWIN
kylo252ae6f1d82022-02-16 19:24:07 +0000409# define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200410#else
411# define WL_CMDLINE WL_START
412#endif
413#ifdef FEAT_FOLDING
kylo252ae6f1d82022-02-16 19:24:07 +0000414# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200415#else
416# define WL_FOLD WL_CMDLINE
417#endif
418#ifdef FEAT_SIGNS
kylo252ae6f1d82022-02-16 19:24:07 +0000419# define WL_SIGN (WL_FOLD + 1) // column for signs
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200420#else
421# define WL_SIGN WL_FOLD // column for signs
422#endif
kylo252ae6f1d82022-02-16 19:24:07 +0000423#define WL_NR (WL_SIGN + 1) // line number
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200424#ifdef FEAT_LINEBREAK
kylo252ae6f1d82022-02-16 19:24:07 +0000425# define WL_BRI (WL_NR + 1) // 'breakindent'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200426#else
427# define WL_BRI WL_NR
428#endif
429#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
kylo252ae6f1d82022-02-16 19:24:07 +0000430# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200431#else
432# define WL_SBR WL_BRI
433#endif
kylo252ae6f1d82022-02-16 19:24:07 +0000434#define WL_LINE (WL_SBR + 1) // text in the line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200435 int draw_state = WL_START; // what to draw next
436#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
437 int feedback_col = 0;
438 int feedback_old_attr = -1;
439#endif
440 int screen_line_flags = 0;
441
442#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
443 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000444 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200445#endif
446#ifdef FEAT_CONCEAL
447 int syntax_flags = 0;
448 int syntax_seqnr = 0;
449 int prev_syntax_id = 0;
450 int conceal_attr = HL_ATTR(HLF_CONCEAL);
451 int is_concealing = FALSE;
452 int boguscols = 0; // nonexistent columns added to force
453 // wrapping
454 int vcol_off = 0; // offset for concealed characters
455 int did_wcol = FALSE;
456 int old_boguscols = 0;
457# define VCOL_HLC (vcol - vcol_off)
458# define FIX_FOR_BOGUSCOLS \
459 { \
460 n_extra += vcol_off; \
461 vcol -= vcol_off; \
462 vcol_off = 0; \
463 col -= boguscols; \
464 old_boguscols = boguscols; \
465 boguscols = 0; \
466 }
467#else
468# define VCOL_HLC (vcol)
469#endif
470
471 if (startrow > endrow) // past the end already!
472 return startrow;
473
474 row = startrow;
475 screen_row = row + W_WINROW(wp);
476
477 if (!number_only)
478 {
479 // To speed up the loop below, set extra_check when there is linebreak,
480 // trailing white space and/or syntax processing to be done.
481#ifdef FEAT_LINEBREAK
482 extra_check = wp->w_p_lbr;
483#endif
484#ifdef FEAT_SYN_HL
485 if (syntax_present(wp) && !wp->w_s->b_syn_error
486# ifdef SYN_TIME_LIMIT
487 && !wp->w_s->b_syn_slow
488# endif
489 )
490 {
491 // Prepare for syntax highlighting in this line. When there is an
492 // error, stop syntax highlighting.
493 save_did_emsg = did_emsg;
494 did_emsg = FALSE;
495 syntax_start(wp, lnum);
496 if (did_emsg)
497 wp->w_s->b_syn_error = TRUE;
498 else
499 {
500 did_emsg = save_did_emsg;
501#ifdef SYN_TIME_LIMIT
502 if (!wp->w_s->b_syn_slow)
503#endif
504 {
505 has_syntax = TRUE;
506 extra_check = TRUE;
507 }
508 }
509 }
510
511 // Check for columns to display for 'colorcolumn'.
512 color_cols = wp->w_p_cc_cols;
513 if (color_cols != NULL)
514 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
515#endif
516
517#ifdef FEAT_TERMINAL
518 if (term_show_buffer(wp->w_buffer))
519 {
520 extra_check = TRUE;
521 get_term_attr = TRUE;
Bram Moolenaar219c7d02020-02-01 21:57:29 +0100522 win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200523 }
524#endif
525
526#ifdef FEAT_SPELL
527 if (wp->w_p_spell
528 && *wp->w_s->b_p_spl != NUL
529 && wp->w_s->b_langp.ga_len > 0
530 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
531 {
532 // Prepare for spell checking.
533 has_spell = TRUE;
534 extra_check = TRUE;
535
536 // Get the start of the next line, so that words that wrap to the
537 // next line are found too: "et<line-break>al.".
538 // Trick: skip a few chars for C/shell/Vim comments
539 nextline[SPWORDLEN] = NUL;
540 if (lnum < wp->w_buffer->b_ml.ml_line_count)
541 {
542 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
543 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
544 }
545
546 // When a word wrapped from the previous line the start of the
547 // current line is valid.
548 if (lnum == checked_lnum)
549 cur_checked_col = checked_col;
550 checked_lnum = 0;
551
552 // When there was a sentence end in the previous line may require a
553 // word starting with capital in this line. In line 1 always check
554 // the first word.
555 if (lnum != capcol_lnum)
556 cap_col = -1;
557 if (lnum == 1)
558 cap_col = 0;
559 capcol_lnum = 0;
560 }
561#endif
562
563 // handle Visual active in this window
564 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
565 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100566 pos_T *top, *bot;
567
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200568 if (LTOREQ_POS(curwin->w_cursor, VIsual))
569 {
570 // Visual is after curwin->w_cursor
571 top = &curwin->w_cursor;
572 bot = &VIsual;
573 }
574 else
575 {
576 // Visual is before curwin->w_cursor
577 top = &VIsual;
578 bot = &curwin->w_cursor;
579 }
580 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
581 if (VIsual_mode == Ctrl_V)
582 {
583 // block mode
584 if (lnum_in_visual_area)
585 {
586 fromcol = wp->w_old_cursor_fcol;
587 tocol = wp->w_old_cursor_lcol;
588 }
589 }
590 else
591 {
592 // non-block mode
593 if (lnum > top->lnum && lnum <= bot->lnum)
594 fromcol = 0;
595 else if (lnum == top->lnum)
596 {
597 if (VIsual_mode == 'V') // linewise
598 fromcol = 0;
599 else
600 {
601 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
602 if (gchar_pos(top) == NUL)
603 tocol = fromcol + 1;
604 }
605 }
606 if (VIsual_mode != 'V' && lnum == bot->lnum)
607 {
608 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
609 {
610 fromcol = -10;
611 tocol = MAXCOL;
612 }
613 else if (bot->col == MAXCOL)
614 tocol = MAXCOL;
615 else
616 {
617 pos = *bot;
618 if (*p_sel == 'e')
619 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
620 else
621 {
622 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
623 ++tocol;
624 }
625 }
626 }
627 }
628
629 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200630 if (!highlight_match && lnum == curwin->w_cursor.lnum
631 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200632#ifdef FEAT_GUI
633 && !gui.in_use
634#endif
635 )
636 noinvcur = TRUE;
637
638 // if inverting in this line set area_highlighting
639 if (fromcol >= 0)
640 {
641 area_highlighting = TRUE;
642 vi_attr = HL_ATTR(HLF_V);
643#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
644 if ((clip_star.available && !clip_star.owned
645 && clip_isautosel_star())
646 || (clip_plus.available && !clip_plus.owned
647 && clip_isautosel_plus()))
648 vi_attr = HL_ATTR(HLF_VNC);
649#endif
650 }
651 }
652
653 // handle 'incsearch' and ":s///c" highlighting
654 else if (highlight_match
655 && wp == curwin
656 && lnum >= curwin->w_cursor.lnum
657 && lnum <= curwin->w_cursor.lnum + search_match_lines)
658 {
659 if (lnum == curwin->w_cursor.lnum)
660 getvcol(curwin, &(curwin->w_cursor),
661 (colnr_T *)&fromcol, NULL, NULL);
662 else
663 fromcol = 0;
664 if (lnum == curwin->w_cursor.lnum + search_match_lines)
665 {
666 pos.lnum = lnum;
667 pos.col = search_match_endcol;
668 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
669 }
670 else
671 tocol = MAXCOL;
672 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100673 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200674 tocol = fromcol + 1;
675 area_highlighting = TRUE;
676 vi_attr = HL_ATTR(HLF_I);
677 }
678 }
679
680#ifdef FEAT_DIFF
681 filler_lines = diff_check(wp, lnum);
682 if (filler_lines < 0)
683 {
684 if (filler_lines == -1)
685 {
686 if (diff_find_change(wp, lnum, &change_start, &change_end))
687 diff_hlf = HLF_ADD; // added line
688 else if (change_start == 0)
689 diff_hlf = HLF_TXD; // changed text
690 else
691 diff_hlf = HLF_CHD; // changed line
692 }
693 else
694 diff_hlf = HLF_ADD; // added line
695 filler_lines = 0;
696 area_highlighting = TRUE;
697 }
698 if (lnum == wp->w_topline)
699 filler_lines = wp->w_topfill;
700 filler_todo = filler_lines;
701#endif
702
703#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +0100704 sign_present = buf_get_signattrs(wp, lnum, &sattr);
James McCoya80aad72021-12-22 19:45:28 +0000705 if (sign_present)
706 num_attr = sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200707#endif
708
709#ifdef LINE_ATTR
710# ifdef FEAT_SIGNS
711 // If this line has a sign with line highlighting set line_attr.
712 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200713 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200714# endif
715# if defined(FEAT_QUICKFIX)
716 // Highlight the current line in the quickfix window.
717 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
718 line_attr = HL_ATTR(HLF_QFL);
719# endif
720 if (line_attr != 0)
721 area_highlighting = TRUE;
722#endif
723
724 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
725 ptr = line;
726
727#ifdef FEAT_SPELL
728 if (has_spell && !number_only)
729 {
730 // For checking first word with a capital skip white space.
731 if (cap_col == 0)
732 cap_col = getwhitecols(line);
733
734 // To be able to spell-check over line boundaries copy the end of the
735 // current line into nextline[]. Above the start of the next line was
736 // copied to nextline[SPWORDLEN].
737 if (nextline[SPWORDLEN] == NUL)
738 {
739 // No next line or it is empty.
740 nextlinecol = MAXCOL;
741 nextline_idx = 0;
742 }
743 else
744 {
745 v = (long)STRLEN(line);
746 if (v < SPWORDLEN)
747 {
748 // Short line, use it completely and append the start of the
749 // next line.
750 nextlinecol = 0;
751 mch_memmove(nextline, line, (size_t)v);
752 STRMOVE(nextline + v, nextline + SPWORDLEN);
753 nextline_idx = v + 1;
754 }
755 else
756 {
757 // Long line, use only the last SPWORDLEN bytes.
758 nextlinecol = v - SPWORDLEN;
759 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
760 nextline_idx = SPWORDLEN + 1;
761 }
762 }
763 }
764#endif
765
766 if (wp->w_p_list)
767 {
Bram Moolenaareed9d462021-02-15 20:38:25 +0100768 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +0200769 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +0100770 || wp->w_lcs_chars.trail
771 || wp->w_lcs_chars.lead
772 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200773 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100774
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200775 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100776 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200777 {
778 trailcol = (colnr_T)STRLEN(ptr);
779 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
780 --trailcol;
781 trailcol += (colnr_T) (ptr - line);
782 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100783 // find end of leading whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100784 if (wp->w_lcs_chars.lead)
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100785 {
786 leadcol = 0;
787 while (VIM_ISWHITE(ptr[leadcol]))
788 ++leadcol;
789 if (ptr[leadcol] == NUL)
790 // in a line full of spaces all of them are treated as trailing
791 leadcol = (colnr_T)0;
792 else
793 // keep track of the first column not filled with spaces
794 leadcol += (colnr_T) (ptr - line) + 1;
795 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200796 }
797
798 wcr_attr = get_wcr_attr(wp);
799 if (wcr_attr != 0)
800 {
801 win_attr = wcr_attr;
802 area_highlighting = TRUE;
803 }
Bram Moolenaar34390282019-10-16 14:38:26 +0200804
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100805#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200806 if (WIN_IS_POPUP(wp))
807 screen_line_flags |= SLF_POPUP;
808#endif
809
810 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
811 // first character to be displayed.
812 if (wp->w_p_wrap)
813 v = wp->w_skipcol;
814 else
815 v = wp->w_leftcol;
816 if (v > 0 && !number_only)
817 {
818 char_u *prev_ptr = ptr;
819
820 while (vcol < v && *ptr != NUL)
821 {
822 c = win_lbr_chartabsize(wp, line, ptr, (colnr_T)vcol, NULL);
823 vcol += c;
824 prev_ptr = ptr;
825 MB_PTR_ADV(ptr);
826 }
827
828 // When:
829 // - 'cuc' is set, or
830 // - 'colorcolumn' is set, or
831 // - 'virtualedit' is set, or
832 // - the visual mode is active,
833 // the end of the line may be before the start of the displayed part.
834 if (vcol < v && (
835#ifdef FEAT_SYN_HL
836 wp->w_p_cuc || draw_color_col ||
837#endif
838 virtual_active() ||
839 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
840 vcol = v;
841
842 // Handle a character that's not completely on the screen: Put ptr at
843 // that character but skip the first few screen characters.
844 if (vcol > v)
845 {
846 vcol -= c;
847 ptr = prev_ptr;
848 // If the character fits on the screen, don't need to skip it.
849 // Except for a TAB.
850 if (( (*mb_ptr2cells)(ptr) >= c || *ptr == TAB) && col == 0)
851 n_skip = v - vcol;
852 }
853
854 // Adjust for when the inverted text is before the screen,
855 // and when the start of the inverted text is before the screen.
856 if (tocol <= vcol)
857 fromcol = 0;
858 else if (fromcol >= 0 && fromcol < vcol)
859 fromcol = vcol;
860
861#ifdef FEAT_LINEBREAK
862 // When w_skipcol is non-zero, first line needs 'showbreak'
863 if (wp->w_p_wrap)
864 need_showbreak = TRUE;
865#endif
866#ifdef FEAT_SPELL
867 // When spell checking a word we need to figure out the start of the
868 // word and if it's badly spelled or not.
869 if (has_spell)
870 {
871 int len;
872 colnr_T linecol = (colnr_T)(ptr - line);
873 hlf_T spell_hlf = HLF_COUNT;
874
875 pos = wp->w_cursor;
876 wp->w_cursor.lnum = lnum;
877 wp->w_cursor.col = linecol;
878 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
879
880 // spell_move_to() may call ml_get() and make "line" invalid
881 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
882 ptr = line + linecol;
883
884 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
885 {
886 // no bad word found at line start, don't check until end of a
887 // word
888 spell_hlf = HLF_COUNT;
889 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
890 }
891 else
892 {
893 // bad word found, use attributes until end of word
894 word_end = wp->w_cursor.col + len + 1;
895
896 // Turn index into actual attributes.
897 if (spell_hlf != HLF_COUNT)
898 spell_attr = highlight_attr[spell_hlf];
899 }
900 wp->w_cursor = pos;
901
902# ifdef FEAT_SYN_HL
903 // Need to restart syntax highlighting for this line.
904 if (has_syntax)
905 syntax_start(wp, lnum);
906# endif
907 }
908#endif
909 }
910
911 // Correct highlighting for cursor that can't be disabled.
912 // Avoids having to check this for each character.
913 if (fromcol >= 0)
914 {
915 if (noinvcur)
916 {
917 if ((colnr_T)fromcol == wp->w_virtcol)
918 {
919 // highlighting starts at cursor, let it start just after the
920 // cursor
921 fromcol_prev = fromcol;
922 fromcol = -1;
923 }
924 else if ((colnr_T)fromcol < wp->w_virtcol)
925 // restart highlighting after the cursor
926 fromcol_prev = wp->w_virtcol;
927 }
928 if (fromcol >= tocol)
929 fromcol = -1;
930 }
931
932#ifdef FEAT_SEARCH_EXTRA
933 if (!number_only)
934 {
935 v = (long)(ptr - line);
936 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
937 &line, &screen_search_hl,
938 &search_attr);
939 ptr = line + v; // "line" may have been updated
940 }
941#endif
942
943#ifdef FEAT_SYN_HL
944 // Cursor line highlighting for 'cursorline' in the current window.
945 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
946 {
947 // Do not show the cursor line in the text when Visual mode is active,
948 // because it's not clear what is selected then. Do update
949 // w_last_cursorline.
950 if (!(wp == curwin && VIsual_active)
951 && wp->w_p_culopt_flags != CULOPT_NBR)
952 {
953 cul_screenline = (wp->w_p_wrap
954 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
955
956 // Only set line_attr here when "screenline" is not present in
957 // 'cursorlineopt'. Otherwise it's done later.
958 if (!cul_screenline)
959 {
960 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +0200961# ifdef FEAT_SIGNS
962 // Combine the 'cursorline' and sign highlighting, depending on
963 // the sign priority.
964 if (sign_present && sattr.sat_linehl > 0)
965 {
966 if (sattr.sat_priority >= 100)
967 line_attr = hl_combine_attr(cul_attr, line_attr);
968 else
969 line_attr = hl_combine_attr(line_attr, cul_attr);
970 }
971 else
972# endif
973 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200974 wp->w_last_cursorline = wp->w_cursor.lnum;
975 }
976 else
977 {
978 line_attr_save = line_attr;
979 wp->w_last_cursorline = 0;
980 margin_columns_win(wp, &left_curline_col, &right_curline_col);
981 }
982 area_highlighting = TRUE;
983 }
984 else
985 wp->w_last_cursorline = wp->w_cursor.lnum;
986 }
987#endif
988
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100989#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200990 {
991 char_u *prop_start;
992
993 text_prop_count = get_text_props(wp->w_buffer, lnum,
994 &prop_start, FALSE);
995 if (text_prop_count > 0)
996 {
997 // Make a copy of the properties, so that they are properly
998 // aligned.
999 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1000 if (text_props != NULL)
1001 mch_memmove(text_props, prop_start,
1002 text_prop_count * sizeof(textprop_T));
1003
1004 // Allocate an array for the indexes.
1005 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1006 area_highlighting = TRUE;
1007 extra_check = TRUE;
1008 }
1009 }
1010#endif
1011
1012 off = (unsigned)(current_ScreenLine - ScreenLines);
1013 col = 0;
1014
1015#ifdef FEAT_RIGHTLEFT
1016 if (wp->w_p_rl)
1017 {
1018 // Rightleft window: process the text in the normal direction, but put
1019 // it in current_ScreenLine[] from right to left. Start at the
1020 // rightmost column of the window.
1021 col = wp->w_width - 1;
1022 off += col;
1023 screen_line_flags |= SLF_RIGHTLEFT;
1024 }
1025#endif
1026
1027 // Repeat for the whole displayed line.
1028 for (;;)
1029 {
1030#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02001031 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001032#endif
1033#ifdef FEAT_CONCEAL
1034 int did_decrement_ptr = FALSE;
1035#endif
1036 // Skip this quickly when working on the text.
1037 if (draw_state != WL_LINE)
1038 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001039#ifdef FEAT_SYN_HL
1040 if (cul_screenline)
1041 {
1042 cul_attr = 0;
1043 line_attr = line_attr_save;
1044 }
1045#endif
1046
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001047#ifdef FEAT_CMDWIN
1048 if (draw_state == WL_CMDLINE - 1 && n_extra == 0)
1049 {
1050 draw_state = WL_CMDLINE;
1051 if (cmdwin_type != 0 && wp == curwin)
1052 {
1053 // Draw the cmdline character.
1054 n_extra = 1;
1055 c_extra = cmdwin_type;
1056 c_final = NUL;
1057 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
1058 }
1059 }
1060#endif
1061
1062#ifdef FEAT_FOLDING
1063 if (draw_state == WL_FOLD - 1 && n_extra == 0)
1064 {
1065 int fdc = compute_foldcolumn(wp, 0);
1066
1067 draw_state = WL_FOLD;
1068 if (fdc > 0)
1069 {
1070 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1071 // already be in use.
1072 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001073 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001074 if (p_extra_free != NULL)
1075 {
Bram Moolenaar9355ae42021-03-08 19:04:05 +01001076 n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001077 FALSE, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001078 p_extra_free[n_extra] = NUL;
1079 p_extra = p_extra_free;
1080 c_extra = NUL;
1081 c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001082 if (use_cursor_line_sign(wp, lnum))
1083 char_attr =
1084 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1085 else
1086 char_attr =
1087 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001088 }
1089 }
1090 }
1091#endif
1092
1093#ifdef FEAT_SIGNS
1094 if (draw_state == WL_SIGN - 1 && n_extra == 0)
1095 {
1096 draw_state = WL_SIGN;
1097 // Show the sign column when there are any signs in this
1098 // buffer or when using Netbeans.
1099 if (signcolumn_on(wp))
1100 get_sign_display_info(FALSE, wp, lnum, &sattr, wcr_attr,
1101 row, startrow, filler_lines, filler_todo, &c_extra,
1102 &c_final, extra, &p_extra, &n_extra, &char_attr);
1103 }
1104#endif
1105
1106 if (draw_state == WL_NR - 1 && n_extra == 0)
1107 {
1108 draw_state = WL_NR;
1109 // Display the absolute or relative line number. After the
1110 // first fill with blanks when the 'n' flag isn't in 'cpo'
1111 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar936dc602022-03-06 20:47:01 +00001112 && (row == startrow + filler_lines
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001113 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
1114 {
1115#ifdef FEAT_SIGNS
1116 // If 'signcolumn' is set to 'number' and a sign is present
1117 // in 'lnum', then display the sign instead of the line
1118 // number.
1119 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1120 && sign_present)
1121 get_sign_display_info(TRUE, wp, lnum, &sattr, wcr_attr,
1122 row, startrow, filler_lines, filler_todo,
1123 &c_extra, &c_final, extra, &p_extra, &n_extra,
1124 &char_attr);
1125 else
1126#endif
1127 {
1128 // Draw the line number (empty space after wrapping).
Bram Moolenaar936dc602022-03-06 20:47:01 +00001129 if (row == startrow + filler_lines)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001130 {
1131 long num;
1132 char *fmt = "%*ld ";
1133
1134 if (wp->w_p_nu && !wp->w_p_rnu)
1135 // 'number' + 'norelativenumber'
1136 num = (long)lnum;
1137 else
1138 {
1139 // 'relativenumber', don't use negative numbers
1140 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1141 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1142 {
1143 // 'number' + 'relativenumber'
1144 num = lnum;
1145 fmt = "%-*ld ";
1146 }
1147 }
1148
1149 sprintf((char *)extra, fmt,
1150 number_width(wp), num);
1151 if (wp->w_skipcol > 0)
1152 for (p_extra = extra; *p_extra == ' '; ++p_extra)
1153 *p_extra = '-';
1154#ifdef FEAT_RIGHTLEFT
1155 if (wp->w_p_rl) // reverse line numbers
1156 {
1157 char_u *p1, *p2;
1158 int t;
1159
1160 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001161 p2 = skipwhite(extra);
1162 p2 = skiptowhite(p2) - 1;
1163 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001164 {
1165 t = *p1;
1166 *p1 = *p2;
1167 *p2 = t;
1168 }
1169 }
1170#endif
1171 p_extra = extra;
1172 c_extra = NUL;
1173 c_final = NUL;
1174 }
1175 else
1176 {
1177 c_extra = ' ';
1178 c_final = NUL;
1179 }
1180 n_extra = number_width(wp) + 1;
1181 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
1182#ifdef FEAT_SYN_HL
1183 // When 'cursorline' is set highlight the line number of
1184 // the current line differently.
zeertzjq754d2b42022-03-13 13:40:45 +00001185 // When 'cursorlineopt' does not have "line" only
1186 // highlight the line number itself.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001187 // TODO: Can we use CursorLine instead of CursorLineNr
1188 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001189 if (wp->w_p_cul
1190 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001191 && (wp->w_p_culopt_flags & CULOPT_NBR)
Bram Moolenaar127969c2022-03-06 19:54:13 +00001192 && (row == startrow + filler_lines
1193 || (row > startrow + filler_lines
zeertzjq754d2b42022-03-13 13:40:45 +00001194 && (wp->w_p_culopt_flags & CULOPT_LINE))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001195 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLN));
1196#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001197 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1198 && HL_ATTR(HLF_LNA) != 0)
1199 // Use LineNrAbove
1200 char_attr = hl_combine_attr(wcr_attr,
1201 HL_ATTR(HLF_LNA));
1202 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1203 && HL_ATTR(HLF_LNB) != 0)
1204 // Use LineNrBelow
1205 char_attr = hl_combine_attr(wcr_attr,
1206 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001207 }
James McCoya80aad72021-12-22 19:45:28 +00001208#ifdef FEAT_SIGNS
1209 if (num_attr)
1210 char_attr = num_attr;
1211#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001212 }
1213 }
1214
1215#ifdef FEAT_LINEBREAK
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001216 if (wp->w_briopt_sbr && draw_state == WL_BRI - 1
Bram Moolenaaree857022019-11-09 23:26:40 +01001217 && n_extra == 0 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001218 // draw indent after showbreak value
1219 draw_state = WL_BRI;
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001220 else if (wp->w_briopt_sbr && draw_state == WL_SBR && n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001221 // After the showbreak, draw the breakindent
1222 draw_state = WL_BRI - 1;
1223
1224 // draw 'breakindent': indent wrapped text accordingly
1225 if (draw_state == WL_BRI - 1 && n_extra == 0)
1226 {
1227 draw_state = WL_BRI;
1228 // if need_showbreak is set, breakindent also applies
Bram Moolenaarfe154992022-03-22 20:42:12 +00001229 if (wp->w_p_bri && (row != startrow || need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001230# ifdef FEAT_DIFF
1231 && filler_lines == 0
1232# endif
1233 )
1234 {
1235 char_attr = 0;
1236# ifdef FEAT_DIFF
1237 if (diff_hlf != (hlf_T)0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001238 char_attr = HL_ATTR(diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001239# endif
1240 p_extra = NULL;
1241 c_extra = ' ';
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001242 c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001243 n_extra = get_breakindent_win(wp,
1244 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001245 if (row == startrow)
1246 {
1247 n_extra -= win_col_off2(wp);
1248 if (n_extra < 0)
1249 n_extra = 0;
1250 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001251 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001252 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001253 // Correct end of highlighted area for 'breakindent',
1254 // required when 'linebreak' is also set.
1255 if (tocol == vcol)
1256 tocol += n_extra;
1257 }
1258 }
1259#endif
1260
1261#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
1262 if (draw_state == WL_SBR - 1 && n_extra == 0)
1263 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001264 char_u *sbr;
1265
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001266 draw_state = WL_SBR;
1267# ifdef FEAT_DIFF
1268 if (filler_todo > 0)
1269 {
1270 // Draw "deleted" diff line(s).
1271 if (char2cells(fill_diff) > 1)
1272 {
1273 c_extra = '-';
1274 c_final = NUL;
1275 }
1276 else
1277 {
1278 c_extra = fill_diff;
1279 c_final = NUL;
1280 }
1281# ifdef FEAT_RIGHTLEFT
1282 if (wp->w_p_rl)
1283 n_extra = col + 1;
1284 else
1285# endif
1286 n_extra = wp->w_width - col;
1287 char_attr = HL_ATTR(HLF_DED);
1288 }
1289# endif
1290# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001291 sbr = get_showbreak_value(wp);
1292 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001293 {
1294 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaaree857022019-11-09 23:26:40 +01001295 p_extra = sbr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001296 c_extra = NUL;
1297 c_final = NUL;
Bram Moolenaaree857022019-11-09 23:26:40 +01001298 n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001299 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1300 need_showbreak = FALSE;
Bram Moolenaaree857022019-11-09 23:26:40 +01001301 vcol_sbr = vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001302 // Correct end of highlighted area for 'showbreak',
1303 // required when 'linebreak' is also set.
1304 if (tocol == vcol)
1305 tocol += n_extra;
1306 // combine 'showbreak' with 'wincolor'
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001307 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001308# ifdef FEAT_SYN_HL
1309 // combine 'showbreak' with 'cursorline'
1310 if (cul_attr != 0)
1311 char_attr = hl_combine_attr(char_attr, cul_attr);
1312# endif
1313 }
1314# endif
1315 }
1316#endif
1317
1318 if (draw_state == WL_LINE - 1 && n_extra == 0)
1319 {
1320 draw_state = WL_LINE;
1321 if (saved_n_extra)
1322 {
1323 // Continue item from end of wrapped line.
1324 n_extra = saved_n_extra;
1325 c_extra = saved_c_extra;
1326 c_final = saved_c_final;
1327 p_extra = saved_p_extra;
1328 char_attr = saved_char_attr;
1329 }
1330 else
1331 char_attr = win_attr;
1332 }
1333 }
1334#ifdef FEAT_SYN_HL
zeertzjq4f33bc22021-08-05 17:57:02 +02001335 if (cul_screenline && draw_state == WL_LINE
1336 && vcol >= left_curline_col
1337 && vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001338 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001339 cul_attr = HL_ATTR(HLF_CUL);
1340 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001341 }
1342#endif
1343
1344 // When still displaying '$' of change command, stop at cursor.
1345 // When only displaying the (relative) line number and that's done,
1346 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001347 if (((dollar_vcol >= 0 && wp == curwin
1348 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol)
1349 || (number_only && draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001350#ifdef FEAT_DIFF
1351 && filler_todo <= 0
1352#endif
1353 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001354 {
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00001355 screen_line(screen_row, wp->w_wincol, col, -wp->w_width,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001356 screen_line_flags);
1357 // Pretend we have finished updating the window. Except when
1358 // 'cursorcolumn' is set.
1359#ifdef FEAT_SYN_HL
1360 if (wp->w_p_cuc)
1361 row = wp->w_cline_row + wp->w_cline_height;
1362 else
1363#endif
1364 row = wp->w_height;
1365 break;
1366 }
1367
Bram Moolenaar34390282019-10-16 14:38:26 +02001368 if (draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001369 {
1370 // handle Visual or match highlighting in this line
1371 if (vcol == fromcol
1372 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0
1373 && (*mb_ptr2cells)(ptr) > 1)
1374 || ((int)vcol_prev == fromcol_prev
1375 && vcol_prev < vcol // not at margin
1376 && vcol < tocol))
1377 area_attr = vi_attr; // start highlighting
1378 else if (area_attr != 0
1379 && (vcol == tocol
1380 || (noinvcur && (colnr_T)vcol == wp->w_virtcol)))
1381 area_attr = 0; // stop highlighting
1382
1383#ifdef FEAT_SEARCH_EXTRA
1384 if (!n_extra)
1385 {
1386 // Check for start/end of 'hlsearch' and other matches.
1387 // After end, check for start/end of next match.
1388 // When another match, have to check for start again.
1389 v = (long)(ptr - line);
1390 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1391 &screen_search_hl, &has_match_conc,
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001392 &match_conc, did_line_attr, lcs_eol_one,
1393 &on_last_col);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001394 ptr = line + v; // "line" may have been changed
Bram Moolenaarfc838d62020-06-25 22:23:48 +02001395
1396 // Do not allow a conceal over EOL otherwise EOL will be missed
1397 // and bad things happen.
1398 if (*ptr == NUL)
1399 has_match_conc = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001400 }
1401#endif
1402
1403#ifdef FEAT_DIFF
1404 if (diff_hlf != (hlf_T)0)
1405 {
1406 if (diff_hlf == HLF_CHD && ptr - line >= change_start
1407 && n_extra == 0)
1408 diff_hlf = HLF_TXD; // changed text
1409 if (diff_hlf == HLF_TXD && ptr - line > change_end
1410 && n_extra == 0)
1411 diff_hlf = HLF_CHD; // changed line
1412 line_attr = HL_ATTR(diff_hlf);
1413 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1414 && wp->w_p_culopt_flags != CULOPT_NBR
1415 && (!cul_screenline || (vcol >= left_curline_col
1416 && vcol <= right_curline_col)))
1417 line_attr = hl_combine_attr(
1418 line_attr, HL_ATTR(HLF_CUL));
1419 }
1420#endif
1421
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001422#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001423 if (text_props != NULL)
1424 {
1425 int pi;
1426 int bcol = (int)(ptr - line);
1427
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001428 if (n_extra > 0
1429# ifdef FEAT_LINEBREAK
1430 && !in_linebreak
1431# endif
1432 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001433 --bcol; // still working on the previous char, e.g. Tab
1434
1435 // Check if any active property ends.
1436 for (pi = 0; pi < text_props_active; ++pi)
1437 {
1438 int tpi = text_prop_idxs[pi];
1439
1440 if (bcol >= text_props[tpi].tp_col - 1
1441 + text_props[tpi].tp_len)
1442 {
1443 if (pi + 1 < text_props_active)
1444 mch_memmove(text_prop_idxs + pi,
1445 text_prop_idxs + pi + 1,
1446 sizeof(int)
1447 * (text_props_active - (pi + 1)));
1448 --text_props_active;
1449 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001450# ifdef FEAT_LINEBREAK
1451 // not exactly right but should work in most cases
1452 if (in_linebreak && syntax_attr == text_prop_attr)
1453 syntax_attr = 0;
1454# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001455 }
1456 }
1457
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001458# ifdef FEAT_LINEBREAK
1459 if (n_extra > 0 && in_linebreak)
1460 // not on the next char yet, don't start another prop
1461 --bcol;
1462# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001463 // Add any text property that starts in this column.
1464 while (text_prop_next < text_prop_count
1465 && bcol >= text_props[text_prop_next].tp_col - 1)
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001466 {
1467 if (bcol <= text_props[text_prop_next].tp_col - 1
1468 + text_props[text_prop_next].tp_len)
1469 text_prop_idxs[text_props_active++] = text_prop_next;
1470 ++text_prop_next;
1471 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001472
1473 text_prop_attr = 0;
1474 text_prop_combine = FALSE;
Bram Moolenaar053f7122019-09-23 22:17:15 +02001475 text_prop_type = NULL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001476 if (text_props_active > 0)
1477 {
1478 // Sort the properties on priority and/or starting last.
1479 // Then combine the attributes, highest priority last.
1480 current_text_props = text_props;
1481 current_buf = wp->w_buffer;
1482 qsort((void *)text_prop_idxs, (size_t)text_props_active,
1483 sizeof(int), text_prop_compare);
1484
1485 for (pi = 0; pi < text_props_active; ++pi)
1486 {
1487 int tpi = text_prop_idxs[pi];
1488 proptype_T *pt = text_prop_type_by_id(
1489 wp->w_buffer, text_props[tpi].tp_type);
1490
1491 if (pt != NULL && pt->pt_hl_id > 0)
1492 {
1493 int pt_attr = syn_id2attr(pt->pt_hl_id);
1494
1495 text_prop_type = pt;
1496 text_prop_attr =
1497 hl_combine_attr(text_prop_attr, pt_attr);
1498 text_prop_combine = pt->pt_flags & PT_FLAG_COMBINE;
1499 }
1500 }
1501 }
1502 }
1503#endif
1504
Bram Moolenaara74fda62019-10-19 17:38:03 +02001505#ifdef FEAT_SYN_HL
Bram Moolenaara74fda62019-10-19 17:38:03 +02001506 if (extra_check && n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001507 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001508 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001509# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001510 if (get_term_attr)
Bram Moolenaar219c7d02020-02-01 21:57:29 +01001511 syntax_attr = term_get_attr(wp, lnum, vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001512# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001513 // Get syntax attribute.
1514 if (has_syntax)
1515 {
1516 // Get the syntax attribute for the character. If there
1517 // is an error, disable syntax highlighting.
1518 save_did_emsg = did_emsg;
1519 did_emsg = FALSE;
1520
1521 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001522 if (v == prev_syntax_col)
1523 // at same column again
1524 syntax_attr = prev_syntax_attr;
1525 else
1526 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001527# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001528 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001529# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001530 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001531# ifdef FEAT_SPELL
1532 has_spell ? &can_spell :
1533# endif
1534 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001535 prev_syntax_col = v;
1536 prev_syntax_attr = syntax_attr;
1537 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001538
Bram Moolenaar34390282019-10-16 14:38:26 +02001539 if (did_emsg)
1540 {
1541 wp->w_s->b_syn_error = TRUE;
1542 has_syntax = FALSE;
1543 syntax_attr = 0;
1544 }
1545 else
1546 did_emsg = save_did_emsg;
1547# ifdef SYN_TIME_LIMIT
1548 if (wp->w_s->b_syn_slow)
1549 has_syntax = FALSE;
1550# endif
1551
1552 // Need to get the line again, a multi-line regexp may
1553 // have made it invalid.
1554 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1555 ptr = line + v;
1556# ifdef FEAT_CONCEAL
1557 // no concealing past the end of the line, it interferes
1558 // with line highlighting
1559 if (*ptr == NUL)
1560 syntax_flags = 0;
1561 else
1562 syntax_flags = get_syntax_info(&syntax_seqnr);
1563# endif
1564 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001565 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001566# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001567 // Combine text property highlight into syntax highlight.
1568 if (text_prop_type != NULL)
1569 {
1570 if (text_prop_combine)
1571 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1572 else
1573 syntax_attr = text_prop_attr;
1574 }
1575# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001576#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001577
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001578 // Decide which of the highlight attributes to use.
1579 attr_pri = TRUE;
1580#ifdef LINE_ATTR
1581 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001582 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001583 char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02001584 if (!highlight_match)
1585 // let search highlight show in Visual area if possible
1586 char_attr = hl_combine_attr(search_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001587# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001588 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001589# endif
1590 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001591 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001592 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001593 char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001594# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001595 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001596# endif
1597 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001598 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
1599 || vcol < fromcol || vcol_prev < fromcol_prev
1600 || vcol >= tocol))
1601 {
1602 // Use line_attr when not in the Visual or 'incsearch' area
1603 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001604# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001605 char_attr = hl_combine_attr(syntax_attr, line_attr);
1606# else
1607 char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001608# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001609 attr_pri = FALSE;
1610 }
1611#else
1612 if (area_attr != 0)
1613 char_attr = area_attr;
1614 else if (search_attr != 0)
1615 char_attr = search_attr;
1616#endif
1617 else
1618 {
1619 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001620#ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001621 char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001622#else
Bram Moolenaardbd43162019-11-09 21:28:14 +01001623 char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001624#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001625 }
1626 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001627
1628 // combine attribute with 'wincolor'
1629 if (win_attr != 0)
1630 {
1631 if (char_attr == 0)
1632 char_attr = win_attr;
1633 else
1634 char_attr = hl_combine_attr(win_attr, char_attr);
1635 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001636
1637 // Get the next character to put on the screen.
1638
1639 // The "p_extra" points to the extra stuff that is inserted to
1640 // represent special characters (non-printable stuff) and other
1641 // things. When all characters are the same, c_extra is used.
1642 // If c_final is set, it will compulsorily be used at the end.
1643 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
1644 // "p_extra[n_extra]".
1645 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
1646 if (n_extra > 0)
1647 {
1648 if (c_extra != NUL || (n_extra == 1 && c_final != NUL))
1649 {
1650 c = (n_extra == 1 && c_final != NUL) ? c_final : c_extra;
1651 mb_c = c; // doesn't handle non-utf-8 multi-byte!
1652 if (enc_utf8 && utf_char2len(c) > 1)
1653 {
1654 mb_utf8 = TRUE;
1655 u8cc[0] = 0;
1656 c = 0xc0;
1657 }
1658 else
1659 mb_utf8 = FALSE;
1660 }
1661 else
1662 {
1663 c = *p_extra;
1664 if (has_mbyte)
1665 {
1666 mb_c = c;
1667 if (enc_utf8)
1668 {
1669 // If the UTF-8 character is more than one byte:
1670 // Decode it into "mb_c".
1671 mb_l = utfc_ptr2len(p_extra);
1672 mb_utf8 = FALSE;
1673 if (mb_l > n_extra)
1674 mb_l = 1;
1675 else if (mb_l > 1)
1676 {
1677 mb_c = utfc_ptr2char(p_extra, u8cc);
1678 mb_utf8 = TRUE;
1679 c = 0xc0;
1680 }
1681 }
1682 else
1683 {
1684 // if this is a DBCS character, put it in "mb_c"
1685 mb_l = MB_BYTE2LEN(c);
1686 if (mb_l >= n_extra)
1687 mb_l = 1;
1688 else if (mb_l > 1)
1689 mb_c = (c << 8) + p_extra[1];
1690 }
1691 if (mb_l == 0) // at the NUL at end-of-line
1692 mb_l = 1;
1693
1694 // If a double-width char doesn't fit display a '>' in the
1695 // last column.
1696 if ((
1697# ifdef FEAT_RIGHTLEFT
1698 wp->w_p_rl ? (col <= 0) :
1699# endif
1700 (col >= wp->w_width - 1))
1701 && (*mb_char2cells)(mb_c) == 2)
1702 {
1703 c = '>';
1704 mb_c = c;
1705 mb_l = 1;
1706 mb_utf8 = FALSE;
1707 multi_attr = HL_ATTR(HLF_AT);
1708#ifdef FEAT_SYN_HL
1709 if (cul_attr)
1710 multi_attr = hl_combine_attr(multi_attr, cul_attr);
1711#endif
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001712 multi_attr = hl_combine_attr(win_attr, multi_attr);
1713
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001714 // put the pointer back to output the double-width
1715 // character at the start of the next line.
1716 ++n_extra;
1717 --p_extra;
1718 }
1719 else
1720 {
1721 n_extra -= mb_l - 1;
1722 p_extra += mb_l - 1;
1723 }
1724 }
1725 ++p_extra;
1726 }
1727 --n_extra;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001728#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001729 if (n_extra <= 0)
1730 in_linebreak = FALSE;
1731#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001732 }
1733 else
1734 {
1735#ifdef FEAT_LINEBREAK
1736 int c0;
1737#endif
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001738 VIM_CLEAR(p_extra_free);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001739
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001740 // Get a character from the line itself.
1741 c = *ptr;
1742#ifdef FEAT_LINEBREAK
1743 c0 = *ptr;
1744#endif
1745 if (has_mbyte)
1746 {
1747 mb_c = c;
1748 if (enc_utf8)
1749 {
1750 // If the UTF-8 character is more than one byte: Decode it
1751 // into "mb_c".
1752 mb_l = utfc_ptr2len(ptr);
1753 mb_utf8 = FALSE;
1754 if (mb_l > 1)
1755 {
1756 mb_c = utfc_ptr2char(ptr, u8cc);
1757 // Overlong encoded ASCII or ASCII with composing char
1758 // is displayed normally, except a NUL.
1759 if (mb_c < 0x80)
1760 {
1761 c = mb_c;
1762#ifdef FEAT_LINEBREAK
1763 c0 = mb_c;
1764#endif
1765 }
1766 mb_utf8 = TRUE;
1767
1768 // At start of the line we can have a composing char.
1769 // Draw it as a space with a composing char.
1770 if (utf_iscomposing(mb_c))
1771 {
1772 int i;
1773
1774 for (i = Screen_mco - 1; i > 0; --i)
1775 u8cc[i] = u8cc[i - 1];
1776 u8cc[0] = mb_c;
1777 mb_c = ' ';
1778 }
1779 }
1780
1781 if ((mb_l == 1 && c >= 0x80)
1782 || (mb_l >= 1 && mb_c == 0)
1783 || (mb_l > 1 && (!vim_isprintc(mb_c))))
1784 {
1785 // Illegal UTF-8 byte: display as <xx>.
1786 // Non-BMP character : display as ? or fullwidth ?.
1787 transchar_hex(extra, mb_c);
1788# ifdef FEAT_RIGHTLEFT
1789 if (wp->w_p_rl) // reverse
1790 rl_mirror(extra);
1791# endif
1792 p_extra = extra;
1793 c = *p_extra;
1794 mb_c = mb_ptr2char_adv(&p_extra);
1795 mb_utf8 = (c >= 0x80);
1796 n_extra = (int)STRLEN(p_extra);
1797 c_extra = NUL;
1798 c_final = NUL;
1799 if (area_attr == 0 && search_attr == 0)
1800 {
1801 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001802 extra_attr = hl_combine_attr(
1803 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001804 saved_attr2 = char_attr; // save current attr
1805 }
1806 }
1807 else if (mb_l == 0) // at the NUL at end-of-line
1808 mb_l = 1;
1809#ifdef FEAT_ARABIC
1810 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
1811 {
1812 // Do Arabic shaping.
1813 int pc, pc1, nc;
1814 int pcc[MAX_MCO];
1815
1816 // The idea of what is the previous and next
1817 // character depends on 'rightleft'.
1818 if (wp->w_p_rl)
1819 {
1820 pc = prev_c;
1821 pc1 = prev_c1;
1822 nc = utf_ptr2char(ptr + mb_l);
1823 prev_c1 = u8cc[0];
1824 }
1825 else
1826 {
1827 pc = utfc_ptr2char(ptr + mb_l, pcc);
1828 nc = prev_c;
1829 pc1 = pcc[0];
1830 }
1831 prev_c = mb_c;
1832
1833 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
1834 }
1835 else
1836 prev_c = mb_c;
1837#endif
1838 }
1839 else // enc_dbcs
1840 {
1841 mb_l = MB_BYTE2LEN(c);
1842 if (mb_l == 0) // at the NUL at end-of-line
1843 mb_l = 1;
1844 else if (mb_l > 1)
1845 {
1846 // We assume a second byte below 32 is illegal.
1847 // Hopefully this is OK for all double-byte encodings!
1848 if (ptr[1] >= 32)
1849 mb_c = (c << 8) + ptr[1];
1850 else
1851 {
1852 if (ptr[1] == NUL)
1853 {
1854 // head byte at end of line
1855 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02001856 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001857 }
1858 else
1859 {
1860 // illegal tail byte
1861 mb_l = 2;
1862 STRCPY(extra, "XX");
1863 }
1864 p_extra = extra;
1865 n_extra = (int)STRLEN(extra) - 1;
1866 c_extra = NUL;
1867 c_final = NUL;
1868 c = *p_extra++;
1869 if (area_attr == 0 && search_attr == 0)
1870 {
1871 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001872 extra_attr = hl_combine_attr(
1873 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001874 saved_attr2 = char_attr; // save current attr
1875 }
1876 mb_c = c;
1877 }
1878 }
1879 }
1880 // If a double-width char doesn't fit display a '>' in the
1881 // last column; the character is displayed at the start of the
1882 // next line.
1883 if ((
1884# ifdef FEAT_RIGHTLEFT
1885 wp->w_p_rl ? (col <= 0) :
1886# endif
1887 (col >= wp->w_width - 1))
1888 && (*mb_char2cells)(mb_c) == 2)
1889 {
1890 c = '>';
1891 mb_c = c;
1892 mb_utf8 = FALSE;
1893 mb_l = 1;
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001894 multi_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001895 // Put pointer back so that the character will be
1896 // displayed at the start of the next line.
1897 --ptr;
1898#ifdef FEAT_CONCEAL
1899 did_decrement_ptr = TRUE;
1900#endif
1901 }
1902 else if (*ptr != NUL)
1903 ptr += mb_l - 1;
1904
1905 // If a double-width char doesn't fit at the left side display
1906 // a '<' in the first column. Don't do this for unprintable
1907 // characters.
1908 if (n_skip > 0 && mb_l > 1 && n_extra == 0)
1909 {
1910 n_extra = 1;
1911 c_extra = MB_FILLER_CHAR;
1912 c_final = NUL;
1913 c = ' ';
1914 if (area_attr == 0 && search_attr == 0)
1915 {
1916 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001917 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001918 saved_attr2 = char_attr; // save current attr
1919 }
1920 mb_c = c;
1921 mb_utf8 = FALSE;
1922 mb_l = 1;
1923 }
1924
1925 }
1926 ++ptr;
1927
1928 if (extra_check)
1929 {
1930#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001931 // Check spelling (unless at the end of the line).
1932 // Only do this when there is no syntax highlighting, the
1933 // @Spell cluster is not used or the current syntax item
1934 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001935 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001936 if (has_spell && v >= word_end && v > cur_checked_col)
1937 {
1938 spell_attr = 0;
1939 if (c != 0 && (
1940# ifdef FEAT_SYN_HL
1941 !has_syntax ||
1942# endif
1943 can_spell))
1944 {
1945 char_u *prev_ptr, *p;
1946 int len;
1947 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01001948
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001949 if (has_mbyte)
1950 {
1951 prev_ptr = ptr - mb_l;
1952 v -= mb_l - 1;
1953 }
1954 else
1955 prev_ptr = ptr - 1;
1956
1957 // Use nextline[] if possible, it has the start of the
1958 // next line concatenated.
1959 if ((prev_ptr - line) - nextlinecol >= 0)
1960 p = nextline + (prev_ptr - line) - nextlinecol;
1961 else
1962 p = prev_ptr;
1963 cap_col -= (int)(prev_ptr - line);
1964 len = spell_check(wp, p, &spell_hlf, &cap_col,
1965 nochange);
1966 word_end = v + len;
1967
1968 // In Insert mode only highlight a word that
1969 // doesn't touch the cursor.
1970 if (spell_hlf != HLF_COUNT
1971 && (State & INSERT) != 0
1972 && wp->w_cursor.lnum == lnum
1973 && wp->w_cursor.col >=
1974 (colnr_T)(prev_ptr - line)
1975 && wp->w_cursor.col < (colnr_T)word_end)
1976 {
1977 spell_hlf = HLF_COUNT;
1978 spell_redraw_lnum = lnum;
1979 }
1980
1981 if (spell_hlf == HLF_COUNT && p != prev_ptr
1982 && (p - nextline) + len > nextline_idx)
1983 {
1984 // Remember that the good word continues at the
1985 // start of the next line.
1986 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001987 checked_col = (int)((p - nextline)
1988 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001989 }
1990
1991 // Turn index into actual attributes.
1992 if (spell_hlf != HLF_COUNT)
1993 spell_attr = highlight_attr[spell_hlf];
1994
1995 if (cap_col > 0)
1996 {
1997 if (p != prev_ptr
1998 && (p - nextline) + cap_col >= nextline_idx)
1999 {
2000 // Remember that the word in the next line
2001 // must start with a capital.
2002 capcol_lnum = lnum + 1;
2003 cap_col = (int)((p - nextline) + cap_col
2004 - nextline_idx);
2005 }
2006 else
2007 // Compute the actual column.
2008 cap_col += (int)(prev_ptr - line);
2009 }
2010 }
2011 }
2012 if (spell_attr != 0)
2013 {
2014 if (!attr_pri)
2015 char_attr = hl_combine_attr(char_attr, spell_attr);
2016 else
2017 char_attr = hl_combine_attr(spell_attr, char_attr);
2018 }
2019#endif
2020#ifdef FEAT_LINEBREAK
2021 // Found last space before word: check for line break.
2022 if (wp->w_p_lbr && c0 == c
2023 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2024 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002025 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2026 : 0;
2027 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002028
2029 // TODO: is passing p for start of the line OK?
2030 n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol,
2031 NULL) - 1;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002032
2033 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002034 // space for it again.
Bram Moolenaara06e3452021-05-29 17:56:37 +02002035 if (vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002036 {
Bram Moolenaara06e3452021-05-29 17:56:37 +02002037 n_extra -= MB_CHARLEN(get_showbreak_value(wp));
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002038 if (n_extra < 0)
2039 n_extra = 0;
2040 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002041 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002042 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002043 // line break, but for TABs the highlighting should
2044 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002045 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002046
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002047 if (c == TAB && n_extra + col > wp->w_width)
2048# ifdef FEAT_VARTABS
2049 n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts,
2050 wp->w_buffer->b_p_vts_array) - 1;
2051# else
2052 n_extra = (int)wp->w_buffer->b_p_ts
2053 - vcol % (int)wp->w_buffer->b_p_ts - 1;
2054# endif
2055
2056 c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2057 c_final = NUL;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002058# if defined(FEAT_PROP_POPUP)
Bram Moolenaar42eba042021-11-30 20:22:49 +00002059 if (n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002060 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002061# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002062 if (VIM_ISWHITE(c))
2063 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002064# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002065 if (c == TAB)
2066 // See "Tab alignment" below.
2067 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002068# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002069 if (!wp->w_p_list)
2070 c = ' ';
2071 }
2072 }
2073#endif
2074
zeertzjqf14b8ba2021-09-10 16:58:30 +02002075 in_multispace = c == ' '
2076 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2077 if (!in_multispace)
2078 multispace_pos = 0;
2079
Bram Moolenaareed9d462021-02-15 20:38:25 +01002080 // 'list': Change char 160 to 'nbsp' and space to 'space'
2081 // setting in 'listchars'. But not when the character is
2082 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002083 if (wp->w_p_list
2084 && ((((c == 160 && mb_l == 1)
2085 || (mb_utf8
2086 && ((mb_c == 160 && mb_l == 2)
2087 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002088 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002089 || (c == ' '
2090 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002091 && (wp->w_lcs_chars.space
2092 || (in_multispace
2093 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002094 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002095 && ptr - line <= trailcol)))
2096 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002097 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2098 {
2099 c = wp->w_lcs_chars.multispace[multispace_pos++];
2100 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2101 multispace_pos = 0;
2102 }
2103 else
2104 c = (c == ' ') ? wp->w_lcs_chars.space
2105 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002106 if (area_attr == 0 && search_attr == 0)
2107 {
2108 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002109 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002110 saved_attr2 = char_attr; // save current attr
2111 }
2112 mb_c = c;
2113 if (enc_utf8 && utf_char2len(c) > 1)
2114 {
2115 mb_utf8 = TRUE;
2116 u8cc[0] = 0;
2117 c = 0xc0;
2118 }
2119 else
2120 mb_utf8 = FALSE;
2121 }
2122
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002123 if ((trailcol != MAXCOL && ptr > line + trailcol && c == ' ')
2124 || (leadcol != 0 && ptr < line + leadcol && c == ' '))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002125 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002126 c = (ptr > line + trailcol) ? wp->w_lcs_chars.trail
2127 : wp->w_lcs_chars.lead;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002128 if (!attr_pri)
2129 {
2130 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002131 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002132 saved_attr2 = char_attr; // save current attr
2133 }
2134 mb_c = c;
2135 if (enc_utf8 && utf_char2len(c) > 1)
2136 {
2137 mb_utf8 = TRUE;
2138 u8cc[0] = 0;
2139 c = 0xc0;
2140 }
2141 else
2142 mb_utf8 = FALSE;
2143 }
2144 }
2145
2146 // Handling of non-printable characters.
2147 if (!vim_isprintc(c))
2148 {
2149 // when getting a character from the file, we may have to
2150 // turn it into something else on the way to putting it
2151 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002152 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002153 {
2154 int tab_len = 0;
2155 long vcol_adjusted = vcol; // removed showbreak length
2156#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002157 char_u *sbr = get_showbreak_value(wp);
2158
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002159 // only adjust the tab_len, when at the first column
2160 // after the showbreak value was drawn
Bram Moolenaaree857022019-11-09 23:26:40 +01002161 if (*sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap)
2162 vcol_adjusted = vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002163#endif
2164 // tab amount depends on current column
2165#ifdef FEAT_VARTABS
2166 tab_len = tabstop_padding(vcol_adjusted,
2167 wp->w_buffer->b_p_ts,
2168 wp->w_buffer->b_p_vts_array) - 1;
2169#else
2170 tab_len = (int)wp->w_buffer->b_p_ts
2171 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2172#endif
2173
2174#ifdef FEAT_LINEBREAK
2175 if (!wp->w_p_lbr || !wp->w_p_list)
2176#endif
2177 // tab amount depends on current column
2178 n_extra = tab_len;
2179#ifdef FEAT_LINEBREAK
2180 else
2181 {
2182 char_u *p;
2183 int len;
2184 int i;
2185 int saved_nextra = n_extra;
2186
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002187# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002188 if (vcol_off > 0)
2189 // there are characters to conceal
2190 tab_len += vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002191
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002192 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002193 if (wp->w_p_list && wp->w_lcs_chars.tab1
2194 && old_boguscols > 0
2195 && n_extra > tab_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002196 tab_len += n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002197# endif
2198 // If n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002199 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002200 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002201 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002202 if (wp->w_lcs_chars.tab3)
2203 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002204 if (n_extra > 0)
2205 len += n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002206 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002207 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002208 if (p == NULL)
2209 n_extra = 0;
2210 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002211 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002212 vim_memset(p, ' ', len);
2213 p[len] = NUL;
2214 vim_free(p_extra_free);
2215 p_extra_free = p;
2216 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002217 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002218 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002219
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002220 if (*p == NUL)
2221 {
2222 tab_len = i;
2223 break;
2224 }
2225
2226 // if tab3 is given, use it for the last char
2227 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2228 lcs = wp->w_lcs_chars.tab3;
2229 p += mb_char2bytes(lcs, p);
2230 n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002231 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002232 }
2233 p_extra = p_extra_free;
2234# ifdef FEAT_CONCEAL
2235 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2236 // macro below, so need to adjust for that here
2237 if (vcol_off > 0)
2238 n_extra -= vcol_off;
2239# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002240 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002241 }
2242#endif
2243#ifdef FEAT_CONCEAL
2244 {
2245 int vc_saved = vcol_off;
2246
2247 // Tab alignment should be identical regardless of
2248 // 'conceallevel' value. So tab compensates of all
2249 // previous concealed characters, and thus resets
2250 // vcol_off and boguscols accumulated so far in the
2251 // line. Note that the tab can be longer than
2252 // 'tabstop' when there are concealed characters.
2253 FIX_FOR_BOGUSCOLS;
2254
2255 // Make sure, the highlighting for the tab char will be
2256 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002257 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002258 if (n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002259 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002260 tab_len += vc_saved;
2261 }
2262#endif
2263 mb_utf8 = FALSE; // don't draw as UTF-8
2264 if (wp->w_p_list)
2265 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002266 c = (n_extra == 0 && wp->w_lcs_chars.tab3)
2267 ? wp->w_lcs_chars.tab3
2268 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002269#ifdef FEAT_LINEBREAK
2270 if (wp->w_p_lbr)
2271 c_extra = NUL; // using p_extra from above
2272 else
2273#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01002274 c_extra = wp->w_lcs_chars.tab2;
2275 c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002276 n_attr = tab_len + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002277 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002278 saved_attr2 = char_attr; // save current attr
2279 mb_c = c;
2280 if (enc_utf8 && utf_char2len(c) > 1)
2281 {
2282 mb_utf8 = TRUE;
2283 u8cc[0] = 0;
2284 c = 0xc0;
2285 }
2286 }
2287 else
2288 {
2289 c_final = NUL;
2290 c_extra = ' ';
2291 c = ' ';
2292 }
2293 }
2294 else if (c == NUL
2295 && (wp->w_p_list
2296 || ((fromcol >= 0 || fromcol_prev >= 0)
2297 && tocol > vcol
2298 && VIsual_mode != Ctrl_V
2299 && (
2300# ifdef FEAT_RIGHTLEFT
2301 wp->w_p_rl ? (col >= 0) :
2302# endif
2303 (col < wp->w_width))
2304 && !(noinvcur
2305 && lnum == wp->w_cursor.lnum
2306 && (colnr_T)vcol == wp->w_virtcol)))
2307 && lcs_eol_one > 0)
2308 {
2309 // Display a '$' after the line or highlight an extra
2310 // character if the line break is included.
2311#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2312 // For a diff line the highlighting continues after the
2313 // "$".
2314 if (
2315# ifdef FEAT_DIFF
2316 diff_hlf == (hlf_T)0
2317# ifdef LINE_ATTR
2318 &&
2319# endif
2320# endif
2321# ifdef LINE_ATTR
2322 line_attr == 0
2323# endif
2324 )
2325#endif
2326 {
2327 // In virtualedit, visual selections may extend
2328 // beyond end of line.
2329 if (area_highlighting && virtual_active()
2330 && tocol != MAXCOL && vcol < tocol)
2331 n_extra = 0;
2332 else
2333 {
2334 p_extra = at_end_str;
2335 n_extra = 1;
2336 c_extra = NUL;
2337 c_final = NUL;
2338 }
2339 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002340 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2341 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002342 else
2343 c = ' ';
2344 lcs_eol_one = -1;
2345 --ptr; // put it back at the NUL
2346 if (!attr_pri)
2347 {
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002348 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002349 n_attr = 1;
2350 }
2351 mb_c = c;
2352 if (enc_utf8 && utf_char2len(c) > 1)
2353 {
2354 mb_utf8 = TRUE;
2355 u8cc[0] = 0;
2356 c = 0xc0;
2357 }
2358 else
2359 mb_utf8 = FALSE; // don't draw as UTF-8
2360 }
2361 else if (c != NUL)
2362 {
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002363 p_extra = transchar_buf(wp->w_buffer, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002364 if (n_extra == 0)
2365 n_extra = byte2cells(c) - 1;
2366#ifdef FEAT_RIGHTLEFT
2367 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
2368 rl_mirror(p_extra); // reverse "<12>"
2369#endif
2370 c_extra = NUL;
2371 c_final = NUL;
2372#ifdef FEAT_LINEBREAK
2373 if (wp->w_p_lbr)
2374 {
2375 char_u *p;
2376
2377 c = *p_extra;
2378 p = alloc(n_extra + 1);
2379 vim_memset(p, ' ', n_extra);
2380 STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1);
2381 p[n_extra] = NUL;
2382 vim_free(p_extra_free);
2383 p_extra_free = p_extra = p;
2384 }
2385 else
2386#endif
2387 {
2388 n_extra = byte2cells(c) - 1;
2389 c = *p_extra++;
2390 }
2391 if (!attr_pri)
2392 {
2393 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002394 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002395 saved_attr2 = char_attr; // save current attr
2396 }
2397 mb_utf8 = FALSE; // don't draw as UTF-8
2398 }
2399 else if (VIsual_active
2400 && (VIsual_mode == Ctrl_V
2401 || VIsual_mode == 'v')
2402 && virtual_active()
2403 && tocol != MAXCOL
2404 && vcol < tocol
2405 && (
2406#ifdef FEAT_RIGHTLEFT
2407 wp->w_p_rl ? (col >= 0) :
2408#endif
2409 (col < wp->w_width)))
2410 {
2411 c = ' ';
2412 --ptr; // put it back at the NUL
2413 }
2414#if defined(LINE_ATTR)
2415 else if ((
2416# ifdef FEAT_DIFF
2417 diff_hlf != (hlf_T)0 ||
2418# endif
2419# ifdef FEAT_TERMINAL
2420 win_attr != 0 ||
2421# endif
2422 line_attr != 0
2423 ) && (
2424# ifdef FEAT_RIGHTLEFT
2425 wp->w_p_rl ? (col >= 0) :
2426# endif
2427 (col
2428# ifdef FEAT_CONCEAL
2429 - boguscols
2430# endif
2431 < wp->w_width)))
2432 {
2433 // Highlight until the right side of the window
2434 c = ' ';
2435 --ptr; // put it back at the NUL
2436
2437 // Remember we do the char for line highlighting.
2438 ++did_line_attr;
2439
2440 // don't do search HL for the rest of the line
2441 if (line_attr != 0 && char_attr == search_attr
2442 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002443 || (wp->w_p_list &&
2444 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002445 char_attr = line_attr;
2446# ifdef FEAT_DIFF
2447 if (diff_hlf == HLF_TXD)
2448 {
2449 diff_hlf = HLF_CHD;
2450 if (vi_attr == 0 || char_attr != vi_attr)
2451 {
2452 char_attr = HL_ATTR(diff_hlf);
2453 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2454 && wp->w_p_culopt_flags != CULOPT_NBR
2455 && (!cul_screenline
2456 || (vcol >= left_curline_col
2457 && vcol <= right_curline_col)))
2458 char_attr = hl_combine_attr(
2459 char_attr, HL_ATTR(HLF_CUL));
2460 }
2461 }
2462# endif
2463# ifdef FEAT_TERMINAL
2464 if (win_attr != 0)
2465 {
2466 char_attr = win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002467 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2468 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002469 {
2470 if (!cul_screenline || (vcol >= left_curline_col
2471 && vcol <= right_curline_col))
2472 char_attr = hl_combine_attr(
2473 char_attr, HL_ATTR(HLF_CUL));
2474 }
2475 else if (line_attr)
2476 char_attr = hl_combine_attr(char_attr, line_attr);
2477 }
2478# endif
2479 }
2480#endif
2481 }
2482
2483#ifdef FEAT_CONCEAL
2484 if ( wp->w_p_cole > 0
2485 && (wp != curwin || lnum != wp->w_cursor.lnum ||
2486 conceal_cursor_line(wp))
2487 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2488 && !(lnum_in_visual_area
2489 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2490 {
2491 char_attr = conceal_attr;
2492 if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002493 && (syn_get_sub_char() != NUL
2494 || (has_match_conc && match_conc)
2495 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002496 && wp->w_p_cole != 3)
2497 {
2498 // First time at this concealed item: display one
2499 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002500 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002501 c = match_conc;
2502 else if (syn_get_sub_char() != NUL)
2503 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01002504 else if (wp->w_lcs_chars.conceal != NUL)
2505 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002506 else
2507 c = ' ';
2508
2509 prev_syntax_id = syntax_seqnr;
2510
2511 if (n_extra > 0)
2512 vcol_off += n_extra;
2513 vcol += n_extra;
2514 if (wp->w_p_wrap && n_extra > 0)
2515 {
2516# ifdef FEAT_RIGHTLEFT
2517 if (wp->w_p_rl)
2518 {
2519 col -= n_extra;
2520 boguscols -= n_extra;
2521 }
2522 else
2523# endif
2524 {
2525 boguscols += n_extra;
2526 col += n_extra;
2527 }
2528 }
2529 n_extra = 0;
2530 n_attr = 0;
2531 }
2532 else if (n_skip == 0)
2533 {
2534 is_concealing = TRUE;
2535 n_skip = 1;
2536 }
2537 mb_c = c;
2538 if (enc_utf8 && utf_char2len(c) > 1)
2539 {
2540 mb_utf8 = TRUE;
2541 u8cc[0] = 0;
2542 c = 0xc0;
2543 }
2544 else
2545 mb_utf8 = FALSE; // don't draw as UTF-8
2546 }
2547 else
2548 {
2549 prev_syntax_id = 0;
2550 is_concealing = FALSE;
2551 }
2552
2553 if (n_skip > 0 && did_decrement_ptr)
2554 // not showing the '>', put pointer back to avoid getting stuck
2555 ++ptr;
2556
2557#endif // FEAT_CONCEAL
2558 }
2559
2560#ifdef FEAT_CONCEAL
2561 // In the cursor line and we may be concealing characters: correct
2562 // the cursor column when we reach its position.
2563 if (!did_wcol && draw_state == WL_LINE
2564 && wp == curwin && lnum == wp->w_cursor.lnum
2565 && conceal_cursor_line(wp)
2566 && (int)wp->w_virtcol <= vcol + n_skip)
2567 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002568# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002569 if (wp->w_p_rl)
2570 wp->w_wcol = wp->w_width - col + boguscols - 1;
2571 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002572# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002573 wp->w_wcol = col - boguscols;
2574 wp->w_wrow = row;
2575 did_wcol = TRUE;
2576 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002577# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01002578 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002579# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002580 }
2581#endif
2582
2583 // Don't override visual selection highlighting.
2584 if (n_attr > 0
2585 && draw_state == WL_LINE
2586 && !attr_pri)
2587 {
2588#ifdef LINE_ATTR
2589 if (line_attr)
2590 char_attr = hl_combine_attr(extra_attr, line_attr);
2591 else
2592#endif
2593 char_attr = extra_attr;
2594 }
2595
2596#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2597 // XIM don't send preedit_start and preedit_end, but they send
2598 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
2599 // im_is_preediting() here.
2600 if (p_imst == IM_ON_THE_SPOT
2601 && xic != NULL
2602 && lnum == wp->w_cursor.lnum
2603 && (State & INSERT)
2604 && !p_imdisable
2605 && im_is_preediting()
2606 && draw_state == WL_LINE)
2607 {
2608 colnr_T tcol;
2609
2610 if (preedit_end_col == MAXCOL)
2611 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
2612 else
2613 tcol = preedit_end_col;
2614 if ((long)preedit_start_col <= vcol && vcol < (long)tcol)
2615 {
2616 if (feedback_old_attr < 0)
2617 {
2618 feedback_col = 0;
2619 feedback_old_attr = char_attr;
2620 }
2621 char_attr = im_get_feedback_attr(feedback_col);
2622 if (char_attr < 0)
2623 char_attr = feedback_old_attr;
2624 feedback_col++;
2625 }
2626 else if (feedback_old_attr >= 0)
2627 {
2628 char_attr = feedback_old_attr;
2629 feedback_old_attr = -1;
2630 feedback_col = 0;
2631 }
2632 }
2633#endif
2634 // Handle the case where we are in column 0 but not on the first
2635 // character of the line and the user wants us to show us a
2636 // special character (via 'listchars' option "precedes:<char>".
2637 if (lcs_prec_todo != NUL
2638 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02002639 && (wp->w_p_wrap ?
2640 (wp->w_skipcol > 0 && row == 0) :
2641 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002642#ifdef FEAT_DIFF
2643 && filler_todo <= 0
2644#endif
2645 && draw_state > WL_NR
2646 && c != NUL)
2647 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002648 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002649 lcs_prec_todo = NUL;
2650 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2651 {
2652 // Double-width character being overwritten by the "precedes"
2653 // character, need to fill up half the character.
2654 c_extra = MB_FILLER_CHAR;
2655 c_final = NUL;
2656 n_extra = 1;
2657 n_attr = 2;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002658 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002659 }
2660 mb_c = c;
2661 if (enc_utf8 && utf_char2len(c) > 1)
2662 {
2663 mb_utf8 = TRUE;
2664 u8cc[0] = 0;
2665 c = 0xc0;
2666 }
2667 else
2668 mb_utf8 = FALSE; // don't draw as UTF-8
2669 if (!attr_pri)
2670 {
2671 saved_attr3 = char_attr; // save current attr
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002672 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002673 n_attr3 = 1;
2674 }
2675 }
2676
2677 // At end of the text line or just after the last character.
2678 if ((c == NUL
2679#if defined(LINE_ATTR)
2680 || did_line_attr == 1
2681#endif
2682 ) && eol_hl_off == 0)
2683 {
2684#ifdef FEAT_SEARCH_EXTRA
2685 // flag to indicate whether prevcol equals startcol of search_hl or
2686 // one of the matches
2687 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
2688 (long)(ptr - line) - (c == NUL));
2689#endif
2690 // Invert at least one char, used for Visual and empty line or
2691 // highlight match at end of line. If it's beyond the last
2692 // char on the screen, just overwrite that one (tricky!) Not
2693 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002694 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002695 && ((area_attr != 0 && vcol == fromcol
2696 && (VIsual_mode != Ctrl_V
2697 || lnum == VIsual.lnum
2698 || lnum == curwin->w_cursor.lnum)
2699 && c == NUL)
2700#ifdef FEAT_SEARCH_EXTRA
2701 // highlight 'hlsearch' match at end of line
2702 || (prevcol_hl_flag
2703# ifdef FEAT_SYN_HL
2704 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
2705 && !(wp == curwin && VIsual_active))
2706# endif
2707# ifdef FEAT_DIFF
2708 && diff_hlf == (hlf_T)0
2709# endif
2710# if defined(LINE_ATTR)
2711 && did_line_attr <= 1
2712# endif
2713 )
2714#endif
2715 ))
2716 {
2717 int n = 0;
2718
2719#ifdef FEAT_RIGHTLEFT
2720 if (wp->w_p_rl)
2721 {
2722 if (col < 0)
2723 n = 1;
2724 }
2725 else
2726#endif
2727 {
2728 if (col >= wp->w_width)
2729 n = -1;
2730 }
2731 if (n != 0)
2732 {
2733 // At the window boundary, highlight the last character
2734 // instead (better than nothing).
2735 off += n;
2736 col += n;
2737 }
2738 else
2739 {
2740 // Add a blank character to highlight.
2741 ScreenLines[off] = ' ';
2742 if (enc_utf8)
2743 ScreenLinesUC[off] = 0;
2744 }
2745#ifdef FEAT_SEARCH_EXTRA
2746 if (area_attr == 0)
2747 {
2748 // Use attributes from match with highest priority among
2749 // 'search_hl' and the match list.
2750 get_search_match_hl(wp, &screen_search_hl,
2751 (long)(ptr - line), &char_attr);
2752 }
2753#endif
2754 ScreenAttrs[off] = char_attr;
2755#ifdef FEAT_RIGHTLEFT
2756 if (wp->w_p_rl)
2757 {
2758 --col;
2759 --off;
2760 }
2761 else
2762#endif
2763 {
2764 ++col;
2765 ++off;
2766 }
2767 ++vcol;
2768 eol_hl_off = 1;
2769 }
2770 }
2771
2772 // At end of the text line.
2773 if (c == NUL)
2774 {
2775#ifdef FEAT_SYN_HL
2776 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
2777 if (wp->w_p_wrap)
2778 v = wp->w_skipcol;
2779 else
2780 v = wp->w_leftcol;
2781
2782 // check if line ends before left margin
2783 if (vcol < v + col - win_col_off(wp))
2784 vcol = v + col - win_col_off(wp);
2785#ifdef FEAT_CONCEAL
2786 // Get rid of the boguscols now, we want to draw until the right
2787 // edge for 'cursorcolumn'.
2788 col -= boguscols;
2789 boguscols = 0;
2790#endif
2791
2792 if (draw_color_col)
2793 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2794
2795 if (((wp->w_p_cuc
2796 && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off
2797 && (int)wp->w_virtcol <
=?UTF-8?q?Dundar=20G=C3=B6c?=d5cec1f2022-01-29 15:19:23 +00002798 (long)wp->w_width * (row - startrow + 1) + v
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002799 && lnum != wp->w_cursor.lnum)
2800 || draw_color_col
2801 || win_attr != 0)
2802# ifdef FEAT_RIGHTLEFT
2803 && !wp->w_p_rl
2804# endif
2805 )
2806 {
2807 int rightmost_vcol = 0;
2808 int i;
2809
2810 if (wp->w_p_cuc)
2811 rightmost_vcol = wp->w_virtcol;
2812 if (draw_color_col)
2813 // determine rightmost colorcolumn to possibly draw
2814 for (i = 0; color_cols[i] >= 0; ++i)
2815 if (rightmost_vcol < color_cols[i])
2816 rightmost_vcol = color_cols[i];
2817
2818 while (col < wp->w_width)
2819 {
2820 ScreenLines[off] = ' ';
2821 if (enc_utf8)
2822 ScreenLinesUC[off] = 0;
2823 ++col;
2824 if (draw_color_col)
2825 draw_color_col = advance_color_col(VCOL_HLC,
2826 &color_cols);
2827
2828 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
2829 ScreenAttrs[off++] = HL_ATTR(HLF_CUC);
2830 else if (draw_color_col && VCOL_HLC == *color_cols)
2831 ScreenAttrs[off++] = HL_ATTR(HLF_MC);
2832 else
2833 ScreenAttrs[off++] = win_attr;
2834
2835 if (VCOL_HLC >= rightmost_vcol && win_attr == 0)
2836 break;
2837
2838 ++vcol;
2839 }
2840 }
2841#endif
2842
2843 screen_line(screen_row, wp->w_wincol, col,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00002844 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002845 row++;
2846
2847 // Update w_cline_height and w_cline_folded if the cursor line was
2848 // updated (saves a call to plines() later).
2849 if (wp == curwin && lnum == curwin->w_cursor.lnum)
2850 {
2851 curwin->w_cline_row = startrow;
2852 curwin->w_cline_height = row - startrow;
2853#ifdef FEAT_FOLDING
2854 curwin->w_cline_folded = FALSE;
2855#endif
2856 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
2857 }
2858
2859 break;
2860 }
2861
2862 // Show "extends" character from 'listchars' if beyond the line end and
2863 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002864 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar41fb7232021-07-08 12:40:05 +02002865 && draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002866 && wp->w_p_list
2867 && !wp->w_p_wrap
2868#ifdef FEAT_DIFF
2869 && filler_todo <= 0
2870#endif
2871 && (
2872#ifdef FEAT_RIGHTLEFT
2873 wp->w_p_rl ? col == 0 :
2874#endif
2875 col == wp->w_width - 1)
2876 && (*ptr != NUL
2877 || (wp->w_p_list && lcs_eol_one > 0)
2878 || (n_extra && (c_extra != NUL || *p_extra != NUL))))
2879 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002880 c = wp->w_lcs_chars.ext;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002881 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002882 mb_c = c;
2883 if (enc_utf8 && utf_char2len(c) > 1)
2884 {
2885 mb_utf8 = TRUE;
2886 u8cc[0] = 0;
2887 c = 0xc0;
2888 }
2889 else
2890 mb_utf8 = FALSE;
2891 }
2892
2893#ifdef FEAT_SYN_HL
2894 // advance to the next 'colorcolumn'
2895 if (draw_color_col)
2896 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2897
2898 // Highlight the cursor column if 'cursorcolumn' is set. But don't
2899 // highlight the cursor position itself.
2900 // Also highlight the 'colorcolumn' if it is different than
2901 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02002902 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
2903 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002904 vcol_save_attr = -1;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002905 if (((draw_state == WL_LINE ||
Bram Moolenaarad5e5632020-09-15 20:52:26 +02002906 draw_state == WL_BRI ||
2907 draw_state == WL_SBR) && !lnum_in_visual_area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002908 && search_attr == 0 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002909# ifdef FEAT_DIFF
2910 && filler_todo <= 0
2911# endif
2912 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002913 {
2914 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
2915 && lnum != wp->w_cursor.lnum)
2916 {
2917 vcol_save_attr = char_attr;
2918 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUC));
2919 }
2920 else if (draw_color_col && VCOL_HLC == *color_cols)
2921 {
2922 vcol_save_attr = char_attr;
2923 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_MC));
2924 }
2925 }
2926#endif
2927
2928 // Store character to be displayed.
2929 // Skip characters that are left of the screen for 'nowrap'.
2930 vcol_prev = vcol;
2931 if (draw_state < WL_LINE || n_skip <= 0)
2932 {
2933 // Store the character.
2934#if defined(FEAT_RIGHTLEFT)
2935 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
2936 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002937 // A double-wide character is: put first half in left cell.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002938 --off;
2939 --col;
2940 }
2941#endif
2942 ScreenLines[off] = c;
2943 if (enc_dbcs == DBCS_JPNU)
2944 {
2945 if ((mb_c & 0xff00) == 0x8e00)
2946 ScreenLines[off] = 0x8e;
2947 ScreenLines2[off] = mb_c & 0xff;
2948 }
2949 else if (enc_utf8)
2950 {
2951 if (mb_utf8)
2952 {
2953 int i;
2954
2955 ScreenLinesUC[off] = mb_c;
2956 if ((c & 0xff) == 0)
2957 ScreenLines[off] = 0x80; // avoid storing zero
2958 for (i = 0; i < Screen_mco; ++i)
2959 {
2960 ScreenLinesC[i][off] = u8cc[i];
2961 if (u8cc[i] == 0)
2962 break;
2963 }
2964 }
2965 else
2966 ScreenLinesUC[off] = 0;
2967 }
2968 if (multi_attr)
2969 {
2970 ScreenAttrs[off] = multi_attr;
2971 multi_attr = 0;
2972 }
2973 else
2974 ScreenAttrs[off] = char_attr;
2975
2976 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2977 {
2978 // Need to fill two screen columns.
2979 ++off;
2980 ++col;
2981 if (enc_utf8)
2982 // UTF-8: Put a 0 in the second screen char.
2983 ScreenLines[off] = 0;
2984 else
2985 // DBCS: Put second byte in the second screen char.
2986 ScreenLines[off] = mb_c & 0xff;
2987 if (draw_state > WL_NR
2988#ifdef FEAT_DIFF
2989 && filler_todo <= 0
2990#endif
2991 )
2992 ++vcol;
2993 // When "tocol" is halfway a character, set it to the end of
2994 // the character, otherwise highlighting won't stop.
2995 if (tocol == vcol)
2996 ++tocol;
2997#ifdef FEAT_RIGHTLEFT
2998 if (wp->w_p_rl)
2999 {
3000 // now it's time to backup one cell
3001 --off;
3002 --col;
3003 }
3004#endif
3005 }
3006#ifdef FEAT_RIGHTLEFT
3007 if (wp->w_p_rl)
3008 {
3009 --off;
3010 --col;
3011 }
3012 else
3013#endif
3014 {
3015 ++off;
3016 ++col;
3017 }
3018 }
3019#ifdef FEAT_CONCEAL
3020 else if (wp->w_p_cole > 0 && is_concealing)
3021 {
3022 --n_skip;
3023 ++vcol_off;
3024 if (n_extra > 0)
3025 vcol_off += n_extra;
3026 if (wp->w_p_wrap)
3027 {
3028 // Special voodoo required if 'wrap' is on.
3029 //
3030 // Advance the column indicator to force the line
3031 // drawing to wrap early. This will make the line
3032 // take up the same screen space when parts are concealed,
3033 // so that cursor line computations aren't messed up.
3034 //
3035 // To avoid the fictitious advance of 'col' causing
3036 // trailing junk to be written out of the screen line
3037 // we are building, 'boguscols' keeps track of the number
3038 // of bad columns we have advanced.
3039 if (n_extra > 0)
3040 {
3041 vcol += n_extra;
3042# ifdef FEAT_RIGHTLEFT
3043 if (wp->w_p_rl)
3044 {
3045 col -= n_extra;
3046 boguscols -= n_extra;
3047 }
3048 else
3049# endif
3050 {
3051 col += n_extra;
3052 boguscols += n_extra;
3053 }
3054 n_extra = 0;
3055 n_attr = 0;
3056 }
3057
3058
3059 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3060 {
3061 // Need to fill two screen columns.
3062# ifdef FEAT_RIGHTLEFT
3063 if (wp->w_p_rl)
3064 {
3065 --boguscols;
3066 --col;
3067 }
3068 else
3069# endif
3070 {
3071 ++boguscols;
3072 ++col;
3073 }
3074 }
3075
3076# ifdef FEAT_RIGHTLEFT
3077 if (wp->w_p_rl)
3078 {
3079 --boguscols;
3080 --col;
3081 }
3082 else
3083# endif
3084 {
3085 ++boguscols;
3086 ++col;
3087 }
3088 }
3089 else
3090 {
3091 if (n_extra > 0)
3092 {
3093 vcol += n_extra;
3094 n_extra = 0;
3095 n_attr = 0;
3096 }
3097 }
3098
3099 }
3100#endif // FEAT_CONCEAL
3101 else
3102 --n_skip;
3103
3104 // Only advance the "vcol" when after the 'number' or 'relativenumber'
3105 // column.
3106 if (draw_state > WL_NR
3107#ifdef FEAT_DIFF
3108 && filler_todo <= 0
3109#endif
3110 )
3111 ++vcol;
3112
3113#ifdef FEAT_SYN_HL
3114 if (vcol_save_attr >= 0)
3115 char_attr = vcol_save_attr;
3116#endif
3117
3118 // restore attributes after "predeces" in 'listchars'
3119 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3120 char_attr = saved_attr3;
3121
3122 // restore attributes after last 'listchars' or 'number' char
3123 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0)
3124 char_attr = saved_attr2;
3125
3126 // At end of screen line and there is more to come: Display the line
3127 // so far. If there is no more to display it is caught above.
3128 if ((
3129#ifdef FEAT_RIGHTLEFT
3130 wp->w_p_rl ? (col < 0) :
3131#endif
3132 (col >= wp->w_width))
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003133 && (draw_state != WL_LINE
3134 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003135#ifdef FEAT_DIFF
3136 || filler_todo > 0
3137#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003138 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
3139 && p_extra != at_end_str)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003140 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL)))
3141 )
3142 {
3143#ifdef FEAT_CONCEAL
3144 screen_line(screen_row, wp->w_wincol, col - boguscols,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00003145 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003146 boguscols = 0;
3147#else
3148 screen_line(screen_row, wp->w_wincol, col,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00003149 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003150#endif
3151 ++row;
3152 ++screen_row;
3153
3154 // When not wrapping and finished diff lines, or when displayed
3155 // '$' and highlighting until last column, break here.
3156 if ((!wp->w_p_wrap
3157#ifdef FEAT_DIFF
3158 && filler_todo <= 0
3159#endif
3160 ) || lcs_eol_one == -1)
3161 break;
3162
3163 // When the window is too narrow draw all "@" lines.
3164 if (draw_state != WL_LINE
3165#ifdef FEAT_DIFF
3166 && filler_todo <= 0
3167#endif
3168 )
3169 {
3170 win_draw_end(wp, '@', ' ', TRUE, row, wp->w_height, HLF_AT);
3171 draw_vsep_win(wp, row);
3172 row = endrow;
3173 }
3174
3175 // When line got too long for screen break here.
3176 if (row == endrow)
3177 {
3178 ++row;
3179 break;
3180 }
3181
3182 if (screen_cur_row == screen_row - 1
3183#ifdef FEAT_DIFF
3184 && filler_todo <= 0
3185#endif
3186 && wp->w_width == Columns)
3187 {
3188 // Remember that the line wraps, used for modeless copy.
3189 LineWraps[screen_row - 1] = TRUE;
3190
3191 // Special trick to make copy/paste of wrapped lines work with
3192 // xterm/screen: write an extra character beyond the end of
3193 // the line. This will work with all terminal types
3194 // (regardless of the xn,am settings).
3195 // Only do this on a fast tty.
3196 // Only do this if the cursor is on the current line
3197 // (something has been written in it).
3198 // Don't do this for the GUI.
3199 // Don't do this for double-width characters.
3200 // Don't do this for a window not at the right screen border.
3201 if (p_tf
3202#ifdef FEAT_GUI
3203 && !gui.in_use
3204#endif
3205 && !(has_mbyte
3206 && ((*mb_off2cells)(LineOffset[screen_row],
3207 LineOffset[screen_row] + screen_Columns)
3208 == 2
3209 || (*mb_off2cells)(LineOffset[screen_row - 1]
3210 + (int)Columns - 2,
3211 LineOffset[screen_row] + screen_Columns)
3212 == 2)))
3213 {
3214 // First make sure we are at the end of the screen line,
3215 // then output the same character again to let the
3216 // terminal know about the wrap. If the terminal doesn't
3217 // auto-wrap, we overwrite the character.
3218 if (screen_cur_col != wp->w_width)
3219 screen_char(LineOffset[screen_row - 1]
3220 + (unsigned)Columns - 1,
3221 screen_row - 1, (int)(Columns - 1));
3222
3223 // When there is a multi-byte character, just output a
3224 // space to keep it simple.
3225 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
3226 screen_row - 1] + (Columns - 1)]) > 1)
3227 out_char(' ');
3228 else
3229 out_char(ScreenLines[LineOffset[screen_row - 1]
3230 + (Columns - 1)]);
3231 // force a redraw of the first char on the next line
3232 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1;
3233 screen_start(); // don't know where cursor is now
3234 }
3235 }
3236
3237 col = 0;
3238 off = (unsigned)(current_ScreenLine - ScreenLines);
3239#ifdef FEAT_RIGHTLEFT
3240 if (wp->w_p_rl)
3241 {
3242 col = wp->w_width - 1; // col is not used if breaking!
3243 off += col;
3244 }
3245#endif
3246
3247 // reset the drawing state for the start of a wrapped line
3248 draw_state = WL_START;
3249 saved_n_extra = n_extra;
3250 saved_p_extra = p_extra;
3251 saved_c_extra = c_extra;
3252 saved_c_final = c_final;
3253#ifdef FEAT_SYN_HL
3254 if (!(cul_screenline
3255# ifdef FEAT_DIFF
Bram Moolenaare7705982020-04-21 22:23:15 +02003256 && diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003257# endif
Bram Moolenaare7705982020-04-21 22:23:15 +02003258 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003259 saved_char_attr = char_attr;
3260 else
3261#endif
3262 saved_char_attr = 0;
3263 n_extra = 0;
Bram Moolenaareed9d462021-02-15 20:38:25 +01003264 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003265#ifdef FEAT_LINEBREAK
3266# ifdef FEAT_DIFF
3267 if (filler_todo <= 0)
3268# endif
3269 need_showbreak = TRUE;
3270#endif
3271#ifdef FEAT_DIFF
3272 --filler_todo;
3273 // When the filler lines are actually below the last line of the
3274 // file, don't draw the line itself, break here.
3275 if (filler_todo == 0 && wp->w_botfill)
3276 break;
3277#endif
3278 }
3279
3280 } // for every character in the line
3281
3282#ifdef FEAT_SPELL
3283 // After an empty line check first word for capital.
3284 if (*skipwhite(line) == NUL)
3285 {
3286 capcol_lnum = lnum + 1;
3287 cap_col = 0;
3288 }
3289#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003290#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003291 vim_free(text_props);
3292 vim_free(text_prop_idxs);
3293#endif
3294
3295 vim_free(p_extra_free);
3296 return row;
3297}