blob: 077e7fcde37f8270af11c0c8f4111031093867cf [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/*
80 * Get information needed to display the sign in line 'lnum' in window 'wp'.
81 * If 'nrcol' is TRUE, the sign is going to be displayed in the number column.
82 * Otherwise the sign is going to be displayed in the sign column.
83 */
84 static void
85get_sign_display_info(
86 int nrcol,
87 win_T *wp,
88 linenr_T lnum UNUSED,
89 sign_attrs_T *sattr,
90 int wcr_attr,
91 int row,
92 int startrow,
93 int filler_lines UNUSED,
94 int filler_todo UNUSED,
95 int *c_extrap,
96 int *c_finalp,
97 char_u *extra,
98 char_u **pp_extra,
99 int *n_extrap,
100 int *char_attrp)
101{
102 int text_sign;
103# ifdef FEAT_SIGN_ICONS
104 int icon_sign;
105# endif
106
107 // Draw two cells with the sign value or blank.
108 *c_extrap = ' ';
109 *c_finalp = NUL;
110 if (nrcol)
111 *n_extrap = number_width(wp) + 1;
112 else
113 {
114 *char_attrp = hl_combine_attr(wcr_attr, HL_ATTR(HLF_SC));
115 *n_extrap = 2;
116 }
117
118 if (row == startrow
119#ifdef FEAT_DIFF
120 + filler_lines && filler_todo <= 0
121#endif
122 )
123 {
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200124 text_sign = (sattr->sat_text != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200125# ifdef FEAT_SIGN_ICONS
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200126 icon_sign = (sattr->sat_icon != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200127 if (gui.in_use && icon_sign != 0)
128 {
129 // Use the image in this position.
130 if (nrcol)
131 {
132 *c_extrap = NUL;
133 sprintf((char *)extra, "%-*c ", number_width(wp), SIGN_BYTE);
134 *pp_extra = extra;
135 *n_extrap = (int)STRLEN(*pp_extra);
136 }
137 else
138 *c_extrap = SIGN_BYTE;
139# ifdef FEAT_NETBEANS_INTG
140 if (netbeans_active() && (buf_signcount(wp->w_buffer, lnum) > 1))
141 {
142 if (nrcol)
143 {
144 *c_extrap = NUL;
145 sprintf((char *)extra, "%-*c ", number_width(wp),
146 MULTISIGN_BYTE);
147 *pp_extra = extra;
148 *n_extrap = (int)STRLEN(*pp_extra);
149 }
150 else
151 *c_extrap = MULTISIGN_BYTE;
152 }
153# endif
154 *c_finalp = NUL;
155 *char_attrp = icon_sign;
156 }
157 else
158# endif
159 if (text_sign != 0)
160 {
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200161 *pp_extra = sattr->sat_text;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200162 if (*pp_extra != NULL)
163 {
164 if (nrcol)
165 {
166 int n, width = number_width(wp) - 2;
167
168 for (n = 0; n < width; n++)
169 extra[n] = ' ';
170 extra[n] = 0;
171 STRCAT(extra, *pp_extra);
172 STRCAT(extra, " ");
173 *pp_extra = extra;
174 }
175 *c_extrap = NUL;
176 *c_finalp = NUL;
177 *n_extrap = (int)STRLEN(*pp_extra);
178 }
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200179 *char_attrp = sattr->sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200180 }
181 }
182}
183#endif
184
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100185#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200186static textprop_T *current_text_props = NULL;
187static buf_T *current_buf = NULL;
188
189 static int
190text_prop_compare(const void *s1, const void *s2)
191{
192 int idx1, idx2;
193 proptype_T *pt1, *pt2;
194 colnr_T col1, col2;
195
196 idx1 = *(int *)s1;
197 idx2 = *(int *)s2;
198 pt1 = text_prop_type_by_id(current_buf, current_text_props[idx1].tp_type);
199 pt2 = text_prop_type_by_id(current_buf, current_text_props[idx2].tp_type);
200 if (pt1 == pt2)
201 return 0;
202 if (pt1 == NULL)
203 return -1;
204 if (pt2 == NULL)
205 return 1;
206 if (pt1->pt_priority != pt2->pt_priority)
207 return pt1->pt_priority > pt2->pt_priority ? 1 : -1;
208 col1 = current_text_props[idx1].tp_col;
209 col2 = current_text_props[idx2].tp_col;
210 return col1 == col2 ? 0 : col1 > col2 ? 1 : -1;
211}
212#endif
213
214/*
215 * Display line "lnum" of window 'wp' on the screen.
216 * Start at row "startrow", stop when "endrow" is reached.
217 * wp->w_virtcol needs to be valid.
218 *
219 * Return the number of last row the line occupies.
220 */
221 int
222win_line(
223 win_T *wp,
224 linenr_T lnum,
225 int startrow,
226 int endrow,
227 int nochange UNUSED, // not updating for changed text
228 int number_only) // only update the number column
229{
230 int col = 0; // visual column on screen
231 unsigned off; // offset in ScreenLines/ScreenAttrs
232 int c = 0; // init for GCC
233 long vcol = 0; // virtual column (for tabs)
234#ifdef FEAT_LINEBREAK
235 long vcol_sbr = -1; // virtual column after showbreak
236#endif
237 long vcol_prev = -1; // "vcol" of previous character
238 char_u *line; // current line
239 char_u *ptr; // current position in "line"
240 int row; // row in the window, excl w_winrow
241 int screen_row; // row on the screen, incl w_winrow
242
243 char_u extra[21]; // "%ld " and 'fdc' must fit in here
244 int n_extra = 0; // number of extra chars
245 char_u *p_extra = NULL; // string of extra chars, plus NUL
246 char_u *p_extra_free = NULL; // p_extra needs to be freed
247 int c_extra = NUL; // extra chars, all the same
248 int c_final = NUL; // final char, mandatory if set
249 int extra_attr = 0; // attributes when n_extra != 0
250 static char_u *at_end_str = (char_u *)""; // used for p_extra when
251 // displaying lcs_eol at end-of-line
252 int lcs_eol_one = lcs_eol; // lcs_eol until it's been used
253 int lcs_prec_todo = lcs_prec; // lcs_prec until it's been used
254
255 // saved "extra" items for when draw_state becomes WL_LINE (again)
256 int saved_n_extra = 0;
257 char_u *saved_p_extra = NULL;
258 int saved_c_extra = 0;
259 int saved_c_final = 0;
260 int saved_char_attr = 0;
261
262 int n_attr = 0; // chars with special attr
263 int saved_attr2 = 0; // char_attr saved for n_attr
264 int n_attr3 = 0; // chars with overruling special attr
265 int saved_attr3 = 0; // char_attr saved for n_attr3
266
267 int n_skip = 0; // nr of chars to skip for 'nowrap'
268
269 int fromcol = -10; // start of inverting
270 int tocol = MAXCOL; // end of inverting
271 int fromcol_prev = -2; // start of inverting after cursor
272 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200273 int lnum_in_visual_area = FALSE;
274 pos_T pos;
275 long v;
276
277 int char_attr = 0; // attributes for next character
278 int attr_pri = FALSE; // char_attr has priority
279 int area_highlighting = FALSE; // Visual or incsearch highlighting
280 // in this line
281 int vi_attr = 0; // attributes for Visual and incsearch
282 // highlighting
283 int wcr_attr = 0; // attributes from 'wincolor'
284 int win_attr = 0; // background for whole window, except
285 // margins and "~" lines.
286 int area_attr = 0; // attributes desired by highlighting
287 int search_attr = 0; // attributes desired by 'hlsearch'
288#ifdef FEAT_SYN_HL
289 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
290 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200291 int prev_syntax_col = -1; // column of prev_syntax_attr
292 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200293 int has_syntax = FALSE; // this buffer has syntax highl.
294 int save_did_emsg;
295 int draw_color_col = FALSE; // highlight colorcolumn
296 int *color_cols = NULL; // pointer to according columns array
297#endif
298 int eol_hl_off = 0; // 1 if highlighted char after EOL
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100299#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200300 int text_prop_count;
301 int text_prop_next = 0; // next text property to use
302 textprop_T *text_props = NULL;
303 int *text_prop_idxs = NULL;
304 int text_props_active = 0;
305 proptype_T *text_prop_type = NULL;
306 int text_prop_attr = 0;
307 int text_prop_combine = FALSE;
308#endif
309#ifdef FEAT_SPELL
310 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaar34390282019-10-16 14:38:26 +0200311 int can_spell;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200312# define SPWORDLEN 150
313 char_u nextline[SPWORDLEN * 2];// text with start of the next line
314 int nextlinecol = 0; // column where nextline[] starts
315 int nextline_idx = 0; // index in nextline[] where next line
316 // starts
317 int spell_attr = 0; // attributes desired by spelling
318 int word_end = 0; // last byte with same spell_attr
319 static linenr_T checked_lnum = 0; // line number for "checked_col"
320 static int checked_col = 0; // column in "checked_lnum" up to which
321 // there are no spell errors
322 static int cap_col = -1; // column to check for Cap word
323 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
324 int cur_checked_col = 0; // checked column for current line
325#endif
326 int extra_check = 0; // has extra highlighting
327 int multi_attr = 0; // attributes desired by multibyte
328 int mb_l = 1; // multi-byte byte length
329 int mb_c = 0; // decoded multi-byte character
330 int mb_utf8 = FALSE; // screen char is UTF-8 char
331 int u8cc[MAX_MCO]; // composing UTF-8 chars
332#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
333 int filler_lines = 0; // nr of filler lines to be drawn
334 int filler_todo = 0; // nr of filler lines still to do + 1
335#endif
336#ifdef FEAT_DIFF
337 hlf_T diff_hlf = (hlf_T)0; // type of diff highlighting
338 int change_start = MAXCOL; // first col of changed area
339 int change_end = -1; // last col of changed area
340#endif
341 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100342 colnr_T leadcol = 0; // start of leading spaces
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200343#ifdef FEAT_LINEBREAK
344 int need_showbreak = FALSE; // overlong line, skipping first x
345 // chars
346#endif
347#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
348 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
349# define LINE_ATTR
350 int line_attr = 0; // attribute for the whole line
351 int line_attr_save;
352#endif
353#ifdef FEAT_SIGNS
354 int sign_present = FALSE;
355 sign_attrs_T sattr;
356#endif
357#ifdef FEAT_ARABIC
358 int prev_c = 0; // previous Arabic character
359 int prev_c1 = 0; // first composing char for prev_c
360#endif
361#if defined(LINE_ATTR)
362 int did_line_attr = 0;
363#endif
364#ifdef FEAT_TERMINAL
365 int get_term_attr = FALSE;
366#endif
367#ifdef FEAT_SYN_HL
368 int cul_attr = 0; // set when 'cursorline' active
369
370 // 'cursorlineopt' has "screenline" and cursor is in this line
371 int cul_screenline = FALSE;
372
373 // margin columns for the screen line, needed for when 'cursorlineopt'
374 // contains "screenline"
375 int left_curline_col = 0;
376 int right_curline_col = 0;
377#endif
378
379 // draw_state: items that are drawn in sequence:
380#define WL_START 0 // nothing done yet
381#ifdef FEAT_CMDWIN
382# define WL_CMDLINE WL_START + 1 // cmdline window column
383#else
384# define WL_CMDLINE WL_START
385#endif
386#ifdef FEAT_FOLDING
387# define WL_FOLD WL_CMDLINE + 1 // 'foldcolumn'
388#else
389# define WL_FOLD WL_CMDLINE
390#endif
391#ifdef FEAT_SIGNS
392# define WL_SIGN WL_FOLD + 1 // column for signs
393#else
394# define WL_SIGN WL_FOLD // column for signs
395#endif
396#define WL_NR WL_SIGN + 1 // line number
397#ifdef FEAT_LINEBREAK
398# define WL_BRI WL_NR + 1 // 'breakindent'
399#else
400# define WL_BRI WL_NR
401#endif
402#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
403# define WL_SBR WL_BRI + 1 // 'showbreak' or 'diff'
404#else
405# define WL_SBR WL_BRI
406#endif
407#define WL_LINE WL_SBR + 1 // text in the line
408 int draw_state = WL_START; // what to draw next
409#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
410 int feedback_col = 0;
411 int feedback_old_attr = -1;
412#endif
413 int screen_line_flags = 0;
414
415#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
416 int match_conc = 0; // cchar for match functions
417#endif
418#ifdef FEAT_CONCEAL
419 int syntax_flags = 0;
420 int syntax_seqnr = 0;
421 int prev_syntax_id = 0;
422 int conceal_attr = HL_ATTR(HLF_CONCEAL);
423 int is_concealing = FALSE;
424 int boguscols = 0; // nonexistent columns added to force
425 // wrapping
426 int vcol_off = 0; // offset for concealed characters
427 int did_wcol = FALSE;
428 int old_boguscols = 0;
429# define VCOL_HLC (vcol - vcol_off)
430# define FIX_FOR_BOGUSCOLS \
431 { \
432 n_extra += vcol_off; \
433 vcol -= vcol_off; \
434 vcol_off = 0; \
435 col -= boguscols; \
436 old_boguscols = boguscols; \
437 boguscols = 0; \
438 }
439#else
440# define VCOL_HLC (vcol)
441#endif
442
443 if (startrow > endrow) // past the end already!
444 return startrow;
445
446 row = startrow;
447 screen_row = row + W_WINROW(wp);
448
449 if (!number_only)
450 {
451 // To speed up the loop below, set extra_check when there is linebreak,
452 // trailing white space and/or syntax processing to be done.
453#ifdef FEAT_LINEBREAK
454 extra_check = wp->w_p_lbr;
455#endif
456#ifdef FEAT_SYN_HL
457 if (syntax_present(wp) && !wp->w_s->b_syn_error
458# ifdef SYN_TIME_LIMIT
459 && !wp->w_s->b_syn_slow
460# endif
461 )
462 {
463 // Prepare for syntax highlighting in this line. When there is an
464 // error, stop syntax highlighting.
465 save_did_emsg = did_emsg;
466 did_emsg = FALSE;
467 syntax_start(wp, lnum);
468 if (did_emsg)
469 wp->w_s->b_syn_error = TRUE;
470 else
471 {
472 did_emsg = save_did_emsg;
473#ifdef SYN_TIME_LIMIT
474 if (!wp->w_s->b_syn_slow)
475#endif
476 {
477 has_syntax = TRUE;
478 extra_check = TRUE;
479 }
480 }
481 }
482
483 // Check for columns to display for 'colorcolumn'.
484 color_cols = wp->w_p_cc_cols;
485 if (color_cols != NULL)
486 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
487#endif
488
489#ifdef FEAT_TERMINAL
490 if (term_show_buffer(wp->w_buffer))
491 {
492 extra_check = TRUE;
493 get_term_attr = TRUE;
Bram Moolenaar219c7d02020-02-01 21:57:29 +0100494 win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200495 }
496#endif
497
498#ifdef FEAT_SPELL
499 if (wp->w_p_spell
500 && *wp->w_s->b_p_spl != NUL
501 && wp->w_s->b_langp.ga_len > 0
502 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
503 {
504 // Prepare for spell checking.
505 has_spell = TRUE;
506 extra_check = TRUE;
507
508 // Get the start of the next line, so that words that wrap to the
509 // next line are found too: "et<line-break>al.".
510 // Trick: skip a few chars for C/shell/Vim comments
511 nextline[SPWORDLEN] = NUL;
512 if (lnum < wp->w_buffer->b_ml.ml_line_count)
513 {
514 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
515 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
516 }
517
518 // When a word wrapped from the previous line the start of the
519 // current line is valid.
520 if (lnum == checked_lnum)
521 cur_checked_col = checked_col;
522 checked_lnum = 0;
523
524 // When there was a sentence end in the previous line may require a
525 // word starting with capital in this line. In line 1 always check
526 // the first word.
527 if (lnum != capcol_lnum)
528 cap_col = -1;
529 if (lnum == 1)
530 cap_col = 0;
531 capcol_lnum = 0;
532 }
533#endif
534
535 // handle Visual active in this window
536 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
537 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100538 pos_T *top, *bot;
539
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200540 if (LTOREQ_POS(curwin->w_cursor, VIsual))
541 {
542 // Visual is after curwin->w_cursor
543 top = &curwin->w_cursor;
544 bot = &VIsual;
545 }
546 else
547 {
548 // Visual is before curwin->w_cursor
549 top = &VIsual;
550 bot = &curwin->w_cursor;
551 }
552 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
553 if (VIsual_mode == Ctrl_V)
554 {
555 // block mode
556 if (lnum_in_visual_area)
557 {
558 fromcol = wp->w_old_cursor_fcol;
559 tocol = wp->w_old_cursor_lcol;
560 }
561 }
562 else
563 {
564 // non-block mode
565 if (lnum > top->lnum && lnum <= bot->lnum)
566 fromcol = 0;
567 else if (lnum == top->lnum)
568 {
569 if (VIsual_mode == 'V') // linewise
570 fromcol = 0;
571 else
572 {
573 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
574 if (gchar_pos(top) == NUL)
575 tocol = fromcol + 1;
576 }
577 }
578 if (VIsual_mode != 'V' && lnum == bot->lnum)
579 {
580 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
581 {
582 fromcol = -10;
583 tocol = MAXCOL;
584 }
585 else if (bot->col == MAXCOL)
586 tocol = MAXCOL;
587 else
588 {
589 pos = *bot;
590 if (*p_sel == 'e')
591 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
592 else
593 {
594 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
595 ++tocol;
596 }
597 }
598 }
599 }
600
601 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200602 if (!highlight_match && lnum == curwin->w_cursor.lnum
603 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200604#ifdef FEAT_GUI
605 && !gui.in_use
606#endif
607 )
608 noinvcur = TRUE;
609
610 // if inverting in this line set area_highlighting
611 if (fromcol >= 0)
612 {
613 area_highlighting = TRUE;
614 vi_attr = HL_ATTR(HLF_V);
615#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
616 if ((clip_star.available && !clip_star.owned
617 && clip_isautosel_star())
618 || (clip_plus.available && !clip_plus.owned
619 && clip_isautosel_plus()))
620 vi_attr = HL_ATTR(HLF_VNC);
621#endif
622 }
623 }
624
625 // handle 'incsearch' and ":s///c" highlighting
626 else if (highlight_match
627 && wp == curwin
628 && lnum >= curwin->w_cursor.lnum
629 && lnum <= curwin->w_cursor.lnum + search_match_lines)
630 {
631 if (lnum == curwin->w_cursor.lnum)
632 getvcol(curwin, &(curwin->w_cursor),
633 (colnr_T *)&fromcol, NULL, NULL);
634 else
635 fromcol = 0;
636 if (lnum == curwin->w_cursor.lnum + search_match_lines)
637 {
638 pos.lnum = lnum;
639 pos.col = search_match_endcol;
640 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
641 }
642 else
643 tocol = MAXCOL;
644 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100645 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200646 tocol = fromcol + 1;
647 area_highlighting = TRUE;
648 vi_attr = HL_ATTR(HLF_I);
649 }
650 }
651
652#ifdef FEAT_DIFF
653 filler_lines = diff_check(wp, lnum);
654 if (filler_lines < 0)
655 {
656 if (filler_lines == -1)
657 {
658 if (diff_find_change(wp, lnum, &change_start, &change_end))
659 diff_hlf = HLF_ADD; // added line
660 else if (change_start == 0)
661 diff_hlf = HLF_TXD; // changed text
662 else
663 diff_hlf = HLF_CHD; // changed line
664 }
665 else
666 diff_hlf = HLF_ADD; // added line
667 filler_lines = 0;
668 area_highlighting = TRUE;
669 }
670 if (lnum == wp->w_topline)
671 filler_lines = wp->w_topfill;
672 filler_todo = filler_lines;
673#endif
674
675#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +0100676 sign_present = buf_get_signattrs(wp, lnum, &sattr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200677#endif
678
679#ifdef LINE_ATTR
680# ifdef FEAT_SIGNS
681 // If this line has a sign with line highlighting set line_attr.
682 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200683 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200684# endif
685# if defined(FEAT_QUICKFIX)
686 // Highlight the current line in the quickfix window.
687 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
688 line_attr = HL_ATTR(HLF_QFL);
689# endif
690 if (line_attr != 0)
691 area_highlighting = TRUE;
692#endif
693
694 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
695 ptr = line;
696
697#ifdef FEAT_SPELL
698 if (has_spell && !number_only)
699 {
700 // For checking first word with a capital skip white space.
701 if (cap_col == 0)
702 cap_col = getwhitecols(line);
703
704 // To be able to spell-check over line boundaries copy the end of the
705 // current line into nextline[]. Above the start of the next line was
706 // copied to nextline[SPWORDLEN].
707 if (nextline[SPWORDLEN] == NUL)
708 {
709 // No next line or it is empty.
710 nextlinecol = MAXCOL;
711 nextline_idx = 0;
712 }
713 else
714 {
715 v = (long)STRLEN(line);
716 if (v < SPWORDLEN)
717 {
718 // Short line, use it completely and append the start of the
719 // next line.
720 nextlinecol = 0;
721 mch_memmove(nextline, line, (size_t)v);
722 STRMOVE(nextline + v, nextline + SPWORDLEN);
723 nextline_idx = v + 1;
724 }
725 else
726 {
727 // Long line, use only the last SPWORDLEN bytes.
728 nextlinecol = v - SPWORDLEN;
729 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
730 nextline_idx = SPWORDLEN + 1;
731 }
732 }
733 }
734#endif
735
736 if (wp->w_p_list)
737 {
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100738 if (lcs_space || lcs_trail || lcs_lead || lcs_nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200739 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100740
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200741 // find start of trailing whitespace
742 if (lcs_trail)
743 {
744 trailcol = (colnr_T)STRLEN(ptr);
745 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
746 --trailcol;
747 trailcol += (colnr_T) (ptr - line);
748 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100749 // find end of leading whitespace
750 if (lcs_lead)
751 {
752 leadcol = 0;
753 while (VIM_ISWHITE(ptr[leadcol]))
754 ++leadcol;
755 if (ptr[leadcol] == NUL)
756 // in a line full of spaces all of them are treated as trailing
757 leadcol = (colnr_T)0;
758 else
759 // keep track of the first column not filled with spaces
760 leadcol += (colnr_T) (ptr - line) + 1;
761 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200762 }
763
764 wcr_attr = get_wcr_attr(wp);
765 if (wcr_attr != 0)
766 {
767 win_attr = wcr_attr;
768 area_highlighting = TRUE;
769 }
Bram Moolenaar34390282019-10-16 14:38:26 +0200770
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100771#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200772 if (WIN_IS_POPUP(wp))
773 screen_line_flags |= SLF_POPUP;
774#endif
775
776 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
777 // first character to be displayed.
778 if (wp->w_p_wrap)
779 v = wp->w_skipcol;
780 else
781 v = wp->w_leftcol;
782 if (v > 0 && !number_only)
783 {
784 char_u *prev_ptr = ptr;
785
786 while (vcol < v && *ptr != NUL)
787 {
788 c = win_lbr_chartabsize(wp, line, ptr, (colnr_T)vcol, NULL);
789 vcol += c;
790 prev_ptr = ptr;
791 MB_PTR_ADV(ptr);
792 }
793
794 // When:
795 // - 'cuc' is set, or
796 // - 'colorcolumn' is set, or
797 // - 'virtualedit' is set, or
798 // - the visual mode is active,
799 // the end of the line may be before the start of the displayed part.
800 if (vcol < v && (
801#ifdef FEAT_SYN_HL
802 wp->w_p_cuc || draw_color_col ||
803#endif
804 virtual_active() ||
805 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
806 vcol = v;
807
808 // Handle a character that's not completely on the screen: Put ptr at
809 // that character but skip the first few screen characters.
810 if (vcol > v)
811 {
812 vcol -= c;
813 ptr = prev_ptr;
814 // If the character fits on the screen, don't need to skip it.
815 // Except for a TAB.
816 if (( (*mb_ptr2cells)(ptr) >= c || *ptr == TAB) && col == 0)
817 n_skip = v - vcol;
818 }
819
820 // Adjust for when the inverted text is before the screen,
821 // and when the start of the inverted text is before the screen.
822 if (tocol <= vcol)
823 fromcol = 0;
824 else if (fromcol >= 0 && fromcol < vcol)
825 fromcol = vcol;
826
827#ifdef FEAT_LINEBREAK
828 // When w_skipcol is non-zero, first line needs 'showbreak'
829 if (wp->w_p_wrap)
830 need_showbreak = TRUE;
831#endif
832#ifdef FEAT_SPELL
833 // When spell checking a word we need to figure out the start of the
834 // word and if it's badly spelled or not.
835 if (has_spell)
836 {
837 int len;
838 colnr_T linecol = (colnr_T)(ptr - line);
839 hlf_T spell_hlf = HLF_COUNT;
840
841 pos = wp->w_cursor;
842 wp->w_cursor.lnum = lnum;
843 wp->w_cursor.col = linecol;
844 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
845
846 // spell_move_to() may call ml_get() and make "line" invalid
847 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
848 ptr = line + linecol;
849
850 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
851 {
852 // no bad word found at line start, don't check until end of a
853 // word
854 spell_hlf = HLF_COUNT;
855 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
856 }
857 else
858 {
859 // bad word found, use attributes until end of word
860 word_end = wp->w_cursor.col + len + 1;
861
862 // Turn index into actual attributes.
863 if (spell_hlf != HLF_COUNT)
864 spell_attr = highlight_attr[spell_hlf];
865 }
866 wp->w_cursor = pos;
867
868# ifdef FEAT_SYN_HL
869 // Need to restart syntax highlighting for this line.
870 if (has_syntax)
871 syntax_start(wp, lnum);
872# endif
873 }
874#endif
875 }
876
877 // Correct highlighting for cursor that can't be disabled.
878 // Avoids having to check this for each character.
879 if (fromcol >= 0)
880 {
881 if (noinvcur)
882 {
883 if ((colnr_T)fromcol == wp->w_virtcol)
884 {
885 // highlighting starts at cursor, let it start just after the
886 // cursor
887 fromcol_prev = fromcol;
888 fromcol = -1;
889 }
890 else if ((colnr_T)fromcol < wp->w_virtcol)
891 // restart highlighting after the cursor
892 fromcol_prev = wp->w_virtcol;
893 }
894 if (fromcol >= tocol)
895 fromcol = -1;
896 }
897
898#ifdef FEAT_SEARCH_EXTRA
899 if (!number_only)
900 {
901 v = (long)(ptr - line);
902 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
903 &line, &screen_search_hl,
904 &search_attr);
905 ptr = line + v; // "line" may have been updated
906 }
907#endif
908
909#ifdef FEAT_SYN_HL
910 // Cursor line highlighting for 'cursorline' in the current window.
911 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
912 {
913 // Do not show the cursor line in the text when Visual mode is active,
914 // because it's not clear what is selected then. Do update
915 // w_last_cursorline.
916 if (!(wp == curwin && VIsual_active)
917 && wp->w_p_culopt_flags != CULOPT_NBR)
918 {
919 cul_screenline = (wp->w_p_wrap
920 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
921
922 // Only set line_attr here when "screenline" is not present in
923 // 'cursorlineopt'. Otherwise it's done later.
924 if (!cul_screenline)
925 {
926 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +0200927# ifdef FEAT_SIGNS
928 // Combine the 'cursorline' and sign highlighting, depending on
929 // the sign priority.
930 if (sign_present && sattr.sat_linehl > 0)
931 {
932 if (sattr.sat_priority >= 100)
933 line_attr = hl_combine_attr(cul_attr, line_attr);
934 else
935 line_attr = hl_combine_attr(line_attr, cul_attr);
936 }
937 else
938# endif
939 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200940 wp->w_last_cursorline = wp->w_cursor.lnum;
941 }
942 else
943 {
944 line_attr_save = line_attr;
945 wp->w_last_cursorline = 0;
946 margin_columns_win(wp, &left_curline_col, &right_curline_col);
947 }
948 area_highlighting = TRUE;
949 }
950 else
951 wp->w_last_cursorline = wp->w_cursor.lnum;
952 }
953#endif
954
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100955#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200956 {
957 char_u *prop_start;
958
959 text_prop_count = get_text_props(wp->w_buffer, lnum,
960 &prop_start, FALSE);
961 if (text_prop_count > 0)
962 {
963 // Make a copy of the properties, so that they are properly
964 // aligned.
965 text_props = ALLOC_MULT(textprop_T, text_prop_count);
966 if (text_props != NULL)
967 mch_memmove(text_props, prop_start,
968 text_prop_count * sizeof(textprop_T));
969
970 // Allocate an array for the indexes.
971 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
972 area_highlighting = TRUE;
973 extra_check = TRUE;
974 }
975 }
976#endif
977
978 off = (unsigned)(current_ScreenLine - ScreenLines);
979 col = 0;
980
981#ifdef FEAT_RIGHTLEFT
982 if (wp->w_p_rl)
983 {
984 // Rightleft window: process the text in the normal direction, but put
985 // it in current_ScreenLine[] from right to left. Start at the
986 // rightmost column of the window.
987 col = wp->w_width - 1;
988 off += col;
989 screen_line_flags |= SLF_RIGHTLEFT;
990 }
991#endif
992
993 // Repeat for the whole displayed line.
994 for (;;)
995 {
996#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +0200997 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200998#endif
999#ifdef FEAT_CONCEAL
1000 int did_decrement_ptr = FALSE;
1001#endif
1002 // Skip this quickly when working on the text.
1003 if (draw_state != WL_LINE)
1004 {
1005#ifdef FEAT_CMDWIN
1006 if (draw_state == WL_CMDLINE - 1 && n_extra == 0)
1007 {
1008 draw_state = WL_CMDLINE;
1009 if (cmdwin_type != 0 && wp == curwin)
1010 {
1011 // Draw the cmdline character.
1012 n_extra = 1;
1013 c_extra = cmdwin_type;
1014 c_final = NUL;
1015 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
1016 }
1017 }
1018#endif
1019
1020#ifdef FEAT_FOLDING
1021 if (draw_state == WL_FOLD - 1 && n_extra == 0)
1022 {
1023 int fdc = compute_foldcolumn(wp, 0);
1024
1025 draw_state = WL_FOLD;
1026 if (fdc > 0)
1027 {
1028 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1029 // already be in use.
1030 vim_free(p_extra_free);
1031 p_extra_free = alloc(12 + 1);
1032
1033 if (p_extra_free != NULL)
1034 {
1035 fill_foldcolumn(p_extra_free, wp, FALSE, lnum);
1036 n_extra = fdc;
1037 p_extra_free[n_extra] = NUL;
1038 p_extra = p_extra_free;
1039 c_extra = NUL;
1040 c_final = NUL;
1041 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
1042 }
1043 }
1044 }
1045#endif
1046
1047#ifdef FEAT_SIGNS
1048 if (draw_state == WL_SIGN - 1 && n_extra == 0)
1049 {
1050 draw_state = WL_SIGN;
1051 // Show the sign column when there are any signs in this
1052 // buffer or when using Netbeans.
1053 if (signcolumn_on(wp))
1054 get_sign_display_info(FALSE, wp, lnum, &sattr, wcr_attr,
1055 row, startrow, filler_lines, filler_todo, &c_extra,
1056 &c_final, extra, &p_extra, &n_extra, &char_attr);
1057 }
1058#endif
1059
1060 if (draw_state == WL_NR - 1 && n_extra == 0)
1061 {
1062 draw_state = WL_NR;
1063 // Display the absolute or relative line number. After the
1064 // first fill with blanks when the 'n' flag isn't in 'cpo'
1065 if ((wp->w_p_nu || wp->w_p_rnu)
1066 && (row == startrow
1067#ifdef FEAT_DIFF
1068 + filler_lines
1069#endif
1070 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
1071 {
1072#ifdef FEAT_SIGNS
1073 // If 'signcolumn' is set to 'number' and a sign is present
1074 // in 'lnum', then display the sign instead of the line
1075 // number.
1076 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1077 && sign_present)
1078 get_sign_display_info(TRUE, wp, lnum, &sattr, wcr_attr,
1079 row, startrow, filler_lines, filler_todo,
1080 &c_extra, &c_final, extra, &p_extra, &n_extra,
1081 &char_attr);
1082 else
1083#endif
1084 {
1085 // Draw the line number (empty space after wrapping).
1086 if (row == startrow
1087#ifdef FEAT_DIFF
1088 + filler_lines
1089#endif
1090 )
1091 {
1092 long num;
1093 char *fmt = "%*ld ";
1094
1095 if (wp->w_p_nu && !wp->w_p_rnu)
1096 // 'number' + 'norelativenumber'
1097 num = (long)lnum;
1098 else
1099 {
1100 // 'relativenumber', don't use negative numbers
1101 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1102 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1103 {
1104 // 'number' + 'relativenumber'
1105 num = lnum;
1106 fmt = "%-*ld ";
1107 }
1108 }
1109
1110 sprintf((char *)extra, fmt,
1111 number_width(wp), num);
1112 if (wp->w_skipcol > 0)
1113 for (p_extra = extra; *p_extra == ' '; ++p_extra)
1114 *p_extra = '-';
1115#ifdef FEAT_RIGHTLEFT
1116 if (wp->w_p_rl) // reverse line numbers
1117 {
1118 char_u *p1, *p2;
1119 int t;
1120
1121 // like rl_mirror(), but keep the space at the end
1122 p2 = skiptowhite(extra) - 1;
1123 for (p1 = extra; p1 < p2; ++p1, --p2)
1124 {
1125 t = *p1;
1126 *p1 = *p2;
1127 *p2 = t;
1128 }
1129 }
1130#endif
1131 p_extra = extra;
1132 c_extra = NUL;
1133 c_final = NUL;
1134 }
1135 else
1136 {
1137 c_extra = ' ';
1138 c_final = NUL;
1139 }
1140 n_extra = number_width(wp) + 1;
1141 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
1142#ifdef FEAT_SYN_HL
1143 // When 'cursorline' is set highlight the line number of
1144 // the current line differently.
1145 // When 'cursorlineopt' has "screenline" only highlight
1146 // the line number itself.
1147 // TODO: Can we use CursorLine instead of CursorLineNr
1148 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001149 if (wp->w_p_cul
1150 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001151 && (wp->w_p_culopt_flags & CULOPT_NBR)
1152 && (row == startrow
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001153 || wp->w_p_culopt_flags & CULOPT_LINE))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001154 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLN));
1155#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001156 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1157 && HL_ATTR(HLF_LNA) != 0)
1158 // Use LineNrAbove
1159 char_attr = hl_combine_attr(wcr_attr,
1160 HL_ATTR(HLF_LNA));
1161 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1162 && HL_ATTR(HLF_LNB) != 0)
1163 // Use LineNrBelow
1164 char_attr = hl_combine_attr(wcr_attr,
1165 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001166 }
1167 }
1168 }
1169
1170#ifdef FEAT_LINEBREAK
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001171 if (wp->w_briopt_sbr && draw_state == WL_BRI - 1
Bram Moolenaaree857022019-11-09 23:26:40 +01001172 && n_extra == 0 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001173 // draw indent after showbreak value
1174 draw_state = WL_BRI;
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001175 else if (wp->w_briopt_sbr && draw_state == WL_SBR && n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001176 // After the showbreak, draw the breakindent
1177 draw_state = WL_BRI - 1;
1178
1179 // draw 'breakindent': indent wrapped text accordingly
1180 if (draw_state == WL_BRI - 1 && n_extra == 0)
1181 {
1182 draw_state = WL_BRI;
1183 // if need_showbreak is set, breakindent also applies
1184 if (wp->w_p_bri && n_extra == 0
1185 && (row != startrow || need_showbreak)
1186# ifdef FEAT_DIFF
1187 && filler_lines == 0
1188# endif
1189 )
1190 {
1191 char_attr = 0;
1192# ifdef FEAT_DIFF
1193 if (diff_hlf != (hlf_T)0)
1194 {
1195 char_attr = HL_ATTR(diff_hlf);
1196# ifdef FEAT_SYN_HL
1197 if (cul_attr != 0)
1198 char_attr = hl_combine_attr(char_attr, cul_attr);
1199# endif
1200 }
1201# endif
1202 p_extra = NULL;
1203 c_extra = ' ';
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001204 c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001205 n_extra = get_breakindent_win(wp,
1206 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001207 if (row == startrow)
1208 {
1209 n_extra -= win_col_off2(wp);
1210 if (n_extra < 0)
1211 n_extra = 0;
1212 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001213 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001214 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001215 // Correct end of highlighted area for 'breakindent',
1216 // required when 'linebreak' is also set.
1217 if (tocol == vcol)
1218 tocol += n_extra;
1219 }
1220 }
1221#endif
1222
1223#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
1224 if (draw_state == WL_SBR - 1 && n_extra == 0)
1225 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001226 char_u *sbr;
1227
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001228 draw_state = WL_SBR;
1229# ifdef FEAT_DIFF
1230 if (filler_todo > 0)
1231 {
1232 // Draw "deleted" diff line(s).
1233 if (char2cells(fill_diff) > 1)
1234 {
1235 c_extra = '-';
1236 c_final = NUL;
1237 }
1238 else
1239 {
1240 c_extra = fill_diff;
1241 c_final = NUL;
1242 }
1243# ifdef FEAT_RIGHTLEFT
1244 if (wp->w_p_rl)
1245 n_extra = col + 1;
1246 else
1247# endif
1248 n_extra = wp->w_width - col;
1249 char_attr = HL_ATTR(HLF_DED);
1250 }
1251# endif
1252# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001253 sbr = get_showbreak_value(wp);
1254 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001255 {
1256 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaaree857022019-11-09 23:26:40 +01001257 p_extra = sbr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001258 c_extra = NUL;
1259 c_final = NUL;
Bram Moolenaaree857022019-11-09 23:26:40 +01001260 n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001261 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1262 need_showbreak = FALSE;
Bram Moolenaaree857022019-11-09 23:26:40 +01001263 vcol_sbr = vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001264 // Correct end of highlighted area for 'showbreak',
1265 // required when 'linebreak' is also set.
1266 if (tocol == vcol)
1267 tocol += n_extra;
1268 // combine 'showbreak' with 'wincolor'
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001269 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001270# ifdef FEAT_SYN_HL
1271 // combine 'showbreak' with 'cursorline'
1272 if (cul_attr != 0)
1273 char_attr = hl_combine_attr(char_attr, cul_attr);
1274# endif
1275 }
1276# endif
1277 }
1278#endif
1279
1280 if (draw_state == WL_LINE - 1 && n_extra == 0)
1281 {
1282 draw_state = WL_LINE;
1283 if (saved_n_extra)
1284 {
1285 // Continue item from end of wrapped line.
1286 n_extra = saved_n_extra;
1287 c_extra = saved_c_extra;
1288 c_final = saved_c_final;
1289 p_extra = saved_p_extra;
1290 char_attr = saved_char_attr;
1291 }
1292 else
1293 char_attr = win_attr;
1294 }
1295 }
1296#ifdef FEAT_SYN_HL
1297 if (cul_screenline)
1298 {
1299 if (draw_state == WL_LINE
1300 && vcol >= left_curline_col
1301 && vcol < right_curline_col)
1302 {
1303 cul_attr = HL_ATTR(HLF_CUL);
1304 line_attr = cul_attr;
1305 }
1306 else
1307 {
1308 cul_attr = 0;
1309 line_attr = line_attr_save;
1310 }
1311 }
1312#endif
1313
1314 // When still displaying '$' of change command, stop at cursor.
1315 // When only displaying the (relative) line number and that's done,
1316 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001317 if (((dollar_vcol >= 0 && wp == curwin
1318 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol)
1319 || (number_only && draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001320#ifdef FEAT_DIFF
1321 && filler_todo <= 0
1322#endif
1323 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001324 {
1325 screen_line(screen_row, wp->w_wincol, col, -(int)wp->w_width,
1326 screen_line_flags);
1327 // Pretend we have finished updating the window. Except when
1328 // 'cursorcolumn' is set.
1329#ifdef FEAT_SYN_HL
1330 if (wp->w_p_cuc)
1331 row = wp->w_cline_row + wp->w_cline_height;
1332 else
1333#endif
1334 row = wp->w_height;
1335 break;
1336 }
1337
Bram Moolenaar34390282019-10-16 14:38:26 +02001338 if (draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001339 {
1340 // handle Visual or match highlighting in this line
1341 if (vcol == fromcol
1342 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0
1343 && (*mb_ptr2cells)(ptr) > 1)
1344 || ((int)vcol_prev == fromcol_prev
1345 && vcol_prev < vcol // not at margin
1346 && vcol < tocol))
1347 area_attr = vi_attr; // start highlighting
1348 else if (area_attr != 0
1349 && (vcol == tocol
1350 || (noinvcur && (colnr_T)vcol == wp->w_virtcol)))
1351 area_attr = 0; // stop highlighting
1352
1353#ifdef FEAT_SEARCH_EXTRA
1354 if (!n_extra)
1355 {
1356 // Check for start/end of 'hlsearch' and other matches.
1357 // After end, check for start/end of next match.
1358 // When another match, have to check for start again.
1359 v = (long)(ptr - line);
1360 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1361 &screen_search_hl, &has_match_conc,
1362 &match_conc, did_line_attr, lcs_eol_one);
1363 ptr = line + v; // "line" may have been changed
Bram Moolenaarfc838d62020-06-25 22:23:48 +02001364
1365 // Do not allow a conceal over EOL otherwise EOL will be missed
1366 // and bad things happen.
1367 if (*ptr == NUL)
1368 has_match_conc = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001369 }
1370#endif
1371
1372#ifdef FEAT_DIFF
1373 if (diff_hlf != (hlf_T)0)
1374 {
1375 if (diff_hlf == HLF_CHD && ptr - line >= change_start
1376 && n_extra == 0)
1377 diff_hlf = HLF_TXD; // changed text
1378 if (diff_hlf == HLF_TXD && ptr - line > change_end
1379 && n_extra == 0)
1380 diff_hlf = HLF_CHD; // changed line
1381 line_attr = HL_ATTR(diff_hlf);
1382 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1383 && wp->w_p_culopt_flags != CULOPT_NBR
1384 && (!cul_screenline || (vcol >= left_curline_col
1385 && vcol <= right_curline_col)))
1386 line_attr = hl_combine_attr(
1387 line_attr, HL_ATTR(HLF_CUL));
1388 }
1389#endif
1390
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001391#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001392 if (text_props != NULL)
1393 {
1394 int pi;
1395 int bcol = (int)(ptr - line);
1396
1397 if (n_extra > 0)
1398 --bcol; // still working on the previous char, e.g. Tab
1399
1400 // Check if any active property ends.
1401 for (pi = 0; pi < text_props_active; ++pi)
1402 {
1403 int tpi = text_prop_idxs[pi];
1404
1405 if (bcol >= text_props[tpi].tp_col - 1
1406 + text_props[tpi].tp_len)
1407 {
1408 if (pi + 1 < text_props_active)
1409 mch_memmove(text_prop_idxs + pi,
1410 text_prop_idxs + pi + 1,
1411 sizeof(int)
1412 * (text_props_active - (pi + 1)));
1413 --text_props_active;
1414 --pi;
1415 }
1416 }
1417
1418 // Add any text property that starts in this column.
1419 while (text_prop_next < text_prop_count
1420 && bcol >= text_props[text_prop_next].tp_col - 1)
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001421 {
1422 if (bcol <= text_props[text_prop_next].tp_col - 1
1423 + text_props[text_prop_next].tp_len)
1424 text_prop_idxs[text_props_active++] = text_prop_next;
1425 ++text_prop_next;
1426 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001427
1428 text_prop_attr = 0;
1429 text_prop_combine = FALSE;
Bram Moolenaar053f7122019-09-23 22:17:15 +02001430 text_prop_type = NULL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001431 if (text_props_active > 0)
1432 {
1433 // Sort the properties on priority and/or starting last.
1434 // Then combine the attributes, highest priority last.
1435 current_text_props = text_props;
1436 current_buf = wp->w_buffer;
1437 qsort((void *)text_prop_idxs, (size_t)text_props_active,
1438 sizeof(int), text_prop_compare);
1439
1440 for (pi = 0; pi < text_props_active; ++pi)
1441 {
1442 int tpi = text_prop_idxs[pi];
1443 proptype_T *pt = text_prop_type_by_id(
1444 wp->w_buffer, text_props[tpi].tp_type);
1445
1446 if (pt != NULL && pt->pt_hl_id > 0)
1447 {
1448 int pt_attr = syn_id2attr(pt->pt_hl_id);
1449
1450 text_prop_type = pt;
1451 text_prop_attr =
1452 hl_combine_attr(text_prop_attr, pt_attr);
1453 text_prop_combine = pt->pt_flags & PT_FLAG_COMBINE;
1454 }
1455 }
1456 }
1457 }
1458#endif
1459
Bram Moolenaara74fda62019-10-19 17:38:03 +02001460#ifdef FEAT_SYN_HL
Bram Moolenaara74fda62019-10-19 17:38:03 +02001461 if (extra_check && n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001462 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001463 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001464# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001465 if (get_term_attr)
Bram Moolenaar219c7d02020-02-01 21:57:29 +01001466 syntax_attr = term_get_attr(wp, lnum, vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001467# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001468 // Get syntax attribute.
1469 if (has_syntax)
1470 {
1471 // Get the syntax attribute for the character. If there
1472 // is an error, disable syntax highlighting.
1473 save_did_emsg = did_emsg;
1474 did_emsg = FALSE;
1475
1476 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001477 if (v == prev_syntax_col)
1478 // at same column again
1479 syntax_attr = prev_syntax_attr;
1480 else
1481 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001482# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001483 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001484# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001485 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001486# ifdef FEAT_SPELL
1487 has_spell ? &can_spell :
1488# endif
1489 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001490 prev_syntax_col = v;
1491 prev_syntax_attr = syntax_attr;
1492 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001493
Bram Moolenaar34390282019-10-16 14:38:26 +02001494 if (did_emsg)
1495 {
1496 wp->w_s->b_syn_error = TRUE;
1497 has_syntax = FALSE;
1498 syntax_attr = 0;
1499 }
1500 else
1501 did_emsg = save_did_emsg;
1502# ifdef SYN_TIME_LIMIT
1503 if (wp->w_s->b_syn_slow)
1504 has_syntax = FALSE;
1505# endif
1506
1507 // Need to get the line again, a multi-line regexp may
1508 // have made it invalid.
1509 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1510 ptr = line + v;
1511# ifdef FEAT_CONCEAL
1512 // no concealing past the end of the line, it interferes
1513 // with line highlighting
1514 if (*ptr == NUL)
1515 syntax_flags = 0;
1516 else
1517 syntax_flags = get_syntax_info(&syntax_seqnr);
1518# endif
1519 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001520 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001521# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001522 // Combine text property highlight into syntax highlight.
1523 if (text_prop_type != NULL)
1524 {
1525 if (text_prop_combine)
1526 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1527 else
1528 syntax_attr = text_prop_attr;
1529 }
1530# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001531#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001532
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001533 // Decide which of the highlight attributes to use.
1534 attr_pri = TRUE;
1535#ifdef LINE_ATTR
1536 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001537 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001538 char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001539# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001540 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001541# endif
1542 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001543 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001544 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001545 char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001546# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001547 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001548# endif
1549 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001550 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
1551 || vcol < fromcol || vcol_prev < fromcol_prev
1552 || vcol >= tocol))
1553 {
1554 // Use line_attr when not in the Visual or 'incsearch' area
1555 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001556# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001557 char_attr = hl_combine_attr(syntax_attr, line_attr);
1558# else
1559 char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001560# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001561 attr_pri = FALSE;
1562 }
1563#else
1564 if (area_attr != 0)
1565 char_attr = area_attr;
1566 else if (search_attr != 0)
1567 char_attr = search_attr;
1568#endif
1569 else
1570 {
1571 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001572#ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001573 char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001574#else
Bram Moolenaardbd43162019-11-09 21:28:14 +01001575 char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001576#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001577 }
1578 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001579
1580 // combine attribute with 'wincolor'
1581 if (win_attr != 0)
1582 {
1583 if (char_attr == 0)
1584 char_attr = win_attr;
1585 else
1586 char_attr = hl_combine_attr(win_attr, char_attr);
1587 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001588
1589 // Get the next character to put on the screen.
1590
1591 // The "p_extra" points to the extra stuff that is inserted to
1592 // represent special characters (non-printable stuff) and other
1593 // things. When all characters are the same, c_extra is used.
1594 // If c_final is set, it will compulsorily be used at the end.
1595 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
1596 // "p_extra[n_extra]".
1597 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
1598 if (n_extra > 0)
1599 {
1600 if (c_extra != NUL || (n_extra == 1 && c_final != NUL))
1601 {
1602 c = (n_extra == 1 && c_final != NUL) ? c_final : c_extra;
1603 mb_c = c; // doesn't handle non-utf-8 multi-byte!
1604 if (enc_utf8 && utf_char2len(c) > 1)
1605 {
1606 mb_utf8 = TRUE;
1607 u8cc[0] = 0;
1608 c = 0xc0;
1609 }
1610 else
1611 mb_utf8 = FALSE;
1612 }
1613 else
1614 {
1615 c = *p_extra;
1616 if (has_mbyte)
1617 {
1618 mb_c = c;
1619 if (enc_utf8)
1620 {
1621 // If the UTF-8 character is more than one byte:
1622 // Decode it into "mb_c".
1623 mb_l = utfc_ptr2len(p_extra);
1624 mb_utf8 = FALSE;
1625 if (mb_l > n_extra)
1626 mb_l = 1;
1627 else if (mb_l > 1)
1628 {
1629 mb_c = utfc_ptr2char(p_extra, u8cc);
1630 mb_utf8 = TRUE;
1631 c = 0xc0;
1632 }
1633 }
1634 else
1635 {
1636 // if this is a DBCS character, put it in "mb_c"
1637 mb_l = MB_BYTE2LEN(c);
1638 if (mb_l >= n_extra)
1639 mb_l = 1;
1640 else if (mb_l > 1)
1641 mb_c = (c << 8) + p_extra[1];
1642 }
1643 if (mb_l == 0) // at the NUL at end-of-line
1644 mb_l = 1;
1645
1646 // If a double-width char doesn't fit display a '>' in the
1647 // last column.
1648 if ((
1649# ifdef FEAT_RIGHTLEFT
1650 wp->w_p_rl ? (col <= 0) :
1651# endif
1652 (col >= wp->w_width - 1))
1653 && (*mb_char2cells)(mb_c) == 2)
1654 {
1655 c = '>';
1656 mb_c = c;
1657 mb_l = 1;
1658 mb_utf8 = FALSE;
1659 multi_attr = HL_ATTR(HLF_AT);
1660#ifdef FEAT_SYN_HL
1661 if (cul_attr)
1662 multi_attr = hl_combine_attr(multi_attr, cul_attr);
1663#endif
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001664 multi_attr = hl_combine_attr(win_attr, multi_attr);
1665
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001666 // put the pointer back to output the double-width
1667 // character at the start of the next line.
1668 ++n_extra;
1669 --p_extra;
1670 }
1671 else
1672 {
1673 n_extra -= mb_l - 1;
1674 p_extra += mb_l - 1;
1675 }
1676 }
1677 ++p_extra;
1678 }
1679 --n_extra;
1680 }
1681 else
1682 {
1683#ifdef FEAT_LINEBREAK
1684 int c0;
1685#endif
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001686 VIM_CLEAR(p_extra_free);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001687
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001688 // Get a character from the line itself.
1689 c = *ptr;
1690#ifdef FEAT_LINEBREAK
1691 c0 = *ptr;
1692#endif
1693 if (has_mbyte)
1694 {
1695 mb_c = c;
1696 if (enc_utf8)
1697 {
1698 // If the UTF-8 character is more than one byte: Decode it
1699 // into "mb_c".
1700 mb_l = utfc_ptr2len(ptr);
1701 mb_utf8 = FALSE;
1702 if (mb_l > 1)
1703 {
1704 mb_c = utfc_ptr2char(ptr, u8cc);
1705 // Overlong encoded ASCII or ASCII with composing char
1706 // is displayed normally, except a NUL.
1707 if (mb_c < 0x80)
1708 {
1709 c = mb_c;
1710#ifdef FEAT_LINEBREAK
1711 c0 = mb_c;
1712#endif
1713 }
1714 mb_utf8 = TRUE;
1715
1716 // At start of the line we can have a composing char.
1717 // Draw it as a space with a composing char.
1718 if (utf_iscomposing(mb_c))
1719 {
1720 int i;
1721
1722 for (i = Screen_mco - 1; i > 0; --i)
1723 u8cc[i] = u8cc[i - 1];
1724 u8cc[0] = mb_c;
1725 mb_c = ' ';
1726 }
1727 }
1728
1729 if ((mb_l == 1 && c >= 0x80)
1730 || (mb_l >= 1 && mb_c == 0)
1731 || (mb_l > 1 && (!vim_isprintc(mb_c))))
1732 {
1733 // Illegal UTF-8 byte: display as <xx>.
1734 // Non-BMP character : display as ? or fullwidth ?.
1735 transchar_hex(extra, mb_c);
1736# ifdef FEAT_RIGHTLEFT
1737 if (wp->w_p_rl) // reverse
1738 rl_mirror(extra);
1739# endif
1740 p_extra = extra;
1741 c = *p_extra;
1742 mb_c = mb_ptr2char_adv(&p_extra);
1743 mb_utf8 = (c >= 0x80);
1744 n_extra = (int)STRLEN(p_extra);
1745 c_extra = NUL;
1746 c_final = NUL;
1747 if (area_attr == 0 && search_attr == 0)
1748 {
1749 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001750 extra_attr = hl_combine_attr(
1751 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001752 saved_attr2 = char_attr; // save current attr
1753 }
1754 }
1755 else if (mb_l == 0) // at the NUL at end-of-line
1756 mb_l = 1;
1757#ifdef FEAT_ARABIC
1758 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
1759 {
1760 // Do Arabic shaping.
1761 int pc, pc1, nc;
1762 int pcc[MAX_MCO];
1763
1764 // The idea of what is the previous and next
1765 // character depends on 'rightleft'.
1766 if (wp->w_p_rl)
1767 {
1768 pc = prev_c;
1769 pc1 = prev_c1;
1770 nc = utf_ptr2char(ptr + mb_l);
1771 prev_c1 = u8cc[0];
1772 }
1773 else
1774 {
1775 pc = utfc_ptr2char(ptr + mb_l, pcc);
1776 nc = prev_c;
1777 pc1 = pcc[0];
1778 }
1779 prev_c = mb_c;
1780
1781 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
1782 }
1783 else
1784 prev_c = mb_c;
1785#endif
1786 }
1787 else // enc_dbcs
1788 {
1789 mb_l = MB_BYTE2LEN(c);
1790 if (mb_l == 0) // at the NUL at end-of-line
1791 mb_l = 1;
1792 else if (mb_l > 1)
1793 {
1794 // We assume a second byte below 32 is illegal.
1795 // Hopefully this is OK for all double-byte encodings!
1796 if (ptr[1] >= 32)
1797 mb_c = (c << 8) + ptr[1];
1798 else
1799 {
1800 if (ptr[1] == NUL)
1801 {
1802 // head byte at end of line
1803 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02001804 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001805 }
1806 else
1807 {
1808 // illegal tail byte
1809 mb_l = 2;
1810 STRCPY(extra, "XX");
1811 }
1812 p_extra = extra;
1813 n_extra = (int)STRLEN(extra) - 1;
1814 c_extra = NUL;
1815 c_final = NUL;
1816 c = *p_extra++;
1817 if (area_attr == 0 && search_attr == 0)
1818 {
1819 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001820 extra_attr = hl_combine_attr(
1821 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001822 saved_attr2 = char_attr; // save current attr
1823 }
1824 mb_c = c;
1825 }
1826 }
1827 }
1828 // If a double-width char doesn't fit display a '>' in the
1829 // last column; the character is displayed at the start of the
1830 // next line.
1831 if ((
1832# ifdef FEAT_RIGHTLEFT
1833 wp->w_p_rl ? (col <= 0) :
1834# endif
1835 (col >= wp->w_width - 1))
1836 && (*mb_char2cells)(mb_c) == 2)
1837 {
1838 c = '>';
1839 mb_c = c;
1840 mb_utf8 = FALSE;
1841 mb_l = 1;
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001842 multi_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001843 // Put pointer back so that the character will be
1844 // displayed at the start of the next line.
1845 --ptr;
1846#ifdef FEAT_CONCEAL
1847 did_decrement_ptr = TRUE;
1848#endif
1849 }
1850 else if (*ptr != NUL)
1851 ptr += mb_l - 1;
1852
1853 // If a double-width char doesn't fit at the left side display
1854 // a '<' in the first column. Don't do this for unprintable
1855 // characters.
1856 if (n_skip > 0 && mb_l > 1 && n_extra == 0)
1857 {
1858 n_extra = 1;
1859 c_extra = MB_FILLER_CHAR;
1860 c_final = NUL;
1861 c = ' ';
1862 if (area_attr == 0 && search_attr == 0)
1863 {
1864 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001865 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001866 saved_attr2 = char_attr; // save current attr
1867 }
1868 mb_c = c;
1869 mb_utf8 = FALSE;
1870 mb_l = 1;
1871 }
1872
1873 }
1874 ++ptr;
1875
1876 if (extra_check)
1877 {
1878#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001879 // Check spelling (unless at the end of the line).
1880 // Only do this when there is no syntax highlighting, the
1881 // @Spell cluster is not used or the current syntax item
1882 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001883 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001884 if (has_spell && v >= word_end && v > cur_checked_col)
1885 {
1886 spell_attr = 0;
1887 if (c != 0 && (
1888# ifdef FEAT_SYN_HL
1889 !has_syntax ||
1890# endif
1891 can_spell))
1892 {
1893 char_u *prev_ptr, *p;
1894 int len;
1895 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01001896
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001897 if (has_mbyte)
1898 {
1899 prev_ptr = ptr - mb_l;
1900 v -= mb_l - 1;
1901 }
1902 else
1903 prev_ptr = ptr - 1;
1904
1905 // Use nextline[] if possible, it has the start of the
1906 // next line concatenated.
1907 if ((prev_ptr - line) - nextlinecol >= 0)
1908 p = nextline + (prev_ptr - line) - nextlinecol;
1909 else
1910 p = prev_ptr;
1911 cap_col -= (int)(prev_ptr - line);
1912 len = spell_check(wp, p, &spell_hlf, &cap_col,
1913 nochange);
1914 word_end = v + len;
1915
1916 // In Insert mode only highlight a word that
1917 // doesn't touch the cursor.
1918 if (spell_hlf != HLF_COUNT
1919 && (State & INSERT) != 0
1920 && wp->w_cursor.lnum == lnum
1921 && wp->w_cursor.col >=
1922 (colnr_T)(prev_ptr - line)
1923 && wp->w_cursor.col < (colnr_T)word_end)
1924 {
1925 spell_hlf = HLF_COUNT;
1926 spell_redraw_lnum = lnum;
1927 }
1928
1929 if (spell_hlf == HLF_COUNT && p != prev_ptr
1930 && (p - nextline) + len > nextline_idx)
1931 {
1932 // Remember that the good word continues at the
1933 // start of the next line.
1934 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001935 checked_col = (int)((p - nextline)
1936 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001937 }
1938
1939 // Turn index into actual attributes.
1940 if (spell_hlf != HLF_COUNT)
1941 spell_attr = highlight_attr[spell_hlf];
1942
1943 if (cap_col > 0)
1944 {
1945 if (p != prev_ptr
1946 && (p - nextline) + cap_col >= nextline_idx)
1947 {
1948 // Remember that the word in the next line
1949 // must start with a capital.
1950 capcol_lnum = lnum + 1;
1951 cap_col = (int)((p - nextline) + cap_col
1952 - nextline_idx);
1953 }
1954 else
1955 // Compute the actual column.
1956 cap_col += (int)(prev_ptr - line);
1957 }
1958 }
1959 }
1960 if (spell_attr != 0)
1961 {
1962 if (!attr_pri)
1963 char_attr = hl_combine_attr(char_attr, spell_attr);
1964 else
1965 char_attr = hl_combine_attr(spell_attr, char_attr);
1966 }
1967#endif
1968#ifdef FEAT_LINEBREAK
1969 // Found last space before word: check for line break.
1970 if (wp->w_p_lbr && c0 == c
1971 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
1972 {
1973 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1) : 0;
1974 char_u *p = ptr - (mb_off + 1);
1975
1976 // TODO: is passing p for start of the line OK?
1977 n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol,
1978 NULL) - 1;
1979 if (c == TAB && n_extra + col > wp->w_width)
1980# ifdef FEAT_VARTABS
1981 n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts,
1982 wp->w_buffer->b_p_vts_array) - 1;
1983# else
1984 n_extra = (int)wp->w_buffer->b_p_ts
1985 - vcol % (int)wp->w_buffer->b_p_ts - 1;
1986# endif
1987
1988 c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
1989 c_final = NUL;
1990 if (VIM_ISWHITE(c))
1991 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01001992# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001993 if (c == TAB)
1994 // See "Tab alignment" below.
1995 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01001996# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001997 if (!wp->w_p_list)
1998 c = ' ';
1999 }
2000 }
2001#endif
2002
2003 // 'list': Change char 160 to lcs_nbsp and space to lcs_space.
2004 // But not when the character is followed by a composing
2005 // character (use mb_l to check that).
2006 if (wp->w_p_list
2007 && ((((c == 160 && mb_l == 1)
2008 || (mb_utf8
2009 && ((mb_c == 160 && mb_l == 2)
2010 || (mb_c == 0x202f && mb_l == 3))))
2011 && lcs_nbsp)
2012 || (c == ' '
2013 && mb_l == 1
2014 && lcs_space
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002015 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002016 && ptr - line <= trailcol)))
2017 {
2018 c = (c == ' ') ? lcs_space : lcs_nbsp;
2019 if (area_attr == 0 && search_attr == 0)
2020 {
2021 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002022 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002023 saved_attr2 = char_attr; // save current attr
2024 }
2025 mb_c = c;
2026 if (enc_utf8 && utf_char2len(c) > 1)
2027 {
2028 mb_utf8 = TRUE;
2029 u8cc[0] = 0;
2030 c = 0xc0;
2031 }
2032 else
2033 mb_utf8 = FALSE;
2034 }
2035
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002036 if ((trailcol != MAXCOL && ptr > line + trailcol && c == ' ')
2037 || (leadcol != 0 && ptr < line + leadcol && c == ' '))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002038 {
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002039 c = (ptr > line + trailcol) ? lcs_trail : lcs_lead;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002040 if (!attr_pri)
2041 {
2042 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002043 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002044 saved_attr2 = char_attr; // save current attr
2045 }
2046 mb_c = c;
2047 if (enc_utf8 && utf_char2len(c) > 1)
2048 {
2049 mb_utf8 = TRUE;
2050 u8cc[0] = 0;
2051 c = 0xc0;
2052 }
2053 else
2054 mb_utf8 = FALSE;
2055 }
2056 }
2057
2058 // Handling of non-printable characters.
2059 if (!vim_isprintc(c))
2060 {
2061 // when getting a character from the file, we may have to
2062 // turn it into something else on the way to putting it
2063 // into "ScreenLines".
2064 if (c == TAB && (!wp->w_p_list || lcs_tab1))
2065 {
2066 int tab_len = 0;
2067 long vcol_adjusted = vcol; // removed showbreak length
2068#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002069 char_u *sbr = get_showbreak_value(wp);
2070
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002071 // only adjust the tab_len, when at the first column
2072 // after the showbreak value was drawn
Bram Moolenaaree857022019-11-09 23:26:40 +01002073 if (*sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap)
2074 vcol_adjusted = vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002075#endif
2076 // tab amount depends on current column
2077#ifdef FEAT_VARTABS
2078 tab_len = tabstop_padding(vcol_adjusted,
2079 wp->w_buffer->b_p_ts,
2080 wp->w_buffer->b_p_vts_array) - 1;
2081#else
2082 tab_len = (int)wp->w_buffer->b_p_ts
2083 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2084#endif
2085
2086#ifdef FEAT_LINEBREAK
2087 if (!wp->w_p_lbr || !wp->w_p_list)
2088#endif
2089 // tab amount depends on current column
2090 n_extra = tab_len;
2091#ifdef FEAT_LINEBREAK
2092 else
2093 {
2094 char_u *p;
2095 int len;
2096 int i;
2097 int saved_nextra = n_extra;
2098
2099#ifdef FEAT_CONCEAL
2100 if (vcol_off > 0)
2101 // there are characters to conceal
2102 tab_len += vcol_off;
2103 // boguscols before FIX_FOR_BOGUSCOLS macro from above
2104 if (wp->w_p_list && lcs_tab1 && old_boguscols > 0
2105 && n_extra > tab_len)
2106 tab_len += n_extra - tab_len;
2107#endif
2108
2109 // if n_extra > 0, it gives the number of chars, to
2110 // use for a tab, else we need to calculate the width
2111 // for a tab
2112 len = (tab_len * mb_char2len(lcs_tab2));
2113 if (n_extra > 0)
2114 len += n_extra - tab_len;
2115 c = lcs_tab1;
2116 p = alloc(len + 1);
2117 vim_memset(p, ' ', len);
2118 p[len] = NUL;
2119 vim_free(p_extra_free);
2120 p_extra_free = p;
2121 for (i = 0; i < tab_len; i++)
2122 {
2123 int lcs = lcs_tab2;
2124
2125 if (*p == NUL)
2126 {
2127 tab_len = i;
2128 break;
2129 }
2130
2131 // if lcs_tab3 is given, need to change the char
2132 // for tab
2133 if (lcs_tab3 && i == tab_len - 1)
2134 lcs = lcs_tab3;
2135 mb_char2bytes(lcs, p);
2136 p += mb_char2len(lcs);
2137 n_extra += mb_char2len(lcs)
2138 - (saved_nextra > 0 ? 1 : 0);
2139 }
2140 p_extra = p_extra_free;
2141#ifdef FEAT_CONCEAL
2142 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2143 // macro below, so need to adjust for that here
2144 if (vcol_off > 0)
2145 n_extra -= vcol_off;
2146#endif
2147 }
2148#endif
2149#ifdef FEAT_CONCEAL
2150 {
2151 int vc_saved = vcol_off;
2152
2153 // Tab alignment should be identical regardless of
2154 // 'conceallevel' value. So tab compensates of all
2155 // previous concealed characters, and thus resets
2156 // vcol_off and boguscols accumulated so far in the
2157 // line. Note that the tab can be longer than
2158 // 'tabstop' when there are concealed characters.
2159 FIX_FOR_BOGUSCOLS;
2160
2161 // Make sure, the highlighting for the tab char will be
2162 // correctly set further below (effectively reverts the
2163 // FIX_FOR_BOGSUCOLS macro
2164 if (n_extra == tab_len + vc_saved && wp->w_p_list
2165 && lcs_tab1)
2166 tab_len += vc_saved;
2167 }
2168#endif
2169 mb_utf8 = FALSE; // don't draw as UTF-8
2170 if (wp->w_p_list)
2171 {
2172 c = (n_extra == 0 && lcs_tab3) ? lcs_tab3 : lcs_tab1;
2173#ifdef FEAT_LINEBREAK
2174 if (wp->w_p_lbr)
2175 c_extra = NUL; // using p_extra from above
2176 else
2177#endif
2178 c_extra = lcs_tab2;
2179 c_final = lcs_tab3;
2180 n_attr = tab_len + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002181 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002182 saved_attr2 = char_attr; // save current attr
2183 mb_c = c;
2184 if (enc_utf8 && utf_char2len(c) > 1)
2185 {
2186 mb_utf8 = TRUE;
2187 u8cc[0] = 0;
2188 c = 0xc0;
2189 }
2190 }
2191 else
2192 {
2193 c_final = NUL;
2194 c_extra = ' ';
2195 c = ' ';
2196 }
2197 }
2198 else if (c == NUL
2199 && (wp->w_p_list
2200 || ((fromcol >= 0 || fromcol_prev >= 0)
2201 && tocol > vcol
2202 && VIsual_mode != Ctrl_V
2203 && (
2204# ifdef FEAT_RIGHTLEFT
2205 wp->w_p_rl ? (col >= 0) :
2206# endif
2207 (col < wp->w_width))
2208 && !(noinvcur
2209 && lnum == wp->w_cursor.lnum
2210 && (colnr_T)vcol == wp->w_virtcol)))
2211 && lcs_eol_one > 0)
2212 {
2213 // Display a '$' after the line or highlight an extra
2214 // character if the line break is included.
2215#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2216 // For a diff line the highlighting continues after the
2217 // "$".
2218 if (
2219# ifdef FEAT_DIFF
2220 diff_hlf == (hlf_T)0
2221# ifdef LINE_ATTR
2222 &&
2223# endif
2224# endif
2225# ifdef LINE_ATTR
2226 line_attr == 0
2227# endif
2228 )
2229#endif
2230 {
2231 // In virtualedit, visual selections may extend
2232 // beyond end of line.
2233 if (area_highlighting && virtual_active()
2234 && tocol != MAXCOL && vcol < tocol)
2235 n_extra = 0;
2236 else
2237 {
2238 p_extra = at_end_str;
2239 n_extra = 1;
2240 c_extra = NUL;
2241 c_final = NUL;
2242 }
2243 }
2244 if (wp->w_p_list && lcs_eol > 0)
2245 c = lcs_eol;
2246 else
2247 c = ' ';
2248 lcs_eol_one = -1;
2249 --ptr; // put it back at the NUL
2250 if (!attr_pri)
2251 {
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002252 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002253 n_attr = 1;
2254 }
2255 mb_c = c;
2256 if (enc_utf8 && utf_char2len(c) > 1)
2257 {
2258 mb_utf8 = TRUE;
2259 u8cc[0] = 0;
2260 c = 0xc0;
2261 }
2262 else
2263 mb_utf8 = FALSE; // don't draw as UTF-8
2264 }
2265 else if (c != NUL)
2266 {
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002267 p_extra = transchar_buf(wp->w_buffer, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002268 if (n_extra == 0)
2269 n_extra = byte2cells(c) - 1;
2270#ifdef FEAT_RIGHTLEFT
2271 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
2272 rl_mirror(p_extra); // reverse "<12>"
2273#endif
2274 c_extra = NUL;
2275 c_final = NUL;
2276#ifdef FEAT_LINEBREAK
2277 if (wp->w_p_lbr)
2278 {
2279 char_u *p;
2280
2281 c = *p_extra;
2282 p = alloc(n_extra + 1);
2283 vim_memset(p, ' ', n_extra);
2284 STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1);
2285 p[n_extra] = NUL;
2286 vim_free(p_extra_free);
2287 p_extra_free = p_extra = p;
2288 }
2289 else
2290#endif
2291 {
2292 n_extra = byte2cells(c) - 1;
2293 c = *p_extra++;
2294 }
2295 if (!attr_pri)
2296 {
2297 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002298 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002299 saved_attr2 = char_attr; // save current attr
2300 }
2301 mb_utf8 = FALSE; // don't draw as UTF-8
2302 }
2303 else if (VIsual_active
2304 && (VIsual_mode == Ctrl_V
2305 || VIsual_mode == 'v')
2306 && virtual_active()
2307 && tocol != MAXCOL
2308 && vcol < tocol
2309 && (
2310#ifdef FEAT_RIGHTLEFT
2311 wp->w_p_rl ? (col >= 0) :
2312#endif
2313 (col < wp->w_width)))
2314 {
2315 c = ' ';
2316 --ptr; // put it back at the NUL
2317 }
2318#if defined(LINE_ATTR)
2319 else if ((
2320# ifdef FEAT_DIFF
2321 diff_hlf != (hlf_T)0 ||
2322# endif
2323# ifdef FEAT_TERMINAL
2324 win_attr != 0 ||
2325# endif
2326 line_attr != 0
2327 ) && (
2328# ifdef FEAT_RIGHTLEFT
2329 wp->w_p_rl ? (col >= 0) :
2330# endif
2331 (col
2332# ifdef FEAT_CONCEAL
2333 - boguscols
2334# endif
2335 < wp->w_width)))
2336 {
2337 // Highlight until the right side of the window
2338 c = ' ';
2339 --ptr; // put it back at the NUL
2340
2341 // Remember we do the char for line highlighting.
2342 ++did_line_attr;
2343
2344 // don't do search HL for the rest of the line
2345 if (line_attr != 0 && char_attr == search_attr
2346 && (did_line_attr > 1
2347 || (wp->w_p_list && lcs_eol > 0)))
2348 char_attr = line_attr;
2349# ifdef FEAT_DIFF
2350 if (diff_hlf == HLF_TXD)
2351 {
2352 diff_hlf = HLF_CHD;
2353 if (vi_attr == 0 || char_attr != vi_attr)
2354 {
2355 char_attr = HL_ATTR(diff_hlf);
2356 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2357 && wp->w_p_culopt_flags != CULOPT_NBR
2358 && (!cul_screenline
2359 || (vcol >= left_curline_col
2360 && vcol <= right_curline_col)))
2361 char_attr = hl_combine_attr(
2362 char_attr, HL_ATTR(HLF_CUL));
2363 }
2364 }
2365# endif
2366# ifdef FEAT_TERMINAL
2367 if (win_attr != 0)
2368 {
2369 char_attr = win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002370 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2371 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002372 {
2373 if (!cul_screenline || (vcol >= left_curline_col
2374 && vcol <= right_curline_col))
2375 char_attr = hl_combine_attr(
2376 char_attr, HL_ATTR(HLF_CUL));
2377 }
2378 else if (line_attr)
2379 char_attr = hl_combine_attr(char_attr, line_attr);
2380 }
2381# endif
2382 }
2383#endif
2384 }
2385
2386#ifdef FEAT_CONCEAL
2387 if ( wp->w_p_cole > 0
2388 && (wp != curwin || lnum != wp->w_cursor.lnum ||
2389 conceal_cursor_line(wp))
2390 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2391 && !(lnum_in_visual_area
2392 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2393 {
2394 char_attr = conceal_attr;
2395 if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002396 && (syn_get_sub_char() != NUL
2397 || (has_match_conc && match_conc)
2398 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002399 && wp->w_p_cole != 3)
2400 {
2401 // First time at this concealed item: display one
2402 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002403 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002404 c = match_conc;
2405 else if (syn_get_sub_char() != NUL)
2406 c = syn_get_sub_char();
2407 else if (lcs_conceal != NUL)
2408 c = lcs_conceal;
2409 else
2410 c = ' ';
2411
2412 prev_syntax_id = syntax_seqnr;
2413
2414 if (n_extra > 0)
2415 vcol_off += n_extra;
2416 vcol += n_extra;
2417 if (wp->w_p_wrap && n_extra > 0)
2418 {
2419# ifdef FEAT_RIGHTLEFT
2420 if (wp->w_p_rl)
2421 {
2422 col -= n_extra;
2423 boguscols -= n_extra;
2424 }
2425 else
2426# endif
2427 {
2428 boguscols += n_extra;
2429 col += n_extra;
2430 }
2431 }
2432 n_extra = 0;
2433 n_attr = 0;
2434 }
2435 else if (n_skip == 0)
2436 {
2437 is_concealing = TRUE;
2438 n_skip = 1;
2439 }
2440 mb_c = c;
2441 if (enc_utf8 && utf_char2len(c) > 1)
2442 {
2443 mb_utf8 = TRUE;
2444 u8cc[0] = 0;
2445 c = 0xc0;
2446 }
2447 else
2448 mb_utf8 = FALSE; // don't draw as UTF-8
2449 }
2450 else
2451 {
2452 prev_syntax_id = 0;
2453 is_concealing = FALSE;
2454 }
2455
2456 if (n_skip > 0 && did_decrement_ptr)
2457 // not showing the '>', put pointer back to avoid getting stuck
2458 ++ptr;
2459
2460#endif // FEAT_CONCEAL
2461 }
2462
2463#ifdef FEAT_CONCEAL
2464 // In the cursor line and we may be concealing characters: correct
2465 // the cursor column when we reach its position.
2466 if (!did_wcol && draw_state == WL_LINE
2467 && wp == curwin && lnum == wp->w_cursor.lnum
2468 && conceal_cursor_line(wp)
2469 && (int)wp->w_virtcol <= vcol + n_skip)
2470 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002471# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002472 if (wp->w_p_rl)
2473 wp->w_wcol = wp->w_width - col + boguscols - 1;
2474 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002475# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002476 wp->w_wcol = col - boguscols;
2477 wp->w_wrow = row;
2478 did_wcol = TRUE;
2479 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002480# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01002481 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002482# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002483 }
2484#endif
2485
2486 // Don't override visual selection highlighting.
2487 if (n_attr > 0
2488 && draw_state == WL_LINE
2489 && !attr_pri)
2490 {
2491#ifdef LINE_ATTR
2492 if (line_attr)
2493 char_attr = hl_combine_attr(extra_attr, line_attr);
2494 else
2495#endif
2496 char_attr = extra_attr;
2497 }
2498
2499#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2500 // XIM don't send preedit_start and preedit_end, but they send
2501 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
2502 // im_is_preediting() here.
2503 if (p_imst == IM_ON_THE_SPOT
2504 && xic != NULL
2505 && lnum == wp->w_cursor.lnum
2506 && (State & INSERT)
2507 && !p_imdisable
2508 && im_is_preediting()
2509 && draw_state == WL_LINE)
2510 {
2511 colnr_T tcol;
2512
2513 if (preedit_end_col == MAXCOL)
2514 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
2515 else
2516 tcol = preedit_end_col;
2517 if ((long)preedit_start_col <= vcol && vcol < (long)tcol)
2518 {
2519 if (feedback_old_attr < 0)
2520 {
2521 feedback_col = 0;
2522 feedback_old_attr = char_attr;
2523 }
2524 char_attr = im_get_feedback_attr(feedback_col);
2525 if (char_attr < 0)
2526 char_attr = feedback_old_attr;
2527 feedback_col++;
2528 }
2529 else if (feedback_old_attr >= 0)
2530 {
2531 char_attr = feedback_old_attr;
2532 feedback_old_attr = -1;
2533 feedback_col = 0;
2534 }
2535 }
2536#endif
2537 // Handle the case where we are in column 0 but not on the first
2538 // character of the line and the user wants us to show us a
2539 // special character (via 'listchars' option "precedes:<char>".
2540 if (lcs_prec_todo != NUL
2541 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02002542 && (wp->w_p_wrap ?
2543 (wp->w_skipcol > 0 && row == 0) :
2544 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002545#ifdef FEAT_DIFF
2546 && filler_todo <= 0
2547#endif
2548 && draw_state > WL_NR
2549 && c != NUL)
2550 {
2551 c = lcs_prec;
2552 lcs_prec_todo = NUL;
2553 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2554 {
2555 // Double-width character being overwritten by the "precedes"
2556 // character, need to fill up half the character.
2557 c_extra = MB_FILLER_CHAR;
2558 c_final = NUL;
2559 n_extra = 1;
2560 n_attr = 2;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002561 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002562 }
2563 mb_c = c;
2564 if (enc_utf8 && utf_char2len(c) > 1)
2565 {
2566 mb_utf8 = TRUE;
2567 u8cc[0] = 0;
2568 c = 0xc0;
2569 }
2570 else
2571 mb_utf8 = FALSE; // don't draw as UTF-8
2572 if (!attr_pri)
2573 {
2574 saved_attr3 = char_attr; // save current attr
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002575 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002576 n_attr3 = 1;
2577 }
2578 }
2579
2580 // At end of the text line or just after the last character.
2581 if ((c == NUL
2582#if defined(LINE_ATTR)
2583 || did_line_attr == 1
2584#endif
2585 ) && eol_hl_off == 0)
2586 {
2587#ifdef FEAT_SEARCH_EXTRA
2588 // flag to indicate whether prevcol equals startcol of search_hl or
2589 // one of the matches
2590 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
2591 (long)(ptr - line) - (c == NUL));
2592#endif
2593 // Invert at least one char, used for Visual and empty line or
2594 // highlight match at end of line. If it's beyond the last
2595 // char on the screen, just overwrite that one (tricky!) Not
2596 // needed when a '$' was displayed for 'list'.
2597 if (lcs_eol == lcs_eol_one
2598 && ((area_attr != 0 && vcol == fromcol
2599 && (VIsual_mode != Ctrl_V
2600 || lnum == VIsual.lnum
2601 || lnum == curwin->w_cursor.lnum)
2602 && c == NUL)
2603#ifdef FEAT_SEARCH_EXTRA
2604 // highlight 'hlsearch' match at end of line
2605 || (prevcol_hl_flag
2606# ifdef FEAT_SYN_HL
2607 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
2608 && !(wp == curwin && VIsual_active))
2609# endif
2610# ifdef FEAT_DIFF
2611 && diff_hlf == (hlf_T)0
2612# endif
2613# if defined(LINE_ATTR)
2614 && did_line_attr <= 1
2615# endif
2616 )
2617#endif
2618 ))
2619 {
2620 int n = 0;
2621
2622#ifdef FEAT_RIGHTLEFT
2623 if (wp->w_p_rl)
2624 {
2625 if (col < 0)
2626 n = 1;
2627 }
2628 else
2629#endif
2630 {
2631 if (col >= wp->w_width)
2632 n = -1;
2633 }
2634 if (n != 0)
2635 {
2636 // At the window boundary, highlight the last character
2637 // instead (better than nothing).
2638 off += n;
2639 col += n;
2640 }
2641 else
2642 {
2643 // Add a blank character to highlight.
2644 ScreenLines[off] = ' ';
2645 if (enc_utf8)
2646 ScreenLinesUC[off] = 0;
2647 }
2648#ifdef FEAT_SEARCH_EXTRA
2649 if (area_attr == 0)
2650 {
2651 // Use attributes from match with highest priority among
2652 // 'search_hl' and the match list.
2653 get_search_match_hl(wp, &screen_search_hl,
2654 (long)(ptr - line), &char_attr);
2655 }
2656#endif
2657 ScreenAttrs[off] = char_attr;
2658#ifdef FEAT_RIGHTLEFT
2659 if (wp->w_p_rl)
2660 {
2661 --col;
2662 --off;
2663 }
2664 else
2665#endif
2666 {
2667 ++col;
2668 ++off;
2669 }
2670 ++vcol;
2671 eol_hl_off = 1;
2672 }
2673 }
2674
2675 // At end of the text line.
2676 if (c == NUL)
2677 {
2678#ifdef FEAT_SYN_HL
2679 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
2680 if (wp->w_p_wrap)
2681 v = wp->w_skipcol;
2682 else
2683 v = wp->w_leftcol;
2684
2685 // check if line ends before left margin
2686 if (vcol < v + col - win_col_off(wp))
2687 vcol = v + col - win_col_off(wp);
2688#ifdef FEAT_CONCEAL
2689 // Get rid of the boguscols now, we want to draw until the right
2690 // edge for 'cursorcolumn'.
2691 col -= boguscols;
2692 boguscols = 0;
2693#endif
2694
2695 if (draw_color_col)
2696 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2697
2698 if (((wp->w_p_cuc
2699 && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off
2700 && (int)wp->w_virtcol <
2701 wp->w_width * (row - startrow + 1) + v
2702 && lnum != wp->w_cursor.lnum)
2703 || draw_color_col
2704 || win_attr != 0)
2705# ifdef FEAT_RIGHTLEFT
2706 && !wp->w_p_rl
2707# endif
2708 )
2709 {
2710 int rightmost_vcol = 0;
2711 int i;
2712
2713 if (wp->w_p_cuc)
2714 rightmost_vcol = wp->w_virtcol;
2715 if (draw_color_col)
2716 // determine rightmost colorcolumn to possibly draw
2717 for (i = 0; color_cols[i] >= 0; ++i)
2718 if (rightmost_vcol < color_cols[i])
2719 rightmost_vcol = color_cols[i];
2720
2721 while (col < wp->w_width)
2722 {
2723 ScreenLines[off] = ' ';
2724 if (enc_utf8)
2725 ScreenLinesUC[off] = 0;
2726 ++col;
2727 if (draw_color_col)
2728 draw_color_col = advance_color_col(VCOL_HLC,
2729 &color_cols);
2730
2731 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
2732 ScreenAttrs[off++] = HL_ATTR(HLF_CUC);
2733 else if (draw_color_col && VCOL_HLC == *color_cols)
2734 ScreenAttrs[off++] = HL_ATTR(HLF_MC);
2735 else
2736 ScreenAttrs[off++] = win_attr;
2737
2738 if (VCOL_HLC >= rightmost_vcol && win_attr == 0)
2739 break;
2740
2741 ++vcol;
2742 }
2743 }
2744#endif
2745
2746 screen_line(screen_row, wp->w_wincol, col,
2747 (int)wp->w_width, screen_line_flags);
2748 row++;
2749
2750 // Update w_cline_height and w_cline_folded if the cursor line was
2751 // updated (saves a call to plines() later).
2752 if (wp == curwin && lnum == curwin->w_cursor.lnum)
2753 {
2754 curwin->w_cline_row = startrow;
2755 curwin->w_cline_height = row - startrow;
2756#ifdef FEAT_FOLDING
2757 curwin->w_cline_folded = FALSE;
2758#endif
2759 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
2760 }
2761
2762 break;
2763 }
2764
2765 // Show "extends" character from 'listchars' if beyond the line end and
2766 // 'list' is set.
2767 if (lcs_ext != NUL
2768 && wp->w_p_list
2769 && !wp->w_p_wrap
2770#ifdef FEAT_DIFF
2771 && filler_todo <= 0
2772#endif
2773 && (
2774#ifdef FEAT_RIGHTLEFT
2775 wp->w_p_rl ? col == 0 :
2776#endif
2777 col == wp->w_width - 1)
2778 && (*ptr != NUL
2779 || (wp->w_p_list && lcs_eol_one > 0)
2780 || (n_extra && (c_extra != NUL || *p_extra != NUL))))
2781 {
2782 c = lcs_ext;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002783 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002784 mb_c = c;
2785 if (enc_utf8 && utf_char2len(c) > 1)
2786 {
2787 mb_utf8 = TRUE;
2788 u8cc[0] = 0;
2789 c = 0xc0;
2790 }
2791 else
2792 mb_utf8 = FALSE;
2793 }
2794
2795#ifdef FEAT_SYN_HL
2796 // advance to the next 'colorcolumn'
2797 if (draw_color_col)
2798 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2799
2800 // Highlight the cursor column if 'cursorcolumn' is set. But don't
2801 // highlight the cursor position itself.
2802 // Also highlight the 'colorcolumn' if it is different than
2803 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02002804 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
2805 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002806 vcol_save_attr = -1;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002807 if (((draw_state == WL_LINE ||
Bram Moolenaarad5e5632020-09-15 20:52:26 +02002808 draw_state == WL_BRI ||
2809 draw_state == WL_SBR) && !lnum_in_visual_area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002810 && search_attr == 0 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002811# ifdef FEAT_DIFF
2812 && filler_todo <= 0
2813# endif
2814 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002815 {
2816 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
2817 && lnum != wp->w_cursor.lnum)
2818 {
2819 vcol_save_attr = char_attr;
2820 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUC));
2821 }
2822 else if (draw_color_col && VCOL_HLC == *color_cols)
2823 {
2824 vcol_save_attr = char_attr;
2825 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_MC));
2826 }
2827 }
2828#endif
2829
2830 // Store character to be displayed.
2831 // Skip characters that are left of the screen for 'nowrap'.
2832 vcol_prev = vcol;
2833 if (draw_state < WL_LINE || n_skip <= 0)
2834 {
2835 // Store the character.
2836#if defined(FEAT_RIGHTLEFT)
2837 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
2838 {
2839 // A double-wide character is: put first halve in left cell.
2840 --off;
2841 --col;
2842 }
2843#endif
2844 ScreenLines[off] = c;
2845 if (enc_dbcs == DBCS_JPNU)
2846 {
2847 if ((mb_c & 0xff00) == 0x8e00)
2848 ScreenLines[off] = 0x8e;
2849 ScreenLines2[off] = mb_c & 0xff;
2850 }
2851 else if (enc_utf8)
2852 {
2853 if (mb_utf8)
2854 {
2855 int i;
2856
2857 ScreenLinesUC[off] = mb_c;
2858 if ((c & 0xff) == 0)
2859 ScreenLines[off] = 0x80; // avoid storing zero
2860 for (i = 0; i < Screen_mco; ++i)
2861 {
2862 ScreenLinesC[i][off] = u8cc[i];
2863 if (u8cc[i] == 0)
2864 break;
2865 }
2866 }
2867 else
2868 ScreenLinesUC[off] = 0;
2869 }
2870 if (multi_attr)
2871 {
2872 ScreenAttrs[off] = multi_attr;
2873 multi_attr = 0;
2874 }
2875 else
2876 ScreenAttrs[off] = char_attr;
2877
2878 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2879 {
2880 // Need to fill two screen columns.
2881 ++off;
2882 ++col;
2883 if (enc_utf8)
2884 // UTF-8: Put a 0 in the second screen char.
2885 ScreenLines[off] = 0;
2886 else
2887 // DBCS: Put second byte in the second screen char.
2888 ScreenLines[off] = mb_c & 0xff;
2889 if (draw_state > WL_NR
2890#ifdef FEAT_DIFF
2891 && filler_todo <= 0
2892#endif
2893 )
2894 ++vcol;
2895 // When "tocol" is halfway a character, set it to the end of
2896 // the character, otherwise highlighting won't stop.
2897 if (tocol == vcol)
2898 ++tocol;
2899#ifdef FEAT_RIGHTLEFT
2900 if (wp->w_p_rl)
2901 {
2902 // now it's time to backup one cell
2903 --off;
2904 --col;
2905 }
2906#endif
2907 }
2908#ifdef FEAT_RIGHTLEFT
2909 if (wp->w_p_rl)
2910 {
2911 --off;
2912 --col;
2913 }
2914 else
2915#endif
2916 {
2917 ++off;
2918 ++col;
2919 }
2920 }
2921#ifdef FEAT_CONCEAL
2922 else if (wp->w_p_cole > 0 && is_concealing)
2923 {
2924 --n_skip;
2925 ++vcol_off;
2926 if (n_extra > 0)
2927 vcol_off += n_extra;
2928 if (wp->w_p_wrap)
2929 {
2930 // Special voodoo required if 'wrap' is on.
2931 //
2932 // Advance the column indicator to force the line
2933 // drawing to wrap early. This will make the line
2934 // take up the same screen space when parts are concealed,
2935 // so that cursor line computations aren't messed up.
2936 //
2937 // To avoid the fictitious advance of 'col' causing
2938 // trailing junk to be written out of the screen line
2939 // we are building, 'boguscols' keeps track of the number
2940 // of bad columns we have advanced.
2941 if (n_extra > 0)
2942 {
2943 vcol += n_extra;
2944# ifdef FEAT_RIGHTLEFT
2945 if (wp->w_p_rl)
2946 {
2947 col -= n_extra;
2948 boguscols -= n_extra;
2949 }
2950 else
2951# endif
2952 {
2953 col += n_extra;
2954 boguscols += n_extra;
2955 }
2956 n_extra = 0;
2957 n_attr = 0;
2958 }
2959
2960
2961 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2962 {
2963 // Need to fill two screen columns.
2964# ifdef FEAT_RIGHTLEFT
2965 if (wp->w_p_rl)
2966 {
2967 --boguscols;
2968 --col;
2969 }
2970 else
2971# endif
2972 {
2973 ++boguscols;
2974 ++col;
2975 }
2976 }
2977
2978# ifdef FEAT_RIGHTLEFT
2979 if (wp->w_p_rl)
2980 {
2981 --boguscols;
2982 --col;
2983 }
2984 else
2985# endif
2986 {
2987 ++boguscols;
2988 ++col;
2989 }
2990 }
2991 else
2992 {
2993 if (n_extra > 0)
2994 {
2995 vcol += n_extra;
2996 n_extra = 0;
2997 n_attr = 0;
2998 }
2999 }
3000
3001 }
3002#endif // FEAT_CONCEAL
3003 else
3004 --n_skip;
3005
3006 // Only advance the "vcol" when after the 'number' or 'relativenumber'
3007 // column.
3008 if (draw_state > WL_NR
3009#ifdef FEAT_DIFF
3010 && filler_todo <= 0
3011#endif
3012 )
3013 ++vcol;
3014
3015#ifdef FEAT_SYN_HL
3016 if (vcol_save_attr >= 0)
3017 char_attr = vcol_save_attr;
3018#endif
3019
3020 // restore attributes after "predeces" in 'listchars'
3021 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3022 char_attr = saved_attr3;
3023
3024 // restore attributes after last 'listchars' or 'number' char
3025 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0)
3026 char_attr = saved_attr2;
3027
3028 // At end of screen line and there is more to come: Display the line
3029 // so far. If there is no more to display it is caught above.
3030 if ((
3031#ifdef FEAT_RIGHTLEFT
3032 wp->w_p_rl ? (col < 0) :
3033#endif
3034 (col >= wp->w_width))
3035 && (*ptr != NUL
3036#ifdef FEAT_DIFF
3037 || filler_todo > 0
3038#endif
3039 || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str)
3040 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL)))
3041 )
3042 {
3043#ifdef FEAT_CONCEAL
3044 screen_line(screen_row, wp->w_wincol, col - boguscols,
3045 (int)wp->w_width, screen_line_flags);
3046 boguscols = 0;
3047#else
3048 screen_line(screen_row, wp->w_wincol, col,
3049 (int)wp->w_width, screen_line_flags);
3050#endif
3051 ++row;
3052 ++screen_row;
3053
3054 // When not wrapping and finished diff lines, or when displayed
3055 // '$' and highlighting until last column, break here.
3056 if ((!wp->w_p_wrap
3057#ifdef FEAT_DIFF
3058 && filler_todo <= 0
3059#endif
3060 ) || lcs_eol_one == -1)
3061 break;
3062
3063 // When the window is too narrow draw all "@" lines.
3064 if (draw_state != WL_LINE
3065#ifdef FEAT_DIFF
3066 && filler_todo <= 0
3067#endif
3068 )
3069 {
3070 win_draw_end(wp, '@', ' ', TRUE, row, wp->w_height, HLF_AT);
3071 draw_vsep_win(wp, row);
3072 row = endrow;
3073 }
3074
3075 // When line got too long for screen break here.
3076 if (row == endrow)
3077 {
3078 ++row;
3079 break;
3080 }
3081
3082 if (screen_cur_row == screen_row - 1
3083#ifdef FEAT_DIFF
3084 && filler_todo <= 0
3085#endif
3086 && wp->w_width == Columns)
3087 {
3088 // Remember that the line wraps, used for modeless copy.
3089 LineWraps[screen_row - 1] = TRUE;
3090
3091 // Special trick to make copy/paste of wrapped lines work with
3092 // xterm/screen: write an extra character beyond the end of
3093 // the line. This will work with all terminal types
3094 // (regardless of the xn,am settings).
3095 // Only do this on a fast tty.
3096 // Only do this if the cursor is on the current line
3097 // (something has been written in it).
3098 // Don't do this for the GUI.
3099 // Don't do this for double-width characters.
3100 // Don't do this for a window not at the right screen border.
3101 if (p_tf
3102#ifdef FEAT_GUI
3103 && !gui.in_use
3104#endif
3105 && !(has_mbyte
3106 && ((*mb_off2cells)(LineOffset[screen_row],
3107 LineOffset[screen_row] + screen_Columns)
3108 == 2
3109 || (*mb_off2cells)(LineOffset[screen_row - 1]
3110 + (int)Columns - 2,
3111 LineOffset[screen_row] + screen_Columns)
3112 == 2)))
3113 {
3114 // First make sure we are at the end of the screen line,
3115 // then output the same character again to let the
3116 // terminal know about the wrap. If the terminal doesn't
3117 // auto-wrap, we overwrite the character.
3118 if (screen_cur_col != wp->w_width)
3119 screen_char(LineOffset[screen_row - 1]
3120 + (unsigned)Columns - 1,
3121 screen_row - 1, (int)(Columns - 1));
3122
3123 // When there is a multi-byte character, just output a
3124 // space to keep it simple.
3125 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
3126 screen_row - 1] + (Columns - 1)]) > 1)
3127 out_char(' ');
3128 else
3129 out_char(ScreenLines[LineOffset[screen_row - 1]
3130 + (Columns - 1)]);
3131 // force a redraw of the first char on the next line
3132 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1;
3133 screen_start(); // don't know where cursor is now
3134 }
3135 }
3136
3137 col = 0;
3138 off = (unsigned)(current_ScreenLine - ScreenLines);
3139#ifdef FEAT_RIGHTLEFT
3140 if (wp->w_p_rl)
3141 {
3142 col = wp->w_width - 1; // col is not used if breaking!
3143 off += col;
3144 }
3145#endif
3146
3147 // reset the drawing state for the start of a wrapped line
3148 draw_state = WL_START;
3149 saved_n_extra = n_extra;
3150 saved_p_extra = p_extra;
3151 saved_c_extra = c_extra;
3152 saved_c_final = c_final;
3153#ifdef FEAT_SYN_HL
3154 if (!(cul_screenline
3155# ifdef FEAT_DIFF
Bram Moolenaare7705982020-04-21 22:23:15 +02003156 && diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003157# endif
Bram Moolenaare7705982020-04-21 22:23:15 +02003158 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003159 saved_char_attr = char_attr;
3160 else
3161#endif
3162 saved_char_attr = 0;
3163 n_extra = 0;
3164 lcs_prec_todo = lcs_prec;
3165#ifdef FEAT_LINEBREAK
3166# ifdef FEAT_DIFF
3167 if (filler_todo <= 0)
3168# endif
3169 need_showbreak = TRUE;
3170#endif
3171#ifdef FEAT_DIFF
3172 --filler_todo;
3173 // When the filler lines are actually below the last line of the
3174 // file, don't draw the line itself, break here.
3175 if (filler_todo == 0 && wp->w_botfill)
3176 break;
3177#endif
3178 }
3179
3180 } // for every character in the line
3181
3182#ifdef FEAT_SPELL
3183 // After an empty line check first word for capital.
3184 if (*skipwhite(line) == NUL)
3185 {
3186 capcol_lnum = lnum + 1;
3187 cap_col = 0;
3188 }
3189#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003190#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003191 vim_free(text_props);
3192 vim_free(text_prop_idxs);
3193#endif
3194
3195 vim_free(p_extra_free);
3196 return row;
3197}