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