blob: 4477b3f0c40bb7f32276ca9d445cfe9c514e8dbe [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)
1404 {
1405 syntax_attr = term_get_attr(wp->w_buffer, lnum, vcol);
1406
1407 if (!attr_pri)
1408 char_attr = syntax_attr;
1409 else
1410 char_attr = hl_combine_attr(syntax_attr, char_attr);
1411 }
1412#endif
1413
1414#ifdef FEAT_SYN_HL
1415 // Get syntax attribute.
1416 if (has_syntax)
1417 {
1418 // Get the syntax attribute for the character. If there
1419 // is an error, disable syntax highlighting.
1420 save_did_emsg = did_emsg;
1421 did_emsg = FALSE;
1422
1423 v = (long)(ptr - line);
1424 can_spell = TRUE;
1425 syntax_attr = get_syntax_attr((colnr_T)v,
1426# ifdef FEAT_SPELL
1427 has_spell ? &can_spell :
1428# endif
1429 NULL, FALSE);
1430
1431 // combine syntax attribute with 'wincolor'
1432 if (syntax_attr != 0 && win_attr != 0)
1433 syntax_attr = hl_combine_attr(win_attr, syntax_attr);
1434
1435 if (did_emsg)
1436 {
1437 wp->w_s->b_syn_error = TRUE;
1438 has_syntax = FALSE;
1439 syntax_attr = 0;
1440 }
1441 else
1442 did_emsg = save_did_emsg;
1443# ifdef SYN_TIME_LIMIT
1444 if (wp->w_s->b_syn_slow)
1445 has_syntax = FALSE;
1446# endif
1447
1448 // Need to get the line again, a multi-line regexp may
1449 // have made it invalid.
1450 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1451 ptr = line + v;
1452# ifdef FEAT_CONCEAL
1453 // no concealing past the end of the line, it interferes
1454 // with line highlighting
1455 if (*ptr == NUL)
1456 syntax_flags = 0;
1457 else
1458 syntax_flags = get_syntax_info(&syntax_seqnr);
1459# endif
1460 }
1461#endif
1462 }
1463
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001464 // Decide which of the highlight attributes to use.
1465 attr_pri = TRUE;
1466#ifdef LINE_ATTR
1467 if (area_attr != 0)
1468 char_attr = hl_combine_attr(line_attr, area_attr);
1469 else if (search_attr != 0)
1470 char_attr = hl_combine_attr(line_attr, search_attr);
1471# ifdef FEAT_TEXT_PROP
1472 else if (text_prop_type != NULL)
1473 {
Bram Moolenaar053f7122019-09-23 22:17:15 +02001474 char_attr = hl_combine_attr(line_attr != 0
1475 ? line_attr
1476 : syntax_attr != 0
1477 ? syntax_attr
1478 : win_attr, text_prop_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001479 }
1480# endif
1481 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
1482 || vcol < fromcol || vcol_prev < fromcol_prev
1483 || vcol >= tocol))
1484 {
1485 // Use line_attr when not in the Visual or 'incsearch' area
1486 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001487# ifdef FEAT_SYN_HL
1488 if (has_syntax)
1489 char_attr = hl_combine_attr(syntax_attr, line_attr);
1490 else
1491# endif
1492 char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001493 attr_pri = FALSE;
1494 }
1495#else
1496 if (area_attr != 0)
1497 char_attr = area_attr;
1498 else if (search_attr != 0)
1499 char_attr = search_attr;
1500#endif
1501 else
1502 {
1503 attr_pri = FALSE;
1504#ifdef FEAT_TEXT_PROP
1505 if (text_prop_type != NULL)
1506 {
1507 if (text_prop_combine)
1508 char_attr = hl_combine_attr(
1509 syntax_attr, text_prop_attr);
1510 else
1511 char_attr = hl_combine_attr(
1512 win_attr, text_prop_attr);
1513 }
1514 else
1515#endif
1516#ifdef FEAT_SYN_HL
1517 if (has_syntax)
1518 char_attr = syntax_attr;
1519 else
1520#endif
1521 char_attr = 0;
1522 }
1523 }
1524 if (char_attr == 0)
1525 char_attr = win_attr;
1526
1527 // Get the next character to put on the screen.
1528
1529 // The "p_extra" points to the extra stuff that is inserted to
1530 // represent special characters (non-printable stuff) and other
1531 // things. When all characters are the same, c_extra is used.
1532 // If c_final is set, it will compulsorily be used at the end.
1533 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
1534 // "p_extra[n_extra]".
1535 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
1536 if (n_extra > 0)
1537 {
1538 if (c_extra != NUL || (n_extra == 1 && c_final != NUL))
1539 {
1540 c = (n_extra == 1 && c_final != NUL) ? c_final : c_extra;
1541 mb_c = c; // doesn't handle non-utf-8 multi-byte!
1542 if (enc_utf8 && utf_char2len(c) > 1)
1543 {
1544 mb_utf8 = TRUE;
1545 u8cc[0] = 0;
1546 c = 0xc0;
1547 }
1548 else
1549 mb_utf8 = FALSE;
1550 }
1551 else
1552 {
1553 c = *p_extra;
1554 if (has_mbyte)
1555 {
1556 mb_c = c;
1557 if (enc_utf8)
1558 {
1559 // If the UTF-8 character is more than one byte:
1560 // Decode it into "mb_c".
1561 mb_l = utfc_ptr2len(p_extra);
1562 mb_utf8 = FALSE;
1563 if (mb_l > n_extra)
1564 mb_l = 1;
1565 else if (mb_l > 1)
1566 {
1567 mb_c = utfc_ptr2char(p_extra, u8cc);
1568 mb_utf8 = TRUE;
1569 c = 0xc0;
1570 }
1571 }
1572 else
1573 {
1574 // if this is a DBCS character, put it in "mb_c"
1575 mb_l = MB_BYTE2LEN(c);
1576 if (mb_l >= n_extra)
1577 mb_l = 1;
1578 else if (mb_l > 1)
1579 mb_c = (c << 8) + p_extra[1];
1580 }
1581 if (mb_l == 0) // at the NUL at end-of-line
1582 mb_l = 1;
1583
1584 // If a double-width char doesn't fit display a '>' in the
1585 // last column.
1586 if ((
1587# ifdef FEAT_RIGHTLEFT
1588 wp->w_p_rl ? (col <= 0) :
1589# endif
1590 (col >= wp->w_width - 1))
1591 && (*mb_char2cells)(mb_c) == 2)
1592 {
1593 c = '>';
1594 mb_c = c;
1595 mb_l = 1;
1596 mb_utf8 = FALSE;
1597 multi_attr = HL_ATTR(HLF_AT);
1598#ifdef FEAT_SYN_HL
1599 if (cul_attr)
1600 multi_attr = hl_combine_attr(multi_attr, cul_attr);
1601#endif
1602 // put the pointer back to output the double-width
1603 // character at the start of the next line.
1604 ++n_extra;
1605 --p_extra;
1606 }
1607 else
1608 {
1609 n_extra -= mb_l - 1;
1610 p_extra += mb_l - 1;
1611 }
1612 }
1613 ++p_extra;
1614 }
1615 --n_extra;
1616 }
1617 else
1618 {
1619#ifdef FEAT_LINEBREAK
1620 int c0;
1621#endif
1622
1623 if (p_extra_free != NULL)
1624 VIM_CLEAR(p_extra_free);
1625 // Get a character from the line itself.
1626 c = *ptr;
1627#ifdef FEAT_LINEBREAK
1628 c0 = *ptr;
1629#endif
1630 if (has_mbyte)
1631 {
1632 mb_c = c;
1633 if (enc_utf8)
1634 {
1635 // If the UTF-8 character is more than one byte: Decode it
1636 // into "mb_c".
1637 mb_l = utfc_ptr2len(ptr);
1638 mb_utf8 = FALSE;
1639 if (mb_l > 1)
1640 {
1641 mb_c = utfc_ptr2char(ptr, u8cc);
1642 // Overlong encoded ASCII or ASCII with composing char
1643 // is displayed normally, except a NUL.
1644 if (mb_c < 0x80)
1645 {
1646 c = mb_c;
1647#ifdef FEAT_LINEBREAK
1648 c0 = mb_c;
1649#endif
1650 }
1651 mb_utf8 = TRUE;
1652
1653 // At start of the line we can have a composing char.
1654 // Draw it as a space with a composing char.
1655 if (utf_iscomposing(mb_c))
1656 {
1657 int i;
1658
1659 for (i = Screen_mco - 1; i > 0; --i)
1660 u8cc[i] = u8cc[i - 1];
1661 u8cc[0] = mb_c;
1662 mb_c = ' ';
1663 }
1664 }
1665
1666 if ((mb_l == 1 && c >= 0x80)
1667 || (mb_l >= 1 && mb_c == 0)
1668 || (mb_l > 1 && (!vim_isprintc(mb_c))))
1669 {
1670 // Illegal UTF-8 byte: display as <xx>.
1671 // Non-BMP character : display as ? or fullwidth ?.
1672 transchar_hex(extra, mb_c);
1673# ifdef FEAT_RIGHTLEFT
1674 if (wp->w_p_rl) // reverse
1675 rl_mirror(extra);
1676# endif
1677 p_extra = extra;
1678 c = *p_extra;
1679 mb_c = mb_ptr2char_adv(&p_extra);
1680 mb_utf8 = (c >= 0x80);
1681 n_extra = (int)STRLEN(p_extra);
1682 c_extra = NUL;
1683 c_final = NUL;
1684 if (area_attr == 0 && search_attr == 0)
1685 {
1686 n_attr = n_extra + 1;
1687 extra_attr = HL_ATTR(HLF_8);
1688 saved_attr2 = char_attr; // save current attr
1689 }
1690 }
1691 else if (mb_l == 0) // at the NUL at end-of-line
1692 mb_l = 1;
1693#ifdef FEAT_ARABIC
1694 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
1695 {
1696 // Do Arabic shaping.
1697 int pc, pc1, nc;
1698 int pcc[MAX_MCO];
1699
1700 // The idea of what is the previous and next
1701 // character depends on 'rightleft'.
1702 if (wp->w_p_rl)
1703 {
1704 pc = prev_c;
1705 pc1 = prev_c1;
1706 nc = utf_ptr2char(ptr + mb_l);
1707 prev_c1 = u8cc[0];
1708 }
1709 else
1710 {
1711 pc = utfc_ptr2char(ptr + mb_l, pcc);
1712 nc = prev_c;
1713 pc1 = pcc[0];
1714 }
1715 prev_c = mb_c;
1716
1717 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
1718 }
1719 else
1720 prev_c = mb_c;
1721#endif
1722 }
1723 else // enc_dbcs
1724 {
1725 mb_l = MB_BYTE2LEN(c);
1726 if (mb_l == 0) // at the NUL at end-of-line
1727 mb_l = 1;
1728 else if (mb_l > 1)
1729 {
1730 // We assume a second byte below 32 is illegal.
1731 // Hopefully this is OK for all double-byte encodings!
1732 if (ptr[1] >= 32)
1733 mb_c = (c << 8) + ptr[1];
1734 else
1735 {
1736 if (ptr[1] == NUL)
1737 {
1738 // head byte at end of line
1739 mb_l = 1;
1740 transchar_nonprint(extra, c);
1741 }
1742 else
1743 {
1744 // illegal tail byte
1745 mb_l = 2;
1746 STRCPY(extra, "XX");
1747 }
1748 p_extra = extra;
1749 n_extra = (int)STRLEN(extra) - 1;
1750 c_extra = NUL;
1751 c_final = NUL;
1752 c = *p_extra++;
1753 if (area_attr == 0 && search_attr == 0)
1754 {
1755 n_attr = n_extra + 1;
1756 extra_attr = HL_ATTR(HLF_8);
1757 saved_attr2 = char_attr; // save current attr
1758 }
1759 mb_c = c;
1760 }
1761 }
1762 }
1763 // If a double-width char doesn't fit display a '>' in the
1764 // last column; the character is displayed at the start of the
1765 // next line.
1766 if ((
1767# ifdef FEAT_RIGHTLEFT
1768 wp->w_p_rl ? (col <= 0) :
1769# endif
1770 (col >= wp->w_width - 1))
1771 && (*mb_char2cells)(mb_c) == 2)
1772 {
1773 c = '>';
1774 mb_c = c;
1775 mb_utf8 = FALSE;
1776 mb_l = 1;
1777 multi_attr = HL_ATTR(HLF_AT);
1778 // Put pointer back so that the character will be
1779 // displayed at the start of the next line.
1780 --ptr;
1781#ifdef FEAT_CONCEAL
1782 did_decrement_ptr = TRUE;
1783#endif
1784 }
1785 else if (*ptr != NUL)
1786 ptr += mb_l - 1;
1787
1788 // If a double-width char doesn't fit at the left side display
1789 // a '<' in the first column. Don't do this for unprintable
1790 // characters.
1791 if (n_skip > 0 && mb_l > 1 && n_extra == 0)
1792 {
1793 n_extra = 1;
1794 c_extra = MB_FILLER_CHAR;
1795 c_final = NUL;
1796 c = ' ';
1797 if (area_attr == 0 && search_attr == 0)
1798 {
1799 n_attr = n_extra + 1;
1800 extra_attr = HL_ATTR(HLF_AT);
1801 saved_attr2 = char_attr; // save current attr
1802 }
1803 mb_c = c;
1804 mb_utf8 = FALSE;
1805 mb_l = 1;
1806 }
1807
1808 }
1809 ++ptr;
1810
1811 if (extra_check)
1812 {
1813#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001814 // Check spelling (unless at the end of the line).
1815 // Only do this when there is no syntax highlighting, the
1816 // @Spell cluster is not used or the current syntax item
1817 // contains the @Spell cluster.
1818 if (has_spell && v >= word_end && v > cur_checked_col)
1819 {
1820 spell_attr = 0;
1821 if (c != 0 && (
1822# ifdef FEAT_SYN_HL
1823 !has_syntax ||
1824# endif
1825 can_spell))
1826 {
1827 char_u *prev_ptr, *p;
1828 int len;
1829 hlf_T spell_hlf = HLF_COUNT;
1830 if (has_mbyte)
1831 {
1832 prev_ptr = ptr - mb_l;
1833 v -= mb_l - 1;
1834 }
1835 else
1836 prev_ptr = ptr - 1;
1837
1838 // Use nextline[] if possible, it has the start of the
1839 // next line concatenated.
1840 if ((prev_ptr - line) - nextlinecol >= 0)
1841 p = nextline + (prev_ptr - line) - nextlinecol;
1842 else
1843 p = prev_ptr;
1844 cap_col -= (int)(prev_ptr - line);
1845 len = spell_check(wp, p, &spell_hlf, &cap_col,
1846 nochange);
1847 word_end = v + len;
1848
1849 // In Insert mode only highlight a word that
1850 // doesn't touch the cursor.
1851 if (spell_hlf != HLF_COUNT
1852 && (State & INSERT) != 0
1853 && wp->w_cursor.lnum == lnum
1854 && wp->w_cursor.col >=
1855 (colnr_T)(prev_ptr - line)
1856 && wp->w_cursor.col < (colnr_T)word_end)
1857 {
1858 spell_hlf = HLF_COUNT;
1859 spell_redraw_lnum = lnum;
1860 }
1861
1862 if (spell_hlf == HLF_COUNT && p != prev_ptr
1863 && (p - nextline) + len > nextline_idx)
1864 {
1865 // Remember that the good word continues at the
1866 // start of the next line.
1867 checked_lnum = lnum + 1;
1868 checked_col = (int)((p - nextline) + len - nextline_idx);
1869 }
1870
1871 // Turn index into actual attributes.
1872 if (spell_hlf != HLF_COUNT)
1873 spell_attr = highlight_attr[spell_hlf];
1874
1875 if (cap_col > 0)
1876 {
1877 if (p != prev_ptr
1878 && (p - nextline) + cap_col >= nextline_idx)
1879 {
1880 // Remember that the word in the next line
1881 // must start with a capital.
1882 capcol_lnum = lnum + 1;
1883 cap_col = (int)((p - nextline) + cap_col
1884 - nextline_idx);
1885 }
1886 else
1887 // Compute the actual column.
1888 cap_col += (int)(prev_ptr - line);
1889 }
1890 }
1891 }
1892 if (spell_attr != 0)
1893 {
1894 if (!attr_pri)
1895 char_attr = hl_combine_attr(char_attr, spell_attr);
1896 else
1897 char_attr = hl_combine_attr(spell_attr, char_attr);
1898 }
1899#endif
1900#ifdef FEAT_LINEBREAK
1901 // Found last space before word: check for line break.
1902 if (wp->w_p_lbr && c0 == c
1903 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
1904 {
1905 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1) : 0;
1906 char_u *p = ptr - (mb_off + 1);
1907
1908 // TODO: is passing p for start of the line OK?
1909 n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol,
1910 NULL) - 1;
1911 if (c == TAB && n_extra + col > wp->w_width)
1912# ifdef FEAT_VARTABS
1913 n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts,
1914 wp->w_buffer->b_p_vts_array) - 1;
1915# else
1916 n_extra = (int)wp->w_buffer->b_p_ts
1917 - vcol % (int)wp->w_buffer->b_p_ts - 1;
1918# endif
1919
1920 c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
1921 c_final = NUL;
1922 if (VIM_ISWHITE(c))
1923 {
1924#ifdef FEAT_CONCEAL
1925 if (c == TAB)
1926 // See "Tab alignment" below.
1927 FIX_FOR_BOGUSCOLS;
1928#endif
1929 if (!wp->w_p_list)
1930 c = ' ';
1931 }
1932 }
1933#endif
1934
1935 // 'list': Change char 160 to lcs_nbsp and space to lcs_space.
1936 // But not when the character is followed by a composing
1937 // character (use mb_l to check that).
1938 if (wp->w_p_list
1939 && ((((c == 160 && mb_l == 1)
1940 || (mb_utf8
1941 && ((mb_c == 160 && mb_l == 2)
1942 || (mb_c == 0x202f && mb_l == 3))))
1943 && lcs_nbsp)
1944 || (c == ' '
1945 && mb_l == 1
1946 && lcs_space
1947 && ptr - line <= trailcol)))
1948 {
1949 c = (c == ' ') ? lcs_space : lcs_nbsp;
1950 if (area_attr == 0 && search_attr == 0)
1951 {
1952 n_attr = 1;
1953 extra_attr = HL_ATTR(HLF_8);
1954 saved_attr2 = char_attr; // save current attr
1955 }
1956 mb_c = c;
1957 if (enc_utf8 && utf_char2len(c) > 1)
1958 {
1959 mb_utf8 = TRUE;
1960 u8cc[0] = 0;
1961 c = 0xc0;
1962 }
1963 else
1964 mb_utf8 = FALSE;
1965 }
1966
1967 if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ')
1968 {
1969 c = lcs_trail;
1970 if (!attr_pri)
1971 {
1972 n_attr = 1;
1973 extra_attr = HL_ATTR(HLF_8);
1974 saved_attr2 = char_attr; // save current attr
1975 }
1976 mb_c = c;
1977 if (enc_utf8 && utf_char2len(c) > 1)
1978 {
1979 mb_utf8 = TRUE;
1980 u8cc[0] = 0;
1981 c = 0xc0;
1982 }
1983 else
1984 mb_utf8 = FALSE;
1985 }
1986 }
1987
1988 // Handling of non-printable characters.
1989 if (!vim_isprintc(c))
1990 {
1991 // when getting a character from the file, we may have to
1992 // turn it into something else on the way to putting it
1993 // into "ScreenLines".
1994 if (c == TAB && (!wp->w_p_list || lcs_tab1))
1995 {
1996 int tab_len = 0;
1997 long vcol_adjusted = vcol; // removed showbreak length
1998#ifdef FEAT_LINEBREAK
1999 // only adjust the tab_len, when at the first column
2000 // after the showbreak value was drawn
2001 if (*p_sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap)
2002 vcol_adjusted = vcol - MB_CHARLEN(p_sbr);
2003#endif
2004 // tab amount depends on current column
2005#ifdef FEAT_VARTABS
2006 tab_len = tabstop_padding(vcol_adjusted,
2007 wp->w_buffer->b_p_ts,
2008 wp->w_buffer->b_p_vts_array) - 1;
2009#else
2010 tab_len = (int)wp->w_buffer->b_p_ts
2011 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2012#endif
2013
2014#ifdef FEAT_LINEBREAK
2015 if (!wp->w_p_lbr || !wp->w_p_list)
2016#endif
2017 // tab amount depends on current column
2018 n_extra = tab_len;
2019#ifdef FEAT_LINEBREAK
2020 else
2021 {
2022 char_u *p;
2023 int len;
2024 int i;
2025 int saved_nextra = n_extra;
2026
2027#ifdef FEAT_CONCEAL
2028 if (vcol_off > 0)
2029 // there are characters to conceal
2030 tab_len += vcol_off;
2031 // boguscols before FIX_FOR_BOGUSCOLS macro from above
2032 if (wp->w_p_list && lcs_tab1 && old_boguscols > 0
2033 && n_extra > tab_len)
2034 tab_len += n_extra - tab_len;
2035#endif
2036
2037 // if n_extra > 0, it gives the number of chars, to
2038 // use for a tab, else we need to calculate the width
2039 // for a tab
2040 len = (tab_len * mb_char2len(lcs_tab2));
2041 if (n_extra > 0)
2042 len += n_extra - tab_len;
2043 c = lcs_tab1;
2044 p = alloc(len + 1);
2045 vim_memset(p, ' ', len);
2046 p[len] = NUL;
2047 vim_free(p_extra_free);
2048 p_extra_free = p;
2049 for (i = 0; i < tab_len; i++)
2050 {
2051 int lcs = lcs_tab2;
2052
2053 if (*p == NUL)
2054 {
2055 tab_len = i;
2056 break;
2057 }
2058
2059 // if lcs_tab3 is given, need to change the char
2060 // for tab
2061 if (lcs_tab3 && i == tab_len - 1)
2062 lcs = lcs_tab3;
2063 mb_char2bytes(lcs, p);
2064 p += mb_char2len(lcs);
2065 n_extra += mb_char2len(lcs)
2066 - (saved_nextra > 0 ? 1 : 0);
2067 }
2068 p_extra = p_extra_free;
2069#ifdef FEAT_CONCEAL
2070 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2071 // macro below, so need to adjust for that here
2072 if (vcol_off > 0)
2073 n_extra -= vcol_off;
2074#endif
2075 }
2076#endif
2077#ifdef FEAT_CONCEAL
2078 {
2079 int vc_saved = vcol_off;
2080
2081 // Tab alignment should be identical regardless of
2082 // 'conceallevel' value. So tab compensates of all
2083 // previous concealed characters, and thus resets
2084 // vcol_off and boguscols accumulated so far in the
2085 // line. Note that the tab can be longer than
2086 // 'tabstop' when there are concealed characters.
2087 FIX_FOR_BOGUSCOLS;
2088
2089 // Make sure, the highlighting for the tab char will be
2090 // correctly set further below (effectively reverts the
2091 // FIX_FOR_BOGSUCOLS macro
2092 if (n_extra == tab_len + vc_saved && wp->w_p_list
2093 && lcs_tab1)
2094 tab_len += vc_saved;
2095 }
2096#endif
2097 mb_utf8 = FALSE; // don't draw as UTF-8
2098 if (wp->w_p_list)
2099 {
2100 c = (n_extra == 0 && lcs_tab3) ? lcs_tab3 : lcs_tab1;
2101#ifdef FEAT_LINEBREAK
2102 if (wp->w_p_lbr)
2103 c_extra = NUL; // using p_extra from above
2104 else
2105#endif
2106 c_extra = lcs_tab2;
2107 c_final = lcs_tab3;
2108 n_attr = tab_len + 1;
2109 extra_attr = HL_ATTR(HLF_8);
2110 saved_attr2 = char_attr; // save current attr
2111 mb_c = c;
2112 if (enc_utf8 && utf_char2len(c) > 1)
2113 {
2114 mb_utf8 = TRUE;
2115 u8cc[0] = 0;
2116 c = 0xc0;
2117 }
2118 }
2119 else
2120 {
2121 c_final = NUL;
2122 c_extra = ' ';
2123 c = ' ';
2124 }
2125 }
2126 else if (c == NUL
2127 && (wp->w_p_list
2128 || ((fromcol >= 0 || fromcol_prev >= 0)
2129 && tocol > vcol
2130 && VIsual_mode != Ctrl_V
2131 && (
2132# ifdef FEAT_RIGHTLEFT
2133 wp->w_p_rl ? (col >= 0) :
2134# endif
2135 (col < wp->w_width))
2136 && !(noinvcur
2137 && lnum == wp->w_cursor.lnum
2138 && (colnr_T)vcol == wp->w_virtcol)))
2139 && lcs_eol_one > 0)
2140 {
2141 // Display a '$' after the line or highlight an extra
2142 // character if the line break is included.
2143#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2144 // For a diff line the highlighting continues after the
2145 // "$".
2146 if (
2147# ifdef FEAT_DIFF
2148 diff_hlf == (hlf_T)0
2149# ifdef LINE_ATTR
2150 &&
2151# endif
2152# endif
2153# ifdef LINE_ATTR
2154 line_attr == 0
2155# endif
2156 )
2157#endif
2158 {
2159 // In virtualedit, visual selections may extend
2160 // beyond end of line.
2161 if (area_highlighting && virtual_active()
2162 && tocol != MAXCOL && vcol < tocol)
2163 n_extra = 0;
2164 else
2165 {
2166 p_extra = at_end_str;
2167 n_extra = 1;
2168 c_extra = NUL;
2169 c_final = NUL;
2170 }
2171 }
2172 if (wp->w_p_list && lcs_eol > 0)
2173 c = lcs_eol;
2174 else
2175 c = ' ';
2176 lcs_eol_one = -1;
2177 --ptr; // put it back at the NUL
2178 if (!attr_pri)
2179 {
2180 extra_attr = HL_ATTR(HLF_AT);
2181 n_attr = 1;
2182 }
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 else
2191 mb_utf8 = FALSE; // don't draw as UTF-8
2192 }
2193 else if (c != NUL)
2194 {
2195 p_extra = transchar(c);
2196 if (n_extra == 0)
2197 n_extra = byte2cells(c) - 1;
2198#ifdef FEAT_RIGHTLEFT
2199 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
2200 rl_mirror(p_extra); // reverse "<12>"
2201#endif
2202 c_extra = NUL;
2203 c_final = NUL;
2204#ifdef FEAT_LINEBREAK
2205 if (wp->w_p_lbr)
2206 {
2207 char_u *p;
2208
2209 c = *p_extra;
2210 p = alloc(n_extra + 1);
2211 vim_memset(p, ' ', n_extra);
2212 STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1);
2213 p[n_extra] = NUL;
2214 vim_free(p_extra_free);
2215 p_extra_free = p_extra = p;
2216 }
2217 else
2218#endif
2219 {
2220 n_extra = byte2cells(c) - 1;
2221 c = *p_extra++;
2222 }
2223 if (!attr_pri)
2224 {
2225 n_attr = n_extra + 1;
2226 extra_attr = HL_ATTR(HLF_8);
2227 saved_attr2 = char_attr; // save current attr
2228 }
2229 mb_utf8 = FALSE; // don't draw as UTF-8
2230 }
2231 else if (VIsual_active
2232 && (VIsual_mode == Ctrl_V
2233 || VIsual_mode == 'v')
2234 && virtual_active()
2235 && tocol != MAXCOL
2236 && vcol < tocol
2237 && (
2238#ifdef FEAT_RIGHTLEFT
2239 wp->w_p_rl ? (col >= 0) :
2240#endif
2241 (col < wp->w_width)))
2242 {
2243 c = ' ';
2244 --ptr; // put it back at the NUL
2245 }
2246#if defined(LINE_ATTR)
2247 else if ((
2248# ifdef FEAT_DIFF
2249 diff_hlf != (hlf_T)0 ||
2250# endif
2251# ifdef FEAT_TERMINAL
2252 win_attr != 0 ||
2253# endif
2254 line_attr != 0
2255 ) && (
2256# ifdef FEAT_RIGHTLEFT
2257 wp->w_p_rl ? (col >= 0) :
2258# endif
2259 (col
2260# ifdef FEAT_CONCEAL
2261 - boguscols
2262# endif
2263 < wp->w_width)))
2264 {
2265 // Highlight until the right side of the window
2266 c = ' ';
2267 --ptr; // put it back at the NUL
2268
2269 // Remember we do the char for line highlighting.
2270 ++did_line_attr;
2271
2272 // don't do search HL for the rest of the line
2273 if (line_attr != 0 && char_attr == search_attr
2274 && (did_line_attr > 1
2275 || (wp->w_p_list && lcs_eol > 0)))
2276 char_attr = line_attr;
2277# ifdef FEAT_DIFF
2278 if (diff_hlf == HLF_TXD)
2279 {
2280 diff_hlf = HLF_CHD;
2281 if (vi_attr == 0 || char_attr != vi_attr)
2282 {
2283 char_attr = HL_ATTR(diff_hlf);
2284 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2285 && wp->w_p_culopt_flags != CULOPT_NBR
2286 && (!cul_screenline
2287 || (vcol >= left_curline_col
2288 && vcol <= right_curline_col)))
2289 char_attr = hl_combine_attr(
2290 char_attr, HL_ATTR(HLF_CUL));
2291 }
2292 }
2293# endif
2294# ifdef FEAT_TERMINAL
2295 if (win_attr != 0)
2296 {
2297 char_attr = win_attr;
2298 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
2299 {
2300 if (!cul_screenline || (vcol >= left_curline_col
2301 && vcol <= right_curline_col))
2302 char_attr = hl_combine_attr(
2303 char_attr, HL_ATTR(HLF_CUL));
2304 }
2305 else if (line_attr)
2306 char_attr = hl_combine_attr(char_attr, line_attr);
2307 }
2308# endif
2309 }
2310#endif
2311 }
2312
2313#ifdef FEAT_CONCEAL
2314 if ( wp->w_p_cole > 0
2315 && (wp != curwin || lnum != wp->w_cursor.lnum ||
2316 conceal_cursor_line(wp))
2317 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2318 && !(lnum_in_visual_area
2319 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2320 {
2321 char_attr = conceal_attr;
2322 if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1)
2323 && (syn_get_sub_char() != NUL || match_conc
2324 || wp->w_p_cole == 1)
2325 && wp->w_p_cole != 3)
2326 {
2327 // First time at this concealed item: display one
2328 // character.
2329 if (match_conc)
2330 c = match_conc;
2331 else if (syn_get_sub_char() != NUL)
2332 c = syn_get_sub_char();
2333 else if (lcs_conceal != NUL)
2334 c = lcs_conceal;
2335 else
2336 c = ' ';
2337
2338 prev_syntax_id = syntax_seqnr;
2339
2340 if (n_extra > 0)
2341 vcol_off += n_extra;
2342 vcol += n_extra;
2343 if (wp->w_p_wrap && n_extra > 0)
2344 {
2345# ifdef FEAT_RIGHTLEFT
2346 if (wp->w_p_rl)
2347 {
2348 col -= n_extra;
2349 boguscols -= n_extra;
2350 }
2351 else
2352# endif
2353 {
2354 boguscols += n_extra;
2355 col += n_extra;
2356 }
2357 }
2358 n_extra = 0;
2359 n_attr = 0;
2360 }
2361 else if (n_skip == 0)
2362 {
2363 is_concealing = TRUE;
2364 n_skip = 1;
2365 }
2366 mb_c = c;
2367 if (enc_utf8 && utf_char2len(c) > 1)
2368 {
2369 mb_utf8 = TRUE;
2370 u8cc[0] = 0;
2371 c = 0xc0;
2372 }
2373 else
2374 mb_utf8 = FALSE; // don't draw as UTF-8
2375 }
2376 else
2377 {
2378 prev_syntax_id = 0;
2379 is_concealing = FALSE;
2380 }
2381
2382 if (n_skip > 0 && did_decrement_ptr)
2383 // not showing the '>', put pointer back to avoid getting stuck
2384 ++ptr;
2385
2386#endif // FEAT_CONCEAL
2387 }
2388
2389#ifdef FEAT_CONCEAL
2390 // In the cursor line and we may be concealing characters: correct
2391 // the cursor column when we reach its position.
2392 if (!did_wcol && draw_state == WL_LINE
2393 && wp == curwin && lnum == wp->w_cursor.lnum
2394 && conceal_cursor_line(wp)
2395 && (int)wp->w_virtcol <= vcol + n_skip)
2396 {
2397# ifdef FEAT_RIGHTLEFT
2398 if (wp->w_p_rl)
2399 wp->w_wcol = wp->w_width - col + boguscols - 1;
2400 else
2401# endif
2402 wp->w_wcol = col - boguscols;
2403 wp->w_wrow = row;
2404 did_wcol = TRUE;
2405 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
2406 }
2407#endif
2408
2409 // Don't override visual selection highlighting.
2410 if (n_attr > 0
2411 && draw_state == WL_LINE
2412 && !attr_pri)
2413 {
2414#ifdef LINE_ATTR
2415 if (line_attr)
2416 char_attr = hl_combine_attr(extra_attr, line_attr);
2417 else
2418#endif
2419 char_attr = extra_attr;
2420 }
2421
2422#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2423 // XIM don't send preedit_start and preedit_end, but they send
2424 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
2425 // im_is_preediting() here.
2426 if (p_imst == IM_ON_THE_SPOT
2427 && xic != NULL
2428 && lnum == wp->w_cursor.lnum
2429 && (State & INSERT)
2430 && !p_imdisable
2431 && im_is_preediting()
2432 && draw_state == WL_LINE)
2433 {
2434 colnr_T tcol;
2435
2436 if (preedit_end_col == MAXCOL)
2437 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
2438 else
2439 tcol = preedit_end_col;
2440 if ((long)preedit_start_col <= vcol && vcol < (long)tcol)
2441 {
2442 if (feedback_old_attr < 0)
2443 {
2444 feedback_col = 0;
2445 feedback_old_attr = char_attr;
2446 }
2447 char_attr = im_get_feedback_attr(feedback_col);
2448 if (char_attr < 0)
2449 char_attr = feedback_old_attr;
2450 feedback_col++;
2451 }
2452 else if (feedback_old_attr >= 0)
2453 {
2454 char_attr = feedback_old_attr;
2455 feedback_old_attr = -1;
2456 feedback_col = 0;
2457 }
2458 }
2459#endif
2460 // Handle the case where we are in column 0 but not on the first
2461 // character of the line and the user wants us to show us a
2462 // special character (via 'listchars' option "precedes:<char>".
2463 if (lcs_prec_todo != NUL
2464 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02002465 && (wp->w_p_wrap ?
2466 (wp->w_skipcol > 0 && row == 0) :
2467 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002468#ifdef FEAT_DIFF
2469 && filler_todo <= 0
2470#endif
2471 && draw_state > WL_NR
2472 && c != NUL)
2473 {
2474 c = lcs_prec;
2475 lcs_prec_todo = NUL;
2476 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2477 {
2478 // Double-width character being overwritten by the "precedes"
2479 // character, need to fill up half the character.
2480 c_extra = MB_FILLER_CHAR;
2481 c_final = NUL;
2482 n_extra = 1;
2483 n_attr = 2;
2484 extra_attr = HL_ATTR(HLF_AT);
2485 }
2486 mb_c = c;
2487 if (enc_utf8 && utf_char2len(c) > 1)
2488 {
2489 mb_utf8 = TRUE;
2490 u8cc[0] = 0;
2491 c = 0xc0;
2492 }
2493 else
2494 mb_utf8 = FALSE; // don't draw as UTF-8
2495 if (!attr_pri)
2496 {
2497 saved_attr3 = char_attr; // save current attr
2498 char_attr = HL_ATTR(HLF_AT); // later copied to char_attr
2499 n_attr3 = 1;
2500 }
2501 }
2502
2503 // At end of the text line or just after the last character.
2504 if ((c == NUL
2505#if defined(LINE_ATTR)
2506 || did_line_attr == 1
2507#endif
2508 ) && eol_hl_off == 0)
2509 {
2510#ifdef FEAT_SEARCH_EXTRA
2511 // flag to indicate whether prevcol equals startcol of search_hl or
2512 // one of the matches
2513 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
2514 (long)(ptr - line) - (c == NUL));
2515#endif
2516 // Invert at least one char, used for Visual and empty line or
2517 // highlight match at end of line. If it's beyond the last
2518 // char on the screen, just overwrite that one (tricky!) Not
2519 // needed when a '$' was displayed for 'list'.
2520 if (lcs_eol == lcs_eol_one
2521 && ((area_attr != 0 && vcol == fromcol
2522 && (VIsual_mode != Ctrl_V
2523 || lnum == VIsual.lnum
2524 || lnum == curwin->w_cursor.lnum)
2525 && c == NUL)
2526#ifdef FEAT_SEARCH_EXTRA
2527 // highlight 'hlsearch' match at end of line
2528 || (prevcol_hl_flag
2529# ifdef FEAT_SYN_HL
2530 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
2531 && !(wp == curwin && VIsual_active))
2532# endif
2533# ifdef FEAT_DIFF
2534 && diff_hlf == (hlf_T)0
2535# endif
2536# if defined(LINE_ATTR)
2537 && did_line_attr <= 1
2538# endif
2539 )
2540#endif
2541 ))
2542 {
2543 int n = 0;
2544
2545#ifdef FEAT_RIGHTLEFT
2546 if (wp->w_p_rl)
2547 {
2548 if (col < 0)
2549 n = 1;
2550 }
2551 else
2552#endif
2553 {
2554 if (col >= wp->w_width)
2555 n = -1;
2556 }
2557 if (n != 0)
2558 {
2559 // At the window boundary, highlight the last character
2560 // instead (better than nothing).
2561 off += n;
2562 col += n;
2563 }
2564 else
2565 {
2566 // Add a blank character to highlight.
2567 ScreenLines[off] = ' ';
2568 if (enc_utf8)
2569 ScreenLinesUC[off] = 0;
2570 }
2571#ifdef FEAT_SEARCH_EXTRA
2572 if (area_attr == 0)
2573 {
2574 // Use attributes from match with highest priority among
2575 // 'search_hl' and the match list.
2576 get_search_match_hl(wp, &screen_search_hl,
2577 (long)(ptr - line), &char_attr);
2578 }
2579#endif
2580 ScreenAttrs[off] = char_attr;
2581#ifdef FEAT_RIGHTLEFT
2582 if (wp->w_p_rl)
2583 {
2584 --col;
2585 --off;
2586 }
2587 else
2588#endif
2589 {
2590 ++col;
2591 ++off;
2592 }
2593 ++vcol;
2594 eol_hl_off = 1;
2595 }
2596 }
2597
2598 // At end of the text line.
2599 if (c == NUL)
2600 {
2601#ifdef FEAT_SYN_HL
2602 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
2603 if (wp->w_p_wrap)
2604 v = wp->w_skipcol;
2605 else
2606 v = wp->w_leftcol;
2607
2608 // check if line ends before left margin
2609 if (vcol < v + col - win_col_off(wp))
2610 vcol = v + col - win_col_off(wp);
2611#ifdef FEAT_CONCEAL
2612 // Get rid of the boguscols now, we want to draw until the right
2613 // edge for 'cursorcolumn'.
2614 col -= boguscols;
2615 boguscols = 0;
2616#endif
2617
2618 if (draw_color_col)
2619 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2620
2621 if (((wp->w_p_cuc
2622 && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off
2623 && (int)wp->w_virtcol <
2624 wp->w_width * (row - startrow + 1) + v
2625 && lnum != wp->w_cursor.lnum)
2626 || draw_color_col
2627 || win_attr != 0)
2628# ifdef FEAT_RIGHTLEFT
2629 && !wp->w_p_rl
2630# endif
2631 )
2632 {
2633 int rightmost_vcol = 0;
2634 int i;
2635
2636 if (wp->w_p_cuc)
2637 rightmost_vcol = wp->w_virtcol;
2638 if (draw_color_col)
2639 // determine rightmost colorcolumn to possibly draw
2640 for (i = 0; color_cols[i] >= 0; ++i)
2641 if (rightmost_vcol < color_cols[i])
2642 rightmost_vcol = color_cols[i];
2643
2644 while (col < wp->w_width)
2645 {
2646 ScreenLines[off] = ' ';
2647 if (enc_utf8)
2648 ScreenLinesUC[off] = 0;
2649 ++col;
2650 if (draw_color_col)
2651 draw_color_col = advance_color_col(VCOL_HLC,
2652 &color_cols);
2653
2654 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
2655 ScreenAttrs[off++] = HL_ATTR(HLF_CUC);
2656 else if (draw_color_col && VCOL_HLC == *color_cols)
2657 ScreenAttrs[off++] = HL_ATTR(HLF_MC);
2658 else
2659 ScreenAttrs[off++] = win_attr;
2660
2661 if (VCOL_HLC >= rightmost_vcol && win_attr == 0)
2662 break;
2663
2664 ++vcol;
2665 }
2666 }
2667#endif
2668
2669 screen_line(screen_row, wp->w_wincol, col,
2670 (int)wp->w_width, screen_line_flags);
2671 row++;
2672
2673 // Update w_cline_height and w_cline_folded if the cursor line was
2674 // updated (saves a call to plines() later).
2675 if (wp == curwin && lnum == curwin->w_cursor.lnum)
2676 {
2677 curwin->w_cline_row = startrow;
2678 curwin->w_cline_height = row - startrow;
2679#ifdef FEAT_FOLDING
2680 curwin->w_cline_folded = FALSE;
2681#endif
2682 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
2683 }
2684
2685 break;
2686 }
2687
2688 // Show "extends" character from 'listchars' if beyond the line end and
2689 // 'list' is set.
2690 if (lcs_ext != NUL
2691 && wp->w_p_list
2692 && !wp->w_p_wrap
2693#ifdef FEAT_DIFF
2694 && filler_todo <= 0
2695#endif
2696 && (
2697#ifdef FEAT_RIGHTLEFT
2698 wp->w_p_rl ? col == 0 :
2699#endif
2700 col == wp->w_width - 1)
2701 && (*ptr != NUL
2702 || (wp->w_p_list && lcs_eol_one > 0)
2703 || (n_extra && (c_extra != NUL || *p_extra != NUL))))
2704 {
2705 c = lcs_ext;
2706 char_attr = HL_ATTR(HLF_AT);
2707 mb_c = c;
2708 if (enc_utf8 && utf_char2len(c) > 1)
2709 {
2710 mb_utf8 = TRUE;
2711 u8cc[0] = 0;
2712 c = 0xc0;
2713 }
2714 else
2715 mb_utf8 = FALSE;
2716 }
2717
2718#ifdef FEAT_SYN_HL
2719 // advance to the next 'colorcolumn'
2720 if (draw_color_col)
2721 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2722
2723 // Highlight the cursor column if 'cursorcolumn' is set. But don't
2724 // highlight the cursor position itself.
2725 // Also highlight the 'colorcolumn' if it is different than
2726 // 'cursorcolumn'
2727 vcol_save_attr = -1;
2728 if (draw_state == WL_LINE && !lnum_in_visual_area
2729 && search_attr == 0 && area_attr == 0)
2730 {
2731 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
2732 && lnum != wp->w_cursor.lnum)
2733 {
2734 vcol_save_attr = char_attr;
2735 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUC));
2736 }
2737 else if (draw_color_col && VCOL_HLC == *color_cols)
2738 {
2739 vcol_save_attr = char_attr;
2740 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_MC));
2741 }
2742 }
2743#endif
2744
2745 // Store character to be displayed.
2746 // Skip characters that are left of the screen for 'nowrap'.
2747 vcol_prev = vcol;
2748 if (draw_state < WL_LINE || n_skip <= 0)
2749 {
2750 // Store the character.
2751#if defined(FEAT_RIGHTLEFT)
2752 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
2753 {
2754 // A double-wide character is: put first halve in left cell.
2755 --off;
2756 --col;
2757 }
2758#endif
2759 ScreenLines[off] = c;
2760 if (enc_dbcs == DBCS_JPNU)
2761 {
2762 if ((mb_c & 0xff00) == 0x8e00)
2763 ScreenLines[off] = 0x8e;
2764 ScreenLines2[off] = mb_c & 0xff;
2765 }
2766 else if (enc_utf8)
2767 {
2768 if (mb_utf8)
2769 {
2770 int i;
2771
2772 ScreenLinesUC[off] = mb_c;
2773 if ((c & 0xff) == 0)
2774 ScreenLines[off] = 0x80; // avoid storing zero
2775 for (i = 0; i < Screen_mco; ++i)
2776 {
2777 ScreenLinesC[i][off] = u8cc[i];
2778 if (u8cc[i] == 0)
2779 break;
2780 }
2781 }
2782 else
2783 ScreenLinesUC[off] = 0;
2784 }
2785 if (multi_attr)
2786 {
2787 ScreenAttrs[off] = multi_attr;
2788 multi_attr = 0;
2789 }
2790 else
2791 ScreenAttrs[off] = char_attr;
2792
2793 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2794 {
2795 // Need to fill two screen columns.
2796 ++off;
2797 ++col;
2798 if (enc_utf8)
2799 // UTF-8: Put a 0 in the second screen char.
2800 ScreenLines[off] = 0;
2801 else
2802 // DBCS: Put second byte in the second screen char.
2803 ScreenLines[off] = mb_c & 0xff;
2804 if (draw_state > WL_NR
2805#ifdef FEAT_DIFF
2806 && filler_todo <= 0
2807#endif
2808 )
2809 ++vcol;
2810 // When "tocol" is halfway a character, set it to the end of
2811 // the character, otherwise highlighting won't stop.
2812 if (tocol == vcol)
2813 ++tocol;
2814#ifdef FEAT_RIGHTLEFT
2815 if (wp->w_p_rl)
2816 {
2817 // now it's time to backup one cell
2818 --off;
2819 --col;
2820 }
2821#endif
2822 }
2823#ifdef FEAT_RIGHTLEFT
2824 if (wp->w_p_rl)
2825 {
2826 --off;
2827 --col;
2828 }
2829 else
2830#endif
2831 {
2832 ++off;
2833 ++col;
2834 }
2835 }
2836#ifdef FEAT_CONCEAL
2837 else if (wp->w_p_cole > 0 && is_concealing)
2838 {
2839 --n_skip;
2840 ++vcol_off;
2841 if (n_extra > 0)
2842 vcol_off += n_extra;
2843 if (wp->w_p_wrap)
2844 {
2845 // Special voodoo required if 'wrap' is on.
2846 //
2847 // Advance the column indicator to force the line
2848 // drawing to wrap early. This will make the line
2849 // take up the same screen space when parts are concealed,
2850 // so that cursor line computations aren't messed up.
2851 //
2852 // To avoid the fictitious advance of 'col' causing
2853 // trailing junk to be written out of the screen line
2854 // we are building, 'boguscols' keeps track of the number
2855 // of bad columns we have advanced.
2856 if (n_extra > 0)
2857 {
2858 vcol += n_extra;
2859# ifdef FEAT_RIGHTLEFT
2860 if (wp->w_p_rl)
2861 {
2862 col -= n_extra;
2863 boguscols -= n_extra;
2864 }
2865 else
2866# endif
2867 {
2868 col += n_extra;
2869 boguscols += n_extra;
2870 }
2871 n_extra = 0;
2872 n_attr = 0;
2873 }
2874
2875
2876 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2877 {
2878 // Need to fill two screen columns.
2879# ifdef FEAT_RIGHTLEFT
2880 if (wp->w_p_rl)
2881 {
2882 --boguscols;
2883 --col;
2884 }
2885 else
2886# endif
2887 {
2888 ++boguscols;
2889 ++col;
2890 }
2891 }
2892
2893# ifdef FEAT_RIGHTLEFT
2894 if (wp->w_p_rl)
2895 {
2896 --boguscols;
2897 --col;
2898 }
2899 else
2900# endif
2901 {
2902 ++boguscols;
2903 ++col;
2904 }
2905 }
2906 else
2907 {
2908 if (n_extra > 0)
2909 {
2910 vcol += n_extra;
2911 n_extra = 0;
2912 n_attr = 0;
2913 }
2914 }
2915
2916 }
2917#endif // FEAT_CONCEAL
2918 else
2919 --n_skip;
2920
2921 // Only advance the "vcol" when after the 'number' or 'relativenumber'
2922 // column.
2923 if (draw_state > WL_NR
2924#ifdef FEAT_DIFF
2925 && filler_todo <= 0
2926#endif
2927 )
2928 ++vcol;
2929
2930#ifdef FEAT_SYN_HL
2931 if (vcol_save_attr >= 0)
2932 char_attr = vcol_save_attr;
2933#endif
2934
2935 // restore attributes after "predeces" in 'listchars'
2936 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
2937 char_attr = saved_attr3;
2938
2939 // restore attributes after last 'listchars' or 'number' char
2940 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0)
2941 char_attr = saved_attr2;
2942
2943 // At end of screen line and there is more to come: Display the line
2944 // so far. If there is no more to display it is caught above.
2945 if ((
2946#ifdef FEAT_RIGHTLEFT
2947 wp->w_p_rl ? (col < 0) :
2948#endif
2949 (col >= wp->w_width))
2950 && (*ptr != NUL
2951#ifdef FEAT_DIFF
2952 || filler_todo > 0
2953#endif
2954 || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str)
2955 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL)))
2956 )
2957 {
2958#ifdef FEAT_CONCEAL
2959 screen_line(screen_row, wp->w_wincol, col - boguscols,
2960 (int)wp->w_width, screen_line_flags);
2961 boguscols = 0;
2962#else
2963 screen_line(screen_row, wp->w_wincol, col,
2964 (int)wp->w_width, screen_line_flags);
2965#endif
2966 ++row;
2967 ++screen_row;
2968
2969 // When not wrapping and finished diff lines, or when displayed
2970 // '$' and highlighting until last column, break here.
2971 if ((!wp->w_p_wrap
2972#ifdef FEAT_DIFF
2973 && filler_todo <= 0
2974#endif
2975 ) || lcs_eol_one == -1)
2976 break;
2977
2978 // When the window is too narrow draw all "@" lines.
2979 if (draw_state != WL_LINE
2980#ifdef FEAT_DIFF
2981 && filler_todo <= 0
2982#endif
2983 )
2984 {
2985 win_draw_end(wp, '@', ' ', TRUE, row, wp->w_height, HLF_AT);
2986 draw_vsep_win(wp, row);
2987 row = endrow;
2988 }
2989
2990 // When line got too long for screen break here.
2991 if (row == endrow)
2992 {
2993 ++row;
2994 break;
2995 }
2996
2997 if (screen_cur_row == screen_row - 1
2998#ifdef FEAT_DIFF
2999 && filler_todo <= 0
3000#endif
3001 && wp->w_width == Columns)
3002 {
3003 // Remember that the line wraps, used for modeless copy.
3004 LineWraps[screen_row - 1] = TRUE;
3005
3006 // Special trick to make copy/paste of wrapped lines work with
3007 // xterm/screen: write an extra character beyond the end of
3008 // the line. This will work with all terminal types
3009 // (regardless of the xn,am settings).
3010 // Only do this on a fast tty.
3011 // Only do this if the cursor is on the current line
3012 // (something has been written in it).
3013 // Don't do this for the GUI.
3014 // Don't do this for double-width characters.
3015 // Don't do this for a window not at the right screen border.
3016 if (p_tf
3017#ifdef FEAT_GUI
3018 && !gui.in_use
3019#endif
3020 && !(has_mbyte
3021 && ((*mb_off2cells)(LineOffset[screen_row],
3022 LineOffset[screen_row] + screen_Columns)
3023 == 2
3024 || (*mb_off2cells)(LineOffset[screen_row - 1]
3025 + (int)Columns - 2,
3026 LineOffset[screen_row] + screen_Columns)
3027 == 2)))
3028 {
3029 // First make sure we are at the end of the screen line,
3030 // then output the same character again to let the
3031 // terminal know about the wrap. If the terminal doesn't
3032 // auto-wrap, we overwrite the character.
3033 if (screen_cur_col != wp->w_width)
3034 screen_char(LineOffset[screen_row - 1]
3035 + (unsigned)Columns - 1,
3036 screen_row - 1, (int)(Columns - 1));
3037
3038 // When there is a multi-byte character, just output a
3039 // space to keep it simple.
3040 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
3041 screen_row - 1] + (Columns - 1)]) > 1)
3042 out_char(' ');
3043 else
3044 out_char(ScreenLines[LineOffset[screen_row - 1]
3045 + (Columns - 1)]);
3046 // force a redraw of the first char on the next line
3047 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1;
3048 screen_start(); // don't know where cursor is now
3049 }
3050 }
3051
3052 col = 0;
3053 off = (unsigned)(current_ScreenLine - ScreenLines);
3054#ifdef FEAT_RIGHTLEFT
3055 if (wp->w_p_rl)
3056 {
3057 col = wp->w_width - 1; // col is not used if breaking!
3058 off += col;
3059 }
3060#endif
3061
3062 // reset the drawing state for the start of a wrapped line
3063 draw_state = WL_START;
3064 saved_n_extra = n_extra;
3065 saved_p_extra = p_extra;
3066 saved_c_extra = c_extra;
3067 saved_c_final = c_final;
3068#ifdef FEAT_SYN_HL
3069 if (!(cul_screenline
3070# ifdef FEAT_DIFF
3071 && diff_hlf == (hlf_T)0)
3072# endif
3073 )
3074 saved_char_attr = char_attr;
3075 else
3076#endif
3077 saved_char_attr = 0;
3078 n_extra = 0;
3079 lcs_prec_todo = lcs_prec;
3080#ifdef FEAT_LINEBREAK
3081# ifdef FEAT_DIFF
3082 if (filler_todo <= 0)
3083# endif
3084 need_showbreak = TRUE;
3085#endif
3086#ifdef FEAT_DIFF
3087 --filler_todo;
3088 // When the filler lines are actually below the last line of the
3089 // file, don't draw the line itself, break here.
3090 if (filler_todo == 0 && wp->w_botfill)
3091 break;
3092#endif
3093 }
3094
3095 } // for every character in the line
3096
3097#ifdef FEAT_SPELL
3098 // After an empty line check first word for capital.
3099 if (*skipwhite(line) == NUL)
3100 {
3101 capcol_lnum = lnum + 1;
3102 cap_col = 0;
3103 }
3104#endif
3105#ifdef FEAT_TEXT_PROP
3106 vim_free(text_props);
3107 vim_free(text_prop_idxs);
3108#endif
3109
3110 vim_free(p_extra_free);
3111 return row;
3112}
3113