blob: 9e03b38a725a393f9af4fab49fc719c3ead748c4 [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;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100211 textprop_T *tp1, *tp2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200212 proptype_T *pt1, *pt2;
213 colnr_T col1, col2;
214
215 idx1 = *(int *)s1;
216 idx2 = *(int *)s2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100217 tp1 = &current_text_props[idx1];
218 tp2 = &current_text_props[idx2];
219 pt1 = text_prop_type_by_id(current_buf, tp1->tp_type);
220 pt2 = text_prop_type_by_id(current_buf, tp2->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200221 if (pt1 == pt2)
222 return 0;
223 if (pt1 == NULL)
224 return -1;
225 if (pt2 == NULL)
226 return 1;
227 if (pt1->pt_priority != pt2->pt_priority)
228 return pt1->pt_priority > pt2->pt_priority ? 1 : -1;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100229 col1 = tp1->tp_col;
230 col2 = tp2->tp_col;
231 if (col1 == MAXCOL && col2 == MAXCOL)
232 {
233 int flags1 = 0;
234 int flags2 = 0;
235
236 // order on 0: after, 1: right, 2: below
237 if (tp1->tp_flags & TP_FLAG_ALIGN_RIGHT)
238 flags1 = 1;
239 if (tp1->tp_flags & TP_FLAG_ALIGN_BELOW)
240 flags1 = 2;
241 if (tp2->tp_flags & TP_FLAG_ALIGN_RIGHT)
242 flags2 = 1;
243 if (tp2->tp_flags & TP_FLAG_ALIGN_BELOW)
244 flags2 = 2;
245 if (flags1 != flags2)
246 return flags1 < flags2 ? 1 : -1;
247 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200248 return col1 == col2 ? 0 : col1 > col2 ? 1 : -1;
249}
250#endif
251
252/*
253 * Display line "lnum" of window 'wp' on the screen.
254 * Start at row "startrow", stop when "endrow" is reached.
255 * wp->w_virtcol needs to be valid.
256 *
257 * Return the number of last row the line occupies.
258 */
259 int
260win_line(
261 win_T *wp,
262 linenr_T lnum,
263 int startrow,
264 int endrow,
265 int nochange UNUSED, // not updating for changed text
266 int number_only) // only update the number column
267{
268 int col = 0; // visual column on screen
269 unsigned off; // offset in ScreenLines/ScreenAttrs
270 int c = 0; // init for GCC
271 long vcol = 0; // virtual column (for tabs)
272#ifdef FEAT_LINEBREAK
273 long vcol_sbr = -1; // virtual column after showbreak
274#endif
275 long vcol_prev = -1; // "vcol" of previous character
276 char_u *line; // current line
277 char_u *ptr; // current position in "line"
278 int row; // row in the window, excl w_winrow
279 int screen_row; // row on the screen, incl w_winrow
280
281 char_u extra[21]; // "%ld " and 'fdc' must fit in here
Bram Moolenaar09ff4b52022-08-01 16:51:02 +0100282 int n_extra = 0; // number of extra bytes
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200283 char_u *p_extra = NULL; // string of extra chars, plus NUL
284 char_u *p_extra_free = NULL; // p_extra needs to be freed
285 int c_extra = NUL; // extra chars, all the same
286 int c_final = NUL; // final char, mandatory if set
287 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000288#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000289 int in_linebreak = FALSE; // n_extra set for showing linebreak
290#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200291 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100292 // displaying eol at end-of-line
293 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000294 int lcs_prec_todo = wp->w_lcs_chars.prec;
295 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200296
297 // saved "extra" items for when draw_state becomes WL_LINE (again)
298 int saved_n_extra = 0;
299 char_u *saved_p_extra = NULL;
300 int saved_c_extra = 0;
301 int saved_c_final = 0;
302 int saved_char_attr = 0;
303
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100304 int n_attr = 0; // chars with special attr
305 int n_attr_skip = 0; // chars to skip before using extra_attr
306 int saved_attr2 = 0; // char_attr saved for n_attr
307 int n_attr3 = 0; // chars with overruling special attr
308 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200309
310 int n_skip = 0; // nr of chars to skip for 'nowrap'
311
312 int fromcol = -10; // start of inverting
313 int tocol = MAXCOL; // end of inverting
314 int fromcol_prev = -2; // start of inverting after cursor
315 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200316 int lnum_in_visual_area = FALSE;
317 pos_T pos;
318 long v;
319
320 int char_attr = 0; // attributes for next character
321 int attr_pri = FALSE; // char_attr has priority
322 int area_highlighting = FALSE; // Visual or incsearch highlighting
323 // in this line
324 int vi_attr = 0; // attributes for Visual and incsearch
325 // highlighting
326 int wcr_attr = 0; // attributes from 'wincolor'
327 int win_attr = 0; // background for whole window, except
328 // margins and "~" lines.
329 int area_attr = 0; // attributes desired by highlighting
330 int search_attr = 0; // attributes desired by 'hlsearch'
331#ifdef FEAT_SYN_HL
332 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
333 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200334 int prev_syntax_col = -1; // column of prev_syntax_attr
335 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200336 int has_syntax = FALSE; // this buffer has syntax highl.
337 int save_did_emsg;
338 int draw_color_col = FALSE; // highlight colorcolumn
339 int *color_cols = NULL; // pointer to according columns array
340#endif
341 int eol_hl_off = 0; // 1 if highlighted char after EOL
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100342#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200343 int text_prop_count;
344 int text_prop_next = 0; // next text property to use
345 textprop_T *text_props = NULL;
346 int *text_prop_idxs = NULL;
347 int text_props_active = 0;
348 proptype_T *text_prop_type = NULL;
349 int text_prop_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100350 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100351 int text_prop_flags = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100352 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200353#endif
354#ifdef FEAT_SPELL
355 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000356 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200357# define SPWORDLEN 150
358 char_u nextline[SPWORDLEN * 2];// text with start of the next line
359 int nextlinecol = 0; // column where nextline[] starts
360 int nextline_idx = 0; // index in nextline[] where next line
361 // starts
362 int spell_attr = 0; // attributes desired by spelling
363 int word_end = 0; // last byte with same spell_attr
364 static linenr_T checked_lnum = 0; // line number for "checked_col"
365 static int checked_col = 0; // column in "checked_lnum" up to which
366 // there are no spell errors
367 static int cap_col = -1; // column to check for Cap word
368 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
369 int cur_checked_col = 0; // checked column for current line
370#endif
371 int extra_check = 0; // has extra highlighting
372 int multi_attr = 0; // attributes desired by multibyte
373 int mb_l = 1; // multi-byte byte length
374 int mb_c = 0; // decoded multi-byte character
375 int mb_utf8 = FALSE; // screen char is UTF-8 char
376 int u8cc[MAX_MCO]; // composing UTF-8 chars
377#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
378 int filler_lines = 0; // nr of filler lines to be drawn
379 int filler_todo = 0; // nr of filler lines still to do + 1
Bram Moolenaar936dc602022-03-06 20:47:01 +0000380#else
381# define filler_lines 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200382#endif
383#ifdef FEAT_DIFF
384 hlf_T diff_hlf = (hlf_T)0; // type of diff highlighting
385 int change_start = MAXCOL; // first col of changed area
386 int change_end = -1; // last col of changed area
387#endif
388 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100389 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200390 int in_multispace = FALSE; // in multiple consecutive spaces
391 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200392#ifdef FEAT_LINEBREAK
393 int need_showbreak = FALSE; // overlong line, skipping first x
394 // chars
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +0100395 int dont_use_showbreak = FALSE; // do not use 'showbreak'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200396#endif
397#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
398 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
399# define LINE_ATTR
400 int line_attr = 0; // attribute for the whole line
401 int line_attr_save;
402#endif
403#ifdef FEAT_SIGNS
404 int sign_present = FALSE;
405 sign_attrs_T sattr;
James McCoya80aad72021-12-22 19:45:28 +0000406 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200407#endif
408#ifdef FEAT_ARABIC
409 int prev_c = 0; // previous Arabic character
410 int prev_c1 = 0; // first composing char for prev_c
411#endif
412#if defined(LINE_ATTR)
413 int did_line_attr = 0;
414#endif
415#ifdef FEAT_TERMINAL
416 int get_term_attr = FALSE;
417#endif
418#ifdef FEAT_SYN_HL
419 int cul_attr = 0; // set when 'cursorline' active
420
421 // 'cursorlineopt' has "screenline" and cursor is in this line
422 int cul_screenline = FALSE;
423
424 // margin columns for the screen line, needed for when 'cursorlineopt'
425 // contains "screenline"
426 int left_curline_col = 0;
427 int right_curline_col = 0;
428#endif
429
430 // draw_state: items that are drawn in sequence:
431#define WL_START 0 // nothing done yet
432#ifdef FEAT_CMDWIN
kylo252ae6f1d82022-02-16 19:24:07 +0000433# define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200434#else
435# define WL_CMDLINE WL_START
436#endif
437#ifdef FEAT_FOLDING
kylo252ae6f1d82022-02-16 19:24:07 +0000438# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200439#else
440# define WL_FOLD WL_CMDLINE
441#endif
442#ifdef FEAT_SIGNS
kylo252ae6f1d82022-02-16 19:24:07 +0000443# define WL_SIGN (WL_FOLD + 1) // column for signs
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200444#else
445# define WL_SIGN WL_FOLD // column for signs
446#endif
kylo252ae6f1d82022-02-16 19:24:07 +0000447#define WL_NR (WL_SIGN + 1) // line number
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200448#ifdef FEAT_LINEBREAK
kylo252ae6f1d82022-02-16 19:24:07 +0000449# define WL_BRI (WL_NR + 1) // 'breakindent'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200450#else
451# define WL_BRI WL_NR
452#endif
453#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
kylo252ae6f1d82022-02-16 19:24:07 +0000454# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200455#else
456# define WL_SBR WL_BRI
457#endif
kylo252ae6f1d82022-02-16 19:24:07 +0000458#define WL_LINE (WL_SBR + 1) // text in the line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200459 int draw_state = WL_START; // what to draw next
460#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
461 int feedback_col = 0;
462 int feedback_old_attr = -1;
463#endif
464 int screen_line_flags = 0;
465
466#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
467 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000468 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200469#endif
470#ifdef FEAT_CONCEAL
471 int syntax_flags = 0;
472 int syntax_seqnr = 0;
473 int prev_syntax_id = 0;
474 int conceal_attr = HL_ATTR(HLF_CONCEAL);
475 int is_concealing = FALSE;
476 int boguscols = 0; // nonexistent columns added to force
477 // wrapping
478 int vcol_off = 0; // offset for concealed characters
479 int did_wcol = FALSE;
480 int old_boguscols = 0;
481# define VCOL_HLC (vcol - vcol_off)
482# define FIX_FOR_BOGUSCOLS \
483 { \
484 n_extra += vcol_off; \
485 vcol -= vcol_off; \
486 vcol_off = 0; \
487 col -= boguscols; \
488 old_boguscols = boguscols; \
489 boguscols = 0; \
490 }
491#else
492# define VCOL_HLC (vcol)
493#endif
494
495 if (startrow > endrow) // past the end already!
496 return startrow;
497
498 row = startrow;
499 screen_row = row + W_WINROW(wp);
500
501 if (!number_only)
502 {
503 // To speed up the loop below, set extra_check when there is linebreak,
504 // trailing white space and/or syntax processing to be done.
505#ifdef FEAT_LINEBREAK
506 extra_check = wp->w_p_lbr;
507#endif
508#ifdef FEAT_SYN_HL
509 if (syntax_present(wp) && !wp->w_s->b_syn_error
510# ifdef SYN_TIME_LIMIT
511 && !wp->w_s->b_syn_slow
512# endif
513 )
514 {
515 // Prepare for syntax highlighting in this line. When there is an
516 // error, stop syntax highlighting.
517 save_did_emsg = did_emsg;
518 did_emsg = FALSE;
519 syntax_start(wp, lnum);
520 if (did_emsg)
521 wp->w_s->b_syn_error = TRUE;
522 else
523 {
524 did_emsg = save_did_emsg;
525#ifdef SYN_TIME_LIMIT
526 if (!wp->w_s->b_syn_slow)
527#endif
528 {
529 has_syntax = TRUE;
530 extra_check = TRUE;
531 }
532 }
533 }
534
535 // Check for columns to display for 'colorcolumn'.
536 color_cols = wp->w_p_cc_cols;
537 if (color_cols != NULL)
538 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
539#endif
540
541#ifdef FEAT_TERMINAL
542 if (term_show_buffer(wp->w_buffer))
543 {
544 extra_check = TRUE;
545 get_term_attr = TRUE;
Bram Moolenaar219c7d02020-02-01 21:57:29 +0100546 win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200547 }
548#endif
549
550#ifdef FEAT_SPELL
551 if (wp->w_p_spell
552 && *wp->w_s->b_p_spl != NUL
553 && wp->w_s->b_langp.ga_len > 0
554 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
555 {
556 // Prepare for spell checking.
557 has_spell = TRUE;
558 extra_check = TRUE;
559
560 // Get the start of the next line, so that words that wrap to the
561 // next line are found too: "et<line-break>al.".
562 // Trick: skip a few chars for C/shell/Vim comments
563 nextline[SPWORDLEN] = NUL;
564 if (lnum < wp->w_buffer->b_ml.ml_line_count)
565 {
566 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
567 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
568 }
569
570 // When a word wrapped from the previous line the start of the
571 // current line is valid.
572 if (lnum == checked_lnum)
573 cur_checked_col = checked_col;
574 checked_lnum = 0;
575
576 // When there was a sentence end in the previous line may require a
577 // word starting with capital in this line. In line 1 always check
578 // the first word.
579 if (lnum != capcol_lnum)
580 cap_col = -1;
581 if (lnum == 1)
582 cap_col = 0;
583 capcol_lnum = 0;
584 }
585#endif
586
587 // handle Visual active in this window
588 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
589 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100590 pos_T *top, *bot;
591
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200592 if (LTOREQ_POS(curwin->w_cursor, VIsual))
593 {
594 // Visual is after curwin->w_cursor
595 top = &curwin->w_cursor;
596 bot = &VIsual;
597 }
598 else
599 {
600 // Visual is before curwin->w_cursor
601 top = &VIsual;
602 bot = &curwin->w_cursor;
603 }
604 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
605 if (VIsual_mode == Ctrl_V)
606 {
607 // block mode
608 if (lnum_in_visual_area)
609 {
610 fromcol = wp->w_old_cursor_fcol;
611 tocol = wp->w_old_cursor_lcol;
612 }
613 }
614 else
615 {
616 // non-block mode
617 if (lnum > top->lnum && lnum <= bot->lnum)
618 fromcol = 0;
619 else if (lnum == top->lnum)
620 {
621 if (VIsual_mode == 'V') // linewise
622 fromcol = 0;
623 else
624 {
625 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
626 if (gchar_pos(top) == NUL)
627 tocol = fromcol + 1;
628 }
629 }
630 if (VIsual_mode != 'V' && lnum == bot->lnum)
631 {
632 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
633 {
634 fromcol = -10;
635 tocol = MAXCOL;
636 }
637 else if (bot->col == MAXCOL)
638 tocol = MAXCOL;
639 else
640 {
641 pos = *bot;
642 if (*p_sel == 'e')
643 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
644 else
645 {
646 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
647 ++tocol;
648 }
649 }
650 }
651 }
652
653 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200654 if (!highlight_match && lnum == curwin->w_cursor.lnum
655 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200656#ifdef FEAT_GUI
657 && !gui.in_use
658#endif
659 )
660 noinvcur = TRUE;
661
662 // if inverting in this line set area_highlighting
663 if (fromcol >= 0)
664 {
665 area_highlighting = TRUE;
666 vi_attr = HL_ATTR(HLF_V);
667#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
668 if ((clip_star.available && !clip_star.owned
669 && clip_isautosel_star())
670 || (clip_plus.available && !clip_plus.owned
671 && clip_isautosel_plus()))
672 vi_attr = HL_ATTR(HLF_VNC);
673#endif
674 }
675 }
676
677 // handle 'incsearch' and ":s///c" highlighting
678 else if (highlight_match
679 && wp == curwin
680 && lnum >= curwin->w_cursor.lnum
681 && lnum <= curwin->w_cursor.lnum + search_match_lines)
682 {
683 if (lnum == curwin->w_cursor.lnum)
684 getvcol(curwin, &(curwin->w_cursor),
685 (colnr_T *)&fromcol, NULL, NULL);
686 else
687 fromcol = 0;
688 if (lnum == curwin->w_cursor.lnum + search_match_lines)
689 {
690 pos.lnum = lnum;
691 pos.col = search_match_endcol;
692 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
693 }
694 else
695 tocol = MAXCOL;
696 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100697 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200698 tocol = fromcol + 1;
699 area_highlighting = TRUE;
700 vi_attr = HL_ATTR(HLF_I);
701 }
702 }
703
704#ifdef FEAT_DIFF
705 filler_lines = diff_check(wp, lnum);
706 if (filler_lines < 0)
707 {
708 if (filler_lines == -1)
709 {
710 if (diff_find_change(wp, lnum, &change_start, &change_end))
711 diff_hlf = HLF_ADD; // added line
712 else if (change_start == 0)
713 diff_hlf = HLF_TXD; // changed text
714 else
715 diff_hlf = HLF_CHD; // changed line
716 }
717 else
718 diff_hlf = HLF_ADD; // added line
719 filler_lines = 0;
720 area_highlighting = TRUE;
721 }
722 if (lnum == wp->w_topline)
723 filler_lines = wp->w_topfill;
724 filler_todo = filler_lines;
725#endif
726
727#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +0100728 sign_present = buf_get_signattrs(wp, lnum, &sattr);
James McCoya80aad72021-12-22 19:45:28 +0000729 if (sign_present)
730 num_attr = sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200731#endif
732
733#ifdef LINE_ATTR
734# ifdef FEAT_SIGNS
735 // If this line has a sign with line highlighting set line_attr.
736 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200737 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200738# endif
739# if defined(FEAT_QUICKFIX)
740 // Highlight the current line in the quickfix window.
741 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
742 line_attr = HL_ATTR(HLF_QFL);
743# endif
744 if (line_attr != 0)
745 area_highlighting = TRUE;
746#endif
747
748 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
749 ptr = line;
750
751#ifdef FEAT_SPELL
752 if (has_spell && !number_only)
753 {
754 // For checking first word with a capital skip white space.
755 if (cap_col == 0)
756 cap_col = getwhitecols(line);
757
758 // To be able to spell-check over line boundaries copy the end of the
759 // current line into nextline[]. Above the start of the next line was
760 // copied to nextline[SPWORDLEN].
761 if (nextline[SPWORDLEN] == NUL)
762 {
763 // No next line or it is empty.
764 nextlinecol = MAXCOL;
765 nextline_idx = 0;
766 }
767 else
768 {
769 v = (long)STRLEN(line);
770 if (v < SPWORDLEN)
771 {
772 // Short line, use it completely and append the start of the
773 // next line.
774 nextlinecol = 0;
775 mch_memmove(nextline, line, (size_t)v);
776 STRMOVE(nextline + v, nextline + SPWORDLEN);
777 nextline_idx = v + 1;
778 }
779 else
780 {
781 // Long line, use only the last SPWORDLEN bytes.
782 nextlinecol = v - SPWORDLEN;
783 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
784 nextline_idx = SPWORDLEN + 1;
785 }
786 }
787 }
788#endif
789
790 if (wp->w_p_list)
791 {
Bram Moolenaareed9d462021-02-15 20:38:25 +0100792 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +0200793 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100794 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +0100795 || wp->w_lcs_chars.trail
796 || wp->w_lcs_chars.lead
797 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200798 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100799
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200800 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100801 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200802 {
803 trailcol = (colnr_T)STRLEN(ptr);
804 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
805 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +0100806 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200807 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100808 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100809 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100810 {
811 leadcol = 0;
812 while (VIM_ISWHITE(ptr[leadcol]))
813 ++leadcol;
814 if (ptr[leadcol] == NUL)
815 // in a line full of spaces all of them are treated as trailing
816 leadcol = (colnr_T)0;
817 else
818 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +0100819 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100820 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200821 }
822
823 wcr_attr = get_wcr_attr(wp);
824 if (wcr_attr != 0)
825 {
826 win_attr = wcr_attr;
827 area_highlighting = TRUE;
828 }
Bram Moolenaar34390282019-10-16 14:38:26 +0200829
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100830#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200831 if (WIN_IS_POPUP(wp))
832 screen_line_flags |= SLF_POPUP;
833#endif
834
835 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
836 // first character to be displayed.
837 if (wp->w_p_wrap)
838 v = wp->w_skipcol;
839 else
840 v = wp->w_leftcol;
841 if (v > 0 && !number_only)
842 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100843 char_u *prev_ptr = ptr;
844 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +0100845 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200846
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100847 init_chartabsize_arg(&cts, wp, lnum, vcol, line, ptr);
848 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200849 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100850 charsize = win_lbr_chartabsize(&cts, NULL);
851 cts.cts_vcol += charsize;
852 prev_ptr = cts.cts_ptr;
853 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200854 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100855 vcol = cts.cts_vcol;
856 ptr = cts.cts_ptr;
857 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200858
859 // When:
860 // - 'cuc' is set, or
861 // - 'colorcolumn' is set, or
862 // - 'virtualedit' is set, or
863 // - the visual mode is active,
864 // the end of the line may be before the start of the displayed part.
865 if (vcol < v && (
866#ifdef FEAT_SYN_HL
867 wp->w_p_cuc || draw_color_col ||
868#endif
869 virtual_active() ||
870 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
871 vcol = v;
872
873 // Handle a character that's not completely on the screen: Put ptr at
874 // that character but skip the first few screen characters.
875 if (vcol > v)
876 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100877 vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200878 ptr = prev_ptr;
879 // If the character fits on the screen, don't need to skip it.
880 // Except for a TAB.
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100881 if (( (*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB) && col == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200882 n_skip = v - vcol;
883 }
884
885 // Adjust for when the inverted text is before the screen,
886 // and when the start of the inverted text is before the screen.
887 if (tocol <= vcol)
888 fromcol = 0;
889 else if (fromcol >= 0 && fromcol < vcol)
890 fromcol = vcol;
891
892#ifdef FEAT_LINEBREAK
893 // When w_skipcol is non-zero, first line needs 'showbreak'
894 if (wp->w_p_wrap)
895 need_showbreak = TRUE;
896#endif
897#ifdef FEAT_SPELL
898 // When spell checking a word we need to figure out the start of the
899 // word and if it's badly spelled or not.
900 if (has_spell)
901 {
902 int len;
903 colnr_T linecol = (colnr_T)(ptr - line);
904 hlf_T spell_hlf = HLF_COUNT;
905
906 pos = wp->w_cursor;
907 wp->w_cursor.lnum = lnum;
908 wp->w_cursor.col = linecol;
909 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
910
911 // spell_move_to() may call ml_get() and make "line" invalid
912 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
913 ptr = line + linecol;
914
915 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
916 {
917 // no bad word found at line start, don't check until end of a
918 // word
919 spell_hlf = HLF_COUNT;
920 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
921 }
922 else
923 {
924 // bad word found, use attributes until end of word
925 word_end = wp->w_cursor.col + len + 1;
926
927 // Turn index into actual attributes.
928 if (spell_hlf != HLF_COUNT)
929 spell_attr = highlight_attr[spell_hlf];
930 }
931 wp->w_cursor = pos;
932
933# ifdef FEAT_SYN_HL
934 // Need to restart syntax highlighting for this line.
935 if (has_syntax)
936 syntax_start(wp, lnum);
937# endif
938 }
939#endif
940 }
941
942 // Correct highlighting for cursor that can't be disabled.
943 // Avoids having to check this for each character.
944 if (fromcol >= 0)
945 {
946 if (noinvcur)
947 {
948 if ((colnr_T)fromcol == wp->w_virtcol)
949 {
950 // highlighting starts at cursor, let it start just after the
951 // cursor
952 fromcol_prev = fromcol;
953 fromcol = -1;
954 }
955 else if ((colnr_T)fromcol < wp->w_virtcol)
956 // restart highlighting after the cursor
957 fromcol_prev = wp->w_virtcol;
958 }
959 if (fromcol >= tocol)
960 fromcol = -1;
961 }
962
963#ifdef FEAT_SEARCH_EXTRA
964 if (!number_only)
965 {
966 v = (long)(ptr - line);
967 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
968 &line, &screen_search_hl,
969 &search_attr);
970 ptr = line + v; // "line" may have been updated
971 }
972#endif
973
974#ifdef FEAT_SYN_HL
975 // Cursor line highlighting for 'cursorline' in the current window.
976 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
977 {
978 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +0000979 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200980 if (!(wp == curwin && VIsual_active)
981 && wp->w_p_culopt_flags != CULOPT_NBR)
982 {
983 cul_screenline = (wp->w_p_wrap
984 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
985
986 // Only set line_attr here when "screenline" is not present in
987 // 'cursorlineopt'. Otherwise it's done later.
988 if (!cul_screenline)
989 {
990 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +0200991# ifdef FEAT_SIGNS
992 // Combine the 'cursorline' and sign highlighting, depending on
993 // the sign priority.
994 if (sign_present && sattr.sat_linehl > 0)
995 {
996 if (sattr.sat_priority >= 100)
997 line_attr = hl_combine_attr(cul_attr, line_attr);
998 else
999 line_attr = hl_combine_attr(line_attr, cul_attr);
1000 }
1001 else
1002# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001003# if defined(FEAT_QUICKFIX)
1004 line_attr = hl_combine_attr(line_attr, cul_attr);
1005# else
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001006 line_attr = cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001007# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001008 }
1009 else
1010 {
1011 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001012 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1013 }
1014 area_highlighting = TRUE;
1015 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001016 }
1017#endif
1018
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001019#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001020 {
1021 char_u *prop_start;
1022
1023 text_prop_count = get_text_props(wp->w_buffer, lnum,
1024 &prop_start, FALSE);
1025 if (text_prop_count > 0)
1026 {
1027 // Make a copy of the properties, so that they are properly
1028 // aligned.
1029 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1030 if (text_props != NULL)
1031 mch_memmove(text_props, prop_start,
1032 text_prop_count * sizeof(textprop_T));
1033
1034 // Allocate an array for the indexes.
1035 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1036 area_highlighting = TRUE;
1037 extra_check = TRUE;
1038 }
1039 }
1040#endif
1041
1042 off = (unsigned)(current_ScreenLine - ScreenLines);
1043 col = 0;
1044
1045#ifdef FEAT_RIGHTLEFT
1046 if (wp->w_p_rl)
1047 {
1048 // Rightleft window: process the text in the normal direction, but put
1049 // it in current_ScreenLine[] from right to left. Start at the
1050 // rightmost column of the window.
1051 col = wp->w_width - 1;
1052 off += col;
1053 screen_line_flags |= SLF_RIGHTLEFT;
1054 }
1055#endif
1056
1057 // Repeat for the whole displayed line.
1058 for (;;)
1059 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001060 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001061#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001062 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001063#endif
1064#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001065 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001066#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001067
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001068 // Skip this quickly when working on the text.
1069 if (draw_state != WL_LINE)
1070 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001071#ifdef FEAT_SYN_HL
1072 if (cul_screenline)
1073 {
1074 cul_attr = 0;
1075 line_attr = line_attr_save;
1076 }
1077#endif
1078
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001079#ifdef FEAT_CMDWIN
1080 if (draw_state == WL_CMDLINE - 1 && n_extra == 0)
1081 {
1082 draw_state = WL_CMDLINE;
1083 if (cmdwin_type != 0 && wp == curwin)
1084 {
1085 // Draw the cmdline character.
1086 n_extra = 1;
1087 c_extra = cmdwin_type;
1088 c_final = NUL;
1089 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
1090 }
1091 }
1092#endif
1093
1094#ifdef FEAT_FOLDING
1095 if (draw_state == WL_FOLD - 1 && n_extra == 0)
1096 {
1097 int fdc = compute_foldcolumn(wp, 0);
1098
1099 draw_state = WL_FOLD;
1100 if (fdc > 0)
1101 {
1102 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1103 // already be in use.
1104 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001105 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001106 if (p_extra_free != NULL)
1107 {
Bram Moolenaar9355ae42021-03-08 19:04:05 +01001108 n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001109 FALSE, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001110 p_extra_free[n_extra] = NUL;
1111 p_extra = p_extra_free;
1112 c_extra = NUL;
1113 c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001114 if (use_cursor_line_sign(wp, lnum))
1115 char_attr =
1116 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1117 else
1118 char_attr =
1119 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001120 }
1121 }
1122 }
1123#endif
1124
1125#ifdef FEAT_SIGNS
1126 if (draw_state == WL_SIGN - 1 && n_extra == 0)
1127 {
1128 draw_state = WL_SIGN;
1129 // Show the sign column when there are any signs in this
1130 // buffer or when using Netbeans.
1131 if (signcolumn_on(wp))
1132 get_sign_display_info(FALSE, wp, lnum, &sattr, wcr_attr,
1133 row, startrow, filler_lines, filler_todo, &c_extra,
1134 &c_final, extra, &p_extra, &n_extra, &char_attr);
1135 }
1136#endif
1137
1138 if (draw_state == WL_NR - 1 && n_extra == 0)
1139 {
1140 draw_state = WL_NR;
1141 // Display the absolute or relative line number. After the
1142 // first fill with blanks when the 'n' flag isn't in 'cpo'
1143 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar936dc602022-03-06 20:47:01 +00001144 && (row == startrow + filler_lines
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001145 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
1146 {
1147#ifdef FEAT_SIGNS
1148 // If 'signcolumn' is set to 'number' and a sign is present
1149 // in 'lnum', then display the sign instead of the line
1150 // number.
1151 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1152 && sign_present)
1153 get_sign_display_info(TRUE, wp, lnum, &sattr, wcr_attr,
1154 row, startrow, filler_lines, filler_todo,
1155 &c_extra, &c_final, extra, &p_extra, &n_extra,
1156 &char_attr);
1157 else
1158#endif
1159 {
1160 // Draw the line number (empty space after wrapping).
Bram Moolenaar936dc602022-03-06 20:47:01 +00001161 if (row == startrow + filler_lines)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001162 {
1163 long num;
1164 char *fmt = "%*ld ";
1165
1166 if (wp->w_p_nu && !wp->w_p_rnu)
1167 // 'number' + 'norelativenumber'
1168 num = (long)lnum;
1169 else
1170 {
1171 // 'relativenumber', don't use negative numbers
1172 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1173 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1174 {
1175 // 'number' + 'relativenumber'
1176 num = lnum;
1177 fmt = "%-*ld ";
1178 }
1179 }
1180
1181 sprintf((char *)extra, fmt,
1182 number_width(wp), num);
1183 if (wp->w_skipcol > 0)
1184 for (p_extra = extra; *p_extra == ' '; ++p_extra)
1185 *p_extra = '-';
1186#ifdef FEAT_RIGHTLEFT
1187 if (wp->w_p_rl) // reverse line numbers
1188 {
1189 char_u *p1, *p2;
1190 int t;
1191
1192 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001193 p2 = skipwhite(extra);
1194 p2 = skiptowhite(p2) - 1;
1195 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001196 {
1197 t = *p1;
1198 *p1 = *p2;
1199 *p2 = t;
1200 }
1201 }
1202#endif
1203 p_extra = extra;
1204 c_extra = NUL;
1205 c_final = NUL;
1206 }
1207 else
1208 {
1209 c_extra = ' ';
1210 c_final = NUL;
1211 }
1212 n_extra = number_width(wp) + 1;
1213 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
1214#ifdef FEAT_SYN_HL
1215 // When 'cursorline' is set highlight the line number of
1216 // the current line differently.
zeertzjq754d2b42022-03-13 13:40:45 +00001217 // When 'cursorlineopt' does not have "line" only
1218 // highlight the line number itself.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001219 // TODO: Can we use CursorLine instead of CursorLineNr
1220 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001221 if (wp->w_p_cul
1222 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001223 && (wp->w_p_culopt_flags & CULOPT_NBR)
Bram Moolenaar127969c2022-03-06 19:54:13 +00001224 && (row == startrow + filler_lines
1225 || (row > startrow + filler_lines
zeertzjq754d2b42022-03-13 13:40:45 +00001226 && (wp->w_p_culopt_flags & CULOPT_LINE))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001227 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLN));
1228#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001229 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1230 && HL_ATTR(HLF_LNA) != 0)
1231 // Use LineNrAbove
1232 char_attr = hl_combine_attr(wcr_attr,
1233 HL_ATTR(HLF_LNA));
1234 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1235 && HL_ATTR(HLF_LNB) != 0)
1236 // Use LineNrBelow
1237 char_attr = hl_combine_attr(wcr_attr,
1238 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001239 }
James McCoya80aad72021-12-22 19:45:28 +00001240#ifdef FEAT_SIGNS
1241 if (num_attr)
1242 char_attr = num_attr;
1243#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001244 }
1245 }
1246
1247#ifdef FEAT_LINEBREAK
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001248 if (wp->w_briopt_sbr && draw_state == WL_BRI - 1
Bram Moolenaaree857022019-11-09 23:26:40 +01001249 && n_extra == 0 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001250 // draw indent after showbreak value
1251 draw_state = WL_BRI;
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001252 else if (wp->w_briopt_sbr && draw_state == WL_SBR && n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001253 // After the showbreak, draw the breakindent
1254 draw_state = WL_BRI - 1;
1255
1256 // draw 'breakindent': indent wrapped text accordingly
1257 if (draw_state == WL_BRI - 1 && n_extra == 0)
1258 {
1259 draw_state = WL_BRI;
1260 // if need_showbreak is set, breakindent also applies
Bram Moolenaarfe154992022-03-22 20:42:12 +00001261 if (wp->w_p_bri && (row != startrow || need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001262# ifdef FEAT_DIFF
1263 && filler_lines == 0
1264# endif
1265 )
1266 {
1267 char_attr = 0;
1268# ifdef FEAT_DIFF
1269 if (diff_hlf != (hlf_T)0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001270 char_attr = HL_ATTR(diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001271# endif
1272 p_extra = NULL;
1273 c_extra = ' ';
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001274 c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001275 n_extra = get_breakindent_win(wp,
1276 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001277 if (row == startrow)
1278 {
1279 n_extra -= win_col_off2(wp);
1280 if (n_extra < 0)
1281 n_extra = 0;
1282 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001283 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001284 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001285 // Correct end of highlighted area for 'breakindent',
1286 // required when 'linebreak' is also set.
1287 if (tocol == vcol)
1288 tocol += n_extra;
1289 }
1290 }
1291#endif
1292
1293#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
1294 if (draw_state == WL_SBR - 1 && n_extra == 0)
1295 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001296 char_u *sbr;
1297
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001298 draw_state = WL_SBR;
1299# ifdef FEAT_DIFF
1300 if (filler_todo > 0)
1301 {
1302 // Draw "deleted" diff line(s).
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001303 if (char2cells(wp->w_fill_chars.diff) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001304 {
1305 c_extra = '-';
1306 c_final = NUL;
1307 }
1308 else
1309 {
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001310 c_extra = wp->w_fill_chars.diff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001311 c_final = NUL;
1312 }
1313# ifdef FEAT_RIGHTLEFT
1314 if (wp->w_p_rl)
1315 n_extra = col + 1;
1316 else
1317# endif
1318 n_extra = wp->w_width - col;
1319 char_attr = HL_ATTR(HLF_DED);
1320 }
1321# endif
1322# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001323 sbr = get_showbreak_value(wp);
1324 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001325 {
1326 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaaree857022019-11-09 23:26:40 +01001327 p_extra = sbr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001328 c_extra = NUL;
1329 c_final = NUL;
Bram Moolenaaree857022019-11-09 23:26:40 +01001330 n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001331 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1332 need_showbreak = FALSE;
Bram Moolenaaree857022019-11-09 23:26:40 +01001333 vcol_sbr = vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001334 // Correct end of highlighted area for 'showbreak',
1335 // required when 'linebreak' is also set.
1336 if (tocol == vcol)
1337 tocol += n_extra;
1338 // combine 'showbreak' with 'wincolor'
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001339 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001340# ifdef FEAT_SYN_HL
1341 // combine 'showbreak' with 'cursorline'
1342 if (cul_attr != 0)
1343 char_attr = hl_combine_attr(char_attr, cul_attr);
1344# endif
1345 }
1346# endif
1347 }
1348#endif
1349
1350 if (draw_state == WL_LINE - 1 && n_extra == 0)
1351 {
1352 draw_state = WL_LINE;
1353 if (saved_n_extra)
1354 {
1355 // Continue item from end of wrapped line.
1356 n_extra = saved_n_extra;
1357 c_extra = saved_c_extra;
1358 c_final = saved_c_final;
1359 p_extra = saved_p_extra;
1360 char_attr = saved_char_attr;
1361 }
1362 else
1363 char_attr = win_attr;
1364 }
1365 }
1366#ifdef FEAT_SYN_HL
zeertzjq4f33bc22021-08-05 17:57:02 +02001367 if (cul_screenline && draw_state == WL_LINE
1368 && vcol >= left_curline_col
1369 && vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001370 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001371 cul_attr = HL_ATTR(HLF_CUL);
1372 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001373 }
1374#endif
1375
1376 // When still displaying '$' of change command, stop at cursor.
1377 // When only displaying the (relative) line number and that's done,
1378 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001379 if (((dollar_vcol >= 0 && wp == curwin
1380 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol)
1381 || (number_only && draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001382#ifdef FEAT_DIFF
1383 && filler_todo <= 0
1384#endif
1385 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001386 {
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001387 screen_line(wp, screen_row, wp->w_wincol, col, -wp->w_width,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001388 screen_line_flags);
1389 // Pretend we have finished updating the window. Except when
1390 // 'cursorcolumn' is set.
1391#ifdef FEAT_SYN_HL
1392 if (wp->w_p_cuc)
1393 row = wp->w_cline_row + wp->w_cline_height;
1394 else
1395#endif
1396 row = wp->w_height;
1397 break;
1398 }
1399
Bram Moolenaar34390282019-10-16 14:38:26 +02001400 if (draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001401 {
1402 // handle Visual or match highlighting in this line
1403 if (vcol == fromcol
1404 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0
1405 && (*mb_ptr2cells)(ptr) > 1)
1406 || ((int)vcol_prev == fromcol_prev
1407 && vcol_prev < vcol // not at margin
1408 && vcol < tocol))
1409 area_attr = vi_attr; // start highlighting
1410 else if (area_attr != 0
1411 && (vcol == tocol
1412 || (noinvcur && (colnr_T)vcol == wp->w_virtcol)))
1413 area_attr = 0; // stop highlighting
1414
1415#ifdef FEAT_SEARCH_EXTRA
1416 if (!n_extra)
1417 {
1418 // Check for start/end of 'hlsearch' and other matches.
1419 // After end, check for start/end of next match.
1420 // When another match, have to check for start again.
1421 v = (long)(ptr - line);
1422 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1423 &screen_search_hl, &has_match_conc,
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001424 &match_conc, did_line_attr, lcs_eol_one,
1425 &on_last_col);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001426 ptr = line + v; // "line" may have been changed
Bram Moolenaarb9081882022-07-09 04:56:24 +01001427 prev_ptr = ptr;
Bram Moolenaarfc838d62020-06-25 22:23:48 +02001428
1429 // Do not allow a conceal over EOL otherwise EOL will be missed
1430 // and bad things happen.
1431 if (*ptr == NUL)
1432 has_match_conc = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001433 }
1434#endif
1435
1436#ifdef FEAT_DIFF
1437 if (diff_hlf != (hlf_T)0)
1438 {
1439 if (diff_hlf == HLF_CHD && ptr - line >= change_start
1440 && n_extra == 0)
1441 diff_hlf = HLF_TXD; // changed text
1442 if (diff_hlf == HLF_TXD && ptr - line > change_end
1443 && n_extra == 0)
1444 diff_hlf = HLF_CHD; // changed line
1445 line_attr = HL_ATTR(diff_hlf);
1446 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1447 && wp->w_p_culopt_flags != CULOPT_NBR
1448 && (!cul_screenline || (vcol >= left_curline_col
1449 && vcol <= right_curline_col)))
1450 line_attr = hl_combine_attr(
1451 line_attr, HL_ATTR(HLF_CUL));
1452 }
1453#endif
1454
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001455#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001456 if (text_props != NULL)
1457 {
1458 int pi;
1459 int bcol = (int)(ptr - line);
1460
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001461 if (n_extra > 0
1462# ifdef FEAT_LINEBREAK
1463 && !in_linebreak
1464# endif
1465 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001466 --bcol; // still working on the previous char, e.g. Tab
1467
1468 // Check if any active property ends.
1469 for (pi = 0; pi < text_props_active; ++pi)
1470 {
1471 int tpi = text_prop_idxs[pi];
1472
1473 if (bcol >= text_props[tpi].tp_col - 1
1474 + text_props[tpi].tp_len)
1475 {
1476 if (pi + 1 < text_props_active)
1477 mch_memmove(text_prop_idxs + pi,
1478 text_prop_idxs + pi + 1,
1479 sizeof(int)
1480 * (text_props_active - (pi + 1)));
1481 --text_props_active;
1482 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001483# ifdef FEAT_LINEBREAK
1484 // not exactly right but should work in most cases
1485 if (in_linebreak && syntax_attr == text_prop_attr)
1486 syntax_attr = 0;
1487# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001488 }
1489 }
1490
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001491# ifdef FEAT_LINEBREAK
1492 if (n_extra > 0 && in_linebreak)
1493 // not on the next char yet, don't start another prop
1494 --bcol;
1495# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001496 // Add any text property that starts in this column.
1497 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001498 && (text_props[text_prop_next].tp_col == MAXCOL
1499 ? *ptr == NUL
1500 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001501 {
1502 if (bcol <= text_props[text_prop_next].tp_col - 1
1503 + text_props[text_prop_next].tp_len)
1504 text_prop_idxs[text_props_active++] = text_prop_next;
1505 ++text_prop_next;
1506 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001507
1508 text_prop_attr = 0;
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001509 text_prop_flags = 0;
Bram Moolenaar053f7122019-09-23 22:17:15 +02001510 text_prop_type = NULL;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001511 text_prop_id = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001512 if (text_props_active > 0 && n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001513 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001514 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001515 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001516 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001517
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001518 // Sort the properties on priority and/or starting last.
1519 // Then combine the attributes, highest priority last.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001520 text_prop_follows = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001521 current_text_props = text_props;
1522 current_buf = wp->w_buffer;
1523 qsort((void *)text_prop_idxs, (size_t)text_props_active,
1524 sizeof(int), text_prop_compare);
1525
1526 for (pi = 0; pi < text_props_active; ++pi)
1527 {
1528 int tpi = text_prop_idxs[pi];
1529 proptype_T *pt = text_prop_type_by_id(
1530 wp->w_buffer, text_props[tpi].tp_type);
1531
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001532 if (pt != NULL && pt->pt_hl_id > 0
1533 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001534 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001535 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001536 text_prop_type = pt;
1537 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001538 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001539 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001540 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001541 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001542 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001543 }
1544 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001545 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001546 && -text_prop_id
1547 <= wp->w_buffer->b_textprop_text.ga_len)
1548 {
1549 char_u *p = ((char_u **)wp->w_buffer
1550 ->b_textprop_text.ga_data)[
1551 -text_prop_id - 1];
1552 if (p != NULL)
1553 {
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001554 int right = (text_props[used_tpi].tp_flags
1555 & TP_FLAG_ALIGN_RIGHT);
1556 int below = (text_props[used_tpi].tp_flags
1557 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaar398649e2022-08-04 15:03:48 +01001558 int wrap = (text_props[used_tpi].tp_flags
1559 & TP_FLAG_WRAP);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001560
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001561 p_extra = p;
Bram Moolenaar711483c2022-07-30 21:33:46 +01001562 c_extra = NUL;
1563 c_final = NUL;
Mike Williams04947892022-07-26 16:03:42 +01001564 n_extra = (int)STRLEN(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001565 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001566 n_attr = mb_charlen(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001567 text_prop_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001568 if (*ptr == NUL)
1569 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001570 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001571#ifdef FEAT_LINEBREAK
1572 if (below || right)
1573 {
1574 // no 'showbreak' before "below" text property
1575 // or after "right" text property
1576 need_showbreak = FALSE;
1577 dont_use_showbreak = TRUE;
1578 }
1579#endif
Bram Moolenaar398649e2022-08-04 15:03:48 +01001580 // Keep in sync with where
1581 // textprop_size_after_trunc() is called in
1582 // win_lbr_chartabsize().
1583 if ((right || below || !wrap) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001584 {
1585 int added = wp->w_width - col;
Bram Moolenaar398649e2022-08-04 15:03:48 +01001586 int n_used = n_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001587 char_u *l;
Bram Moolenaar398649e2022-08-04 15:03:48 +01001588 int strsize = wrap
1589 ? vim_strsize(p_extra)
1590 : textprop_size_after_trunc(wp,
1591 below, added, p_extra, &n_used);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001592
Bram Moolenaar398649e2022-08-04 15:03:48 +01001593 if (wrap || right || below || n_used < n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001594 {
Bram Moolenaar398649e2022-08-04 15:03:48 +01001595 // Right-align: fill with spaces
1596 if (right)
1597 added -= strsize;
1598 if (added < 0 || (below && col == 0)
1599 || (!below && n_used < n_extra))
1600 added = 0;
1601 // add 1 for NUL, 2 for when '…' is used
1602 l = alloc(n_used + added + 3);
1603 if (l != NULL)
1604 {
1605 vim_memset(l, ' ', added);
1606 vim_strncpy(l + added, p_extra, n_used);
1607 if (n_used < n_extra)
1608 {
1609 char_u *lp = l + added + n_used - 1;
1610
1611 if (has_mbyte)
1612 {
1613 // change last character to '…'
1614 lp -= (*mb_head_off)(l, lp);
1615 STRCPY(lp, "…");
1616 n_used = lp - l + 3;
1617 }
1618 else
1619 // change last character to '>'
1620 *lp = '>';
1621 }
1622 vim_free(p_extra_free);
1623 p_extra = p_extra_free = l;
1624 n_extra = n_used + added;
1625 n_attr_skip = added;
1626 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001627 }
1628 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001629 }
1630 // reset the ID in the copy to avoid it being used
1631 // again
1632 text_props[used_tpi].tp_id = -MAXCOL;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001633
1634 // If another text prop follows the condition below at
1635 // the last window column must know.
1636 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001637 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001638 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001639 else if (text_prop_next < text_prop_count
1640 && text_props[text_prop_next].tp_col == MAXCOL
1641 && *ptr != NUL
1642 && ptr[mb_ptr2len(ptr)] == NUL)
1643 // When at last-but-one character and a text property
1644 // follows after it, we may need to flush the line after
1645 // displaying that character.
1646 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001647 }
1648#endif
1649
Bram Moolenaara74fda62019-10-19 17:38:03 +02001650#ifdef FEAT_SYN_HL
Bram Moolenaara74fda62019-10-19 17:38:03 +02001651 if (extra_check && n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001652 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001653 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001654# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001655 if (get_term_attr)
Bram Moolenaar219c7d02020-02-01 21:57:29 +01001656 syntax_attr = term_get_attr(wp, lnum, vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001657# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001658 // Get syntax attribute.
1659 if (has_syntax)
1660 {
1661 // Get the syntax attribute for the character. If there
1662 // is an error, disable syntax highlighting.
1663 save_did_emsg = did_emsg;
1664 did_emsg = FALSE;
1665
1666 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001667 if (v == prev_syntax_col)
1668 // at same column again
1669 syntax_attr = prev_syntax_attr;
1670 else
1671 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001672# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001673 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001674# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001675 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001676# ifdef FEAT_SPELL
1677 has_spell ? &can_spell :
1678# endif
1679 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001680 prev_syntax_col = v;
1681 prev_syntax_attr = syntax_attr;
1682 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001683
Bram Moolenaar34390282019-10-16 14:38:26 +02001684 if (did_emsg)
1685 {
1686 wp->w_s->b_syn_error = TRUE;
1687 has_syntax = FALSE;
1688 syntax_attr = 0;
1689 }
1690 else
1691 did_emsg = save_did_emsg;
1692# ifdef SYN_TIME_LIMIT
1693 if (wp->w_s->b_syn_slow)
1694 has_syntax = FALSE;
1695# endif
1696
1697 // Need to get the line again, a multi-line regexp may
1698 // have made it invalid.
1699 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1700 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001701 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001702# ifdef FEAT_CONCEAL
1703 // no concealing past the end of the line, it interferes
1704 // with line highlighting
1705 if (*ptr == NUL)
1706 syntax_flags = 0;
1707 else
1708 syntax_flags = get_syntax_info(&syntax_seqnr);
1709# endif
1710 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001711 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001712# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001713 // Combine text property highlight into syntax highlight.
1714 if (text_prop_type != NULL)
1715 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001716 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01001717 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1718 else
1719 syntax_attr = text_prop_attr;
1720 }
1721# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001722#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001723
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001724 // Decide which of the highlight attributes to use.
1725 attr_pri = TRUE;
1726#ifdef LINE_ATTR
1727 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001728 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001729 char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02001730 if (!highlight_match)
1731 // let search highlight show in Visual area if possible
1732 char_attr = hl_combine_attr(search_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001733# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001734 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001735# endif
1736 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001737 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001738 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001739 char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001740# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001741 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001742# endif
1743 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001744 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
1745 || vcol < fromcol || vcol_prev < fromcol_prev
1746 || vcol >= tocol))
1747 {
1748 // Use line_attr when not in the Visual or 'incsearch' area
1749 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001750# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001751 char_attr = hl_combine_attr(syntax_attr, line_attr);
1752# else
1753 char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001754# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001755 attr_pri = FALSE;
1756 }
1757#else
1758 if (area_attr != 0)
1759 char_attr = area_attr;
1760 else if (search_attr != 0)
1761 char_attr = search_attr;
1762#endif
1763 else
1764 {
1765 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001766#ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001767 char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001768#else
Bram Moolenaardbd43162019-11-09 21:28:14 +01001769 char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001770#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001771 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001772#ifdef FEAT_PROP_POPUP
1773 // override with text property highlight when "override" is TRUE
1774 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
1775 char_attr = hl_combine_attr(char_attr, text_prop_attr);
1776#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001777 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001778
1779 // combine attribute with 'wincolor'
1780 if (win_attr != 0)
1781 {
1782 if (char_attr == 0)
1783 char_attr = win_attr;
1784 else
1785 char_attr = hl_combine_attr(win_attr, char_attr);
1786 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001787
1788 // Get the next character to put on the screen.
1789
1790 // The "p_extra" points to the extra stuff that is inserted to
1791 // represent special characters (non-printable stuff) and other
1792 // things. When all characters are the same, c_extra is used.
1793 // If c_final is set, it will compulsorily be used at the end.
1794 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
1795 // "p_extra[n_extra]".
1796 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
1797 if (n_extra > 0)
1798 {
1799 if (c_extra != NUL || (n_extra == 1 && c_final != NUL))
1800 {
1801 c = (n_extra == 1 && c_final != NUL) ? c_final : c_extra;
1802 mb_c = c; // doesn't handle non-utf-8 multi-byte!
1803 if (enc_utf8 && utf_char2len(c) > 1)
1804 {
1805 mb_utf8 = TRUE;
1806 u8cc[0] = 0;
1807 c = 0xc0;
1808 }
1809 else
1810 mb_utf8 = FALSE;
1811 }
1812 else
1813 {
1814 c = *p_extra;
1815 if (has_mbyte)
1816 {
1817 mb_c = c;
1818 if (enc_utf8)
1819 {
1820 // If the UTF-8 character is more than one byte:
1821 // Decode it into "mb_c".
1822 mb_l = utfc_ptr2len(p_extra);
1823 mb_utf8 = FALSE;
1824 if (mb_l > n_extra)
1825 mb_l = 1;
1826 else if (mb_l > 1)
1827 {
1828 mb_c = utfc_ptr2char(p_extra, u8cc);
1829 mb_utf8 = TRUE;
1830 c = 0xc0;
1831 }
1832 }
1833 else
1834 {
1835 // if this is a DBCS character, put it in "mb_c"
1836 mb_l = MB_BYTE2LEN(c);
1837 if (mb_l >= n_extra)
1838 mb_l = 1;
1839 else if (mb_l > 1)
1840 mb_c = (c << 8) + p_extra[1];
1841 }
1842 if (mb_l == 0) // at the NUL at end-of-line
1843 mb_l = 1;
1844
1845 // If a double-width char doesn't fit display a '>' in the
1846 // last column.
1847 if ((
1848# ifdef FEAT_RIGHTLEFT
1849 wp->w_p_rl ? (col <= 0) :
1850# endif
1851 (col >= wp->w_width - 1))
1852 && (*mb_char2cells)(mb_c) == 2)
1853 {
1854 c = '>';
1855 mb_c = c;
1856 mb_l = 1;
1857 mb_utf8 = FALSE;
1858 multi_attr = HL_ATTR(HLF_AT);
1859#ifdef FEAT_SYN_HL
1860 if (cul_attr)
1861 multi_attr = hl_combine_attr(multi_attr, cul_attr);
1862#endif
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001863 multi_attr = hl_combine_attr(win_attr, multi_attr);
1864
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001865 // put the pointer back to output the double-width
1866 // character at the start of the next line.
1867 ++n_extra;
1868 --p_extra;
1869 }
1870 else
1871 {
1872 n_extra -= mb_l - 1;
1873 p_extra += mb_l - 1;
1874 }
1875 }
1876 ++p_extra;
1877 }
1878 --n_extra;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001879#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001880 if (n_extra <= 0)
1881 in_linebreak = FALSE;
1882#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001883 }
1884 else
1885 {
1886#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01001887 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001888#endif
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001889 VIM_CLEAR(p_extra_free);
Bram Moolenaarb9081882022-07-09 04:56:24 +01001890 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001891
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001892 // Get a character from the line itself.
1893 c = *ptr;
1894#ifdef FEAT_LINEBREAK
1895 c0 = *ptr;
1896#endif
1897 if (has_mbyte)
1898 {
1899 mb_c = c;
1900 if (enc_utf8)
1901 {
1902 // If the UTF-8 character is more than one byte: Decode it
1903 // into "mb_c".
1904 mb_l = utfc_ptr2len(ptr);
1905 mb_utf8 = FALSE;
1906 if (mb_l > 1)
1907 {
1908 mb_c = utfc_ptr2char(ptr, u8cc);
1909 // Overlong encoded ASCII or ASCII with composing char
1910 // is displayed normally, except a NUL.
1911 if (mb_c < 0x80)
1912 {
1913 c = mb_c;
1914#ifdef FEAT_LINEBREAK
1915 c0 = mb_c;
1916#endif
1917 }
1918 mb_utf8 = TRUE;
1919
1920 // At start of the line we can have a composing char.
1921 // Draw it as a space with a composing char.
1922 if (utf_iscomposing(mb_c))
1923 {
1924 int i;
1925
1926 for (i = Screen_mco - 1; i > 0; --i)
1927 u8cc[i] = u8cc[i - 1];
1928 u8cc[0] = mb_c;
1929 mb_c = ' ';
1930 }
1931 }
1932
1933 if ((mb_l == 1 && c >= 0x80)
1934 || (mb_l >= 1 && mb_c == 0)
1935 || (mb_l > 1 && (!vim_isprintc(mb_c))))
1936 {
1937 // Illegal UTF-8 byte: display as <xx>.
1938 // Non-BMP character : display as ? or fullwidth ?.
1939 transchar_hex(extra, mb_c);
1940# ifdef FEAT_RIGHTLEFT
1941 if (wp->w_p_rl) // reverse
1942 rl_mirror(extra);
1943# endif
1944 p_extra = extra;
1945 c = *p_extra;
1946 mb_c = mb_ptr2char_adv(&p_extra);
1947 mb_utf8 = (c >= 0x80);
1948 n_extra = (int)STRLEN(p_extra);
1949 c_extra = NUL;
1950 c_final = NUL;
1951 if (area_attr == 0 && search_attr == 0)
1952 {
1953 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001954 extra_attr = hl_combine_attr(
1955 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001956 saved_attr2 = char_attr; // save current attr
1957 }
1958 }
1959 else if (mb_l == 0) // at the NUL at end-of-line
1960 mb_l = 1;
1961#ifdef FEAT_ARABIC
1962 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
1963 {
1964 // Do Arabic shaping.
1965 int pc, pc1, nc;
1966 int pcc[MAX_MCO];
1967
1968 // The idea of what is the previous and next
1969 // character depends on 'rightleft'.
1970 if (wp->w_p_rl)
1971 {
1972 pc = prev_c;
1973 pc1 = prev_c1;
1974 nc = utf_ptr2char(ptr + mb_l);
1975 prev_c1 = u8cc[0];
1976 }
1977 else
1978 {
1979 pc = utfc_ptr2char(ptr + mb_l, pcc);
1980 nc = prev_c;
1981 pc1 = pcc[0];
1982 }
1983 prev_c = mb_c;
1984
1985 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
1986 }
1987 else
1988 prev_c = mb_c;
1989#endif
1990 }
1991 else // enc_dbcs
1992 {
1993 mb_l = MB_BYTE2LEN(c);
1994 if (mb_l == 0) // at the NUL at end-of-line
1995 mb_l = 1;
1996 else if (mb_l > 1)
1997 {
1998 // We assume a second byte below 32 is illegal.
1999 // Hopefully this is OK for all double-byte encodings!
2000 if (ptr[1] >= 32)
2001 mb_c = (c << 8) + ptr[1];
2002 else
2003 {
2004 if (ptr[1] == NUL)
2005 {
2006 // head byte at end of line
2007 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002008 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002009 }
2010 else
2011 {
2012 // illegal tail byte
2013 mb_l = 2;
2014 STRCPY(extra, "XX");
2015 }
2016 p_extra = extra;
2017 n_extra = (int)STRLEN(extra) - 1;
2018 c_extra = NUL;
2019 c_final = NUL;
2020 c = *p_extra++;
2021 if (area_attr == 0 && search_attr == 0)
2022 {
2023 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002024 extra_attr = hl_combine_attr(
2025 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002026 saved_attr2 = char_attr; // save current attr
2027 }
2028 mb_c = c;
2029 }
2030 }
2031 }
2032 // If a double-width char doesn't fit display a '>' in the
2033 // last column; the character is displayed at the start of the
2034 // next line.
2035 if ((
2036# ifdef FEAT_RIGHTLEFT
2037 wp->w_p_rl ? (col <= 0) :
2038# endif
2039 (col >= wp->w_width - 1))
2040 && (*mb_char2cells)(mb_c) == 2)
2041 {
2042 c = '>';
2043 mb_c = c;
2044 mb_utf8 = FALSE;
2045 mb_l = 1;
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002046 multi_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002047 // Put pointer back so that the character will be
2048 // displayed at the start of the next line.
2049 --ptr;
2050#ifdef FEAT_CONCEAL
2051 did_decrement_ptr = TRUE;
2052#endif
2053 }
2054 else if (*ptr != NUL)
2055 ptr += mb_l - 1;
2056
2057 // If a double-width char doesn't fit at the left side display
2058 // a '<' in the first column. Don't do this for unprintable
2059 // characters.
2060 if (n_skip > 0 && mb_l > 1 && n_extra == 0)
2061 {
2062 n_extra = 1;
2063 c_extra = MB_FILLER_CHAR;
2064 c_final = NUL;
2065 c = ' ';
2066 if (area_attr == 0 && search_attr == 0)
2067 {
2068 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002069 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002070 saved_attr2 = char_attr; // save current attr
2071 }
2072 mb_c = c;
2073 mb_utf8 = FALSE;
2074 mb_l = 1;
2075 }
2076
2077 }
2078 ++ptr;
2079
2080 if (extra_check)
2081 {
2082#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002083 // Check spelling (unless at the end of the line).
2084 // Only do this when there is no syntax highlighting, the
2085 // @Spell cluster is not used or the current syntax item
2086 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002087 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002088 if (has_spell && v >= word_end && v > cur_checked_col)
2089 {
2090 spell_attr = 0;
2091 if (c != 0 && (
2092# ifdef FEAT_SYN_HL
2093 !has_syntax ||
2094# endif
2095 can_spell))
2096 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002097 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002098 int len;
2099 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002100
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002101 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002102 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002103
2104 // Use nextline[] if possible, it has the start of the
2105 // next line concatenated.
2106 if ((prev_ptr - line) - nextlinecol >= 0)
2107 p = nextline + (prev_ptr - line) - nextlinecol;
2108 else
2109 p = prev_ptr;
2110 cap_col -= (int)(prev_ptr - line);
2111 len = spell_check(wp, p, &spell_hlf, &cap_col,
2112 nochange);
2113 word_end = v + len;
2114
2115 // In Insert mode only highlight a word that
2116 // doesn't touch the cursor.
2117 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002118 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002119 && wp->w_cursor.lnum == lnum
2120 && wp->w_cursor.col >=
2121 (colnr_T)(prev_ptr - line)
2122 && wp->w_cursor.col < (colnr_T)word_end)
2123 {
2124 spell_hlf = HLF_COUNT;
2125 spell_redraw_lnum = lnum;
2126 }
2127
2128 if (spell_hlf == HLF_COUNT && p != prev_ptr
2129 && (p - nextline) + len > nextline_idx)
2130 {
2131 // Remember that the good word continues at the
2132 // start of the next line.
2133 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002134 checked_col = (int)((p - nextline)
2135 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002136 }
2137
2138 // Turn index into actual attributes.
2139 if (spell_hlf != HLF_COUNT)
2140 spell_attr = highlight_attr[spell_hlf];
2141
2142 if (cap_col > 0)
2143 {
2144 if (p != prev_ptr
2145 && (p - nextline) + cap_col >= nextline_idx)
2146 {
2147 // Remember that the word in the next line
2148 // must start with a capital.
2149 capcol_lnum = lnum + 1;
2150 cap_col = (int)((p - nextline) + cap_col
2151 - nextline_idx);
2152 }
2153 else
2154 // Compute the actual column.
2155 cap_col += (int)(prev_ptr - line);
2156 }
2157 }
2158 }
2159 if (spell_attr != 0)
2160 {
2161 if (!attr_pri)
2162 char_attr = hl_combine_attr(char_attr, spell_attr);
2163 else
2164 char_attr = hl_combine_attr(spell_attr, char_attr);
2165 }
2166#endif
2167#ifdef FEAT_LINEBREAK
2168 // Found last space before word: check for line break.
2169 if (wp->w_p_lbr && c0 == c
2170 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2171 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002172 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2173 : 0;
2174 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002175 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002176
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002177 init_chartabsize_arg(&cts, wp, lnum, vcol, line, p);
2178 n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002179
2180 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002181 // space for it again.
Bram Moolenaara06e3452021-05-29 17:56:37 +02002182 if (vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002183 {
Bram Moolenaara06e3452021-05-29 17:56:37 +02002184 n_extra -= MB_CHARLEN(get_showbreak_value(wp));
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002185 if (n_extra < 0)
2186 n_extra = 0;
2187 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002188 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002189 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002190 // line break, but for TABs the highlighting should
2191 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002192 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002193
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002194 if (c == TAB && n_extra + col > wp->w_width)
2195# ifdef FEAT_VARTABS
2196 n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts,
2197 wp->w_buffer->b_p_vts_array) - 1;
2198# else
2199 n_extra = (int)wp->w_buffer->b_p_ts
2200 - vcol % (int)wp->w_buffer->b_p_ts - 1;
2201# endif
2202
2203 c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2204 c_final = NUL;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002205# if defined(FEAT_PROP_POPUP)
Bram Moolenaar42eba042021-11-30 20:22:49 +00002206 if (n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002207 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002208# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002209 if (VIM_ISWHITE(c))
2210 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002211# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002212 if (c == TAB)
2213 // See "Tab alignment" below.
2214 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002215# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002216 if (!wp->w_p_list)
2217 c = ' ';
2218 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002219 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002220 }
2221#endif
2222
zeertzjqf14b8ba2021-09-10 16:58:30 +02002223 in_multispace = c == ' '
2224 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2225 if (!in_multispace)
2226 multispace_pos = 0;
2227
Bram Moolenaareed9d462021-02-15 20:38:25 +01002228 // 'list': Change char 160 to 'nbsp' and space to 'space'
2229 // setting in 'listchars'. But not when the character is
2230 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002231 if (wp->w_p_list
2232 && ((((c == 160 && mb_l == 1)
2233 || (mb_utf8
2234 && ((mb_c == 160 && mb_l == 2)
2235 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002236 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002237 || (c == ' '
2238 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002239 && (wp->w_lcs_chars.space
2240 || (in_multispace
2241 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002242 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002243 && ptr - line <= trailcol)))
2244 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002245 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2246 {
2247 c = wp->w_lcs_chars.multispace[multispace_pos++];
2248 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2249 multispace_pos = 0;
2250 }
2251 else
2252 c = (c == ' ') ? wp->w_lcs_chars.space
2253 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002254 if (area_attr == 0 && search_attr == 0)
2255 {
2256 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002257 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002258 saved_attr2 = char_attr; // save current attr
2259 }
2260 mb_c = c;
2261 if (enc_utf8 && utf_char2len(c) > 1)
2262 {
2263 mb_utf8 = TRUE;
2264 u8cc[0] = 0;
2265 c = 0xc0;
2266 }
2267 else
2268 mb_utf8 = FALSE;
2269 }
2270
zeertzjq2e7cba32022-06-10 15:30:32 +01002271 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2272 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002273 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002274 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2275 && wp->w_lcs_chars.leadmultispace != NULL)
2276 {
2277 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002278 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2279 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002280 multispace_pos = 0;
2281 }
2282
2283 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2284 c = wp->w_lcs_chars.trail;
2285
2286 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2287 c = wp->w_lcs_chars.lead;
2288
zeertzjq2e7cba32022-06-10 15:30:32 +01002289 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002290 c = wp->w_lcs_chars.space;
2291
2292
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002293 if (!attr_pri)
2294 {
2295 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002296 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002297 saved_attr2 = char_attr; // save current attr
2298 }
2299 mb_c = c;
2300 if (enc_utf8 && utf_char2len(c) > 1)
2301 {
2302 mb_utf8 = TRUE;
2303 u8cc[0] = 0;
2304 c = 0xc0;
2305 }
2306 else
2307 mb_utf8 = FALSE;
2308 }
2309 }
2310
2311 // Handling of non-printable characters.
2312 if (!vim_isprintc(c))
2313 {
2314 // when getting a character from the file, we may have to
2315 // turn it into something else on the way to putting it
2316 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002317 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002318 {
2319 int tab_len = 0;
2320 long vcol_adjusted = vcol; // removed showbreak length
2321#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002322 char_u *sbr = get_showbreak_value(wp);
2323
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002324 // only adjust the tab_len, when at the first column
2325 // after the showbreak value was drawn
Bram Moolenaaree857022019-11-09 23:26:40 +01002326 if (*sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap)
2327 vcol_adjusted = vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002328#endif
2329 // tab amount depends on current column
2330#ifdef FEAT_VARTABS
2331 tab_len = tabstop_padding(vcol_adjusted,
2332 wp->w_buffer->b_p_ts,
2333 wp->w_buffer->b_p_vts_array) - 1;
2334#else
2335 tab_len = (int)wp->w_buffer->b_p_ts
2336 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2337#endif
2338
2339#ifdef FEAT_LINEBREAK
2340 if (!wp->w_p_lbr || !wp->w_p_list)
2341#endif
2342 // tab amount depends on current column
2343 n_extra = tab_len;
2344#ifdef FEAT_LINEBREAK
2345 else
2346 {
2347 char_u *p;
2348 int len;
2349 int i;
2350 int saved_nextra = n_extra;
2351
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002352# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002353 if (vcol_off > 0)
2354 // there are characters to conceal
2355 tab_len += vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002356
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002357 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002358 if (wp->w_p_list && wp->w_lcs_chars.tab1
2359 && old_boguscols > 0
2360 && n_extra > tab_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002361 tab_len += n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002362# endif
2363 // If n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002364 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002365 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002366 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002367 if (wp->w_lcs_chars.tab3)
2368 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002369 if (n_extra > 0)
2370 len += n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002371 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002372 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002373 if (p == NULL)
2374 n_extra = 0;
2375 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002376 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002377 vim_memset(p, ' ', len);
2378 p[len] = NUL;
2379 vim_free(p_extra_free);
2380 p_extra_free = p;
2381 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002382 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002383 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002384
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002385 if (*p == NUL)
2386 {
2387 tab_len = i;
2388 break;
2389 }
2390
2391 // if tab3 is given, use it for the last char
2392 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2393 lcs = wp->w_lcs_chars.tab3;
2394 p += mb_char2bytes(lcs, p);
2395 n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002396 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002397 }
2398 p_extra = p_extra_free;
2399# ifdef FEAT_CONCEAL
2400 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2401 // macro below, so need to adjust for that here
2402 if (vcol_off > 0)
2403 n_extra -= vcol_off;
2404# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002405 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002406 }
2407#endif
2408#ifdef FEAT_CONCEAL
2409 {
2410 int vc_saved = vcol_off;
2411
2412 // Tab alignment should be identical regardless of
2413 // 'conceallevel' value. So tab compensates of all
2414 // previous concealed characters, and thus resets
2415 // vcol_off and boguscols accumulated so far in the
2416 // line. Note that the tab can be longer than
2417 // 'tabstop' when there are concealed characters.
2418 FIX_FOR_BOGUSCOLS;
2419
2420 // Make sure, the highlighting for the tab char will be
2421 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002422 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002423 if (n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002424 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002425 tab_len += vc_saved;
2426 }
2427#endif
2428 mb_utf8 = FALSE; // don't draw as UTF-8
2429 if (wp->w_p_list)
2430 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002431 c = (n_extra == 0 && wp->w_lcs_chars.tab3)
2432 ? wp->w_lcs_chars.tab3
2433 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002434#ifdef FEAT_LINEBREAK
2435 if (wp->w_p_lbr)
2436 c_extra = NUL; // using p_extra from above
2437 else
2438#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01002439 c_extra = wp->w_lcs_chars.tab2;
2440 c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002441 n_attr = tab_len + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002442 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002443 saved_attr2 = char_attr; // save current attr
2444 mb_c = c;
2445 if (enc_utf8 && utf_char2len(c) > 1)
2446 {
2447 mb_utf8 = TRUE;
2448 u8cc[0] = 0;
2449 c = 0xc0;
2450 }
2451 }
2452 else
2453 {
2454 c_final = NUL;
2455 c_extra = ' ';
2456 c = ' ';
2457 }
2458 }
2459 else if (c == NUL
2460 && (wp->w_p_list
2461 || ((fromcol >= 0 || fromcol_prev >= 0)
2462 && tocol > vcol
2463 && VIsual_mode != Ctrl_V
2464 && (
2465# ifdef FEAT_RIGHTLEFT
2466 wp->w_p_rl ? (col >= 0) :
2467# endif
2468 (col < wp->w_width))
2469 && !(noinvcur
2470 && lnum == wp->w_cursor.lnum
2471 && (colnr_T)vcol == wp->w_virtcol)))
2472 && lcs_eol_one > 0)
2473 {
2474 // Display a '$' after the line or highlight an extra
2475 // character if the line break is included.
2476#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2477 // For a diff line the highlighting continues after the
2478 // "$".
2479 if (
2480# ifdef FEAT_DIFF
2481 diff_hlf == (hlf_T)0
2482# ifdef LINE_ATTR
2483 &&
2484# endif
2485# endif
2486# ifdef LINE_ATTR
2487 line_attr == 0
2488# endif
2489 )
2490#endif
2491 {
2492 // In virtualedit, visual selections may extend
2493 // beyond end of line.
2494 if (area_highlighting && virtual_active()
2495 && tocol != MAXCOL && vcol < tocol)
2496 n_extra = 0;
2497 else
2498 {
2499 p_extra = at_end_str;
2500 n_extra = 1;
2501 c_extra = NUL;
2502 c_final = NUL;
2503 }
2504 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002505 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2506 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002507 else
2508 c = ' ';
2509 lcs_eol_one = -1;
2510 --ptr; // put it back at the NUL
2511 if (!attr_pri)
2512 {
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002513 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002514 n_attr = 1;
2515 }
2516 mb_c = c;
2517 if (enc_utf8 && utf_char2len(c) > 1)
2518 {
2519 mb_utf8 = TRUE;
2520 u8cc[0] = 0;
2521 c = 0xc0;
2522 }
2523 else
2524 mb_utf8 = FALSE; // don't draw as UTF-8
2525 }
2526 else if (c != NUL)
2527 {
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002528 p_extra = transchar_buf(wp->w_buffer, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002529 if (n_extra == 0)
2530 n_extra = byte2cells(c) - 1;
2531#ifdef FEAT_RIGHTLEFT
2532 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
2533 rl_mirror(p_extra); // reverse "<12>"
2534#endif
2535 c_extra = NUL;
2536 c_final = NUL;
2537#ifdef FEAT_LINEBREAK
2538 if (wp->w_p_lbr)
2539 {
2540 char_u *p;
2541
2542 c = *p_extra;
2543 p = alloc(n_extra + 1);
2544 vim_memset(p, ' ', n_extra);
2545 STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1);
2546 p[n_extra] = NUL;
2547 vim_free(p_extra_free);
2548 p_extra_free = p_extra = p;
2549 }
2550 else
2551#endif
2552 {
2553 n_extra = byte2cells(c) - 1;
2554 c = *p_extra++;
2555 }
2556 if (!attr_pri)
2557 {
2558 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002559 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002560 saved_attr2 = char_attr; // save current attr
2561 }
2562 mb_utf8 = FALSE; // don't draw as UTF-8
2563 }
2564 else if (VIsual_active
2565 && (VIsual_mode == Ctrl_V
2566 || VIsual_mode == 'v')
2567 && virtual_active()
2568 && tocol != MAXCOL
2569 && vcol < tocol
2570 && (
2571#ifdef FEAT_RIGHTLEFT
2572 wp->w_p_rl ? (col >= 0) :
2573#endif
2574 (col < wp->w_width)))
2575 {
2576 c = ' ';
2577 --ptr; // put it back at the NUL
2578 }
2579#if defined(LINE_ATTR)
2580 else if ((
2581# ifdef FEAT_DIFF
2582 diff_hlf != (hlf_T)0 ||
2583# endif
2584# ifdef FEAT_TERMINAL
2585 win_attr != 0 ||
2586# endif
2587 line_attr != 0
2588 ) && (
2589# ifdef FEAT_RIGHTLEFT
2590 wp->w_p_rl ? (col >= 0) :
2591# endif
2592 (col
2593# ifdef FEAT_CONCEAL
2594 - boguscols
2595# endif
2596 < wp->w_width)))
2597 {
2598 // Highlight until the right side of the window
2599 c = ' ';
2600 --ptr; // put it back at the NUL
2601
2602 // Remember we do the char for line highlighting.
2603 ++did_line_attr;
2604
2605 // don't do search HL for the rest of the line
2606 if (line_attr != 0 && char_attr == search_attr
2607 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002608 || (wp->w_p_list &&
2609 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002610 char_attr = line_attr;
2611# ifdef FEAT_DIFF
2612 if (diff_hlf == HLF_TXD)
2613 {
2614 diff_hlf = HLF_CHD;
2615 if (vi_attr == 0 || char_attr != vi_attr)
2616 {
2617 char_attr = HL_ATTR(diff_hlf);
2618 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2619 && wp->w_p_culopt_flags != CULOPT_NBR
2620 && (!cul_screenline
2621 || (vcol >= left_curline_col
2622 && vcol <= right_curline_col)))
2623 char_attr = hl_combine_attr(
2624 char_attr, HL_ATTR(HLF_CUL));
2625 }
2626 }
2627# endif
2628# ifdef FEAT_TERMINAL
2629 if (win_attr != 0)
2630 {
2631 char_attr = win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002632 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2633 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002634 {
2635 if (!cul_screenline || (vcol >= left_curline_col
2636 && vcol <= right_curline_col))
2637 char_attr = hl_combine_attr(
2638 char_attr, HL_ATTR(HLF_CUL));
2639 }
2640 else if (line_attr)
2641 char_attr = hl_combine_attr(char_attr, line_attr);
2642 }
2643# endif
2644 }
2645#endif
2646 }
2647
2648#ifdef FEAT_CONCEAL
2649 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01002650 && (wp != curwin || lnum != wp->w_cursor.lnum
2651 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002652 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2653 && !(lnum_in_visual_area
2654 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2655 {
2656 char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01002657 if (((prev_syntax_id != syntax_seqnr
2658 && (syntax_flags & HL_CONCEAL) != 0)
2659 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002660 && (syn_get_sub_char() != NUL
2661 || (has_match_conc && match_conc)
2662 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002663 && wp->w_p_cole != 3)
2664 {
2665 // First time at this concealed item: display one
2666 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002667 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002668 c = match_conc;
2669 else if (syn_get_sub_char() != NUL)
2670 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01002671 else if (wp->w_lcs_chars.conceal != NUL)
2672 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002673 else
2674 c = ' ';
2675
2676 prev_syntax_id = syntax_seqnr;
2677
2678 if (n_extra > 0)
2679 vcol_off += n_extra;
2680 vcol += n_extra;
2681 if (wp->w_p_wrap && n_extra > 0)
2682 {
2683# ifdef FEAT_RIGHTLEFT
2684 if (wp->w_p_rl)
2685 {
2686 col -= n_extra;
2687 boguscols -= n_extra;
2688 }
2689 else
2690# endif
2691 {
2692 boguscols += n_extra;
2693 col += n_extra;
2694 }
2695 }
2696 n_extra = 0;
2697 n_attr = 0;
2698 }
2699 else if (n_skip == 0)
2700 {
2701 is_concealing = TRUE;
2702 n_skip = 1;
2703 }
2704 mb_c = c;
2705 if (enc_utf8 && utf_char2len(c) > 1)
2706 {
2707 mb_utf8 = TRUE;
2708 u8cc[0] = 0;
2709 c = 0xc0;
2710 }
2711 else
2712 mb_utf8 = FALSE; // don't draw as UTF-8
2713 }
2714 else
2715 {
2716 prev_syntax_id = 0;
2717 is_concealing = FALSE;
2718 }
2719
2720 if (n_skip > 0 && did_decrement_ptr)
2721 // not showing the '>', put pointer back to avoid getting stuck
2722 ++ptr;
2723
2724#endif // FEAT_CONCEAL
2725 }
2726
2727#ifdef FEAT_CONCEAL
2728 // In the cursor line and we may be concealing characters: correct
2729 // the cursor column when we reach its position.
2730 if (!did_wcol && draw_state == WL_LINE
2731 && wp == curwin && lnum == wp->w_cursor.lnum
2732 && conceal_cursor_line(wp)
2733 && (int)wp->w_virtcol <= vcol + n_skip)
2734 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002735# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002736 if (wp->w_p_rl)
2737 wp->w_wcol = wp->w_width - col + boguscols - 1;
2738 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002739# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002740 wp->w_wcol = col - boguscols;
2741 wp->w_wrow = row;
2742 did_wcol = TRUE;
2743 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002744# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01002745 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002746# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002747 }
2748#endif
2749
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002750 // Use "extra_attr", but don't override visual selection highlighting.
2751 // Don't use "extra_attr" until n_attr_skip is zero.
2752 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002753 && draw_state == WL_LINE
2754 && !attr_pri)
2755 {
2756#ifdef LINE_ATTR
2757 if (line_attr)
2758 char_attr = hl_combine_attr(extra_attr, line_attr);
2759 else
2760#endif
2761 char_attr = extra_attr;
2762 }
2763
2764#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2765 // XIM don't send preedit_start and preedit_end, but they send
2766 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
2767 // im_is_preediting() here.
2768 if (p_imst == IM_ON_THE_SPOT
2769 && xic != NULL
2770 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01002771 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002772 && !p_imdisable
2773 && im_is_preediting()
2774 && draw_state == WL_LINE)
2775 {
2776 colnr_T tcol;
2777
2778 if (preedit_end_col == MAXCOL)
2779 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
2780 else
2781 tcol = preedit_end_col;
2782 if ((long)preedit_start_col <= vcol && vcol < (long)tcol)
2783 {
2784 if (feedback_old_attr < 0)
2785 {
2786 feedback_col = 0;
2787 feedback_old_attr = char_attr;
2788 }
2789 char_attr = im_get_feedback_attr(feedback_col);
2790 if (char_attr < 0)
2791 char_attr = feedback_old_attr;
2792 feedback_col++;
2793 }
2794 else if (feedback_old_attr >= 0)
2795 {
2796 char_attr = feedback_old_attr;
2797 feedback_old_attr = -1;
2798 feedback_col = 0;
2799 }
2800 }
2801#endif
2802 // Handle the case where we are in column 0 but not on the first
2803 // character of the line and the user wants us to show us a
2804 // special character (via 'listchars' option "precedes:<char>".
2805 if (lcs_prec_todo != NUL
2806 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02002807 && (wp->w_p_wrap ?
2808 (wp->w_skipcol > 0 && row == 0) :
2809 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002810#ifdef FEAT_DIFF
2811 && filler_todo <= 0
2812#endif
2813 && draw_state > WL_NR
2814 && c != NUL)
2815 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002816 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002817 lcs_prec_todo = NUL;
2818 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2819 {
2820 // Double-width character being overwritten by the "precedes"
2821 // character, need to fill up half the character.
2822 c_extra = MB_FILLER_CHAR;
2823 c_final = NUL;
2824 n_extra = 1;
2825 n_attr = 2;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002826 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002827 }
2828 mb_c = c;
2829 if (enc_utf8 && utf_char2len(c) > 1)
2830 {
2831 mb_utf8 = TRUE;
2832 u8cc[0] = 0;
2833 c = 0xc0;
2834 }
2835 else
2836 mb_utf8 = FALSE; // don't draw as UTF-8
2837 if (!attr_pri)
2838 {
2839 saved_attr3 = char_attr; // save current attr
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002840 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002841 n_attr3 = 1;
2842 }
2843 }
2844
2845 // At end of the text line or just after the last character.
2846 if ((c == NUL
2847#if defined(LINE_ATTR)
2848 || did_line_attr == 1
2849#endif
2850 ) && eol_hl_off == 0)
2851 {
2852#ifdef FEAT_SEARCH_EXTRA
2853 // flag to indicate whether prevcol equals startcol of search_hl or
2854 // one of the matches
2855 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
2856 (long)(ptr - line) - (c == NUL));
2857#endif
2858 // Invert at least one char, used for Visual and empty line or
2859 // highlight match at end of line. If it's beyond the last
2860 // char on the screen, just overwrite that one (tricky!) Not
2861 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002862 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002863 && ((area_attr != 0 && vcol == fromcol
2864 && (VIsual_mode != Ctrl_V
2865 || lnum == VIsual.lnum
2866 || lnum == curwin->w_cursor.lnum)
2867 && c == NUL)
2868#ifdef FEAT_SEARCH_EXTRA
2869 // highlight 'hlsearch' match at end of line
2870 || (prevcol_hl_flag
2871# ifdef FEAT_SYN_HL
2872 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
2873 && !(wp == curwin && VIsual_active))
2874# endif
2875# ifdef FEAT_DIFF
2876 && diff_hlf == (hlf_T)0
2877# endif
2878# if defined(LINE_ATTR)
2879 && did_line_attr <= 1
2880# endif
2881 )
2882#endif
2883 ))
2884 {
2885 int n = 0;
2886
2887#ifdef FEAT_RIGHTLEFT
2888 if (wp->w_p_rl)
2889 {
2890 if (col < 0)
2891 n = 1;
2892 }
2893 else
2894#endif
2895 {
2896 if (col >= wp->w_width)
2897 n = -1;
2898 }
2899 if (n != 0)
2900 {
2901 // At the window boundary, highlight the last character
2902 // instead (better than nothing).
2903 off += n;
2904 col += n;
2905 }
2906 else
2907 {
2908 // Add a blank character to highlight.
2909 ScreenLines[off] = ' ';
2910 if (enc_utf8)
2911 ScreenLinesUC[off] = 0;
2912 }
2913#ifdef FEAT_SEARCH_EXTRA
2914 if (area_attr == 0)
2915 {
2916 // Use attributes from match with highest priority among
2917 // 'search_hl' and the match list.
2918 get_search_match_hl(wp, &screen_search_hl,
2919 (long)(ptr - line), &char_attr);
2920 }
2921#endif
2922 ScreenAttrs[off] = char_attr;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002923 ScreenCols[off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002924#ifdef FEAT_RIGHTLEFT
2925 if (wp->w_p_rl)
2926 {
2927 --col;
2928 --off;
2929 }
2930 else
2931#endif
2932 {
2933 ++col;
2934 ++off;
2935 }
2936 ++vcol;
2937 eol_hl_off = 1;
2938 }
2939 }
2940
2941 // At end of the text line.
2942 if (c == NUL)
2943 {
2944#ifdef FEAT_SYN_HL
2945 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
2946 if (wp->w_p_wrap)
2947 v = wp->w_skipcol;
2948 else
2949 v = wp->w_leftcol;
2950
2951 // check if line ends before left margin
2952 if (vcol < v + col - win_col_off(wp))
2953 vcol = v + col - win_col_off(wp);
2954#ifdef FEAT_CONCEAL
2955 // Get rid of the boguscols now, we want to draw until the right
2956 // edge for 'cursorcolumn'.
2957 col -= boguscols;
2958 boguscols = 0;
2959#endif
2960
2961 if (draw_color_col)
2962 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2963
2964 if (((wp->w_p_cuc
2965 && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off
2966 && (int)wp->w_virtcol <
=?UTF-8?q?Dundar=20G=C3=B6c?=d5cec1f2022-01-29 15:19:23 +00002967 (long)wp->w_width * (row - startrow + 1) + v
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002968 && lnum != wp->w_cursor.lnum)
2969 || draw_color_col
2970 || win_attr != 0)
2971# ifdef FEAT_RIGHTLEFT
2972 && !wp->w_p_rl
2973# endif
2974 )
2975 {
2976 int rightmost_vcol = 0;
2977 int i;
2978
2979 if (wp->w_p_cuc)
2980 rightmost_vcol = wp->w_virtcol;
2981 if (draw_color_col)
2982 // determine rightmost colorcolumn to possibly draw
2983 for (i = 0; color_cols[i] >= 0; ++i)
2984 if (rightmost_vcol < color_cols[i])
2985 rightmost_vcol = color_cols[i];
2986
2987 while (col < wp->w_width)
2988 {
2989 ScreenLines[off] = ' ';
2990 if (enc_utf8)
2991 ScreenLinesUC[off] = 0;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002992 ScreenCols[off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002993 ++col;
2994 if (draw_color_col)
2995 draw_color_col = advance_color_col(VCOL_HLC,
2996 &color_cols);
2997
2998 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
2999 ScreenAttrs[off++] = HL_ATTR(HLF_CUC);
3000 else if (draw_color_col && VCOL_HLC == *color_cols)
3001 ScreenAttrs[off++] = HL_ATTR(HLF_MC);
3002 else
3003 ScreenAttrs[off++] = win_attr;
3004
3005 if (VCOL_HLC >= rightmost_vcol && win_attr == 0)
3006 break;
3007
3008 ++vcol;
3009 }
3010 }
3011#endif
3012
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01003013 screen_line(wp, screen_row, wp->w_wincol, col,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00003014 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003015 row++;
3016
3017 // Update w_cline_height and w_cline_folded if the cursor line was
3018 // updated (saves a call to plines() later).
3019 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3020 {
3021 curwin->w_cline_row = startrow;
3022 curwin->w_cline_height = row - startrow;
3023#ifdef FEAT_FOLDING
3024 curwin->w_cline_folded = FALSE;
3025#endif
3026 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3027 }
3028
3029 break;
3030 }
3031
3032 // Show "extends" character from 'listchars' if beyond the line end and
3033 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003034 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003035 && draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003036 && wp->w_p_list
3037 && !wp->w_p_wrap
3038#ifdef FEAT_DIFF
3039 && filler_todo <= 0
3040#endif
3041 && (
3042#ifdef FEAT_RIGHTLEFT
3043 wp->w_p_rl ? col == 0 :
3044#endif
3045 col == wp->w_width - 1)
3046 && (*ptr != NUL
3047 || (wp->w_p_list && lcs_eol_one > 0)
3048 || (n_extra && (c_extra != NUL || *p_extra != NUL))))
3049 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003050 c = wp->w_lcs_chars.ext;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01003051 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003052 mb_c = c;
3053 if (enc_utf8 && utf_char2len(c) > 1)
3054 {
3055 mb_utf8 = TRUE;
3056 u8cc[0] = 0;
3057 c = 0xc0;
3058 }
3059 else
3060 mb_utf8 = FALSE;
3061 }
3062
3063#ifdef FEAT_SYN_HL
3064 // advance to the next 'colorcolumn'
3065 if (draw_color_col)
3066 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
3067
3068 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3069 // highlight the cursor position itself.
3070 // Also highlight the 'colorcolumn' if it is different than
3071 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003072 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3073 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003074 vcol_save_attr = -1;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003075 if (((draw_state == WL_LINE ||
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003076 draw_state == WL_BRI ||
3077 draw_state == WL_SBR) && !lnum_in_visual_area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003078 && search_attr == 0 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003079# ifdef FEAT_DIFF
3080 && filler_todo <= 0
3081# endif
3082 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003083 {
3084 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3085 && lnum != wp->w_cursor.lnum)
3086 {
3087 vcol_save_attr = char_attr;
3088 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUC));
3089 }
3090 else if (draw_color_col && VCOL_HLC == *color_cols)
3091 {
3092 vcol_save_attr = char_attr;
3093 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_MC));
3094 }
3095 }
3096#endif
3097
3098 // Store character to be displayed.
3099 // Skip characters that are left of the screen for 'nowrap'.
3100 vcol_prev = vcol;
3101 if (draw_state < WL_LINE || n_skip <= 0)
3102 {
3103 // Store the character.
3104#if defined(FEAT_RIGHTLEFT)
3105 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3106 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003107 // A double-wide character is: put first half in left cell.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003108 --off;
3109 --col;
3110 }
3111#endif
3112 ScreenLines[off] = c;
3113 if (enc_dbcs == DBCS_JPNU)
3114 {
3115 if ((mb_c & 0xff00) == 0x8e00)
3116 ScreenLines[off] = 0x8e;
3117 ScreenLines2[off] = mb_c & 0xff;
3118 }
3119 else if (enc_utf8)
3120 {
3121 if (mb_utf8)
3122 {
3123 int i;
3124
3125 ScreenLinesUC[off] = mb_c;
3126 if ((c & 0xff) == 0)
3127 ScreenLines[off] = 0x80; // avoid storing zero
3128 for (i = 0; i < Screen_mco; ++i)
3129 {
3130 ScreenLinesC[i][off] = u8cc[i];
3131 if (u8cc[i] == 0)
3132 break;
3133 }
3134 }
3135 else
3136 ScreenLinesUC[off] = 0;
3137 }
3138 if (multi_attr)
3139 {
3140 ScreenAttrs[off] = multi_attr;
3141 multi_attr = 0;
3142 }
3143 else
3144 ScreenAttrs[off] = char_attr;
3145
Bram Moolenaarb9081882022-07-09 04:56:24 +01003146 ScreenCols[off] = (colnr_T)(prev_ptr - line);
3147
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003148 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3149 {
3150 // Need to fill two screen columns.
3151 ++off;
3152 ++col;
3153 if (enc_utf8)
3154 // UTF-8: Put a 0 in the second screen char.
3155 ScreenLines[off] = 0;
3156 else
3157 // DBCS: Put second byte in the second screen char.
3158 ScreenLines[off] = mb_c & 0xff;
3159 if (draw_state > WL_NR
3160#ifdef FEAT_DIFF
3161 && filler_todo <= 0
3162#endif
3163 )
3164 ++vcol;
3165 // When "tocol" is halfway a character, set it to the end of
3166 // the character, otherwise highlighting won't stop.
3167 if (tocol == vcol)
3168 ++tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003169
3170 ScreenCols[off] = (colnr_T)(prev_ptr - line);
3171
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003172#ifdef FEAT_RIGHTLEFT
3173 if (wp->w_p_rl)
3174 {
3175 // now it's time to backup one cell
3176 --off;
3177 --col;
3178 }
3179#endif
3180 }
3181#ifdef FEAT_RIGHTLEFT
3182 if (wp->w_p_rl)
3183 {
3184 --off;
3185 --col;
3186 }
3187 else
3188#endif
3189 {
3190 ++off;
3191 ++col;
3192 }
3193 }
3194#ifdef FEAT_CONCEAL
3195 else if (wp->w_p_cole > 0 && is_concealing)
3196 {
3197 --n_skip;
3198 ++vcol_off;
3199 if (n_extra > 0)
3200 vcol_off += n_extra;
3201 if (wp->w_p_wrap)
3202 {
3203 // Special voodoo required if 'wrap' is on.
3204 //
3205 // Advance the column indicator to force the line
3206 // drawing to wrap early. This will make the line
3207 // take up the same screen space when parts are concealed,
3208 // so that cursor line computations aren't messed up.
3209 //
3210 // To avoid the fictitious advance of 'col' causing
3211 // trailing junk to be written out of the screen line
3212 // we are building, 'boguscols' keeps track of the number
3213 // of bad columns we have advanced.
3214 if (n_extra > 0)
3215 {
3216 vcol += n_extra;
3217# ifdef FEAT_RIGHTLEFT
3218 if (wp->w_p_rl)
3219 {
3220 col -= n_extra;
3221 boguscols -= n_extra;
3222 }
3223 else
3224# endif
3225 {
3226 col += n_extra;
3227 boguscols += n_extra;
3228 }
3229 n_extra = 0;
3230 n_attr = 0;
3231 }
3232
3233
3234 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3235 {
3236 // Need to fill two screen columns.
3237# ifdef FEAT_RIGHTLEFT
3238 if (wp->w_p_rl)
3239 {
3240 --boguscols;
3241 --col;
3242 }
3243 else
3244# endif
3245 {
3246 ++boguscols;
3247 ++col;
3248 }
3249 }
3250
3251# ifdef FEAT_RIGHTLEFT
3252 if (wp->w_p_rl)
3253 {
3254 --boguscols;
3255 --col;
3256 }
3257 else
3258# endif
3259 {
3260 ++boguscols;
3261 ++col;
3262 }
3263 }
3264 else
3265 {
3266 if (n_extra > 0)
3267 {
3268 vcol += n_extra;
3269 n_extra = 0;
3270 n_attr = 0;
3271 }
3272 }
3273
3274 }
3275#endif // FEAT_CONCEAL
3276 else
3277 --n_skip;
3278
3279 // Only advance the "vcol" when after the 'number' or 'relativenumber'
3280 // column.
3281 if (draw_state > WL_NR
3282#ifdef FEAT_DIFF
3283 && filler_todo <= 0
3284#endif
3285 )
3286 ++vcol;
3287
3288#ifdef FEAT_SYN_HL
3289 if (vcol_save_attr >= 0)
3290 char_attr = vcol_save_attr;
3291#endif
3292
3293 // restore attributes after "predeces" in 'listchars'
3294 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3295 char_attr = saved_attr3;
3296
3297 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003298 if (n_attr > 0 && draw_state == WL_LINE
3299 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003300 char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003301 if (n_attr_skip > 0)
3302 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003303
3304 // At end of screen line and there is more to come: Display the line
3305 // so far. If there is no more to display it is caught above.
3306 if ((
3307#ifdef FEAT_RIGHTLEFT
3308 wp->w_p_rl ? (col < 0) :
3309#endif
3310 (col >= wp->w_width))
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003311 && (draw_state != WL_LINE
3312 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003313#ifdef FEAT_DIFF
3314 || filler_todo > 0
3315#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003316#ifdef FEAT_PROP_POPUP
3317 || text_prop_follows
3318#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003319 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
3320 && p_extra != at_end_str)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003321 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL)))
3322 )
3323 {
3324#ifdef FEAT_CONCEAL
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01003325 screen_line(wp, screen_row, wp->w_wincol, col - boguscols,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00003326 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003327 boguscols = 0;
3328#else
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01003329 screen_line(wp, screen_row, wp->w_wincol, col,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00003330 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003331#endif
3332 ++row;
3333 ++screen_row;
3334
3335 // When not wrapping and finished diff lines, or when displayed
3336 // '$' and highlighting until last column, break here.
3337 if ((!wp->w_p_wrap
3338#ifdef FEAT_DIFF
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003339 && filler_todo <= 0
3340#endif
3341#ifdef FEAT_PROP_POPUP
3342 && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003343#endif
3344 ) || lcs_eol_one == -1)
3345 break;
3346
3347 // When the window is too narrow draw all "@" lines.
3348 if (draw_state != WL_LINE
3349#ifdef FEAT_DIFF
3350 && filler_todo <= 0
3351#endif
3352 )
3353 {
3354 win_draw_end(wp, '@', ' ', TRUE, row, wp->w_height, HLF_AT);
3355 draw_vsep_win(wp, row);
3356 row = endrow;
3357 }
3358
3359 // When line got too long for screen break here.
3360 if (row == endrow)
3361 {
3362 ++row;
3363 break;
3364 }
3365
3366 if (screen_cur_row == screen_row - 1
3367#ifdef FEAT_DIFF
3368 && filler_todo <= 0
3369#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003370#ifdef FEAT_PROP_POPUP
3371 && !text_prop_follows
3372#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003373 && wp->w_width == Columns)
3374 {
3375 // Remember that the line wraps, used for modeless copy.
3376 LineWraps[screen_row - 1] = TRUE;
3377
3378 // Special trick to make copy/paste of wrapped lines work with
3379 // xterm/screen: write an extra character beyond the end of
3380 // the line. This will work with all terminal types
3381 // (regardless of the xn,am settings).
3382 // Only do this on a fast tty.
3383 // Only do this if the cursor is on the current line
3384 // (something has been written in it).
3385 // Don't do this for the GUI.
3386 // Don't do this for double-width characters.
3387 // Don't do this for a window not at the right screen border.
3388 if (p_tf
3389#ifdef FEAT_GUI
3390 && !gui.in_use
3391#endif
3392 && !(has_mbyte
3393 && ((*mb_off2cells)(LineOffset[screen_row],
3394 LineOffset[screen_row] + screen_Columns)
3395 == 2
3396 || (*mb_off2cells)(LineOffset[screen_row - 1]
3397 + (int)Columns - 2,
3398 LineOffset[screen_row] + screen_Columns)
3399 == 2)))
3400 {
3401 // First make sure we are at the end of the screen line,
3402 // then output the same character again to let the
3403 // terminal know about the wrap. If the terminal doesn't
3404 // auto-wrap, we overwrite the character.
3405 if (screen_cur_col != wp->w_width)
3406 screen_char(LineOffset[screen_row - 1]
3407 + (unsigned)Columns - 1,
3408 screen_row - 1, (int)(Columns - 1));
3409
3410 // When there is a multi-byte character, just output a
3411 // space to keep it simple.
3412 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
3413 screen_row - 1] + (Columns - 1)]) > 1)
3414 out_char(' ');
3415 else
3416 out_char(ScreenLines[LineOffset[screen_row - 1]
3417 + (Columns - 1)]);
3418 // force a redraw of the first char on the next line
3419 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1;
3420 screen_start(); // don't know where cursor is now
3421 }
3422 }
3423
3424 col = 0;
3425 off = (unsigned)(current_ScreenLine - ScreenLines);
3426#ifdef FEAT_RIGHTLEFT
3427 if (wp->w_p_rl)
3428 {
3429 col = wp->w_width - 1; // col is not used if breaking!
3430 off += col;
3431 }
3432#endif
3433
3434 // reset the drawing state for the start of a wrapped line
3435 draw_state = WL_START;
3436 saved_n_extra = n_extra;
3437 saved_p_extra = p_extra;
3438 saved_c_extra = c_extra;
3439 saved_c_final = c_final;
3440#ifdef FEAT_SYN_HL
3441 if (!(cul_screenline
3442# ifdef FEAT_DIFF
Bram Moolenaare7705982020-04-21 22:23:15 +02003443 && diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003444# endif
Bram Moolenaare7705982020-04-21 22:23:15 +02003445 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003446 saved_char_attr = char_attr;
3447 else
3448#endif
3449 saved_char_attr = 0;
3450 n_extra = 0;
Bram Moolenaareed9d462021-02-15 20:38:25 +01003451 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003452#ifdef FEAT_LINEBREAK
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003453 if (!dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003454# ifdef FEAT_DIFF
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003455 && filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003456# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003457 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003458 need_showbreak = TRUE;
3459#endif
3460#ifdef FEAT_DIFF
3461 --filler_todo;
3462 // When the filler lines are actually below the last line of the
3463 // file, don't draw the line itself, break here.
3464 if (filler_todo == 0 && wp->w_botfill)
3465 break;
3466#endif
3467 }
3468
3469 } // for every character in the line
3470
3471#ifdef FEAT_SPELL
3472 // After an empty line check first word for capital.
3473 if (*skipwhite(line) == NUL)
3474 {
3475 capcol_lnum = lnum + 1;
3476 cap_col = 0;
3477 }
3478#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003479#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003480 vim_free(text_props);
3481 vim_free(text_prop_idxs);
3482#endif
3483
3484 vim_free(p_extra_free);
3485 return row;
3486}