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