blob: 6a5c28df1d520d751d76ac5c963dd0d1e3ddf1bd [file] [log] [blame]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * drawline.c: Functions for drawing window lines on the screen.
12 * This is the middle level, drawscreen. is the higher level and screen.c the
13 * lower level.
14 */
15
16#include "vim.h"
17
18#ifdef FEAT_SYN_HL
19/*
20 * Advance **color_cols and return TRUE when there are columns to draw.
21 */
22 static int
23advance_color_col(int vcol, int **color_cols)
24{
25 while (**color_cols >= 0 && vcol > **color_cols)
26 ++*color_cols;
27 return (**color_cols >= 0);
28}
29#endif
30
31#ifdef FEAT_SYN_HL
32/*
33 * Used when 'cursorlineopt' contains "screenline": compute the margins between
34 * which the highlighting is used.
35 */
36 static void
37margin_columns_win(win_T *wp, int *left_col, int *right_col)
38{
39 // cache previous calculations depending on w_virtcol
40 static int saved_w_virtcol;
41 static win_T *prev_wp;
42 static int prev_left_col;
43 static int prev_right_col;
44 static int prev_col_off;
45
46 int cur_col_off = win_col_off(wp);
47 int width1;
48 int width2;
49
50 if (saved_w_virtcol == wp->w_virtcol
51 && prev_wp == wp && prev_col_off == cur_col_off)
52 {
53 *right_col = prev_right_col;
54 *left_col = prev_left_col;
55 return;
56 }
57
58 width1 = wp->w_width - cur_col_off;
59 width2 = width1 + win_col_off2(wp);
60
61 *left_col = 0;
62 *right_col = width1;
63
64 if (wp->w_virtcol >= (colnr_T)width1)
65 *right_col = width1 + ((wp->w_virtcol - width1) / width2 + 1) * width2;
66 if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0)
67 *left_col = (wp->w_virtcol - width1) / width2 * width2 + width1;
68
69 // cache values
70 prev_left_col = *left_col;
71 prev_right_col = *right_col;
72 prev_wp = wp;
73 saved_w_virtcol = wp->w_virtcol;
74 prev_col_off = cur_col_off;
75}
76#endif
77
78#ifdef FEAT_SIGNS
79/*
Bram Moolenaare413ea02021-11-24 16:20:13 +000080 * Return TRUE if CursorLineSign highlight is to be used.
81 */
82 static int
83use_cursor_line_sign(win_T *wp, linenr_T lnum)
84{
85 return wp->w_p_cul
86 && lnum == wp->w_cursor.lnum
87 && (wp->w_p_culopt_flags & CULOPT_NBR);
88}
89
90/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020091 * Get information needed to display the sign in line 'lnum' in window 'wp'.
92 * If 'nrcol' is TRUE, the sign is going to be displayed in the number column.
93 * Otherwise the sign is going to be displayed in the sign column.
94 */
95 static void
96get_sign_display_info(
97 int nrcol,
98 win_T *wp,
Bram Moolenaare413ea02021-11-24 16:20:13 +000099 linenr_T lnum,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200100 sign_attrs_T *sattr,
101 int wcr_attr,
102 int row,
103 int startrow,
104 int filler_lines UNUSED,
105 int filler_todo UNUSED,
106 int *c_extrap,
107 int *c_finalp,
108 char_u *extra,
109 char_u **pp_extra,
110 int *n_extrap,
111 int *char_attrp)
112{
113 int text_sign;
114# ifdef FEAT_SIGN_ICONS
115 int icon_sign;
116# endif
117
118 // Draw two cells with the sign value or blank.
119 *c_extrap = ' ';
120 *c_finalp = NUL;
121 if (nrcol)
122 *n_extrap = number_width(wp) + 1;
123 else
124 {
Bram Moolenaare413ea02021-11-24 16:20:13 +0000125 if (use_cursor_line_sign(wp, lnum))
126 *char_attrp = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLS));
127 else
128 *char_attrp = hl_combine_attr(wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200129 *n_extrap = 2;
130 }
131
132 if (row == startrow
133#ifdef FEAT_DIFF
134 + filler_lines && filler_todo <= 0
135#endif
136 )
137 {
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200138 text_sign = (sattr->sat_text != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200139# ifdef FEAT_SIGN_ICONS
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200140 icon_sign = (sattr->sat_icon != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200141 if (gui.in_use && icon_sign != 0)
142 {
143 // Use the image in this position.
144 if (nrcol)
145 {
146 *c_extrap = NUL;
147 sprintf((char *)extra, "%-*c ", number_width(wp), SIGN_BYTE);
148 *pp_extra = extra;
149 *n_extrap = (int)STRLEN(*pp_extra);
150 }
151 else
152 *c_extrap = SIGN_BYTE;
153# ifdef FEAT_NETBEANS_INTG
154 if (netbeans_active() && (buf_signcount(wp->w_buffer, lnum) > 1))
155 {
156 if (nrcol)
157 {
158 *c_extrap = NUL;
159 sprintf((char *)extra, "%-*c ", number_width(wp),
160 MULTISIGN_BYTE);
161 *pp_extra = extra;
162 *n_extrap = (int)STRLEN(*pp_extra);
163 }
164 else
165 *c_extrap = MULTISIGN_BYTE;
166 }
167# endif
168 *c_finalp = NUL;
169 *char_attrp = icon_sign;
170 }
171 else
172# endif
173 if (text_sign != 0)
174 {
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200175 *pp_extra = sattr->sat_text;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200176 if (*pp_extra != NULL)
177 {
178 if (nrcol)
179 {
180 int n, width = number_width(wp) - 2;
181
182 for (n = 0; n < width; n++)
183 extra[n] = ' ';
184 extra[n] = 0;
185 STRCAT(extra, *pp_extra);
186 STRCAT(extra, " ");
187 *pp_extra = extra;
188 }
189 *c_extrap = NUL;
190 *c_finalp = NUL;
191 *n_extrap = (int)STRLEN(*pp_extra);
192 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000193
194 if (use_cursor_line_sign(wp, lnum) && sattr->sat_culhl > 0)
195 *char_attrp = sattr->sat_culhl;
196 else
197 *char_attrp = sattr->sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200198 }
199 }
200}
201#endif
202
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100203#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200204static textprop_T *current_text_props = NULL;
205static buf_T *current_buf = NULL;
206
207 static int
208text_prop_compare(const void *s1, const void *s2)
209{
210 int idx1, idx2;
211 proptype_T *pt1, *pt2;
212 colnr_T col1, col2;
213
214 idx1 = *(int *)s1;
215 idx2 = *(int *)s2;
216 pt1 = text_prop_type_by_id(current_buf, current_text_props[idx1].tp_type);
217 pt2 = text_prop_type_by_id(current_buf, current_text_props[idx2].tp_type);
218 if (pt1 == pt2)
219 return 0;
220 if (pt1 == NULL)
221 return -1;
222 if (pt2 == NULL)
223 return 1;
224 if (pt1->pt_priority != pt2->pt_priority)
225 return pt1->pt_priority > pt2->pt_priority ? 1 : -1;
226 col1 = current_text_props[idx1].tp_col;
227 col2 = current_text_props[idx2].tp_col;
228 return col1 == col2 ? 0 : col1 > col2 ? 1 : -1;
229}
230#endif
231
232/*
233 * Display line "lnum" of window 'wp' on the screen.
234 * Start at row "startrow", stop when "endrow" is reached.
235 * wp->w_virtcol needs to be valid.
236 *
237 * Return the number of last row the line occupies.
238 */
239 int
240win_line(
241 win_T *wp,
242 linenr_T lnum,
243 int startrow,
244 int endrow,
245 int nochange UNUSED, // not updating for changed text
246 int number_only) // only update the number column
247{
248 int col = 0; // visual column on screen
249 unsigned off; // offset in ScreenLines/ScreenAttrs
250 int c = 0; // init for GCC
251 long vcol = 0; // virtual column (for tabs)
252#ifdef FEAT_LINEBREAK
253 long vcol_sbr = -1; // virtual column after showbreak
254#endif
255 long vcol_prev = -1; // "vcol" of previous character
256 char_u *line; // current line
257 char_u *ptr; // current position in "line"
258 int row; // row in the window, excl w_winrow
259 int screen_row; // row on the screen, incl w_winrow
260
261 char_u extra[21]; // "%ld " and 'fdc' must fit in here
262 int n_extra = 0; // number of extra chars
263 char_u *p_extra = NULL; // string of extra chars, plus NUL
264 char_u *p_extra_free = NULL; // p_extra needs to be freed
265 int c_extra = NUL; // extra chars, all the same
266 int c_final = NUL; // final char, mandatory if set
267 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000268#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000269 int in_linebreak = FALSE; // n_extra set for showing linebreak
270#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200271 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100272 // displaying eol at end-of-line
273 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000274 int lcs_prec_todo = wp->w_lcs_chars.prec;
275 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200276
277 // saved "extra" items for when draw_state becomes WL_LINE (again)
278 int saved_n_extra = 0;
279 char_u *saved_p_extra = NULL;
280 int saved_c_extra = 0;
281 int saved_c_final = 0;
282 int saved_char_attr = 0;
283
284 int n_attr = 0; // chars with special attr
285 int saved_attr2 = 0; // char_attr saved for n_attr
286 int n_attr3 = 0; // chars with overruling special attr
287 int saved_attr3 = 0; // char_attr saved for n_attr3
288
289 int n_skip = 0; // nr of chars to skip for 'nowrap'
290
291 int fromcol = -10; // start of inverting
292 int tocol = MAXCOL; // end of inverting
293 int fromcol_prev = -2; // start of inverting after cursor
294 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200295 int lnum_in_visual_area = FALSE;
296 pos_T pos;
297 long v;
298
299 int char_attr = 0; // attributes for next character
300 int attr_pri = FALSE; // char_attr has priority
301 int area_highlighting = FALSE; // Visual or incsearch highlighting
302 // in this line
303 int vi_attr = 0; // attributes for Visual and incsearch
304 // highlighting
305 int wcr_attr = 0; // attributes from 'wincolor'
306 int win_attr = 0; // background for whole window, except
307 // margins and "~" lines.
308 int area_attr = 0; // attributes desired by highlighting
309 int search_attr = 0; // attributes desired by 'hlsearch'
310#ifdef FEAT_SYN_HL
311 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
312 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200313 int prev_syntax_col = -1; // column of prev_syntax_attr
314 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200315 int has_syntax = FALSE; // this buffer has syntax highl.
316 int save_did_emsg;
317 int draw_color_col = FALSE; // highlight colorcolumn
318 int *color_cols = NULL; // pointer to according columns array
319#endif
320 int eol_hl_off = 0; // 1 if highlighted char after EOL
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100321#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200322 int text_prop_count;
323 int text_prop_next = 0; // next text property to use
324 textprop_T *text_props = NULL;
325 int *text_prop_idxs = NULL;
326 int text_props_active = 0;
327 proptype_T *text_prop_type = NULL;
328 int text_prop_attr = 0;
329 int text_prop_combine = FALSE;
330#endif
331#ifdef FEAT_SPELL
332 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000333 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200334# define SPWORDLEN 150
335 char_u nextline[SPWORDLEN * 2];// text with start of the next line
336 int nextlinecol = 0; // column where nextline[] starts
337 int nextline_idx = 0; // index in nextline[] where next line
338 // starts
339 int spell_attr = 0; // attributes desired by spelling
340 int word_end = 0; // last byte with same spell_attr
341 static linenr_T checked_lnum = 0; // line number for "checked_col"
342 static int checked_col = 0; // column in "checked_lnum" up to which
343 // there are no spell errors
344 static int cap_col = -1; // column to check for Cap word
345 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
346 int cur_checked_col = 0; // checked column for current line
347#endif
348 int extra_check = 0; // has extra highlighting
349 int multi_attr = 0; // attributes desired by multibyte
350 int mb_l = 1; // multi-byte byte length
351 int mb_c = 0; // decoded multi-byte character
352 int mb_utf8 = FALSE; // screen char is UTF-8 char
353 int u8cc[MAX_MCO]; // composing UTF-8 chars
354#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
355 int filler_lines = 0; // nr of filler lines to be drawn
356 int filler_todo = 0; // nr of filler lines still to do + 1
357#endif
358#ifdef FEAT_DIFF
359 hlf_T diff_hlf = (hlf_T)0; // type of diff highlighting
360 int change_start = MAXCOL; // first col of changed area
361 int change_end = -1; // last col of changed area
362#endif
363 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100364 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200365 int in_multispace = FALSE; // in multiple consecutive spaces
366 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200367#ifdef FEAT_LINEBREAK
368 int need_showbreak = FALSE; // overlong line, skipping first x
369 // chars
370#endif
371#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
372 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
373# define LINE_ATTR
374 int line_attr = 0; // attribute for the whole line
375 int line_attr_save;
376#endif
377#ifdef FEAT_SIGNS
378 int sign_present = FALSE;
379 sign_attrs_T sattr;
James McCoya80aad72021-12-22 19:45:28 +0000380 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200381#endif
382#ifdef FEAT_ARABIC
383 int prev_c = 0; // previous Arabic character
384 int prev_c1 = 0; // first composing char for prev_c
385#endif
386#if defined(LINE_ATTR)
387 int did_line_attr = 0;
388#endif
389#ifdef FEAT_TERMINAL
390 int get_term_attr = FALSE;
391#endif
392#ifdef FEAT_SYN_HL
393 int cul_attr = 0; // set when 'cursorline' active
394
395 // 'cursorlineopt' has "screenline" and cursor is in this line
396 int cul_screenline = FALSE;
397
398 // margin columns for the screen line, needed for when 'cursorlineopt'
399 // contains "screenline"
400 int left_curline_col = 0;
401 int right_curline_col = 0;
402#endif
403
404 // draw_state: items that are drawn in sequence:
405#define WL_START 0 // nothing done yet
406#ifdef FEAT_CMDWIN
kylo252ae6f1d82022-02-16 19:24:07 +0000407# define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200408#else
409# define WL_CMDLINE WL_START
410#endif
411#ifdef FEAT_FOLDING
kylo252ae6f1d82022-02-16 19:24:07 +0000412# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200413#else
414# define WL_FOLD WL_CMDLINE
415#endif
416#ifdef FEAT_SIGNS
kylo252ae6f1d82022-02-16 19:24:07 +0000417# define WL_SIGN (WL_FOLD + 1) // column for signs
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200418#else
419# define WL_SIGN WL_FOLD // column for signs
420#endif
kylo252ae6f1d82022-02-16 19:24:07 +0000421#define WL_NR (WL_SIGN + 1) // line number
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200422#ifdef FEAT_LINEBREAK
kylo252ae6f1d82022-02-16 19:24:07 +0000423# define WL_BRI (WL_NR + 1) // 'breakindent'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200424#else
425# define WL_BRI WL_NR
426#endif
427#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
kylo252ae6f1d82022-02-16 19:24:07 +0000428# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200429#else
430# define WL_SBR WL_BRI
431#endif
kylo252ae6f1d82022-02-16 19:24:07 +0000432#define WL_LINE (WL_SBR + 1) // text in the line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200433 int draw_state = WL_START; // what to draw next
434#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
435 int feedback_col = 0;
436 int feedback_old_attr = -1;
437#endif
438 int screen_line_flags = 0;
439
440#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
441 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000442 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200443#endif
444#ifdef FEAT_CONCEAL
445 int syntax_flags = 0;
446 int syntax_seqnr = 0;
447 int prev_syntax_id = 0;
448 int conceal_attr = HL_ATTR(HLF_CONCEAL);
449 int is_concealing = FALSE;
450 int boguscols = 0; // nonexistent columns added to force
451 // wrapping
452 int vcol_off = 0; // offset for concealed characters
453 int did_wcol = FALSE;
454 int old_boguscols = 0;
455# define VCOL_HLC (vcol - vcol_off)
456# define FIX_FOR_BOGUSCOLS \
457 { \
458 n_extra += vcol_off; \
459 vcol -= vcol_off; \
460 vcol_off = 0; \
461 col -= boguscols; \
462 old_boguscols = boguscols; \
463 boguscols = 0; \
464 }
465#else
466# define VCOL_HLC (vcol)
467#endif
468
469 if (startrow > endrow) // past the end already!
470 return startrow;
471
472 row = startrow;
473 screen_row = row + W_WINROW(wp);
474
475 if (!number_only)
476 {
477 // To speed up the loop below, set extra_check when there is linebreak,
478 // trailing white space and/or syntax processing to be done.
479#ifdef FEAT_LINEBREAK
480 extra_check = wp->w_p_lbr;
481#endif
482#ifdef FEAT_SYN_HL
483 if (syntax_present(wp) && !wp->w_s->b_syn_error
484# ifdef SYN_TIME_LIMIT
485 && !wp->w_s->b_syn_slow
486# endif
487 )
488 {
489 // Prepare for syntax highlighting in this line. When there is an
490 // error, stop syntax highlighting.
491 save_did_emsg = did_emsg;
492 did_emsg = FALSE;
493 syntax_start(wp, lnum);
494 if (did_emsg)
495 wp->w_s->b_syn_error = TRUE;
496 else
497 {
498 did_emsg = save_did_emsg;
499#ifdef SYN_TIME_LIMIT
500 if (!wp->w_s->b_syn_slow)
501#endif
502 {
503 has_syntax = TRUE;
504 extra_check = TRUE;
505 }
506 }
507 }
508
509 // Check for columns to display for 'colorcolumn'.
510 color_cols = wp->w_p_cc_cols;
511 if (color_cols != NULL)
512 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
513#endif
514
515#ifdef FEAT_TERMINAL
516 if (term_show_buffer(wp->w_buffer))
517 {
518 extra_check = TRUE;
519 get_term_attr = TRUE;
Bram Moolenaar219c7d02020-02-01 21:57:29 +0100520 win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200521 }
522#endif
523
524#ifdef FEAT_SPELL
525 if (wp->w_p_spell
526 && *wp->w_s->b_p_spl != NUL
527 && wp->w_s->b_langp.ga_len > 0
528 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
529 {
530 // Prepare for spell checking.
531 has_spell = TRUE;
532 extra_check = TRUE;
533
534 // Get the start of the next line, so that words that wrap to the
535 // next line are found too: "et<line-break>al.".
536 // Trick: skip a few chars for C/shell/Vim comments
537 nextline[SPWORDLEN] = NUL;
538 if (lnum < wp->w_buffer->b_ml.ml_line_count)
539 {
540 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
541 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
542 }
543
544 // When a word wrapped from the previous line the start of the
545 // current line is valid.
546 if (lnum == checked_lnum)
547 cur_checked_col = checked_col;
548 checked_lnum = 0;
549
550 // When there was a sentence end in the previous line may require a
551 // word starting with capital in this line. In line 1 always check
552 // the first word.
553 if (lnum != capcol_lnum)
554 cap_col = -1;
555 if (lnum == 1)
556 cap_col = 0;
557 capcol_lnum = 0;
558 }
559#endif
560
561 // handle Visual active in this window
562 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
563 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100564 pos_T *top, *bot;
565
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200566 if (LTOREQ_POS(curwin->w_cursor, VIsual))
567 {
568 // Visual is after curwin->w_cursor
569 top = &curwin->w_cursor;
570 bot = &VIsual;
571 }
572 else
573 {
574 // Visual is before curwin->w_cursor
575 top = &VIsual;
576 bot = &curwin->w_cursor;
577 }
578 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
579 if (VIsual_mode == Ctrl_V)
580 {
581 // block mode
582 if (lnum_in_visual_area)
583 {
584 fromcol = wp->w_old_cursor_fcol;
585 tocol = wp->w_old_cursor_lcol;
586 }
587 }
588 else
589 {
590 // non-block mode
591 if (lnum > top->lnum && lnum <= bot->lnum)
592 fromcol = 0;
593 else if (lnum == top->lnum)
594 {
595 if (VIsual_mode == 'V') // linewise
596 fromcol = 0;
597 else
598 {
599 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
600 if (gchar_pos(top) == NUL)
601 tocol = fromcol + 1;
602 }
603 }
604 if (VIsual_mode != 'V' && lnum == bot->lnum)
605 {
606 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
607 {
608 fromcol = -10;
609 tocol = MAXCOL;
610 }
611 else if (bot->col == MAXCOL)
612 tocol = MAXCOL;
613 else
614 {
615 pos = *bot;
616 if (*p_sel == 'e')
617 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
618 else
619 {
620 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
621 ++tocol;
622 }
623 }
624 }
625 }
626
627 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200628 if (!highlight_match && lnum == curwin->w_cursor.lnum
629 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200630#ifdef FEAT_GUI
631 && !gui.in_use
632#endif
633 )
634 noinvcur = TRUE;
635
636 // if inverting in this line set area_highlighting
637 if (fromcol >= 0)
638 {
639 area_highlighting = TRUE;
640 vi_attr = HL_ATTR(HLF_V);
641#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
642 if ((clip_star.available && !clip_star.owned
643 && clip_isautosel_star())
644 || (clip_plus.available && !clip_plus.owned
645 && clip_isautosel_plus()))
646 vi_attr = HL_ATTR(HLF_VNC);
647#endif
648 }
649 }
650
651 // handle 'incsearch' and ":s///c" highlighting
652 else if (highlight_match
653 && wp == curwin
654 && lnum >= curwin->w_cursor.lnum
655 && lnum <= curwin->w_cursor.lnum + search_match_lines)
656 {
657 if (lnum == curwin->w_cursor.lnum)
658 getvcol(curwin, &(curwin->w_cursor),
659 (colnr_T *)&fromcol, NULL, NULL);
660 else
661 fromcol = 0;
662 if (lnum == curwin->w_cursor.lnum + search_match_lines)
663 {
664 pos.lnum = lnum;
665 pos.col = search_match_endcol;
666 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
667 }
668 else
669 tocol = MAXCOL;
670 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100671 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200672 tocol = fromcol + 1;
673 area_highlighting = TRUE;
674 vi_attr = HL_ATTR(HLF_I);
675 }
676 }
677
678#ifdef FEAT_DIFF
679 filler_lines = diff_check(wp, lnum);
680 if (filler_lines < 0)
681 {
682 if (filler_lines == -1)
683 {
684 if (diff_find_change(wp, lnum, &change_start, &change_end))
685 diff_hlf = HLF_ADD; // added line
686 else if (change_start == 0)
687 diff_hlf = HLF_TXD; // changed text
688 else
689 diff_hlf = HLF_CHD; // changed line
690 }
691 else
692 diff_hlf = HLF_ADD; // added line
693 filler_lines = 0;
694 area_highlighting = TRUE;
695 }
696 if (lnum == wp->w_topline)
697 filler_lines = wp->w_topfill;
698 filler_todo = filler_lines;
699#endif
700
701#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +0100702 sign_present = buf_get_signattrs(wp, lnum, &sattr);
James McCoya80aad72021-12-22 19:45:28 +0000703 if (sign_present)
704 num_attr = sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200705#endif
706
707#ifdef LINE_ATTR
708# ifdef FEAT_SIGNS
709 // If this line has a sign with line highlighting set line_attr.
710 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200711 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200712# endif
713# if defined(FEAT_QUICKFIX)
714 // Highlight the current line in the quickfix window.
715 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
716 line_attr = HL_ATTR(HLF_QFL);
717# endif
718 if (line_attr != 0)
719 area_highlighting = TRUE;
720#endif
721
722 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
723 ptr = line;
724
725#ifdef FEAT_SPELL
726 if (has_spell && !number_only)
727 {
728 // For checking first word with a capital skip white space.
729 if (cap_col == 0)
730 cap_col = getwhitecols(line);
731
732 // To be able to spell-check over line boundaries copy the end of the
733 // current line into nextline[]. Above the start of the next line was
734 // copied to nextline[SPWORDLEN].
735 if (nextline[SPWORDLEN] == NUL)
736 {
737 // No next line or it is empty.
738 nextlinecol = MAXCOL;
739 nextline_idx = 0;
740 }
741 else
742 {
743 v = (long)STRLEN(line);
744 if (v < SPWORDLEN)
745 {
746 // Short line, use it completely and append the start of the
747 // next line.
748 nextlinecol = 0;
749 mch_memmove(nextline, line, (size_t)v);
750 STRMOVE(nextline + v, nextline + SPWORDLEN);
751 nextline_idx = v + 1;
752 }
753 else
754 {
755 // Long line, use only the last SPWORDLEN bytes.
756 nextlinecol = v - SPWORDLEN;
757 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
758 nextline_idx = SPWORDLEN + 1;
759 }
760 }
761 }
762#endif
763
764 if (wp->w_p_list)
765 {
Bram Moolenaareed9d462021-02-15 20:38:25 +0100766 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +0200767 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +0100768 || wp->w_lcs_chars.trail
769 || wp->w_lcs_chars.lead
770 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200771 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100772
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200773 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100774 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200775 {
776 trailcol = (colnr_T)STRLEN(ptr);
777 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
778 --trailcol;
779 trailcol += (colnr_T) (ptr - line);
780 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100781 // find end of leading whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100782 if (wp->w_lcs_chars.lead)
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100783 {
784 leadcol = 0;
785 while (VIM_ISWHITE(ptr[leadcol]))
786 ++leadcol;
787 if (ptr[leadcol] == NUL)
788 // in a line full of spaces all of them are treated as trailing
789 leadcol = (colnr_T)0;
790 else
791 // keep track of the first column not filled with spaces
792 leadcol += (colnr_T) (ptr - line) + 1;
793 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200794 }
795
796 wcr_attr = get_wcr_attr(wp);
797 if (wcr_attr != 0)
798 {
799 win_attr = wcr_attr;
800 area_highlighting = TRUE;
801 }
Bram Moolenaar34390282019-10-16 14:38:26 +0200802
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100803#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200804 if (WIN_IS_POPUP(wp))
805 screen_line_flags |= SLF_POPUP;
806#endif
807
808 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
809 // first character to be displayed.
810 if (wp->w_p_wrap)
811 v = wp->w_skipcol;
812 else
813 v = wp->w_leftcol;
814 if (v > 0 && !number_only)
815 {
816 char_u *prev_ptr = ptr;
817
818 while (vcol < v && *ptr != NUL)
819 {
820 c = win_lbr_chartabsize(wp, line, ptr, (colnr_T)vcol, NULL);
821 vcol += c;
822 prev_ptr = ptr;
823 MB_PTR_ADV(ptr);
824 }
825
826 // When:
827 // - 'cuc' is set, or
828 // - 'colorcolumn' is set, or
829 // - 'virtualedit' is set, or
830 // - the visual mode is active,
831 // the end of the line may be before the start of the displayed part.
832 if (vcol < v && (
833#ifdef FEAT_SYN_HL
834 wp->w_p_cuc || draw_color_col ||
835#endif
836 virtual_active() ||
837 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
838 vcol = v;
839
840 // Handle a character that's not completely on the screen: Put ptr at
841 // that character but skip the first few screen characters.
842 if (vcol > v)
843 {
844 vcol -= c;
845 ptr = prev_ptr;
846 // If the character fits on the screen, don't need to skip it.
847 // Except for a TAB.
848 if (( (*mb_ptr2cells)(ptr) >= c || *ptr == TAB) && col == 0)
849 n_skip = v - vcol;
850 }
851
852 // Adjust for when the inverted text is before the screen,
853 // and when the start of the inverted text is before the screen.
854 if (tocol <= vcol)
855 fromcol = 0;
856 else if (fromcol >= 0 && fromcol < vcol)
857 fromcol = vcol;
858
859#ifdef FEAT_LINEBREAK
860 // When w_skipcol is non-zero, first line needs 'showbreak'
861 if (wp->w_p_wrap)
862 need_showbreak = TRUE;
863#endif
864#ifdef FEAT_SPELL
865 // When spell checking a word we need to figure out the start of the
866 // word and if it's badly spelled or not.
867 if (has_spell)
868 {
869 int len;
870 colnr_T linecol = (colnr_T)(ptr - line);
871 hlf_T spell_hlf = HLF_COUNT;
872
873 pos = wp->w_cursor;
874 wp->w_cursor.lnum = lnum;
875 wp->w_cursor.col = linecol;
876 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
877
878 // spell_move_to() may call ml_get() and make "line" invalid
879 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
880 ptr = line + linecol;
881
882 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
883 {
884 // no bad word found at line start, don't check until end of a
885 // word
886 spell_hlf = HLF_COUNT;
887 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
888 }
889 else
890 {
891 // bad word found, use attributes until end of word
892 word_end = wp->w_cursor.col + len + 1;
893
894 // Turn index into actual attributes.
895 if (spell_hlf != HLF_COUNT)
896 spell_attr = highlight_attr[spell_hlf];
897 }
898 wp->w_cursor = pos;
899
900# ifdef FEAT_SYN_HL
901 // Need to restart syntax highlighting for this line.
902 if (has_syntax)
903 syntax_start(wp, lnum);
904# endif
905 }
906#endif
907 }
908
909 // Correct highlighting for cursor that can't be disabled.
910 // Avoids having to check this for each character.
911 if (fromcol >= 0)
912 {
913 if (noinvcur)
914 {
915 if ((colnr_T)fromcol == wp->w_virtcol)
916 {
917 // highlighting starts at cursor, let it start just after the
918 // cursor
919 fromcol_prev = fromcol;
920 fromcol = -1;
921 }
922 else if ((colnr_T)fromcol < wp->w_virtcol)
923 // restart highlighting after the cursor
924 fromcol_prev = wp->w_virtcol;
925 }
926 if (fromcol >= tocol)
927 fromcol = -1;
928 }
929
930#ifdef FEAT_SEARCH_EXTRA
931 if (!number_only)
932 {
933 v = (long)(ptr - line);
934 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
935 &line, &screen_search_hl,
936 &search_attr);
937 ptr = line + v; // "line" may have been updated
938 }
939#endif
940
941#ifdef FEAT_SYN_HL
942 // Cursor line highlighting for 'cursorline' in the current window.
943 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
944 {
945 // Do not show the cursor line in the text when Visual mode is active,
946 // because it's not clear what is selected then. Do update
947 // w_last_cursorline.
948 if (!(wp == curwin && VIsual_active)
949 && wp->w_p_culopt_flags != CULOPT_NBR)
950 {
951 cul_screenline = (wp->w_p_wrap
952 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
953
954 // Only set line_attr here when "screenline" is not present in
955 // 'cursorlineopt'. Otherwise it's done later.
956 if (!cul_screenline)
957 {
958 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +0200959# ifdef FEAT_SIGNS
960 // Combine the 'cursorline' and sign highlighting, depending on
961 // the sign priority.
962 if (sign_present && sattr.sat_linehl > 0)
963 {
964 if (sattr.sat_priority >= 100)
965 line_attr = hl_combine_attr(cul_attr, line_attr);
966 else
967 line_attr = hl_combine_attr(line_attr, cul_attr);
968 }
969 else
970# endif
971 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200972 wp->w_last_cursorline = wp->w_cursor.lnum;
973 }
974 else
975 {
976 line_attr_save = line_attr;
977 wp->w_last_cursorline = 0;
978 margin_columns_win(wp, &left_curline_col, &right_curline_col);
979 }
980 area_highlighting = TRUE;
981 }
982 else
983 wp->w_last_cursorline = wp->w_cursor.lnum;
984 }
985#endif
986
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100987#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200988 {
989 char_u *prop_start;
990
991 text_prop_count = get_text_props(wp->w_buffer, lnum,
992 &prop_start, FALSE);
993 if (text_prop_count > 0)
994 {
995 // Make a copy of the properties, so that they are properly
996 // aligned.
997 text_props = ALLOC_MULT(textprop_T, text_prop_count);
998 if (text_props != NULL)
999 mch_memmove(text_props, prop_start,
1000 text_prop_count * sizeof(textprop_T));
1001
1002 // Allocate an array for the indexes.
1003 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1004 area_highlighting = TRUE;
1005 extra_check = TRUE;
1006 }
1007 }
1008#endif
1009
1010 off = (unsigned)(current_ScreenLine - ScreenLines);
1011 col = 0;
1012
1013#ifdef FEAT_RIGHTLEFT
1014 if (wp->w_p_rl)
1015 {
1016 // Rightleft window: process the text in the normal direction, but put
1017 // it in current_ScreenLine[] from right to left. Start at the
1018 // rightmost column of the window.
1019 col = wp->w_width - 1;
1020 off += col;
1021 screen_line_flags |= SLF_RIGHTLEFT;
1022 }
1023#endif
1024
1025 // Repeat for the whole displayed line.
1026 for (;;)
1027 {
1028#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02001029 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001030#endif
1031#ifdef FEAT_CONCEAL
1032 int did_decrement_ptr = FALSE;
1033#endif
1034 // Skip this quickly when working on the text.
1035 if (draw_state != WL_LINE)
1036 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001037#ifdef FEAT_SYN_HL
1038 if (cul_screenline)
1039 {
1040 cul_attr = 0;
1041 line_attr = line_attr_save;
1042 }
1043#endif
1044
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001045#ifdef FEAT_CMDWIN
1046 if (draw_state == WL_CMDLINE - 1 && n_extra == 0)
1047 {
1048 draw_state = WL_CMDLINE;
1049 if (cmdwin_type != 0 && wp == curwin)
1050 {
1051 // Draw the cmdline character.
1052 n_extra = 1;
1053 c_extra = cmdwin_type;
1054 c_final = NUL;
1055 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
1056 }
1057 }
1058#endif
1059
1060#ifdef FEAT_FOLDING
1061 if (draw_state == WL_FOLD - 1 && n_extra == 0)
1062 {
1063 int fdc = compute_foldcolumn(wp, 0);
1064
1065 draw_state = WL_FOLD;
1066 if (fdc > 0)
1067 {
1068 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1069 // already be in use.
1070 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001071 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001072 if (p_extra_free != NULL)
1073 {
Bram Moolenaar9355ae42021-03-08 19:04:05 +01001074 n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001075 FALSE, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001076 p_extra_free[n_extra] = NUL;
1077 p_extra = p_extra_free;
1078 c_extra = NUL;
1079 c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001080 if (use_cursor_line_sign(wp, lnum))
1081 char_attr =
1082 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1083 else
1084 char_attr =
1085 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001086 }
1087 }
1088 }
1089#endif
1090
1091#ifdef FEAT_SIGNS
1092 if (draw_state == WL_SIGN - 1 && n_extra == 0)
1093 {
1094 draw_state = WL_SIGN;
1095 // Show the sign column when there are any signs in this
1096 // buffer or when using Netbeans.
1097 if (signcolumn_on(wp))
1098 get_sign_display_info(FALSE, wp, lnum, &sattr, wcr_attr,
1099 row, startrow, filler_lines, filler_todo, &c_extra,
1100 &c_final, extra, &p_extra, &n_extra, &char_attr);
1101 }
1102#endif
1103
1104 if (draw_state == WL_NR - 1 && n_extra == 0)
1105 {
1106 draw_state = WL_NR;
1107 // Display the absolute or relative line number. After the
1108 // first fill with blanks when the 'n' flag isn't in 'cpo'
1109 if ((wp->w_p_nu || wp->w_p_rnu)
1110 && (row == startrow
1111#ifdef FEAT_DIFF
1112 + filler_lines
1113#endif
1114 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
1115 {
1116#ifdef FEAT_SIGNS
1117 // If 'signcolumn' is set to 'number' and a sign is present
1118 // in 'lnum', then display the sign instead of the line
1119 // number.
1120 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1121 && sign_present)
1122 get_sign_display_info(TRUE, wp, lnum, &sattr, wcr_attr,
1123 row, startrow, filler_lines, filler_todo,
1124 &c_extra, &c_final, extra, &p_extra, &n_extra,
1125 &char_attr);
1126 else
1127#endif
1128 {
1129 // Draw the line number (empty space after wrapping).
1130 if (row == startrow
1131#ifdef FEAT_DIFF
1132 + filler_lines
1133#endif
1134 )
1135 {
1136 long num;
1137 char *fmt = "%*ld ";
1138
1139 if (wp->w_p_nu && !wp->w_p_rnu)
1140 // 'number' + 'norelativenumber'
1141 num = (long)lnum;
1142 else
1143 {
1144 // 'relativenumber', don't use negative numbers
1145 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1146 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1147 {
1148 // 'number' + 'relativenumber'
1149 num = lnum;
1150 fmt = "%-*ld ";
1151 }
1152 }
1153
1154 sprintf((char *)extra, fmt,
1155 number_width(wp), num);
1156 if (wp->w_skipcol > 0)
1157 for (p_extra = extra; *p_extra == ' '; ++p_extra)
1158 *p_extra = '-';
1159#ifdef FEAT_RIGHTLEFT
1160 if (wp->w_p_rl) // reverse line numbers
1161 {
1162 char_u *p1, *p2;
1163 int t;
1164
1165 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001166 p2 = skipwhite(extra);
1167 p2 = skiptowhite(p2) - 1;
1168 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001169 {
1170 t = *p1;
1171 *p1 = *p2;
1172 *p2 = t;
1173 }
1174 }
1175#endif
1176 p_extra = extra;
1177 c_extra = NUL;
1178 c_final = NUL;
1179 }
1180 else
1181 {
1182 c_extra = ' ';
1183 c_final = NUL;
1184 }
1185 n_extra = number_width(wp) + 1;
1186 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
1187#ifdef FEAT_SYN_HL
1188 // When 'cursorline' is set highlight the line number of
1189 // the current line differently.
1190 // When 'cursorlineopt' has "screenline" only highlight
1191 // the line number itself.
1192 // TODO: Can we use CursorLine instead of CursorLineNr
1193 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001194 if (wp->w_p_cul
1195 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001196 && (wp->w_p_culopt_flags & CULOPT_NBR)
Bram Moolenaar127969c2022-03-06 19:54:13 +00001197 && (row == startrow + filler_lines
1198 || (row > startrow + filler_lines
1199 && wp->w_p_culopt_flags & CULOPT_LINE)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001200 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLN));
1201#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001202 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1203 && HL_ATTR(HLF_LNA) != 0)
1204 // Use LineNrAbove
1205 char_attr = hl_combine_attr(wcr_attr,
1206 HL_ATTR(HLF_LNA));
1207 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1208 && HL_ATTR(HLF_LNB) != 0)
1209 // Use LineNrBelow
1210 char_attr = hl_combine_attr(wcr_attr,
1211 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001212 }
James McCoya80aad72021-12-22 19:45:28 +00001213#ifdef FEAT_SIGNS
1214 if (num_attr)
1215 char_attr = num_attr;
1216#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001217 }
1218 }
1219
1220#ifdef FEAT_LINEBREAK
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001221 if (wp->w_briopt_sbr && draw_state == WL_BRI - 1
Bram Moolenaaree857022019-11-09 23:26:40 +01001222 && n_extra == 0 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001223 // draw indent after showbreak value
1224 draw_state = WL_BRI;
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001225 else if (wp->w_briopt_sbr && draw_state == WL_SBR && n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001226 // After the showbreak, draw the breakindent
1227 draw_state = WL_BRI - 1;
1228
1229 // draw 'breakindent': indent wrapped text accordingly
1230 if (draw_state == WL_BRI - 1 && n_extra == 0)
1231 {
1232 draw_state = WL_BRI;
1233 // if need_showbreak is set, breakindent also applies
1234 if (wp->w_p_bri && n_extra == 0
1235 && (row != startrow || need_showbreak)
1236# ifdef FEAT_DIFF
1237 && filler_lines == 0
1238# endif
1239 )
1240 {
1241 char_attr = 0;
1242# ifdef FEAT_DIFF
1243 if (diff_hlf != (hlf_T)0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001244 char_attr = HL_ATTR(diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001245# endif
1246 p_extra = NULL;
1247 c_extra = ' ';
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001248 c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001249 n_extra = get_breakindent_win(wp,
1250 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001251 if (row == startrow)
1252 {
1253 n_extra -= win_col_off2(wp);
1254 if (n_extra < 0)
1255 n_extra = 0;
1256 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001257 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001258 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001259 // Correct end of highlighted area for 'breakindent',
1260 // required when 'linebreak' is also set.
1261 if (tocol == vcol)
1262 tocol += n_extra;
1263 }
1264 }
1265#endif
1266
1267#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
1268 if (draw_state == WL_SBR - 1 && n_extra == 0)
1269 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001270 char_u *sbr;
1271
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001272 draw_state = WL_SBR;
1273# ifdef FEAT_DIFF
1274 if (filler_todo > 0)
1275 {
1276 // Draw "deleted" diff line(s).
1277 if (char2cells(fill_diff) > 1)
1278 {
1279 c_extra = '-';
1280 c_final = NUL;
1281 }
1282 else
1283 {
1284 c_extra = fill_diff;
1285 c_final = NUL;
1286 }
1287# ifdef FEAT_RIGHTLEFT
1288 if (wp->w_p_rl)
1289 n_extra = col + 1;
1290 else
1291# endif
1292 n_extra = wp->w_width - col;
1293 char_attr = HL_ATTR(HLF_DED);
1294 }
1295# endif
1296# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001297 sbr = get_showbreak_value(wp);
1298 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001299 {
1300 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaaree857022019-11-09 23:26:40 +01001301 p_extra = sbr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001302 c_extra = NUL;
1303 c_final = NUL;
Bram Moolenaaree857022019-11-09 23:26:40 +01001304 n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001305 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1306 need_showbreak = FALSE;
Bram Moolenaaree857022019-11-09 23:26:40 +01001307 vcol_sbr = vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001308 // Correct end of highlighted area for 'showbreak',
1309 // required when 'linebreak' is also set.
1310 if (tocol == vcol)
1311 tocol += n_extra;
1312 // combine 'showbreak' with 'wincolor'
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001313 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001314# ifdef FEAT_SYN_HL
1315 // combine 'showbreak' with 'cursorline'
1316 if (cul_attr != 0)
1317 char_attr = hl_combine_attr(char_attr, cul_attr);
1318# endif
1319 }
1320# endif
1321 }
1322#endif
1323
1324 if (draw_state == WL_LINE - 1 && n_extra == 0)
1325 {
1326 draw_state = WL_LINE;
1327 if (saved_n_extra)
1328 {
1329 // Continue item from end of wrapped line.
1330 n_extra = saved_n_extra;
1331 c_extra = saved_c_extra;
1332 c_final = saved_c_final;
1333 p_extra = saved_p_extra;
1334 char_attr = saved_char_attr;
1335 }
1336 else
1337 char_attr = win_attr;
1338 }
1339 }
1340#ifdef FEAT_SYN_HL
zeertzjq4f33bc22021-08-05 17:57:02 +02001341 if (cul_screenline && draw_state == WL_LINE
1342 && vcol >= left_curline_col
1343 && vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001344 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001345 cul_attr = HL_ATTR(HLF_CUL);
1346 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001347 }
1348#endif
1349
1350 // When still displaying '$' of change command, stop at cursor.
1351 // When only displaying the (relative) line number and that's done,
1352 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001353 if (((dollar_vcol >= 0 && wp == curwin
1354 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol)
1355 || (number_only && draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001356#ifdef FEAT_DIFF
1357 && filler_todo <= 0
1358#endif
1359 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001360 {
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00001361 screen_line(screen_row, wp->w_wincol, col, -wp->w_width,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001362 screen_line_flags);
1363 // Pretend we have finished updating the window. Except when
1364 // 'cursorcolumn' is set.
1365#ifdef FEAT_SYN_HL
1366 if (wp->w_p_cuc)
1367 row = wp->w_cline_row + wp->w_cline_height;
1368 else
1369#endif
1370 row = wp->w_height;
1371 break;
1372 }
1373
Bram Moolenaar34390282019-10-16 14:38:26 +02001374 if (draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001375 {
1376 // handle Visual or match highlighting in this line
1377 if (vcol == fromcol
1378 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0
1379 && (*mb_ptr2cells)(ptr) > 1)
1380 || ((int)vcol_prev == fromcol_prev
1381 && vcol_prev < vcol // not at margin
1382 && vcol < tocol))
1383 area_attr = vi_attr; // start highlighting
1384 else if (area_attr != 0
1385 && (vcol == tocol
1386 || (noinvcur && (colnr_T)vcol == wp->w_virtcol)))
1387 area_attr = 0; // stop highlighting
1388
1389#ifdef FEAT_SEARCH_EXTRA
1390 if (!n_extra)
1391 {
1392 // Check for start/end of 'hlsearch' and other matches.
1393 // After end, check for start/end of next match.
1394 // When another match, have to check for start again.
1395 v = (long)(ptr - line);
1396 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1397 &screen_search_hl, &has_match_conc,
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001398 &match_conc, did_line_attr, lcs_eol_one,
1399 &on_last_col);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001400 ptr = line + v; // "line" may have been changed
Bram Moolenaarfc838d62020-06-25 22:23:48 +02001401
1402 // Do not allow a conceal over EOL otherwise EOL will be missed
1403 // and bad things happen.
1404 if (*ptr == NUL)
1405 has_match_conc = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001406 }
1407#endif
1408
1409#ifdef FEAT_DIFF
1410 if (diff_hlf != (hlf_T)0)
1411 {
1412 if (diff_hlf == HLF_CHD && ptr - line >= change_start
1413 && n_extra == 0)
1414 diff_hlf = HLF_TXD; // changed text
1415 if (diff_hlf == HLF_TXD && ptr - line > change_end
1416 && n_extra == 0)
1417 diff_hlf = HLF_CHD; // changed line
1418 line_attr = HL_ATTR(diff_hlf);
1419 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1420 && wp->w_p_culopt_flags != CULOPT_NBR
1421 && (!cul_screenline || (vcol >= left_curline_col
1422 && vcol <= right_curline_col)))
1423 line_attr = hl_combine_attr(
1424 line_attr, HL_ATTR(HLF_CUL));
1425 }
1426#endif
1427
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001428#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001429 if (text_props != NULL)
1430 {
1431 int pi;
1432 int bcol = (int)(ptr - line);
1433
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001434 if (n_extra > 0
1435# ifdef FEAT_LINEBREAK
1436 && !in_linebreak
1437# endif
1438 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001439 --bcol; // still working on the previous char, e.g. Tab
1440
1441 // Check if any active property ends.
1442 for (pi = 0; pi < text_props_active; ++pi)
1443 {
1444 int tpi = text_prop_idxs[pi];
1445
1446 if (bcol >= text_props[tpi].tp_col - 1
1447 + text_props[tpi].tp_len)
1448 {
1449 if (pi + 1 < text_props_active)
1450 mch_memmove(text_prop_idxs + pi,
1451 text_prop_idxs + pi + 1,
1452 sizeof(int)
1453 * (text_props_active - (pi + 1)));
1454 --text_props_active;
1455 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001456# ifdef FEAT_LINEBREAK
1457 // not exactly right but should work in most cases
1458 if (in_linebreak && syntax_attr == text_prop_attr)
1459 syntax_attr = 0;
1460# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001461 }
1462 }
1463
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001464# ifdef FEAT_LINEBREAK
1465 if (n_extra > 0 && in_linebreak)
1466 // not on the next char yet, don't start another prop
1467 --bcol;
1468# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001469 // Add any text property that starts in this column.
1470 while (text_prop_next < text_prop_count
1471 && bcol >= text_props[text_prop_next].tp_col - 1)
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001472 {
1473 if (bcol <= text_props[text_prop_next].tp_col - 1
1474 + text_props[text_prop_next].tp_len)
1475 text_prop_idxs[text_props_active++] = text_prop_next;
1476 ++text_prop_next;
1477 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001478
1479 text_prop_attr = 0;
1480 text_prop_combine = FALSE;
Bram Moolenaar053f7122019-09-23 22:17:15 +02001481 text_prop_type = NULL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001482 if (text_props_active > 0)
1483 {
1484 // Sort the properties on priority and/or starting last.
1485 // Then combine the attributes, highest priority last.
1486 current_text_props = text_props;
1487 current_buf = wp->w_buffer;
1488 qsort((void *)text_prop_idxs, (size_t)text_props_active,
1489 sizeof(int), text_prop_compare);
1490
1491 for (pi = 0; pi < text_props_active; ++pi)
1492 {
1493 int tpi = text_prop_idxs[pi];
1494 proptype_T *pt = text_prop_type_by_id(
1495 wp->w_buffer, text_props[tpi].tp_type);
1496
1497 if (pt != NULL && pt->pt_hl_id > 0)
1498 {
1499 int pt_attr = syn_id2attr(pt->pt_hl_id);
1500
1501 text_prop_type = pt;
1502 text_prop_attr =
1503 hl_combine_attr(text_prop_attr, pt_attr);
1504 text_prop_combine = pt->pt_flags & PT_FLAG_COMBINE;
1505 }
1506 }
1507 }
1508 }
1509#endif
1510
Bram Moolenaara74fda62019-10-19 17:38:03 +02001511#ifdef FEAT_SYN_HL
Bram Moolenaara74fda62019-10-19 17:38:03 +02001512 if (extra_check && n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001513 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001514 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001515# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001516 if (get_term_attr)
Bram Moolenaar219c7d02020-02-01 21:57:29 +01001517 syntax_attr = term_get_attr(wp, lnum, vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001518# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001519 // Get syntax attribute.
1520 if (has_syntax)
1521 {
1522 // Get the syntax attribute for the character. If there
1523 // is an error, disable syntax highlighting.
1524 save_did_emsg = did_emsg;
1525 did_emsg = FALSE;
1526
1527 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001528 if (v == prev_syntax_col)
1529 // at same column again
1530 syntax_attr = prev_syntax_attr;
1531 else
1532 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001533# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001534 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001535# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001536 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001537# ifdef FEAT_SPELL
1538 has_spell ? &can_spell :
1539# endif
1540 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001541 prev_syntax_col = v;
1542 prev_syntax_attr = syntax_attr;
1543 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001544
Bram Moolenaar34390282019-10-16 14:38:26 +02001545 if (did_emsg)
1546 {
1547 wp->w_s->b_syn_error = TRUE;
1548 has_syntax = FALSE;
1549 syntax_attr = 0;
1550 }
1551 else
1552 did_emsg = save_did_emsg;
1553# ifdef SYN_TIME_LIMIT
1554 if (wp->w_s->b_syn_slow)
1555 has_syntax = FALSE;
1556# endif
1557
1558 // Need to get the line again, a multi-line regexp may
1559 // have made it invalid.
1560 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1561 ptr = line + v;
1562# ifdef FEAT_CONCEAL
1563 // no concealing past the end of the line, it interferes
1564 // with line highlighting
1565 if (*ptr == NUL)
1566 syntax_flags = 0;
1567 else
1568 syntax_flags = get_syntax_info(&syntax_seqnr);
1569# endif
1570 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001571 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001572# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001573 // Combine text property highlight into syntax highlight.
1574 if (text_prop_type != NULL)
1575 {
1576 if (text_prop_combine)
1577 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1578 else
1579 syntax_attr = text_prop_attr;
1580 }
1581# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001582#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001583
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001584 // Decide which of the highlight attributes to use.
1585 attr_pri = TRUE;
1586#ifdef LINE_ATTR
1587 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001588 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001589 char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02001590 if (!highlight_match)
1591 // let search highlight show in Visual area if possible
1592 char_attr = hl_combine_attr(search_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001593# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001594 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001595# endif
1596 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001597 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001598 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001599 char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001600# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001601 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001602# endif
1603 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001604 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
1605 || vcol < fromcol || vcol_prev < fromcol_prev
1606 || vcol >= tocol))
1607 {
1608 // Use line_attr when not in the Visual or 'incsearch' area
1609 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001610# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001611 char_attr = hl_combine_attr(syntax_attr, line_attr);
1612# else
1613 char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001614# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001615 attr_pri = FALSE;
1616 }
1617#else
1618 if (area_attr != 0)
1619 char_attr = area_attr;
1620 else if (search_attr != 0)
1621 char_attr = search_attr;
1622#endif
1623 else
1624 {
1625 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001626#ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001627 char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001628#else
Bram Moolenaardbd43162019-11-09 21:28:14 +01001629 char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001630#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001631 }
1632 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001633
1634 // combine attribute with 'wincolor'
1635 if (win_attr != 0)
1636 {
1637 if (char_attr == 0)
1638 char_attr = win_attr;
1639 else
1640 char_attr = hl_combine_attr(win_attr, char_attr);
1641 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001642
1643 // Get the next character to put on the screen.
1644
1645 // The "p_extra" points to the extra stuff that is inserted to
1646 // represent special characters (non-printable stuff) and other
1647 // things. When all characters are the same, c_extra is used.
1648 // If c_final is set, it will compulsorily be used at the end.
1649 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
1650 // "p_extra[n_extra]".
1651 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
1652 if (n_extra > 0)
1653 {
1654 if (c_extra != NUL || (n_extra == 1 && c_final != NUL))
1655 {
1656 c = (n_extra == 1 && c_final != NUL) ? c_final : c_extra;
1657 mb_c = c; // doesn't handle non-utf-8 multi-byte!
1658 if (enc_utf8 && utf_char2len(c) > 1)
1659 {
1660 mb_utf8 = TRUE;
1661 u8cc[0] = 0;
1662 c = 0xc0;
1663 }
1664 else
1665 mb_utf8 = FALSE;
1666 }
1667 else
1668 {
1669 c = *p_extra;
1670 if (has_mbyte)
1671 {
1672 mb_c = c;
1673 if (enc_utf8)
1674 {
1675 // If the UTF-8 character is more than one byte:
1676 // Decode it into "mb_c".
1677 mb_l = utfc_ptr2len(p_extra);
1678 mb_utf8 = FALSE;
1679 if (mb_l > n_extra)
1680 mb_l = 1;
1681 else if (mb_l > 1)
1682 {
1683 mb_c = utfc_ptr2char(p_extra, u8cc);
1684 mb_utf8 = TRUE;
1685 c = 0xc0;
1686 }
1687 }
1688 else
1689 {
1690 // if this is a DBCS character, put it in "mb_c"
1691 mb_l = MB_BYTE2LEN(c);
1692 if (mb_l >= n_extra)
1693 mb_l = 1;
1694 else if (mb_l > 1)
1695 mb_c = (c << 8) + p_extra[1];
1696 }
1697 if (mb_l == 0) // at the NUL at end-of-line
1698 mb_l = 1;
1699
1700 // If a double-width char doesn't fit display a '>' in the
1701 // last column.
1702 if ((
1703# ifdef FEAT_RIGHTLEFT
1704 wp->w_p_rl ? (col <= 0) :
1705# endif
1706 (col >= wp->w_width - 1))
1707 && (*mb_char2cells)(mb_c) == 2)
1708 {
1709 c = '>';
1710 mb_c = c;
1711 mb_l = 1;
1712 mb_utf8 = FALSE;
1713 multi_attr = HL_ATTR(HLF_AT);
1714#ifdef FEAT_SYN_HL
1715 if (cul_attr)
1716 multi_attr = hl_combine_attr(multi_attr, cul_attr);
1717#endif
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001718 multi_attr = hl_combine_attr(win_attr, multi_attr);
1719
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001720 // put the pointer back to output the double-width
1721 // character at the start of the next line.
1722 ++n_extra;
1723 --p_extra;
1724 }
1725 else
1726 {
1727 n_extra -= mb_l - 1;
1728 p_extra += mb_l - 1;
1729 }
1730 }
1731 ++p_extra;
1732 }
1733 --n_extra;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001734#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001735 if (n_extra <= 0)
1736 in_linebreak = FALSE;
1737#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001738 }
1739 else
1740 {
1741#ifdef FEAT_LINEBREAK
1742 int c0;
1743#endif
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001744 VIM_CLEAR(p_extra_free);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001745
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001746 // Get a character from the line itself.
1747 c = *ptr;
1748#ifdef FEAT_LINEBREAK
1749 c0 = *ptr;
1750#endif
1751 if (has_mbyte)
1752 {
1753 mb_c = c;
1754 if (enc_utf8)
1755 {
1756 // If the UTF-8 character is more than one byte: Decode it
1757 // into "mb_c".
1758 mb_l = utfc_ptr2len(ptr);
1759 mb_utf8 = FALSE;
1760 if (mb_l > 1)
1761 {
1762 mb_c = utfc_ptr2char(ptr, u8cc);
1763 // Overlong encoded ASCII or ASCII with composing char
1764 // is displayed normally, except a NUL.
1765 if (mb_c < 0x80)
1766 {
1767 c = mb_c;
1768#ifdef FEAT_LINEBREAK
1769 c0 = mb_c;
1770#endif
1771 }
1772 mb_utf8 = TRUE;
1773
1774 // At start of the line we can have a composing char.
1775 // Draw it as a space with a composing char.
1776 if (utf_iscomposing(mb_c))
1777 {
1778 int i;
1779
1780 for (i = Screen_mco - 1; i > 0; --i)
1781 u8cc[i] = u8cc[i - 1];
1782 u8cc[0] = mb_c;
1783 mb_c = ' ';
1784 }
1785 }
1786
1787 if ((mb_l == 1 && c >= 0x80)
1788 || (mb_l >= 1 && mb_c == 0)
1789 || (mb_l > 1 && (!vim_isprintc(mb_c))))
1790 {
1791 // Illegal UTF-8 byte: display as <xx>.
1792 // Non-BMP character : display as ? or fullwidth ?.
1793 transchar_hex(extra, mb_c);
1794# ifdef FEAT_RIGHTLEFT
1795 if (wp->w_p_rl) // reverse
1796 rl_mirror(extra);
1797# endif
1798 p_extra = extra;
1799 c = *p_extra;
1800 mb_c = mb_ptr2char_adv(&p_extra);
1801 mb_utf8 = (c >= 0x80);
1802 n_extra = (int)STRLEN(p_extra);
1803 c_extra = NUL;
1804 c_final = NUL;
1805 if (area_attr == 0 && search_attr == 0)
1806 {
1807 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001808 extra_attr = hl_combine_attr(
1809 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001810 saved_attr2 = char_attr; // save current attr
1811 }
1812 }
1813 else if (mb_l == 0) // at the NUL at end-of-line
1814 mb_l = 1;
1815#ifdef FEAT_ARABIC
1816 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
1817 {
1818 // Do Arabic shaping.
1819 int pc, pc1, nc;
1820 int pcc[MAX_MCO];
1821
1822 // The idea of what is the previous and next
1823 // character depends on 'rightleft'.
1824 if (wp->w_p_rl)
1825 {
1826 pc = prev_c;
1827 pc1 = prev_c1;
1828 nc = utf_ptr2char(ptr + mb_l);
1829 prev_c1 = u8cc[0];
1830 }
1831 else
1832 {
1833 pc = utfc_ptr2char(ptr + mb_l, pcc);
1834 nc = prev_c;
1835 pc1 = pcc[0];
1836 }
1837 prev_c = mb_c;
1838
1839 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
1840 }
1841 else
1842 prev_c = mb_c;
1843#endif
1844 }
1845 else // enc_dbcs
1846 {
1847 mb_l = MB_BYTE2LEN(c);
1848 if (mb_l == 0) // at the NUL at end-of-line
1849 mb_l = 1;
1850 else if (mb_l > 1)
1851 {
1852 // We assume a second byte below 32 is illegal.
1853 // Hopefully this is OK for all double-byte encodings!
1854 if (ptr[1] >= 32)
1855 mb_c = (c << 8) + ptr[1];
1856 else
1857 {
1858 if (ptr[1] == NUL)
1859 {
1860 // head byte at end of line
1861 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02001862 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001863 }
1864 else
1865 {
1866 // illegal tail byte
1867 mb_l = 2;
1868 STRCPY(extra, "XX");
1869 }
1870 p_extra = extra;
1871 n_extra = (int)STRLEN(extra) - 1;
1872 c_extra = NUL;
1873 c_final = NUL;
1874 c = *p_extra++;
1875 if (area_attr == 0 && search_attr == 0)
1876 {
1877 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001878 extra_attr = hl_combine_attr(
1879 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001880 saved_attr2 = char_attr; // save current attr
1881 }
1882 mb_c = c;
1883 }
1884 }
1885 }
1886 // If a double-width char doesn't fit display a '>' in the
1887 // last column; the character is displayed at the start of the
1888 // next line.
1889 if ((
1890# ifdef FEAT_RIGHTLEFT
1891 wp->w_p_rl ? (col <= 0) :
1892# endif
1893 (col >= wp->w_width - 1))
1894 && (*mb_char2cells)(mb_c) == 2)
1895 {
1896 c = '>';
1897 mb_c = c;
1898 mb_utf8 = FALSE;
1899 mb_l = 1;
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001900 multi_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001901 // Put pointer back so that the character will be
1902 // displayed at the start of the next line.
1903 --ptr;
1904#ifdef FEAT_CONCEAL
1905 did_decrement_ptr = TRUE;
1906#endif
1907 }
1908 else if (*ptr != NUL)
1909 ptr += mb_l - 1;
1910
1911 // If a double-width char doesn't fit at the left side display
1912 // a '<' in the first column. Don't do this for unprintable
1913 // characters.
1914 if (n_skip > 0 && mb_l > 1 && n_extra == 0)
1915 {
1916 n_extra = 1;
1917 c_extra = MB_FILLER_CHAR;
1918 c_final = NUL;
1919 c = ' ';
1920 if (area_attr == 0 && search_attr == 0)
1921 {
1922 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001923 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001924 saved_attr2 = char_attr; // save current attr
1925 }
1926 mb_c = c;
1927 mb_utf8 = FALSE;
1928 mb_l = 1;
1929 }
1930
1931 }
1932 ++ptr;
1933
1934 if (extra_check)
1935 {
1936#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001937 // Check spelling (unless at the end of the line).
1938 // Only do this when there is no syntax highlighting, the
1939 // @Spell cluster is not used or the current syntax item
1940 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001941 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001942 if (has_spell && v >= word_end && v > cur_checked_col)
1943 {
1944 spell_attr = 0;
1945 if (c != 0 && (
1946# ifdef FEAT_SYN_HL
1947 !has_syntax ||
1948# endif
1949 can_spell))
1950 {
1951 char_u *prev_ptr, *p;
1952 int len;
1953 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01001954
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001955 if (has_mbyte)
1956 {
1957 prev_ptr = ptr - mb_l;
1958 v -= mb_l - 1;
1959 }
1960 else
1961 prev_ptr = ptr - 1;
1962
1963 // Use nextline[] if possible, it has the start of the
1964 // next line concatenated.
1965 if ((prev_ptr - line) - nextlinecol >= 0)
1966 p = nextline + (prev_ptr - line) - nextlinecol;
1967 else
1968 p = prev_ptr;
1969 cap_col -= (int)(prev_ptr - line);
1970 len = spell_check(wp, p, &spell_hlf, &cap_col,
1971 nochange);
1972 word_end = v + len;
1973
1974 // In Insert mode only highlight a word that
1975 // doesn't touch the cursor.
1976 if (spell_hlf != HLF_COUNT
1977 && (State & INSERT) != 0
1978 && wp->w_cursor.lnum == lnum
1979 && wp->w_cursor.col >=
1980 (colnr_T)(prev_ptr - line)
1981 && wp->w_cursor.col < (colnr_T)word_end)
1982 {
1983 spell_hlf = HLF_COUNT;
1984 spell_redraw_lnum = lnum;
1985 }
1986
1987 if (spell_hlf == HLF_COUNT && p != prev_ptr
1988 && (p - nextline) + len > nextline_idx)
1989 {
1990 // Remember that the good word continues at the
1991 // start of the next line.
1992 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001993 checked_col = (int)((p - nextline)
1994 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001995 }
1996
1997 // Turn index into actual attributes.
1998 if (spell_hlf != HLF_COUNT)
1999 spell_attr = highlight_attr[spell_hlf];
2000
2001 if (cap_col > 0)
2002 {
2003 if (p != prev_ptr
2004 && (p - nextline) + cap_col >= nextline_idx)
2005 {
2006 // Remember that the word in the next line
2007 // must start with a capital.
2008 capcol_lnum = lnum + 1;
2009 cap_col = (int)((p - nextline) + cap_col
2010 - nextline_idx);
2011 }
2012 else
2013 // Compute the actual column.
2014 cap_col += (int)(prev_ptr - line);
2015 }
2016 }
2017 }
2018 if (spell_attr != 0)
2019 {
2020 if (!attr_pri)
2021 char_attr = hl_combine_attr(char_attr, spell_attr);
2022 else
2023 char_attr = hl_combine_attr(spell_attr, char_attr);
2024 }
2025#endif
2026#ifdef FEAT_LINEBREAK
2027 // Found last space before word: check for line break.
2028 if (wp->w_p_lbr && c0 == c
2029 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2030 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002031 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2032 : 0;
2033 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002034
2035 // TODO: is passing p for start of the line OK?
2036 n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol,
2037 NULL) - 1;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002038
2039 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002040 // space for it again.
Bram Moolenaara06e3452021-05-29 17:56:37 +02002041 if (vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002042 {
Bram Moolenaara06e3452021-05-29 17:56:37 +02002043 n_extra -= MB_CHARLEN(get_showbreak_value(wp));
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002044 if (n_extra < 0)
2045 n_extra = 0;
2046 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002047 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002048 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002049 // line break, but for TABs the highlighting should
2050 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002051 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002052
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002053 if (c == TAB && n_extra + col > wp->w_width)
2054# ifdef FEAT_VARTABS
2055 n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts,
2056 wp->w_buffer->b_p_vts_array) - 1;
2057# else
2058 n_extra = (int)wp->w_buffer->b_p_ts
2059 - vcol % (int)wp->w_buffer->b_p_ts - 1;
2060# endif
2061
2062 c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2063 c_final = NUL;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002064# if defined(FEAT_PROP_POPUP)
Bram Moolenaar42eba042021-11-30 20:22:49 +00002065 if (n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002066 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002067# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002068 if (VIM_ISWHITE(c))
2069 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002070# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002071 if (c == TAB)
2072 // See "Tab alignment" below.
2073 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002074# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002075 if (!wp->w_p_list)
2076 c = ' ';
2077 }
2078 }
2079#endif
2080
zeertzjqf14b8ba2021-09-10 16:58:30 +02002081 in_multispace = c == ' '
2082 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2083 if (!in_multispace)
2084 multispace_pos = 0;
2085
Bram Moolenaareed9d462021-02-15 20:38:25 +01002086 // 'list': Change char 160 to 'nbsp' and space to 'space'
2087 // setting in 'listchars'. But not when the character is
2088 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002089 if (wp->w_p_list
2090 && ((((c == 160 && mb_l == 1)
2091 || (mb_utf8
2092 && ((mb_c == 160 && mb_l == 2)
2093 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002094 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002095 || (c == ' '
2096 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002097 && (wp->w_lcs_chars.space
2098 || (in_multispace
2099 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002100 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002101 && ptr - line <= trailcol)))
2102 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002103 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2104 {
2105 c = wp->w_lcs_chars.multispace[multispace_pos++];
2106 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2107 multispace_pos = 0;
2108 }
2109 else
2110 c = (c == ' ') ? wp->w_lcs_chars.space
2111 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002112 if (area_attr == 0 && search_attr == 0)
2113 {
2114 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002115 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002116 saved_attr2 = char_attr; // save current attr
2117 }
2118 mb_c = c;
2119 if (enc_utf8 && utf_char2len(c) > 1)
2120 {
2121 mb_utf8 = TRUE;
2122 u8cc[0] = 0;
2123 c = 0xc0;
2124 }
2125 else
2126 mb_utf8 = FALSE;
2127 }
2128
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002129 if ((trailcol != MAXCOL && ptr > line + trailcol && c == ' ')
2130 || (leadcol != 0 && ptr < line + leadcol && c == ' '))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002131 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002132 c = (ptr > line + trailcol) ? wp->w_lcs_chars.trail
2133 : wp->w_lcs_chars.lead;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002134 if (!attr_pri)
2135 {
2136 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002137 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002138 saved_attr2 = char_attr; // save current attr
2139 }
2140 mb_c = c;
2141 if (enc_utf8 && utf_char2len(c) > 1)
2142 {
2143 mb_utf8 = TRUE;
2144 u8cc[0] = 0;
2145 c = 0xc0;
2146 }
2147 else
2148 mb_utf8 = FALSE;
2149 }
2150 }
2151
2152 // Handling of non-printable characters.
2153 if (!vim_isprintc(c))
2154 {
2155 // when getting a character from the file, we may have to
2156 // turn it into something else on the way to putting it
2157 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002158 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002159 {
2160 int tab_len = 0;
2161 long vcol_adjusted = vcol; // removed showbreak length
2162#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002163 char_u *sbr = get_showbreak_value(wp);
2164
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002165 // only adjust the tab_len, when at the first column
2166 // after the showbreak value was drawn
Bram Moolenaaree857022019-11-09 23:26:40 +01002167 if (*sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap)
2168 vcol_adjusted = vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002169#endif
2170 // tab amount depends on current column
2171#ifdef FEAT_VARTABS
2172 tab_len = tabstop_padding(vcol_adjusted,
2173 wp->w_buffer->b_p_ts,
2174 wp->w_buffer->b_p_vts_array) - 1;
2175#else
2176 tab_len = (int)wp->w_buffer->b_p_ts
2177 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2178#endif
2179
2180#ifdef FEAT_LINEBREAK
2181 if (!wp->w_p_lbr || !wp->w_p_list)
2182#endif
2183 // tab amount depends on current column
2184 n_extra = tab_len;
2185#ifdef FEAT_LINEBREAK
2186 else
2187 {
2188 char_u *p;
2189 int len;
2190 int i;
2191 int saved_nextra = n_extra;
2192
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002193# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002194 if (vcol_off > 0)
2195 // there are characters to conceal
2196 tab_len += vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002197
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002198 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002199 if (wp->w_p_list && wp->w_lcs_chars.tab1
2200 && old_boguscols > 0
2201 && n_extra > tab_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002202 tab_len += n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002203# endif
2204 // If n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002205 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002206 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002207 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002208 if (wp->w_lcs_chars.tab3)
2209 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002210 if (n_extra > 0)
2211 len += n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002212 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002213 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002214 if (p == NULL)
2215 n_extra = 0;
2216 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002217 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002218 vim_memset(p, ' ', len);
2219 p[len] = NUL;
2220 vim_free(p_extra_free);
2221 p_extra_free = p;
2222 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002223 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002224 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002225
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002226 if (*p == NUL)
2227 {
2228 tab_len = i;
2229 break;
2230 }
2231
2232 // if tab3 is given, use it for the last char
2233 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2234 lcs = wp->w_lcs_chars.tab3;
2235 p += mb_char2bytes(lcs, p);
2236 n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002237 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002238 }
2239 p_extra = p_extra_free;
2240# ifdef FEAT_CONCEAL
2241 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2242 // macro below, so need to adjust for that here
2243 if (vcol_off > 0)
2244 n_extra -= vcol_off;
2245# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002246 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002247 }
2248#endif
2249#ifdef FEAT_CONCEAL
2250 {
2251 int vc_saved = vcol_off;
2252
2253 // Tab alignment should be identical regardless of
2254 // 'conceallevel' value. So tab compensates of all
2255 // previous concealed characters, and thus resets
2256 // vcol_off and boguscols accumulated so far in the
2257 // line. Note that the tab can be longer than
2258 // 'tabstop' when there are concealed characters.
2259 FIX_FOR_BOGUSCOLS;
2260
2261 // Make sure, the highlighting for the tab char will be
2262 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002263 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002264 if (n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002265 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002266 tab_len += vc_saved;
2267 }
2268#endif
2269 mb_utf8 = FALSE; // don't draw as UTF-8
2270 if (wp->w_p_list)
2271 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002272 c = (n_extra == 0 && wp->w_lcs_chars.tab3)
2273 ? wp->w_lcs_chars.tab3
2274 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002275#ifdef FEAT_LINEBREAK
2276 if (wp->w_p_lbr)
2277 c_extra = NUL; // using p_extra from above
2278 else
2279#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01002280 c_extra = wp->w_lcs_chars.tab2;
2281 c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002282 n_attr = tab_len + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002283 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002284 saved_attr2 = char_attr; // save current attr
2285 mb_c = c;
2286 if (enc_utf8 && utf_char2len(c) > 1)
2287 {
2288 mb_utf8 = TRUE;
2289 u8cc[0] = 0;
2290 c = 0xc0;
2291 }
2292 }
2293 else
2294 {
2295 c_final = NUL;
2296 c_extra = ' ';
2297 c = ' ';
2298 }
2299 }
2300 else if (c == NUL
2301 && (wp->w_p_list
2302 || ((fromcol >= 0 || fromcol_prev >= 0)
2303 && tocol > vcol
2304 && VIsual_mode != Ctrl_V
2305 && (
2306# ifdef FEAT_RIGHTLEFT
2307 wp->w_p_rl ? (col >= 0) :
2308# endif
2309 (col < wp->w_width))
2310 && !(noinvcur
2311 && lnum == wp->w_cursor.lnum
2312 && (colnr_T)vcol == wp->w_virtcol)))
2313 && lcs_eol_one > 0)
2314 {
2315 // Display a '$' after the line or highlight an extra
2316 // character if the line break is included.
2317#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2318 // For a diff line the highlighting continues after the
2319 // "$".
2320 if (
2321# ifdef FEAT_DIFF
2322 diff_hlf == (hlf_T)0
2323# ifdef LINE_ATTR
2324 &&
2325# endif
2326# endif
2327# ifdef LINE_ATTR
2328 line_attr == 0
2329# endif
2330 )
2331#endif
2332 {
2333 // In virtualedit, visual selections may extend
2334 // beyond end of line.
2335 if (area_highlighting && virtual_active()
2336 && tocol != MAXCOL && vcol < tocol)
2337 n_extra = 0;
2338 else
2339 {
2340 p_extra = at_end_str;
2341 n_extra = 1;
2342 c_extra = NUL;
2343 c_final = NUL;
2344 }
2345 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002346 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2347 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002348 else
2349 c = ' ';
2350 lcs_eol_one = -1;
2351 --ptr; // put it back at the NUL
2352 if (!attr_pri)
2353 {
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002354 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002355 n_attr = 1;
2356 }
2357 mb_c = c;
2358 if (enc_utf8 && utf_char2len(c) > 1)
2359 {
2360 mb_utf8 = TRUE;
2361 u8cc[0] = 0;
2362 c = 0xc0;
2363 }
2364 else
2365 mb_utf8 = FALSE; // don't draw as UTF-8
2366 }
2367 else if (c != NUL)
2368 {
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002369 p_extra = transchar_buf(wp->w_buffer, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002370 if (n_extra == 0)
2371 n_extra = byte2cells(c) - 1;
2372#ifdef FEAT_RIGHTLEFT
2373 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
2374 rl_mirror(p_extra); // reverse "<12>"
2375#endif
2376 c_extra = NUL;
2377 c_final = NUL;
2378#ifdef FEAT_LINEBREAK
2379 if (wp->w_p_lbr)
2380 {
2381 char_u *p;
2382
2383 c = *p_extra;
2384 p = alloc(n_extra + 1);
2385 vim_memset(p, ' ', n_extra);
2386 STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1);
2387 p[n_extra] = NUL;
2388 vim_free(p_extra_free);
2389 p_extra_free = p_extra = p;
2390 }
2391 else
2392#endif
2393 {
2394 n_extra = byte2cells(c) - 1;
2395 c = *p_extra++;
2396 }
2397 if (!attr_pri)
2398 {
2399 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002400 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002401 saved_attr2 = char_attr; // save current attr
2402 }
2403 mb_utf8 = FALSE; // don't draw as UTF-8
2404 }
2405 else if (VIsual_active
2406 && (VIsual_mode == Ctrl_V
2407 || VIsual_mode == 'v')
2408 && virtual_active()
2409 && tocol != MAXCOL
2410 && vcol < tocol
2411 && (
2412#ifdef FEAT_RIGHTLEFT
2413 wp->w_p_rl ? (col >= 0) :
2414#endif
2415 (col < wp->w_width)))
2416 {
2417 c = ' ';
2418 --ptr; // put it back at the NUL
2419 }
2420#if defined(LINE_ATTR)
2421 else if ((
2422# ifdef FEAT_DIFF
2423 diff_hlf != (hlf_T)0 ||
2424# endif
2425# ifdef FEAT_TERMINAL
2426 win_attr != 0 ||
2427# endif
2428 line_attr != 0
2429 ) && (
2430# ifdef FEAT_RIGHTLEFT
2431 wp->w_p_rl ? (col >= 0) :
2432# endif
2433 (col
2434# ifdef FEAT_CONCEAL
2435 - boguscols
2436# endif
2437 < wp->w_width)))
2438 {
2439 // Highlight until the right side of the window
2440 c = ' ';
2441 --ptr; // put it back at the NUL
2442
2443 // Remember we do the char for line highlighting.
2444 ++did_line_attr;
2445
2446 // don't do search HL for the rest of the line
2447 if (line_attr != 0 && char_attr == search_attr
2448 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002449 || (wp->w_p_list &&
2450 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002451 char_attr = line_attr;
2452# ifdef FEAT_DIFF
2453 if (diff_hlf == HLF_TXD)
2454 {
2455 diff_hlf = HLF_CHD;
2456 if (vi_attr == 0 || char_attr != vi_attr)
2457 {
2458 char_attr = HL_ATTR(diff_hlf);
2459 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2460 && wp->w_p_culopt_flags != CULOPT_NBR
2461 && (!cul_screenline
2462 || (vcol >= left_curline_col
2463 && vcol <= right_curline_col)))
2464 char_attr = hl_combine_attr(
2465 char_attr, HL_ATTR(HLF_CUL));
2466 }
2467 }
2468# endif
2469# ifdef FEAT_TERMINAL
2470 if (win_attr != 0)
2471 {
2472 char_attr = win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002473 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2474 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002475 {
2476 if (!cul_screenline || (vcol >= left_curline_col
2477 && vcol <= right_curline_col))
2478 char_attr = hl_combine_attr(
2479 char_attr, HL_ATTR(HLF_CUL));
2480 }
2481 else if (line_attr)
2482 char_attr = hl_combine_attr(char_attr, line_attr);
2483 }
2484# endif
2485 }
2486#endif
2487 }
2488
2489#ifdef FEAT_CONCEAL
2490 if ( wp->w_p_cole > 0
2491 && (wp != curwin || lnum != wp->w_cursor.lnum ||
2492 conceal_cursor_line(wp))
2493 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2494 && !(lnum_in_visual_area
2495 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2496 {
2497 char_attr = conceal_attr;
2498 if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002499 && (syn_get_sub_char() != NUL
2500 || (has_match_conc && match_conc)
2501 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002502 && wp->w_p_cole != 3)
2503 {
2504 // First time at this concealed item: display one
2505 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002506 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002507 c = match_conc;
2508 else if (syn_get_sub_char() != NUL)
2509 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01002510 else if (wp->w_lcs_chars.conceal != NUL)
2511 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002512 else
2513 c = ' ';
2514
2515 prev_syntax_id = syntax_seqnr;
2516
2517 if (n_extra > 0)
2518 vcol_off += n_extra;
2519 vcol += n_extra;
2520 if (wp->w_p_wrap && n_extra > 0)
2521 {
2522# ifdef FEAT_RIGHTLEFT
2523 if (wp->w_p_rl)
2524 {
2525 col -= n_extra;
2526 boguscols -= n_extra;
2527 }
2528 else
2529# endif
2530 {
2531 boguscols += n_extra;
2532 col += n_extra;
2533 }
2534 }
2535 n_extra = 0;
2536 n_attr = 0;
2537 }
2538 else if (n_skip == 0)
2539 {
2540 is_concealing = TRUE;
2541 n_skip = 1;
2542 }
2543 mb_c = c;
2544 if (enc_utf8 && utf_char2len(c) > 1)
2545 {
2546 mb_utf8 = TRUE;
2547 u8cc[0] = 0;
2548 c = 0xc0;
2549 }
2550 else
2551 mb_utf8 = FALSE; // don't draw as UTF-8
2552 }
2553 else
2554 {
2555 prev_syntax_id = 0;
2556 is_concealing = FALSE;
2557 }
2558
2559 if (n_skip > 0 && did_decrement_ptr)
2560 // not showing the '>', put pointer back to avoid getting stuck
2561 ++ptr;
2562
2563#endif // FEAT_CONCEAL
2564 }
2565
2566#ifdef FEAT_CONCEAL
2567 // In the cursor line and we may be concealing characters: correct
2568 // the cursor column when we reach its position.
2569 if (!did_wcol && draw_state == WL_LINE
2570 && wp == curwin && lnum == wp->w_cursor.lnum
2571 && conceal_cursor_line(wp)
2572 && (int)wp->w_virtcol <= vcol + n_skip)
2573 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002574# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002575 if (wp->w_p_rl)
2576 wp->w_wcol = wp->w_width - col + boguscols - 1;
2577 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002578# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002579 wp->w_wcol = col - boguscols;
2580 wp->w_wrow = row;
2581 did_wcol = TRUE;
2582 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002583# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01002584 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002585# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002586 }
2587#endif
2588
2589 // Don't override visual selection highlighting.
2590 if (n_attr > 0
2591 && draw_state == WL_LINE
2592 && !attr_pri)
2593 {
2594#ifdef LINE_ATTR
2595 if (line_attr)
2596 char_attr = hl_combine_attr(extra_attr, line_attr);
2597 else
2598#endif
2599 char_attr = extra_attr;
2600 }
2601
2602#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2603 // XIM don't send preedit_start and preedit_end, but they send
2604 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
2605 // im_is_preediting() here.
2606 if (p_imst == IM_ON_THE_SPOT
2607 && xic != NULL
2608 && lnum == wp->w_cursor.lnum
2609 && (State & INSERT)
2610 && !p_imdisable
2611 && im_is_preediting()
2612 && draw_state == WL_LINE)
2613 {
2614 colnr_T tcol;
2615
2616 if (preedit_end_col == MAXCOL)
2617 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
2618 else
2619 tcol = preedit_end_col;
2620 if ((long)preedit_start_col <= vcol && vcol < (long)tcol)
2621 {
2622 if (feedback_old_attr < 0)
2623 {
2624 feedback_col = 0;
2625 feedback_old_attr = char_attr;
2626 }
2627 char_attr = im_get_feedback_attr(feedback_col);
2628 if (char_attr < 0)
2629 char_attr = feedback_old_attr;
2630 feedback_col++;
2631 }
2632 else if (feedback_old_attr >= 0)
2633 {
2634 char_attr = feedback_old_attr;
2635 feedback_old_attr = -1;
2636 feedback_col = 0;
2637 }
2638 }
2639#endif
2640 // Handle the case where we are in column 0 but not on the first
2641 // character of the line and the user wants us to show us a
2642 // special character (via 'listchars' option "precedes:<char>".
2643 if (lcs_prec_todo != NUL
2644 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02002645 && (wp->w_p_wrap ?
2646 (wp->w_skipcol > 0 && row == 0) :
2647 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002648#ifdef FEAT_DIFF
2649 && filler_todo <= 0
2650#endif
2651 && draw_state > WL_NR
2652 && c != NUL)
2653 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002654 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002655 lcs_prec_todo = NUL;
2656 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2657 {
2658 // Double-width character being overwritten by the "precedes"
2659 // character, need to fill up half the character.
2660 c_extra = MB_FILLER_CHAR;
2661 c_final = NUL;
2662 n_extra = 1;
2663 n_attr = 2;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002664 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002665 }
2666 mb_c = c;
2667 if (enc_utf8 && utf_char2len(c) > 1)
2668 {
2669 mb_utf8 = TRUE;
2670 u8cc[0] = 0;
2671 c = 0xc0;
2672 }
2673 else
2674 mb_utf8 = FALSE; // don't draw as UTF-8
2675 if (!attr_pri)
2676 {
2677 saved_attr3 = char_attr; // save current attr
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002678 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002679 n_attr3 = 1;
2680 }
2681 }
2682
2683 // At end of the text line or just after the last character.
2684 if ((c == NUL
2685#if defined(LINE_ATTR)
2686 || did_line_attr == 1
2687#endif
2688 ) && eol_hl_off == 0)
2689 {
2690#ifdef FEAT_SEARCH_EXTRA
2691 // flag to indicate whether prevcol equals startcol of search_hl or
2692 // one of the matches
2693 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
2694 (long)(ptr - line) - (c == NUL));
2695#endif
2696 // Invert at least one char, used for Visual and empty line or
2697 // highlight match at end of line. If it's beyond the last
2698 // char on the screen, just overwrite that one (tricky!) Not
2699 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002700 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002701 && ((area_attr != 0 && vcol == fromcol
2702 && (VIsual_mode != Ctrl_V
2703 || lnum == VIsual.lnum
2704 || lnum == curwin->w_cursor.lnum)
2705 && c == NUL)
2706#ifdef FEAT_SEARCH_EXTRA
2707 // highlight 'hlsearch' match at end of line
2708 || (prevcol_hl_flag
2709# ifdef FEAT_SYN_HL
2710 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
2711 && !(wp == curwin && VIsual_active))
2712# endif
2713# ifdef FEAT_DIFF
2714 && diff_hlf == (hlf_T)0
2715# endif
2716# if defined(LINE_ATTR)
2717 && did_line_attr <= 1
2718# endif
2719 )
2720#endif
2721 ))
2722 {
2723 int n = 0;
2724
2725#ifdef FEAT_RIGHTLEFT
2726 if (wp->w_p_rl)
2727 {
2728 if (col < 0)
2729 n = 1;
2730 }
2731 else
2732#endif
2733 {
2734 if (col >= wp->w_width)
2735 n = -1;
2736 }
2737 if (n != 0)
2738 {
2739 // At the window boundary, highlight the last character
2740 // instead (better than nothing).
2741 off += n;
2742 col += n;
2743 }
2744 else
2745 {
2746 // Add a blank character to highlight.
2747 ScreenLines[off] = ' ';
2748 if (enc_utf8)
2749 ScreenLinesUC[off] = 0;
2750 }
2751#ifdef FEAT_SEARCH_EXTRA
2752 if (area_attr == 0)
2753 {
2754 // Use attributes from match with highest priority among
2755 // 'search_hl' and the match list.
2756 get_search_match_hl(wp, &screen_search_hl,
2757 (long)(ptr - line), &char_attr);
2758 }
2759#endif
2760 ScreenAttrs[off] = char_attr;
2761#ifdef FEAT_RIGHTLEFT
2762 if (wp->w_p_rl)
2763 {
2764 --col;
2765 --off;
2766 }
2767 else
2768#endif
2769 {
2770 ++col;
2771 ++off;
2772 }
2773 ++vcol;
2774 eol_hl_off = 1;
2775 }
2776 }
2777
2778 // At end of the text line.
2779 if (c == NUL)
2780 {
2781#ifdef FEAT_SYN_HL
2782 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
2783 if (wp->w_p_wrap)
2784 v = wp->w_skipcol;
2785 else
2786 v = wp->w_leftcol;
2787
2788 // check if line ends before left margin
2789 if (vcol < v + col - win_col_off(wp))
2790 vcol = v + col - win_col_off(wp);
2791#ifdef FEAT_CONCEAL
2792 // Get rid of the boguscols now, we want to draw until the right
2793 // edge for 'cursorcolumn'.
2794 col -= boguscols;
2795 boguscols = 0;
2796#endif
2797
2798 if (draw_color_col)
2799 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2800
2801 if (((wp->w_p_cuc
2802 && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off
2803 && (int)wp->w_virtcol <
=?UTF-8?q?Dundar=20G=C3=B6c?=d5cec1f2022-01-29 15:19:23 +00002804 (long)wp->w_width * (row - startrow + 1) + v
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002805 && lnum != wp->w_cursor.lnum)
2806 || draw_color_col
2807 || win_attr != 0)
2808# ifdef FEAT_RIGHTLEFT
2809 && !wp->w_p_rl
2810# endif
2811 )
2812 {
2813 int rightmost_vcol = 0;
2814 int i;
2815
2816 if (wp->w_p_cuc)
2817 rightmost_vcol = wp->w_virtcol;
2818 if (draw_color_col)
2819 // determine rightmost colorcolumn to possibly draw
2820 for (i = 0; color_cols[i] >= 0; ++i)
2821 if (rightmost_vcol < color_cols[i])
2822 rightmost_vcol = color_cols[i];
2823
2824 while (col < wp->w_width)
2825 {
2826 ScreenLines[off] = ' ';
2827 if (enc_utf8)
2828 ScreenLinesUC[off] = 0;
2829 ++col;
2830 if (draw_color_col)
2831 draw_color_col = advance_color_col(VCOL_HLC,
2832 &color_cols);
2833
2834 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
2835 ScreenAttrs[off++] = HL_ATTR(HLF_CUC);
2836 else if (draw_color_col && VCOL_HLC == *color_cols)
2837 ScreenAttrs[off++] = HL_ATTR(HLF_MC);
2838 else
2839 ScreenAttrs[off++] = win_attr;
2840
2841 if (VCOL_HLC >= rightmost_vcol && win_attr == 0)
2842 break;
2843
2844 ++vcol;
2845 }
2846 }
2847#endif
2848
2849 screen_line(screen_row, wp->w_wincol, col,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00002850 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002851 row++;
2852
2853 // Update w_cline_height and w_cline_folded if the cursor line was
2854 // updated (saves a call to plines() later).
2855 if (wp == curwin && lnum == curwin->w_cursor.lnum)
2856 {
2857 curwin->w_cline_row = startrow;
2858 curwin->w_cline_height = row - startrow;
2859#ifdef FEAT_FOLDING
2860 curwin->w_cline_folded = FALSE;
2861#endif
2862 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
2863 }
2864
2865 break;
2866 }
2867
2868 // Show "extends" character from 'listchars' if beyond the line end and
2869 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002870 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar41fb7232021-07-08 12:40:05 +02002871 && draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002872 && wp->w_p_list
2873 && !wp->w_p_wrap
2874#ifdef FEAT_DIFF
2875 && filler_todo <= 0
2876#endif
2877 && (
2878#ifdef FEAT_RIGHTLEFT
2879 wp->w_p_rl ? col == 0 :
2880#endif
2881 col == wp->w_width - 1)
2882 && (*ptr != NUL
2883 || (wp->w_p_list && lcs_eol_one > 0)
2884 || (n_extra && (c_extra != NUL || *p_extra != NUL))))
2885 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002886 c = wp->w_lcs_chars.ext;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002887 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002888 mb_c = c;
2889 if (enc_utf8 && utf_char2len(c) > 1)
2890 {
2891 mb_utf8 = TRUE;
2892 u8cc[0] = 0;
2893 c = 0xc0;
2894 }
2895 else
2896 mb_utf8 = FALSE;
2897 }
2898
2899#ifdef FEAT_SYN_HL
2900 // advance to the next 'colorcolumn'
2901 if (draw_color_col)
2902 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2903
2904 // Highlight the cursor column if 'cursorcolumn' is set. But don't
2905 // highlight the cursor position itself.
2906 // Also highlight the 'colorcolumn' if it is different than
2907 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02002908 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
2909 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002910 vcol_save_attr = -1;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002911 if (((draw_state == WL_LINE ||
Bram Moolenaarad5e5632020-09-15 20:52:26 +02002912 draw_state == WL_BRI ||
2913 draw_state == WL_SBR) && !lnum_in_visual_area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002914 && search_attr == 0 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002915# ifdef FEAT_DIFF
2916 && filler_todo <= 0
2917# endif
2918 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002919 {
2920 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
2921 && lnum != wp->w_cursor.lnum)
2922 {
2923 vcol_save_attr = char_attr;
2924 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUC));
2925 }
2926 else if (draw_color_col && VCOL_HLC == *color_cols)
2927 {
2928 vcol_save_attr = char_attr;
2929 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_MC));
2930 }
2931 }
2932#endif
2933
2934 // Store character to be displayed.
2935 // Skip characters that are left of the screen for 'nowrap'.
2936 vcol_prev = vcol;
2937 if (draw_state < WL_LINE || n_skip <= 0)
2938 {
2939 // Store the character.
2940#if defined(FEAT_RIGHTLEFT)
2941 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
2942 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002943 // A double-wide character is: put first half in left cell.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002944 --off;
2945 --col;
2946 }
2947#endif
2948 ScreenLines[off] = c;
2949 if (enc_dbcs == DBCS_JPNU)
2950 {
2951 if ((mb_c & 0xff00) == 0x8e00)
2952 ScreenLines[off] = 0x8e;
2953 ScreenLines2[off] = mb_c & 0xff;
2954 }
2955 else if (enc_utf8)
2956 {
2957 if (mb_utf8)
2958 {
2959 int i;
2960
2961 ScreenLinesUC[off] = mb_c;
2962 if ((c & 0xff) == 0)
2963 ScreenLines[off] = 0x80; // avoid storing zero
2964 for (i = 0; i < Screen_mco; ++i)
2965 {
2966 ScreenLinesC[i][off] = u8cc[i];
2967 if (u8cc[i] == 0)
2968 break;
2969 }
2970 }
2971 else
2972 ScreenLinesUC[off] = 0;
2973 }
2974 if (multi_attr)
2975 {
2976 ScreenAttrs[off] = multi_attr;
2977 multi_attr = 0;
2978 }
2979 else
2980 ScreenAttrs[off] = char_attr;
2981
2982 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2983 {
2984 // Need to fill two screen columns.
2985 ++off;
2986 ++col;
2987 if (enc_utf8)
2988 // UTF-8: Put a 0 in the second screen char.
2989 ScreenLines[off] = 0;
2990 else
2991 // DBCS: Put second byte in the second screen char.
2992 ScreenLines[off] = mb_c & 0xff;
2993 if (draw_state > WL_NR
2994#ifdef FEAT_DIFF
2995 && filler_todo <= 0
2996#endif
2997 )
2998 ++vcol;
2999 // When "tocol" is halfway a character, set it to the end of
3000 // the character, otherwise highlighting won't stop.
3001 if (tocol == vcol)
3002 ++tocol;
3003#ifdef FEAT_RIGHTLEFT
3004 if (wp->w_p_rl)
3005 {
3006 // now it's time to backup one cell
3007 --off;
3008 --col;
3009 }
3010#endif
3011 }
3012#ifdef FEAT_RIGHTLEFT
3013 if (wp->w_p_rl)
3014 {
3015 --off;
3016 --col;
3017 }
3018 else
3019#endif
3020 {
3021 ++off;
3022 ++col;
3023 }
3024 }
3025#ifdef FEAT_CONCEAL
3026 else if (wp->w_p_cole > 0 && is_concealing)
3027 {
3028 --n_skip;
3029 ++vcol_off;
3030 if (n_extra > 0)
3031 vcol_off += n_extra;
3032 if (wp->w_p_wrap)
3033 {
3034 // Special voodoo required if 'wrap' is on.
3035 //
3036 // Advance the column indicator to force the line
3037 // drawing to wrap early. This will make the line
3038 // take up the same screen space when parts are concealed,
3039 // so that cursor line computations aren't messed up.
3040 //
3041 // To avoid the fictitious advance of 'col' causing
3042 // trailing junk to be written out of the screen line
3043 // we are building, 'boguscols' keeps track of the number
3044 // of bad columns we have advanced.
3045 if (n_extra > 0)
3046 {
3047 vcol += n_extra;
3048# ifdef FEAT_RIGHTLEFT
3049 if (wp->w_p_rl)
3050 {
3051 col -= n_extra;
3052 boguscols -= n_extra;
3053 }
3054 else
3055# endif
3056 {
3057 col += n_extra;
3058 boguscols += n_extra;
3059 }
3060 n_extra = 0;
3061 n_attr = 0;
3062 }
3063
3064
3065 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3066 {
3067 // Need to fill two screen columns.
3068# ifdef FEAT_RIGHTLEFT
3069 if (wp->w_p_rl)
3070 {
3071 --boguscols;
3072 --col;
3073 }
3074 else
3075# endif
3076 {
3077 ++boguscols;
3078 ++col;
3079 }
3080 }
3081
3082# ifdef FEAT_RIGHTLEFT
3083 if (wp->w_p_rl)
3084 {
3085 --boguscols;
3086 --col;
3087 }
3088 else
3089# endif
3090 {
3091 ++boguscols;
3092 ++col;
3093 }
3094 }
3095 else
3096 {
3097 if (n_extra > 0)
3098 {
3099 vcol += n_extra;
3100 n_extra = 0;
3101 n_attr = 0;
3102 }
3103 }
3104
3105 }
3106#endif // FEAT_CONCEAL
3107 else
3108 --n_skip;
3109
3110 // Only advance the "vcol" when after the 'number' or 'relativenumber'
3111 // column.
3112 if (draw_state > WL_NR
3113#ifdef FEAT_DIFF
3114 && filler_todo <= 0
3115#endif
3116 )
3117 ++vcol;
3118
3119#ifdef FEAT_SYN_HL
3120 if (vcol_save_attr >= 0)
3121 char_attr = vcol_save_attr;
3122#endif
3123
3124 // restore attributes after "predeces" in 'listchars'
3125 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3126 char_attr = saved_attr3;
3127
3128 // restore attributes after last 'listchars' or 'number' char
3129 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0)
3130 char_attr = saved_attr2;
3131
3132 // At end of screen line and there is more to come: Display the line
3133 // so far. If there is no more to display it is caught above.
3134 if ((
3135#ifdef FEAT_RIGHTLEFT
3136 wp->w_p_rl ? (col < 0) :
3137#endif
3138 (col >= wp->w_width))
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003139 && (draw_state != WL_LINE
3140 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003141#ifdef FEAT_DIFF
3142 || filler_todo > 0
3143#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003144 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
3145 && p_extra != at_end_str)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003146 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL)))
3147 )
3148 {
3149#ifdef FEAT_CONCEAL
3150 screen_line(screen_row, wp->w_wincol, col - boguscols,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00003151 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003152 boguscols = 0;
3153#else
3154 screen_line(screen_row, wp->w_wincol, col,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00003155 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003156#endif
3157 ++row;
3158 ++screen_row;
3159
3160 // When not wrapping and finished diff lines, or when displayed
3161 // '$' and highlighting until last column, break here.
3162 if ((!wp->w_p_wrap
3163#ifdef FEAT_DIFF
3164 && filler_todo <= 0
3165#endif
3166 ) || lcs_eol_one == -1)
3167 break;
3168
3169 // When the window is too narrow draw all "@" lines.
3170 if (draw_state != WL_LINE
3171#ifdef FEAT_DIFF
3172 && filler_todo <= 0
3173#endif
3174 )
3175 {
3176 win_draw_end(wp, '@', ' ', TRUE, row, wp->w_height, HLF_AT);
3177 draw_vsep_win(wp, row);
3178 row = endrow;
3179 }
3180
3181 // When line got too long for screen break here.
3182 if (row == endrow)
3183 {
3184 ++row;
3185 break;
3186 }
3187
3188 if (screen_cur_row == screen_row - 1
3189#ifdef FEAT_DIFF
3190 && filler_todo <= 0
3191#endif
3192 && wp->w_width == Columns)
3193 {
3194 // Remember that the line wraps, used for modeless copy.
3195 LineWraps[screen_row - 1] = TRUE;
3196
3197 // Special trick to make copy/paste of wrapped lines work with
3198 // xterm/screen: write an extra character beyond the end of
3199 // the line. This will work with all terminal types
3200 // (regardless of the xn,am settings).
3201 // Only do this on a fast tty.
3202 // Only do this if the cursor is on the current line
3203 // (something has been written in it).
3204 // Don't do this for the GUI.
3205 // Don't do this for double-width characters.
3206 // Don't do this for a window not at the right screen border.
3207 if (p_tf
3208#ifdef FEAT_GUI
3209 && !gui.in_use
3210#endif
3211 && !(has_mbyte
3212 && ((*mb_off2cells)(LineOffset[screen_row],
3213 LineOffset[screen_row] + screen_Columns)
3214 == 2
3215 || (*mb_off2cells)(LineOffset[screen_row - 1]
3216 + (int)Columns - 2,
3217 LineOffset[screen_row] + screen_Columns)
3218 == 2)))
3219 {
3220 // First make sure we are at the end of the screen line,
3221 // then output the same character again to let the
3222 // terminal know about the wrap. If the terminal doesn't
3223 // auto-wrap, we overwrite the character.
3224 if (screen_cur_col != wp->w_width)
3225 screen_char(LineOffset[screen_row - 1]
3226 + (unsigned)Columns - 1,
3227 screen_row - 1, (int)(Columns - 1));
3228
3229 // When there is a multi-byte character, just output a
3230 // space to keep it simple.
3231 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
3232 screen_row - 1] + (Columns - 1)]) > 1)
3233 out_char(' ');
3234 else
3235 out_char(ScreenLines[LineOffset[screen_row - 1]
3236 + (Columns - 1)]);
3237 // force a redraw of the first char on the next line
3238 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1;
3239 screen_start(); // don't know where cursor is now
3240 }
3241 }
3242
3243 col = 0;
3244 off = (unsigned)(current_ScreenLine - ScreenLines);
3245#ifdef FEAT_RIGHTLEFT
3246 if (wp->w_p_rl)
3247 {
3248 col = wp->w_width - 1; // col is not used if breaking!
3249 off += col;
3250 }
3251#endif
3252
3253 // reset the drawing state for the start of a wrapped line
3254 draw_state = WL_START;
3255 saved_n_extra = n_extra;
3256 saved_p_extra = p_extra;
3257 saved_c_extra = c_extra;
3258 saved_c_final = c_final;
3259#ifdef FEAT_SYN_HL
3260 if (!(cul_screenline
3261# ifdef FEAT_DIFF
Bram Moolenaare7705982020-04-21 22:23:15 +02003262 && diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003263# endif
Bram Moolenaare7705982020-04-21 22:23:15 +02003264 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003265 saved_char_attr = char_attr;
3266 else
3267#endif
3268 saved_char_attr = 0;
3269 n_extra = 0;
Bram Moolenaareed9d462021-02-15 20:38:25 +01003270 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003271#ifdef FEAT_LINEBREAK
3272# ifdef FEAT_DIFF
3273 if (filler_todo <= 0)
3274# endif
3275 need_showbreak = TRUE;
3276#endif
3277#ifdef FEAT_DIFF
3278 --filler_todo;
3279 // When the filler lines are actually below the last line of the
3280 // file, don't draw the line itself, break here.
3281 if (filler_todo == 0 && wp->w_botfill)
3282 break;
3283#endif
3284 }
3285
3286 } // for every character in the line
3287
3288#ifdef FEAT_SPELL
3289 // After an empty line check first word for capital.
3290 if (*skipwhite(line) == NUL)
3291 {
3292 capcol_lnum = lnum + 1;
3293 cap_col = 0;
3294 }
3295#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003296#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003297 vim_free(text_props);
3298 vim_free(text_prop_idxs);
3299#endif
3300
3301 vim_free(p_extra_free);
3302 return row;
3303}