blob: 51dcfb1bb9e0477e3de835bbf94287f59eb3e1a8 [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 Moolenaar34390282019-10-16 14:38:26 +0200333 int can_spell;
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
357#endif
358#ifdef FEAT_DIFF
359 hlf_T diff_hlf = (hlf_T)0; // type of diff highlighting
360 int change_start = MAXCOL; // first col of changed area
361 int change_end = -1; // last col of changed area
362#endif
363 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100364 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200365 int in_multispace = FALSE; // in multiple consecutive spaces
366 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200367#ifdef FEAT_LINEBREAK
368 int need_showbreak = FALSE; // overlong line, skipping first x
369 // chars
370#endif
371#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
372 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
373# define LINE_ATTR
374 int line_attr = 0; // attribute for the whole line
375 int line_attr_save;
376#endif
377#ifdef FEAT_SIGNS
378 int sign_present = FALSE;
379 sign_attrs_T sattr;
James McCoya80aad72021-12-22 19:45:28 +0000380 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200381#endif
382#ifdef FEAT_ARABIC
383 int prev_c = 0; // previous Arabic character
384 int prev_c1 = 0; // first composing char for prev_c
385#endif
386#if defined(LINE_ATTR)
387 int did_line_attr = 0;
388#endif
389#ifdef FEAT_TERMINAL
390 int get_term_attr = FALSE;
391#endif
392#ifdef FEAT_SYN_HL
393 int cul_attr = 0; // set when 'cursorline' active
394
395 // 'cursorlineopt' has "screenline" and cursor is in this line
396 int cul_screenline = FALSE;
397
398 // margin columns for the screen line, needed for when 'cursorlineopt'
399 // contains "screenline"
400 int left_curline_col = 0;
401 int right_curline_col = 0;
402#endif
403
404 // draw_state: items that are drawn in sequence:
405#define WL_START 0 // nothing done yet
406#ifdef FEAT_CMDWIN
kylo252ae6f1d82022-02-16 19:24:07 +0000407# define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200408#else
409# define WL_CMDLINE WL_START
410#endif
411#ifdef FEAT_FOLDING
kylo252ae6f1d82022-02-16 19:24:07 +0000412# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200413#else
414# define WL_FOLD WL_CMDLINE
415#endif
416#ifdef FEAT_SIGNS
kylo252ae6f1d82022-02-16 19:24:07 +0000417# define WL_SIGN (WL_FOLD + 1) // column for signs
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200418#else
419# define WL_SIGN WL_FOLD // column for signs
420#endif
kylo252ae6f1d82022-02-16 19:24:07 +0000421#define WL_NR (WL_SIGN + 1) // line number
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200422#ifdef FEAT_LINEBREAK
kylo252ae6f1d82022-02-16 19:24:07 +0000423# define WL_BRI (WL_NR + 1) // 'breakindent'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200424#else
425# define WL_BRI WL_NR
426#endif
427#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
kylo252ae6f1d82022-02-16 19:24:07 +0000428# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200429#else
430# define WL_SBR WL_BRI
431#endif
kylo252ae6f1d82022-02-16 19:24:07 +0000432#define WL_LINE (WL_SBR + 1) // text in the line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200433 int draw_state = WL_START; // what to draw next
434#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
435 int feedback_col = 0;
436 int feedback_old_attr = -1;
437#endif
438 int screen_line_flags = 0;
439
440#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
441 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000442 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200443#endif
444#ifdef FEAT_CONCEAL
445 int syntax_flags = 0;
446 int syntax_seqnr = 0;
447 int prev_syntax_id = 0;
448 int conceal_attr = HL_ATTR(HLF_CONCEAL);
449 int is_concealing = FALSE;
450 int boguscols = 0; // nonexistent columns added to force
451 // wrapping
452 int vcol_off = 0; // offset for concealed characters
453 int did_wcol = FALSE;
454 int old_boguscols = 0;
455# define VCOL_HLC (vcol - vcol_off)
456# define FIX_FOR_BOGUSCOLS \
457 { \
458 n_extra += vcol_off; \
459 vcol -= vcol_off; \
460 vcol_off = 0; \
461 col -= boguscols; \
462 old_boguscols = boguscols; \
463 boguscols = 0; \
464 }
465#else
466# define VCOL_HLC (vcol)
467#endif
468
469 if (startrow > endrow) // past the end already!
470 return startrow;
471
472 row = startrow;
473 screen_row = row + W_WINROW(wp);
474
475 if (!number_only)
476 {
477 // To speed up the loop below, set extra_check when there is linebreak,
478 // trailing white space and/or syntax processing to be done.
479#ifdef FEAT_LINEBREAK
480 extra_check = wp->w_p_lbr;
481#endif
482#ifdef FEAT_SYN_HL
483 if (syntax_present(wp) && !wp->w_s->b_syn_error
484# ifdef SYN_TIME_LIMIT
485 && !wp->w_s->b_syn_slow
486# endif
487 )
488 {
489 // Prepare for syntax highlighting in this line. When there is an
490 // error, stop syntax highlighting.
491 save_did_emsg = did_emsg;
492 did_emsg = FALSE;
493 syntax_start(wp, lnum);
494 if (did_emsg)
495 wp->w_s->b_syn_error = TRUE;
496 else
497 {
498 did_emsg = save_did_emsg;
499#ifdef SYN_TIME_LIMIT
500 if (!wp->w_s->b_syn_slow)
501#endif
502 {
503 has_syntax = TRUE;
504 extra_check = TRUE;
505 }
506 }
507 }
508
509 // Check for columns to display for 'colorcolumn'.
510 color_cols = wp->w_p_cc_cols;
511 if (color_cols != NULL)
512 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
513#endif
514
515#ifdef FEAT_TERMINAL
516 if (term_show_buffer(wp->w_buffer))
517 {
518 extra_check = TRUE;
519 get_term_attr = TRUE;
Bram Moolenaar219c7d02020-02-01 21:57:29 +0100520 win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200521 }
522#endif
523
524#ifdef FEAT_SPELL
525 if (wp->w_p_spell
526 && *wp->w_s->b_p_spl != NUL
527 && wp->w_s->b_langp.ga_len > 0
528 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
529 {
530 // Prepare for spell checking.
531 has_spell = TRUE;
532 extra_check = TRUE;
533
534 // Get the start of the next line, so that words that wrap to the
535 // next line are found too: "et<line-break>al.".
536 // Trick: skip a few chars for C/shell/Vim comments
537 nextline[SPWORDLEN] = NUL;
538 if (lnum < wp->w_buffer->b_ml.ml_line_count)
539 {
540 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
541 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
542 }
543
544 // When a word wrapped from the previous line the start of the
545 // current line is valid.
546 if (lnum == checked_lnum)
547 cur_checked_col = checked_col;
548 checked_lnum = 0;
549
550 // When there was a sentence end in the previous line may require a
551 // word starting with capital in this line. In line 1 always check
552 // the first word.
553 if (lnum != capcol_lnum)
554 cap_col = -1;
555 if (lnum == 1)
556 cap_col = 0;
557 capcol_lnum = 0;
558 }
559#endif
560
561 // handle Visual active in this window
562 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
563 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100564 pos_T *top, *bot;
565
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200566 if (LTOREQ_POS(curwin->w_cursor, VIsual))
567 {
568 // Visual is after curwin->w_cursor
569 top = &curwin->w_cursor;
570 bot = &VIsual;
571 }
572 else
573 {
574 // Visual is before curwin->w_cursor
575 top = &VIsual;
576 bot = &curwin->w_cursor;
577 }
578 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
579 if (VIsual_mode == Ctrl_V)
580 {
581 // block mode
582 if (lnum_in_visual_area)
583 {
584 fromcol = wp->w_old_cursor_fcol;
585 tocol = wp->w_old_cursor_lcol;
586 }
587 }
588 else
589 {
590 // non-block mode
591 if (lnum > top->lnum && lnum <= bot->lnum)
592 fromcol = 0;
593 else if (lnum == top->lnum)
594 {
595 if (VIsual_mode == 'V') // linewise
596 fromcol = 0;
597 else
598 {
599 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
600 if (gchar_pos(top) == NUL)
601 tocol = fromcol + 1;
602 }
603 }
604 if (VIsual_mode != 'V' && lnum == bot->lnum)
605 {
606 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
607 {
608 fromcol = -10;
609 tocol = MAXCOL;
610 }
611 else if (bot->col == MAXCOL)
612 tocol = MAXCOL;
613 else
614 {
615 pos = *bot;
616 if (*p_sel == 'e')
617 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
618 else
619 {
620 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
621 ++tocol;
622 }
623 }
624 }
625 }
626
627 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200628 if (!highlight_match && lnum == curwin->w_cursor.lnum
629 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200630#ifdef FEAT_GUI
631 && !gui.in_use
632#endif
633 )
634 noinvcur = TRUE;
635
636 // if inverting in this line set area_highlighting
637 if (fromcol >= 0)
638 {
639 area_highlighting = TRUE;
640 vi_attr = HL_ATTR(HLF_V);
641#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
642 if ((clip_star.available && !clip_star.owned
643 && clip_isautosel_star())
644 || (clip_plus.available && !clip_plus.owned
645 && clip_isautosel_plus()))
646 vi_attr = HL_ATTR(HLF_VNC);
647#endif
648 }
649 }
650
651 // handle 'incsearch' and ":s///c" highlighting
652 else if (highlight_match
653 && wp == curwin
654 && lnum >= curwin->w_cursor.lnum
655 && lnum <= curwin->w_cursor.lnum + search_match_lines)
656 {
657 if (lnum == curwin->w_cursor.lnum)
658 getvcol(curwin, &(curwin->w_cursor),
659 (colnr_T *)&fromcol, NULL, NULL);
660 else
661 fromcol = 0;
662 if (lnum == curwin->w_cursor.lnum + search_match_lines)
663 {
664 pos.lnum = lnum;
665 pos.col = search_match_endcol;
666 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
667 }
668 else
669 tocol = MAXCOL;
670 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100671 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200672 tocol = fromcol + 1;
673 area_highlighting = TRUE;
674 vi_attr = HL_ATTR(HLF_I);
675 }
676 }
677
678#ifdef FEAT_DIFF
679 filler_lines = diff_check(wp, lnum);
680 if (filler_lines < 0)
681 {
682 if (filler_lines == -1)
683 {
684 if (diff_find_change(wp, lnum, &change_start, &change_end))
685 diff_hlf = HLF_ADD; // added line
686 else if (change_start == 0)
687 diff_hlf = HLF_TXD; // changed text
688 else
689 diff_hlf = HLF_CHD; // changed line
690 }
691 else
692 diff_hlf = HLF_ADD; // added line
693 filler_lines = 0;
694 area_highlighting = TRUE;
695 }
696 if (lnum == wp->w_topline)
697 filler_lines = wp->w_topfill;
698 filler_todo = filler_lines;
699#endif
700
701#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +0100702 sign_present = buf_get_signattrs(wp, lnum, &sattr);
James McCoya80aad72021-12-22 19:45:28 +0000703 if (sign_present)
704 num_attr = sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200705#endif
706
707#ifdef LINE_ATTR
708# ifdef FEAT_SIGNS
709 // If this line has a sign with line highlighting set line_attr.
710 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200711 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200712# endif
713# if defined(FEAT_QUICKFIX)
714 // Highlight the current line in the quickfix window.
715 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
716 line_attr = HL_ATTR(HLF_QFL);
717# endif
718 if (line_attr != 0)
719 area_highlighting = TRUE;
720#endif
721
722 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
723 ptr = line;
724
725#ifdef FEAT_SPELL
726 if (has_spell && !number_only)
727 {
728 // For checking first word with a capital skip white space.
729 if (cap_col == 0)
730 cap_col = getwhitecols(line);
731
732 // To be able to spell-check over line boundaries copy the end of the
733 // current line into nextline[]. Above the start of the next line was
734 // copied to nextline[SPWORDLEN].
735 if (nextline[SPWORDLEN] == NUL)
736 {
737 // No next line or it is empty.
738 nextlinecol = MAXCOL;
739 nextline_idx = 0;
740 }
741 else
742 {
743 v = (long)STRLEN(line);
744 if (v < SPWORDLEN)
745 {
746 // Short line, use it completely and append the start of the
747 // next line.
748 nextlinecol = 0;
749 mch_memmove(nextline, line, (size_t)v);
750 STRMOVE(nextline + v, nextline + SPWORDLEN);
751 nextline_idx = v + 1;
752 }
753 else
754 {
755 // Long line, use only the last SPWORDLEN bytes.
756 nextlinecol = v - SPWORDLEN;
757 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
758 nextline_idx = SPWORDLEN + 1;
759 }
760 }
761 }
762#endif
763
764 if (wp->w_p_list)
765 {
Bram Moolenaareed9d462021-02-15 20:38:25 +0100766 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +0200767 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +0100768 || wp->w_lcs_chars.trail
769 || wp->w_lcs_chars.lead
770 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200771 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100772
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200773 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100774 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200775 {
776 trailcol = (colnr_T)STRLEN(ptr);
777 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
778 --trailcol;
779 trailcol += (colnr_T) (ptr - line);
780 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100781 // find end of leading whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100782 if (wp->w_lcs_chars.lead)
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100783 {
784 leadcol = 0;
785 while (VIM_ISWHITE(ptr[leadcol]))
786 ++leadcol;
787 if (ptr[leadcol] == NUL)
788 // in a line full of spaces all of them are treated as trailing
789 leadcol = (colnr_T)0;
790 else
791 // keep track of the first column not filled with spaces
792 leadcol += (colnr_T) (ptr - line) + 1;
793 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200794 }
795
796 wcr_attr = get_wcr_attr(wp);
797 if (wcr_attr != 0)
798 {
799 win_attr = wcr_attr;
800 area_highlighting = TRUE;
801 }
Bram Moolenaar34390282019-10-16 14:38:26 +0200802
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100803#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200804 if (WIN_IS_POPUP(wp))
805 screen_line_flags |= SLF_POPUP;
806#endif
807
808 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
809 // first character to be displayed.
810 if (wp->w_p_wrap)
811 v = wp->w_skipcol;
812 else
813 v = wp->w_leftcol;
814 if (v > 0 && !number_only)
815 {
816 char_u *prev_ptr = ptr;
817
818 while (vcol < v && *ptr != NUL)
819 {
820 c = win_lbr_chartabsize(wp, line, ptr, (colnr_T)vcol, NULL);
821 vcol += c;
822 prev_ptr = ptr;
823 MB_PTR_ADV(ptr);
824 }
825
826 // When:
827 // - 'cuc' is set, or
828 // - 'colorcolumn' is set, or
829 // - 'virtualedit' is set, or
830 // - the visual mode is active,
831 // the end of the line may be before the start of the displayed part.
832 if (vcol < v && (
833#ifdef FEAT_SYN_HL
834 wp->w_p_cuc || draw_color_col ||
835#endif
836 virtual_active() ||
837 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
838 vcol = v;
839
840 // Handle a character that's not completely on the screen: Put ptr at
841 // that character but skip the first few screen characters.
842 if (vcol > v)
843 {
844 vcol -= c;
845 ptr = prev_ptr;
846 // If the character fits on the screen, don't need to skip it.
847 // Except for a TAB.
848 if (( (*mb_ptr2cells)(ptr) >= c || *ptr == TAB) && col == 0)
849 n_skip = v - vcol;
850 }
851
852 // Adjust for when the inverted text is before the screen,
853 // and when the start of the inverted text is before the screen.
854 if (tocol <= vcol)
855 fromcol = 0;
856 else if (fromcol >= 0 && fromcol < vcol)
857 fromcol = vcol;
858
859#ifdef FEAT_LINEBREAK
860 // When w_skipcol is non-zero, first line needs 'showbreak'
861 if (wp->w_p_wrap)
862 need_showbreak = TRUE;
863#endif
864#ifdef FEAT_SPELL
865 // When spell checking a word we need to figure out the start of the
866 // word and if it's badly spelled or not.
867 if (has_spell)
868 {
869 int len;
870 colnr_T linecol = (colnr_T)(ptr - line);
871 hlf_T spell_hlf = HLF_COUNT;
872
873 pos = wp->w_cursor;
874 wp->w_cursor.lnum = lnum;
875 wp->w_cursor.col = linecol;
876 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
877
878 // spell_move_to() may call ml_get() and make "line" invalid
879 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
880 ptr = line + linecol;
881
882 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
883 {
884 // no bad word found at line start, don't check until end of a
885 // word
886 spell_hlf = HLF_COUNT;
887 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
888 }
889 else
890 {
891 // bad word found, use attributes until end of word
892 word_end = wp->w_cursor.col + len + 1;
893
894 // Turn index into actual attributes.
895 if (spell_hlf != HLF_COUNT)
896 spell_attr = highlight_attr[spell_hlf];
897 }
898 wp->w_cursor = pos;
899
900# ifdef FEAT_SYN_HL
901 // Need to restart syntax highlighting for this line.
902 if (has_syntax)
903 syntax_start(wp, lnum);
904# endif
905 }
906#endif
907 }
908
909 // Correct highlighting for cursor that can't be disabled.
910 // Avoids having to check this for each character.
911 if (fromcol >= 0)
912 {
913 if (noinvcur)
914 {
915 if ((colnr_T)fromcol == wp->w_virtcol)
916 {
917 // highlighting starts at cursor, let it start just after the
918 // cursor
919 fromcol_prev = fromcol;
920 fromcol = -1;
921 }
922 else if ((colnr_T)fromcol < wp->w_virtcol)
923 // restart highlighting after the cursor
924 fromcol_prev = wp->w_virtcol;
925 }
926 if (fromcol >= tocol)
927 fromcol = -1;
928 }
929
930#ifdef FEAT_SEARCH_EXTRA
931 if (!number_only)
932 {
933 v = (long)(ptr - line);
934 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
935 &line, &screen_search_hl,
936 &search_attr);
937 ptr = line + v; // "line" may have been updated
938 }
939#endif
940
941#ifdef FEAT_SYN_HL
942 // Cursor line highlighting for 'cursorline' in the current window.
943 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
944 {
945 // Do not show the cursor line in the text when Visual mode is active,
946 // because it's not clear what is selected then. Do update
947 // w_last_cursorline.
948 if (!(wp == curwin && VIsual_active)
949 && wp->w_p_culopt_flags != CULOPT_NBR)
950 {
951 cul_screenline = (wp->w_p_wrap
952 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
953
954 // Only set line_attr here when "screenline" is not present in
955 // 'cursorlineopt'. Otherwise it's done later.
956 if (!cul_screenline)
957 {
958 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +0200959# ifdef FEAT_SIGNS
960 // Combine the 'cursorline' and sign highlighting, depending on
961 // the sign priority.
962 if (sign_present && sattr.sat_linehl > 0)
963 {
964 if (sattr.sat_priority >= 100)
965 line_attr = hl_combine_attr(cul_attr, line_attr);
966 else
967 line_attr = hl_combine_attr(line_attr, cul_attr);
968 }
969 else
970# endif
971 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200972 wp->w_last_cursorline = wp->w_cursor.lnum;
973 }
974 else
975 {
976 line_attr_save = line_attr;
977 wp->w_last_cursorline = 0;
978 margin_columns_win(wp, &left_curline_col, &right_curline_col);
979 }
980 area_highlighting = TRUE;
981 }
982 else
983 wp->w_last_cursorline = wp->w_cursor.lnum;
984 }
985#endif
986
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100987#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200988 {
989 char_u *prop_start;
990
991 text_prop_count = get_text_props(wp->w_buffer, lnum,
992 &prop_start, FALSE);
993 if (text_prop_count > 0)
994 {
995 // Make a copy of the properties, so that they are properly
996 // aligned.
997 text_props = ALLOC_MULT(textprop_T, text_prop_count);
998 if (text_props != NULL)
999 mch_memmove(text_props, prop_start,
1000 text_prop_count * sizeof(textprop_T));
1001
1002 // Allocate an array for the indexes.
1003 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1004 area_highlighting = TRUE;
1005 extra_check = TRUE;
1006 }
1007 }
1008#endif
1009
1010 off = (unsigned)(current_ScreenLine - ScreenLines);
1011 col = 0;
1012
1013#ifdef FEAT_RIGHTLEFT
1014 if (wp->w_p_rl)
1015 {
1016 // Rightleft window: process the text in the normal direction, but put
1017 // it in current_ScreenLine[] from right to left. Start at the
1018 // rightmost column of the window.
1019 col = wp->w_width - 1;
1020 off += col;
1021 screen_line_flags |= SLF_RIGHTLEFT;
1022 }
1023#endif
1024
1025 // Repeat for the whole displayed line.
1026 for (;;)
1027 {
1028#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02001029 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001030#endif
1031#ifdef FEAT_CONCEAL
1032 int did_decrement_ptr = FALSE;
1033#endif
1034 // Skip this quickly when working on the text.
1035 if (draw_state != WL_LINE)
1036 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001037#ifdef FEAT_SYN_HL
1038 if (cul_screenline)
1039 {
1040 cul_attr = 0;
1041 line_attr = line_attr_save;
1042 }
1043#endif
1044
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001045#ifdef FEAT_CMDWIN
1046 if (draw_state == WL_CMDLINE - 1 && n_extra == 0)
1047 {
1048 draw_state = WL_CMDLINE;
1049 if (cmdwin_type != 0 && wp == curwin)
1050 {
1051 // Draw the cmdline character.
1052 n_extra = 1;
1053 c_extra = cmdwin_type;
1054 c_final = NUL;
1055 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
1056 }
1057 }
1058#endif
1059
1060#ifdef FEAT_FOLDING
1061 if (draw_state == WL_FOLD - 1 && n_extra == 0)
1062 {
1063 int fdc = compute_foldcolumn(wp, 0);
1064
1065 draw_state = WL_FOLD;
1066 if (fdc > 0)
1067 {
1068 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1069 // already be in use.
1070 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001071 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001072 if (p_extra_free != NULL)
1073 {
Bram Moolenaar9355ae42021-03-08 19:04:05 +01001074 n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001075 FALSE, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001076 p_extra_free[n_extra] = NUL;
1077 p_extra = p_extra_free;
1078 c_extra = NUL;
1079 c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001080 if (use_cursor_line_sign(wp, lnum))
1081 char_attr =
1082 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1083 else
1084 char_attr =
1085 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001086 }
1087 }
1088 }
1089#endif
1090
1091#ifdef FEAT_SIGNS
1092 if (draw_state == WL_SIGN - 1 && n_extra == 0)
1093 {
1094 draw_state = WL_SIGN;
1095 // Show the sign column when there are any signs in this
1096 // buffer or when using Netbeans.
1097 if (signcolumn_on(wp))
1098 get_sign_display_info(FALSE, wp, lnum, &sattr, wcr_attr,
1099 row, startrow, filler_lines, filler_todo, &c_extra,
1100 &c_final, extra, &p_extra, &n_extra, &char_attr);
1101 }
1102#endif
1103
1104 if (draw_state == WL_NR - 1 && n_extra == 0)
1105 {
1106 draw_state = WL_NR;
1107 // Display the absolute or relative line number. After the
1108 // first fill with blanks when the 'n' flag isn't in 'cpo'
1109 if ((wp->w_p_nu || wp->w_p_rnu)
1110 && (row == startrow
1111#ifdef FEAT_DIFF
1112 + filler_lines
1113#endif
1114 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
1115 {
1116#ifdef FEAT_SIGNS
1117 // If 'signcolumn' is set to 'number' and a sign is present
1118 // in 'lnum', then display the sign instead of the line
1119 // number.
1120 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1121 && sign_present)
1122 get_sign_display_info(TRUE, wp, lnum, &sattr, wcr_attr,
1123 row, startrow, filler_lines, filler_todo,
1124 &c_extra, &c_final, extra, &p_extra, &n_extra,
1125 &char_attr);
1126 else
1127#endif
1128 {
1129 // Draw the line number (empty space after wrapping).
1130 if (row == startrow
1131#ifdef FEAT_DIFF
1132 + filler_lines
1133#endif
1134 )
1135 {
1136 long num;
1137 char *fmt = "%*ld ";
1138
1139 if (wp->w_p_nu && !wp->w_p_rnu)
1140 // 'number' + 'norelativenumber'
1141 num = (long)lnum;
1142 else
1143 {
1144 // 'relativenumber', don't use negative numbers
1145 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1146 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1147 {
1148 // 'number' + 'relativenumber'
1149 num = lnum;
1150 fmt = "%-*ld ";
1151 }
1152 }
1153
1154 sprintf((char *)extra, fmt,
1155 number_width(wp), num);
1156 if (wp->w_skipcol > 0)
1157 for (p_extra = extra; *p_extra == ' '; ++p_extra)
1158 *p_extra = '-';
1159#ifdef FEAT_RIGHTLEFT
1160 if (wp->w_p_rl) // reverse line numbers
1161 {
1162 char_u *p1, *p2;
1163 int t;
1164
1165 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001166 p2 = skipwhite(extra);
1167 p2 = skiptowhite(p2) - 1;
1168 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001169 {
1170 t = *p1;
1171 *p1 = *p2;
1172 *p2 = t;
1173 }
1174 }
1175#endif
1176 p_extra = extra;
1177 c_extra = NUL;
1178 c_final = NUL;
1179 }
1180 else
1181 {
1182 c_extra = ' ';
1183 c_final = NUL;
1184 }
1185 n_extra = number_width(wp) + 1;
1186 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
1187#ifdef FEAT_SYN_HL
1188 // When 'cursorline' is set highlight the line number of
1189 // the current line differently.
1190 // When 'cursorlineopt' has "screenline" only highlight
1191 // the line number itself.
1192 // TODO: Can we use CursorLine instead of CursorLineNr
1193 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001194 if (wp->w_p_cul
1195 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001196 && (wp->w_p_culopt_flags & CULOPT_NBR)
1197 && (row == startrow
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001198 || wp->w_p_culopt_flags & CULOPT_LINE))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001199 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLN));
1200#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001201 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1202 && HL_ATTR(HLF_LNA) != 0)
1203 // Use LineNrAbove
1204 char_attr = hl_combine_attr(wcr_attr,
1205 HL_ATTR(HLF_LNA));
1206 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1207 && HL_ATTR(HLF_LNB) != 0)
1208 // Use LineNrBelow
1209 char_attr = hl_combine_attr(wcr_attr,
1210 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001211 }
James McCoya80aad72021-12-22 19:45:28 +00001212#ifdef FEAT_SIGNS
1213 if (num_attr)
1214 char_attr = num_attr;
1215#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001216 }
1217 }
1218
1219#ifdef FEAT_LINEBREAK
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001220 if (wp->w_briopt_sbr && draw_state == WL_BRI - 1
Bram Moolenaaree857022019-11-09 23:26:40 +01001221 && n_extra == 0 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001222 // draw indent after showbreak value
1223 draw_state = WL_BRI;
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001224 else if (wp->w_briopt_sbr && draw_state == WL_SBR && n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001225 // After the showbreak, draw the breakindent
1226 draw_state = WL_BRI - 1;
1227
1228 // draw 'breakindent': indent wrapped text accordingly
1229 if (draw_state == WL_BRI - 1 && n_extra == 0)
1230 {
1231 draw_state = WL_BRI;
1232 // if need_showbreak is set, breakindent also applies
1233 if (wp->w_p_bri && n_extra == 0
1234 && (row != startrow || need_showbreak)
1235# ifdef FEAT_DIFF
1236 && filler_lines == 0
1237# endif
1238 )
1239 {
1240 char_attr = 0;
1241# ifdef FEAT_DIFF
1242 if (diff_hlf != (hlf_T)0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001243 char_attr = HL_ATTR(diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001244# endif
1245 p_extra = NULL;
1246 c_extra = ' ';
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001247 c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001248 n_extra = get_breakindent_win(wp,
1249 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001250 if (row == startrow)
1251 {
1252 n_extra -= win_col_off2(wp);
1253 if (n_extra < 0)
1254 n_extra = 0;
1255 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001256 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001257 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001258 // Correct end of highlighted area for 'breakindent',
1259 // required when 'linebreak' is also set.
1260 if (tocol == vcol)
1261 tocol += n_extra;
1262 }
1263 }
1264#endif
1265
1266#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
1267 if (draw_state == WL_SBR - 1 && n_extra == 0)
1268 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001269 char_u *sbr;
1270
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001271 draw_state = WL_SBR;
1272# ifdef FEAT_DIFF
1273 if (filler_todo > 0)
1274 {
1275 // Draw "deleted" diff line(s).
1276 if (char2cells(fill_diff) > 1)
1277 {
1278 c_extra = '-';
1279 c_final = NUL;
1280 }
1281 else
1282 {
1283 c_extra = fill_diff;
1284 c_final = NUL;
1285 }
1286# ifdef FEAT_RIGHTLEFT
1287 if (wp->w_p_rl)
1288 n_extra = col + 1;
1289 else
1290# endif
1291 n_extra = wp->w_width - col;
1292 char_attr = HL_ATTR(HLF_DED);
1293 }
1294# endif
1295# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001296 sbr = get_showbreak_value(wp);
1297 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001298 {
1299 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaaree857022019-11-09 23:26:40 +01001300 p_extra = sbr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001301 c_extra = NUL;
1302 c_final = NUL;
Bram Moolenaaree857022019-11-09 23:26:40 +01001303 n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001304 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1305 need_showbreak = FALSE;
Bram Moolenaaree857022019-11-09 23:26:40 +01001306 vcol_sbr = vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001307 // Correct end of highlighted area for 'showbreak',
1308 // required when 'linebreak' is also set.
1309 if (tocol == vcol)
1310 tocol += n_extra;
1311 // combine 'showbreak' with 'wincolor'
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001312 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001313# ifdef FEAT_SYN_HL
1314 // combine 'showbreak' with 'cursorline'
1315 if (cul_attr != 0)
1316 char_attr = hl_combine_attr(char_attr, cul_attr);
1317# endif
1318 }
1319# endif
1320 }
1321#endif
1322
1323 if (draw_state == WL_LINE - 1 && n_extra == 0)
1324 {
1325 draw_state = WL_LINE;
1326 if (saved_n_extra)
1327 {
1328 // Continue item from end of wrapped line.
1329 n_extra = saved_n_extra;
1330 c_extra = saved_c_extra;
1331 c_final = saved_c_final;
1332 p_extra = saved_p_extra;
1333 char_attr = saved_char_attr;
1334 }
1335 else
1336 char_attr = win_attr;
1337 }
1338 }
1339#ifdef FEAT_SYN_HL
zeertzjq4f33bc22021-08-05 17:57:02 +02001340 if (cul_screenline && draw_state == WL_LINE
1341 && vcol >= left_curline_col
1342 && vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001343 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001344 cul_attr = HL_ATTR(HLF_CUL);
1345 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001346 }
1347#endif
1348
1349 // When still displaying '$' of change command, stop at cursor.
1350 // When only displaying the (relative) line number and that's done,
1351 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001352 if (((dollar_vcol >= 0 && wp == curwin
1353 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol)
1354 || (number_only && draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001355#ifdef FEAT_DIFF
1356 && filler_todo <= 0
1357#endif
1358 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001359 {
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00001360 screen_line(screen_row, wp->w_wincol, col, -wp->w_width,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001361 screen_line_flags);
1362 // Pretend we have finished updating the window. Except when
1363 // 'cursorcolumn' is set.
1364#ifdef FEAT_SYN_HL
1365 if (wp->w_p_cuc)
1366 row = wp->w_cline_row + wp->w_cline_height;
1367 else
1368#endif
1369 row = wp->w_height;
1370 break;
1371 }
1372
Bram Moolenaar34390282019-10-16 14:38:26 +02001373 if (draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001374 {
1375 // handle Visual or match highlighting in this line
1376 if (vcol == fromcol
1377 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0
1378 && (*mb_ptr2cells)(ptr) > 1)
1379 || ((int)vcol_prev == fromcol_prev
1380 && vcol_prev < vcol // not at margin
1381 && vcol < tocol))
1382 area_attr = vi_attr; // start highlighting
1383 else if (area_attr != 0
1384 && (vcol == tocol
1385 || (noinvcur && (colnr_T)vcol == wp->w_virtcol)))
1386 area_attr = 0; // stop highlighting
1387
1388#ifdef FEAT_SEARCH_EXTRA
1389 if (!n_extra)
1390 {
1391 // Check for start/end of 'hlsearch' and other matches.
1392 // After end, check for start/end of next match.
1393 // When another match, have to check for start again.
1394 v = (long)(ptr - line);
1395 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1396 &screen_search_hl, &has_match_conc,
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001397 &match_conc, did_line_attr, lcs_eol_one,
1398 &on_last_col);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001399 ptr = line + v; // "line" may have been changed
Bram Moolenaarfc838d62020-06-25 22:23:48 +02001400
1401 // Do not allow a conceal over EOL otherwise EOL will be missed
1402 // and bad things happen.
1403 if (*ptr == NUL)
1404 has_match_conc = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001405 }
1406#endif
1407
1408#ifdef FEAT_DIFF
1409 if (diff_hlf != (hlf_T)0)
1410 {
1411 if (diff_hlf == HLF_CHD && ptr - line >= change_start
1412 && n_extra == 0)
1413 diff_hlf = HLF_TXD; // changed text
1414 if (diff_hlf == HLF_TXD && ptr - line > change_end
1415 && n_extra == 0)
1416 diff_hlf = HLF_CHD; // changed line
1417 line_attr = HL_ATTR(diff_hlf);
1418 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1419 && wp->w_p_culopt_flags != CULOPT_NBR
1420 && (!cul_screenline || (vcol >= left_curline_col
1421 && vcol <= right_curline_col)))
1422 line_attr = hl_combine_attr(
1423 line_attr, HL_ATTR(HLF_CUL));
1424 }
1425#endif
1426
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001427#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001428 if (text_props != NULL)
1429 {
1430 int pi;
1431 int bcol = (int)(ptr - line);
1432
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001433 if (n_extra > 0
1434# ifdef FEAT_LINEBREAK
1435 && !in_linebreak
1436# endif
1437 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001438 --bcol; // still working on the previous char, e.g. Tab
1439
1440 // Check if any active property ends.
1441 for (pi = 0; pi < text_props_active; ++pi)
1442 {
1443 int tpi = text_prop_idxs[pi];
1444
1445 if (bcol >= text_props[tpi].tp_col - 1
1446 + text_props[tpi].tp_len)
1447 {
1448 if (pi + 1 < text_props_active)
1449 mch_memmove(text_prop_idxs + pi,
1450 text_prop_idxs + pi + 1,
1451 sizeof(int)
1452 * (text_props_active - (pi + 1)));
1453 --text_props_active;
1454 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001455# ifdef FEAT_LINEBREAK
1456 // not exactly right but should work in most cases
1457 if (in_linebreak && syntax_attr == text_prop_attr)
1458 syntax_attr = 0;
1459# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001460 }
1461 }
1462
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001463# ifdef FEAT_LINEBREAK
1464 if (n_extra > 0 && in_linebreak)
1465 // not on the next char yet, don't start another prop
1466 --bcol;
1467# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001468 // Add any text property that starts in this column.
1469 while (text_prop_next < text_prop_count
1470 && bcol >= text_props[text_prop_next].tp_col - 1)
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001471 {
1472 if (bcol <= text_props[text_prop_next].tp_col - 1
1473 + text_props[text_prop_next].tp_len)
1474 text_prop_idxs[text_props_active++] = text_prop_next;
1475 ++text_prop_next;
1476 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001477
1478 text_prop_attr = 0;
1479 text_prop_combine = FALSE;
Bram Moolenaar053f7122019-09-23 22:17:15 +02001480 text_prop_type = NULL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001481 if (text_props_active > 0)
1482 {
1483 // Sort the properties on priority and/or starting last.
1484 // Then combine the attributes, highest priority last.
1485 current_text_props = text_props;
1486 current_buf = wp->w_buffer;
1487 qsort((void *)text_prop_idxs, (size_t)text_props_active,
1488 sizeof(int), text_prop_compare);
1489
1490 for (pi = 0; pi < text_props_active; ++pi)
1491 {
1492 int tpi = text_prop_idxs[pi];
1493 proptype_T *pt = text_prop_type_by_id(
1494 wp->w_buffer, text_props[tpi].tp_type);
1495
1496 if (pt != NULL && pt->pt_hl_id > 0)
1497 {
1498 int pt_attr = syn_id2attr(pt->pt_hl_id);
1499
1500 text_prop_type = pt;
1501 text_prop_attr =
1502 hl_combine_attr(text_prop_attr, pt_attr);
1503 text_prop_combine = pt->pt_flags & PT_FLAG_COMBINE;
1504 }
1505 }
1506 }
1507 }
1508#endif
1509
Bram Moolenaara74fda62019-10-19 17:38:03 +02001510#ifdef FEAT_SYN_HL
Bram Moolenaara74fda62019-10-19 17:38:03 +02001511 if (extra_check && n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001512 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001513 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001514# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001515 if (get_term_attr)
Bram Moolenaar219c7d02020-02-01 21:57:29 +01001516 syntax_attr = term_get_attr(wp, lnum, vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001517# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001518 // Get syntax attribute.
1519 if (has_syntax)
1520 {
1521 // Get the syntax attribute for the character. If there
1522 // is an error, disable syntax highlighting.
1523 save_did_emsg = did_emsg;
1524 did_emsg = FALSE;
1525
1526 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001527 if (v == prev_syntax_col)
1528 // at same column again
1529 syntax_attr = prev_syntax_attr;
1530 else
1531 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001532# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001533 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001534# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001535 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001536# ifdef FEAT_SPELL
1537 has_spell ? &can_spell :
1538# endif
1539 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001540 prev_syntax_col = v;
1541 prev_syntax_attr = syntax_attr;
1542 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001543
Bram Moolenaar34390282019-10-16 14:38:26 +02001544 if (did_emsg)
1545 {
1546 wp->w_s->b_syn_error = TRUE;
1547 has_syntax = FALSE;
1548 syntax_attr = 0;
1549 }
1550 else
1551 did_emsg = save_did_emsg;
1552# ifdef SYN_TIME_LIMIT
1553 if (wp->w_s->b_syn_slow)
1554 has_syntax = FALSE;
1555# endif
1556
1557 // Need to get the line again, a multi-line regexp may
1558 // have made it invalid.
1559 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1560 ptr = line + v;
1561# ifdef FEAT_CONCEAL
1562 // no concealing past the end of the line, it interferes
1563 // with line highlighting
1564 if (*ptr == NUL)
1565 syntax_flags = 0;
1566 else
1567 syntax_flags = get_syntax_info(&syntax_seqnr);
1568# endif
1569 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001570 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001571# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001572 // Combine text property highlight into syntax highlight.
1573 if (text_prop_type != NULL)
1574 {
1575 if (text_prop_combine)
1576 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1577 else
1578 syntax_attr = text_prop_attr;
1579 }
1580# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001581#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001582
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001583 // Decide which of the highlight attributes to use.
1584 attr_pri = TRUE;
1585#ifdef LINE_ATTR
1586 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001587 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001588 char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02001589 if (!highlight_match)
1590 // let search highlight show in Visual area if possible
1591 char_attr = hl_combine_attr(search_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001592# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001593 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001594# endif
1595 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001596 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001597 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001598 char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001599# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001600 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001601# endif
1602 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001603 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
1604 || vcol < fromcol || vcol_prev < fromcol_prev
1605 || vcol >= tocol))
1606 {
1607 // Use line_attr when not in the Visual or 'incsearch' area
1608 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001609# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001610 char_attr = hl_combine_attr(syntax_attr, line_attr);
1611# else
1612 char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001613# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001614 attr_pri = FALSE;
1615 }
1616#else
1617 if (area_attr != 0)
1618 char_attr = area_attr;
1619 else if (search_attr != 0)
1620 char_attr = search_attr;
1621#endif
1622 else
1623 {
1624 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001625#ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001626 char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001627#else
Bram Moolenaardbd43162019-11-09 21:28:14 +01001628 char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001629#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001630 }
1631 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001632
1633 // combine attribute with 'wincolor'
1634 if (win_attr != 0)
1635 {
1636 if (char_attr == 0)
1637 char_attr = win_attr;
1638 else
1639 char_attr = hl_combine_attr(win_attr, char_attr);
1640 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001641
1642 // Get the next character to put on the screen.
1643
1644 // The "p_extra" points to the extra stuff that is inserted to
1645 // represent special characters (non-printable stuff) and other
1646 // things. When all characters are the same, c_extra is used.
1647 // If c_final is set, it will compulsorily be used at the end.
1648 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
1649 // "p_extra[n_extra]".
1650 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
1651 if (n_extra > 0)
1652 {
1653 if (c_extra != NUL || (n_extra == 1 && c_final != NUL))
1654 {
1655 c = (n_extra == 1 && c_final != NUL) ? c_final : c_extra;
1656 mb_c = c; // doesn't handle non-utf-8 multi-byte!
1657 if (enc_utf8 && utf_char2len(c) > 1)
1658 {
1659 mb_utf8 = TRUE;
1660 u8cc[0] = 0;
1661 c = 0xc0;
1662 }
1663 else
1664 mb_utf8 = FALSE;
1665 }
1666 else
1667 {
1668 c = *p_extra;
1669 if (has_mbyte)
1670 {
1671 mb_c = c;
1672 if (enc_utf8)
1673 {
1674 // If the UTF-8 character is more than one byte:
1675 // Decode it into "mb_c".
1676 mb_l = utfc_ptr2len(p_extra);
1677 mb_utf8 = FALSE;
1678 if (mb_l > n_extra)
1679 mb_l = 1;
1680 else if (mb_l > 1)
1681 {
1682 mb_c = utfc_ptr2char(p_extra, u8cc);
1683 mb_utf8 = TRUE;
1684 c = 0xc0;
1685 }
1686 }
1687 else
1688 {
1689 // if this is a DBCS character, put it in "mb_c"
1690 mb_l = MB_BYTE2LEN(c);
1691 if (mb_l >= n_extra)
1692 mb_l = 1;
1693 else if (mb_l > 1)
1694 mb_c = (c << 8) + p_extra[1];
1695 }
1696 if (mb_l == 0) // at the NUL at end-of-line
1697 mb_l = 1;
1698
1699 // If a double-width char doesn't fit display a '>' in the
1700 // last column.
1701 if ((
1702# ifdef FEAT_RIGHTLEFT
1703 wp->w_p_rl ? (col <= 0) :
1704# endif
1705 (col >= wp->w_width - 1))
1706 && (*mb_char2cells)(mb_c) == 2)
1707 {
1708 c = '>';
1709 mb_c = c;
1710 mb_l = 1;
1711 mb_utf8 = FALSE;
1712 multi_attr = HL_ATTR(HLF_AT);
1713#ifdef FEAT_SYN_HL
1714 if (cul_attr)
1715 multi_attr = hl_combine_attr(multi_attr, cul_attr);
1716#endif
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001717 multi_attr = hl_combine_attr(win_attr, multi_attr);
1718
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001719 // put the pointer back to output the double-width
1720 // character at the start of the next line.
1721 ++n_extra;
1722 --p_extra;
1723 }
1724 else
1725 {
1726 n_extra -= mb_l - 1;
1727 p_extra += mb_l - 1;
1728 }
1729 }
1730 ++p_extra;
1731 }
1732 --n_extra;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001733#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001734 if (n_extra <= 0)
1735 in_linebreak = FALSE;
1736#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001737 }
1738 else
1739 {
1740#ifdef FEAT_LINEBREAK
1741 int c0;
1742#endif
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001743 VIM_CLEAR(p_extra_free);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001744
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001745 // Get a character from the line itself.
1746 c = *ptr;
1747#ifdef FEAT_LINEBREAK
1748 c0 = *ptr;
1749#endif
1750 if (has_mbyte)
1751 {
1752 mb_c = c;
1753 if (enc_utf8)
1754 {
1755 // If the UTF-8 character is more than one byte: Decode it
1756 // into "mb_c".
1757 mb_l = utfc_ptr2len(ptr);
1758 mb_utf8 = FALSE;
1759 if (mb_l > 1)
1760 {
1761 mb_c = utfc_ptr2char(ptr, u8cc);
1762 // Overlong encoded ASCII or ASCII with composing char
1763 // is displayed normally, except a NUL.
1764 if (mb_c < 0x80)
1765 {
1766 c = mb_c;
1767#ifdef FEAT_LINEBREAK
1768 c0 = mb_c;
1769#endif
1770 }
1771 mb_utf8 = TRUE;
1772
1773 // At start of the line we can have a composing char.
1774 // Draw it as a space with a composing char.
1775 if (utf_iscomposing(mb_c))
1776 {
1777 int i;
1778
1779 for (i = Screen_mco - 1; i > 0; --i)
1780 u8cc[i] = u8cc[i - 1];
1781 u8cc[0] = mb_c;
1782 mb_c = ' ';
1783 }
1784 }
1785
1786 if ((mb_l == 1 && c >= 0x80)
1787 || (mb_l >= 1 && mb_c == 0)
1788 || (mb_l > 1 && (!vim_isprintc(mb_c))))
1789 {
1790 // Illegal UTF-8 byte: display as <xx>.
1791 // Non-BMP character : display as ? or fullwidth ?.
1792 transchar_hex(extra, mb_c);
1793# ifdef FEAT_RIGHTLEFT
1794 if (wp->w_p_rl) // reverse
1795 rl_mirror(extra);
1796# endif
1797 p_extra = extra;
1798 c = *p_extra;
1799 mb_c = mb_ptr2char_adv(&p_extra);
1800 mb_utf8 = (c >= 0x80);
1801 n_extra = (int)STRLEN(p_extra);
1802 c_extra = NUL;
1803 c_final = NUL;
1804 if (area_attr == 0 && search_attr == 0)
1805 {
1806 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001807 extra_attr = hl_combine_attr(
1808 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001809 saved_attr2 = char_attr; // save current attr
1810 }
1811 }
1812 else if (mb_l == 0) // at the NUL at end-of-line
1813 mb_l = 1;
1814#ifdef FEAT_ARABIC
1815 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
1816 {
1817 // Do Arabic shaping.
1818 int pc, pc1, nc;
1819 int pcc[MAX_MCO];
1820
1821 // The idea of what is the previous and next
1822 // character depends on 'rightleft'.
1823 if (wp->w_p_rl)
1824 {
1825 pc = prev_c;
1826 pc1 = prev_c1;
1827 nc = utf_ptr2char(ptr + mb_l);
1828 prev_c1 = u8cc[0];
1829 }
1830 else
1831 {
1832 pc = utfc_ptr2char(ptr + mb_l, pcc);
1833 nc = prev_c;
1834 pc1 = pcc[0];
1835 }
1836 prev_c = mb_c;
1837
1838 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
1839 }
1840 else
1841 prev_c = mb_c;
1842#endif
1843 }
1844 else // enc_dbcs
1845 {
1846 mb_l = MB_BYTE2LEN(c);
1847 if (mb_l == 0) // at the NUL at end-of-line
1848 mb_l = 1;
1849 else if (mb_l > 1)
1850 {
1851 // We assume a second byte below 32 is illegal.
1852 // Hopefully this is OK for all double-byte encodings!
1853 if (ptr[1] >= 32)
1854 mb_c = (c << 8) + ptr[1];
1855 else
1856 {
1857 if (ptr[1] == NUL)
1858 {
1859 // head byte at end of line
1860 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02001861 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001862 }
1863 else
1864 {
1865 // illegal tail byte
1866 mb_l = 2;
1867 STRCPY(extra, "XX");
1868 }
1869 p_extra = extra;
1870 n_extra = (int)STRLEN(extra) - 1;
1871 c_extra = NUL;
1872 c_final = NUL;
1873 c = *p_extra++;
1874 if (area_attr == 0 && search_attr == 0)
1875 {
1876 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001877 extra_attr = hl_combine_attr(
1878 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001879 saved_attr2 = char_attr; // save current attr
1880 }
1881 mb_c = c;
1882 }
1883 }
1884 }
1885 // If a double-width char doesn't fit display a '>' in the
1886 // last column; the character is displayed at the start of the
1887 // next line.
1888 if ((
1889# ifdef FEAT_RIGHTLEFT
1890 wp->w_p_rl ? (col <= 0) :
1891# endif
1892 (col >= wp->w_width - 1))
1893 && (*mb_char2cells)(mb_c) == 2)
1894 {
1895 c = '>';
1896 mb_c = c;
1897 mb_utf8 = FALSE;
1898 mb_l = 1;
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001899 multi_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001900 // Put pointer back so that the character will be
1901 // displayed at the start of the next line.
1902 --ptr;
1903#ifdef FEAT_CONCEAL
1904 did_decrement_ptr = TRUE;
1905#endif
1906 }
1907 else if (*ptr != NUL)
1908 ptr += mb_l - 1;
1909
1910 // If a double-width char doesn't fit at the left side display
1911 // a '<' in the first column. Don't do this for unprintable
1912 // characters.
1913 if (n_skip > 0 && mb_l > 1 && n_extra == 0)
1914 {
1915 n_extra = 1;
1916 c_extra = MB_FILLER_CHAR;
1917 c_final = NUL;
1918 c = ' ';
1919 if (area_attr == 0 && search_attr == 0)
1920 {
1921 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001922 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001923 saved_attr2 = char_attr; // save current attr
1924 }
1925 mb_c = c;
1926 mb_utf8 = FALSE;
1927 mb_l = 1;
1928 }
1929
1930 }
1931 ++ptr;
1932
1933 if (extra_check)
1934 {
1935#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001936 // Check spelling (unless at the end of the line).
1937 // Only do this when there is no syntax highlighting, the
1938 // @Spell cluster is not used or the current syntax item
1939 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001940 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001941 if (has_spell && v >= word_end && v > cur_checked_col)
1942 {
1943 spell_attr = 0;
1944 if (c != 0 && (
1945# ifdef FEAT_SYN_HL
1946 !has_syntax ||
1947# endif
1948 can_spell))
1949 {
1950 char_u *prev_ptr, *p;
1951 int len;
1952 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01001953
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001954 if (has_mbyte)
1955 {
1956 prev_ptr = ptr - mb_l;
1957 v -= mb_l - 1;
1958 }
1959 else
1960 prev_ptr = ptr - 1;
1961
1962 // Use nextline[] if possible, it has the start of the
1963 // next line concatenated.
1964 if ((prev_ptr - line) - nextlinecol >= 0)
1965 p = nextline + (prev_ptr - line) - nextlinecol;
1966 else
1967 p = prev_ptr;
1968 cap_col -= (int)(prev_ptr - line);
1969 len = spell_check(wp, p, &spell_hlf, &cap_col,
1970 nochange);
1971 word_end = v + len;
1972
1973 // In Insert mode only highlight a word that
1974 // doesn't touch the cursor.
1975 if (spell_hlf != HLF_COUNT
1976 && (State & INSERT) != 0
1977 && wp->w_cursor.lnum == lnum
1978 && wp->w_cursor.col >=
1979 (colnr_T)(prev_ptr - line)
1980 && wp->w_cursor.col < (colnr_T)word_end)
1981 {
1982 spell_hlf = HLF_COUNT;
1983 spell_redraw_lnum = lnum;
1984 }
1985
1986 if (spell_hlf == HLF_COUNT && p != prev_ptr
1987 && (p - nextline) + len > nextline_idx)
1988 {
1989 // Remember that the good word continues at the
1990 // start of the next line.
1991 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001992 checked_col = (int)((p - nextline)
1993 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001994 }
1995
1996 // Turn index into actual attributes.
1997 if (spell_hlf != HLF_COUNT)
1998 spell_attr = highlight_attr[spell_hlf];
1999
2000 if (cap_col > 0)
2001 {
2002 if (p != prev_ptr
2003 && (p - nextline) + cap_col >= nextline_idx)
2004 {
2005 // Remember that the word in the next line
2006 // must start with a capital.
2007 capcol_lnum = lnum + 1;
2008 cap_col = (int)((p - nextline) + cap_col
2009 - nextline_idx);
2010 }
2011 else
2012 // Compute the actual column.
2013 cap_col += (int)(prev_ptr - line);
2014 }
2015 }
2016 }
2017 if (spell_attr != 0)
2018 {
2019 if (!attr_pri)
2020 char_attr = hl_combine_attr(char_attr, spell_attr);
2021 else
2022 char_attr = hl_combine_attr(spell_attr, char_attr);
2023 }
2024#endif
2025#ifdef FEAT_LINEBREAK
2026 // Found last space before word: check for line break.
2027 if (wp->w_p_lbr && c0 == c
2028 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2029 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002030 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2031 : 0;
2032 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002033
2034 // TODO: is passing p for start of the line OK?
2035 n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol,
2036 NULL) - 1;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002037
2038 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002039 // space for it again.
Bram Moolenaara06e3452021-05-29 17:56:37 +02002040 if (vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002041 {
Bram Moolenaara06e3452021-05-29 17:56:37 +02002042 n_extra -= MB_CHARLEN(get_showbreak_value(wp));
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002043 if (n_extra < 0)
2044 n_extra = 0;
2045 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002046 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002047 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002048 // line break, but for TABs the highlighting should
2049 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002050 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002051
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002052 if (c == TAB && n_extra + col > wp->w_width)
2053# ifdef FEAT_VARTABS
2054 n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts,
2055 wp->w_buffer->b_p_vts_array) - 1;
2056# else
2057 n_extra = (int)wp->w_buffer->b_p_ts
2058 - vcol % (int)wp->w_buffer->b_p_ts - 1;
2059# endif
2060
2061 c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2062 c_final = NUL;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002063# if defined(FEAT_PROP_POPUP)
Bram Moolenaar42eba042021-11-30 20:22:49 +00002064 if (n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002065 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002066# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002067 if (VIM_ISWHITE(c))
2068 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002069# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002070 if (c == TAB)
2071 // See "Tab alignment" below.
2072 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002073# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002074 if (!wp->w_p_list)
2075 c = ' ';
2076 }
2077 }
2078#endif
2079
zeertzjqf14b8ba2021-09-10 16:58:30 +02002080 in_multispace = c == ' '
2081 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2082 if (!in_multispace)
2083 multispace_pos = 0;
2084
Bram Moolenaareed9d462021-02-15 20:38:25 +01002085 // 'list': Change char 160 to 'nbsp' and space to 'space'
2086 // setting in 'listchars'. But not when the character is
2087 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002088 if (wp->w_p_list
2089 && ((((c == 160 && mb_l == 1)
2090 || (mb_utf8
2091 && ((mb_c == 160 && mb_l == 2)
2092 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002093 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002094 || (c == ' '
2095 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002096 && (wp->w_lcs_chars.space
2097 || (in_multispace
2098 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002099 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002100 && ptr - line <= trailcol)))
2101 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002102 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2103 {
2104 c = wp->w_lcs_chars.multispace[multispace_pos++];
2105 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2106 multispace_pos = 0;
2107 }
2108 else
2109 c = (c == ' ') ? wp->w_lcs_chars.space
2110 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002111 if (area_attr == 0 && search_attr == 0)
2112 {
2113 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002114 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002115 saved_attr2 = char_attr; // save current attr
2116 }
2117 mb_c = c;
2118 if (enc_utf8 && utf_char2len(c) > 1)
2119 {
2120 mb_utf8 = TRUE;
2121 u8cc[0] = 0;
2122 c = 0xc0;
2123 }
2124 else
2125 mb_utf8 = FALSE;
2126 }
2127
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002128 if ((trailcol != MAXCOL && ptr > line + trailcol && c == ' ')
2129 || (leadcol != 0 && ptr < line + leadcol && c == ' '))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002130 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002131 c = (ptr > line + trailcol) ? wp->w_lcs_chars.trail
2132 : wp->w_lcs_chars.lead;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002133 if (!attr_pri)
2134 {
2135 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002136 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002137 saved_attr2 = char_attr; // save current attr
2138 }
2139 mb_c = c;
2140 if (enc_utf8 && utf_char2len(c) > 1)
2141 {
2142 mb_utf8 = TRUE;
2143 u8cc[0] = 0;
2144 c = 0xc0;
2145 }
2146 else
2147 mb_utf8 = FALSE;
2148 }
2149 }
2150
2151 // Handling of non-printable characters.
2152 if (!vim_isprintc(c))
2153 {
2154 // when getting a character from the file, we may have to
2155 // turn it into something else on the way to putting it
2156 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002157 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002158 {
2159 int tab_len = 0;
2160 long vcol_adjusted = vcol; // removed showbreak length
2161#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002162 char_u *sbr = get_showbreak_value(wp);
2163
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002164 // only adjust the tab_len, when at the first column
2165 // after the showbreak value was drawn
Bram Moolenaaree857022019-11-09 23:26:40 +01002166 if (*sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap)
2167 vcol_adjusted = vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002168#endif
2169 // tab amount depends on current column
2170#ifdef FEAT_VARTABS
2171 tab_len = tabstop_padding(vcol_adjusted,
2172 wp->w_buffer->b_p_ts,
2173 wp->w_buffer->b_p_vts_array) - 1;
2174#else
2175 tab_len = (int)wp->w_buffer->b_p_ts
2176 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2177#endif
2178
2179#ifdef FEAT_LINEBREAK
2180 if (!wp->w_p_lbr || !wp->w_p_list)
2181#endif
2182 // tab amount depends on current column
2183 n_extra = tab_len;
2184#ifdef FEAT_LINEBREAK
2185 else
2186 {
2187 char_u *p;
2188 int len;
2189 int i;
2190 int saved_nextra = n_extra;
2191
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002192# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002193 if (vcol_off > 0)
2194 // there are characters to conceal
2195 tab_len += vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002196
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002197 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002198 if (wp->w_p_list && wp->w_lcs_chars.tab1
2199 && old_boguscols > 0
2200 && n_extra > tab_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002201 tab_len += n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002202# endif
2203 // If n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002204 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002205 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002206 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002207 if (wp->w_lcs_chars.tab3)
2208 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002209 if (n_extra > 0)
2210 len += n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002211 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002212 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002213 if (p == NULL)
2214 n_extra = 0;
2215 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002216 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002217 vim_memset(p, ' ', len);
2218 p[len] = NUL;
2219 vim_free(p_extra_free);
2220 p_extra_free = p;
2221 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002222 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002223 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002224
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002225 if (*p == NUL)
2226 {
2227 tab_len = i;
2228 break;
2229 }
2230
2231 // if tab3 is given, use it for the last char
2232 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2233 lcs = wp->w_lcs_chars.tab3;
2234 p += mb_char2bytes(lcs, p);
2235 n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002236 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002237 }
2238 p_extra = p_extra_free;
2239# ifdef FEAT_CONCEAL
2240 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2241 // macro below, so need to adjust for that here
2242 if (vcol_off > 0)
2243 n_extra -= vcol_off;
2244# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002245 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002246 }
2247#endif
2248#ifdef FEAT_CONCEAL
2249 {
2250 int vc_saved = vcol_off;
2251
2252 // Tab alignment should be identical regardless of
2253 // 'conceallevel' value. So tab compensates of all
2254 // previous concealed characters, and thus resets
2255 // vcol_off and boguscols accumulated so far in the
2256 // line. Note that the tab can be longer than
2257 // 'tabstop' when there are concealed characters.
2258 FIX_FOR_BOGUSCOLS;
2259
2260 // Make sure, the highlighting for the tab char will be
2261 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002262 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002263 if (n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002264 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002265 tab_len += vc_saved;
2266 }
2267#endif
2268 mb_utf8 = FALSE; // don't draw as UTF-8
2269 if (wp->w_p_list)
2270 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002271 c = (n_extra == 0 && wp->w_lcs_chars.tab3)
2272 ? wp->w_lcs_chars.tab3
2273 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002274#ifdef FEAT_LINEBREAK
2275 if (wp->w_p_lbr)
2276 c_extra = NUL; // using p_extra from above
2277 else
2278#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01002279 c_extra = wp->w_lcs_chars.tab2;
2280 c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002281 n_attr = tab_len + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002282 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002283 saved_attr2 = char_attr; // save current attr
2284 mb_c = c;
2285 if (enc_utf8 && utf_char2len(c) > 1)
2286 {
2287 mb_utf8 = TRUE;
2288 u8cc[0] = 0;
2289 c = 0xc0;
2290 }
2291 }
2292 else
2293 {
2294 c_final = NUL;
2295 c_extra = ' ';
2296 c = ' ';
2297 }
2298 }
2299 else if (c == NUL
2300 && (wp->w_p_list
2301 || ((fromcol >= 0 || fromcol_prev >= 0)
2302 && tocol > vcol
2303 && VIsual_mode != Ctrl_V
2304 && (
2305# ifdef FEAT_RIGHTLEFT
2306 wp->w_p_rl ? (col >= 0) :
2307# endif
2308 (col < wp->w_width))
2309 && !(noinvcur
2310 && lnum == wp->w_cursor.lnum
2311 && (colnr_T)vcol == wp->w_virtcol)))
2312 && lcs_eol_one > 0)
2313 {
2314 // Display a '$' after the line or highlight an extra
2315 // character if the line break is included.
2316#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2317 // For a diff line the highlighting continues after the
2318 // "$".
2319 if (
2320# ifdef FEAT_DIFF
2321 diff_hlf == (hlf_T)0
2322# ifdef LINE_ATTR
2323 &&
2324# endif
2325# endif
2326# ifdef LINE_ATTR
2327 line_attr == 0
2328# endif
2329 )
2330#endif
2331 {
2332 // In virtualedit, visual selections may extend
2333 // beyond end of line.
2334 if (area_highlighting && virtual_active()
2335 && tocol != MAXCOL && vcol < tocol)
2336 n_extra = 0;
2337 else
2338 {
2339 p_extra = at_end_str;
2340 n_extra = 1;
2341 c_extra = NUL;
2342 c_final = NUL;
2343 }
2344 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002345 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2346 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002347 else
2348 c = ' ';
2349 lcs_eol_one = -1;
2350 --ptr; // put it back at the NUL
2351 if (!attr_pri)
2352 {
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002353 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002354 n_attr = 1;
2355 }
2356 mb_c = c;
2357 if (enc_utf8 && utf_char2len(c) > 1)
2358 {
2359 mb_utf8 = TRUE;
2360 u8cc[0] = 0;
2361 c = 0xc0;
2362 }
2363 else
2364 mb_utf8 = FALSE; // don't draw as UTF-8
2365 }
2366 else if (c != NUL)
2367 {
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002368 p_extra = transchar_buf(wp->w_buffer, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002369 if (n_extra == 0)
2370 n_extra = byte2cells(c) - 1;
2371#ifdef FEAT_RIGHTLEFT
2372 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
2373 rl_mirror(p_extra); // reverse "<12>"
2374#endif
2375 c_extra = NUL;
2376 c_final = NUL;
2377#ifdef FEAT_LINEBREAK
2378 if (wp->w_p_lbr)
2379 {
2380 char_u *p;
2381
2382 c = *p_extra;
2383 p = alloc(n_extra + 1);
2384 vim_memset(p, ' ', n_extra);
2385 STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1);
2386 p[n_extra] = NUL;
2387 vim_free(p_extra_free);
2388 p_extra_free = p_extra = p;
2389 }
2390 else
2391#endif
2392 {
2393 n_extra = byte2cells(c) - 1;
2394 c = *p_extra++;
2395 }
2396 if (!attr_pri)
2397 {
2398 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002399 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002400 saved_attr2 = char_attr; // save current attr
2401 }
2402 mb_utf8 = FALSE; // don't draw as UTF-8
2403 }
2404 else if (VIsual_active
2405 && (VIsual_mode == Ctrl_V
2406 || VIsual_mode == 'v')
2407 && virtual_active()
2408 && tocol != MAXCOL
2409 && vcol < tocol
2410 && (
2411#ifdef FEAT_RIGHTLEFT
2412 wp->w_p_rl ? (col >= 0) :
2413#endif
2414 (col < wp->w_width)))
2415 {
2416 c = ' ';
2417 --ptr; // put it back at the NUL
2418 }
2419#if defined(LINE_ATTR)
2420 else if ((
2421# ifdef FEAT_DIFF
2422 diff_hlf != (hlf_T)0 ||
2423# endif
2424# ifdef FEAT_TERMINAL
2425 win_attr != 0 ||
2426# endif
2427 line_attr != 0
2428 ) && (
2429# ifdef FEAT_RIGHTLEFT
2430 wp->w_p_rl ? (col >= 0) :
2431# endif
2432 (col
2433# ifdef FEAT_CONCEAL
2434 - boguscols
2435# endif
2436 < wp->w_width)))
2437 {
2438 // Highlight until the right side of the window
2439 c = ' ';
2440 --ptr; // put it back at the NUL
2441
2442 // Remember we do the char for line highlighting.
2443 ++did_line_attr;
2444
2445 // don't do search HL for the rest of the line
2446 if (line_attr != 0 && char_attr == search_attr
2447 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002448 || (wp->w_p_list &&
2449 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002450 char_attr = line_attr;
2451# ifdef FEAT_DIFF
2452 if (diff_hlf == HLF_TXD)
2453 {
2454 diff_hlf = HLF_CHD;
2455 if (vi_attr == 0 || char_attr != vi_attr)
2456 {
2457 char_attr = HL_ATTR(diff_hlf);
2458 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2459 && wp->w_p_culopt_flags != CULOPT_NBR
2460 && (!cul_screenline
2461 || (vcol >= left_curline_col
2462 && vcol <= right_curline_col)))
2463 char_attr = hl_combine_attr(
2464 char_attr, HL_ATTR(HLF_CUL));
2465 }
2466 }
2467# endif
2468# ifdef FEAT_TERMINAL
2469 if (win_attr != 0)
2470 {
2471 char_attr = win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002472 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2473 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002474 {
2475 if (!cul_screenline || (vcol >= left_curline_col
2476 && vcol <= right_curline_col))
2477 char_attr = hl_combine_attr(
2478 char_attr, HL_ATTR(HLF_CUL));
2479 }
2480 else if (line_attr)
2481 char_attr = hl_combine_attr(char_attr, line_attr);
2482 }
2483# endif
2484 }
2485#endif
2486 }
2487
2488#ifdef FEAT_CONCEAL
2489 if ( wp->w_p_cole > 0
2490 && (wp != curwin || lnum != wp->w_cursor.lnum ||
2491 conceal_cursor_line(wp))
2492 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2493 && !(lnum_in_visual_area
2494 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2495 {
2496 char_attr = conceal_attr;
2497 if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002498 && (syn_get_sub_char() != NUL
2499 || (has_match_conc && match_conc)
2500 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002501 && wp->w_p_cole != 3)
2502 {
2503 // First time at this concealed item: display one
2504 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002505 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002506 c = match_conc;
2507 else if (syn_get_sub_char() != NUL)
2508 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01002509 else if (wp->w_lcs_chars.conceal != NUL)
2510 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002511 else
2512 c = ' ';
2513
2514 prev_syntax_id = syntax_seqnr;
2515
2516 if (n_extra > 0)
2517 vcol_off += n_extra;
2518 vcol += n_extra;
2519 if (wp->w_p_wrap && n_extra > 0)
2520 {
2521# ifdef FEAT_RIGHTLEFT
2522 if (wp->w_p_rl)
2523 {
2524 col -= n_extra;
2525 boguscols -= n_extra;
2526 }
2527 else
2528# endif
2529 {
2530 boguscols += n_extra;
2531 col += n_extra;
2532 }
2533 }
2534 n_extra = 0;
2535 n_attr = 0;
2536 }
2537 else if (n_skip == 0)
2538 {
2539 is_concealing = TRUE;
2540 n_skip = 1;
2541 }
2542 mb_c = c;
2543 if (enc_utf8 && utf_char2len(c) > 1)
2544 {
2545 mb_utf8 = TRUE;
2546 u8cc[0] = 0;
2547 c = 0xc0;
2548 }
2549 else
2550 mb_utf8 = FALSE; // don't draw as UTF-8
2551 }
2552 else
2553 {
2554 prev_syntax_id = 0;
2555 is_concealing = FALSE;
2556 }
2557
2558 if (n_skip > 0 && did_decrement_ptr)
2559 // not showing the '>', put pointer back to avoid getting stuck
2560 ++ptr;
2561
2562#endif // FEAT_CONCEAL
2563 }
2564
2565#ifdef FEAT_CONCEAL
2566 // In the cursor line and we may be concealing characters: correct
2567 // the cursor column when we reach its position.
2568 if (!did_wcol && draw_state == WL_LINE
2569 && wp == curwin && lnum == wp->w_cursor.lnum
2570 && conceal_cursor_line(wp)
2571 && (int)wp->w_virtcol <= vcol + n_skip)
2572 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002573# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002574 if (wp->w_p_rl)
2575 wp->w_wcol = wp->w_width - col + boguscols - 1;
2576 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002577# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002578 wp->w_wcol = col - boguscols;
2579 wp->w_wrow = row;
2580 did_wcol = TRUE;
2581 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002582# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01002583 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002584# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002585 }
2586#endif
2587
2588 // Don't override visual selection highlighting.
2589 if (n_attr > 0
2590 && draw_state == WL_LINE
2591 && !attr_pri)
2592 {
2593#ifdef LINE_ATTR
2594 if (line_attr)
2595 char_attr = hl_combine_attr(extra_attr, line_attr);
2596 else
2597#endif
2598 char_attr = extra_attr;
2599 }
2600
2601#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2602 // XIM don't send preedit_start and preedit_end, but they send
2603 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
2604 // im_is_preediting() here.
2605 if (p_imst == IM_ON_THE_SPOT
2606 && xic != NULL
2607 && lnum == wp->w_cursor.lnum
2608 && (State & INSERT)
2609 && !p_imdisable
2610 && im_is_preediting()
2611 && draw_state == WL_LINE)
2612 {
2613 colnr_T tcol;
2614
2615 if (preedit_end_col == MAXCOL)
2616 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
2617 else
2618 tcol = preedit_end_col;
2619 if ((long)preedit_start_col <= vcol && vcol < (long)tcol)
2620 {
2621 if (feedback_old_attr < 0)
2622 {
2623 feedback_col = 0;
2624 feedback_old_attr = char_attr;
2625 }
2626 char_attr = im_get_feedback_attr(feedback_col);
2627 if (char_attr < 0)
2628 char_attr = feedback_old_attr;
2629 feedback_col++;
2630 }
2631 else if (feedback_old_attr >= 0)
2632 {
2633 char_attr = feedback_old_attr;
2634 feedback_old_attr = -1;
2635 feedback_col = 0;
2636 }
2637 }
2638#endif
2639 // Handle the case where we are in column 0 but not on the first
2640 // character of the line and the user wants us to show us a
2641 // special character (via 'listchars' option "precedes:<char>".
2642 if (lcs_prec_todo != NUL
2643 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02002644 && (wp->w_p_wrap ?
2645 (wp->w_skipcol > 0 && row == 0) :
2646 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002647#ifdef FEAT_DIFF
2648 && filler_todo <= 0
2649#endif
2650 && draw_state > WL_NR
2651 && c != NUL)
2652 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002653 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002654 lcs_prec_todo = NUL;
2655 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2656 {
2657 // Double-width character being overwritten by the "precedes"
2658 // character, need to fill up half the character.
2659 c_extra = MB_FILLER_CHAR;
2660 c_final = NUL;
2661 n_extra = 1;
2662 n_attr = 2;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002663 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002664 }
2665 mb_c = c;
2666 if (enc_utf8 && utf_char2len(c) > 1)
2667 {
2668 mb_utf8 = TRUE;
2669 u8cc[0] = 0;
2670 c = 0xc0;
2671 }
2672 else
2673 mb_utf8 = FALSE; // don't draw as UTF-8
2674 if (!attr_pri)
2675 {
2676 saved_attr3 = char_attr; // save current attr
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002677 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002678 n_attr3 = 1;
2679 }
2680 }
2681
2682 // At end of the text line or just after the last character.
2683 if ((c == NUL
2684#if defined(LINE_ATTR)
2685 || did_line_attr == 1
2686#endif
2687 ) && eol_hl_off == 0)
2688 {
2689#ifdef FEAT_SEARCH_EXTRA
2690 // flag to indicate whether prevcol equals startcol of search_hl or
2691 // one of the matches
2692 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
2693 (long)(ptr - line) - (c == NUL));
2694#endif
2695 // Invert at least one char, used for Visual and empty line or
2696 // highlight match at end of line. If it's beyond the last
2697 // char on the screen, just overwrite that one (tricky!) Not
2698 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002699 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002700 && ((area_attr != 0 && vcol == fromcol
2701 && (VIsual_mode != Ctrl_V
2702 || lnum == VIsual.lnum
2703 || lnum == curwin->w_cursor.lnum)
2704 && c == NUL)
2705#ifdef FEAT_SEARCH_EXTRA
2706 // highlight 'hlsearch' match at end of line
2707 || (prevcol_hl_flag
2708# ifdef FEAT_SYN_HL
2709 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
2710 && !(wp == curwin && VIsual_active))
2711# endif
2712# ifdef FEAT_DIFF
2713 && diff_hlf == (hlf_T)0
2714# endif
2715# if defined(LINE_ATTR)
2716 && did_line_attr <= 1
2717# endif
2718 )
2719#endif
2720 ))
2721 {
2722 int n = 0;
2723
2724#ifdef FEAT_RIGHTLEFT
2725 if (wp->w_p_rl)
2726 {
2727 if (col < 0)
2728 n = 1;
2729 }
2730 else
2731#endif
2732 {
2733 if (col >= wp->w_width)
2734 n = -1;
2735 }
2736 if (n != 0)
2737 {
2738 // At the window boundary, highlight the last character
2739 // instead (better than nothing).
2740 off += n;
2741 col += n;
2742 }
2743 else
2744 {
2745 // Add a blank character to highlight.
2746 ScreenLines[off] = ' ';
2747 if (enc_utf8)
2748 ScreenLinesUC[off] = 0;
2749 }
2750#ifdef FEAT_SEARCH_EXTRA
2751 if (area_attr == 0)
2752 {
2753 // Use attributes from match with highest priority among
2754 // 'search_hl' and the match list.
2755 get_search_match_hl(wp, &screen_search_hl,
2756 (long)(ptr - line), &char_attr);
2757 }
2758#endif
2759 ScreenAttrs[off] = char_attr;
2760#ifdef FEAT_RIGHTLEFT
2761 if (wp->w_p_rl)
2762 {
2763 --col;
2764 --off;
2765 }
2766 else
2767#endif
2768 {
2769 ++col;
2770 ++off;
2771 }
2772 ++vcol;
2773 eol_hl_off = 1;
2774 }
2775 }
2776
2777 // At end of the text line.
2778 if (c == NUL)
2779 {
2780#ifdef FEAT_SYN_HL
2781 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
2782 if (wp->w_p_wrap)
2783 v = wp->w_skipcol;
2784 else
2785 v = wp->w_leftcol;
2786
2787 // check if line ends before left margin
2788 if (vcol < v + col - win_col_off(wp))
2789 vcol = v + col - win_col_off(wp);
2790#ifdef FEAT_CONCEAL
2791 // Get rid of the boguscols now, we want to draw until the right
2792 // edge for 'cursorcolumn'.
2793 col -= boguscols;
2794 boguscols = 0;
2795#endif
2796
2797 if (draw_color_col)
2798 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2799
2800 if (((wp->w_p_cuc
2801 && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off
2802 && (int)wp->w_virtcol <
=?UTF-8?q?Dundar=20G=C3=B6c?=d5cec1f2022-01-29 15:19:23 +00002803 (long)wp->w_width * (row - startrow + 1) + v
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002804 && lnum != wp->w_cursor.lnum)
2805 || draw_color_col
2806 || win_attr != 0)
2807# ifdef FEAT_RIGHTLEFT
2808 && !wp->w_p_rl
2809# endif
2810 )
2811 {
2812 int rightmost_vcol = 0;
2813 int i;
2814
2815 if (wp->w_p_cuc)
2816 rightmost_vcol = wp->w_virtcol;
2817 if (draw_color_col)
2818 // determine rightmost colorcolumn to possibly draw
2819 for (i = 0; color_cols[i] >= 0; ++i)
2820 if (rightmost_vcol < color_cols[i])
2821 rightmost_vcol = color_cols[i];
2822
2823 while (col < wp->w_width)
2824 {
2825 ScreenLines[off] = ' ';
2826 if (enc_utf8)
2827 ScreenLinesUC[off] = 0;
2828 ++col;
2829 if (draw_color_col)
2830 draw_color_col = advance_color_col(VCOL_HLC,
2831 &color_cols);
2832
2833 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
2834 ScreenAttrs[off++] = HL_ATTR(HLF_CUC);
2835 else if (draw_color_col && VCOL_HLC == *color_cols)
2836 ScreenAttrs[off++] = HL_ATTR(HLF_MC);
2837 else
2838 ScreenAttrs[off++] = win_attr;
2839
2840 if (VCOL_HLC >= rightmost_vcol && win_attr == 0)
2841 break;
2842
2843 ++vcol;
2844 }
2845 }
2846#endif
2847
2848 screen_line(screen_row, wp->w_wincol, col,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00002849 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002850 row++;
2851
2852 // Update w_cline_height and w_cline_folded if the cursor line was
2853 // updated (saves a call to plines() later).
2854 if (wp == curwin && lnum == curwin->w_cursor.lnum)
2855 {
2856 curwin->w_cline_row = startrow;
2857 curwin->w_cline_height = row - startrow;
2858#ifdef FEAT_FOLDING
2859 curwin->w_cline_folded = FALSE;
2860#endif
2861 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
2862 }
2863
2864 break;
2865 }
2866
2867 // Show "extends" character from 'listchars' if beyond the line end and
2868 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002869 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar41fb7232021-07-08 12:40:05 +02002870 && draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002871 && wp->w_p_list
2872 && !wp->w_p_wrap
2873#ifdef FEAT_DIFF
2874 && filler_todo <= 0
2875#endif
2876 && (
2877#ifdef FEAT_RIGHTLEFT
2878 wp->w_p_rl ? col == 0 :
2879#endif
2880 col == wp->w_width - 1)
2881 && (*ptr != NUL
2882 || (wp->w_p_list && lcs_eol_one > 0)
2883 || (n_extra && (c_extra != NUL || *p_extra != NUL))))
2884 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002885 c = wp->w_lcs_chars.ext;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002886 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002887 mb_c = c;
2888 if (enc_utf8 && utf_char2len(c) > 1)
2889 {
2890 mb_utf8 = TRUE;
2891 u8cc[0] = 0;
2892 c = 0xc0;
2893 }
2894 else
2895 mb_utf8 = FALSE;
2896 }
2897
2898#ifdef FEAT_SYN_HL
2899 // advance to the next 'colorcolumn'
2900 if (draw_color_col)
2901 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2902
2903 // Highlight the cursor column if 'cursorcolumn' is set. But don't
2904 // highlight the cursor position itself.
2905 // Also highlight the 'colorcolumn' if it is different than
2906 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02002907 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
2908 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002909 vcol_save_attr = -1;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002910 if (((draw_state == WL_LINE ||
Bram Moolenaarad5e5632020-09-15 20:52:26 +02002911 draw_state == WL_BRI ||
2912 draw_state == WL_SBR) && !lnum_in_visual_area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002913 && search_attr == 0 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002914# ifdef FEAT_DIFF
2915 && filler_todo <= 0
2916# endif
2917 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002918 {
2919 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
2920 && lnum != wp->w_cursor.lnum)
2921 {
2922 vcol_save_attr = char_attr;
2923 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUC));
2924 }
2925 else if (draw_color_col && VCOL_HLC == *color_cols)
2926 {
2927 vcol_save_attr = char_attr;
2928 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_MC));
2929 }
2930 }
2931#endif
2932
2933 // Store character to be displayed.
2934 // Skip characters that are left of the screen for 'nowrap'.
2935 vcol_prev = vcol;
2936 if (draw_state < WL_LINE || n_skip <= 0)
2937 {
2938 // Store the character.
2939#if defined(FEAT_RIGHTLEFT)
2940 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
2941 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002942 // A double-wide character is: put first half in left cell.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002943 --off;
2944 --col;
2945 }
2946#endif
2947 ScreenLines[off] = c;
2948 if (enc_dbcs == DBCS_JPNU)
2949 {
2950 if ((mb_c & 0xff00) == 0x8e00)
2951 ScreenLines[off] = 0x8e;
2952 ScreenLines2[off] = mb_c & 0xff;
2953 }
2954 else if (enc_utf8)
2955 {
2956 if (mb_utf8)
2957 {
2958 int i;
2959
2960 ScreenLinesUC[off] = mb_c;
2961 if ((c & 0xff) == 0)
2962 ScreenLines[off] = 0x80; // avoid storing zero
2963 for (i = 0; i < Screen_mco; ++i)
2964 {
2965 ScreenLinesC[i][off] = u8cc[i];
2966 if (u8cc[i] == 0)
2967 break;
2968 }
2969 }
2970 else
2971 ScreenLinesUC[off] = 0;
2972 }
2973 if (multi_attr)
2974 {
2975 ScreenAttrs[off] = multi_attr;
2976 multi_attr = 0;
2977 }
2978 else
2979 ScreenAttrs[off] = char_attr;
2980
2981 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2982 {
2983 // Need to fill two screen columns.
2984 ++off;
2985 ++col;
2986 if (enc_utf8)
2987 // UTF-8: Put a 0 in the second screen char.
2988 ScreenLines[off] = 0;
2989 else
2990 // DBCS: Put second byte in the second screen char.
2991 ScreenLines[off] = mb_c & 0xff;
2992 if (draw_state > WL_NR
2993#ifdef FEAT_DIFF
2994 && filler_todo <= 0
2995#endif
2996 )
2997 ++vcol;
2998 // When "tocol" is halfway a character, set it to the end of
2999 // the character, otherwise highlighting won't stop.
3000 if (tocol == vcol)
3001 ++tocol;
3002#ifdef FEAT_RIGHTLEFT
3003 if (wp->w_p_rl)
3004 {
3005 // now it's time to backup one cell
3006 --off;
3007 --col;
3008 }
3009#endif
3010 }
3011#ifdef FEAT_RIGHTLEFT
3012 if (wp->w_p_rl)
3013 {
3014 --off;
3015 --col;
3016 }
3017 else
3018#endif
3019 {
3020 ++off;
3021 ++col;
3022 }
3023 }
3024#ifdef FEAT_CONCEAL
3025 else if (wp->w_p_cole > 0 && is_concealing)
3026 {
3027 --n_skip;
3028 ++vcol_off;
3029 if (n_extra > 0)
3030 vcol_off += n_extra;
3031 if (wp->w_p_wrap)
3032 {
3033 // Special voodoo required if 'wrap' is on.
3034 //
3035 // Advance the column indicator to force the line
3036 // drawing to wrap early. This will make the line
3037 // take up the same screen space when parts are concealed,
3038 // so that cursor line computations aren't messed up.
3039 //
3040 // To avoid the fictitious advance of 'col' causing
3041 // trailing junk to be written out of the screen line
3042 // we are building, 'boguscols' keeps track of the number
3043 // of bad columns we have advanced.
3044 if (n_extra > 0)
3045 {
3046 vcol += n_extra;
3047# ifdef FEAT_RIGHTLEFT
3048 if (wp->w_p_rl)
3049 {
3050 col -= n_extra;
3051 boguscols -= n_extra;
3052 }
3053 else
3054# endif
3055 {
3056 col += n_extra;
3057 boguscols += n_extra;
3058 }
3059 n_extra = 0;
3060 n_attr = 0;
3061 }
3062
3063
3064 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3065 {
3066 // Need to fill two screen columns.
3067# ifdef FEAT_RIGHTLEFT
3068 if (wp->w_p_rl)
3069 {
3070 --boguscols;
3071 --col;
3072 }
3073 else
3074# endif
3075 {
3076 ++boguscols;
3077 ++col;
3078 }
3079 }
3080
3081# ifdef FEAT_RIGHTLEFT
3082 if (wp->w_p_rl)
3083 {
3084 --boguscols;
3085 --col;
3086 }
3087 else
3088# endif
3089 {
3090 ++boguscols;
3091 ++col;
3092 }
3093 }
3094 else
3095 {
3096 if (n_extra > 0)
3097 {
3098 vcol += n_extra;
3099 n_extra = 0;
3100 n_attr = 0;
3101 }
3102 }
3103
3104 }
3105#endif // FEAT_CONCEAL
3106 else
3107 --n_skip;
3108
3109 // Only advance the "vcol" when after the 'number' or 'relativenumber'
3110 // column.
3111 if (draw_state > WL_NR
3112#ifdef FEAT_DIFF
3113 && filler_todo <= 0
3114#endif
3115 )
3116 ++vcol;
3117
3118#ifdef FEAT_SYN_HL
3119 if (vcol_save_attr >= 0)
3120 char_attr = vcol_save_attr;
3121#endif
3122
3123 // restore attributes after "predeces" in 'listchars'
3124 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3125 char_attr = saved_attr3;
3126
3127 // restore attributes after last 'listchars' or 'number' char
3128 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0)
3129 char_attr = saved_attr2;
3130
3131 // At end of screen line and there is more to come: Display the line
3132 // so far. If there is no more to display it is caught above.
3133 if ((
3134#ifdef FEAT_RIGHTLEFT
3135 wp->w_p_rl ? (col < 0) :
3136#endif
3137 (col >= wp->w_width))
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003138 && (draw_state != WL_LINE
3139 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003140#ifdef FEAT_DIFF
3141 || filler_todo > 0
3142#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003143 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
3144 && p_extra != at_end_str)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003145 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL)))
3146 )
3147 {
3148#ifdef FEAT_CONCEAL
3149 screen_line(screen_row, wp->w_wincol, col - boguscols,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00003150 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003151 boguscols = 0;
3152#else
3153 screen_line(screen_row, wp->w_wincol, col,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00003154 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003155#endif
3156 ++row;
3157 ++screen_row;
3158
3159 // When not wrapping and finished diff lines, or when displayed
3160 // '$' and highlighting until last column, break here.
3161 if ((!wp->w_p_wrap
3162#ifdef FEAT_DIFF
3163 && filler_todo <= 0
3164#endif
3165 ) || lcs_eol_one == -1)
3166 break;
3167
3168 // When the window is too narrow draw all "@" lines.
3169 if (draw_state != WL_LINE
3170#ifdef FEAT_DIFF
3171 && filler_todo <= 0
3172#endif
3173 )
3174 {
3175 win_draw_end(wp, '@', ' ', TRUE, row, wp->w_height, HLF_AT);
3176 draw_vsep_win(wp, row);
3177 row = endrow;
3178 }
3179
3180 // When line got too long for screen break here.
3181 if (row == endrow)
3182 {
3183 ++row;
3184 break;
3185 }
3186
3187 if (screen_cur_row == screen_row - 1
3188#ifdef FEAT_DIFF
3189 && filler_todo <= 0
3190#endif
3191 && wp->w_width == Columns)
3192 {
3193 // Remember that the line wraps, used for modeless copy.
3194 LineWraps[screen_row - 1] = TRUE;
3195
3196 // Special trick to make copy/paste of wrapped lines work with
3197 // xterm/screen: write an extra character beyond the end of
3198 // the line. This will work with all terminal types
3199 // (regardless of the xn,am settings).
3200 // Only do this on a fast tty.
3201 // Only do this if the cursor is on the current line
3202 // (something has been written in it).
3203 // Don't do this for the GUI.
3204 // Don't do this for double-width characters.
3205 // Don't do this for a window not at the right screen border.
3206 if (p_tf
3207#ifdef FEAT_GUI
3208 && !gui.in_use
3209#endif
3210 && !(has_mbyte
3211 && ((*mb_off2cells)(LineOffset[screen_row],
3212 LineOffset[screen_row] + screen_Columns)
3213 == 2
3214 || (*mb_off2cells)(LineOffset[screen_row - 1]
3215 + (int)Columns - 2,
3216 LineOffset[screen_row] + screen_Columns)
3217 == 2)))
3218 {
3219 // First make sure we are at the end of the screen line,
3220 // then output the same character again to let the
3221 // terminal know about the wrap. If the terminal doesn't
3222 // auto-wrap, we overwrite the character.
3223 if (screen_cur_col != wp->w_width)
3224 screen_char(LineOffset[screen_row - 1]
3225 + (unsigned)Columns - 1,
3226 screen_row - 1, (int)(Columns - 1));
3227
3228 // When there is a multi-byte character, just output a
3229 // space to keep it simple.
3230 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
3231 screen_row - 1] + (Columns - 1)]) > 1)
3232 out_char(' ');
3233 else
3234 out_char(ScreenLines[LineOffset[screen_row - 1]
3235 + (Columns - 1)]);
3236 // force a redraw of the first char on the next line
3237 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1;
3238 screen_start(); // don't know where cursor is now
3239 }
3240 }
3241
3242 col = 0;
3243 off = (unsigned)(current_ScreenLine - ScreenLines);
3244#ifdef FEAT_RIGHTLEFT
3245 if (wp->w_p_rl)
3246 {
3247 col = wp->w_width - 1; // col is not used if breaking!
3248 off += col;
3249 }
3250#endif
3251
3252 // reset the drawing state for the start of a wrapped line
3253 draw_state = WL_START;
3254 saved_n_extra = n_extra;
3255 saved_p_extra = p_extra;
3256 saved_c_extra = c_extra;
3257 saved_c_final = c_final;
3258#ifdef FEAT_SYN_HL
3259 if (!(cul_screenline
3260# ifdef FEAT_DIFF
Bram Moolenaare7705982020-04-21 22:23:15 +02003261 && diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003262# endif
Bram Moolenaare7705982020-04-21 22:23:15 +02003263 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003264 saved_char_attr = char_attr;
3265 else
3266#endif
3267 saved_char_attr = 0;
3268 n_extra = 0;
Bram Moolenaareed9d462021-02-15 20:38:25 +01003269 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003270#ifdef FEAT_LINEBREAK
3271# ifdef FEAT_DIFF
3272 if (filler_todo <= 0)
3273# endif
3274 need_showbreak = TRUE;
3275#endif
3276#ifdef FEAT_DIFF
3277 --filler_todo;
3278 // When the filler lines are actually below the last line of the
3279 // file, don't draw the line itself, break here.
3280 if (filler_todo == 0 && wp->w_botfill)
3281 break;
3282#endif
3283 }
3284
3285 } // for every character in the line
3286
3287#ifdef FEAT_SPELL
3288 // After an empty line check first word for capital.
3289 if (*skipwhite(line) == NUL)
3290 {
3291 capcol_lnum = lnum + 1;
3292 cap_col = 0;
3293 }
3294#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003295#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003296 vim_free(text_props);
3297 vim_free(text_prop_idxs);
3298#endif
3299
3300 vim_free(p_extra_free);
3301 return row;
3302}