blob: 66c3a39b452d4d4ad4d03a7f94ecc3795d440d58 [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
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 * screen.c: code for displaying on the screen
12 *
13 * Output to the screen (console, terminal emulator or GUI window) is minimized
14 * by remembering what is already on the screen, and only updating the parts
15 * that changed.
16 *
17 * ScreenLines[off] Contains a copy of the whole screen, as it is currently
18 * displayed (excluding text written by external commands).
19 * ScreenAttrs[off] Contains the associated attributes.
20 * LineOffset[row] Contains the offset into ScreenLines*[] and ScreenAttrs[]
21 * for each line.
22 * LineWraps[row] Flag for each line whether it wraps to the next line.
23 *
24 * For double-byte characters, two consecutive bytes in ScreenLines[] can form
25 * one character which occupies two display cells.
26 * For UTF-8 a multi-byte character is converted to Unicode and stored in
27 * ScreenLinesUC[]. ScreenLines[] contains the first byte only. For an ASCII
Bram Moolenaar70c49c12010-03-23 15:36:35 +010028 * character without composing chars ScreenLinesUC[] will be 0 and
29 * ScreenLinesC[][] is not used. When the character occupies two display
30 * cells the next byte in ScreenLines[] is 0.
Bram Moolenaar362e1a32006-03-06 23:29:24 +000031 * ScreenLinesC[][] contain up to 'maxcombine' composing characters
Bram Moolenaar70c49c12010-03-23 15:36:35 +010032 * (drawn on top of the first character). There is 0 after the last one used.
Bram Moolenaar071d4272004-06-13 20:20:40 +000033 * ScreenLines2[] is only used for euc-jp to store the second byte if the
34 * first byte is 0x8e (single-width character).
35 *
36 * The screen_*() functions write to the screen and handle updating
37 * ScreenLines[].
38 *
39 * update_screen() is the function that updates all windows and status lines.
40 * It is called form the main loop when must_redraw is non-zero. It may be
Bram Moolenaar2c7a7632007-05-10 18:19:11 +000041 * called from other places when an immediate screen update is needed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000042 *
43 * The part of the buffer that is displayed in a window is set with:
44 * - w_topline (first buffer line in window)
Bram Moolenaarea389e92014-05-28 21:40:52 +020045 * - w_topfill (filler lines above the first line)
Bram Moolenaar071d4272004-06-13 20:20:40 +000046 * - w_leftcol (leftmost window cell in window),
47 * - w_skipcol (skipped window cells of first line)
48 *
49 * Commands that only move the cursor around in a window, do not need to take
50 * action to update the display. The main loop will check if w_topline is
51 * valid and update it (scroll the window) when needed.
52 *
53 * Commands that scroll a window change w_topline and must call
54 * check_cursor() to move the cursor into the visible part of the window, and
55 * call redraw_later(VALID) to have the window displayed by update_screen()
56 * later.
57 *
58 * Commands that change text in the buffer must call changed_bytes() or
59 * changed_lines() to mark the area that changed and will require updating
60 * later. The main loop will call update_screen(), which will update each
61 * window that shows the changed buffer. This assumes text above the change
62 * can remain displayed as it is. Text after the change may need updating for
63 * scrolling, folding and syntax highlighting.
64 *
65 * Commands that change how a window is displayed (e.g., setting 'list') or
66 * invalidate the contents of a window in another way (e.g., change fold
67 * settings), must call redraw_later(NOT_VALID) to have the whole window
68 * redisplayed by update_screen() later.
69 *
70 * Commands that change how a buffer is displayed (e.g., setting 'tabstop')
71 * must call redraw_curbuf_later(NOT_VALID) to have all the windows for the
72 * buffer redisplayed by update_screen() later.
73 *
Bram Moolenaar600dddc2006-03-12 22:05:10 +000074 * Commands that change highlighting and possibly cause a scroll too must call
75 * redraw_later(SOME_VALID) to update the whole window but still use scrolling
76 * to avoid redrawing everything. But the length of displayed lines must not
77 * change, use NOT_VALID then.
78 *
Bram Moolenaar071d4272004-06-13 20:20:40 +000079 * Commands that move the window position must call redraw_later(NOT_VALID).
80 * TODO: should minimize redrawing by scrolling when possible.
81 *
82 * Commands that change everything (e.g., resizing the screen) must call
83 * redraw_all_later(NOT_VALID) or redraw_all_later(CLEAR).
84 *
85 * Things that are handled indirectly:
86 * - When messages scroll the screen up, msg_scrolled will be set and
87 * update_screen() called to redraw.
88 */
89
90#include "vim.h"
91
Bram Moolenaar5641f382012-06-13 18:06:36 +020092#define MB_FILLER_CHAR '<' /* character used when a double-width character
93 * doesn't fit. */
94
Bram Moolenaar071d4272004-06-13 20:20:40 +000095/*
96 * The attributes that are actually active for writing to the screen.
97 */
98static int screen_attr = 0;
99
100/*
101 * Positioning the cursor is reduced by remembering the last position.
102 * Mostly used by windgoto() and screen_char().
103 */
104static int screen_cur_row, screen_cur_col; /* last known cursor position */
105
106#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaar071d4272004-06-13 20:20:40 +0000107static match_T search_hl; /* used for 'hlsearch' highlight matching */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000108#endif
109
110#ifdef FEAT_FOLDING
111static foldinfo_T win_foldinfo; /* info for 'foldcolumn' */
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +0100112static int compute_foldcolumn(win_T *wp, int col);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000113#endif
114
Bram Moolenaar80dd3f92017-07-19 12:51:52 +0200115/* Flag that is set when drawing for a callback, not from the main command
116 * loop. */
117static int redrawing_for_callback = 0;
118
Bram Moolenaar071d4272004-06-13 20:20:40 +0000119/*
120 * Buffer for one screen line (characters and attributes).
121 */
122static schar_T *current_ScreenLine;
123
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200124#ifdef FEAT_TEXT_PROP
125static void update_popups(void);
126#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +0100127static void win_update(win_T *wp);
Bram Moolenaar6ba3ec12018-06-16 15:32:38 +0200128static void win_redr_status(win_T *wp, int ignore_pum);
Bram Moolenaar8ee4c012019-03-29 18:08:18 +0100129static void win_draw_end(win_T *wp, int c1, int c2, int draw_margin, int row, int endrow, hlf_T hl);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000130#ifdef FEAT_FOLDING
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +0100131static void fold_line(win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T lnum, int row);
132static void fill_foldcolumn(char_u *p, win_T *wp, int closed, linenr_T lnum);
133static void copy_text_attr(int off, char_u *buf, int len, int attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000134#endif
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +0200135static int win_line(win_T *, linenr_T, int, int, int nochange, int number_only);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +0100136static void draw_vsep_win(win_T *wp, int row);
Bram Moolenaar238a5642006-02-21 22:12:05 +0000137#ifdef FEAT_STL_OPT
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +0100138static void redraw_custom_statusline(win_T *wp);
Bram Moolenaar238a5642006-02-21 22:12:05 +0000139#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000140#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaarde993ea2014-06-17 23:18:01 +0200141# define SEARCH_HL_PRIORITY 0
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +0100142static void start_search_hl(void);
143static void end_search_hl(void);
144static void init_search_hl(win_T *wp);
145static void prepare_search_hl(win_T *wp, linenr_T lnum);
146static void next_search_hl(win_T *win, match_T *shl, linenr_T lnum, colnr_T mincol, matchitem_T *cur);
147static int next_search_hl_pos(match_T *shl, linenr_T lnum, posmatch_T *pos, colnr_T mincol);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000148#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +0100149static void screen_char(unsigned off, int row, int col);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +0100150static void screen_char_2(unsigned off, int row, int col);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +0100151static void screenclear2(void);
Bram Moolenaarcfce7172017-08-17 20:31:48 +0200152static void lineclear(unsigned off, int width, int attr);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +0100153static void lineinvalid(unsigned off, int width);
Bram Moolenaarcfce7172017-08-17 20:31:48 +0200154static int win_do_lines(win_T *wp, int row, int line_count, int mayclear, int del, int clear_attr);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +0100155static void win_rest_invalid(win_T *wp);
156static void msg_pos_mode(void);
157static void recording_mode(int attr);
Bram Moolenaar3633cf52017-07-31 22:29:35 +0200158static int fillchar_status(int *attr, win_T *wp);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +0100159static int fillchar_vsep(int *attr);
Bram Moolenaar1b9645d2017-09-17 23:03:31 +0200160#ifdef FEAT_MENU
161static void redraw_win_toolbar(win_T *wp);
162#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000163#ifdef FEAT_STL_OPT
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +0100164static void win_redr_custom(win_T *wp, int draw_ruler);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000165#endif
166#ifdef FEAT_CMDL_INFO
Bram Moolenaar491ac282018-06-17 14:47:55 +0200167static void win_redr_ruler(win_T *wp, int always, int ignore_pum);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000168#endif
169
Bram Moolenaar071d4272004-06-13 20:20:40 +0000170/* Ugly global: overrule attribute used by screen_char() */
171static int screen_char_attr = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000172
Bram Moolenaar06f1ed22017-06-18 22:41:03 +0200173#if defined(FEAT_SYN_HL) && defined(FEAT_RELTIME)
174/* Can limit syntax highlight time to 'redrawtime'. */
175# define SYN_TIME_LIMIT 1
176#endif
177
Bram Moolenaarc0aa4822017-07-16 14:04:29 +0200178#ifdef FEAT_RIGHTLEFT
179# define HAS_RIGHTLEFT(x) x
180#else
181# define HAS_RIGHTLEFT(x) FALSE
182#endif
183
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200184// flags for screen_line()
185#define SLF_RIGHTLEFT 1
186#define SLF_POPUP 2
187
Bram Moolenaar071d4272004-06-13 20:20:40 +0000188/*
189 * Redraw the current window later, with update_screen(type).
190 * Set must_redraw only if not already set to a higher value.
Bram Moolenaarae654382019-01-17 21:09:05 +0100191 * E.g. if must_redraw is CLEAR, type NOT_VALID will do nothing.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000192 */
193 void
Bram Moolenaar05540972016-01-30 20:31:25 +0100194redraw_later(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000195{
196 redraw_win_later(curwin, type);
197}
198
199 void
Bram Moolenaar05540972016-01-30 20:31:25 +0100200redraw_win_later(
201 win_T *wp,
202 int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000203{
Bram Moolenaar4f198282017-10-23 21:53:30 +0200204 if (!exiting && wp->w_redr_type < type)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000205 {
206 wp->w_redr_type = type;
207 if (type >= NOT_VALID)
208 wp->w_lines_valid = 0;
209 if (must_redraw < type) /* must_redraw is the maximum of all windows */
210 must_redraw = type;
211 }
212}
213
214/*
215 * Force a complete redraw later. Also resets the highlighting. To be used
216 * after executing a shell command that messes up the screen.
217 */
218 void
Bram Moolenaar05540972016-01-30 20:31:25 +0100219redraw_later_clear(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000220{
221 redraw_all_later(CLEAR);
Bram Moolenaar4c3f5362006-04-11 21:38:50 +0000222#ifdef FEAT_GUI
223 if (gui.in_use)
224 /* Use a code that will reset gui.highlight_mask in
225 * gui_stop_highlight(). */
226 screen_attr = HL_ALL + 1;
227 else
228#endif
229 /* Use attributes that is very unlikely to appear in text. */
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +0200230 screen_attr = HL_BOLD | HL_UNDERLINE | HL_INVERSE | HL_STRIKETHROUGH;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000231}
232
233/*
234 * Mark all windows to be redrawn later.
235 */
236 void
Bram Moolenaar05540972016-01-30 20:31:25 +0100237redraw_all_later(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000238{
239 win_T *wp;
240
241 FOR_ALL_WINDOWS(wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000242 redraw_win_later(wp, type);
Bram Moolenaar04b4e1a2019-01-06 22:22:07 +0100243 // This may be needed when switching tabs.
244 if (must_redraw < type)
245 must_redraw = type;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000246}
247
248/*
Bram Moolenaar75c50c42005-06-04 22:06:24 +0000249 * Mark all windows that are editing the current buffer to be updated later.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000250 */
251 void
Bram Moolenaar05540972016-01-30 20:31:25 +0100252redraw_curbuf_later(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000253{
254 redraw_buf_later(curbuf, type);
255}
256
257 void
Bram Moolenaar05540972016-01-30 20:31:25 +0100258redraw_buf_later(buf_T *buf, int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000259{
260 win_T *wp;
261
262 FOR_ALL_WINDOWS(wp)
263 {
264 if (wp->w_buffer == buf)
265 redraw_win_later(wp, type);
266 }
267}
268
Bram Moolenaar113e1072019-01-20 15:30:40 +0100269#if defined(FEAT_SIGNS) || defined(PROTO)
Bram Moolenaar29ae3772017-04-30 19:39:39 +0200270 void
Bram Moolenaar27a472c2019-01-09 21:47:30 +0100271redraw_buf_line_later(buf_T *buf, linenr_T lnum)
272{
273 win_T *wp;
274
275 FOR_ALL_WINDOWS(wp)
276 if (wp->w_buffer == buf && lnum >= wp->w_topline
277 && lnum < wp->w_botline)
278 redrawWinline(wp, lnum);
279}
Bram Moolenaar113e1072019-01-20 15:30:40 +0100280#endif
Bram Moolenaar27a472c2019-01-09 21:47:30 +0100281
Bram Moolenaar113e1072019-01-20 15:30:40 +0100282#if defined(FEAT_JOB_CHANNEL) || defined(PROTO)
Bram Moolenaar27a472c2019-01-09 21:47:30 +0100283 void
Bram Moolenaar29ae3772017-04-30 19:39:39 +0200284redraw_buf_and_status_later(buf_T *buf, int type)
285{
286 win_T *wp;
287
Bram Moolenaar85dad2c2017-07-12 21:12:43 +0200288#ifdef FEAT_WILDMENU
Bram Moolenaar86033562017-07-12 20:24:41 +0200289 if (wild_menu_showing != 0)
290 /* Don't redraw while the command line completion is displayed, it
291 * would disappear. */
292 return;
Bram Moolenaar85dad2c2017-07-12 21:12:43 +0200293#endif
Bram Moolenaar29ae3772017-04-30 19:39:39 +0200294 FOR_ALL_WINDOWS(wp)
295 {
296 if (wp->w_buffer == buf)
297 {
298 redraw_win_later(wp, type);
299 wp->w_redr_status = TRUE;
300 }
301 }
302}
Bram Moolenaar113e1072019-01-20 15:30:40 +0100303#endif
Bram Moolenaar29ae3772017-04-30 19:39:39 +0200304
Bram Moolenaar113e1072019-01-20 15:30:40 +0100305#if defined(FEAT_TERMRESPONSE) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000306/*
Bram Moolenaar2951b772013-07-03 12:45:31 +0200307 * Redraw as soon as possible. When the command line is not scrolled redraw
308 * right away and restore what was on the command line.
309 * Return a code indicating what happened.
310 */
311 int
Bram Moolenaar05540972016-01-30 20:31:25 +0100312redraw_asap(int type)
Bram Moolenaar2951b772013-07-03 12:45:31 +0200313{
314 int rows;
Bram Moolenaar5f95f282015-07-25 22:53:00 +0200315 int cols = screen_Columns;
Bram Moolenaar2951b772013-07-03 12:45:31 +0200316 int r;
317 int ret = 0;
Bram Moolenaare1fc4e22013-07-03 13:29:58 +0200318 schar_T *screenline; /* copy from ScreenLines[] */
319 sattr_T *screenattr; /* copy from ScreenAttrs[] */
Bram Moolenaar2951b772013-07-03 12:45:31 +0200320 int i;
Bram Moolenaare1fc4e22013-07-03 13:29:58 +0200321 u8char_T *screenlineUC = NULL; /* copy from ScreenLinesUC[] */
Bram Moolenaar2951b772013-07-03 12:45:31 +0200322 u8char_T *screenlineC[MAX_MCO]; /* copy from ScreenLinesC[][] */
Bram Moolenaare1fc4e22013-07-03 13:29:58 +0200323 schar_T *screenline2 = NULL; /* copy from ScreenLines2[] */
Bram Moolenaar2951b772013-07-03 12:45:31 +0200324
325 redraw_later(type);
Bram Moolenaar5f95f282015-07-25 22:53:00 +0200326 if (msg_scrolled || (State != NORMAL && State != NORMAL_BUSY) || exiting)
Bram Moolenaar2951b772013-07-03 12:45:31 +0200327 return ret;
328
329 /* Allocate space to save the text displayed in the command line area. */
Bram Moolenaar5f95f282015-07-25 22:53:00 +0200330 rows = screen_Rows - cmdline_row;
Bram Moolenaarc799fe22019-05-28 23:08:19 +0200331 screenline = LALLOC_MULT(schar_T, rows * cols);
332 screenattr = LALLOC_MULT(sattr_T, rows * cols);
Bram Moolenaar2951b772013-07-03 12:45:31 +0200333 if (screenline == NULL || screenattr == NULL)
334 ret = 2;
Bram Moolenaar2951b772013-07-03 12:45:31 +0200335 if (enc_utf8)
336 {
Bram Moolenaarc799fe22019-05-28 23:08:19 +0200337 screenlineUC = LALLOC_MULT(u8char_T, rows * cols);
Bram Moolenaar2951b772013-07-03 12:45:31 +0200338 if (screenlineUC == NULL)
339 ret = 2;
340 for (i = 0; i < p_mco; ++i)
341 {
Bram Moolenaarc799fe22019-05-28 23:08:19 +0200342 screenlineC[i] = LALLOC_MULT(u8char_T, rows * cols);
Bram Moolenaar2951b772013-07-03 12:45:31 +0200343 if (screenlineC[i] == NULL)
344 ret = 2;
345 }
346 }
347 if (enc_dbcs == DBCS_JPNU)
348 {
Bram Moolenaarc799fe22019-05-28 23:08:19 +0200349 screenline2 = LALLOC_MULT(schar_T, rows * cols);
Bram Moolenaar2951b772013-07-03 12:45:31 +0200350 if (screenline2 == NULL)
351 ret = 2;
352 }
Bram Moolenaar2951b772013-07-03 12:45:31 +0200353
354 if (ret != 2)
355 {
356 /* Save the text displayed in the command line area. */
357 for (r = 0; r < rows; ++r)
358 {
Bram Moolenaar5f95f282015-07-25 22:53:00 +0200359 mch_memmove(screenline + r * cols,
Bram Moolenaar2951b772013-07-03 12:45:31 +0200360 ScreenLines + LineOffset[cmdline_row + r],
Bram Moolenaar5f95f282015-07-25 22:53:00 +0200361 (size_t)cols * sizeof(schar_T));
362 mch_memmove(screenattr + r * cols,
Bram Moolenaar2951b772013-07-03 12:45:31 +0200363 ScreenAttrs + LineOffset[cmdline_row + r],
Bram Moolenaar5f95f282015-07-25 22:53:00 +0200364 (size_t)cols * sizeof(sattr_T));
Bram Moolenaar2951b772013-07-03 12:45:31 +0200365 if (enc_utf8)
366 {
Bram Moolenaar5f95f282015-07-25 22:53:00 +0200367 mch_memmove(screenlineUC + r * cols,
Bram Moolenaar2951b772013-07-03 12:45:31 +0200368 ScreenLinesUC + LineOffset[cmdline_row + r],
Bram Moolenaar5f95f282015-07-25 22:53:00 +0200369 (size_t)cols * sizeof(u8char_T));
Bram Moolenaar2951b772013-07-03 12:45:31 +0200370 for (i = 0; i < p_mco; ++i)
Bram Moolenaar5f95f282015-07-25 22:53:00 +0200371 mch_memmove(screenlineC[i] + r * cols,
372 ScreenLinesC[i] + LineOffset[cmdline_row + r],
373 (size_t)cols * sizeof(u8char_T));
Bram Moolenaar2951b772013-07-03 12:45:31 +0200374 }
375 if (enc_dbcs == DBCS_JPNU)
Bram Moolenaar5f95f282015-07-25 22:53:00 +0200376 mch_memmove(screenline2 + r * cols,
Bram Moolenaar2951b772013-07-03 12:45:31 +0200377 ScreenLines2 + LineOffset[cmdline_row + r],
Bram Moolenaar5f95f282015-07-25 22:53:00 +0200378 (size_t)cols * sizeof(schar_T));
Bram Moolenaar2951b772013-07-03 12:45:31 +0200379 }
380
381 update_screen(0);
382 ret = 3;
383
384 if (must_redraw == 0)
385 {
386 int off = (int)(current_ScreenLine - ScreenLines);
387
388 /* Restore the text displayed in the command line area. */
389 for (r = 0; r < rows; ++r)
390 {
391 mch_memmove(current_ScreenLine,
Bram Moolenaar5f95f282015-07-25 22:53:00 +0200392 screenline + r * cols,
393 (size_t)cols * sizeof(schar_T));
Bram Moolenaar2951b772013-07-03 12:45:31 +0200394 mch_memmove(ScreenAttrs + off,
Bram Moolenaar5f95f282015-07-25 22:53:00 +0200395 screenattr + r * cols,
396 (size_t)cols * sizeof(sattr_T));
Bram Moolenaar2951b772013-07-03 12:45:31 +0200397 if (enc_utf8)
398 {
399 mch_memmove(ScreenLinesUC + off,
Bram Moolenaar5f95f282015-07-25 22:53:00 +0200400 screenlineUC + r * cols,
401 (size_t)cols * sizeof(u8char_T));
Bram Moolenaar2951b772013-07-03 12:45:31 +0200402 for (i = 0; i < p_mco; ++i)
403 mch_memmove(ScreenLinesC[i] + off,
Bram Moolenaar5f95f282015-07-25 22:53:00 +0200404 screenlineC[i] + r * cols,
405 (size_t)cols * sizeof(u8char_T));
Bram Moolenaar2951b772013-07-03 12:45:31 +0200406 }
407 if (enc_dbcs == DBCS_JPNU)
408 mch_memmove(ScreenLines2 + off,
Bram Moolenaar5f95f282015-07-25 22:53:00 +0200409 screenline2 + r * cols,
410 (size_t)cols * sizeof(schar_T));
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200411 screen_line(cmdline_row + r, 0, cols, cols, 0);
Bram Moolenaar2951b772013-07-03 12:45:31 +0200412 }
413 ret = 4;
414 }
Bram Moolenaar2951b772013-07-03 12:45:31 +0200415 }
416
417 vim_free(screenline);
418 vim_free(screenattr);
Bram Moolenaar2951b772013-07-03 12:45:31 +0200419 if (enc_utf8)
420 {
421 vim_free(screenlineUC);
422 for (i = 0; i < p_mco; ++i)
423 vim_free(screenlineC[i]);
424 }
425 if (enc_dbcs == DBCS_JPNU)
426 vim_free(screenline2);
Bram Moolenaar2951b772013-07-03 12:45:31 +0200427
Bram Moolenaar249f0dd2013-07-04 22:31:03 +0200428 /* Show the intro message when appropriate. */
429 maybe_intro_message();
430
431 setcursor();
432
Bram Moolenaar2951b772013-07-03 12:45:31 +0200433 return ret;
434}
Bram Moolenaar113e1072019-01-20 15:30:40 +0100435#endif
Bram Moolenaar2951b772013-07-03 12:45:31 +0200436
437/*
Bram Moolenaar975b5272016-03-15 23:10:59 +0100438 * Invoked after an asynchronous callback is called.
439 * If an echo command was used the cursor needs to be put back where
440 * it belongs. If highlighting was changed a redraw is needed.
Bram Moolenaar02e177d2017-08-26 23:43:28 +0200441 * If "call_update_screen" is FALSE don't call update_screen() when at the
442 * command line.
Bram Moolenaar975b5272016-03-15 23:10:59 +0100443 */
444 void
Bram Moolenaar02e177d2017-08-26 23:43:28 +0200445redraw_after_callback(int call_update_screen)
Bram Moolenaar975b5272016-03-15 23:10:59 +0100446{
Bram Moolenaar80dd3f92017-07-19 12:51:52 +0200447 ++redrawing_for_callback;
448
Bram Moolenaarbfb96c02016-03-19 17:05:20 +0100449 if (State == HITRETURN || State == ASKMORE)
Bram Moolenaar4cbdf152018-08-26 21:23:07 +0200450 ; // do nothing
Bram Moolenaarbfb96c02016-03-19 17:05:20 +0100451 else if (State & CMDLINE)
Bram Moolenaar29ae3772017-04-30 19:39:39 +0200452 {
Bram Moolenaar4cbdf152018-08-26 21:23:07 +0200453 // Don't redraw when in prompt_for_number().
454 if (cmdline_row > 0)
455 {
456 // Redrawing only works when the screen didn't scroll. Don't clear
457 // wildmenu entries.
458 if (msg_scrolled == 0
Bram Moolenaar85dad2c2017-07-12 21:12:43 +0200459#ifdef FEAT_WILDMENU
Bram Moolenaar4cbdf152018-08-26 21:23:07 +0200460 && wild_menu_showing == 0
Bram Moolenaar85dad2c2017-07-12 21:12:43 +0200461#endif
Bram Moolenaar4cbdf152018-08-26 21:23:07 +0200462 && call_update_screen)
463 update_screen(0);
464
465 // Redraw in the same position, so that the user can continue
466 // editing the command.
467 redrawcmdline_ex(FALSE);
468 }
Bram Moolenaar29ae3772017-04-30 19:39:39 +0200469 }
Bram Moolenaar1b9645d2017-09-17 23:03:31 +0200470 else if (State & (NORMAL | INSERT | TERMINAL))
Bram Moolenaarbfb96c02016-03-19 17:05:20 +0100471 {
Bram Moolenaar4cbdf152018-08-26 21:23:07 +0200472 // keep the command line if possible
Bram Moolenaar29ae3772017-04-30 19:39:39 +0200473 update_screen(VALID_NO_UPDATE);
Bram Moolenaarbfb96c02016-03-19 17:05:20 +0100474 setcursor();
475 }
Bram Moolenaar975b5272016-03-15 23:10:59 +0100476 cursor_on();
Bram Moolenaar975b5272016-03-15 23:10:59 +0100477#ifdef FEAT_GUI
Bram Moolenaara338adc2018-01-31 20:51:47 +0100478 if (gui.in_use && !gui_mch_is_blink_off())
Bram Moolenaar4cbdf152018-08-26 21:23:07 +0200479 // Don't update the cursor when it is blinking and off to avoid
480 // flicker.
Bram Moolenaara338adc2018-01-31 20:51:47 +0100481 out_flush_cursor(FALSE, FALSE);
482 else
Bram Moolenaar975b5272016-03-15 23:10:59 +0100483#endif
Bram Moolenaaracda04f2018-02-08 09:57:28 +0100484 out_flush();
Bram Moolenaar80dd3f92017-07-19 12:51:52 +0200485
486 --redrawing_for_callback;
Bram Moolenaar975b5272016-03-15 23:10:59 +0100487}
488
489/*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000490 * Changed something in the current window, at buffer line "lnum", that
491 * requires that line and possibly other lines to be redrawn.
492 * Used when entering/leaving Insert mode with the cursor on a folded line.
493 * Used to remove the "$" from a change command.
494 * Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot
495 * may become invalid and the whole window will have to be redrawn.
496 */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000497 void
Bram Moolenaar05540972016-01-30 20:31:25 +0100498redrawWinline(
Bram Moolenaar90a99792018-09-12 21:52:18 +0200499 win_T *wp,
Bram Moolenaarae12f4b2019-01-09 20:51:04 +0100500 linenr_T lnum)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000501{
Bram Moolenaar90a99792018-09-12 21:52:18 +0200502 if (wp->w_redraw_top == 0 || wp->w_redraw_top > lnum)
503 wp->w_redraw_top = lnum;
504 if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum)
505 wp->w_redraw_bot = lnum;
506 redraw_win_later(wp, VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000507}
508
Bram Moolenaar68a4b042019-05-29 22:28:29 +0200509/*
510 * To be called when "updating_screen" was set before and now the postponed
511 * side effects may take place.
512 */
Bram Moolenaar0cb8ac72018-05-11 22:01:51 +0200513 void
Bram Moolenaar68a4b042019-05-29 22:28:29 +0200514after_updating_screen(int may_resize_shell UNUSED)
Bram Moolenaar0cb8ac72018-05-11 22:01:51 +0200515{
516 updating_screen = FALSE;
517#ifdef FEAT_GUI
518 if (may_resize_shell)
519 gui_may_resize_shell();
520#endif
521#ifdef FEAT_TERMINAL
522 term_check_channel_closed_recently();
523#endif
Bram Moolenaar92d147b2018-07-29 17:35:23 +0200524
525#ifdef HAVE_DROP_FILE
526 // If handle_drop() was called while updating_screen was TRUE need to
527 // handle the drop now.
528 handle_any_postponed_drop();
529#endif
Bram Moolenaar0cb8ac72018-05-11 22:01:51 +0200530}
531
Bram Moolenaar071d4272004-06-13 20:20:40 +0000532/*
Bram Moolenaar29ae3772017-04-30 19:39:39 +0200533 * Update all windows that are editing the current buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000534 */
535 void
Bram Moolenaar05540972016-01-30 20:31:25 +0100536update_curbuf(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000537{
538 redraw_curbuf_later(type);
539 update_screen(type);
540}
541
542/*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000543 * Based on the current value of curwin->w_topline, transfer a screenfull
544 * of stuff from Filemem to ScreenLines[], and update curwin->w_botline.
Bram Moolenaar072412e2017-09-13 22:11:35 +0200545 * Return OK when the screen was updated, FAIL if it was not done.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000546 */
Bram Moolenaar072412e2017-09-13 22:11:35 +0200547 int
Bram Moolenaar29ae3772017-04-30 19:39:39 +0200548update_screen(int type_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000549{
Bram Moolenaar29ae3772017-04-30 19:39:39 +0200550 int type = type_arg;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000551 win_T *wp;
552 static int did_intro = FALSE;
553#if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
554 int did_one;
555#endif
Bram Moolenaar144445d2016-07-08 21:41:54 +0200556#ifdef FEAT_GUI
Bram Moolenaar107abd22016-08-12 14:08:25 +0200557 int did_undraw = FALSE;
Bram Moolenaar1f3601e2019-04-26 20:33:00 +0200558 int gui_cursor_col = 0;
559 int gui_cursor_row = 0;
Bram Moolenaar144445d2016-07-08 21:41:54 +0200560#endif
Bram Moolenaar29ae3772017-04-30 19:39:39 +0200561 int no_update = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000562
Bram Moolenaar19f990e2009-11-25 12:08:03 +0000563 /* Don't do anything if the screen structures are (not yet) valid. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000564 if (!screen_valid(TRUE))
Bram Moolenaar072412e2017-09-13 22:11:35 +0200565 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000566
Bram Moolenaar29ae3772017-04-30 19:39:39 +0200567 if (type == VALID_NO_UPDATE)
568 {
569 no_update = TRUE;
570 type = 0;
571 }
572
Bram Moolenaara3347722019-05-11 21:14:24 +0200573#ifdef FEAT_EVAL
Bram Moolenaarfe1ade02019-05-14 21:20:36 +0200574 {
575 buf_T *buf;
576
577 // Before updating the screen, notify any listeners of changed text.
578 FOR_ALL_BUFFERS(buf)
579 invoke_listeners(buf);
580 }
Bram Moolenaara3347722019-05-11 21:14:24 +0200581#endif
582
Bram Moolenaar071d4272004-06-13 20:20:40 +0000583 if (must_redraw)
584 {
585 if (type < must_redraw) /* use maximal type */
586 type = must_redraw;
Bram Moolenaar943fae42007-07-30 20:00:38 +0000587
588 /* must_redraw is reset here, so that when we run into some weird
589 * reason to redraw while busy redrawing (e.g., asynchronous
590 * scrolling), or update_topline() in win_update() will cause a
591 * scroll, the screen will be redrawn later or in win_update(). */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000592 must_redraw = 0;
593 }
594
Bram Moolenaar6eddadf2018-05-06 16:40:16 +0200595 /* May need to update w_lines[]. */
596 if (curwin->w_lines_valid == 0 && type < NOT_VALID
597#ifdef FEAT_TERMINAL
598 && !term_do_update_window(curwin)
599#endif
600 )
Bram Moolenaar071d4272004-06-13 20:20:40 +0000601 type = NOT_VALID;
602
Bram Moolenaar19f990e2009-11-25 12:08:03 +0000603 /* Postpone the redrawing when it's not needed and when being called
604 * recursively. */
605 if (!redrawing() || updating_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000606 {
607 redraw_later(type); /* remember type for next time */
608 must_redraw = type;
609 if (type > INVERTED_ALL)
610 curwin->w_lines_valid = 0; /* don't use w_lines[].wl_size now */
Bram Moolenaar072412e2017-09-13 22:11:35 +0200611 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000612 }
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200613#ifdef FEAT_TEXT_PROP
614 // TODO: avoid redrawing everything when there is a popup window.
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200615 if (popup_any_visible())
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200616 type = NOT_VALID;
617#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000618
619 updating_screen = TRUE;
620#ifdef FEAT_SYN_HL
621 ++display_tick; /* let syntax code know we're in a next round of
622 * display updating */
623#endif
Bram Moolenaar29ae3772017-04-30 19:39:39 +0200624 if (no_update)
625 ++no_win_do_lines_ins;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000626
627 /*
628 * if the screen was scrolled up when displaying a message, scroll it down
629 */
630 if (msg_scrolled)
631 {
632 clear_cmdline = TRUE;
633 if (msg_scrolled > Rows - 5) /* clearing is faster */
634 type = CLEAR;
635 else if (type != CLEAR)
636 {
637 check_for_delay(FALSE);
Bram Moolenaarcfce7172017-08-17 20:31:48 +0200638 if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, 0, NULL)
639 == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000640 type = CLEAR;
641 FOR_ALL_WINDOWS(wp)
642 {
643 if (W_WINROW(wp) < msg_scrolled)
644 {
645 if (W_WINROW(wp) + wp->w_height > msg_scrolled
646 && wp->w_redr_type < REDRAW_TOP
647 && wp->w_lines_valid > 0
648 && wp->w_topline == wp->w_lines[0].wl_lnum)
649 {
650 wp->w_upd_rows = msg_scrolled - W_WINROW(wp);
651 wp->w_redr_type = REDRAW_TOP;
652 }
653 else
654 {
655 wp->w_redr_type = NOT_VALID;
Bram Moolenaare0de17d2017-09-24 16:24:34 +0200656 if (W_WINROW(wp) + wp->w_height + wp->w_status_height
657 <= msg_scrolled)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000658 wp->w_redr_status = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000659 }
660 }
661 }
Bram Moolenaar29ae3772017-04-30 19:39:39 +0200662 if (!no_update)
663 redraw_cmdline = TRUE;
Bram Moolenaar997fb4b2006-02-17 21:53:23 +0000664 redraw_tabline = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000665 }
666 msg_scrolled = 0;
667 need_wait_return = FALSE;
668 }
669
670 /* reset cmdline_row now (may have been changed temporarily) */
671 compute_cmdrow();
672
673 /* Check for changed highlighting */
674 if (need_highlight_changed)
675 highlight_changed();
676
677 if (type == CLEAR) /* first clear screen */
678 {
679 screenclear(); /* will reset clear_cmdline */
680 type = NOT_VALID;
Bram Moolenaar9f5f7bf2017-06-28 20:45:26 +0200681 /* must_redraw may be set indirectly, avoid another redraw later */
682 must_redraw = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000683 }
684
685 if (clear_cmdline) /* going to clear cmdline (done below) */
686 check_for_delay(FALSE);
687
Bram Moolenaar592e0a22004-07-03 16:05:59 +0000688#ifdef FEAT_LINEBREAK
Bram Moolenaar64486672010-05-16 15:46:46 +0200689 /* Force redraw when width of 'number' or 'relativenumber' column
690 * changes. */
Bram Moolenaar592e0a22004-07-03 16:05:59 +0000691 if (curwin->w_redr_type < NOT_VALID
Bram Moolenaar64486672010-05-16 15:46:46 +0200692 && curwin->w_nrwidth != ((curwin->w_p_nu || curwin->w_p_rnu)
693 ? number_width(curwin) : 0))
Bram Moolenaar592e0a22004-07-03 16:05:59 +0000694 curwin->w_redr_type = NOT_VALID;
695#endif
696
Bram Moolenaar071d4272004-06-13 20:20:40 +0000697 /*
698 * Only start redrawing if there is really something to do.
699 */
700 if (type == INVERTED)
701 update_curswant();
702 if (curwin->w_redr_type < type
703 && !((type == VALID
704 && curwin->w_lines[0].wl_valid
705#ifdef FEAT_DIFF
706 && curwin->w_topfill == curwin->w_old_topfill
707 && curwin->w_botfill == curwin->w_old_botfill
708#endif
709 && curwin->w_topline == curwin->w_lines[0].wl_lnum)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000710 || (type == INVERTED
Bram Moolenaarb0c9a852006-11-28 15:14:56 +0000711 && VIsual_active
Bram Moolenaar071d4272004-06-13 20:20:40 +0000712 && curwin->w_old_cursor_lnum == curwin->w_cursor.lnum
713 && curwin->w_old_visual_mode == VIsual_mode
714 && (curwin->w_valid & VALID_VIRTCOL)
715 && curwin->w_old_curswant == curwin->w_curswant)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000716 ))
717 curwin->w_redr_type = type;
718
Bram Moolenaar5a305422006-04-28 22:38:25 +0000719 /* Redraw the tab pages line if needed. */
720 if (redraw_tabline || type >= NOT_VALID)
721 draw_tabline();
Bram Moolenaar5a305422006-04-28 22:38:25 +0000722
Bram Moolenaar071d4272004-06-13 20:20:40 +0000723#ifdef FEAT_SYN_HL
724 /*
725 * Correct stored syntax highlighting info for changes in each displayed
726 * buffer. Each buffer must only be done once.
727 */
728 FOR_ALL_WINDOWS(wp)
729 {
730 if (wp->w_buffer->b_mod_set)
731 {
Bram Moolenaar071d4272004-06-13 20:20:40 +0000732 win_T *wwp;
733
734 /* Check if we already did this buffer. */
735 for (wwp = firstwin; wwp != wp; wwp = wwp->w_next)
736 if (wwp->w_buffer == wp->w_buffer)
737 break;
Bram Moolenaar4033c552017-09-16 20:54:51 +0200738 if (wwp == wp && syntax_present(wp))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000739 syn_stack_apply_changes(wp->w_buffer);
740 }
741 }
742#endif
743
744 /*
745 * Go from top to bottom through the windows, redrawing the ones that need
746 * it.
747 */
748#if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
749 did_one = FALSE;
750#endif
751#ifdef FEAT_SEARCH_EXTRA
752 search_hl.rm.regprog = NULL;
753#endif
754 FOR_ALL_WINDOWS(wp)
755 {
756 if (wp->w_redr_type != 0)
757 {
758 cursor_off();
759#if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
760 if (!did_one)
761 {
762 did_one = TRUE;
763# ifdef FEAT_SEARCH_EXTRA
764 start_search_hl();
765# endif
766# ifdef FEAT_CLIPBOARD
767 /* When Visual area changed, may have to update selection. */
Bram Moolenaarc0885aa2012-07-10 16:49:23 +0200768 if (clip_star.available && clip_isautosel_star())
769 clip_update_selection(&clip_star);
770 if (clip_plus.available && clip_isautosel_plus())
771 clip_update_selection(&clip_plus);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000772# endif
773#ifdef FEAT_GUI
774 /* Remove the cursor before starting to do anything, because
775 * scrolling may make it difficult to redraw the text under
776 * it. */
Bram Moolenaar107abd22016-08-12 14:08:25 +0200777 if (gui.in_use && wp == curwin)
Bram Moolenaar144445d2016-07-08 21:41:54 +0200778 {
779 gui_cursor_col = gui.cursor_col;
780 gui_cursor_row = gui.cursor_row;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000781 gui_undraw_cursor();
Bram Moolenaar107abd22016-08-12 14:08:25 +0200782 did_undraw = TRUE;
Bram Moolenaar144445d2016-07-08 21:41:54 +0200783 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000784#endif
785 }
786#endif
787 win_update(wp);
788 }
789
Bram Moolenaar071d4272004-06-13 20:20:40 +0000790 /* redraw status line after the window to minimize cursor movement */
791 if (wp->w_redr_status)
792 {
793 cursor_off();
Bram Moolenaar6ba3ec12018-06-16 15:32:38 +0200794 win_redr_status(wp, TRUE); // any popup menu will be redrawn below
Bram Moolenaar071d4272004-06-13 20:20:40 +0000795 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000796 }
797#if defined(FEAT_SEARCH_EXTRA)
798 end_search_hl();
799#endif
Bram Moolenaar51971b32013-02-13 12:16:05 +0100800#ifdef FEAT_INS_EXPAND
801 /* May need to redraw the popup menu. */
Bram Moolenaar491ac282018-06-17 14:47:55 +0200802 pum_may_redraw();
Bram Moolenaar51971b32013-02-13 12:16:05 +0100803#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000804
Bram Moolenaar071d4272004-06-13 20:20:40 +0000805 /* Reset b_mod_set flags. Going through all windows is probably faster
806 * than going through all buffers (there could be many buffers). */
Bram Moolenaar29323592016-07-24 22:04:11 +0200807 FOR_ALL_WINDOWS(wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000808 wp->w_buffer->b_mod_set = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000809
Bram Moolenaar68a4b042019-05-29 22:28:29 +0200810 after_updating_screen(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000811
812 /* Clear or redraw the command line. Done last, because scrolling may
813 * mess up the command line. */
Bram Moolenaar4c25bd72019-04-20 23:38:07 +0200814 if (clear_cmdline || redraw_cmdline || redraw_mode)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000815 showmode();
816
Bram Moolenaar29ae3772017-04-30 19:39:39 +0200817 if (no_update)
818 --no_win_do_lines_ins;
819
Bram Moolenaar071d4272004-06-13 20:20:40 +0000820 /* May put up an introductory message when not editing a file */
Bram Moolenaar249f0dd2013-07-04 22:31:03 +0200821 if (!did_intro)
822 maybe_intro_message();
Bram Moolenaar071d4272004-06-13 20:20:40 +0000823 did_intro = TRUE;
824
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200825#ifdef FEAT_TEXT_PROP
826 // Display popup windows on top of the others.
827 update_popups();
828#endif
829
Bram Moolenaar071d4272004-06-13 20:20:40 +0000830#ifdef FEAT_GUI
831 /* Redraw the cursor and update the scrollbars when all screen updating is
832 * done. */
833 if (gui.in_use)
834 {
Bram Moolenaar107abd22016-08-12 14:08:25 +0200835 if (did_undraw && !gui_mch_is_blink_off())
Bram Moolenaar144445d2016-07-08 21:41:54 +0200836 {
Bram Moolenaara338adc2018-01-31 20:51:47 +0100837 mch_disable_flush();
838 out_flush(); /* required before updating the cursor */
839 mch_enable_flush();
840
Bram Moolenaar144445d2016-07-08 21:41:54 +0200841 /* Put the GUI position where the cursor was, gui_update_cursor()
842 * uses that. */
843 gui.col = gui_cursor_col;
844 gui.row = gui_cursor_row;
Bram Moolenaar84dbd492016-10-02 23:09:31 +0200845 gui.col = mb_fix_col(gui.col, gui.row);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000846 gui_update_cursor(FALSE, FALSE);
Bram Moolenaara338adc2018-01-31 20:51:47 +0100847 gui_may_flush();
Bram Moolenaar65549bd2016-07-08 22:52:37 +0200848 screen_cur_col = gui.col;
849 screen_cur_row = gui.row;
Bram Moolenaar144445d2016-07-08 21:41:54 +0200850 }
Bram Moolenaara338adc2018-01-31 20:51:47 +0100851 else
852 out_flush();
Bram Moolenaar071d4272004-06-13 20:20:40 +0000853 gui_update_scrollbars(FALSE);
854 }
855#endif
Bram Moolenaar072412e2017-09-13 22:11:35 +0200856 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000857}
858
Bram Moolenaar1fa8fdd2019-02-25 05:41:15 +0100859#if defined(FEAT_NETBEANS_INTG) || defined(FEAT_GUI)
Bram Moolenaarc10f0e72017-02-01 18:37:14 +0100860/*
861 * Prepare for updating one or more windows.
862 * Caller must check for "updating_screen" already set to avoid recursiveness.
863 */
864 static void
865update_prepare(void)
866{
867 cursor_off();
868 updating_screen = TRUE;
869#ifdef FEAT_GUI
870 /* Remove the cursor before starting to do anything, because scrolling may
871 * make it difficult to redraw the text under it. */
872 if (gui.in_use)
873 gui_undraw_cursor();
874#endif
875#ifdef FEAT_SEARCH_EXTRA
876 start_search_hl();
877#endif
878}
879
880/*
881 * Finish updating one or more windows.
882 */
883 static void
884update_finish(void)
885{
Bram Moolenaar4c25bd72019-04-20 23:38:07 +0200886 if (redraw_cmdline || redraw_mode)
Bram Moolenaarc10f0e72017-02-01 18:37:14 +0100887 showmode();
888
889# ifdef FEAT_SEARCH_EXTRA
890 end_search_hl();
891# endif
892
Bram Moolenaar68a4b042019-05-29 22:28:29 +0200893 after_updating_screen(TRUE);
Bram Moolenaarc10f0e72017-02-01 18:37:14 +0100894
895# ifdef FEAT_GUI
Bram Moolenaarc10f0e72017-02-01 18:37:14 +0100896 /* Redraw the cursor and update the scrollbars when all screen updating is
897 * done. */
898 if (gui.in_use)
899 {
Bram Moolenaara338adc2018-01-31 20:51:47 +0100900 out_flush_cursor(FALSE, FALSE);
Bram Moolenaarc10f0e72017-02-01 18:37:14 +0100901 gui_update_scrollbars(FALSE);
902 }
903# endif
904}
905#endif
906
Bram Moolenaar860cae12010-06-05 23:22:07 +0200907#if defined(FEAT_CONCEAL) || defined(PROTO)
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200908/*
909 * Return TRUE if the cursor line in window "wp" may be concealed, according
910 * to the 'concealcursor' option.
911 */
912 int
Bram Moolenaar05540972016-01-30 20:31:25 +0100913conceal_cursor_line(win_T *wp)
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200914{
915 int c;
916
917 if (*wp->w_p_cocu == NUL)
918 return FALSE;
919 if (get_real_state() & VISUAL)
920 c = 'v';
921 else if (State & INSERT)
922 c = 'i';
923 else if (State & NORMAL)
924 c = 'n';
Bram Moolenaarca8c9862010-07-24 15:00:38 +0200925 else if (State & CMDLINE)
926 c = 'c';
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200927 else
928 return FALSE;
929 return vim_strchr(wp->w_p_cocu, c) != NULL;
930}
931
932/*
933 * Check if the cursor line needs to be redrawn because of 'concealcursor'.
934 */
935 void
Bram Moolenaarb9464822018-05-10 15:09:49 +0200936conceal_check_cursor_line(void)
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200937{
938 if (curwin->w_p_cole > 0 && conceal_cursor_line(curwin))
939 {
940 need_cursor_line_redraw = TRUE;
941 /* Need to recompute cursor column, e.g., when starting Visual mode
942 * without concealing. */
943 curs_columns(TRUE);
944 }
945}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000946#endif
947
Bram Moolenaar113e1072019-01-20 15:30:40 +0100948#if defined(FEAT_NETBEANS_INTG) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000949 void
Bram Moolenaar05540972016-01-30 20:31:25 +0100950update_debug_sign(buf_T *buf, linenr_T lnum)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000951{
952 win_T *wp;
953 int doit = FALSE;
954
955# ifdef FEAT_FOLDING
956 win_foldinfo.fi_level = 0;
957# endif
958
Bram Moolenaar27a472c2019-01-09 21:47:30 +0100959 // update/delete a specific sign
960 redraw_buf_line_later(buf, lnum);
961
962 // check if it resulted in the need to redraw a window
Bram Moolenaar071d4272004-06-13 20:20:40 +0000963 FOR_ALL_WINDOWS(wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000964 if (wp->w_redr_type != 0)
965 doit = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000966
Bram Moolenaar738f8fc2012-01-10 12:42:09 +0100967 /* Return when there is nothing to do, screen updating is already
Bram Moolenaar07920482017-08-01 20:53:30 +0200968 * happening (recursive call), messages on the screen or still starting up.
969 */
Bram Moolenaar738f8fc2012-01-10 12:42:09 +0100970 if (!doit || updating_screen
Bram Moolenaar07920482017-08-01 20:53:30 +0200971 || State == ASKMORE || State == HITRETURN
972 || msg_scrolled
Bram Moolenaar738f8fc2012-01-10 12:42:09 +0100973#ifdef FEAT_GUI
974 || gui.starting
975#endif
976 || starting)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000977 return;
978
979 /* update all windows that need updating */
980 update_prepare();
981
Bram Moolenaar29323592016-07-24 22:04:11 +0200982 FOR_ALL_WINDOWS(wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000983 {
984 if (wp->w_redr_type != 0)
985 win_update(wp);
986 if (wp->w_redr_status)
Bram Moolenaar6ba3ec12018-06-16 15:32:38 +0200987 win_redr_status(wp, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000988 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000989
990 update_finish();
991}
992#endif
993
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200994/*
995 * Get 'wincolor' attribute for window "wp". If not set and "wp" is a popup
996 * window then get the "Pmenu" highlight attribute.
997 */
998 static int
999get_wcr_attr(win_T *wp)
1000{
1001 int wcr_attr = 0;
1002
1003 if (*wp->w_p_wcr != NUL)
1004 wcr_attr = syn_name2attr(wp->w_p_wcr);
1005#ifdef FEAT_TEXT_PROP
1006 if (bt_popup(wp->w_buffer) && wcr_attr == 0)
1007 wcr_attr = HL_ATTR(HLF_PNI);
1008#endif
1009 return wcr_attr;
1010}
1011
Bram Moolenaar2fd8e352019-06-01 20:16:48 +02001012#ifdef FEAT_TEXT_PROP
1013/*
1014 * Return a string of "len" spaces in IObuff.
1015 */
1016 static char_u *
1017get_spaces(int len)
1018{
1019 vim_memset(IObuff, ' ', (size_t)len);
1020 IObuff[len] = NUL;
1021 return IObuff;
1022}
1023
1024 static void
1025update_popups(void)
1026{
1027 win_T *wp;
1028 int top_off;
1029 int left_off;
1030 int total_width;
1031 int total_height;
1032 int popup_attr;
1033 int row;
Bram Moolenaar3bfd04e2019-06-01 20:45:21 +02001034 int tl_corner_char = '+';
1035 char *tr_corner_str = "+";
1036 int bl_corner_char = '+';
1037 char *br_corner_str = "+";
1038 int hor_line_char = '-';
1039 char *ver_line_str = "|";
Bram Moolenaar2fd8e352019-06-01 20:16:48 +02001040
1041 // Find the window with the lowest zindex that hasn't been updated yet,
1042 // so that the window with a higher zindex is drawn later, thus goes on
1043 // top.
1044 // TODO: don't redraw every popup every time.
1045 popup_reset_handled();
1046 while ((wp = find_next_popup(TRUE)) != NULL)
1047 {
1048 // Recompute the position if the text changed.
1049 if (wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer))
1050 popup_adjust_position(wp);
1051
1052 // adjust w_winrow and w_wincol for border and padding, since
1053 // win_update() doesn't handle them.
1054 top_off = wp->w_popup_padding[0] + wp->w_popup_border[0];
1055 left_off = wp->w_popup_padding[3] + wp->w_popup_border[3];
1056 wp->w_winrow += top_off;
1057 wp->w_wincol += left_off;
1058
1059 // Draw the popup text.
1060 win_update(wp);
1061
1062 wp->w_winrow -= top_off;
1063 wp->w_wincol -= left_off;
1064
1065 total_width = wp->w_popup_border[3] + wp->w_popup_padding[3]
1066 + wp->w_width + wp->w_popup_padding[1] + wp->w_popup_border[1];
1067 total_height = wp->w_popup_border[0] + wp->w_popup_padding[0]
1068 + wp->w_height + wp->w_popup_padding[2] + wp->w_popup_border[2];
1069 popup_attr = get_wcr_attr(wp);
1070
Bram Moolenaar3bfd04e2019-06-01 20:45:21 +02001071 if (enc_utf8)
1072 {
1073 tl_corner_char = 0x2554;
1074 tr_corner_str = "\xe2\x95\x97";
1075 bl_corner_char = 0x255a;
1076 br_corner_str = "\xe2\x95\x9d";
1077 hor_line_char = 0x2550;
1078 ver_line_str = "\xe2\x95\x91";
1079 }
1080
Bram Moolenaar2fd8e352019-06-01 20:16:48 +02001081 if (wp->w_popup_border[0] > 0)
1082 {
1083 // top border
1084 screen_fill(wp->w_winrow, wp->w_winrow + 1,
1085 wp->w_wincol,
1086 wp->w_wincol + total_width,
Bram Moolenaar3bfd04e2019-06-01 20:45:21 +02001087 wp->w_popup_border[3] != 0
1088 ? tl_corner_char : hor_line_char,
1089 hor_line_char, popup_attr);
Bram Moolenaar2fd8e352019-06-01 20:16:48 +02001090 if (wp->w_popup_border[1] > 0)
Bram Moolenaar3bfd04e2019-06-01 20:45:21 +02001091 screen_puts((char_u *)tr_corner_str, wp->w_winrow,
Bram Moolenaar2fd8e352019-06-01 20:16:48 +02001092 wp->w_wincol + total_width - 1, popup_attr);
1093 }
1094
1095 if (wp->w_popup_padding[0] > 0)
1096 {
1097 // top padding
1098 row = wp->w_winrow + wp->w_popup_border[0];
1099 screen_fill(row, row + wp->w_popup_padding[0],
1100 wp->w_wincol + wp->w_popup_border[3],
1101 wp->w_wincol + total_width - wp->w_popup_border[1],
1102 ' ', ' ', popup_attr);
1103 }
1104
1105 for (row = wp->w_winrow + wp->w_popup_border[0];
1106 row < wp->w_winrow + total_height - wp->w_popup_border[2];
1107 ++row)
1108 {
1109 // left border
1110 if (wp->w_popup_border[3] > 0)
Bram Moolenaar3bfd04e2019-06-01 20:45:21 +02001111 screen_puts((char_u *)ver_line_str, row, wp->w_wincol, popup_attr);
Bram Moolenaar2fd8e352019-06-01 20:16:48 +02001112 // left padding
1113 if (wp->w_popup_padding[3] > 0)
1114 screen_puts(get_spaces(wp->w_popup_padding[3]), row,
1115 wp->w_wincol + wp->w_popup_border[3], popup_attr);
1116 // right border
1117 if (wp->w_popup_border[1] > 0)
Bram Moolenaar3bfd04e2019-06-01 20:45:21 +02001118 screen_puts((char_u *)ver_line_str, row,
Bram Moolenaar2fd8e352019-06-01 20:16:48 +02001119 wp->w_wincol + total_width - 1, popup_attr);
1120 // right padding
1121 if (wp->w_popup_padding[1] > 0)
1122 screen_puts(get_spaces(wp->w_popup_padding[1]), row,
1123 wp->w_wincol + wp->w_popup_border[3]
1124 + wp->w_popup_padding[3] + wp->w_width, popup_attr);
1125 }
1126
1127 if (wp->w_popup_padding[2] > 0)
1128 {
1129 // bottom padding
1130 row = wp->w_winrow + wp->w_popup_border[0]
1131 + wp->w_popup_padding[0] + wp->w_height;
1132 screen_fill(row, row + wp->w_popup_padding[2],
1133 wp->w_wincol + wp->w_popup_border[3],
1134 wp->w_wincol + total_width - wp->w_popup_border[1],
1135 ' ', ' ', popup_attr);
1136 }
1137
1138 if (wp->w_popup_border[2] > 0)
1139 {
1140 // bottom border
1141 row = wp->w_winrow + total_height - 1;
1142 screen_fill(row , row + 1,
1143 wp->w_wincol,
1144 wp->w_wincol + total_width,
Bram Moolenaar3bfd04e2019-06-01 20:45:21 +02001145 wp->w_popup_border[3] != 0 ? bl_corner_char : hor_line_char,
1146 hor_line_char, popup_attr);
Bram Moolenaar2fd8e352019-06-01 20:16:48 +02001147 if (wp->w_popup_border[1] > 0)
Bram Moolenaar3bfd04e2019-06-01 20:45:21 +02001148 screen_puts((char_u *)br_corner_str, row,
Bram Moolenaar2fd8e352019-06-01 20:16:48 +02001149 wp->w_wincol + total_width - 1, popup_attr);
1150 }
1151 }
1152}
1153#endif
1154
Bram Moolenaar071d4272004-06-13 20:20:40 +00001155#if defined(FEAT_GUI) || defined(PROTO)
1156/*
1157 * Update a single window, its status line and maybe the command line msg.
1158 * Used for the GUI scrollbar.
1159 */
1160 void
Bram Moolenaar05540972016-01-30 20:31:25 +01001161updateWindow(win_T *wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001162{
Bram Moolenaar19f990e2009-11-25 12:08:03 +00001163 /* return if already busy updating */
1164 if (updating_screen)
1165 return;
1166
Bram Moolenaar071d4272004-06-13 20:20:40 +00001167 update_prepare();
1168
1169#ifdef FEAT_CLIPBOARD
1170 /* When Visual area changed, may have to update selection. */
Bram Moolenaarc0885aa2012-07-10 16:49:23 +02001171 if (clip_star.available && clip_isautosel_star())
1172 clip_update_selection(&clip_star);
1173 if (clip_plus.available && clip_isautosel_plus())
1174 clip_update_selection(&clip_plus);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001175#endif
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00001176
Bram Moolenaar071d4272004-06-13 20:20:40 +00001177 win_update(wp);
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00001178
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00001179 /* When the screen was cleared redraw the tab pages line. */
Bram Moolenaar997fb4b2006-02-17 21:53:23 +00001180 if (redraw_tabline)
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00001181 draw_tabline();
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00001182
Bram Moolenaar071d4272004-06-13 20:20:40 +00001183 if (wp->w_redr_status
1184# ifdef FEAT_CMDL_INFO
1185 || p_ru
1186# endif
1187# ifdef FEAT_STL_OPT
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00001188 || *p_stl != NUL || *wp->w_p_stl != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00001189# endif
1190 )
Bram Moolenaar6ba3ec12018-06-16 15:32:38 +02001191 win_redr_status(wp, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192
1193 update_finish();
1194}
1195#endif
1196
1197/*
1198 * Update a single window.
1199 *
1200 * This may cause the windows below it also to be redrawn (when clearing the
1201 * screen or scrolling lines).
1202 *
1203 * How the window is redrawn depends on wp->w_redr_type. Each type also
1204 * implies the one below it.
1205 * NOT_VALID redraw the whole window
Bram Moolenaar600dddc2006-03-12 22:05:10 +00001206 * SOME_VALID redraw the whole window but do scroll when possible
Bram Moolenaar071d4272004-06-13 20:20:40 +00001207 * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID
1208 * INVERTED redraw the changed part of the Visual area
1209 * INVERTED_ALL redraw the whole Visual area
1210 * VALID 1. scroll up/down to adjust for a changed w_topline
1211 * 2. update lines at the top when scrolled down
1212 * 3. redraw changed text:
Bram Moolenaar75c50c42005-06-04 22:06:24 +00001213 * - if wp->w_buffer->b_mod_set set, update lines between
Bram Moolenaar071d4272004-06-13 20:20:40 +00001214 * b_mod_top and b_mod_bot.
1215 * - if wp->w_redraw_top non-zero, redraw lines between
1216 * wp->w_redraw_top and wp->w_redr_bot.
1217 * - continue redrawing when syntax status is invalid.
1218 * 4. if scrolled up, update lines at the bottom.
1219 * This results in three areas that may need updating:
1220 * top: from first row to top_end (when scrolled down)
1221 * mid: from mid_start to mid_end (update inversion or changed text)
1222 * bot: from bot_start to last row (when scrolled up)
1223 */
1224 static void
Bram Moolenaar05540972016-01-30 20:31:25 +01001225win_update(win_T *wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001226{
1227 buf_T *buf = wp->w_buffer;
1228 int type;
1229 int top_end = 0; /* Below last row of the top area that needs
1230 updating. 0 when no top area updating. */
1231 int mid_start = 999;/* first row of the mid area that needs
1232 updating. 999 when no mid area updating. */
1233 int mid_end = 0; /* Below last row of the mid area that needs
1234 updating. 0 when no mid area updating. */
1235 int bot_start = 999;/* first row of the bot area that needs
1236 updating. 999 when no bot area updating */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001237 int scrolled_down = FALSE; /* TRUE when scrolled down when
1238 w_topline got smaller a bit */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001239#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaar6ee10162007-07-26 20:58:42 +00001240 matchitem_T *cur; /* points to the match list */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001241 int top_to_mod = FALSE; /* redraw above mod_top */
1242#endif
1243
1244 int row; /* current window row to display */
1245 linenr_T lnum; /* current buffer lnum to display */
1246 int idx; /* current index in w_lines[] */
1247 int srow; /* starting row of the current line */
1248
1249 int eof = FALSE; /* if TRUE, we hit the end of the file */
1250 int didline = FALSE; /* if TRUE, we finished the last line */
1251 int i;
1252 long j;
1253 static int recursive = FALSE; /* being called recursively */
1254 int old_botline = wp->w_botline;
1255#ifdef FEAT_FOLDING
1256 long fold_count;
1257#endif
1258#ifdef FEAT_SYN_HL
1259 /* remember what happened to the previous line, to know if
1260 * check_visual_highlight() can be used */
1261#define DID_NONE 1 /* didn't update a line */
1262#define DID_LINE 2 /* updated a normal line */
1263#define DID_FOLD 3 /* updated a folded line */
1264 int did_update = DID_NONE;
1265 linenr_T syntax_last_parsed = 0; /* last parsed text line */
1266#endif
1267 linenr_T mod_top = 0;
1268 linenr_T mod_bot = 0;
1269#if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
1270 int save_got_int;
1271#endif
Bram Moolenaar06f1ed22017-06-18 22:41:03 +02001272#ifdef SYN_TIME_LIMIT
1273 proftime_T syntax_tm;
1274#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001275
1276 type = wp->w_redr_type;
1277
1278 if (type == NOT_VALID)
1279 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00001280 wp->w_redr_status = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001281 wp->w_lines_valid = 0;
1282 }
1283
1284 /* Window is zero-height: nothing to draw. */
Bram Moolenaar415a6932017-12-05 20:31:07 +01001285 if (wp->w_height + WINBAR_HEIGHT(wp) == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001286 {
1287 wp->w_redr_type = 0;
1288 return;
1289 }
1290
Bram Moolenaar071d4272004-06-13 20:20:40 +00001291 /* Window is zero-width: Only need to draw the separator. */
1292 if (wp->w_width == 0)
1293 {
1294 /* draw the vertical separator right of this window */
1295 draw_vsep_win(wp, 0);
1296 wp->w_redr_type = 0;
1297 return;
1298 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001299
Bram Moolenaarcb8bbe92017-07-16 13:48:22 +02001300#ifdef FEAT_TERMINAL
Bram Moolenaar6eddadf2018-05-06 16:40:16 +02001301 // If this window contains a terminal, redraw works completely differently.
1302 if (term_do_update_window(wp))
Bram Moolenaarcb8bbe92017-07-16 13:48:22 +02001303 {
Bram Moolenaar6eddadf2018-05-06 16:40:16 +02001304 term_update_window(wp);
Bram Moolenaar181ca992018-02-13 21:19:21 +01001305# ifdef FEAT_MENU
1306 /* Draw the window toolbar, if there is one. */
1307 if (winbar_height(wp) > 0)
1308 redraw_win_toolbar(wp);
1309# endif
Bram Moolenaarcb8bbe92017-07-16 13:48:22 +02001310 wp->w_redr_type = 0;
1311 return;
1312 }
1313#endif
1314
Bram Moolenaar071d4272004-06-13 20:20:40 +00001315#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaar0af8ceb2010-07-05 22:22:57 +02001316 init_search_hl(wp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001317#endif
1318
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001319#ifdef FEAT_LINEBREAK
Bram Moolenaar64486672010-05-16 15:46:46 +02001320 /* Force redraw when width of 'number' or 'relativenumber' column
1321 * changes. */
1322 i = (wp->w_p_nu || wp->w_p_rnu) ? number_width(wp) : 0;
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00001323 if (wp->w_nrwidth != i)
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001324 {
1325 type = NOT_VALID;
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00001326 wp->w_nrwidth = i;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001327 }
1328 else
1329#endif
1330
Bram Moolenaar071d4272004-06-13 20:20:40 +00001331 if (buf->b_mod_set && buf->b_mod_xlines != 0 && wp->w_redraw_top != 0)
1332 {
1333 /*
1334 * When there are both inserted/deleted lines and specific lines to be
1335 * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw
1336 * everything (only happens when redrawing is off for while).
1337 */
1338 type = NOT_VALID;
1339 }
1340 else
1341 {
1342 /*
1343 * Set mod_top to the first line that needs displaying because of
1344 * changes. Set mod_bot to the first line after the changes.
1345 */
1346 mod_top = wp->w_redraw_top;
1347 if (wp->w_redraw_bot != 0)
1348 mod_bot = wp->w_redraw_bot + 1;
1349 else
1350 mod_bot = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001351 if (buf->b_mod_set)
1352 {
1353 if (mod_top == 0 || mod_top > buf->b_mod_top)
1354 {
1355 mod_top = buf->b_mod_top;
1356#ifdef FEAT_SYN_HL
1357 /* Need to redraw lines above the change that may be included
1358 * in a pattern match. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02001359 if (syntax_present(wp))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001360 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02001361 mod_top -= buf->b_s.b_syn_sync_linebreaks;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001362 if (mod_top < 1)
1363 mod_top = 1;
1364 }
1365#endif
1366 }
1367 if (mod_bot == 0 || mod_bot < buf->b_mod_bot)
1368 mod_bot = buf->b_mod_bot;
1369
1370#ifdef FEAT_SEARCH_EXTRA
1371 /* When 'hlsearch' is on and using a multi-line search pattern, a
1372 * change in one line may make the Search highlighting in a
1373 * previous line invalid. Simple solution: redraw all visible
1374 * lines above the change.
Bram Moolenaar6ee10162007-07-26 20:58:42 +00001375 * Same for a match pattern.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001376 */
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00001377 if (search_hl.rm.regprog != NULL
1378 && re_multiline(search_hl.rm.regprog))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001379 top_to_mod = TRUE;
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00001380 else
Bram Moolenaar6ee10162007-07-26 20:58:42 +00001381 {
1382 cur = wp->w_match_head;
1383 while (cur != NULL)
1384 {
1385 if (cur->match.regprog != NULL
1386 && re_multiline(cur->match.regprog))
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00001387 {
1388 top_to_mod = TRUE;
1389 break;
1390 }
Bram Moolenaar6ee10162007-07-26 20:58:42 +00001391 cur = cur->next;
1392 }
1393 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001394#endif
1395 }
1396#ifdef FEAT_FOLDING
1397 if (mod_top != 0 && hasAnyFolding(wp))
1398 {
1399 linenr_T lnumt, lnumb;
1400
1401 /*
1402 * A change in a line can cause lines above it to become folded or
1403 * unfolded. Find the top most buffer line that may be affected.
1404 * If the line was previously folded and displayed, get the first
1405 * line of that fold. If the line is folded now, get the first
1406 * folded line. Use the minimum of these two.
1407 */
1408
1409 /* Find last valid w_lines[] entry above mod_top. Set lnumt to
1410 * the line below it. If there is no valid entry, use w_topline.
1411 * Find the first valid w_lines[] entry below mod_bot. Set lnumb
1412 * to this line. If there is no valid entry, use MAXLNUM. */
1413 lnumt = wp->w_topline;
1414 lnumb = MAXLNUM;
1415 for (i = 0; i < wp->w_lines_valid; ++i)
1416 if (wp->w_lines[i].wl_valid)
1417 {
1418 if (wp->w_lines[i].wl_lastlnum < mod_top)
1419 lnumt = wp->w_lines[i].wl_lastlnum + 1;
1420 if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot)
1421 {
1422 lnumb = wp->w_lines[i].wl_lnum;
1423 /* When there is a fold column it might need updating
1424 * in the next line ("J" just above an open fold). */
Bram Moolenaar1c934292015-01-27 16:39:29 +01001425 if (compute_foldcolumn(wp, 0) > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001426 ++lnumb;
1427 }
1428 }
1429
1430 (void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL);
1431 if (mod_top > lnumt)
1432 mod_top = lnumt;
1433
1434 /* Now do the same for the bottom line (one above mod_bot). */
1435 --mod_bot;
1436 (void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL);
1437 ++mod_bot;
1438 if (mod_bot < lnumb)
1439 mod_bot = lnumb;
1440 }
1441#endif
1442
1443 /* When a change starts above w_topline and the end is below
1444 * w_topline, start redrawing at w_topline.
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001445 * If the end of the change is above w_topline: do like no change was
1446 * made, but redraw the first line to find changes in syntax. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001447 if (mod_top != 0 && mod_top < wp->w_topline)
1448 {
1449 if (mod_bot > wp->w_topline)
1450 mod_top = wp->w_topline;
1451#ifdef FEAT_SYN_HL
Bram Moolenaar860cae12010-06-05 23:22:07 +02001452 else if (syntax_present(wp))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001453 top_end = 1;
1454#endif
1455 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001456
1457 /* When line numbers are displayed need to redraw all lines below
1458 * inserted/deleted lines. */
1459 if (mod_top != 0 && buf->b_mod_xlines != 0 && wp->w_p_nu)
1460 mod_bot = MAXLNUM;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001461 }
Bram Moolenaar895d9662019-01-31 21:57:21 +01001462 wp->w_redraw_top = 0; // reset for next time
1463 wp->w_redraw_bot = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001464
1465 /*
1466 * When only displaying the lines at the top, set top_end. Used when
1467 * window has scrolled down for msg_scrolled.
1468 */
1469 if (type == REDRAW_TOP)
1470 {
1471 j = 0;
1472 for (i = 0; i < wp->w_lines_valid; ++i)
1473 {
1474 j += wp->w_lines[i].wl_size;
1475 if (j >= wp->w_upd_rows)
1476 {
1477 top_end = j;
1478 break;
1479 }
1480 }
1481 if (top_end == 0)
1482 /* not found (cannot happen?): redraw everything */
1483 type = NOT_VALID;
1484 else
1485 /* top area defined, the rest is VALID */
1486 type = VALID;
1487 }
1488
Bram Moolenaar367329b2007-08-30 11:53:22 +00001489 /* Trick: we want to avoid clearing the screen twice. screenclear() will
Bram Moolenaar943fae42007-07-30 20:00:38 +00001490 * set "screen_cleared" to TRUE. The special value MAYBE (which is still
1491 * non-zero and thus not FALSE) will indicate that screenclear() was not
1492 * called. */
1493 if (screen_cleared)
1494 screen_cleared = MAYBE;
1495
Bram Moolenaar071d4272004-06-13 20:20:40 +00001496 /*
1497 * If there are no changes on the screen that require a complete redraw,
1498 * handle three cases:
1499 * 1: we are off the top of the screen by a few lines: scroll down
1500 * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up
1501 * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in
1502 * w_lines[] that needs updating.
1503 */
Bram Moolenaar600dddc2006-03-12 22:05:10 +00001504 if ((type == VALID || type == SOME_VALID
1505 || type == INVERTED || type == INVERTED_ALL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001506#ifdef FEAT_DIFF
1507 && !wp->w_botfill && !wp->w_old_botfill
1508#endif
1509 )
1510 {
1511 if (mod_top != 0 && wp->w_topline == mod_top)
1512 {
1513 /*
1514 * w_topline is the first changed line, the scrolling will be done
1515 * further down.
1516 */
1517 }
1518 else if (wp->w_lines[0].wl_valid
1519 && (wp->w_topline < wp->w_lines[0].wl_lnum
1520#ifdef FEAT_DIFF
1521 || (wp->w_topline == wp->w_lines[0].wl_lnum
1522 && wp->w_topfill > wp->w_old_topfill)
1523#endif
1524 ))
1525 {
1526 /*
1527 * New topline is above old topline: May scroll down.
1528 */
1529#ifdef FEAT_FOLDING
1530 if (hasAnyFolding(wp))
1531 {
1532 linenr_T ln;
1533
1534 /* count the number of lines we are off, counting a sequence
1535 * of folded lines as one */
1536 j = 0;
1537 for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ++ln)
1538 {
1539 ++j;
1540 if (j >= wp->w_height - 2)
1541 break;
1542 (void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL);
1543 }
1544 }
1545 else
1546#endif
1547 j = wp->w_lines[0].wl_lnum - wp->w_topline;
1548 if (j < wp->w_height - 2) /* not too far off */
1549 {
1550 i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1);
1551#ifdef FEAT_DIFF
1552 /* insert extra lines for previously invisible filler lines */
1553 if (wp->w_lines[0].wl_lnum != wp->w_topline)
1554 i += diff_check_fill(wp, wp->w_lines[0].wl_lnum)
1555 - wp->w_old_topfill;
1556#endif
1557 if (i < wp->w_height - 2) /* less than a screen off */
1558 {
1559 /*
1560 * Try to insert the correct number of lines.
1561 * If not the last window, delete the lines at the bottom.
1562 * win_ins_lines may fail when the terminal can't do it.
1563 */
1564 if (i > 0)
1565 check_for_delay(FALSE);
1566 if (win_ins_lines(wp, 0, i, FALSE, wp == firstwin) == OK)
1567 {
1568 if (wp->w_lines_valid != 0)
1569 {
1570 /* Need to update rows that are new, stop at the
1571 * first one that scrolled down. */
1572 top_end = i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001573 scrolled_down = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001574
1575 /* Move the entries that were scrolled, disable
1576 * the entries for the lines to be redrawn. */
1577 if ((wp->w_lines_valid += j) > wp->w_height)
1578 wp->w_lines_valid = wp->w_height;
1579 for (idx = wp->w_lines_valid; idx - j >= 0; idx--)
1580 wp->w_lines[idx] = wp->w_lines[idx - j];
1581 while (idx >= 0)
1582 wp->w_lines[idx--].wl_valid = FALSE;
1583 }
1584 }
1585 else
1586 mid_start = 0; /* redraw all lines */
1587 }
1588 else
1589 mid_start = 0; /* redraw all lines */
1590 }
1591 else
1592 mid_start = 0; /* redraw all lines */
1593 }
1594 else
1595 {
1596 /*
1597 * New topline is at or below old topline: May scroll up.
1598 * When topline didn't change, find first entry in w_lines[] that
1599 * needs updating.
1600 */
1601
1602 /* try to find wp->w_topline in wp->w_lines[].wl_lnum */
1603 j = -1;
1604 row = 0;
1605 for (i = 0; i < wp->w_lines_valid; i++)
1606 {
1607 if (wp->w_lines[i].wl_valid
1608 && wp->w_lines[i].wl_lnum == wp->w_topline)
1609 {
1610 j = i;
1611 break;
1612 }
1613 row += wp->w_lines[i].wl_size;
1614 }
1615 if (j == -1)
1616 {
1617 /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all
1618 * lines */
1619 mid_start = 0;
1620 }
1621 else
1622 {
1623 /*
1624 * Try to delete the correct number of lines.
1625 * wp->w_topline is at wp->w_lines[i].wl_lnum.
1626 */
1627#ifdef FEAT_DIFF
1628 /* If the topline didn't change, delete old filler lines,
1629 * otherwise delete filler lines of the new topline... */
1630 if (wp->w_lines[0].wl_lnum == wp->w_topline)
1631 row += wp->w_old_topfill;
1632 else
1633 row += diff_check_fill(wp, wp->w_topline);
1634 /* ... but don't delete new filler lines. */
1635 row -= wp->w_topfill;
1636#endif
1637 if (row > 0)
1638 {
1639 check_for_delay(FALSE);
Bram Moolenaarcfce7172017-08-17 20:31:48 +02001640 if (win_del_lines(wp, 0, row, FALSE, wp == firstwin, 0)
1641 == OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001642 bot_start = wp->w_height - row;
1643 else
1644 mid_start = 0; /* redraw all lines */
1645 }
1646 if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0)
1647 {
1648 /*
1649 * Skip the lines (below the deleted lines) that are still
1650 * valid and don't need redrawing. Copy their info
1651 * upwards, to compensate for the deleted lines. Set
1652 * bot_start to the first row that needs redrawing.
1653 */
1654 bot_start = 0;
1655 idx = 0;
1656 for (;;)
1657 {
1658 wp->w_lines[idx] = wp->w_lines[j];
1659 /* stop at line that didn't fit, unless it is still
1660 * valid (no lines deleted) */
1661 if (row > 0 && bot_start + row
1662 + (int)wp->w_lines[j].wl_size > wp->w_height)
1663 {
1664 wp->w_lines_valid = idx + 1;
1665 break;
1666 }
1667 bot_start += wp->w_lines[idx++].wl_size;
1668
1669 /* stop at the last valid entry in w_lines[].wl_size */
1670 if (++j >= wp->w_lines_valid)
1671 {
1672 wp->w_lines_valid = idx;
1673 break;
1674 }
1675 }
1676#ifdef FEAT_DIFF
1677 /* Correct the first entry for filler lines at the top
1678 * when it won't get updated below. */
1679 if (wp->w_p_diff && bot_start > 0)
1680 wp->w_lines[0].wl_size =
1681 plines_win_nofill(wp, wp->w_topline, TRUE)
1682 + wp->w_topfill;
1683#endif
1684 }
1685 }
1686 }
1687
1688 /* When starting redraw in the first line, redraw all lines. When
1689 * there is only one window it's probably faster to clear the screen
1690 * first. */
1691 if (mid_start == 0)
1692 {
1693 mid_end = wp->w_height;
Bram Moolenaara1f4cb92016-11-06 15:25:42 +01001694 if (ONE_WINDOW)
Bram Moolenaarbc1a7c32006-09-14 19:04:14 +00001695 {
Bram Moolenaar943fae42007-07-30 20:00:38 +00001696 /* Clear the screen when it was not done by win_del_lines() or
1697 * win_ins_lines() above, "screen_cleared" is FALSE or MAYBE
1698 * then. */
1699 if (screen_cleared != TRUE)
1700 screenclear();
Bram Moolenaarbc1a7c32006-09-14 19:04:14 +00001701 /* The screen was cleared, redraw the tab pages line. */
1702 if (redraw_tabline)
1703 draw_tabline();
Bram Moolenaarbc1a7c32006-09-14 19:04:14 +00001704 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001705 }
Bram Moolenaar943fae42007-07-30 20:00:38 +00001706
1707 /* When win_del_lines() or win_ins_lines() caused the screen to be
1708 * cleared (only happens for the first window) or when screenclear()
1709 * was called directly above, "must_redraw" will have been set to
1710 * NOT_VALID, need to reset it here to avoid redrawing twice. */
1711 if (screen_cleared == TRUE)
1712 must_redraw = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001713 }
1714 else
1715 {
1716 /* Not VALID or INVERTED: redraw all lines. */
1717 mid_start = 0;
1718 mid_end = wp->w_height;
1719 }
1720
Bram Moolenaar600dddc2006-03-12 22:05:10 +00001721 if (type == SOME_VALID)
1722 {
1723 /* SOME_VALID: redraw all lines. */
1724 mid_start = 0;
1725 mid_end = wp->w_height;
1726 type = NOT_VALID;
1727 }
1728
Bram Moolenaar071d4272004-06-13 20:20:40 +00001729 /* check if we are updating or removing the inverted part */
1730 if ((VIsual_active && buf == curwin->w_buffer)
1731 || (wp->w_old_cursor_lnum != 0 && type != NOT_VALID))
1732 {
1733 linenr_T from, to;
1734
1735 if (VIsual_active)
1736 {
1737 if (VIsual_active
1738 && (VIsual_mode != wp->w_old_visual_mode
1739 || type == INVERTED_ALL))
1740 {
1741 /*
1742 * If the type of Visual selection changed, redraw the whole
1743 * selection. Also when the ownership of the X selection is
1744 * gained or lost.
1745 */
1746 if (curwin->w_cursor.lnum < VIsual.lnum)
1747 {
1748 from = curwin->w_cursor.lnum;
1749 to = VIsual.lnum;
1750 }
1751 else
1752 {
1753 from = VIsual.lnum;
1754 to = curwin->w_cursor.lnum;
1755 }
1756 /* redraw more when the cursor moved as well */
1757 if (wp->w_old_cursor_lnum < from)
1758 from = wp->w_old_cursor_lnum;
1759 if (wp->w_old_cursor_lnum > to)
1760 to = wp->w_old_cursor_lnum;
1761 if (wp->w_old_visual_lnum < from)
1762 from = wp->w_old_visual_lnum;
1763 if (wp->w_old_visual_lnum > to)
1764 to = wp->w_old_visual_lnum;
1765 }
1766 else
1767 {
1768 /*
1769 * Find the line numbers that need to be updated: The lines
1770 * between the old cursor position and the current cursor
1771 * position. Also check if the Visual position changed.
1772 */
1773 if (curwin->w_cursor.lnum < wp->w_old_cursor_lnum)
1774 {
1775 from = curwin->w_cursor.lnum;
1776 to = wp->w_old_cursor_lnum;
1777 }
1778 else
1779 {
1780 from = wp->w_old_cursor_lnum;
1781 to = curwin->w_cursor.lnum;
1782 if (from == 0) /* Visual mode just started */
1783 from = to;
1784 }
1785
Bram Moolenaar6c131c42005-07-19 22:17:30 +00001786 if (VIsual.lnum != wp->w_old_visual_lnum
1787 || VIsual.col != wp->w_old_visual_col)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001788 {
1789 if (wp->w_old_visual_lnum < from
1790 && wp->w_old_visual_lnum != 0)
1791 from = wp->w_old_visual_lnum;
1792 if (wp->w_old_visual_lnum > to)
1793 to = wp->w_old_visual_lnum;
1794 if (VIsual.lnum < from)
1795 from = VIsual.lnum;
1796 if (VIsual.lnum > to)
1797 to = VIsual.lnum;
1798 }
1799 }
1800
1801 /*
1802 * If in block mode and changed column or curwin->w_curswant:
1803 * update all lines.
1804 * First compute the actual start and end column.
1805 */
1806 if (VIsual_mode == Ctrl_V)
1807 {
Bram Moolenaar404406a2014-10-09 13:24:43 +02001808 colnr_T fromc, toc;
Bram Moolenaar29ddebe2019-01-26 17:28:26 +01001809#if defined(FEAT_LINEBREAK)
Bram Moolenaar404406a2014-10-09 13:24:43 +02001810 int save_ve_flags = ve_flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001811
Bram Moolenaar404406a2014-10-09 13:24:43 +02001812 if (curwin->w_p_lbr)
1813 ve_flags = VE_ALL;
1814#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001815 getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc);
Bram Moolenaar29ddebe2019-01-26 17:28:26 +01001816#if defined(FEAT_LINEBREAK)
Bram Moolenaar404406a2014-10-09 13:24:43 +02001817 ve_flags = save_ve_flags;
1818#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001819 ++toc;
1820 if (curwin->w_curswant == MAXCOL)
1821 toc = MAXCOL;
1822
1823 if (fromc != wp->w_old_cursor_fcol
1824 || toc != wp->w_old_cursor_lcol)
1825 {
1826 if (from > VIsual.lnum)
1827 from = VIsual.lnum;
1828 if (to < VIsual.lnum)
1829 to = VIsual.lnum;
1830 }
1831 wp->w_old_cursor_fcol = fromc;
1832 wp->w_old_cursor_lcol = toc;
1833 }
1834 }
1835 else
1836 {
1837 /* Use the line numbers of the old Visual area. */
1838 if (wp->w_old_cursor_lnum < wp->w_old_visual_lnum)
1839 {
1840 from = wp->w_old_cursor_lnum;
1841 to = wp->w_old_visual_lnum;
1842 }
1843 else
1844 {
1845 from = wp->w_old_visual_lnum;
1846 to = wp->w_old_cursor_lnum;
1847 }
1848 }
1849
1850 /*
1851 * There is no need to update lines above the top of the window.
1852 */
1853 if (from < wp->w_topline)
1854 from = wp->w_topline;
1855
1856 /*
1857 * If we know the value of w_botline, use it to restrict the update to
1858 * the lines that are visible in the window.
1859 */
1860 if (wp->w_valid & VALID_BOTLINE)
1861 {
1862 if (from >= wp->w_botline)
1863 from = wp->w_botline - 1;
1864 if (to >= wp->w_botline)
1865 to = wp->w_botline - 1;
1866 }
1867
1868 /*
1869 * Find the minimal part to be updated.
1870 * Watch out for scrolling that made entries in w_lines[] invalid.
1871 * E.g., CTRL-U makes the first half of w_lines[] invalid and sets
1872 * top_end; need to redraw from top_end to the "to" line.
1873 * A middle mouse click with a Visual selection may change the text
1874 * above the Visual area and reset wl_valid, do count these for
1875 * mid_end (in srow).
1876 */
1877 if (mid_start > 0)
1878 {
1879 lnum = wp->w_topline;
1880 idx = 0;
1881 srow = 0;
1882 if (scrolled_down)
1883 mid_start = top_end;
1884 else
1885 mid_start = 0;
1886 while (lnum < from && idx < wp->w_lines_valid) /* find start */
1887 {
1888 if (wp->w_lines[idx].wl_valid)
1889 mid_start += wp->w_lines[idx].wl_size;
1890 else if (!scrolled_down)
1891 srow += wp->w_lines[idx].wl_size;
1892 ++idx;
1893# ifdef FEAT_FOLDING
1894 if (idx < wp->w_lines_valid && wp->w_lines[idx].wl_valid)
1895 lnum = wp->w_lines[idx].wl_lnum;
1896 else
1897# endif
1898 ++lnum;
1899 }
1900 srow += mid_start;
1901 mid_end = wp->w_height;
1902 for ( ; idx < wp->w_lines_valid; ++idx) /* find end */
1903 {
1904 if (wp->w_lines[idx].wl_valid
1905 && wp->w_lines[idx].wl_lnum >= to + 1)
1906 {
1907 /* Only update until first row of this line */
1908 mid_end = srow;
1909 break;
1910 }
1911 srow += wp->w_lines[idx].wl_size;
1912 }
1913 }
1914 }
1915
1916 if (VIsual_active && buf == curwin->w_buffer)
1917 {
1918 wp->w_old_visual_mode = VIsual_mode;
1919 wp->w_old_cursor_lnum = curwin->w_cursor.lnum;
1920 wp->w_old_visual_lnum = VIsual.lnum;
Bram Moolenaar6c131c42005-07-19 22:17:30 +00001921 wp->w_old_visual_col = VIsual.col;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001922 wp->w_old_curswant = curwin->w_curswant;
1923 }
1924 else
1925 {
1926 wp->w_old_visual_mode = 0;
1927 wp->w_old_cursor_lnum = 0;
1928 wp->w_old_visual_lnum = 0;
Bram Moolenaar6c131c42005-07-19 22:17:30 +00001929 wp->w_old_visual_col = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001930 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001931
1932#if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
1933 /* reset got_int, otherwise regexp won't work */
1934 save_got_int = got_int;
1935 got_int = 0;
1936#endif
Bram Moolenaar06f1ed22017-06-18 22:41:03 +02001937#ifdef SYN_TIME_LIMIT
1938 /* Set the time limit to 'redrawtime'. */
1939 profile_setlimit(p_rdt, &syntax_tm);
Bram Moolenaarf3d769a2017-09-22 13:44:56 +02001940 syn_set_timeout(&syntax_tm);
Bram Moolenaar06f1ed22017-06-18 22:41:03 +02001941#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001942#ifdef FEAT_FOLDING
1943 win_foldinfo.fi_level = 0;
1944#endif
1945
Bram Moolenaar1b9645d2017-09-17 23:03:31 +02001946#ifdef FEAT_MENU
1947 /*
1948 * Draw the window toolbar, if there is one.
1949 * TODO: only when needed.
1950 */
1951 if (winbar_height(wp) > 0)
1952 redraw_win_toolbar(wp);
1953#endif
1954
Bram Moolenaar071d4272004-06-13 20:20:40 +00001955 /*
1956 * Update all the window rows.
1957 */
1958 idx = 0; /* first entry in w_lines[].wl_size */
1959 row = 0;
1960 srow = 0;
1961 lnum = wp->w_topline; /* first line shown in window */
1962 for (;;)
1963 {
1964 /* stop updating when reached the end of the window (check for _past_
1965 * the end of the window is at the end of the loop) */
1966 if (row == wp->w_height)
1967 {
1968 didline = TRUE;
1969 break;
1970 }
1971
1972 /* stop updating when hit the end of the file */
1973 if (lnum > buf->b_ml.ml_line_count)
1974 {
1975 eof = TRUE;
1976 break;
1977 }
1978
1979 /* Remember the starting row of the line that is going to be dealt
1980 * with. It is used further down when the line doesn't fit. */
1981 srow = row;
1982
1983 /*
1984 * Update a line when it is in an area that needs updating, when it
1985 * has changes or w_lines[idx] is invalid.
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02001986 * "bot_start" may be halfway a wrapped line after using
Bram Moolenaar071d4272004-06-13 20:20:40 +00001987 * win_del_lines(), check if the current line includes it.
1988 * When syntax folding is being used, the saved syntax states will
1989 * already have been updated, we can't see where the syntax state is
1990 * the same again, just update until the end of the window.
1991 */
1992 if (row < top_end
1993 || (row >= mid_start && row < mid_end)
1994#ifdef FEAT_SEARCH_EXTRA
1995 || top_to_mod
1996#endif
1997 || idx >= wp->w_lines_valid
1998 || (row + wp->w_lines[idx].wl_size > bot_start)
1999 || (mod_top != 0
2000 && (lnum == mod_top
2001 || (lnum >= mod_top
2002 && (lnum < mod_bot
2003#ifdef FEAT_SYN_HL
2004 || did_update == DID_FOLD
2005 || (did_update == DID_LINE
Bram Moolenaar860cae12010-06-05 23:22:07 +02002006 && syntax_present(wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002007 && (
2008# ifdef FEAT_FOLDING
2009 (foldmethodIsSyntax(wp)
2010 && hasAnyFolding(wp)) ||
2011# endif
2012 syntax_check_changed(lnum)))
2013#endif
Bram Moolenaar4ce239b2013-06-15 23:00:30 +02002014#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaardab70c62014-07-02 17:16:58 +02002015 /* match in fixed position might need redraw
2016 * if lines were inserted or deleted */
2017 || (wp->w_match_head != NULL
2018 && buf->b_mod_xlines != 0)
Bram Moolenaar4ce239b2013-06-15 23:00:30 +02002019#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002020 )))))
2021 {
2022#ifdef FEAT_SEARCH_EXTRA
2023 if (lnum == mod_top)
2024 top_to_mod = FALSE;
2025#endif
2026
2027 /*
2028 * When at start of changed lines: May scroll following lines
2029 * up or down to minimize redrawing.
2030 * Don't do this when the change continues until the end.
Bram Moolenaar76b9b362012-02-04 23:35:00 +01002031 * Don't scroll when dollar_vcol >= 0, keep the "$".
Bram Moolenaar071d4272004-06-13 20:20:40 +00002032 */
2033 if (lnum == mod_top
2034 && mod_bot != MAXLNUM
Bram Moolenaar76b9b362012-02-04 23:35:00 +01002035 && !(dollar_vcol >= 0 && mod_bot == mod_top + 1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002036 {
2037 int old_rows = 0;
2038 int new_rows = 0;
2039 int xtra_rows;
2040 linenr_T l;
2041
2042 /* Count the old number of window rows, using w_lines[], which
2043 * should still contain the sizes for the lines as they are
2044 * currently displayed. */
2045 for (i = idx; i < wp->w_lines_valid; ++i)
2046 {
2047 /* Only valid lines have a meaningful wl_lnum. Invalid
2048 * lines are part of the changed area. */
2049 if (wp->w_lines[i].wl_valid
2050 && wp->w_lines[i].wl_lnum == mod_bot)
2051 break;
2052 old_rows += wp->w_lines[i].wl_size;
2053#ifdef FEAT_FOLDING
2054 if (wp->w_lines[i].wl_valid
2055 && wp->w_lines[i].wl_lastlnum + 1 == mod_bot)
2056 {
2057 /* Must have found the last valid entry above mod_bot.
2058 * Add following invalid entries. */
2059 ++i;
2060 while (i < wp->w_lines_valid
2061 && !wp->w_lines[i].wl_valid)
2062 old_rows += wp->w_lines[i++].wl_size;
2063 break;
2064 }
2065#endif
2066 }
2067
2068 if (i >= wp->w_lines_valid)
2069 {
2070 /* We can't find a valid line below the changed lines,
2071 * need to redraw until the end of the window.
2072 * Inserting/deleting lines has no use. */
2073 bot_start = 0;
2074 }
2075 else
2076 {
2077 /* Able to count old number of rows: Count new window
2078 * rows, and may insert/delete lines */
2079 j = idx;
2080 for (l = lnum; l < mod_bot; ++l)
2081 {
2082#ifdef FEAT_FOLDING
2083 if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL))
2084 ++new_rows;
2085 else
2086#endif
2087#ifdef FEAT_DIFF
2088 if (l == wp->w_topline)
2089 new_rows += plines_win_nofill(wp, l, TRUE)
2090 + wp->w_topfill;
2091 else
2092#endif
2093 new_rows += plines_win(wp, l, TRUE);
2094 ++j;
2095 if (new_rows > wp->w_height - row - 2)
2096 {
2097 /* it's getting too much, must redraw the rest */
2098 new_rows = 9999;
2099 break;
2100 }
2101 }
2102 xtra_rows = new_rows - old_rows;
2103 if (xtra_rows < 0)
2104 {
2105 /* May scroll text up. If there is not enough
2106 * remaining text or scrolling fails, must redraw the
2107 * rest. If scrolling works, must redraw the text
2108 * below the scrolled text. */
2109 if (row - xtra_rows >= wp->w_height - 2)
2110 mod_bot = MAXLNUM;
2111 else
2112 {
2113 check_for_delay(FALSE);
2114 if (win_del_lines(wp, row,
Bram Moolenaarcfce7172017-08-17 20:31:48 +02002115 -xtra_rows, FALSE, FALSE, 0) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002116 mod_bot = MAXLNUM;
2117 else
2118 bot_start = wp->w_height + xtra_rows;
2119 }
2120 }
2121 else if (xtra_rows > 0)
2122 {
2123 /* May scroll text down. If there is not enough
2124 * remaining text of scrolling fails, must redraw the
2125 * rest. */
2126 if (row + xtra_rows >= wp->w_height - 2)
2127 mod_bot = MAXLNUM;
2128 else
2129 {
2130 check_for_delay(FALSE);
2131 if (win_ins_lines(wp, row + old_rows,
2132 xtra_rows, FALSE, FALSE) == FAIL)
2133 mod_bot = MAXLNUM;
2134 else if (top_end > row + old_rows)
2135 /* Scrolled the part at the top that requires
2136 * updating down. */
2137 top_end += xtra_rows;
2138 }
2139 }
2140
2141 /* When not updating the rest, may need to move w_lines[]
2142 * entries. */
2143 if (mod_bot != MAXLNUM && i != j)
2144 {
2145 if (j < i)
2146 {
2147 int x = row + new_rows;
2148
2149 /* move entries in w_lines[] upwards */
2150 for (;;)
2151 {
2152 /* stop at last valid entry in w_lines[] */
2153 if (i >= wp->w_lines_valid)
2154 {
2155 wp->w_lines_valid = j;
2156 break;
2157 }
2158 wp->w_lines[j] = wp->w_lines[i];
2159 /* stop at a line that won't fit */
2160 if (x + (int)wp->w_lines[j].wl_size
2161 > wp->w_height)
2162 {
2163 wp->w_lines_valid = j + 1;
2164 break;
2165 }
2166 x += wp->w_lines[j++].wl_size;
2167 ++i;
2168 }
2169 if (bot_start > x)
2170 bot_start = x;
2171 }
2172 else /* j > i */
2173 {
2174 /* move entries in w_lines[] downwards */
2175 j -= i;
2176 wp->w_lines_valid += j;
2177 if (wp->w_lines_valid > wp->w_height)
2178 wp->w_lines_valid = wp->w_height;
2179 for (i = wp->w_lines_valid; i - j >= idx; --i)
2180 wp->w_lines[i] = wp->w_lines[i - j];
2181
2182 /* The w_lines[] entries for inserted lines are
2183 * now invalid, but wl_size may be used above.
2184 * Reset to zero. */
2185 while (i >= idx)
2186 {
2187 wp->w_lines[i].wl_size = 0;
2188 wp->w_lines[i--].wl_valid = FALSE;
2189 }
2190 }
2191 }
2192 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002193 }
2194
2195#ifdef FEAT_FOLDING
2196 /*
2197 * When lines are folded, display one line for all of them.
2198 * Otherwise, display normally (can be several display lines when
2199 * 'wrap' is on).
2200 */
2201 fold_count = foldedCount(wp, lnum, &win_foldinfo);
2202 if (fold_count != 0)
2203 {
2204 fold_line(wp, fold_count, &win_foldinfo, lnum, row);
2205 ++row;
2206 --fold_count;
2207 wp->w_lines[idx].wl_folded = TRUE;
2208 wp->w_lines[idx].wl_lastlnum = lnum + fold_count;
2209# ifdef FEAT_SYN_HL
2210 did_update = DID_FOLD;
2211# endif
2212 }
2213 else
2214#endif
2215 if (idx < wp->w_lines_valid
2216 && wp->w_lines[idx].wl_valid
2217 && wp->w_lines[idx].wl_lnum == lnum
2218 && lnum > wp->w_topline
Bram Moolenaarad9c2a02016-07-27 23:26:04 +02002219 && !(dy_flags & (DY_LASTLINE | DY_TRUNCATE))
Bram Moolenaar17146962019-05-30 00:12:11 +02002220#ifdef FEAT_TEXT_PROP
2221 && !bt_popup(wp->w_buffer)
2222#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002223 && srow + wp->w_lines[idx].wl_size > wp->w_height
2224#ifdef FEAT_DIFF
2225 && diff_check_fill(wp, lnum) == 0
2226#endif
2227 )
2228 {
2229 /* This line is not going to fit. Don't draw anything here,
2230 * will draw "@ " lines below. */
2231 row = wp->w_height + 1;
2232 }
2233 else
2234 {
2235#ifdef FEAT_SEARCH_EXTRA
2236 prepare_search_hl(wp, lnum);
2237#endif
2238#ifdef FEAT_SYN_HL
2239 /* Let the syntax stuff know we skipped a few lines. */
2240 if (syntax_last_parsed != 0 && syntax_last_parsed + 1 < lnum
Bram Moolenaar860cae12010-06-05 23:22:07 +02002241 && syntax_present(wp))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002242 syntax_end_parsing(syntax_last_parsed + 1);
2243#endif
2244
2245 /*
2246 * Display one line.
2247 */
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02002248 row = win_line(wp, lnum, srow, wp->w_height,
2249 mod_top == 0, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002250
2251#ifdef FEAT_FOLDING
2252 wp->w_lines[idx].wl_folded = FALSE;
2253 wp->w_lines[idx].wl_lastlnum = lnum;
2254#endif
2255#ifdef FEAT_SYN_HL
2256 did_update = DID_LINE;
2257 syntax_last_parsed = lnum;
2258#endif
2259 }
2260
2261 wp->w_lines[idx].wl_lnum = lnum;
2262 wp->w_lines[idx].wl_valid = TRUE;
Bram Moolenaar0e19fc02017-10-28 14:45:16 +02002263
2264 /* Past end of the window or end of the screen. Note that after
2265 * resizing wp->w_height may be end up too big. That's a problem
2266 * elsewhere, but prevent a crash here. */
2267 if (row > wp->w_height || row + wp->w_winrow >= Rows)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002268 {
2269 /* we may need the size of that too long line later on */
Bram Moolenaar76b9b362012-02-04 23:35:00 +01002270 if (dollar_vcol == -1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002271 wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE);
2272 ++idx;
2273 break;
2274 }
Bram Moolenaar76b9b362012-02-04 23:35:00 +01002275 if (dollar_vcol == -1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002276 wp->w_lines[idx].wl_size = row - srow;
2277 ++idx;
2278#ifdef FEAT_FOLDING
2279 lnum += fold_count + 1;
2280#else
2281 ++lnum;
2282#endif
2283 }
2284 else
2285 {
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02002286 if (wp->w_p_rnu)
2287 {
Bram Moolenaar0e9deef2018-10-02 21:48:34 +02002288#ifdef FEAT_FOLDING
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02002289 // 'relativenumber' set: The text doesn't need to be drawn, but
2290 // the number column nearly always does.
Bram Moolenaar7701f302018-10-02 21:20:32 +02002291 fold_count = foldedCount(wp, lnum, &win_foldinfo);
2292 if (fold_count != 0)
Bram Moolenaar7701f302018-10-02 21:20:32 +02002293 fold_line(wp, fold_count, &win_foldinfo, lnum, row);
Bram Moolenaar7701f302018-10-02 21:20:32 +02002294 else
Bram Moolenaar0e9deef2018-10-02 21:48:34 +02002295#endif
Bram Moolenaar7701f302018-10-02 21:20:32 +02002296 (void)win_line(wp, lnum, srow, wp->w_height, TRUE, TRUE);
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02002297 }
2298
2299 // This line does not need to be drawn, advance to the next one.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002300 row += wp->w_lines[idx++].wl_size;
2301 if (row > wp->w_height) /* past end of screen */
2302 break;
2303#ifdef FEAT_FOLDING
2304 lnum = wp->w_lines[idx - 1].wl_lastlnum + 1;
2305#else
2306 ++lnum;
2307#endif
2308#ifdef FEAT_SYN_HL
2309 did_update = DID_NONE;
2310#endif
2311 }
2312
2313 if (lnum > buf->b_ml.ml_line_count)
2314 {
2315 eof = TRUE;
2316 break;
2317 }
2318 }
2319 /*
2320 * End of loop over all window lines.
2321 */
2322
Bram Moolenaarcafafb32018-02-22 21:07:09 +01002323#ifdef FEAT_VTP
2324 /* Rewrite the character at the end of the screen line. */
2325 if (use_vtp())
2326 {
2327 int i;
2328
2329 for (i = 0; i < Rows; ++i)
Bram Moolenaarcafafb32018-02-22 21:07:09 +01002330 if (enc_utf8)
2331 if ((*mb_off2cells)(LineOffset[i] + Columns - 2,
2332 LineOffset[i] + screen_Columns) > 1)
2333 screen_draw_rectangle(i, Columns - 2, 1, 2, FALSE);
2334 else
2335 screen_draw_rectangle(i, Columns - 1, 1, 1, FALSE);
2336 else
Bram Moolenaarcafafb32018-02-22 21:07:09 +01002337 screen_char(LineOffset[i] + Columns - 1, i, Columns - 1);
2338 }
2339#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002340
2341 if (idx > wp->w_lines_valid)
2342 wp->w_lines_valid = idx;
2343
2344#ifdef FEAT_SYN_HL
2345 /*
2346 * Let the syntax stuff know we stop parsing here.
2347 */
Bram Moolenaar860cae12010-06-05 23:22:07 +02002348 if (syntax_last_parsed != 0 && syntax_present(wp))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002349 syntax_end_parsing(syntax_last_parsed + 1);
2350#endif
2351
2352 /*
2353 * If we didn't hit the end of the file, and we didn't finish the last
2354 * line we were working on, then the line didn't fit.
2355 */
2356 wp->w_empty_rows = 0;
2357#ifdef FEAT_DIFF
2358 wp->w_filler_rows = 0;
2359#endif
2360 if (!eof && !didline)
2361 {
2362 if (lnum == wp->w_topline)
2363 {
2364 /*
2365 * Single line that does not fit!
2366 * Don't overwrite it, it can be edited.
2367 */
2368 wp->w_botline = lnum + 1;
2369 }
2370#ifdef FEAT_DIFF
2371 else if (diff_check_fill(wp, lnum) >= wp->w_height - srow)
2372 {
2373 /* Window ends in filler lines. */
2374 wp->w_botline = lnum;
2375 wp->w_filler_rows = wp->w_height - srow;
2376 }
2377#endif
Bram Moolenaar17146962019-05-30 00:12:11 +02002378#ifdef FEAT_TEXT_PROP
2379 else if (bt_popup(wp->w_buffer))
2380 {
2381 // popup line that doesn't fit is left as-is
2382 wp->w_botline = lnum;
2383 }
2384#endif
Bram Moolenaarad9c2a02016-07-27 23:26:04 +02002385 else if (dy_flags & DY_TRUNCATE) /* 'display' has "truncate" */
2386 {
2387 int scr_row = W_WINROW(wp) + wp->w_height - 1;
2388
2389 /*
2390 * Last line isn't finished: Display "@@@" in the last screen line.
2391 */
Bram Moolenaar53f81742017-09-22 14:35:51 +02002392 screen_puts_len((char_u *)"@@", 2, scr_row, wp->w_wincol,
Bram Moolenaar8820b482017-03-16 17:23:31 +01002393 HL_ATTR(HLF_AT));
Bram Moolenaarad9c2a02016-07-27 23:26:04 +02002394 screen_fill(scr_row, scr_row + 1,
Bram Moolenaar53f81742017-09-22 14:35:51 +02002395 (int)wp->w_wincol + 2, (int)W_ENDCOL(wp),
Bram Moolenaar8820b482017-03-16 17:23:31 +01002396 '@', ' ', HL_ATTR(HLF_AT));
Bram Moolenaarad9c2a02016-07-27 23:26:04 +02002397 set_empty_rows(wp, srow);
2398 wp->w_botline = lnum;
2399 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400 else if (dy_flags & DY_LASTLINE) /* 'display' has "lastline" */
2401 {
2402 /*
2403 * Last line isn't finished: Display "@@@" at the end.
2404 */
2405 screen_fill(W_WINROW(wp) + wp->w_height - 1,
2406 W_WINROW(wp) + wp->w_height,
2407 (int)W_ENDCOL(wp) - 3, (int)W_ENDCOL(wp),
Bram Moolenaar8820b482017-03-16 17:23:31 +01002408 '@', '@', HL_ATTR(HLF_AT));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002409 set_empty_rows(wp, srow);
2410 wp->w_botline = lnum;
2411 }
2412 else
2413 {
Bram Moolenaar8ee4c012019-03-29 18:08:18 +01002414 win_draw_end(wp, '@', ' ', TRUE, srow, wp->w_height, HLF_AT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002415 wp->w_botline = lnum;
2416 }
2417 }
2418 else
2419 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00002420 draw_vsep_win(wp, row);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002421 if (eof) /* we hit the end of the file */
2422 {
2423 wp->w_botline = buf->b_ml.ml_line_count + 1;
2424#ifdef FEAT_DIFF
2425 j = diff_check_fill(wp, wp->w_botline);
2426 if (j > 0 && !wp->w_botfill)
2427 {
Bram Moolenaar8ee4c012019-03-29 18:08:18 +01002428 // Display filler lines at the end of the file.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002429 if (char2cells(fill_diff) > 1)
2430 i = '-';
2431 else
2432 i = fill_diff;
2433 if (row + j > wp->w_height)
2434 j = wp->w_height - row;
Bram Moolenaar8ee4c012019-03-29 18:08:18 +01002435 win_draw_end(wp, i, i, TRUE, row, row + (int)j, HLF_DED);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002436 row += j;
2437 }
2438#endif
2439 }
Bram Moolenaar76b9b362012-02-04 23:35:00 +01002440 else if (dollar_vcol == -1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002441 wp->w_botline = lnum;
2442
Bram Moolenaar8ee4c012019-03-29 18:08:18 +01002443 // Make sure the rest of the screen is blank
2444 // put '~'s on rows that aren't part of the file.
Bram Moolenaar17146962019-05-30 00:12:11 +02002445 win_draw_end(wp,
2446#ifdef FEAT_TEXT_PROP
2447 bt_popup(wp->w_buffer) ? ' ' :
2448#endif
2449 '~', ' ', FALSE, row, wp->w_height, HLF_EOB);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002450 }
2451
Bram Moolenaarf3d769a2017-09-22 13:44:56 +02002452#ifdef SYN_TIME_LIMIT
2453 syn_set_timeout(NULL);
2454#endif
2455
Bram Moolenaar071d4272004-06-13 20:20:40 +00002456 /* Reset the type of redrawing required, the window has been updated. */
2457 wp->w_redr_type = 0;
2458#ifdef FEAT_DIFF
2459 wp->w_old_topfill = wp->w_topfill;
2460 wp->w_old_botfill = wp->w_botfill;
2461#endif
2462
Bram Moolenaar76b9b362012-02-04 23:35:00 +01002463 if (dollar_vcol == -1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002464 {
2465 /*
2466 * There is a trick with w_botline. If we invalidate it on each
2467 * change that might modify it, this will cause a lot of expensive
2468 * calls to plines() in update_topline() each time. Therefore the
2469 * value of w_botline is often approximated, and this value is used to
2470 * compute the value of w_topline. If the value of w_botline was
2471 * wrong, check that the value of w_topline is correct (cursor is on
2472 * the visible part of the text). If it's not, we need to redraw
2473 * again. Mostly this just means scrolling up a few lines, so it
2474 * doesn't look too bad. Only do this for the current window (where
2475 * changes are relevant).
2476 */
2477 wp->w_valid |= VALID_BOTLINE;
2478 if (wp == curwin && wp->w_botline != old_botline && !recursive)
2479 {
2480 recursive = TRUE;
2481 curwin->w_valid &= ~VALID_TOPLINE;
2482 update_topline(); /* may invalidate w_botline again */
2483 if (must_redraw != 0)
2484 {
2485 /* Don't update for changes in buffer again. */
2486 i = curbuf->b_mod_set;
2487 curbuf->b_mod_set = FALSE;
2488 win_update(curwin);
2489 must_redraw = 0;
2490 curbuf->b_mod_set = i;
2491 }
2492 recursive = FALSE;
2493 }
2494 }
2495
2496#if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
2497 /* restore got_int, unless CTRL-C was hit while redrawing */
2498 if (!got_int)
2499 got_int = save_got_int;
2500#endif
2501}
2502
Bram Moolenaar071d4272004-06-13 20:20:40 +00002503/*
Bram Moolenaar8ee4c012019-03-29 18:08:18 +01002504 * Call screen_fill() with the columns adjusted for 'rightleft' if needed.
2505 * Return the new offset.
2506 */
2507 static int
2508screen_fill_end(
2509 win_T *wp,
2510 int c1,
2511 int c2,
2512 int off,
2513 int width,
2514 int row,
2515 int endrow,
2516 int attr)
2517{
2518 int nn = off + width;
2519
2520 if (nn > wp->w_width)
2521 nn = wp->w_width;
2522#ifdef FEAT_RIGHTLEFT
2523 if (wp->w_p_rl)
2524 {
2525 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow,
2526 W_ENDCOL(wp) - nn, (int)W_ENDCOL(wp) - off,
2527 c1, c2, attr);
2528 }
2529 else
2530#endif
2531 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow,
2532 wp->w_wincol + off, (int)wp->w_wincol + nn,
2533 c1, c2, attr);
2534 return nn;
2535}
2536
2537/*
2538 * Clear lines near the end the window and mark the unused lines with "c1".
2539 * use "c2" as the filler character.
2540 * When "draw_margin" is TRUE then draw the sign, fold and number columns.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002541 */
2542 static void
Bram Moolenaar05540972016-01-30 20:31:25 +01002543win_draw_end(
2544 win_T *wp,
2545 int c1,
2546 int c2,
Bram Moolenaar8ee4c012019-03-29 18:08:18 +01002547 int draw_margin,
Bram Moolenaar05540972016-01-30 20:31:25 +01002548 int row,
2549 int endrow,
2550 hlf_T hl)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002551{
Bram Moolenaar071d4272004-06-13 20:20:40 +00002552 int n = 0;
Bram Moolenaar193ffd12019-05-25 22:57:30 +02002553 int attr = HL_ATTR(hl);
Bram Moolenaar60cdb302019-05-27 21:54:10 +02002554 int wcr_attr = get_wcr_attr(wp);
Bram Moolenaar193ffd12019-05-25 22:57:30 +02002555
Bram Moolenaar60cdb302019-05-27 21:54:10 +02002556 attr = hl_combine_attr(wcr_attr, attr);
Bram Moolenaar8ee4c012019-03-29 18:08:18 +01002557
2558 if (draw_margin)
2559 {
Bram Moolenaar1c934292015-01-27 16:39:29 +01002560#ifdef FEAT_FOLDING
Bram Moolenaar8ee4c012019-03-29 18:08:18 +01002561 int fdc = compute_foldcolumn(wp, 0);
2562
2563 if (fdc > 0)
2564 // draw the fold column
2565 n = screen_fill_end(wp, ' ', ' ', n, fdc,
Bram Moolenaar193ffd12019-05-25 22:57:30 +02002566 row, endrow, hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC)));
Bram Moolenaar1c934292015-01-27 16:39:29 +01002567#endif
Bram Moolenaar8ee4c012019-03-29 18:08:18 +01002568#ifdef FEAT_SIGNS
2569 if (signcolumn_on(wp))
2570 // draw the sign column
2571 n = screen_fill_end(wp, ' ', ' ', n, 2,
Bram Moolenaar193ffd12019-05-25 22:57:30 +02002572 row, endrow, hl_combine_attr(wcr_attr, HL_ATTR(HLF_SC)));
Bram Moolenaar8ee4c012019-03-29 18:08:18 +01002573#endif
2574 if ((wp->w_p_nu || wp->w_p_rnu)
2575 && vim_strchr(p_cpo, CPO_NUMCOL) == NULL)
2576 // draw the number column
2577 n = screen_fill_end(wp, ' ', ' ', n, number_width(wp) + 1,
Bram Moolenaar193ffd12019-05-25 22:57:30 +02002578 row, endrow, hl_combine_attr(wcr_attr, HL_ATTR(HLF_N)));
Bram Moolenaar8ee4c012019-03-29 18:08:18 +01002579 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002580
2581#ifdef FEAT_RIGHTLEFT
2582 if (wp->w_p_rl)
2583 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00002584 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow,
Bram Moolenaar8ee4c012019-03-29 18:08:18 +01002585 wp->w_wincol, W_ENDCOL(wp) - 1 - n,
Bram Moolenaar193ffd12019-05-25 22:57:30 +02002586 c2, c2, attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002587 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow,
Bram Moolenaar8ee4c012019-03-29 18:08:18 +01002588 W_ENDCOL(wp) - 1 - n, W_ENDCOL(wp) - n,
Bram Moolenaar193ffd12019-05-25 22:57:30 +02002589 c1, c2, attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002590 }
2591 else
2592#endif
2593 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00002594 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow,
Bram Moolenaar8ee4c012019-03-29 18:08:18 +01002595 wp->w_wincol + n, (int)W_ENDCOL(wp),
Bram Moolenaar193ffd12019-05-25 22:57:30 +02002596 c1, c2, attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002597 }
Bram Moolenaar8ee4c012019-03-29 18:08:18 +01002598
Bram Moolenaar071d4272004-06-13 20:20:40 +00002599 set_empty_rows(wp, row);
2600}
2601
Bram Moolenaar1a384422010-07-14 19:53:30 +02002602#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02002603/*
2604 * Advance **color_cols and return TRUE when there are columns to draw.
2605 */
2606 static int
Bram Moolenaar05540972016-01-30 20:31:25 +01002607advance_color_col(int vcol, int **color_cols)
Bram Moolenaar1a384422010-07-14 19:53:30 +02002608{
2609 while (**color_cols >= 0 && vcol > **color_cols)
2610 ++*color_cols;
2611 return (**color_cols >= 0);
2612}
2613#endif
2614
Bram Moolenaar1b9645d2017-09-17 23:03:31 +02002615#if defined(FEAT_MENU) || defined(FEAT_FOLDING)
2616/*
2617 * Copy "text" to ScreenLines using "attr".
2618 * Returns the next screen column.
2619 */
2620 static int
2621text_to_screenline(win_T *wp, char_u *text, int col)
2622{
2623 int off = (int)(current_ScreenLine - ScreenLines);
2624
Bram Moolenaar1b9645d2017-09-17 23:03:31 +02002625 if (has_mbyte)
2626 {
2627 int cells;
2628 int u8c, u8cc[MAX_MCO];
2629 int i;
2630 int idx;
2631 int c_len;
2632 char_u *p;
2633# ifdef FEAT_ARABIC
2634 int prev_c = 0; /* previous Arabic character */
2635 int prev_c1 = 0; /* first composing char for prev_c */
2636# endif
2637
2638# ifdef FEAT_RIGHTLEFT
2639 if (wp->w_p_rl)
2640 idx = off;
2641 else
2642# endif
2643 idx = off + col;
2644
2645 /* Store multibyte characters in ScreenLines[] et al. correctly. */
2646 for (p = text; *p != NUL; )
2647 {
2648 cells = (*mb_ptr2cells)(p);
2649 c_len = (*mb_ptr2len)(p);
Bram Moolenaar02631462017-09-22 15:20:32 +02002650 if (col + cells > wp->w_width
Bram Moolenaar1b9645d2017-09-17 23:03:31 +02002651# ifdef FEAT_RIGHTLEFT
2652 - (wp->w_p_rl ? col : 0)
2653# endif
2654 )
2655 break;
2656 ScreenLines[idx] = *p;
2657 if (enc_utf8)
2658 {
2659 u8c = utfc_ptr2char(p, u8cc);
2660 if (*p < 0x80 && u8cc[0] == 0)
2661 {
2662 ScreenLinesUC[idx] = 0;
2663#ifdef FEAT_ARABIC
2664 prev_c = u8c;
2665#endif
2666 }
2667 else
2668 {
2669#ifdef FEAT_ARABIC
2670 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c))
2671 {
2672 /* Do Arabic shaping. */
2673 int pc, pc1, nc;
2674 int pcc[MAX_MCO];
2675 int firstbyte = *p;
2676
2677 /* The idea of what is the previous and next
2678 * character depends on 'rightleft'. */
2679 if (wp->w_p_rl)
2680 {
2681 pc = prev_c;
2682 pc1 = prev_c1;
2683 nc = utf_ptr2char(p + c_len);
2684 prev_c1 = u8cc[0];
2685 }
2686 else
2687 {
2688 pc = utfc_ptr2char(p + c_len, pcc);
2689 nc = prev_c;
2690 pc1 = pcc[0];
2691 }
2692 prev_c = u8c;
2693
2694 u8c = arabic_shape(u8c, &firstbyte, &u8cc[0],
2695 pc, pc1, nc);
2696 ScreenLines[idx] = firstbyte;
2697 }
2698 else
2699 prev_c = u8c;
2700#endif
2701 /* Non-BMP character: display as ? or fullwidth ?. */
Bram Moolenaar9ba61172019-01-24 18:20:17 +01002702 ScreenLinesUC[idx] = u8c;
Bram Moolenaar1b9645d2017-09-17 23:03:31 +02002703 for (i = 0; i < Screen_mco; ++i)
2704 {
2705 ScreenLinesC[i][idx] = u8cc[i];
2706 if (u8cc[i] == 0)
2707 break;
2708 }
2709 }
2710 if (cells > 1)
2711 ScreenLines[idx + 1] = 0;
2712 }
2713 else if (enc_dbcs == DBCS_JPNU && *p == 0x8e)
2714 /* double-byte single width character */
2715 ScreenLines2[idx] = p[1];
2716 else if (cells > 1)
2717 /* double-width character */
2718 ScreenLines[idx + 1] = p[1];
2719 col += cells;
2720 idx += cells;
2721 p += c_len;
2722 }
2723 }
2724 else
Bram Moolenaar1b9645d2017-09-17 23:03:31 +02002725 {
2726 int len = (int)STRLEN(text);
2727
Bram Moolenaar02631462017-09-22 15:20:32 +02002728 if (len > wp->w_width - col)
2729 len = wp->w_width - col;
Bram Moolenaar1b9645d2017-09-17 23:03:31 +02002730 if (len > 0)
2731 {
2732#ifdef FEAT_RIGHTLEFT
2733 if (wp->w_p_rl)
Bram Moolenaarc6663882019-02-22 19:14:54 +01002734 mch_memmove(current_ScreenLine, text, len);
Bram Moolenaar1b9645d2017-09-17 23:03:31 +02002735 else
2736#endif
Bram Moolenaarc6663882019-02-22 19:14:54 +01002737 mch_memmove(current_ScreenLine + col, text, len);
Bram Moolenaar1b9645d2017-09-17 23:03:31 +02002738 col += len;
2739 }
2740 }
2741 return col;
2742}
2743#endif
2744
Bram Moolenaar071d4272004-06-13 20:20:40 +00002745#ifdef FEAT_FOLDING
2746/*
Bram Moolenaar1c934292015-01-27 16:39:29 +01002747 * Compute the width of the foldcolumn. Based on 'foldcolumn' and how much
2748 * space is available for window "wp", minus "col".
2749 */
2750 static int
Bram Moolenaar05540972016-01-30 20:31:25 +01002751compute_foldcolumn(win_T *wp, int col)
Bram Moolenaar1c934292015-01-27 16:39:29 +01002752{
2753 int fdc = wp->w_p_fdc;
2754 int wmw = wp == curwin && p_wmw == 0 ? 1 : p_wmw;
Bram Moolenaar02631462017-09-22 15:20:32 +02002755 int wwidth = wp->w_width;
Bram Moolenaar1c934292015-01-27 16:39:29 +01002756
2757 if (fdc > wwidth - (col + wmw))
2758 fdc = wwidth - (col + wmw);
2759 return fdc;
2760}
2761
2762/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00002763 * Display one folded line.
2764 */
2765 static void
Bram Moolenaar05540972016-01-30 20:31:25 +01002766fold_line(
2767 win_T *wp,
2768 long fold_count,
2769 foldinfo_T *foldinfo,
2770 linenr_T lnum,
2771 int row)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002772{
Bram Moolenaaree695f72016-08-03 22:08:45 +02002773 char_u buf[FOLD_TEXT_LEN];
Bram Moolenaar071d4272004-06-13 20:20:40 +00002774 pos_T *top, *bot;
2775 linenr_T lnume = lnum + fold_count - 1;
2776 int len;
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00002777 char_u *text;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002778 int fdc;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002779 int col;
2780 int txtcol;
2781 int off = (int)(current_ScreenLine - ScreenLines);
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00002782 int ri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002783
2784 /* Build the fold line:
2785 * 1. Add the cmdwin_type for the command-line window
2786 * 2. Add the 'foldcolumn'
Bram Moolenaar64486672010-05-16 15:46:46 +02002787 * 3. Add the 'number' or 'relativenumber' column
Bram Moolenaar071d4272004-06-13 20:20:40 +00002788 * 4. Compose the text
2789 * 5. Add the text
2790 * 6. set highlighting for the Visual area an other text
2791 */
2792 col = 0;
2793
2794 /*
2795 * 1. Add the cmdwin_type for the command-line window
2796 * Ignores 'rightleft', this window is never right-left.
2797 */
2798#ifdef FEAT_CMDWIN
2799 if (cmdwin_type != 0 && wp == curwin)
2800 {
2801 ScreenLines[off] = cmdwin_type;
Bram Moolenaar8820b482017-03-16 17:23:31 +01002802 ScreenAttrs[off] = HL_ATTR(HLF_AT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002803 if (enc_utf8)
2804 ScreenLinesUC[off] = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002805 ++col;
2806 }
2807#endif
2808
2809 /*
2810 * 2. Add the 'foldcolumn'
Bram Moolenaar1c934292015-01-27 16:39:29 +01002811 * Reduce the width when there is not enough space.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002812 */
Bram Moolenaar1c934292015-01-27 16:39:29 +01002813 fdc = compute_foldcolumn(wp, col);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002814 if (fdc > 0)
2815 {
2816 fill_foldcolumn(buf, wp, TRUE, lnum);
2817#ifdef FEAT_RIGHTLEFT
2818 if (wp->w_p_rl)
2819 {
2820 int i;
2821
Bram Moolenaar02631462017-09-22 15:20:32 +02002822 copy_text_attr(off + wp->w_width - fdc - col, buf, fdc,
Bram Moolenaar8820b482017-03-16 17:23:31 +01002823 HL_ATTR(HLF_FC));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002824 /* reverse the fold column */
2825 for (i = 0; i < fdc; ++i)
Bram Moolenaar02631462017-09-22 15:20:32 +02002826 ScreenLines[off + wp->w_width - i - 1 - col] = buf[i];
Bram Moolenaar071d4272004-06-13 20:20:40 +00002827 }
2828 else
2829#endif
Bram Moolenaar8820b482017-03-16 17:23:31 +01002830 copy_text_attr(off + col, buf, fdc, HL_ATTR(HLF_FC));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002831 col += fdc;
2832 }
2833
2834#ifdef FEAT_RIGHTLEFT
Bram Moolenaar6f470022018-04-10 18:47:20 +02002835# define RL_MEMSET(p, v, l) \
2836 do { \
2837 if (wp->w_p_rl) \
2838 for (ri = 0; ri < l; ++ri) \
2839 ScreenAttrs[off + (wp->w_width - (p) - (l)) + ri] = v; \
2840 else \
2841 for (ri = 0; ri < l; ++ri) \
2842 ScreenAttrs[off + (p) + ri] = v; \
2843 } while (0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002844#else
Bram Moolenaar6f470022018-04-10 18:47:20 +02002845# define RL_MEMSET(p, v, l) \
2846 do { \
2847 for (ri = 0; ri < l; ++ri) \
2848 ScreenAttrs[off + (p) + ri] = v; \
2849 } while (0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002850#endif
2851
Bram Moolenaar64486672010-05-16 15:46:46 +02002852 /* Set all attributes of the 'number' or 'relativenumber' column and the
2853 * text */
Bram Moolenaar02631462017-09-22 15:20:32 +02002854 RL_MEMSET(col, HL_ATTR(HLF_FL), wp->w_width - col);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002855
2856#ifdef FEAT_SIGNS
2857 /* If signs are being displayed, add two spaces. */
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002858 if (signcolumn_on(wp))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002859 {
Bram Moolenaar02631462017-09-22 15:20:32 +02002860 len = wp->w_width - col;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002861 if (len > 0)
2862 {
2863 if (len > 2)
2864 len = 2;
2865# ifdef FEAT_RIGHTLEFT
2866 if (wp->w_p_rl)
2867 /* the line number isn't reversed */
Bram Moolenaar02631462017-09-22 15:20:32 +02002868 copy_text_attr(off + wp->w_width - len - col,
Bram Moolenaar8820b482017-03-16 17:23:31 +01002869 (char_u *)" ", len, HL_ATTR(HLF_FL));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002870 else
2871# endif
Bram Moolenaar8820b482017-03-16 17:23:31 +01002872 copy_text_attr(off + col, (char_u *)" ", len, HL_ATTR(HLF_FL));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002873 col += len;
2874 }
2875 }
2876#endif
2877
2878 /*
Bram Moolenaar64486672010-05-16 15:46:46 +02002879 * 3. Add the 'number' or 'relativenumber' column
Bram Moolenaar071d4272004-06-13 20:20:40 +00002880 */
Bram Moolenaar64486672010-05-16 15:46:46 +02002881 if (wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002882 {
Bram Moolenaar02631462017-09-22 15:20:32 +02002883 len = wp->w_width - col;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002884 if (len > 0)
2885 {
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002886 int w = number_width(wp);
Bram Moolenaar24dc2302014-05-13 20:19:58 +02002887 long num;
2888 char *fmt = "%*ld ";
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002889
2890 if (len > w + 1)
2891 len = w + 1;
Bram Moolenaar64486672010-05-16 15:46:46 +02002892
Bram Moolenaar5ebc09b2013-06-04 22:13:50 +02002893 if (wp->w_p_nu && !wp->w_p_rnu)
2894 /* 'number' + 'norelativenumber' */
Bram Moolenaar64486672010-05-16 15:46:46 +02002895 num = (long)lnum;
2896 else
Bram Moolenaar700e7342013-01-30 12:31:36 +01002897 {
Bram Moolenaar64486672010-05-16 15:46:46 +02002898 /* 'relativenumber', don't use negative numbers */
Bram Moolenaar7eb46522010-12-30 14:57:08 +01002899 num = labs((long)get_cursor_rel_lnum(wp, lnum));
Bram Moolenaar5ebc09b2013-06-04 22:13:50 +02002900 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
Bram Moolenaar700e7342013-01-30 12:31:36 +01002901 {
Bram Moolenaar5ebc09b2013-06-04 22:13:50 +02002902 /* 'number' + 'relativenumber': cursor line shows absolute
2903 * line number */
Bram Moolenaar700e7342013-01-30 12:31:36 +01002904 num = lnum;
2905 fmt = "%-*ld ";
2906 }
2907 }
Bram Moolenaar64486672010-05-16 15:46:46 +02002908
Bram Moolenaar700e7342013-01-30 12:31:36 +01002909 sprintf((char *)buf, fmt, w, num);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002910#ifdef FEAT_RIGHTLEFT
2911 if (wp->w_p_rl)
2912 /* the line number isn't reversed */
Bram Moolenaar02631462017-09-22 15:20:32 +02002913 copy_text_attr(off + wp->w_width - len - col, buf, len,
Bram Moolenaar8820b482017-03-16 17:23:31 +01002914 HL_ATTR(HLF_FL));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002915 else
2916#endif
Bram Moolenaar8820b482017-03-16 17:23:31 +01002917 copy_text_attr(off + col, buf, len, HL_ATTR(HLF_FL));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002918 col += len;
2919 }
2920 }
2921
2922 /*
2923 * 4. Compose the folded-line string with 'foldtext', if set.
2924 */
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00002925 text = get_foldtext(wp, lnum, lnume, foldinfo, buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002926
2927 txtcol = col; /* remember where text starts */
2928
2929 /*
2930 * 5. move the text to current_ScreenLine. Fill up with "fill_fold".
2931 * Right-left text is put in columns 0 - number-col, normal text is put
2932 * in columns number-col - window-width.
2933 */
Bram Moolenaar1b9645d2017-09-17 23:03:31 +02002934 col = text_to_screenline(wp, text, col);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002935
2936 /* Fill the rest of the line with the fold filler */
2937#ifdef FEAT_RIGHTLEFT
2938 if (wp->w_p_rl)
2939 col -= txtcol;
2940#endif
Bram Moolenaar02631462017-09-22 15:20:32 +02002941 while (col < wp->w_width
Bram Moolenaar071d4272004-06-13 20:20:40 +00002942#ifdef FEAT_RIGHTLEFT
2943 - (wp->w_p_rl ? txtcol : 0)
2944#endif
2945 )
2946 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00002947 if (enc_utf8)
2948 {
2949 if (fill_fold >= 0x80)
2950 {
2951 ScreenLinesUC[off + col] = fill_fold;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00002952 ScreenLinesC[0][off + col] = 0;
Bram Moolenaaracda04f2018-02-08 09:57:28 +01002953 ScreenLines[off + col] = 0x80; /* avoid storing zero */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002954 }
2955 else
Bram Moolenaar8da1e6c2017-03-29 20:38:59 +02002956 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00002957 ScreenLinesUC[off + col] = 0;
Bram Moolenaar8da1e6c2017-03-29 20:38:59 +02002958 ScreenLines[off + col] = fill_fold;
2959 }
Bram Moolenaarc6cd8402017-03-29 14:40:47 +02002960 col++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002961 }
Bram Moolenaarc6cd8402017-03-29 14:40:47 +02002962 else
Bram Moolenaarc6cd8402017-03-29 14:40:47 +02002963 ScreenLines[off + col++] = fill_fold;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002964 }
2965
2966 if (text != buf)
2967 vim_free(text);
2968
2969 /*
2970 * 6. set highlighting for the Visual area an other text.
2971 * If all folded lines are in the Visual area, highlight the line.
2972 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002973 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
2974 {
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01002975 if (LTOREQ_POS(curwin->w_cursor, VIsual))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002976 {
2977 /* Visual is after curwin->w_cursor */
2978 top = &curwin->w_cursor;
2979 bot = &VIsual;
2980 }
2981 else
2982 {
2983 /* Visual is before curwin->w_cursor */
2984 top = &VIsual;
2985 bot = &curwin->w_cursor;
2986 }
2987 if (lnum >= top->lnum
2988 && lnume <= bot->lnum
2989 && (VIsual_mode != 'v'
2990 || ((lnum > top->lnum
2991 || (lnum == top->lnum
2992 && top->col == 0))
2993 && (lnume < bot->lnum
2994 || (lnume == bot->lnum
2995 && (bot->col - (*p_sel == 'e'))
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002996 >= (colnr_T)STRLEN(ml_get_buf(wp->w_buffer, lnume, FALSE)))))))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997 {
2998 if (VIsual_mode == Ctrl_V)
2999 {
3000 /* Visual block mode: highlight the chars part of the block */
Bram Moolenaar02631462017-09-22 15:20:32 +02003001 if (wp->w_old_cursor_fcol + txtcol < (colnr_T)wp->w_width)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003002 {
Bram Moolenaar6c167c62011-09-02 14:07:36 +02003003 if (wp->w_old_cursor_lcol != MAXCOL
3004 && wp->w_old_cursor_lcol + txtcol
Bram Moolenaar02631462017-09-22 15:20:32 +02003005 < (colnr_T)wp->w_width)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003006 len = wp->w_old_cursor_lcol;
3007 else
Bram Moolenaar02631462017-09-22 15:20:32 +02003008 len = wp->w_width - txtcol;
Bram Moolenaar8820b482017-03-16 17:23:31 +01003009 RL_MEMSET(wp->w_old_cursor_fcol + txtcol, HL_ATTR(HLF_V),
Bram Moolenaar68b76a62005-03-25 21:53:48 +00003010 len - (int)wp->w_old_cursor_fcol);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011 }
3012 }
3013 else
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00003014 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003015 /* Set all attributes of the text */
Bram Moolenaar02631462017-09-22 15:20:32 +02003016 RL_MEMSET(txtcol, HL_ATTR(HLF_V), wp->w_width - txtcol);
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00003017 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003018 }
3019 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020
Bram Moolenaar600dddc2006-03-12 22:05:10 +00003021#ifdef FEAT_SYN_HL
Bram Moolenaarfbc25b22015-03-20 17:16:27 +01003022 /* Show colorcolumn in the fold line, but let cursorcolumn override it. */
3023 if (wp->w_p_cc_cols)
3024 {
3025 int i = 0;
3026 int j = wp->w_p_cc_cols[i];
3027 int old_txtcol = txtcol;
3028
3029 while (j > -1)
3030 {
3031 txtcol += j;
3032 if (wp->w_p_wrap)
3033 txtcol -= wp->w_skipcol;
3034 else
3035 txtcol -= wp->w_leftcol;
Bram Moolenaar02631462017-09-22 15:20:32 +02003036 if (txtcol >= 0 && txtcol < wp->w_width)
Bram Moolenaarfbc25b22015-03-20 17:16:27 +01003037 ScreenAttrs[off + txtcol] = hl_combine_attr(
Bram Moolenaar8820b482017-03-16 17:23:31 +01003038 ScreenAttrs[off + txtcol], HL_ATTR(HLF_MC));
Bram Moolenaarfbc25b22015-03-20 17:16:27 +01003039 txtcol = old_txtcol;
3040 j = wp->w_p_cc_cols[++i];
3041 }
3042 }
3043
Bram Moolenaar600dddc2006-03-12 22:05:10 +00003044 /* Show 'cursorcolumn' in the fold line. */
Bram Moolenaar85595c52008-10-02 16:04:05 +00003045 if (wp->w_p_cuc)
3046 {
3047 txtcol += wp->w_virtcol;
3048 if (wp->w_p_wrap)
3049 txtcol -= wp->w_skipcol;
3050 else
3051 txtcol -= wp->w_leftcol;
Bram Moolenaar02631462017-09-22 15:20:32 +02003052 if (txtcol >= 0 && txtcol < wp->w_width)
Bram Moolenaar85595c52008-10-02 16:04:05 +00003053 ScreenAttrs[off + txtcol] = hl_combine_attr(
Bram Moolenaar8820b482017-03-16 17:23:31 +01003054 ScreenAttrs[off + txtcol], HL_ATTR(HLF_CUC));
Bram Moolenaar85595c52008-10-02 16:04:05 +00003055 }
Bram Moolenaar600dddc2006-03-12 22:05:10 +00003056#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057
Bram Moolenaar02631462017-09-22 15:20:32 +02003058 screen_line(row + W_WINROW(wp), wp->w_wincol, (int)wp->w_width,
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003059 (int)wp->w_width, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003060
3061 /*
3062 * Update w_cline_height and w_cline_folded if the cursor line was
3063 * updated (saves a call to plines() later).
3064 */
3065 if (wp == curwin
3066 && lnum <= curwin->w_cursor.lnum
3067 && lnume >= curwin->w_cursor.lnum)
3068 {
3069 curwin->w_cline_row = row;
3070 curwin->w_cline_height = 1;
3071 curwin->w_cline_folded = TRUE;
3072 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3073 }
3074}
3075
3076/*
3077 * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr".
3078 */
3079 static void
Bram Moolenaar05540972016-01-30 20:31:25 +01003080copy_text_attr(
3081 int off,
3082 char_u *buf,
3083 int len,
3084 int attr)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003085{
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00003086 int i;
3087
Bram Moolenaar071d4272004-06-13 20:20:40 +00003088 mch_memmove(ScreenLines + off, buf, (size_t)len);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003089 if (enc_utf8)
3090 vim_memset(ScreenLinesUC + off, 0, sizeof(u8char_T) * (size_t)len);
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00003091 for (i = 0; i < len; ++i)
3092 ScreenAttrs[off + i] = attr;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003093}
3094
3095/*
3096 * Fill the foldcolumn at "p" for window "wp".
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00003097 * Only to be called when 'foldcolumn' > 0.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003098 */
3099 static void
Bram Moolenaar05540972016-01-30 20:31:25 +01003100fill_foldcolumn(
3101 char_u *p,
3102 win_T *wp,
3103 int closed, /* TRUE of FALSE */
3104 linenr_T lnum) /* current line number */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003105{
3106 int i = 0;
3107 int level;
3108 int first_level;
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003109 int empty;
Bram Moolenaar1c934292015-01-27 16:39:29 +01003110 int fdc = compute_foldcolumn(wp, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003111
3112 /* Init to all spaces. */
Bram Moolenaar2536d4f2015-07-17 13:22:51 +02003113 vim_memset(p, ' ', (size_t)fdc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003114
3115 level = win_foldinfo.fi_level;
3116 if (level > 0)
3117 {
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003118 /* If there is only one column put more info in it. */
Bram Moolenaar1c934292015-01-27 16:39:29 +01003119 empty = (fdc == 1) ? 0 : 1;
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003120
Bram Moolenaar071d4272004-06-13 20:20:40 +00003121 /* If the column is too narrow, we start at the lowest level that
3122 * fits and use numbers to indicated the depth. */
Bram Moolenaar1c934292015-01-27 16:39:29 +01003123 first_level = level - fdc - closed + 1 + empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003124 if (first_level < 1)
3125 first_level = 1;
3126
Bram Moolenaar1c934292015-01-27 16:39:29 +01003127 for (i = 0; i + empty < fdc; ++i)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003128 {
3129 if (win_foldinfo.fi_lnum == lnum
3130 && first_level + i >= win_foldinfo.fi_low_level)
3131 p[i] = '-';
3132 else if (first_level == 1)
3133 p[i] = '|';
3134 else if (first_level + i <= 9)
3135 p[i] = '0' + first_level + i;
3136 else
3137 p[i] = '>';
3138 if (first_level + i == level)
3139 break;
3140 }
3141 }
3142 if (closed)
Bram Moolenaar1c934292015-01-27 16:39:29 +01003143 p[i >= fdc ? i - 1 : i] = '+';
Bram Moolenaar071d4272004-06-13 20:20:40 +00003144}
3145#endif /* FEAT_FOLDING */
3146
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01003147#ifdef FEAT_TEXT_PROP
3148static textprop_T *current_text_props = NULL;
3149static buf_T *current_buf = NULL;
3150
3151 static int
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01003152text_prop_compare(const void *s1, const void *s2)
3153{
3154 int idx1, idx2;
3155 proptype_T *pt1, *pt2;
3156 colnr_T col1, col2;
3157
3158 idx1 = *(int *)s1;
3159 idx2 = *(int *)s2;
3160 pt1 = text_prop_type_by_id(current_buf, current_text_props[idx1].tp_type);
3161 pt2 = text_prop_type_by_id(current_buf, current_text_props[idx2].tp_type);
3162 if (pt1 == pt2)
3163 return 0;
3164 if (pt1 == NULL)
3165 return -1;
3166 if (pt2 == NULL)
3167 return 1;
3168 if (pt1->pt_priority != pt2->pt_priority)
3169 return pt1->pt_priority > pt2->pt_priority ? 1 : -1;
3170 col1 = current_text_props[idx1].tp_col;
3171 col2 = current_text_props[idx2].tp_col;
3172 return col1 == col2 ? 0 : col1 > col2 ? 1 : -1;
3173}
3174#endif
3175
Bram Moolenaar071d4272004-06-13 20:20:40 +00003176/*
3177 * Display line "lnum" of window 'wp' on the screen.
3178 * Start at row "startrow", stop when "endrow" is reached.
3179 * wp->w_virtcol needs to be valid.
3180 *
3181 * Return the number of last row the line occupies.
3182 */
3183 static int
Bram Moolenaar05540972016-01-30 20:31:25 +01003184win_line(
3185 win_T *wp,
3186 linenr_T lnum,
3187 int startrow,
3188 int endrow,
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003189 int nochange UNUSED, // not updating for changed text
3190 int number_only) // only update the number column
Bram Moolenaar071d4272004-06-13 20:20:40 +00003191{
Bram Moolenaar04e87b72017-02-01 21:23:10 +01003192 int col = 0; /* visual column on screen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003193 unsigned off; /* offset in ScreenLines/ScreenAttrs */
3194 int c = 0; /* init for GCC */
3195 long vcol = 0; /* virtual column (for tabs) */
Bram Moolenaard574ea22015-01-14 19:35:14 +01003196#ifdef FEAT_LINEBREAK
3197 long vcol_sbr = -1; /* virtual column after showbreak */
3198#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003199 long vcol_prev = -1; /* "vcol" of previous character */
3200 char_u *line; /* current line */
3201 char_u *ptr; /* current position in "line" */
3202 int row; /* row in the window, excl w_winrow */
3203 int screen_row; /* row on the screen, incl w_winrow */
3204
3205 char_u extra[18]; /* "%ld" and 'fdc' must fit in here */
3206 int n_extra = 0; /* number of extra chars */
Bram Moolenaara064ac82007-08-05 18:10:54 +00003207 char_u *p_extra = NULL; /* string of extra chars, plus NUL */
Bram Moolenaar86b17e92014-07-02 20:00:47 +02003208 char_u *p_extra_free = NULL; /* p_extra needs to be freed */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003209 int c_extra = NUL; /* extra chars, all the same */
Bram Moolenaar83a52172019-01-16 22:41:54 +01003210 int c_final = NUL; /* final char, mandatory if set */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003211 int extra_attr = 0; /* attributes when n_extra != 0 */
3212 static char_u *at_end_str = (char_u *)""; /* used for p_extra when
3213 displaying lcs_eol at end-of-line */
3214 int lcs_eol_one = lcs_eol; /* lcs_eol until it's been used */
3215 int lcs_prec_todo = lcs_prec; /* lcs_prec until it's been used */
3216
3217 /* saved "extra" items for when draw_state becomes WL_LINE (again) */
3218 int saved_n_extra = 0;
3219 char_u *saved_p_extra = NULL;
3220 int saved_c_extra = 0;
Bram Moolenaar83a52172019-01-16 22:41:54 +01003221 int saved_c_final = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003222 int saved_char_attr = 0;
3223
3224 int n_attr = 0; /* chars with special attr */
3225 int saved_attr2 = 0; /* char_attr saved for n_attr */
3226 int n_attr3 = 0; /* chars with overruling special attr */
3227 int saved_attr3 = 0; /* char_attr saved for n_attr3 */
3228
3229 int n_skip = 0; /* nr of chars to skip for 'nowrap' */
3230
3231 int fromcol, tocol; /* start/end of inverting */
3232 int fromcol_prev = -2; /* start of inverting after cursor */
3233 int noinvcur = FALSE; /* don't invert the cursor */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003234 pos_T *top, *bot;
Bram Moolenaar54ef7112009-02-21 20:11:41 +00003235 int lnum_in_visual_area = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003236 pos_T pos;
3237 long v;
3238
Bram Moolenaar193ffd12019-05-25 22:57:30 +02003239 int char_attr = 0; // attributes for next character
3240 int attr_pri = FALSE; // char_attr has priority
3241 int area_highlighting = FALSE; // Visual or incsearch highlighting
3242 // in this line
3243 int vi_attr = 0; // attributes for Visual and incsearch
3244 // highlighting
3245 int wcr_attr = 0; // attributes from 'wincolor'
Bram Moolenaar60cdb302019-05-27 21:54:10 +02003246 int win_attr = 0; // background for whole window, except
3247 // margins and "~" lines.
Bram Moolenaar193ffd12019-05-25 22:57:30 +02003248 int area_attr = 0; // attributes desired by highlighting
3249 int search_attr = 0; // attributes desired by 'hlsearch'
Bram Moolenaar071d4272004-06-13 20:20:40 +00003250#ifdef FEAT_SYN_HL
Bram Moolenaar600dddc2006-03-12 22:05:10 +00003251 int vcol_save_attr = 0; /* saved attr for 'cursorcolumn' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003252 int syntax_attr = 0; /* attributes desired by syntax */
3253 int has_syntax = FALSE; /* this buffer has syntax highl. */
3254 int save_did_emsg;
Bram Moolenaara443af82007-11-08 13:51:42 +00003255 int eol_hl_off = 0; /* 1 if highlighted char after EOL */
Bram Moolenaar1a384422010-07-14 19:53:30 +02003256 int draw_color_col = FALSE; /* highlight colorcolumn */
3257 int *color_cols = NULL; /* pointer to according columns array */
Bram Moolenaar600dddc2006-03-12 22:05:10 +00003258#endif
Bram Moolenaar98aefe72018-12-13 22:20:09 +01003259#ifdef FEAT_TEXT_PROP
3260 int text_prop_count;
3261 int text_prop_next = 0; // next text property to use
3262 textprop_T *text_props = NULL;
3263 int *text_prop_idxs = NULL;
3264 int text_props_active = 0;
3265 proptype_T *text_prop_type = NULL;
3266 int text_prop_attr = 0;
Bram Moolenaarde24a872019-05-05 15:48:00 +02003267 int text_prop_combine = FALSE;
Bram Moolenaar98aefe72018-12-13 22:20:09 +01003268#endif
Bram Moolenaar600dddc2006-03-12 22:05:10 +00003269#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00003270 int has_spell = FALSE; /* this buffer has spell checking */
Bram Moolenaar30abd282005-06-22 22:35:10 +00003271# define SPWORDLEN 150
3272 char_u nextline[SPWORDLEN * 2];/* text with start of the next line */
Bram Moolenaar3b506942005-06-23 22:36:45 +00003273 int nextlinecol = 0; /* column where nextline[] starts */
3274 int nextline_idx = 0; /* index in nextline[] where next line
Bram Moolenaar30abd282005-06-22 22:35:10 +00003275 starts */
Bram Moolenaar217ad922005-03-20 22:37:15 +00003276 int spell_attr = 0; /* attributes desired by spelling */
3277 int word_end = 0; /* last byte with same spell_attr */
Bram Moolenaard042c562005-06-30 22:04:15 +00003278 static linenr_T checked_lnum = 0; /* line number for "checked_col" */
3279 static int checked_col = 0; /* column in "checked_lnum" up to which
Bram Moolenaar30abd282005-06-22 22:35:10 +00003280 * there are no spell errors */
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003281 static int cap_col = -1; /* column to check for Cap word */
3282 static linenr_T capcol_lnum = 0; /* line number where "cap_col" used */
Bram Moolenaar30abd282005-06-22 22:35:10 +00003283 int cur_checked_col = 0; /* checked column for current line */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003284#endif
Bram Moolenaar98aefe72018-12-13 22:20:09 +01003285 int extra_check = 0; // has extra highlighting
Bram Moolenaar071d4272004-06-13 20:20:40 +00003286 int multi_attr = 0; /* attributes desired by multibyte */
3287 int mb_l = 1; /* multi-byte byte length */
3288 int mb_c = 0; /* decoded multi-byte character */
3289 int mb_utf8 = FALSE; /* screen char is UTF-8 char */
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003290 int u8cc[MAX_MCO]; /* composing UTF-8 chars */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003291#ifdef FEAT_DIFF
3292 int filler_lines; /* nr of filler lines to be drawn */
3293 int filler_todo; /* nr of filler lines still to do + 1 */
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00003294 hlf_T diff_hlf = (hlf_T)0; /* type of diff highlighting */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003295 int change_start = MAXCOL; /* first col of changed area */
3296 int change_end = -1; /* last col of changed area */
3297#endif
3298 colnr_T trailcol = MAXCOL; /* start of trailing spaces */
3299#ifdef FEAT_LINEBREAK
Bram Moolenaar6c896862016-11-17 19:46:51 +01003300 int need_showbreak = FALSE; /* overlong line, skipping first x
3301 chars */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003302#endif
Bram Moolenaar4033c552017-09-16 20:54:51 +02003303#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
Bram Moolenaar6c60ea22006-07-11 20:36:45 +00003304 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003305# define LINE_ATTR
Bram Moolenaar4ef9e492008-02-13 20:49:04 +00003306 int line_attr = 0; /* attribute for the whole line */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003307#endif
3308#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaar6ee10162007-07-26 20:58:42 +00003309 matchitem_T *cur; /* points to the match list */
3310 match_T *shl; /* points to search_hl or a match */
3311 int shl_flag; /* flag to indicate whether search_hl
3312 has been processed or not */
Bram Moolenaarb3414592014-06-17 17:48:32 +02003313 int pos_inprogress; /* marks that position match search is
3314 in progress */
Bram Moolenaar6ee10162007-07-26 20:58:42 +00003315 int prevcol_hl_flag; /* flag to indicate whether prevcol
3316 equals startcol of search_hl or one
3317 of the matches */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003318#endif
3319#ifdef FEAT_ARABIC
3320 int prev_c = 0; /* previous Arabic character */
3321 int prev_c1 = 0; /* first composing char for prev_c */
3322#endif
Bram Moolenaar6c60ea22006-07-11 20:36:45 +00003323#if defined(LINE_ATTR)
Bram Moolenaar91170f82006-05-05 21:15:17 +00003324 int did_line_attr = 0;
3325#endif
Bram Moolenaar63ecdda2017-07-28 22:29:35 +02003326#ifdef FEAT_TERMINAL
3327 int get_term_attr = FALSE;
3328#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003329
3330 /* draw_state: items that are drawn in sequence: */
3331#define WL_START 0 /* nothing done yet */
3332#ifdef FEAT_CMDWIN
3333# define WL_CMDLINE WL_START + 1 /* cmdline window column */
3334#else
3335# define WL_CMDLINE WL_START
3336#endif
3337#ifdef FEAT_FOLDING
3338# define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */
3339#else
3340# define WL_FOLD WL_CMDLINE
3341#endif
3342#ifdef FEAT_SIGNS
3343# define WL_SIGN WL_FOLD + 1 /* column for signs */
3344#else
3345# define WL_SIGN WL_FOLD /* column for signs */
3346#endif
3347#define WL_NR WL_SIGN + 1 /* line number */
Bram Moolenaar597a4222014-06-25 14:39:50 +02003348#ifdef FEAT_LINEBREAK
3349# define WL_BRI WL_NR + 1 /* 'breakindent' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003350#else
Bram Moolenaar597a4222014-06-25 14:39:50 +02003351# define WL_BRI WL_NR
3352#endif
3353#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
3354# define WL_SBR WL_BRI + 1 /* 'showbreak' or 'diff' */
3355#else
3356# define WL_SBR WL_BRI
Bram Moolenaar071d4272004-06-13 20:20:40 +00003357#endif
3358#define WL_LINE WL_SBR + 1 /* text in the line */
3359 int draw_state = WL_START; /* what to draw next */
Bram Moolenaar9372a112005-12-06 19:59:18 +00003360#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003361 int feedback_col = 0;
3362 int feedback_old_attr = -1;
3363#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003364 int screen_line_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003365
Bram Moolenaar860cae12010-06-05 23:22:07 +02003366#ifdef FEAT_CONCEAL
3367 int syntax_flags = 0;
Bram Moolenaarffbbcb52010-07-24 17:29:03 +02003368 int syntax_seqnr = 0;
Bram Moolenaar27c735b2010-07-22 22:16:29 +02003369 int prev_syntax_id = 0;
Bram Moolenaar8820b482017-03-16 17:23:31 +01003370 int conceal_attr = HL_ATTR(HLF_CONCEAL);
Bram Moolenaar860cae12010-06-05 23:22:07 +02003371 int is_concealing = FALSE;
3372 int boguscols = 0; /* nonexistent columns added to force
3373 wrapping */
Bram Moolenaar8d9b40e2010-07-25 15:49:07 +02003374 int vcol_off = 0; /* offset for concealed characters */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02003375 int did_wcol = FALSE;
Bram Moolenaar4d585022016-04-14 19:50:22 +02003376 int match_conc = 0; /* cchar for match functions */
Bram Moolenaar6a6028c2015-01-20 19:01:35 +01003377 int old_boguscols = 0;
Bram Moolenaarac550fd2010-07-18 13:55:02 +02003378# define VCOL_HLC (vcol - vcol_off)
Bram Moolenaar3ff9b182013-07-13 12:36:55 +02003379# define FIX_FOR_BOGUSCOLS \
3380 { \
3381 n_extra += vcol_off; \
3382 vcol -= vcol_off; \
3383 vcol_off = 0; \
3384 col -= boguscols; \
Bram Moolenaar6a6028c2015-01-20 19:01:35 +01003385 old_boguscols = boguscols; \
Bram Moolenaar3ff9b182013-07-13 12:36:55 +02003386 boguscols = 0; \
3387 }
Bram Moolenaarac550fd2010-07-18 13:55:02 +02003388#else
3389# define VCOL_HLC (vcol)
Bram Moolenaar860cae12010-06-05 23:22:07 +02003390#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003391
3392 if (startrow > endrow) /* past the end already! */
3393 return startrow;
3394
3395 row = startrow;
3396 screen_row = row + W_WINROW(wp);
3397
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003398 if (!number_only)
3399 {
3400 /*
3401 * To speed up the loop below, set extra_check when there is linebreak,
3402 * trailing white space and/or syntax processing to be done.
3403 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003404#ifdef FEAT_LINEBREAK
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003405 extra_check = wp->w_p_lbr;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003406#endif
3407#ifdef FEAT_SYN_HL
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003408 if (syntax_present(wp) && !wp->w_s->b_syn_error
Bram Moolenaar06f1ed22017-06-18 22:41:03 +02003409# ifdef SYN_TIME_LIMIT
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003410 && !wp->w_s->b_syn_slow
Bram Moolenaar06f1ed22017-06-18 22:41:03 +02003411# endif
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003412 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003413 {
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003414 /* Prepare for syntax highlighting in this line. When there is an
3415 * error, stop syntax highlighting. */
3416 save_did_emsg = did_emsg;
3417 did_emsg = FALSE;
3418 syntax_start(wp, lnum);
3419 if (did_emsg)
3420 wp->w_s->b_syn_error = TRUE;
3421 else
Bram Moolenaar06f1ed22017-06-18 22:41:03 +02003422 {
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003423 did_emsg = save_did_emsg;
3424#ifdef SYN_TIME_LIMIT
3425 if (!wp->w_s->b_syn_slow)
3426#endif
3427 {
3428 has_syntax = TRUE;
3429 extra_check = TRUE;
3430 }
Bram Moolenaar06f1ed22017-06-18 22:41:03 +02003431 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003432 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02003433
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003434 /* Check for columns to display for 'colorcolumn'. */
3435 color_cols = wp->w_p_cc_cols;
3436 if (color_cols != NULL)
3437 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
Bram Moolenaar600dddc2006-03-12 22:05:10 +00003438#endif
Bram Moolenaar217ad922005-03-20 22:37:15 +00003439
Bram Moolenaar63ecdda2017-07-28 22:29:35 +02003440#ifdef FEAT_TERMINAL
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003441 if (term_show_buffer(wp->w_buffer))
3442 {
3443 extra_check = TRUE;
3444 get_term_attr = TRUE;
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003445 win_attr = term_get_attr(wp->w_buffer, lnum, -1);
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003446 }
Bram Moolenaar63ecdda2017-07-28 22:29:35 +02003447#endif
3448
Bram Moolenaar600dddc2006-03-12 22:05:10 +00003449#ifdef FEAT_SPELL
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003450 if (wp->w_p_spell
3451 && *wp->w_s->b_p_spl != NUL
3452 && wp->w_s->b_langp.ga_len > 0
3453 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
Bram Moolenaar30abd282005-06-22 22:35:10 +00003454 {
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003455 /* Prepare for spell checking. */
3456 has_spell = TRUE;
3457 extra_check = TRUE;
3458
Bram Moolenaar7701f302018-10-02 21:20:32 +02003459 /* Get the start of the next line, so that words that wrap to the
3460 * next line are found too: "et<line-break>al.".
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003461 * Trick: skip a few chars for C/shell/Vim comments */
3462 nextline[SPWORDLEN] = NUL;
3463 if (lnum < wp->w_buffer->b_ml.ml_line_count)
3464 {
3465 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
3466 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
3467 }
3468
Bram Moolenaar7701f302018-10-02 21:20:32 +02003469 /* When a word wrapped from the previous line the start of the
3470 * current line is valid. */
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003471 if (lnum == checked_lnum)
3472 cur_checked_col = checked_col;
3473 checked_lnum = 0;
3474
3475 /* When there was a sentence end in the previous line may require a
3476 * word starting with capital in this line. In line 1 always check
3477 * the first word. */
3478 if (lnum != capcol_lnum)
3479 cap_col = -1;
3480 if (lnum == 1)
3481 cap_col = 0;
3482 capcol_lnum = 0;
Bram Moolenaar30abd282005-06-22 22:35:10 +00003483 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003484#endif
3485
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003486 /*
3487 * handle visual active in this window
3488 */
3489 fromcol = -10;
3490 tocol = MAXCOL;
3491 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003492 {
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003493 /* Visual is after curwin->w_cursor */
3494 if (LTOREQ_POS(curwin->w_cursor, VIsual))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003495 {
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003496 top = &curwin->w_cursor;
3497 bot = &VIsual;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003498 }
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003499 else /* Visual is before curwin->w_cursor */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003500 {
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003501 top = &VIsual;
3502 bot = &curwin->w_cursor;
3503 }
3504 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
3505 if (VIsual_mode == Ctrl_V) /* block mode */
3506 {
3507 if (lnum_in_visual_area)
3508 {
3509 fromcol = wp->w_old_cursor_fcol;
3510 tocol = wp->w_old_cursor_lcol;
3511 }
3512 }
3513 else /* non-block mode */
3514 {
3515 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003516 fromcol = 0;
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003517 else if (lnum == top->lnum)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003518 {
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003519 if (VIsual_mode == 'V') /* linewise */
3520 fromcol = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003521 else
3522 {
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003523 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
3524 if (gchar_pos(top) == NUL)
3525 tocol = fromcol + 1;
3526 }
3527 }
3528 if (VIsual_mode != 'V' && lnum == bot->lnum)
3529 {
Bram Moolenaar29ddebe2019-01-26 17:28:26 +01003530 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003531 {
3532 fromcol = -10;
3533 tocol = MAXCOL;
3534 }
3535 else if (bot->col == MAXCOL)
3536 tocol = MAXCOL;
3537 else
3538 {
3539 pos = *bot;
3540 if (*p_sel == 'e')
3541 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
3542 else
3543 {
3544 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
3545 ++tocol;
3546 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003547 }
3548 }
3549 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003550
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003551 /* Check if the character under the cursor should not be inverted */
3552 if (!highlight_match && lnum == curwin->w_cursor.lnum && wp == curwin
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003553#ifdef FEAT_GUI
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003554 && !gui.in_use
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003555#endif
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003556 )
3557 noinvcur = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003558
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003559 /* if inverting in this line set area_highlighting */
3560 if (fromcol >= 0)
3561 {
3562 area_highlighting = TRUE;
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003563 vi_attr = HL_ATTR(HLF_V);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003564#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003565 if ((clip_star.available && !clip_star.owned
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003566 && clip_isautosel_star())
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003567 || (clip_plus.available && !clip_plus.owned
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003568 && clip_isautosel_plus()))
3569 vi_attr = HL_ATTR(HLF_VNC);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003570#endif
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003571 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003572 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003573
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003574 /*
3575 * handle 'incsearch' and ":s///c" highlighting
3576 */
3577 else if (highlight_match
3578 && wp == curwin
3579 && lnum >= curwin->w_cursor.lnum
3580 && lnum <= curwin->w_cursor.lnum + search_match_lines)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003581 {
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003582 if (lnum == curwin->w_cursor.lnum)
3583 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc6663882019-02-22 19:14:54 +01003584 (colnr_T *)&fromcol, NULL, NULL);
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003585 else
3586 fromcol = 0;
3587 if (lnum == curwin->w_cursor.lnum + search_match_lines)
3588 {
3589 pos.lnum = lnum;
3590 pos.col = search_match_endcol;
3591 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
3592 }
3593 else
3594 tocol = MAXCOL;
3595 /* do at least one character; happens when past end of line */
3596 if (fromcol == tocol)
3597 tocol = fromcol + 1;
3598 area_highlighting = TRUE;
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003599 vi_attr = HL_ATTR(HLF_I);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003600 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003601 }
3602
3603#ifdef FEAT_DIFF
3604 filler_lines = diff_check(wp, lnum);
3605 if (filler_lines < 0)
3606 {
3607 if (filler_lines == -1)
3608 {
3609 if (diff_find_change(wp, lnum, &change_start, &change_end))
3610 diff_hlf = HLF_ADD; /* added line */
3611 else if (change_start == 0)
3612 diff_hlf = HLF_TXD; /* changed text */
3613 else
3614 diff_hlf = HLF_CHD; /* changed line */
3615 }
3616 else
3617 diff_hlf = HLF_ADD; /* added line */
3618 filler_lines = 0;
3619 area_highlighting = TRUE;
3620 }
3621 if (lnum == wp->w_topline)
3622 filler_lines = wp->w_topfill;
3623 filler_todo = filler_lines;
3624#endif
3625
3626#ifdef LINE_ATTR
3627# ifdef FEAT_SIGNS
3628 /* If this line has a sign with line highlighting set line_attr. */
3629 v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL);
3630 if (v != 0)
3631 line_attr = sign_get_attr((int)v, TRUE);
3632# endif
Bram Moolenaar4033c552017-09-16 20:54:51 +02003633# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003634 /* Highlight the current line in the quickfix window. */
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003635 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar21020352017-06-13 17:21:04 +02003636 line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003637# endif
3638 if (line_attr != 0)
3639 area_highlighting = TRUE;
3640#endif
3641
3642 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
3643 ptr = line;
3644
Bram Moolenaar600dddc2006-03-12 22:05:10 +00003645#ifdef FEAT_SPELL
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003646 if (has_spell && !number_only)
Bram Moolenaar30abd282005-06-22 22:35:10 +00003647 {
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003648 /* For checking first word with a capital skip white space. */
3649 if (cap_col == 0)
Bram Moolenaare2e69e42017-09-02 20:30:35 +02003650 cap_col = getwhitecols(line);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003651
Bram Moolenaar30abd282005-06-22 22:35:10 +00003652 /* To be able to spell-check over line boundaries copy the end of the
3653 * current line into nextline[]. Above the start of the next line was
3654 * copied to nextline[SPWORDLEN]. */
3655 if (nextline[SPWORDLEN] == NUL)
3656 {
3657 /* No next line or it is empty. */
3658 nextlinecol = MAXCOL;
3659 nextline_idx = 0;
3660 }
3661 else
3662 {
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003663 v = (long)STRLEN(line);
Bram Moolenaar30abd282005-06-22 22:35:10 +00003664 if (v < SPWORDLEN)
3665 {
3666 /* Short line, use it completely and append the start of the
3667 * next line. */
3668 nextlinecol = 0;
3669 mch_memmove(nextline, line, (size_t)v);
Bram Moolenaar446cb832008-06-24 21:56:24 +00003670 STRMOVE(nextline + v, nextline + SPWORDLEN);
Bram Moolenaar30abd282005-06-22 22:35:10 +00003671 nextline_idx = v + 1;
3672 }
3673 else
3674 {
3675 /* Long line, use only the last SPWORDLEN bytes. */
3676 nextlinecol = v - SPWORDLEN;
3677 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
3678 nextline_idx = SPWORDLEN + 1;
3679 }
3680 }
3681 }
3682#endif
3683
Bram Moolenaar9bc01eb2015-12-17 21:14:58 +01003684 if (wp->w_p_list)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003685 {
Bram Moolenaar895d9662019-01-31 21:57:21 +01003686 if (lcs_space || lcs_trail || lcs_nbsp)
Bram Moolenaar9bc01eb2015-12-17 21:14:58 +01003687 extra_check = TRUE;
3688 /* find start of trailing whitespace */
3689 if (lcs_trail)
3690 {
3691 trailcol = (colnr_T)STRLEN(ptr);
Bram Moolenaar1c465442017-03-12 20:10:05 +01003692 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
Bram Moolenaar9bc01eb2015-12-17 21:14:58 +01003693 --trailcol;
3694 trailcol += (colnr_T) (ptr - line);
3695 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003696 }
3697
Bram Moolenaar60cdb302019-05-27 21:54:10 +02003698 wcr_attr = get_wcr_attr(wp);
3699 if (wcr_attr != 0)
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003700 {
Bram Moolenaar60cdb302019-05-27 21:54:10 +02003701 win_attr = wcr_attr;
3702 area_highlighting = TRUE;
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003703 }
3704#ifdef FEAT_TEXT_PROP
3705 if (bt_popup(wp->w_buffer))
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003706 screen_line_flags |= SLF_POPUP;
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003707#endif
3708
Bram Moolenaar071d4272004-06-13 20:20:40 +00003709 /*
3710 * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
3711 * first character to be displayed.
3712 */
3713 if (wp->w_p_wrap)
3714 v = wp->w_skipcol;
3715 else
3716 v = wp->w_leftcol;
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02003717 if (v > 0 && !number_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003718 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003719 char_u *prev_ptr = ptr;
Bram Moolenaara12a1612019-01-24 16:39:02 +01003720
Bram Moolenaar071d4272004-06-13 20:20:40 +00003721 while (vcol < v && *ptr != NUL)
3722 {
Bram Moolenaar597a4222014-06-25 14:39:50 +02003723 c = win_lbr_chartabsize(wp, line, ptr, (colnr_T)vcol, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003724 vcol += c;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003725 prev_ptr = ptr;
Bram Moolenaar91acfff2017-03-12 19:22:36 +01003726 MB_PTR_ADV(ptr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003727 }
3728
Bram Moolenaarbb6a7052009-11-03 16:36:44 +00003729 /* When:
3730 * - 'cuc' is set, or
Bram Moolenaar1a384422010-07-14 19:53:30 +02003731 * - 'colorcolumn' is set, or
Bram Moolenaarbb6a7052009-11-03 16:36:44 +00003732 * - 'virtualedit' is set, or
3733 * - the visual mode is active,
3734 * the end of the line may be before the start of the displayed part.
3735 */
3736 if (vcol < v && (
Bram Moolenaarf7ff6e82014-03-23 15:13:05 +01003737#ifdef FEAT_SYN_HL
3738 wp->w_p_cuc || draw_color_col ||
3739#endif
Bram Moolenaarf7ff6e82014-03-23 15:13:05 +01003740 virtual_active() ||
Bram Moolenaarf7ff6e82014-03-23 15:13:05 +01003741 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003742 vcol = v;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003743
3744 /* Handle a character that's not completely on the screen: Put ptr at
3745 * that character but skip the first few screen characters. */
3746 if (vcol > v)
3747 {
3748 vcol -= c;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003749 ptr = prev_ptr;
Bram Moolenaarabc39ab2017-03-01 18:04:05 +01003750 /* If the character fits on the screen, don't need to skip it.
3751 * Except for a TAB. */
Bram Moolenaara12a1612019-01-24 16:39:02 +01003752 if (( (*mb_ptr2cells)(ptr) >= c || *ptr == TAB) && col == 0)
Bram Moolenaar04e87b72017-02-01 21:23:10 +01003753 n_skip = v - vcol;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003754 }
3755
3756 /*
3757 * Adjust for when the inverted text is before the screen,
3758 * and when the start of the inverted text is before the screen.
3759 */
3760 if (tocol <= vcol)
3761 fromcol = 0;
3762 else if (fromcol >= 0 && fromcol < vcol)
3763 fromcol = vcol;
3764
3765#ifdef FEAT_LINEBREAK
3766 /* When w_skipcol is non-zero, first line needs 'showbreak' */
3767 if (wp->w_p_wrap)
3768 need_showbreak = TRUE;
3769#endif
Bram Moolenaar600dddc2006-03-12 22:05:10 +00003770#ifdef FEAT_SPELL
Bram Moolenaar81f1ecb2005-08-25 21:27:31 +00003771 /* When spell checking a word we need to figure out the start of the
3772 * word and if it's badly spelled or not. */
3773 if (has_spell)
3774 {
3775 int len;
Bram Moolenaar4ef9e492008-02-13 20:49:04 +00003776 colnr_T linecol = (colnr_T)(ptr - line);
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00003777 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaar81f1ecb2005-08-25 21:27:31 +00003778
3779 pos = wp->w_cursor;
3780 wp->w_cursor.lnum = lnum;
Bram Moolenaar4ef9e492008-02-13 20:49:04 +00003781 wp->w_cursor.col = linecol;
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00003782 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
Bram Moolenaar4ef9e492008-02-13 20:49:04 +00003783
3784 /* spell_move_to() may call ml_get() and make "line" invalid */
3785 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
3786 ptr = line + linecol;
3787
Bram Moolenaar60a795a2005-09-16 21:55:43 +00003788 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
Bram Moolenaar81f1ecb2005-08-25 21:27:31 +00003789 {
3790 /* no bad word found at line start, don't check until end of a
3791 * word */
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00003792 spell_hlf = HLF_COUNT;
Bram Moolenaar3b393a02012-06-06 19:05:50 +02003793 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
Bram Moolenaar81f1ecb2005-08-25 21:27:31 +00003794 }
3795 else
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00003796 {
Bram Moolenaar81f1ecb2005-08-25 21:27:31 +00003797 /* bad word found, use attributes until end of word */
3798 word_end = wp->w_cursor.col + len + 1;
3799
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00003800 /* Turn index into actual attributes. */
3801 if (spell_hlf != HLF_COUNT)
3802 spell_attr = highlight_attr[spell_hlf];
3803 }
Bram Moolenaar81f1ecb2005-08-25 21:27:31 +00003804 wp->w_cursor = pos;
Bram Moolenaarda2303d2005-08-30 21:55:26 +00003805
Bram Moolenaar600dddc2006-03-12 22:05:10 +00003806# ifdef FEAT_SYN_HL
Bram Moolenaarda2303d2005-08-30 21:55:26 +00003807 /* Need to restart syntax highlighting for this line. */
3808 if (has_syntax)
Bram Moolenaarf3d769a2017-09-22 13:44:56 +02003809 syntax_start(wp, lnum);
Bram Moolenaar600dddc2006-03-12 22:05:10 +00003810# endif
Bram Moolenaar81f1ecb2005-08-25 21:27:31 +00003811 }
3812#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003813 }
3814
3815 /*
3816 * Correct highlighting for cursor that can't be disabled.
3817 * Avoids having to check this for each character.
3818 */
3819 if (fromcol >= 0)
3820 {
3821 if (noinvcur)
3822 {
3823 if ((colnr_T)fromcol == wp->w_virtcol)
3824 {
3825 /* highlighting starts at cursor, let it start just after the
3826 * cursor */
3827 fromcol_prev = fromcol;
3828 fromcol = -1;
3829 }
3830 else if ((colnr_T)fromcol < wp->w_virtcol)
3831 /* restart highlighting after the cursor */
3832 fromcol_prev = wp->w_virtcol;
3833 }
3834 if (fromcol >= tocol)
3835 fromcol = -1;
3836 }
3837
3838#ifdef FEAT_SEARCH_EXTRA
3839 /*
Bram Moolenaar6ee10162007-07-26 20:58:42 +00003840 * Handle highlighting the last used search pattern and matches.
3841 * Do this for both search_hl and the match list.
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003842 * Not in a popup window.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003843 */
Bram Moolenaar6ee10162007-07-26 20:58:42 +00003844 cur = wp->w_match_head;
3845 shl_flag = FALSE;
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003846 while ((cur != NULL || shl_flag == FALSE) && !number_only
3847 && !(screen_line_flags & SLF_POPUP))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003848 {
Bram Moolenaar6ee10162007-07-26 20:58:42 +00003849 if (shl_flag == FALSE)
3850 {
3851 shl = &search_hl;
3852 shl_flag = TRUE;
3853 }
3854 else
3855 shl = &cur->hl;
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003856 shl->startcol = MAXCOL;
3857 shl->endcol = MAXCOL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003858 shl->attr_cur = 0;
Bram Moolenaar4f416e42016-08-16 16:08:18 +02003859 shl->is_addpos = FALSE;
Bram Moolenaarb3414592014-06-17 17:48:32 +02003860 v = (long)(ptr - line);
3861 if (cur != NULL)
3862 cur->pos.cur = 0;
Bram Moolenaare17bdff2016-08-27 18:34:29 +02003863 next_search_hl(wp, shl, lnum, (colnr_T)v,
3864 shl == &search_hl ? NULL : cur);
Bram Moolenaarb3414592014-06-17 17:48:32 +02003865
3866 /* Need to get the line again, a multi-line regexp may have made it
3867 * invalid. */
3868 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
3869 ptr = line + v;
3870
3871 if (shl->lnum != 0 && shl->lnum <= lnum)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003872 {
Bram Moolenaarb3414592014-06-17 17:48:32 +02003873 if (shl->lnum == lnum)
3874 shl->startcol = shl->rm.startpos[0].col;
3875 else
3876 shl->startcol = 0;
3877 if (lnum == shl->lnum + shl->rm.endpos[0].lnum
3878 - shl->rm.startpos[0].lnum)
3879 shl->endcol = shl->rm.endpos[0].col;
3880 else
3881 shl->endcol = MAXCOL;
3882 /* Highlight one character for an empty match. */
3883 if (shl->startcol == shl->endcol)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003884 {
Bram Moolenaarb3414592014-06-17 17:48:32 +02003885 if (has_mbyte && line[shl->endcol] != NUL)
3886 shl->endcol += (*mb_ptr2len)(line + shl->endcol);
3887 else
Bram Moolenaarb3414592014-06-17 17:48:32 +02003888 ++shl->endcol;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003889 }
Bram Moolenaarb3414592014-06-17 17:48:32 +02003890 if ((long)shl->startcol < v) /* match at leftcol */
3891 {
3892 shl->attr_cur = shl->attr;
3893 search_attr = shl->attr;
3894 }
3895 area_highlighting = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003896 }
Bram Moolenaar6ee10162007-07-26 20:58:42 +00003897 if (shl != &search_hl && cur != NULL)
3898 cur = cur->next;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003899 }
3900#endif
3901
Bram Moolenaar600dddc2006-03-12 22:05:10 +00003902#ifdef FEAT_SYN_HL
Bram Moolenaar8156ed32019-03-09 11:46:15 +01003903 // Cursor line highlighting for 'cursorline' in the current window.
3904 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
Bram Moolenaar600dddc2006-03-12 22:05:10 +00003905 {
Bram Moolenaar8156ed32019-03-09 11:46:15 +01003906 // Do not show the cursor line when Visual mode is active, because it's
3907 // not clear what is selected then. Do update w_last_cursorline.
3908 if (!(wp == curwin && VIsual_active))
3909 {
3910 line_attr = HL_ATTR(HLF_CUL);
3911 area_highlighting = TRUE;
3912 }
Bram Moolenaarc07ff5c2019-01-30 21:41:14 +01003913 wp->w_last_cursorline = wp->w_cursor.lnum;
Bram Moolenaar600dddc2006-03-12 22:05:10 +00003914 }
3915#endif
3916
Bram Moolenaar98aefe72018-12-13 22:20:09 +01003917#ifdef FEAT_TEXT_PROP
3918 {
3919 char_u *prop_start;
3920
3921 text_prop_count = get_text_props(wp->w_buffer, lnum,
3922 &prop_start, FALSE);
3923 if (text_prop_count > 0)
3924 {
3925 // Make a copy of the properties, so that they are properly
3926 // aligned.
Bram Moolenaarc799fe22019-05-28 23:08:19 +02003927 text_props = ALLOC_MULT(textprop_T, text_prop_count);
Bram Moolenaar98aefe72018-12-13 22:20:09 +01003928 if (text_props != NULL)
3929 mch_memmove(text_props, prop_start,
3930 text_prop_count * sizeof(textprop_T));
3931
3932 // Allocate an array for the indexes.
Bram Moolenaarc799fe22019-05-28 23:08:19 +02003933 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaar98aefe72018-12-13 22:20:09 +01003934 area_highlighting = TRUE;
3935 extra_check = TRUE;
3936 }
3937 }
3938#endif
3939
Bram Moolenaar92d640f2005-09-05 22:11:52 +00003940 off = (unsigned)(current_ScreenLine - ScreenLines);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003941 col = 0;
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003942
Bram Moolenaar071d4272004-06-13 20:20:40 +00003943#ifdef FEAT_RIGHTLEFT
3944 if (wp->w_p_rl)
3945 {
3946 /* Rightleft window: process the text in the normal direction, but put
3947 * it in current_ScreenLine[] from right to left. Start at the
3948 * rightmost column of the window. */
Bram Moolenaar02631462017-09-22 15:20:32 +02003949 col = wp->w_width - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003950 off += col;
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003951 screen_line_flags |= SLF_RIGHTLEFT;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003952 }
3953#endif
3954
3955 /*
3956 * Repeat for the whole displayed line.
3957 */
3958 for (;;)
3959 {
Bram Moolenaar6561d522015-07-21 15:48:27 +02003960#ifdef FEAT_CONCEAL
Bram Moolenaar0ebe12b2019-05-17 12:31:44 +02003961 int has_match_conc = 0; // match wants to conceal
3962 int did_decrement_ptr = FALSE;
Bram Moolenaar6561d522015-07-21 15:48:27 +02003963#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003964 /* Skip this quickly when working on the text. */
3965 if (draw_state != WL_LINE)
3966 {
3967#ifdef FEAT_CMDWIN
3968 if (draw_state == WL_CMDLINE - 1 && n_extra == 0)
3969 {
3970 draw_state = WL_CMDLINE;
3971 if (cmdwin_type != 0 && wp == curwin)
3972 {
3973 /* Draw the cmdline character. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003974 n_extra = 1;
Bram Moolenaara064ac82007-08-05 18:10:54 +00003975 c_extra = cmdwin_type;
Bram Moolenaar83a52172019-01-16 22:41:54 +01003976 c_final = NUL;
Bram Moolenaar193ffd12019-05-25 22:57:30 +02003977 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003978 }
3979 }
3980#endif
3981
3982#ifdef FEAT_FOLDING
3983 if (draw_state == WL_FOLD - 1 && n_extra == 0)
3984 {
Bram Moolenaar1c934292015-01-27 16:39:29 +01003985 int fdc = compute_foldcolumn(wp, 0);
3986
Bram Moolenaar071d4272004-06-13 20:20:40 +00003987 draw_state = WL_FOLD;
Bram Moolenaar1c934292015-01-27 16:39:29 +01003988 if (fdc > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003989 {
Bram Moolenaar62706602016-12-09 19:28:48 +01003990 /* Draw the 'foldcolumn'. Allocate a buffer, "extra" may
Bram Moolenaarc695cec2017-01-08 20:00:04 +01003991 * already be in use. */
Bram Moolenaarb031c4e2017-01-24 20:14:48 +01003992 vim_free(p_extra_free);
Bram Moolenaar62706602016-12-09 19:28:48 +01003993 p_extra_free = alloc(12 + 1);
3994
3995 if (p_extra_free != NULL)
3996 {
3997 fill_foldcolumn(p_extra_free, wp, FALSE, lnum);
3998 n_extra = fdc;
3999 p_extra_free[n_extra] = NUL;
4000 p_extra = p_extra_free;
4001 c_extra = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01004002 c_final = NUL;
Bram Moolenaar193ffd12019-05-25 22:57:30 +02004003 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar62706602016-12-09 19:28:48 +01004004 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004005 }
4006 }
4007#endif
4008
4009#ifdef FEAT_SIGNS
4010 if (draw_state == WL_SIGN - 1 && n_extra == 0)
4011 {
4012 draw_state = WL_SIGN;
4013 /* Show the sign column when there are any signs in this
4014 * buffer or when using Netbeans. */
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02004015 if (signcolumn_on(wp))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004016 {
Bram Moolenaar7c5676b2010-12-08 19:56:58 +01004017 int text_sign;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004018# ifdef FEAT_SIGN_ICONS
Bram Moolenaar7c5676b2010-12-08 19:56:58 +01004019 int icon_sign;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004020# endif
4021
4022 /* Draw two cells with the sign value or blank. */
4023 c_extra = ' ';
Bram Moolenaar83a52172019-01-16 22:41:54 +01004024 c_final = NUL;
Bram Moolenaar193ffd12019-05-25 22:57:30 +02004025 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar071d4272004-06-13 20:20:40 +00004026 n_extra = 2;
4027
Bram Moolenaarbc6cf6c2014-05-22 15:51:04 +02004028 if (row == startrow
4029#ifdef FEAT_DIFF
4030 + filler_lines && filler_todo <= 0
4031#endif
4032 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004033 {
4034 text_sign = buf_getsigntype(wp->w_buffer, lnum,
4035 SIGN_TEXT);
4036# ifdef FEAT_SIGN_ICONS
4037 icon_sign = buf_getsigntype(wp->w_buffer, lnum,
4038 SIGN_ICON);
4039 if (gui.in_use && icon_sign != 0)
4040 {
4041 /* Use the image in this position. */
4042 c_extra = SIGN_BYTE;
Bram Moolenaar83a52172019-01-16 22:41:54 +01004043 c_final = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004044# ifdef FEAT_NETBEANS_INTG
4045 if (buf_signcount(wp->w_buffer, lnum) > 1)
Bram Moolenaar83a52172019-01-16 22:41:54 +01004046 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004047 c_extra = MULTISIGN_BYTE;
Bram Moolenaar83a52172019-01-16 22:41:54 +01004048 c_final = NUL;
4049 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004050# endif
4051 char_attr = icon_sign;
4052 }
4053 else
4054# endif
4055 if (text_sign != 0)
4056 {
4057 p_extra = sign_get_text(text_sign);
4058 if (p_extra != NULL)
4059 {
4060 c_extra = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01004061 c_final = NUL;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004062 n_extra = (int)STRLEN(p_extra);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004063 }
4064 char_attr = sign_get_attr(text_sign, FALSE);
4065 }
4066 }
4067 }
4068 }
4069#endif
4070
4071 if (draw_state == WL_NR - 1 && n_extra == 0)
4072 {
4073 draw_state = WL_NR;
Bram Moolenaar64486672010-05-16 15:46:46 +02004074 /* Display the absolute or relative line number. After the
4075 * first fill with blanks when the 'n' flag isn't in 'cpo' */
4076 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004077 && (row == startrow
4078#ifdef FEAT_DIFF
4079 + filler_lines
4080#endif
4081 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
4082 {
4083 /* Draw the line number (empty space after wrapping). */
4084 if (row == startrow
4085#ifdef FEAT_DIFF
4086 + filler_lines
4087#endif
4088 )
4089 {
Bram Moolenaar64486672010-05-16 15:46:46 +02004090 long num;
Bram Moolenaar700e7342013-01-30 12:31:36 +01004091 char *fmt = "%*ld ";
Bram Moolenaar64486672010-05-16 15:46:46 +02004092
Bram Moolenaar5ebc09b2013-06-04 22:13:50 +02004093 if (wp->w_p_nu && !wp->w_p_rnu)
4094 /* 'number' + 'norelativenumber' */
Bram Moolenaar64486672010-05-16 15:46:46 +02004095 num = (long)lnum;
4096 else
Bram Moolenaar700e7342013-01-30 12:31:36 +01004097 {
Bram Moolenaar64486672010-05-16 15:46:46 +02004098 /* 'relativenumber', don't use negative numbers */
Bram Moolenaar7eb46522010-12-30 14:57:08 +01004099 num = labs((long)get_cursor_rel_lnum(wp, lnum));
Bram Moolenaar5ebc09b2013-06-04 22:13:50 +02004100 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
Bram Moolenaar700e7342013-01-30 12:31:36 +01004101 {
Bram Moolenaar5ebc09b2013-06-04 22:13:50 +02004102 /* 'number' + 'relativenumber' */
Bram Moolenaar700e7342013-01-30 12:31:36 +01004103 num = lnum;
4104 fmt = "%-*ld ";
4105 }
4106 }
Bram Moolenaar64486672010-05-16 15:46:46 +02004107
Bram Moolenaar700e7342013-01-30 12:31:36 +01004108 sprintf((char *)extra, fmt,
Bram Moolenaar64486672010-05-16 15:46:46 +02004109 number_width(wp), num);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004110 if (wp->w_skipcol > 0)
4111 for (p_extra = extra; *p_extra == ' '; ++p_extra)
4112 *p_extra = '-';
4113#ifdef FEAT_RIGHTLEFT
4114 if (wp->w_p_rl) /* reverse line numbers */
Bram Moolenaare73f9112019-03-29 18:29:54 +01004115 {
4116 char_u *p1, *p2;
4117 int t;
4118
4119 // like rl_mirror(), but keep the space at the end
4120 p2 = skiptowhite(extra) - 1;
4121 for (p1 = extra; p1 < p2; ++p1, --p2)
4122 {
4123 t = *p1;
4124 *p1 = *p2;
4125 *p2 = t;
4126 }
4127 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004128#endif
4129 p_extra = extra;
4130 c_extra = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01004131 c_final = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004132 }
4133 else
Bram Moolenaar83a52172019-01-16 22:41:54 +01004134 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004135 c_extra = ' ';
Bram Moolenaar83a52172019-01-16 22:41:54 +01004136 c_final = NUL;
4137 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00004138 n_extra = number_width(wp) + 1;
Bram Moolenaar193ffd12019-05-25 22:57:30 +02004139 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
Bram Moolenaar600dddc2006-03-12 22:05:10 +00004140#ifdef FEAT_SYN_HL
4141 /* When 'cursorline' is set highlight the line number of
Bram Moolenaar06ca5132012-03-23 16:25:17 +01004142 * the current line differently.
4143 * TODO: Can we use CursorLine instead of CursorLineNr
4144 * when CursorLineNr isn't set? */
Bram Moolenaarbd65c462013-07-01 20:18:33 +02004145 if ((wp->w_p_cul || wp->w_p_rnu)
Bram Moolenaar700e7342013-01-30 12:31:36 +01004146 && lnum == wp->w_cursor.lnum)
Bram Moolenaar193ffd12019-05-25 22:57:30 +02004147 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLN));
Bram Moolenaar600dddc2006-03-12 22:05:10 +00004148#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004149 }
4150 }
4151
Bram Moolenaar597a4222014-06-25 14:39:50 +02004152#ifdef FEAT_LINEBREAK
4153 if (wp->w_p_brisbr && draw_state == WL_BRI - 1
4154 && n_extra == 0 && *p_sbr != NUL)
4155 /* draw indent after showbreak value */
4156 draw_state = WL_BRI;
4157 else if (wp->w_p_brisbr && draw_state == WL_SBR && n_extra == 0)
4158 /* After the showbreak, draw the breakindent */
4159 draw_state = WL_BRI - 1;
4160
4161 /* draw 'breakindent': indent wrapped text accordingly */
4162 if (draw_state == WL_BRI - 1 && n_extra == 0)
4163 {
4164 draw_state = WL_BRI;
Bram Moolenaar6c896862016-11-17 19:46:51 +01004165 /* if need_showbreak is set, breakindent also applies */
4166 if (wp->w_p_bri && n_extra == 0
4167 && (row != startrow || need_showbreak)
Bram Moolenaard710e0d2015-06-10 12:16:47 +02004168# ifdef FEAT_DIFF
Bram Moolenaar597a4222014-06-25 14:39:50 +02004169 && filler_lines == 0
Bram Moolenaard710e0d2015-06-10 12:16:47 +02004170# endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02004171 )
4172 {
Bram Moolenaar6c896862016-11-17 19:46:51 +01004173 char_attr = 0;
Bram Moolenaard710e0d2015-06-10 12:16:47 +02004174# ifdef FEAT_DIFF
Bram Moolenaar597a4222014-06-25 14:39:50 +02004175 if (diff_hlf != (hlf_T)0)
Bram Moolenaare0f14822014-08-06 13:20:56 +02004176 {
Bram Moolenaar8820b482017-03-16 17:23:31 +01004177 char_attr = HL_ATTR(diff_hlf);
Bram Moolenaard710e0d2015-06-10 12:16:47 +02004178# ifdef FEAT_SYN_HL
Bram Moolenaare0f14822014-08-06 13:20:56 +02004179 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
4180 char_attr = hl_combine_attr(char_attr,
Bram Moolenaar8820b482017-03-16 17:23:31 +01004181 HL_ATTR(HLF_CUL));
Bram Moolenaard710e0d2015-06-10 12:16:47 +02004182# endif
Bram Moolenaare0f14822014-08-06 13:20:56 +02004183 }
Bram Moolenaard710e0d2015-06-10 12:16:47 +02004184# endif
Bram Moolenaarb8b57462014-07-03 22:54:08 +02004185 p_extra = NULL;
Bram Moolenaar597a4222014-06-25 14:39:50 +02004186 c_extra = ' ';
4187 n_extra = get_breakindent_win(wp,
4188 ml_get_buf(wp->w_buffer, lnum, FALSE));
4189 /* Correct end of highlighted area for 'breakindent',
4190 * required when 'linebreak' is also set. */
4191 if (tocol == vcol)
4192 tocol += n_extra;
4193 }
4194 }
4195#endif
4196
Bram Moolenaar071d4272004-06-13 20:20:40 +00004197#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
4198 if (draw_state == WL_SBR - 1 && n_extra == 0)
4199 {
4200 draw_state = WL_SBR;
4201# ifdef FEAT_DIFF
4202 if (filler_todo > 0)
4203 {
4204 /* Draw "deleted" diff line(s). */
4205 if (char2cells(fill_diff) > 1)
Bram Moolenaar83a52172019-01-16 22:41:54 +01004206 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004207 c_extra = '-';
Bram Moolenaar83a52172019-01-16 22:41:54 +01004208 c_final = NUL;
4209 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004210 else
Bram Moolenaar83a52172019-01-16 22:41:54 +01004211 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004212 c_extra = fill_diff;
Bram Moolenaar83a52172019-01-16 22:41:54 +01004213 c_final = NUL;
4214 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004215# ifdef FEAT_RIGHTLEFT
4216 if (wp->w_p_rl)
4217 n_extra = col + 1;
4218 else
4219# endif
Bram Moolenaar02631462017-09-22 15:20:32 +02004220 n_extra = wp->w_width - col;
Bram Moolenaar8820b482017-03-16 17:23:31 +01004221 char_attr = HL_ATTR(HLF_DED);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004222 }
4223# endif
4224# ifdef FEAT_LINEBREAK
4225 if (*p_sbr != NUL && need_showbreak)
4226 {
4227 /* Draw 'showbreak' at the start of each broken line. */
4228 p_extra = p_sbr;
4229 c_extra = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01004230 c_final = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004231 n_extra = (int)STRLEN(p_sbr);
Bram Moolenaar8820b482017-03-16 17:23:31 +01004232 char_attr = HL_ATTR(HLF_AT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004233 need_showbreak = FALSE;
Bram Moolenaard574ea22015-01-14 19:35:14 +01004234 vcol_sbr = vcol + MB_CHARLEN(p_sbr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004235 /* Correct end of highlighted area for 'showbreak',
4236 * required when 'linebreak' is also set. */
4237 if (tocol == vcol)
4238 tocol += n_extra;
Bram Moolenaar5a4d51e2013-06-30 17:24:16 +02004239#ifdef FEAT_SYN_HL
4240 /* combine 'showbreak' with 'cursorline' */
Bram Moolenaarbd65c462013-07-01 20:18:33 +02004241 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
Bram Moolenaare0f14822014-08-06 13:20:56 +02004242 char_attr = hl_combine_attr(char_attr,
Bram Moolenaar8820b482017-03-16 17:23:31 +01004243 HL_ATTR(HLF_CUL));
Bram Moolenaar5a4d51e2013-06-30 17:24:16 +02004244#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004245 }
4246# endif
4247 }
4248#endif
4249
4250 if (draw_state == WL_LINE - 1 && n_extra == 0)
4251 {
4252 draw_state = WL_LINE;
4253 if (saved_n_extra)
4254 {
4255 /* Continue item from end of wrapped line. */
4256 n_extra = saved_n_extra;
4257 c_extra = saved_c_extra;
Bram Moolenaar83a52172019-01-16 22:41:54 +01004258 c_final = saved_c_final;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004259 p_extra = saved_p_extra;
4260 char_attr = saved_char_attr;
4261 }
4262 else
Bram Moolenaar4d784b22019-05-25 19:51:39 +02004263 char_attr = win_attr;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004264 }
4265 }
4266
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02004267 // When still displaying '$' of change command, stop at cursor.
4268 // When only displaying the (relative) line number and that's done,
4269 // stop here.
4270 if ((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar910f66f2006-04-05 20:41:53 +00004271 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol
Bram Moolenaar071d4272004-06-13 20:20:40 +00004272#ifdef FEAT_DIFF
4273 && filler_todo <= 0
4274#endif
4275 )
Bram Moolenaarbd9a53c2018-09-12 23:15:48 +02004276 || (number_only && draw_state > WL_NR))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004277 {
Bram Moolenaar02631462017-09-22 15:20:32 +02004278 screen_line(screen_row, wp->w_wincol, col, -(int)wp->w_width,
Bram Moolenaar4d784b22019-05-25 19:51:39 +02004279 screen_line_flags);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00004280 /* Pretend we have finished updating the window. Except when
4281 * 'cursorcolumn' is set. */
4282#ifdef FEAT_SYN_HL
4283 if (wp->w_p_cuc)
4284 row = wp->w_cline_row + wp->w_cline_height;
4285 else
4286#endif
4287 row = wp->w_height;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004288 break;
4289 }
4290
Bram Moolenaar637532b2019-01-03 21:44:40 +01004291 if (draw_state == WL_LINE && (area_highlighting
4292#ifdef FEAT_SPELL
4293 || has_spell
4294#endif
4295 ))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004296 {
4297 /* handle Visual or match highlighting in this line */
4298 if (vcol == fromcol
Bram Moolenaar071d4272004-06-13 20:20:40 +00004299 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0
4300 && (*mb_ptr2cells)(ptr) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004301 || ((int)vcol_prev == fromcol_prev
Bram Moolenaarfa363cd2009-02-21 20:23:59 +00004302 && vcol_prev < vcol /* not at margin */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004303 && vcol < tocol))
Bram Moolenaar4d784b22019-05-25 19:51:39 +02004304 area_attr = vi_attr; /* start highlighting */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004305 else if (area_attr != 0
4306 && (vcol == tocol
4307 || (noinvcur && (colnr_T)vcol == wp->w_virtcol)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004308 area_attr = 0; /* stop highlighting */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004309
4310#ifdef FEAT_SEARCH_EXTRA
4311 if (!n_extra)
4312 {
4313 /*
4314 * Check for start/end of search pattern match.
4315 * After end, check for start/end of next match.
4316 * When another match, have to check for start again.
4317 * Watch out for matching an empty string!
Bram Moolenaar6ee10162007-07-26 20:58:42 +00004318 * Do this for 'search_hl' and the match list (ordered by
4319 * priority).
Bram Moolenaar071d4272004-06-13 20:20:40 +00004320 */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004321 v = (long)(ptr - line);
Bram Moolenaar6ee10162007-07-26 20:58:42 +00004322 cur = wp->w_match_head;
4323 shl_flag = FALSE;
4324 while (cur != NULL || shl_flag == FALSE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004325 {
Bram Moolenaar6ee10162007-07-26 20:58:42 +00004326 if (shl_flag == FALSE
4327 && ((cur != NULL
4328 && cur->priority > SEARCH_HL_PRIORITY)
4329 || cur == NULL))
4330 {
4331 shl = &search_hl;
4332 shl_flag = TRUE;
4333 }
4334 else
4335 shl = &cur->hl;
Bram Moolenaarb3414592014-06-17 17:48:32 +02004336 if (cur != NULL)
4337 cur->pos.cur = 0;
4338 pos_inprogress = TRUE;
4339 while (shl->rm.regprog != NULL
4340 || (cur != NULL && pos_inprogress))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004341 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004342 if (shl->startcol != MAXCOL
4343 && v >= (long)shl->startcol
4344 && v < (long)shl->endcol)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004345 {
Bram Moolenaaraff5c3a2014-12-13 03:36:39 +01004346 int tmp_col = v + MB_PTR2LEN(ptr);
4347
4348 if (shl->endcol < tmp_col)
4349 shl->endcol = tmp_col;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004350 shl->attr_cur = shl->attr;
Bram Moolenaar6561d522015-07-21 15:48:27 +02004351#ifdef FEAT_CONCEAL
Bram Moolenaarab62c192019-03-30 16:39:05 +01004352 // Match with the "Conceal" group results in hiding
4353 // the match.
4354 if (cur != NULL
4355 && shl != &search_hl
4356 && syn_name2id((char_u *)"Conceal")
4357 == cur->hlg_id)
Bram Moolenaar6561d522015-07-21 15:48:27 +02004358 {
Bram Moolenaar4d585022016-04-14 19:50:22 +02004359 has_match_conc =
4360 v == (long)shl->startcol ? 2 : 1;
Bram Moolenaar6561d522015-07-21 15:48:27 +02004361 match_conc = cur->conceal_char;
4362 }
4363 else
Bram Moolenaar4d585022016-04-14 19:50:22 +02004364 has_match_conc = match_conc = 0;
Bram Moolenaar6561d522015-07-21 15:48:27 +02004365#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004366 }
Bram Moolenaaraff5c3a2014-12-13 03:36:39 +01004367 else if (v == (long)shl->endcol)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004368 {
4369 shl->attr_cur = 0;
Bram Moolenaare17bdff2016-08-27 18:34:29 +02004370 next_search_hl(wp, shl, lnum, (colnr_T)v,
4371 shl == &search_hl ? NULL : cur);
Bram Moolenaarb3414592014-06-17 17:48:32 +02004372 pos_inprogress = cur == NULL || cur->pos.cur == 0
Bram Moolenaar6561d522015-07-21 15:48:27 +02004373 ? FALSE : TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004374
4375 /* Need to get the line again, a multi-line regexp
4376 * may have made it invalid. */
4377 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
4378 ptr = line + v;
4379
4380 if (shl->lnum == lnum)
4381 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004382 shl->startcol = shl->rm.startpos[0].col;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004383 if (shl->rm.endpos[0].lnum == 0)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004384 shl->endcol = shl->rm.endpos[0].col;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004385 else
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004386 shl->endcol = MAXCOL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004387
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004388 if (shl->startcol == shl->endcol)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004389 {
4390 /* highlight empty match, try again after
4391 * it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004392 if (has_mbyte)
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004393 shl->endcol += (*mb_ptr2len)(line
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004394 + shl->endcol);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004395 else
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004396 ++shl->endcol;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004397 }
4398
4399 /* Loop to check if the match starts at the
4400 * current position */
4401 continue;
4402 }
4403 }
4404 break;
4405 }
Bram Moolenaar6ee10162007-07-26 20:58:42 +00004406 if (shl != &search_hl && cur != NULL)
4407 cur = cur->next;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004408 }
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00004409
Bram Moolenaar6ee10162007-07-26 20:58:42 +00004410 /* Use attributes from match with highest priority among
4411 * 'search_hl' and the match list. */
4412 search_attr = search_hl.attr_cur;
4413 cur = wp->w_match_head;
4414 shl_flag = FALSE;
4415 while (cur != NULL || shl_flag == FALSE)
4416 {
4417 if (shl_flag == FALSE
4418 && ((cur != NULL
4419 && cur->priority > SEARCH_HL_PRIORITY)
4420 || cur == NULL))
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00004421 {
Bram Moolenaar6ee10162007-07-26 20:58:42 +00004422 shl = &search_hl;
4423 shl_flag = TRUE;
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00004424 }
Bram Moolenaar6ee10162007-07-26 20:58:42 +00004425 else
4426 shl = &cur->hl;
4427 if (shl->attr_cur != 0)
4428 search_attr = shl->attr_cur;
4429 if (shl != &search_hl && cur != NULL)
4430 cur = cur->next;
4431 }
Bram Moolenaar0aa398f2017-09-30 21:23:55 +02004432 /* Only highlight one character after the last column. */
Bram Moolenaar5ece3e32017-10-01 14:35:02 +02004433 if (*ptr == NUL && (did_line_attr >= 1
4434 || (wp->w_p_list && lcs_eol_one == -1)))
Bram Moolenaar0aa398f2017-09-30 21:23:55 +02004435 search_attr = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004436 }
4437#endif
4438
Bram Moolenaar071d4272004-06-13 20:20:40 +00004439#ifdef FEAT_DIFF
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00004440 if (diff_hlf != (hlf_T)0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004441 {
Bram Moolenaar4b80a512007-06-19 15:44:58 +00004442 if (diff_hlf == HLF_CHD && ptr - line >= change_start
4443 && n_extra == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004444 diff_hlf = HLF_TXD; /* changed text */
Bram Moolenaar4b80a512007-06-19 15:44:58 +00004445 if (diff_hlf == HLF_TXD && ptr - line > change_end
4446 && n_extra == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004447 diff_hlf = HLF_CHD; /* changed line */
Bram Moolenaar8820b482017-03-16 17:23:31 +01004448 line_attr = HL_ATTR(diff_hlf);
Bram Moolenaare0f14822014-08-06 13:20:56 +02004449 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
Bram Moolenaar8820b482017-03-16 17:23:31 +01004450 line_attr = hl_combine_attr(line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar071d4272004-06-13 20:20:40 +00004451 }
4452#endif
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00004453
Bram Moolenaar48f88ac2018-12-26 00:25:20 +01004454#ifdef FEAT_TEXT_PROP
4455 if (text_props != NULL)
4456 {
4457 int pi;
Bram Moolenaar5e53ac02019-01-01 20:31:31 +01004458 int bcol = (int)(ptr - line);
Bram Moolenaar48f88ac2018-12-26 00:25:20 +01004459
4460 // Check if any active property ends.
4461 for (pi = 0; pi < text_props_active; ++pi)
4462 {
4463 int tpi = text_prop_idxs[pi];
4464
Bram Moolenaar5e53ac02019-01-01 20:31:31 +01004465 if (bcol >= text_props[tpi].tp_col - 1
Bram Moolenaar48f88ac2018-12-26 00:25:20 +01004466 + text_props[tpi].tp_len)
4467 {
4468 if (pi + 1 < text_props_active)
4469 mch_memmove(text_prop_idxs + pi,
4470 text_prop_idxs + pi + 1,
4471 sizeof(int)
4472 * (text_props_active - (pi + 1)));
4473 --text_props_active;
4474 --pi;
4475 }
4476 }
4477
4478 // Add any text property that starts in this column.
4479 while (text_prop_next < text_prop_count
Bram Moolenaar5e53ac02019-01-01 20:31:31 +01004480 && bcol >= text_props[text_prop_next].tp_col - 1)
Bram Moolenaar48f88ac2018-12-26 00:25:20 +01004481 text_prop_idxs[text_props_active++] = text_prop_next++;
4482
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01004483 text_prop_attr = 0;
Bram Moolenaarde24a872019-05-05 15:48:00 +02004484 text_prop_combine = FALSE;
Bram Moolenaar48f88ac2018-12-26 00:25:20 +01004485 if (text_props_active > 0)
4486 {
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01004487 // Sort the properties on priority and/or starting last.
4488 // Then combine the attributes, highest priority last.
4489 current_text_props = text_props;
4490 current_buf = wp->w_buffer;
4491 qsort((void *)text_prop_idxs, (size_t)text_props_active,
4492 sizeof(int), text_prop_compare);
Bram Moolenaar48f88ac2018-12-26 00:25:20 +01004493
Bram Moolenaar48f88ac2018-12-26 00:25:20 +01004494 for (pi = 0; pi < text_props_active; ++pi)
4495 {
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01004496 int tpi = text_prop_idxs[pi];
Bram Moolenaarde24a872019-05-05 15:48:00 +02004497 proptype_T *pt = text_prop_type_by_id(
4498 wp->w_buffer, text_props[tpi].tp_type);
Bram Moolenaar48f88ac2018-12-26 00:25:20 +01004499
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01004500 if (pt != NULL)
Bram Moolenaar48f88ac2018-12-26 00:25:20 +01004501 {
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01004502 int pt_attr = syn_id2attr(pt->pt_hl_id);
4503
Bram Moolenaar48f88ac2018-12-26 00:25:20 +01004504 text_prop_type = pt;
Bram Moolenaarde24a872019-05-05 15:48:00 +02004505 text_prop_attr =
4506 hl_combine_attr(text_prop_attr, pt_attr);
4507 text_prop_combine = pt->pt_flags & PT_FLAG_COMBINE;
Bram Moolenaar48f88ac2018-12-26 00:25:20 +01004508 }
4509 }
Bram Moolenaar48f88ac2018-12-26 00:25:20 +01004510 }
4511 }
4512#endif
4513
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00004514 /* Decide which of the highlight attributes to use. */
4515 attr_pri = TRUE;
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00004516#ifdef LINE_ATTR
Bram Moolenaar09deeb72015-03-24 18:22:41 +01004517 if (area_attr != 0)
4518 char_attr = hl_combine_attr(line_attr, area_attr);
4519 else if (search_attr != 0)
4520 char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaarbfd45122019-05-17 13:05:07 +02004521# ifdef FEAT_TEXT_PROP
4522 else if (text_prop_type != NULL)
Bram Moolenaar7a8d0272019-05-26 23:32:06 +02004523 {
4524 char_attr = hl_combine_attr(
4525 line_attr != 0 ? line_attr : win_attr, text_prop_attr);
4526 }
Bram Moolenaarbfd45122019-05-17 13:05:07 +02004527# endif
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00004528 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
Bram Moolenaarf837ef92009-03-11 16:47:21 +00004529 || vcol < fromcol || vcol_prev < fromcol_prev
4530 || vcol >= tocol))
Bram Moolenaarbfd45122019-05-17 13:05:07 +02004531 // Use line_attr when not in the Visual or 'incsearch' area
4532 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00004533 char_attr = line_attr;
Bram Moolenaar09deeb72015-03-24 18:22:41 +01004534#else
4535 if (area_attr != 0)
4536 char_attr = area_attr;
4537 else if (search_attr != 0)
4538 char_attr = search_attr;
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00004539#endif
4540 else
4541 {
4542 attr_pri = FALSE;
Bram Moolenaar98aefe72018-12-13 22:20:09 +01004543#ifdef FEAT_TEXT_PROP
4544 if (text_prop_type != NULL)
Bram Moolenaarde24a872019-05-05 15:48:00 +02004545 {
4546 if (text_prop_combine)
4547 char_attr = hl_combine_attr(
4548 syntax_attr, text_prop_attr);
4549 else
Bram Moolenaar7a8d0272019-05-26 23:32:06 +02004550 char_attr = hl_combine_attr(
4551 win_attr, text_prop_attr);
Bram Moolenaarde24a872019-05-05 15:48:00 +02004552 }
Bram Moolenaar98aefe72018-12-13 22:20:09 +01004553 else
4554#endif
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00004555#ifdef FEAT_SYN_HL
4556 if (has_syntax)
4557 char_attr = syntax_attr;
4558 else
4559#endif
4560 char_attr = 0;
4561 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004562 }
Bram Moolenaar4d784b22019-05-25 19:51:39 +02004563 if (char_attr == 0)
4564 char_attr = win_attr;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004565
4566 /*
4567 * Get the next character to put on the screen.
4568 */
4569 /*
Bram Moolenaara064ac82007-08-05 18:10:54 +00004570 * The "p_extra" points to the extra stuff that is inserted to
4571 * represent special characters (non-printable stuff) and other
4572 * things. When all characters are the same, c_extra is used.
Bram Moolenaar83a52172019-01-16 22:41:54 +01004573 * If c_final is set, it will compulsorily be used at the end.
Bram Moolenaara064ac82007-08-05 18:10:54 +00004574 * "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
4575 * "p_extra[n_extra]".
Bram Moolenaar071d4272004-06-13 20:20:40 +00004576 * For the '$' of the 'list' option, n_extra == 1, p_extra == "".
4577 */
4578 if (n_extra > 0)
4579 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01004580 if (c_extra != NUL || (n_extra == 1 && c_final != NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004581 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01004582 c = (n_extra == 1 && c_final != NUL) ? c_final : c_extra;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004583 mb_c = c; /* doesn't handle non-utf-8 multi-byte! */
Bram Moolenaarace95982017-03-29 17:30:27 +02004584 if (enc_utf8 && utf_char2len(c) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004585 {
4586 mb_utf8 = TRUE;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00004587 u8cc[0] = 0;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00004588 c = 0xc0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004589 }
4590 else
4591 mb_utf8 = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004592 }
4593 else
4594 {
4595 c = *p_extra;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004596 if (has_mbyte)
4597 {
4598 mb_c = c;
4599 if (enc_utf8)
4600 {
4601 /* If the UTF-8 character is more than one byte:
4602 * Decode it into "mb_c". */
Bram Moolenaarace95982017-03-29 17:30:27 +02004603 mb_l = utfc_ptr2len(p_extra);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004604 mb_utf8 = FALSE;
4605 if (mb_l > n_extra)
4606 mb_l = 1;
4607 else if (mb_l > 1)
4608 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00004609 mb_c = utfc_ptr2char(p_extra, u8cc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004610 mb_utf8 = TRUE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00004611 c = 0xc0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004612 }
4613 }
4614 else
4615 {
4616 /* if this is a DBCS character, put it in "mb_c" */
4617 mb_l = MB_BYTE2LEN(c);
4618 if (mb_l >= n_extra)
4619 mb_l = 1;
4620 else if (mb_l > 1)
4621 mb_c = (c << 8) + p_extra[1];
4622 }
Bram Moolenaar92d640f2005-09-05 22:11:52 +00004623 if (mb_l == 0) /* at the NUL at end-of-line */
4624 mb_l = 1;
4625
Bram Moolenaar071d4272004-06-13 20:20:40 +00004626 /* If a double-width char doesn't fit display a '>' in the
4627 * last column. */
Bram Moolenaar92d640f2005-09-05 22:11:52 +00004628 if ((
Bram Moolenaar071d4272004-06-13 20:20:40 +00004629# ifdef FEAT_RIGHTLEFT
4630 wp->w_p_rl ? (col <= 0) :
4631# endif
Bram Moolenaar02631462017-09-22 15:20:32 +02004632 (col >= wp->w_width - 1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004633 && (*mb_char2cells)(mb_c) == 2)
4634 {
4635 c = '>';
4636 mb_c = c;
4637 mb_l = 1;
4638 mb_utf8 = FALSE;
Bram Moolenaar8820b482017-03-16 17:23:31 +01004639 multi_attr = HL_ATTR(HLF_AT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004640 /* put the pointer back to output the double-width
4641 * character at the start of the next line. */
4642 ++n_extra;
4643 --p_extra;
4644 }
4645 else
4646 {
4647 n_extra -= mb_l - 1;
4648 p_extra += mb_l - 1;
4649 }
4650 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004651 ++p_extra;
4652 }
4653 --n_extra;
4654 }
4655 else
4656 {
Bram Moolenaar88e76882017-02-27 20:33:46 +01004657#ifdef FEAT_LINEBREAK
Bram Moolenaar38632fa2017-02-26 19:40:59 +01004658 int c0;
Bram Moolenaar88e76882017-02-27 20:33:46 +01004659#endif
Bram Moolenaar38632fa2017-02-26 19:40:59 +01004660
Bram Moolenaar86b17e92014-07-02 20:00:47 +02004661 if (p_extra_free != NULL)
Bram Moolenaard23a8232018-02-10 18:45:26 +01004662 VIM_CLEAR(p_extra_free);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004663 /*
4664 * Get a character from the line itself.
4665 */
Bram Moolenaar10a8da02017-02-27 21:11:35 +01004666 c = *ptr;
Bram Moolenaar88e76882017-02-27 20:33:46 +01004667#ifdef FEAT_LINEBREAK
Bram Moolenaar10a8da02017-02-27 21:11:35 +01004668 c0 = *ptr;
Bram Moolenaar88e76882017-02-27 20:33:46 +01004669#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004670 if (has_mbyte)
4671 {
4672 mb_c = c;
4673 if (enc_utf8)
4674 {
4675 /* If the UTF-8 character is more than one byte: Decode it
4676 * into "mb_c". */
Bram Moolenaarace95982017-03-29 17:30:27 +02004677 mb_l = utfc_ptr2len(ptr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004678 mb_utf8 = FALSE;
4679 if (mb_l > 1)
4680 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00004681 mb_c = utfc_ptr2char(ptr, u8cc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004682 /* Overlong encoded ASCII or ASCII with composing char
4683 * is displayed normally, except a NUL. */
4684 if (mb_c < 0x80)
Bram Moolenaar88e76882017-02-27 20:33:46 +01004685 {
4686 c = mb_c;
Bram Moolenaara12a1612019-01-24 16:39:02 +01004687#ifdef FEAT_LINEBREAK
Bram Moolenaar88e76882017-02-27 20:33:46 +01004688 c0 = mb_c;
Bram Moolenaara12a1612019-01-24 16:39:02 +01004689#endif
Bram Moolenaar88e76882017-02-27 20:33:46 +01004690 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004691 mb_utf8 = TRUE;
Bram Moolenaarcafda4f2005-09-06 19:25:11 +00004692
4693 /* At start of the line we can have a composing char.
4694 * Draw it as a space with a composing char. */
4695 if (utf_iscomposing(mb_c))
4696 {
Bram Moolenaar6ee10162007-07-26 20:58:42 +00004697 int i;
4698
Bram Moolenaar362e1a32006-03-06 23:29:24 +00004699 for (i = Screen_mco - 1; i > 0; --i)
4700 u8cc[i] = u8cc[i - 1];
4701 u8cc[0] = mb_c;
Bram Moolenaarcafda4f2005-09-06 19:25:11 +00004702 mb_c = ' ';
4703 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004704 }
4705
4706 if ((mb_l == 1 && c >= 0x80)
4707 || (mb_l >= 1 && mb_c == 0)
Bram Moolenaar9ba61172019-01-24 18:20:17 +01004708 || (mb_l > 1 && (!vim_isprintc(mb_c))))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004709 {
4710 /*
4711 * Illegal UTF-8 byte: display as <xx>.
4712 * Non-BMP character : display as ? or fullwidth ?.
4713 */
Bram Moolenaar9ba61172019-01-24 18:20:17 +01004714 transchar_hex(extra, mb_c);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00004715# ifdef FEAT_RIGHTLEFT
Bram Moolenaar9ba61172019-01-24 18:20:17 +01004716 if (wp->w_p_rl) /* reverse */
4717 rl_mirror(extra);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00004718# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004719 p_extra = extra;
4720 c = *p_extra;
4721 mb_c = mb_ptr2char_adv(&p_extra);
4722 mb_utf8 = (c >= 0x80);
4723 n_extra = (int)STRLEN(p_extra);
4724 c_extra = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01004725 c_final = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004726 if (area_attr == 0 && search_attr == 0)
4727 {
4728 n_attr = n_extra + 1;
Bram Moolenaar8820b482017-03-16 17:23:31 +01004729 extra_attr = HL_ATTR(HLF_8);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004730 saved_attr2 = char_attr; /* save current attr */
4731 }
4732 }
4733 else if (mb_l == 0) /* at the NUL at end-of-line */
4734 mb_l = 1;
4735#ifdef FEAT_ARABIC
4736 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
4737 {
4738 /* Do Arabic shaping. */
Bram Moolenaar362e1a32006-03-06 23:29:24 +00004739 int pc, pc1, nc;
4740 int pcc[MAX_MCO];
Bram Moolenaar071d4272004-06-13 20:20:40 +00004741
4742 /* The idea of what is the previous and next
4743 * character depends on 'rightleft'. */
4744 if (wp->w_p_rl)
4745 {
4746 pc = prev_c;
4747 pc1 = prev_c1;
4748 nc = utf_ptr2char(ptr + mb_l);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00004749 prev_c1 = u8cc[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +00004750 }
4751 else
4752 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00004753 pc = utfc_ptr2char(ptr + mb_l, pcc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004754 nc = prev_c;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00004755 pc1 = pcc[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +00004756 }
4757 prev_c = mb_c;
4758
Bram Moolenaar362e1a32006-03-06 23:29:24 +00004759 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004760 }
4761 else
4762 prev_c = mb_c;
4763#endif
4764 }
4765 else /* enc_dbcs */
4766 {
4767 mb_l = MB_BYTE2LEN(c);
4768 if (mb_l == 0) /* at the NUL at end-of-line */
4769 mb_l = 1;
4770 else if (mb_l > 1)
4771 {
4772 /* We assume a second byte below 32 is illegal.
4773 * Hopefully this is OK for all double-byte encodings!
4774 */
4775 if (ptr[1] >= 32)
4776 mb_c = (c << 8) + ptr[1];
4777 else
4778 {
4779 if (ptr[1] == NUL)
4780 {
4781 /* head byte at end of line */
4782 mb_l = 1;
4783 transchar_nonprint(extra, c);
4784 }
4785 else
4786 {
4787 /* illegal tail byte */
4788 mb_l = 2;
4789 STRCPY(extra, "XX");
4790 }
4791 p_extra = extra;
4792 n_extra = (int)STRLEN(extra) - 1;
4793 c_extra = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01004794 c_final = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004795 c = *p_extra++;
4796 if (area_attr == 0 && search_attr == 0)
4797 {
4798 n_attr = n_extra + 1;
Bram Moolenaar8820b482017-03-16 17:23:31 +01004799 extra_attr = HL_ATTR(HLF_8);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004800 saved_attr2 = char_attr; /* save current attr */
4801 }
4802 mb_c = c;
4803 }
4804 }
4805 }
4806 /* If a double-width char doesn't fit display a '>' in the
4807 * last column; the character is displayed at the start of the
4808 * next line. */
4809 if ((
4810# ifdef FEAT_RIGHTLEFT
4811 wp->w_p_rl ? (col <= 0) :
4812# endif
Bram Moolenaar02631462017-09-22 15:20:32 +02004813 (col >= wp->w_width - 1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004814 && (*mb_char2cells)(mb_c) == 2)
4815 {
4816 c = '>';
4817 mb_c = c;
4818 mb_utf8 = FALSE;
4819 mb_l = 1;
Bram Moolenaar8820b482017-03-16 17:23:31 +01004820 multi_attr = HL_ATTR(HLF_AT);
Bram Moolenaar0ebe12b2019-05-17 12:31:44 +02004821 // Put pointer back so that the character will be
4822 // displayed at the start of the next line.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004823 --ptr;
Bram Moolenaar0ebe12b2019-05-17 12:31:44 +02004824#ifdef FEAT_CONCEAL
4825 did_decrement_ptr = TRUE;
4826#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004827 }
4828 else if (*ptr != NUL)
4829 ptr += mb_l - 1;
4830
4831 /* If a double-width char doesn't fit at the left side display
Bram Moolenaar7ba6ed32010-08-07 16:38:13 +02004832 * a '<' in the first column. Don't do this for unprintable
Bram Moolenaar84a05ac2013-05-06 04:24:17 +02004833 * characters. */
Bram Moolenaar7ba6ed32010-08-07 16:38:13 +02004834 if (n_skip > 0 && mb_l > 1 && n_extra == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004835 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004836 n_extra = 1;
Bram Moolenaar5641f382012-06-13 18:06:36 +02004837 c_extra = MB_FILLER_CHAR;
Bram Moolenaar83a52172019-01-16 22:41:54 +01004838 c_final = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004839 c = ' ';
4840 if (area_attr == 0 && search_attr == 0)
4841 {
4842 n_attr = n_extra + 1;
Bram Moolenaar8820b482017-03-16 17:23:31 +01004843 extra_attr = HL_ATTR(HLF_AT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004844 saved_attr2 = char_attr; /* save current attr */
4845 }
4846 mb_c = c;
4847 mb_utf8 = FALSE;
4848 mb_l = 1;
4849 }
4850
4851 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004852 ++ptr;
4853
4854 if (extra_check)
4855 {
Bram Moolenaar600dddc2006-03-12 22:05:10 +00004856#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00004857 int can_spell = TRUE;
Bram Moolenaar600dddc2006-03-12 22:05:10 +00004858#endif
Bram Moolenaar217ad922005-03-20 22:37:15 +00004859
Bram Moolenaar63ecdda2017-07-28 22:29:35 +02004860#ifdef FEAT_TERMINAL
4861 if (get_term_attr)
4862 {
Bram Moolenaar68c4bdd2017-07-30 13:57:41 +02004863 syntax_attr = term_get_attr(wp->w_buffer, lnum, vcol);
Bram Moolenaar63ecdda2017-07-28 22:29:35 +02004864
4865 if (!attr_pri)
4866 char_attr = syntax_attr;
4867 else
4868 char_attr = hl_combine_attr(syntax_attr, char_attr);
4869 }
4870#endif
4871
Bram Moolenaar600dddc2006-03-12 22:05:10 +00004872#ifdef FEAT_SYN_HL
Bram Moolenaar48f88ac2018-12-26 00:25:20 +01004873 // Get syntax attribute, unless still at the start of the line
4874 // (double-wide char that doesn't fit).
Bram Moolenaar217ad922005-03-20 22:37:15 +00004875 v = (long)(ptr - line);
4876 if (has_syntax && v > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004877 {
4878 /* Get the syntax attribute for the character. If there
4879 * is an error, disable syntax highlighting. */
4880 save_did_emsg = did_emsg;
4881 did_emsg = FALSE;
4882
Bram Moolenaar217ad922005-03-20 22:37:15 +00004883 syntax_attr = get_syntax_attr((colnr_T)v - 1,
Bram Moolenaar860cae12010-06-05 23:22:07 +02004884# ifdef FEAT_SPELL
4885 has_spell ? &can_spell :
4886# endif
4887 NULL, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004888
4889 if (did_emsg)
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00004890 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02004891 wp->w_s->b_syn_error = TRUE;
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00004892 has_syntax = FALSE;
Bram Moolenaar4d784b22019-05-25 19:51:39 +02004893 syntax_attr = 0;
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00004894 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004895 else
4896 did_emsg = save_did_emsg;
Bram Moolenaar4d784b22019-05-25 19:51:39 +02004897
4898 // combine syntax attribute with 'wincolor'
4899 if (win_attr != 0)
4900 syntax_attr = hl_combine_attr(win_attr, syntax_attr);
4901
Bram Moolenaar06f1ed22017-06-18 22:41:03 +02004902#ifdef SYN_TIME_LIMIT
4903 if (wp->w_s->b_syn_slow)
4904 has_syntax = FALSE;
4905#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004906
4907 /* Need to get the line again, a multi-line regexp may
4908 * have made it invalid. */
4909 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
4910 ptr = line + v;
4911
Bram Moolenaar48f88ac2018-12-26 00:25:20 +01004912# ifdef FEAT_TEXT_PROP
Bram Moolenaarde24a872019-05-05 15:48:00 +02004913 // Text properties overrule syntax highlighting or combine.
4914 if (text_prop_attr == 0 || text_prop_combine)
4915# endif
Bram Moolenaar48f88ac2018-12-26 00:25:20 +01004916 {
Bram Moolenaarde24a872019-05-05 15:48:00 +02004917 int comb_attr = syntax_attr;
4918# ifdef FEAT_TEXT_PROP
4919 comb_attr = hl_combine_attr(text_prop_attr, comb_attr);
4920# endif
Bram Moolenaar48f88ac2018-12-26 00:25:20 +01004921 if (!attr_pri)
Bram Moolenaarde24a872019-05-05 15:48:00 +02004922 char_attr = comb_attr;
Bram Moolenaar48f88ac2018-12-26 00:25:20 +01004923 else
Bram Moolenaarde24a872019-05-05 15:48:00 +02004924 char_attr = hl_combine_attr(comb_attr, char_attr);
Bram Moolenaar48f88ac2018-12-26 00:25:20 +01004925 }
Bram Moolenaarc095b282010-07-20 22:33:34 +02004926# ifdef FEAT_CONCEAL
4927 /* no concealing past the end of the line, it interferes
4928 * with line highlighting */
4929 if (c == NUL)
4930 syntax_flags = 0;
Bram Moolenaar27c735b2010-07-22 22:16:29 +02004931 else
Bram Moolenaarffbbcb52010-07-24 17:29:03 +02004932 syntax_flags = get_syntax_info(&syntax_seqnr);
Bram Moolenaarc095b282010-07-20 22:33:34 +02004933# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004934 }
Bram Moolenaar600dddc2006-03-12 22:05:10 +00004935#endif
Bram Moolenaar217ad922005-03-20 22:37:15 +00004936
Bram Moolenaar600dddc2006-03-12 22:05:10 +00004937#ifdef FEAT_SPELL
Bram Moolenaar75c50c42005-06-04 22:06:24 +00004938 /* Check spelling (unless at the end of the line).
Bram Moolenaarf3681cc2005-06-08 22:03:13 +00004939 * Only do this when there is no syntax highlighting, the
4940 * @Spell cluster is not used or the current syntax item
4941 * contains the @Spell cluster. */
Bram Moolenaar30abd282005-06-22 22:35:10 +00004942 if (has_spell && v >= word_end && v > cur_checked_col)
Bram Moolenaar217ad922005-03-20 22:37:15 +00004943 {
Bram Moolenaar68b76a62005-03-25 21:53:48 +00004944 spell_attr = 0;
Bram Moolenaar600dddc2006-03-12 22:05:10 +00004945 if (c != 0 && (
4946# ifdef FEAT_SYN_HL
4947 !has_syntax ||
4948# endif
4949 can_spell))
Bram Moolenaar217ad922005-03-20 22:37:15 +00004950 {
Bram Moolenaar30abd282005-06-22 22:35:10 +00004951 char_u *prev_ptr, *p;
4952 int len;
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00004953 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaare7566042005-06-17 22:00:15 +00004954 if (has_mbyte)
4955 {
4956 prev_ptr = ptr - mb_l;
4957 v -= mb_l - 1;
4958 }
4959 else
Bram Moolenaare7566042005-06-17 22:00:15 +00004960 prev_ptr = ptr - 1;
Bram Moolenaar30abd282005-06-22 22:35:10 +00004961
4962 /* Use nextline[] if possible, it has the start of the
4963 * next line concatenated. */
4964 if ((prev_ptr - line) - nextlinecol >= 0)
4965 p = nextline + (prev_ptr - line) - nextlinecol;
4966 else
4967 p = prev_ptr;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004968 cap_col -= (int)(prev_ptr - line);
Bram Moolenaar4770d092006-01-12 23:22:24 +00004969 len = spell_check(wp, p, &spell_hlf, &cap_col,
4970 nochange);
Bram Moolenaar30abd282005-06-22 22:35:10 +00004971 word_end = v + len;
Bram Moolenaar217ad922005-03-20 22:37:15 +00004972
Bram Moolenaar75c50c42005-06-04 22:06:24 +00004973 /* In Insert mode only highlight a word that
4974 * doesn't touch the cursor. */
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00004975 if (spell_hlf != HLF_COUNT
Bram Moolenaar75c50c42005-06-04 22:06:24 +00004976 && (State & INSERT) != 0
4977 && wp->w_cursor.lnum == lnum
4978 && wp->w_cursor.col >=
Bram Moolenaar217ad922005-03-20 22:37:15 +00004979 (colnr_T)(prev_ptr - line)
Bram Moolenaar75c50c42005-06-04 22:06:24 +00004980 && wp->w_cursor.col < (colnr_T)word_end)
4981 {
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00004982 spell_hlf = HLF_COUNT;
Bram Moolenaar75c50c42005-06-04 22:06:24 +00004983 spell_redraw_lnum = lnum;
Bram Moolenaar217ad922005-03-20 22:37:15 +00004984 }
Bram Moolenaar30abd282005-06-22 22:35:10 +00004985
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00004986 if (spell_hlf == HLF_COUNT && p != prev_ptr
Bram Moolenaar30abd282005-06-22 22:35:10 +00004987 && (p - nextline) + len > nextline_idx)
4988 {
4989 /* Remember that the good word continues at the
4990 * start of the next line. */
4991 checked_lnum = lnum + 1;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004992 checked_col = (int)((p - nextline) + len - nextline_idx);
Bram Moolenaar30abd282005-06-22 22:35:10 +00004993 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00004994
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00004995 /* Turn index into actual attributes. */
4996 if (spell_hlf != HLF_COUNT)
4997 spell_attr = highlight_attr[spell_hlf];
4998
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00004999 if (cap_col > 0)
5000 {
5001 if (p != prev_ptr
5002 && (p - nextline) + cap_col >= nextline_idx)
5003 {
5004 /* Remember that the word in the next line
5005 * must start with a capital. */
5006 capcol_lnum = lnum + 1;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005007 cap_col = (int)((p - nextline) + cap_col
5008 - nextline_idx);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00005009 }
5010 else
5011 /* Compute the actual column. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005012 cap_col += (int)(prev_ptr - line);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00005013 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00005014 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00005015 }
5016 if (spell_attr != 0)
Bram Moolenaar30abd282005-06-22 22:35:10 +00005017 {
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00005018 if (!attr_pri)
Bram Moolenaar30abd282005-06-22 22:35:10 +00005019 char_attr = hl_combine_attr(char_attr, spell_attr);
5020 else
5021 char_attr = hl_combine_attr(spell_attr, char_attr);
5022 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005023#endif
5024#ifdef FEAT_LINEBREAK
5025 /*
Bram Moolenaar217ad922005-03-20 22:37:15 +00005026 * Found last space before word: check for line break.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005027 */
Bram Moolenaar38632fa2017-02-26 19:40:59 +01005028 if (wp->w_p_lbr && c0 == c
Bram Moolenaar977d0372017-03-12 21:31:58 +01005029 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005030 {
Bram Moolenaar4df70292015-03-21 14:20:16 +01005031 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1) : 0;
Bram Moolenaara12a1612019-01-24 16:39:02 +01005032 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar76feaf12015-03-20 15:58:52 +01005033
Bram Moolenaar597a4222014-06-25 14:39:50 +02005034 /* TODO: is passing p for start of the line OK? */
Bram Moolenaar86b17e92014-07-02 20:00:47 +02005035 n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol,
Bram Moolenaar597a4222014-06-25 14:39:50 +02005036 NULL) - 1;
Bram Moolenaar02631462017-09-22 15:20:32 +02005037 if (c == TAB && n_extra + col > wp->w_width)
Bram Moolenaar307ac5c2018-06-28 22:23:00 +02005038# ifdef FEAT_VARTABS
Bram Moolenaara87b72c2018-06-25 21:24:51 +02005039 n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts,
Bram Moolenaar307ac5c2018-06-28 22:23:00 +02005040 wp->w_buffer->b_p_vts_array) - 1;
5041# else
Bram Moolenaara3650912014-11-19 13:21:57 +01005042 n_extra = (int)wp->w_buffer->b_p_ts
5043 - vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +02005044# endif
Bram Moolenaara3650912014-11-19 13:21:57 +01005045
Bram Moolenaar4df70292015-03-21 14:20:16 +01005046 c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
Bram Moolenaar83a52172019-01-16 22:41:54 +01005047 c_final = NUL;
Bram Moolenaar1c465442017-03-12 20:10:05 +01005048 if (VIM_ISWHITE(c))
Bram Moolenaar3ff9b182013-07-13 12:36:55 +02005049 {
5050#ifdef FEAT_CONCEAL
5051 if (c == TAB)
5052 /* See "Tab alignment" below. */
5053 FIX_FOR_BOGUSCOLS;
5054#endif
Bram Moolenaar86b17e92014-07-02 20:00:47 +02005055 if (!wp->w_p_list)
5056 c = ' ';
Bram Moolenaar3ff9b182013-07-13 12:36:55 +02005057 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005058 }
5059#endif
5060
Bram Moolenaare5e4e222019-04-04 13:28:45 +02005061 // 'list': Change char 160 to lcs_nbsp and space to lcs_space.
5062 // But not when the character is followed by a composing
5063 // character (use mb_l to check that).
5064 if (wp->w_p_list
5065 && ((((c == 160 && mb_l == 1)
5066 || (mb_utf8
5067 && ((mb_c == 160 && mb_l == 2)
5068 || (mb_c == 0x202f && mb_l == 3))))
5069 && lcs_nbsp)
5070 || (c == ' '
5071 && mb_l == 1
5072 && lcs_space
5073 && ptr - line <= trailcol)))
Bram Moolenaar9bc01eb2015-12-17 21:14:58 +01005074 {
Bram Moolenaare5e4e222019-04-04 13:28:45 +02005075 c = (c == ' ') ? lcs_space : lcs_nbsp;
5076 if (area_attr == 0 && search_attr == 0)
Bram Moolenaar9bc01eb2015-12-17 21:14:58 +01005077 {
Bram Moolenaare5e4e222019-04-04 13:28:45 +02005078 n_attr = 1;
5079 extra_attr = HL_ATTR(HLF_8);
5080 saved_attr2 = char_attr; /* save current attr */
Bram Moolenaar9bc01eb2015-12-17 21:14:58 +01005081 }
Bram Moolenaare5e4e222019-04-04 13:28:45 +02005082 mb_c = c;
5083 if (enc_utf8 && utf_char2len(c) > 1)
Bram Moolenaar9bc01eb2015-12-17 21:14:58 +01005084 {
Bram Moolenaare5e4e222019-04-04 13:28:45 +02005085 mb_utf8 = TRUE;
5086 u8cc[0] = 0;
5087 c = 0xc0;
Bram Moolenaar9bc01eb2015-12-17 21:14:58 +01005088 }
Bram Moolenaare5e4e222019-04-04 13:28:45 +02005089 else
5090 mb_utf8 = FALSE;
Bram Moolenaar9bc01eb2015-12-17 21:14:58 +01005091 }
5092
Bram Moolenaar071d4272004-06-13 20:20:40 +00005093 if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ')
5094 {
5095 c = lcs_trail;
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00005096 if (!attr_pri)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005097 {
5098 n_attr = 1;
Bram Moolenaar8820b482017-03-16 17:23:31 +01005099 extra_attr = HL_ATTR(HLF_8);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005100 saved_attr2 = char_attr; /* save current attr */
5101 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005102 mb_c = c;
Bram Moolenaarace95982017-03-29 17:30:27 +02005103 if (enc_utf8 && utf_char2len(c) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005104 {
5105 mb_utf8 = TRUE;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00005106 u8cc[0] = 0;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00005107 c = 0xc0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005108 }
5109 else
5110 mb_utf8 = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005111 }
5112 }
5113
5114 /*
5115 * Handling of non-printable characters.
5116 */
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005117 if (!vim_isprintc(c))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005118 {
5119 /*
5120 * when getting a character from the file, we may have to
5121 * turn it into something else on the way to putting it
5122 * into "ScreenLines".
5123 */
5124 if (c == TAB && (!wp->w_p_list || lcs_tab1))
5125 {
Bram Moolenaar86b17e92014-07-02 20:00:47 +02005126 int tab_len = 0;
Bram Moolenaard574ea22015-01-14 19:35:14 +01005127 long vcol_adjusted = vcol; /* removed showbreak length */
5128#ifdef FEAT_LINEBREAK
5129 /* only adjust the tab_len, when at the first column
5130 * after the showbreak value was drawn */
5131 if (*p_sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap)
5132 vcol_adjusted = vcol - MB_CHARLEN(p_sbr);
5133#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005134 /* tab amount depends on current column */
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005135#ifdef FEAT_VARTABS
5136 tab_len = tabstop_padding(vcol_adjusted,
5137 wp->w_buffer->b_p_ts,
5138 wp->w_buffer->b_p_vts_array) - 1;
5139#else
Bram Moolenaar86b17e92014-07-02 20:00:47 +02005140 tab_len = (int)wp->w_buffer->b_p_ts
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005141 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
5142#endif
Bram Moolenaard574ea22015-01-14 19:35:14 +01005143
Bram Moolenaar86b17e92014-07-02 20:00:47 +02005144#ifdef FEAT_LINEBREAK
Bram Moolenaarb81c85d2014-07-30 16:44:22 +02005145 if (!wp->w_p_lbr || !wp->w_p_list)
Bram Moolenaar86b17e92014-07-02 20:00:47 +02005146#endif
5147 /* tab amount depends on current column */
5148 n_extra = tab_len;
5149#ifdef FEAT_LINEBREAK
5150 else
5151 {
5152 char_u *p;
Bram Moolenaar2c519cf2019-03-21 21:45:34 +01005153 int len;
Bram Moolenaar86b17e92014-07-02 20:00:47 +02005154 int i;
5155 int saved_nextra = n_extra;
5156
Bram Moolenaar49f9dd72014-08-29 12:08:43 +02005157#ifdef FEAT_CONCEAL
Bram Moolenaar8fc6bc72015-02-17 17:26:10 +01005158 if (vcol_off > 0)
Bram Moolenaar49f9dd72014-08-29 12:08:43 +02005159 /* there are characters to conceal */
5160 tab_len += vcol_off;
Bram Moolenaar6a6028c2015-01-20 19:01:35 +01005161 /* boguscols before FIX_FOR_BOGUSCOLS macro from above
5162 */
5163 if (wp->w_p_list && lcs_tab1 && old_boguscols > 0
5164 && n_extra > tab_len)
5165 tab_len += n_extra - tab_len;
Bram Moolenaar49f9dd72014-08-29 12:08:43 +02005166#endif
Bram Moolenaar6a6028c2015-01-20 19:01:35 +01005167
Bram Moolenaar86b17e92014-07-02 20:00:47 +02005168 /* if n_extra > 0, it gives the number of chars, to
5169 * use for a tab, else we need to calculate the width
5170 * for a tab */
Bram Moolenaar86b17e92014-07-02 20:00:47 +02005171 len = (tab_len * mb_char2len(lcs_tab2));
5172 if (n_extra > 0)
5173 len += n_extra - tab_len;
Bram Moolenaar86b17e92014-07-02 20:00:47 +02005174 c = lcs_tab1;
Bram Moolenaar964b3742019-05-24 18:54:09 +02005175 p = alloc(len + 1);
Bram Moolenaar86b17e92014-07-02 20:00:47 +02005176 vim_memset(p, ' ', len);
5177 p[len] = NUL;
Bram Moolenaarb031c4e2017-01-24 20:14:48 +01005178 vim_free(p_extra_free);
Bram Moolenaar86b17e92014-07-02 20:00:47 +02005179 p_extra_free = p;
5180 for (i = 0; i < tab_len; i++)
5181 {
Bram Moolenaar307ac5c2018-06-28 22:23:00 +02005182 if (*p == NUL)
5183 {
5184 tab_len = i;
5185 break;
5186 }
Bram Moolenaar86b17e92014-07-02 20:00:47 +02005187 mb_char2bytes(lcs_tab2, p);
5188 p += mb_char2len(lcs_tab2);
5189 n_extra += mb_char2len(lcs_tab2)
5190 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar86b17e92014-07-02 20:00:47 +02005191 }
5192 p_extra = p_extra_free;
Bram Moolenaar49f9dd72014-08-29 12:08:43 +02005193#ifdef FEAT_CONCEAL
5194 /* n_extra will be increased by FIX_FOX_BOGUSCOLS
5195 * macro below, so need to adjust for that here */
Bram Moolenaar8fc6bc72015-02-17 17:26:10 +01005196 if (vcol_off > 0)
Bram Moolenaar49f9dd72014-08-29 12:08:43 +02005197 n_extra -= vcol_off;
5198#endif
Bram Moolenaar86b17e92014-07-02 20:00:47 +02005199 }
5200#endif
Bram Moolenaar0f9d0862012-12-05 15:32:30 +01005201#ifdef FEAT_CONCEAL
Bram Moolenaar8fc6bc72015-02-17 17:26:10 +01005202 {
5203 int vc_saved = vcol_off;
5204
5205 /* Tab alignment should be identical regardless of
5206 * 'conceallevel' value. So tab compensates of all
5207 * previous concealed characters, and thus resets
5208 * vcol_off and boguscols accumulated so far in the
5209 * line. Note that the tab can be longer than
5210 * 'tabstop' when there are concealed characters. */
5211 FIX_FOR_BOGUSCOLS;
5212
5213 /* Make sure, the highlighting for the tab char will be
5214 * correctly set further below (effectively reverts the
5215 * FIX_FOR_BOGSUCOLS macro */
5216 if (n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaar6a6028c2015-01-20 19:01:35 +01005217 && lcs_tab1)
Bram Moolenaar8fc6bc72015-02-17 17:26:10 +01005218 tab_len += vc_saved;
5219 }
Bram Moolenaar0f9d0862012-12-05 15:32:30 +01005220#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005221 mb_utf8 = FALSE; /* don't draw as UTF-8 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005222 if (wp->w_p_list)
5223 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01005224 c = (n_extra == 0 && lcs_tab3) ? lcs_tab3 : lcs_tab1;
Bram Moolenaar86b17e92014-07-02 20:00:47 +02005225#ifdef FEAT_LINEBREAK
5226 if (wp->w_p_lbr)
5227 c_extra = NUL; /* using p_extra from above */
5228 else
5229#endif
5230 c_extra = lcs_tab2;
Bram Moolenaar83a52172019-01-16 22:41:54 +01005231 c_final = lcs_tab3;
Bram Moolenaar86b17e92014-07-02 20:00:47 +02005232 n_attr = tab_len + 1;
Bram Moolenaar8820b482017-03-16 17:23:31 +01005233 extra_attr = HL_ATTR(HLF_8);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005234 saved_attr2 = char_attr; /* save current attr */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005235 mb_c = c;
Bram Moolenaarace95982017-03-29 17:30:27 +02005236 if (enc_utf8 && utf_char2len(c) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005237 {
5238 mb_utf8 = TRUE;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00005239 u8cc[0] = 0;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00005240 c = 0xc0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005241 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005242 }
5243 else
5244 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01005245 c_final = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005246 c_extra = ' ';
5247 c = ' ';
5248 }
5249 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005250 else if (c == NUL
Bram Moolenaard59c0992015-05-04 16:52:01 +02005251 && (wp->w_p_list
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005252 || ((fromcol >= 0 || fromcol_prev >= 0)
5253 && tocol > vcol
5254 && VIsual_mode != Ctrl_V
5255 && (
5256# ifdef FEAT_RIGHTLEFT
5257 wp->w_p_rl ? (col >= 0) :
5258# endif
Bram Moolenaar02631462017-09-22 15:20:32 +02005259 (col < wp->w_width))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005260 && !(noinvcur
Bram Moolenaarf3205d12009-03-18 18:09:03 +00005261 && lnum == wp->w_cursor.lnum
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005262 && (colnr_T)vcol == wp->w_virtcol)))
Bram Moolenaar0481fee2015-05-14 05:56:09 +02005263 && lcs_eol_one > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005264 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005265 /* Display a '$' after the line or highlight an extra
5266 * character if the line break is included. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005267#if defined(FEAT_DIFF) || defined(LINE_ATTR)
5268 /* For a diff line the highlighting continues after the
5269 * "$". */
5270 if (
5271# ifdef FEAT_DIFF
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00005272 diff_hlf == (hlf_T)0
Bram Moolenaar071d4272004-06-13 20:20:40 +00005273# ifdef LINE_ATTR
5274 &&
5275# endif
5276# endif
5277# ifdef LINE_ATTR
5278 line_attr == 0
5279# endif
5280 )
5281#endif
5282 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00005283 /* In virtualedit, visual selections may extend
5284 * beyond end of line. */
5285 if (area_highlighting && virtual_active()
5286 && tocol != MAXCOL && vcol < tocol)
5287 n_extra = 0;
5288 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005289 {
5290 p_extra = at_end_str;
5291 n_extra = 1;
5292 c_extra = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01005293 c_final = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005294 }
5295 }
Bram Moolenaard59c0992015-05-04 16:52:01 +02005296 if (wp->w_p_list && lcs_eol > 0)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005297 c = lcs_eol;
5298 else
5299 c = ' ';
Bram Moolenaar071d4272004-06-13 20:20:40 +00005300 lcs_eol_one = -1;
5301 --ptr; /* put it back at the NUL */
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00005302 if (!attr_pri)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005303 {
Bram Moolenaar8820b482017-03-16 17:23:31 +01005304 extra_attr = HL_ATTR(HLF_AT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005305 n_attr = 1;
5306 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005307 mb_c = c;
Bram Moolenaarace95982017-03-29 17:30:27 +02005308 if (enc_utf8 && utf_char2len(c) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005309 {
5310 mb_utf8 = TRUE;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00005311 u8cc[0] = 0;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00005312 c = 0xc0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005313 }
5314 else
5315 mb_utf8 = FALSE; /* don't draw as UTF-8 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005316 }
5317 else if (c != NUL)
5318 {
5319 p_extra = transchar(c);
Bram Moolenaar5524aeb2014-07-16 17:29:51 +02005320 if (n_extra == 0)
5321 n_extra = byte2cells(c) - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005322#ifdef FEAT_RIGHTLEFT
5323 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
5324 rl_mirror(p_extra); /* reverse "<12>" */
5325#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005326 c_extra = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01005327 c_final = NUL;
Bram Moolenaar86b17e92014-07-02 20:00:47 +02005328#ifdef FEAT_LINEBREAK
5329 if (wp->w_p_lbr)
5330 {
5331 char_u *p;
5332
5333 c = *p_extra;
Bram Moolenaar964b3742019-05-24 18:54:09 +02005334 p = alloc(n_extra + 1);
Bram Moolenaar86b17e92014-07-02 20:00:47 +02005335 vim_memset(p, ' ', n_extra);
5336 STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1);
5337 p[n_extra] = NUL;
Bram Moolenaarb031c4e2017-01-24 20:14:48 +01005338 vim_free(p_extra_free);
Bram Moolenaar86b17e92014-07-02 20:00:47 +02005339 p_extra_free = p_extra = p;
5340 }
5341 else
5342#endif
5343 {
5344 n_extra = byte2cells(c) - 1;
5345 c = *p_extra++;
5346 }
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00005347 if (!attr_pri)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005348 {
5349 n_attr = n_extra + 1;
Bram Moolenaar8820b482017-03-16 17:23:31 +01005350 extra_attr = HL_ATTR(HLF_8);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005351 saved_attr2 = char_attr; /* save current attr */
5352 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005353 mb_utf8 = FALSE; /* don't draw as UTF-8 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005354 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005355 else if (VIsual_active
5356 && (VIsual_mode == Ctrl_V
5357 || VIsual_mode == 'v')
5358 && virtual_active()
5359 && tocol != MAXCOL
5360 && vcol < tocol
5361 && (
Bram Moolenaar29ddebe2019-01-26 17:28:26 +01005362#ifdef FEAT_RIGHTLEFT
Bram Moolenaar071d4272004-06-13 20:20:40 +00005363 wp->w_p_rl ? (col >= 0) :
Bram Moolenaar29ddebe2019-01-26 17:28:26 +01005364#endif
Bram Moolenaar02631462017-09-22 15:20:32 +02005365 (col < wp->w_width)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005366 {
5367 c = ' ';
5368 --ptr; /* put it back at the NUL */
5369 }
Bram Moolenaar6c60ea22006-07-11 20:36:45 +00005370#if defined(LINE_ATTR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005371 else if ((
5372# ifdef FEAT_DIFF
Bram Moolenaar6c60ea22006-07-11 20:36:45 +00005373 diff_hlf != (hlf_T)0 ||
Bram Moolenaar071d4272004-06-13 20:20:40 +00005374# endif
Bram Moolenaar238d43b2017-09-11 22:00:51 +02005375# ifdef FEAT_TERMINAL
Bram Moolenaar4d784b22019-05-25 19:51:39 +02005376 win_attr != 0 ||
Bram Moolenaar238d43b2017-09-11 22:00:51 +02005377# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005378 line_attr != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00005379 ) && (
5380# ifdef FEAT_RIGHTLEFT
5381 wp->w_p_rl ? (col >= 0) :
5382# endif
Bram Moolenaar2a988a12010-08-13 15:24:39 +02005383 (col
5384# ifdef FEAT_CONCEAL
5385 - boguscols
5386# endif
Bram Moolenaar02631462017-09-22 15:20:32 +02005387 < wp->w_width)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005388 {
5389 /* Highlight until the right side of the window */
5390 c = ' ';
5391 --ptr; /* put it back at the NUL */
Bram Moolenaar91170f82006-05-05 21:15:17 +00005392
5393 /* Remember we do the char for line highlighting. */
5394 ++did_line_attr;
5395
5396 /* don't do search HL for the rest of the line */
Bram Moolenaar0aa398f2017-09-30 21:23:55 +02005397 if (line_attr != 0 && char_attr == search_attr
5398 && (did_line_attr > 1
5399 || (wp->w_p_list && lcs_eol > 0)))
Bram Moolenaar91170f82006-05-05 21:15:17 +00005400 char_attr = line_attr;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005401# ifdef FEAT_DIFF
5402 if (diff_hlf == HLF_TXD)
5403 {
5404 diff_hlf = HLF_CHD;
Bram Moolenaar4d784b22019-05-25 19:51:39 +02005405 if (vi_attr == 0 || char_attr != vi_attr)
Bram Moolenaare0f14822014-08-06 13:20:56 +02005406 {
Bram Moolenaar8820b482017-03-16 17:23:31 +01005407 char_attr = HL_ATTR(diff_hlf);
Bram Moolenaare0f14822014-08-06 13:20:56 +02005408 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
5409 char_attr = hl_combine_attr(char_attr,
Bram Moolenaar8820b482017-03-16 17:23:31 +01005410 HL_ATTR(HLF_CUL));
Bram Moolenaare0f14822014-08-06 13:20:56 +02005411 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005412 }
5413# endif
Bram Moolenaar238d43b2017-09-11 22:00:51 +02005414# ifdef FEAT_TERMINAL
Bram Moolenaar4d784b22019-05-25 19:51:39 +02005415 if (win_attr != 0)
Bram Moolenaar238d43b2017-09-11 22:00:51 +02005416 {
Bram Moolenaar4d784b22019-05-25 19:51:39 +02005417 char_attr = win_attr;
Bram Moolenaar238d43b2017-09-11 22:00:51 +02005418 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
5419 char_attr = hl_combine_attr(char_attr,
5420 HL_ATTR(HLF_CUL));
5421 }
5422# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005423 }
5424#endif
5425 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02005426
5427#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02005428 if ( wp->w_p_cole > 0
5429 && (wp != curwin || lnum != wp->w_cursor.lnum ||
Bram Moolenaarab62c192019-03-30 16:39:05 +01005430 conceal_cursor_line(wp))
5431 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
Bram Moolenaare6dc5732010-07-24 23:52:26 +02005432 && !(lnum_in_visual_area
5433 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
Bram Moolenaar860cae12010-06-05 23:22:07 +02005434 {
5435 char_attr = conceal_attr;
Bram Moolenaar4d585022016-04-14 19:50:22 +02005436 if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1)
Bram Moolenaar6561d522015-07-21 15:48:27 +02005437 && (syn_get_sub_char() != NUL || match_conc
5438 || wp->w_p_cole == 1)
Bram Moolenaarf5963f72010-07-23 22:10:27 +02005439 && wp->w_p_cole != 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02005440 {
Bram Moolenaar27c735b2010-07-22 22:16:29 +02005441 /* First time at this concealed item: display one
5442 * character. */
Bram Moolenaar6561d522015-07-21 15:48:27 +02005443 if (match_conc)
5444 c = match_conc;
5445 else if (syn_get_sub_char() != NUL)
Bram Moolenaar860cae12010-06-05 23:22:07 +02005446 c = syn_get_sub_char();
5447 else if (lcs_conceal != NUL)
5448 c = lcs_conceal;
5449 else
5450 c = ' ';
5451
Bram Moolenaarffbbcb52010-07-24 17:29:03 +02005452 prev_syntax_id = syntax_seqnr;
Bram Moolenaar860cae12010-06-05 23:22:07 +02005453
Bram Moolenaarac550fd2010-07-18 13:55:02 +02005454 if (n_extra > 0)
5455 vcol_off += n_extra;
Bram Moolenaar860cae12010-06-05 23:22:07 +02005456 vcol += n_extra;
5457 if (wp->w_p_wrap && n_extra > 0)
5458 {
5459# ifdef FEAT_RIGHTLEFT
5460 if (wp->w_p_rl)
5461 {
5462 col -= n_extra;
5463 boguscols -= n_extra;
5464 }
5465 else
5466# endif
5467 {
5468 boguscols += n_extra;
5469 col += n_extra;
5470 }
5471 }
5472 n_extra = 0;
5473 n_attr = 0;
5474 }
5475 else if (n_skip == 0)
5476 {
5477 is_concealing = TRUE;
5478 n_skip = 1;
5479 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02005480 mb_c = c;
Bram Moolenaarace95982017-03-29 17:30:27 +02005481 if (enc_utf8 && utf_char2len(c) > 1)
Bram Moolenaar860cae12010-06-05 23:22:07 +02005482 {
5483 mb_utf8 = TRUE;
5484 u8cc[0] = 0;
5485 c = 0xc0;
5486 }
5487 else
5488 mb_utf8 = FALSE; /* don't draw as UTF-8 */
Bram Moolenaar860cae12010-06-05 23:22:07 +02005489 }
5490 else
5491 {
Bram Moolenaar27c735b2010-07-22 22:16:29 +02005492 prev_syntax_id = 0;
Bram Moolenaarc400cb92010-07-19 19:52:13 +02005493 is_concealing = FALSE;
Bram Moolenaar860cae12010-06-05 23:22:07 +02005494 }
Bram Moolenaar0ebe12b2019-05-17 12:31:44 +02005495
5496 if (n_skip > 0 && did_decrement_ptr)
5497 // not showing the '>', put pointer back to avoid getting stuck
5498 ++ptr;
5499
5500#endif // FEAT_CONCEAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00005501 }
5502
Bram Moolenaarf5963f72010-07-23 22:10:27 +02005503#ifdef FEAT_CONCEAL
5504 /* In the cursor line and we may be concealing characters: correct
5505 * the cursor column when we reach its position. */
Bram Moolenaarf691b842010-07-24 13:31:09 +02005506 if (!did_wcol && draw_state == WL_LINE
5507 && wp == curwin && lnum == wp->w_cursor.lnum
Bram Moolenaarf5963f72010-07-23 22:10:27 +02005508 && conceal_cursor_line(wp)
5509 && (int)wp->w_virtcol <= vcol + n_skip)
5510 {
Bram Moolenaare39b3d92016-01-15 22:52:22 +01005511# ifdef FEAT_RIGHTLEFT
5512 if (wp->w_p_rl)
Bram Moolenaar02631462017-09-22 15:20:32 +02005513 wp->w_wcol = wp->w_width - col + boguscols - 1;
Bram Moolenaare39b3d92016-01-15 22:52:22 +01005514 else
5515# endif
5516 wp->w_wcol = col - boguscols;
Bram Moolenaar72ada0f2010-07-24 17:39:52 +02005517 wp->w_wrow = row;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02005518 did_wcol = TRUE;
5519 }
5520#endif
5521
Bram Moolenaar071d4272004-06-13 20:20:40 +00005522 /* Don't override visual selection highlighting. */
5523 if (n_attr > 0
5524 && draw_state == WL_LINE
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00005525 && !attr_pri)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005526 char_attr = extra_attr;
5527
Bram Moolenaar81695252004-12-29 20:58:21 +00005528#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005529 /* XIM don't send preedit_start and preedit_end, but they send
5530 * preedit_changed and commit. Thus Vim can't set "im_is_active", use
5531 * im_is_preediting() here. */
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02005532 if (p_imst == IM_ON_THE_SPOT
5533 && xic != NULL
Bram Moolenaarf3205d12009-03-18 18:09:03 +00005534 && lnum == wp->w_cursor.lnum
Bram Moolenaar071d4272004-06-13 20:20:40 +00005535 && (State & INSERT)
5536 && !p_imdisable
5537 && im_is_preediting()
5538 && draw_state == WL_LINE)
5539 {
5540 colnr_T tcol;
5541
5542 if (preedit_end_col == MAXCOL)
Bram Moolenaarf3205d12009-03-18 18:09:03 +00005543 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005544 else
5545 tcol = preedit_end_col;
5546 if ((long)preedit_start_col <= vcol && vcol < (long)tcol)
5547 {
5548 if (feedback_old_attr < 0)
5549 {
5550 feedback_col = 0;
5551 feedback_old_attr = char_attr;
5552 }
5553 char_attr = im_get_feedback_attr(feedback_col);
5554 if (char_attr < 0)
5555 char_attr = feedback_old_attr;
5556 feedback_col++;
5557 }
5558 else if (feedback_old_attr >= 0)
5559 {
5560 char_attr = feedback_old_attr;
5561 feedback_old_attr = -1;
5562 feedback_col = 0;
5563 }
5564 }
5565#endif
5566 /*
5567 * Handle the case where we are in column 0 but not on the first
5568 * character of the line and the user wants us to show us a
5569 * special character (via 'listchars' option "precedes:<char>".
5570 */
5571 if (lcs_prec_todo != NUL
Bram Moolenaar7425b932014-10-10 15:28:46 +02005572 && wp->w_p_list
Bram Moolenaar071d4272004-06-13 20:20:40 +00005573 && (wp->w_p_wrap ? wp->w_skipcol > 0 : wp->w_leftcol > 0)
5574#ifdef FEAT_DIFF
5575 && filler_todo <= 0
5576#endif
5577 && draw_state > WL_NR
5578 && c != NUL)
5579 {
5580 c = lcs_prec;
5581 lcs_prec_todo = NUL;
Bram Moolenaar5641f382012-06-13 18:06:36 +02005582 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
5583 {
5584 /* Double-width character being overwritten by the "precedes"
5585 * character, need to fill up half the character. */
5586 c_extra = MB_FILLER_CHAR;
Bram Moolenaar83a52172019-01-16 22:41:54 +01005587 c_final = NUL;
Bram Moolenaar5641f382012-06-13 18:06:36 +02005588 n_extra = 1;
5589 n_attr = 2;
Bram Moolenaar8820b482017-03-16 17:23:31 +01005590 extra_attr = HL_ATTR(HLF_AT);
Bram Moolenaar5641f382012-06-13 18:06:36 +02005591 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005592 mb_c = c;
Bram Moolenaarace95982017-03-29 17:30:27 +02005593 if (enc_utf8 && utf_char2len(c) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005594 {
5595 mb_utf8 = TRUE;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00005596 u8cc[0] = 0;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00005597 c = 0xc0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005598 }
5599 else
5600 mb_utf8 = FALSE; /* don't draw as UTF-8 */
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00005601 if (!attr_pri)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005602 {
5603 saved_attr3 = char_attr; /* save current attr */
Bram Moolenaar8820b482017-03-16 17:23:31 +01005604 char_attr = HL_ATTR(HLF_AT); /* later copied to char_attr */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005605 n_attr3 = 1;
5606 }
5607 }
5608
5609 /*
Bram Moolenaar91170f82006-05-05 21:15:17 +00005610 * At end of the text line or just after the last character.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005611 */
Bram Moolenaar91170f82006-05-05 21:15:17 +00005612 if (c == NUL
Bram Moolenaar6c60ea22006-07-11 20:36:45 +00005613#if defined(LINE_ATTR)
Bram Moolenaar91170f82006-05-05 21:15:17 +00005614 || did_line_attr == 1
5615#endif
5616 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005617 {
Bram Moolenaar91170f82006-05-05 21:15:17 +00005618#ifdef FEAT_SEARCH_EXTRA
5619 long prevcol = (long)(ptr - line) - (c == NUL);
Bram Moolenaara443af82007-11-08 13:51:42 +00005620
5621 /* we're not really at that column when skipping some text */
Bram Moolenaar33741a02007-11-08 20:24:19 +00005622 if ((long)(wp->w_p_wrap ? wp->w_skipcol : wp->w_leftcol) > prevcol)
Bram Moolenaara443af82007-11-08 13:51:42 +00005623 ++prevcol;
Bram Moolenaar91170f82006-05-05 21:15:17 +00005624#endif
5625
Bram Moolenaarac550fd2010-07-18 13:55:02 +02005626 /* Invert at least one char, used for Visual and empty line or
Bram Moolenaar071d4272004-06-13 20:20:40 +00005627 * highlight match at end of line. If it's beyond the last
5628 * char on the screen, just overwrite that one (tricky!) Not
5629 * needed when a '$' was displayed for 'list'. */
Bram Moolenaar6ee10162007-07-26 20:58:42 +00005630#ifdef FEAT_SEARCH_EXTRA
5631 prevcol_hl_flag = FALSE;
Bram Moolenaar4f416e42016-08-16 16:08:18 +02005632 if (!search_hl.is_addpos && prevcol == (long)search_hl.startcol)
Bram Moolenaar6ee10162007-07-26 20:58:42 +00005633 prevcol_hl_flag = TRUE;
5634 else
5635 {
5636 cur = wp->w_match_head;
5637 while (cur != NULL)
5638 {
Bram Moolenaar4f416e42016-08-16 16:08:18 +02005639 if (!cur->hl.is_addpos && prevcol == (long)cur->hl.startcol)
Bram Moolenaar6ee10162007-07-26 20:58:42 +00005640 {
5641 prevcol_hl_flag = TRUE;
5642 break;
5643 }
5644 cur = cur->next;
5645 }
5646 }
5647#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005648 if (lcs_eol == lcs_eol_one
Bram Moolenaarf3205d12009-03-18 18:09:03 +00005649 && ((area_attr != 0 && vcol == fromcol
Bram Moolenaarf3205d12009-03-18 18:09:03 +00005650 && (VIsual_mode != Ctrl_V
5651 || lnum == VIsual.lnum
5652 || lnum == curwin->w_cursor.lnum)
Bram Moolenaarf3205d12009-03-18 18:09:03 +00005653 && c == NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005654#ifdef FEAT_SEARCH_EXTRA
5655 /* highlight 'hlsearch' match at end of line */
Bram Moolenaar6ee10162007-07-26 20:58:42 +00005656 || (prevcol_hl_flag == TRUE
Bram Moolenaar0aa398f2017-09-30 21:23:55 +02005657# ifdef FEAT_SYN_HL
5658 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
5659 && !(wp == curwin && VIsual_active))
5660# endif
5661# ifdef FEAT_DIFF
5662 && diff_hlf == (hlf_T)0
5663# endif
Bram Moolenaar6c60ea22006-07-11 20:36:45 +00005664# if defined(LINE_ATTR)
Bram Moolenaar91170f82006-05-05 21:15:17 +00005665 && did_line_attr <= 1
5666# endif
5667 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005668#endif
5669 ))
5670 {
5671 int n = 0;
5672
5673#ifdef FEAT_RIGHTLEFT
5674 if (wp->w_p_rl)
5675 {
5676 if (col < 0)
5677 n = 1;
5678 }
5679 else
5680#endif
5681 {
Bram Moolenaar02631462017-09-22 15:20:32 +02005682 if (col >= wp->w_width)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005683 n = -1;
5684 }
5685 if (n != 0)
5686 {
5687 /* At the window boundary, highlight the last character
5688 * instead (better than nothing). */
5689 off += n;
5690 col += n;
5691 }
5692 else
5693 {
5694 /* Add a blank character to highlight. */
5695 ScreenLines[off] = ' ';
Bram Moolenaar071d4272004-06-13 20:20:40 +00005696 if (enc_utf8)
5697 ScreenLinesUC[off] = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005698 }
5699#ifdef FEAT_SEARCH_EXTRA
5700 if (area_attr == 0)
5701 {
Bram Moolenaar6ee10162007-07-26 20:58:42 +00005702 /* Use attributes from match with highest priority among
5703 * 'search_hl' and the match list. */
5704 char_attr = search_hl.attr;
5705 cur = wp->w_match_head;
5706 shl_flag = FALSE;
5707 while (cur != NULL || shl_flag == FALSE)
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00005708 {
Bram Moolenaar6ee10162007-07-26 20:58:42 +00005709 if (shl_flag == FALSE
5710 && ((cur != NULL
5711 && cur->priority > SEARCH_HL_PRIORITY)
5712 || cur == NULL))
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00005713 {
Bram Moolenaar6ee10162007-07-26 20:58:42 +00005714 shl = &search_hl;
5715 shl_flag = TRUE;
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00005716 }
Bram Moolenaar6ee10162007-07-26 20:58:42 +00005717 else
5718 shl = &cur->hl;
Bram Moolenaar4f416e42016-08-16 16:08:18 +02005719 if ((ptr - line) - 1 == (long)shl->startcol
5720 && (shl == &search_hl || !shl->is_addpos))
Bram Moolenaar6ee10162007-07-26 20:58:42 +00005721 char_attr = shl->attr;
5722 if (shl != &search_hl && cur != NULL)
5723 cur = cur->next;
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00005724 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005725 }
5726#endif
5727 ScreenAttrs[off] = char_attr;
5728#ifdef FEAT_RIGHTLEFT
5729 if (wp->w_p_rl)
Bram Moolenaara443af82007-11-08 13:51:42 +00005730 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00005731 --col;
Bram Moolenaara443af82007-11-08 13:51:42 +00005732 --off;
5733 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005734 else
5735#endif
Bram Moolenaara443af82007-11-08 13:51:42 +00005736 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00005737 ++col;
Bram Moolenaara443af82007-11-08 13:51:42 +00005738 ++off;
5739 }
Bram Moolenaar600dddc2006-03-12 22:05:10 +00005740 ++vcol;
Bram Moolenaara443af82007-11-08 13:51:42 +00005741#ifdef FEAT_SYN_HL
5742 eol_hl_off = 1;
5743#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005744 }
Bram Moolenaar91170f82006-05-05 21:15:17 +00005745 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005746
Bram Moolenaar91170f82006-05-05 21:15:17 +00005747 /*
5748 * At end of the text line.
5749 */
5750 if (c == NUL)
5751 {
Bram Moolenaar600dddc2006-03-12 22:05:10 +00005752#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02005753 /* Highlight 'cursorcolumn' & 'colorcolumn' past end of the line. */
Bram Moolenaar1f4d4de2006-03-14 23:00:46 +00005754 if (wp->w_p_wrap)
5755 v = wp->w_skipcol;
5756 else
5757 v = wp->w_leftcol;
Bram Moolenaar1a384422010-07-14 19:53:30 +02005758
Bram Moolenaar8dff8182006-04-06 20:18:50 +00005759 /* check if line ends before left margin */
5760 if (vcol < v + col - win_col_off(wp))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00005761 vcol = v + col - win_col_off(wp);
Bram Moolenaarac550fd2010-07-18 13:55:02 +02005762#ifdef FEAT_CONCEAL
Bram Moolenaar2c519cf2019-03-21 21:45:34 +01005763 // Get rid of the boguscols now, we want to draw until the right
5764 // edge for 'cursorcolumn'.
Bram Moolenaarac550fd2010-07-18 13:55:02 +02005765 col -= boguscols;
5766 boguscols = 0;
5767#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +02005768
5769 if (draw_color_col)
Bram Moolenaarac550fd2010-07-18 13:55:02 +02005770 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
Bram Moolenaar1a384422010-07-14 19:53:30 +02005771
5772 if (((wp->w_p_cuc
Bram Moolenaarac550fd2010-07-18 13:55:02 +02005773 && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off
5774 && (int)wp->w_virtcol <
Bram Moolenaar02631462017-09-22 15:20:32 +02005775 wp->w_width * (row - startrow + 1) + v
Bram Moolenaar1a384422010-07-14 19:53:30 +02005776 && lnum != wp->w_cursor.lnum)
Bram Moolenaar4d784b22019-05-25 19:51:39 +02005777 || draw_color_col
5778 || win_attr != 0)
Bram Moolenaar600dddc2006-03-12 22:05:10 +00005779# ifdef FEAT_RIGHTLEFT
5780 && !wp->w_p_rl
5781# endif
5782 )
5783 {
Bram Moolenaar1a384422010-07-14 19:53:30 +02005784 int rightmost_vcol = 0;
5785 int i;
5786
5787 if (wp->w_p_cuc)
5788 rightmost_vcol = wp->w_virtcol;
5789 if (draw_color_col)
5790 /* determine rightmost colorcolumn to possibly draw */
5791 for (i = 0; color_cols[i] >= 0; ++i)
5792 if (rightmost_vcol < color_cols[i])
5793 rightmost_vcol = color_cols[i];
5794
Bram Moolenaar02631462017-09-22 15:20:32 +02005795 while (col < wp->w_width)
Bram Moolenaar600dddc2006-03-12 22:05:10 +00005796 {
5797 ScreenLines[off] = ' ';
Bram Moolenaar600dddc2006-03-12 22:05:10 +00005798 if (enc_utf8)
5799 ScreenLinesUC[off] = 0;
Bram Moolenaar600dddc2006-03-12 22:05:10 +00005800 ++col;
Bram Moolenaar973bd472010-07-20 11:29:07 +02005801 if (draw_color_col)
5802 draw_color_col = advance_color_col(VCOL_HLC,
5803 &color_cols);
5804
Bram Moolenaarac550fd2010-07-18 13:55:02 +02005805 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
Bram Moolenaar8820b482017-03-16 17:23:31 +01005806 ScreenAttrs[off++] = HL_ATTR(HLF_CUC);
Bram Moolenaarac550fd2010-07-18 13:55:02 +02005807 else if (draw_color_col && VCOL_HLC == *color_cols)
Bram Moolenaar8820b482017-03-16 17:23:31 +01005808 ScreenAttrs[off++] = HL_ATTR(HLF_MC);
Bram Moolenaar1a384422010-07-14 19:53:30 +02005809 else
Bram Moolenaar4d784b22019-05-25 19:51:39 +02005810 ScreenAttrs[off++] = win_attr;
Bram Moolenaar1a384422010-07-14 19:53:30 +02005811
Bram Moolenaar4d784b22019-05-25 19:51:39 +02005812 if (VCOL_HLC >= rightmost_vcol && win_attr == 0)
Bram Moolenaar600dddc2006-03-12 22:05:10 +00005813 break;
Bram Moolenaar1a384422010-07-14 19:53:30 +02005814
Bram Moolenaar600dddc2006-03-12 22:05:10 +00005815 ++vcol;
5816 }
5817 }
5818#endif
5819
Bram Moolenaar53f81742017-09-22 14:35:51 +02005820 screen_line(screen_row, wp->w_wincol, col,
Bram Moolenaar4d784b22019-05-25 19:51:39 +02005821 (int)wp->w_width, screen_line_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005822 row++;
5823
5824 /*
5825 * Update w_cline_height and w_cline_folded if the cursor line was
5826 * updated (saves a call to plines() later).
5827 */
5828 if (wp == curwin && lnum == curwin->w_cursor.lnum)
5829 {
5830 curwin->w_cline_row = startrow;
5831 curwin->w_cline_height = row - startrow;
5832#ifdef FEAT_FOLDING
5833 curwin->w_cline_folded = FALSE;
5834#endif
5835 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
5836 }
5837
5838 break;
5839 }
5840
Bram Moolenaara5c6a0b2019-05-08 20:20:46 +02005841 // Show "extends" character from 'listchars' if beyond the line end and
5842 // 'list' is set.
5843 if (lcs_ext != NUL
5844 && wp->w_p_list
Bram Moolenaar071d4272004-06-13 20:20:40 +00005845 && !wp->w_p_wrap
5846#ifdef FEAT_DIFF
5847 && filler_todo <= 0
5848#endif
5849 && (
5850#ifdef FEAT_RIGHTLEFT
5851 wp->w_p_rl ? col == 0 :
5852#endif
Bram Moolenaar02631462017-09-22 15:20:32 +02005853 col == wp->w_width - 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005854 && (*ptr != NUL
Bram Moolenaar5bbc21d2008-03-09 13:30:56 +00005855 || (wp->w_p_list && lcs_eol_one > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005856 || (n_extra && (c_extra != NUL || *p_extra != NUL))))
5857 {
5858 c = lcs_ext;
Bram Moolenaar8820b482017-03-16 17:23:31 +01005859 char_attr = HL_ATTR(HLF_AT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005860 mb_c = c;
Bram Moolenaarace95982017-03-29 17:30:27 +02005861 if (enc_utf8 && utf_char2len(c) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005862 {
5863 mb_utf8 = TRUE;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00005864 u8cc[0] = 0;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00005865 c = 0xc0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005866 }
5867 else
5868 mb_utf8 = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005869 }
5870
Bram Moolenaar600dddc2006-03-12 22:05:10 +00005871#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02005872 /* advance to the next 'colorcolumn' */
5873 if (draw_color_col)
Bram Moolenaarac550fd2010-07-18 13:55:02 +02005874 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
Bram Moolenaar1a384422010-07-14 19:53:30 +02005875
Bram Moolenaar600dddc2006-03-12 22:05:10 +00005876 /* Highlight the cursor column if 'cursorcolumn' is set. But don't
Bram Moolenaar1a384422010-07-14 19:53:30 +02005877 * highlight the cursor position itself.
5878 * Also highlight the 'colorcolumn' if it is different than
5879 * 'cursorcolumn' */
5880 vcol_save_attr = -1;
Bram Moolenaar774e5a92017-06-25 18:03:37 +02005881 if (draw_state == WL_LINE && !lnum_in_visual_area
5882 && search_attr == 0 && area_attr == 0)
Bram Moolenaar600dddc2006-03-12 22:05:10 +00005883 {
Bram Moolenaarac550fd2010-07-18 13:55:02 +02005884 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
Bram Moolenaar1a384422010-07-14 19:53:30 +02005885 && lnum != wp->w_cursor.lnum)
5886 {
5887 vcol_save_attr = char_attr;
Bram Moolenaar8820b482017-03-16 17:23:31 +01005888 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUC));
Bram Moolenaar1a384422010-07-14 19:53:30 +02005889 }
Bram Moolenaard160c342010-07-18 23:30:34 +02005890 else if (draw_color_col && VCOL_HLC == *color_cols)
Bram Moolenaar1a384422010-07-14 19:53:30 +02005891 {
5892 vcol_save_attr = char_attr;
Bram Moolenaar8820b482017-03-16 17:23:31 +01005893 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar1a384422010-07-14 19:53:30 +02005894 }
Bram Moolenaar600dddc2006-03-12 22:05:10 +00005895 }
Bram Moolenaar600dddc2006-03-12 22:05:10 +00005896#endif
5897
Bram Moolenaar071d4272004-06-13 20:20:40 +00005898 /*
5899 * Store character to be displayed.
5900 * Skip characters that are left of the screen for 'nowrap'.
5901 */
5902 vcol_prev = vcol;
5903 if (draw_state < WL_LINE || n_skip <= 0)
5904 {
5905 /*
5906 * Store the character.
5907 */
Bram Moolenaara12a1612019-01-24 16:39:02 +01005908#if defined(FEAT_RIGHTLEFT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005909 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
5910 {
5911 /* A double-wide character is: put first halve in left cell. */
5912 --off;
5913 --col;
5914 }
5915#endif
5916 ScreenLines[off] = c;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005917 if (enc_dbcs == DBCS_JPNU)
Bram Moolenaar990bb662010-02-03 15:48:04 +01005918 {
5919 if ((mb_c & 0xff00) == 0x8e00)
5920 ScreenLines[off] = 0x8e;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005921 ScreenLines2[off] = mb_c & 0xff;
Bram Moolenaar990bb662010-02-03 15:48:04 +01005922 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005923 else if (enc_utf8)
5924 {
5925 if (mb_utf8)
5926 {
Bram Moolenaar6ee10162007-07-26 20:58:42 +00005927 int i;
5928
Bram Moolenaar071d4272004-06-13 20:20:40 +00005929 ScreenLinesUC[off] = mb_c;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00005930 if ((c & 0xff) == 0)
5931 ScreenLines[off] = 0x80; /* avoid storing zero */
Bram Moolenaar362e1a32006-03-06 23:29:24 +00005932 for (i = 0; i < Screen_mco; ++i)
5933 {
5934 ScreenLinesC[i][off] = u8cc[i];
5935 if (u8cc[i] == 0)
5936 break;
5937 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005938 }
5939 else
5940 ScreenLinesUC[off] = 0;
5941 }
5942 if (multi_attr)
5943 {
5944 ScreenAttrs[off] = multi_attr;
5945 multi_attr = 0;
5946 }
5947 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005948 ScreenAttrs[off] = char_attr;
5949
Bram Moolenaar071d4272004-06-13 20:20:40 +00005950 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
5951 {
5952 /* Need to fill two screen columns. */
5953 ++off;
5954 ++col;
5955 if (enc_utf8)
5956 /* UTF-8: Put a 0 in the second screen char. */
5957 ScreenLines[off] = 0;
5958 else
5959 /* DBCS: Put second byte in the second screen char. */
5960 ScreenLines[off] = mb_c & 0xff;
Bram Moolenaar32a214e2015-12-03 14:29:02 +01005961 if (draw_state > WL_NR
5962#ifdef FEAT_DIFF
5963 && filler_todo <= 0
5964#endif
5965 )
5966 ++vcol;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005967 /* When "tocol" is halfway a character, set it to the end of
5968 * the character, otherwise highlighting won't stop. */
5969 if (tocol == vcol)
5970 ++tocol;
5971#ifdef FEAT_RIGHTLEFT
5972 if (wp->w_p_rl)
5973 {
5974 /* now it's time to backup one cell */
5975 --off;
5976 --col;
5977 }
5978#endif
5979 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005980#ifdef FEAT_RIGHTLEFT
5981 if (wp->w_p_rl)
5982 {
5983 --off;
5984 --col;
5985 }
5986 else
5987#endif
5988 {
5989 ++off;
5990 ++col;
5991 }
5992 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02005993#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02005994 else if (wp->w_p_cole > 0 && is_concealing)
Bram Moolenaar860cae12010-06-05 23:22:07 +02005995 {
5996 --n_skip;
Bram Moolenaarac550fd2010-07-18 13:55:02 +02005997 ++vcol_off;
5998 if (n_extra > 0)
5999 vcol_off += n_extra;
Bram Moolenaar860cae12010-06-05 23:22:07 +02006000 if (wp->w_p_wrap)
6001 {
6002 /*
6003 * Special voodoo required if 'wrap' is on.
6004 *
6005 * Advance the column indicator to force the line
6006 * drawing to wrap early. This will make the line
6007 * take up the same screen space when parts are concealed,
6008 * so that cursor line computations aren't messed up.
6009 *
6010 * To avoid the fictitious advance of 'col' causing
6011 * trailing junk to be written out of the screen line
6012 * we are building, 'boguscols' keeps track of the number
6013 * of bad columns we have advanced.
6014 */
6015 if (n_extra > 0)
6016 {
6017 vcol += n_extra;
6018# ifdef FEAT_RIGHTLEFT
6019 if (wp->w_p_rl)
6020 {
6021 col -= n_extra;
6022 boguscols -= n_extra;
6023 }
6024 else
6025# endif
6026 {
6027 col += n_extra;
6028 boguscols += n_extra;
6029 }
6030 n_extra = 0;
6031 n_attr = 0;
6032 }
6033
6034
Bram Moolenaar860cae12010-06-05 23:22:07 +02006035 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
6036 {
6037 /* Need to fill two screen columns. */
Bram Moolenaara12a1612019-01-24 16:39:02 +01006038# ifdef FEAT_RIGHTLEFT
Bram Moolenaar860cae12010-06-05 23:22:07 +02006039 if (wp->w_p_rl)
6040 {
6041 --boguscols;
6042 --col;
6043 }
6044 else
Bram Moolenaara12a1612019-01-24 16:39:02 +01006045# endif
Bram Moolenaar860cae12010-06-05 23:22:07 +02006046 {
6047 ++boguscols;
6048 ++col;
6049 }
6050 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02006051
6052# ifdef FEAT_RIGHTLEFT
6053 if (wp->w_p_rl)
6054 {
6055 --boguscols;
6056 --col;
6057 }
6058 else
6059# endif
6060 {
6061 ++boguscols;
6062 ++col;
6063 }
6064 }
6065 else
6066 {
6067 if (n_extra > 0)
6068 {
6069 vcol += n_extra;
6070 n_extra = 0;
6071 n_attr = 0;
6072 }
6073 }
6074
6075 }
6076#endif /* FEAT_CONCEAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006077 else
6078 --n_skip;
6079
Bram Moolenaar64486672010-05-16 15:46:46 +02006080 /* Only advance the "vcol" when after the 'number' or 'relativenumber'
6081 * column. */
Bram Moolenaar1b636fa2009-03-18 15:28:08 +00006082 if (draw_state > WL_NR
Bram Moolenaar071d4272004-06-13 20:20:40 +00006083#ifdef FEAT_DIFF
6084 && filler_todo <= 0
6085#endif
6086 )
6087 ++vcol;
6088
Bram Moolenaar600dddc2006-03-12 22:05:10 +00006089#ifdef FEAT_SYN_HL
6090 if (vcol_save_attr >= 0)
6091 char_attr = vcol_save_attr;
6092#endif
6093
Bram Moolenaar071d4272004-06-13 20:20:40 +00006094 /* restore attributes after "predeces" in 'listchars' */
6095 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
6096 char_attr = saved_attr3;
6097
6098 /* restore attributes after last 'listchars' or 'number' char */
6099 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0)
6100 char_attr = saved_attr2;
6101
6102 /*
6103 * At end of screen line and there is more to come: Display the line
Bram Moolenaar367329b2007-08-30 11:53:22 +00006104 * so far. If there is no more to display it is caught above.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006105 */
6106 if ((
6107#ifdef FEAT_RIGHTLEFT
6108 wp->w_p_rl ? (col < 0) :
6109#endif
Bram Moolenaar02631462017-09-22 15:20:32 +02006110 (col >= wp->w_width))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006111 && (*ptr != NUL
6112#ifdef FEAT_DIFF
6113 || filler_todo > 0
6114#endif
Bram Moolenaare9d4b582011-03-22 13:29:24 +01006115 || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006116 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL)))
6117 )
6118 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006119#ifdef FEAT_CONCEAL
Bram Moolenaar53f81742017-09-22 14:35:51 +02006120 screen_line(screen_row, wp->w_wincol, col - boguscols,
Bram Moolenaar4d784b22019-05-25 19:51:39 +02006121 (int)wp->w_width, screen_line_flags);
Bram Moolenaar860cae12010-06-05 23:22:07 +02006122 boguscols = 0;
6123#else
Bram Moolenaar53f81742017-09-22 14:35:51 +02006124 screen_line(screen_row, wp->w_wincol, col,
Bram Moolenaar4d784b22019-05-25 19:51:39 +02006125 (int)wp->w_width, screen_line_flags);
Bram Moolenaar860cae12010-06-05 23:22:07 +02006126#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006127 ++row;
6128 ++screen_row;
6129
6130 /* When not wrapping and finished diff lines, or when displayed
6131 * '$' and highlighting until last column, break here. */
6132 if ((!wp->w_p_wrap
6133#ifdef FEAT_DIFF
6134 && filler_todo <= 0
6135#endif
6136 ) || lcs_eol_one == -1)
6137 break;
6138
6139 /* When the window is too narrow draw all "@" lines. */
6140 if (draw_state != WL_LINE
6141#ifdef FEAT_DIFF
6142 && filler_todo <= 0
6143#endif
6144 )
6145 {
Bram Moolenaar8ee4c012019-03-29 18:08:18 +01006146 win_draw_end(wp, '@', ' ', TRUE, row, wp->w_height, HLF_AT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006147 draw_vsep_win(wp, row);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006148 row = endrow;
6149 }
6150
6151 /* When line got too long for screen break here. */
6152 if (row == endrow)
6153 {
6154 ++row;
6155 break;
6156 }
6157
6158 if (screen_cur_row == screen_row - 1
6159#ifdef FEAT_DIFF
6160 && filler_todo <= 0
6161#endif
Bram Moolenaar02631462017-09-22 15:20:32 +02006162 && wp->w_width == Columns)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006163 {
6164 /* Remember that the line wraps, used for modeless copy. */
6165 LineWraps[screen_row - 1] = TRUE;
6166
6167 /*
6168 * Special trick to make copy/paste of wrapped lines work with
6169 * xterm/screen: write an extra character beyond the end of
6170 * the line. This will work with all terminal types
6171 * (regardless of the xn,am settings).
6172 * Only do this on a fast tty.
6173 * Only do this if the cursor is on the current line
6174 * (something has been written in it).
6175 * Don't do this for the GUI.
6176 * Don't do this for double-width characters.
6177 * Don't do this for a window not at the right screen border.
6178 */
6179 if (p_tf
6180#ifdef FEAT_GUI
6181 && !gui.in_use
6182#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006183 && !(has_mbyte
Bram Moolenaar367329b2007-08-30 11:53:22 +00006184 && ((*mb_off2cells)(LineOffset[screen_row],
6185 LineOffset[screen_row] + screen_Columns)
6186 == 2
Bram Moolenaar071d4272004-06-13 20:20:40 +00006187 || (*mb_off2cells)(LineOffset[screen_row - 1]
Bram Moolenaar367329b2007-08-30 11:53:22 +00006188 + (int)Columns - 2,
6189 LineOffset[screen_row] + screen_Columns)
Bram Moolenaara12a1612019-01-24 16:39:02 +01006190 == 2)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006191 {
6192 /* First make sure we are at the end of the screen line,
6193 * then output the same character again to let the
6194 * terminal know about the wrap. If the terminal doesn't
6195 * auto-wrap, we overwrite the character. */
Bram Moolenaar02631462017-09-22 15:20:32 +02006196 if (screen_cur_col != wp->w_width)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006197 screen_char(LineOffset[screen_row - 1]
6198 + (unsigned)Columns - 1,
6199 screen_row - 1, (int)(Columns - 1));
6200
Bram Moolenaar071d4272004-06-13 20:20:40 +00006201 /* When there is a multi-byte character, just output a
6202 * space to keep it simple. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006203 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
6204 screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006205 out_char(' ');
6206 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006207 out_char(ScreenLines[LineOffset[screen_row - 1]
6208 + (Columns - 1)]);
6209 /* force a redraw of the first char on the next line */
6210 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1;
6211 screen_start(); /* don't know where cursor is now */
6212 }
6213 }
6214
6215 col = 0;
6216 off = (unsigned)(current_ScreenLine - ScreenLines);
6217#ifdef FEAT_RIGHTLEFT
6218 if (wp->w_p_rl)
6219 {
Bram Moolenaar02631462017-09-22 15:20:32 +02006220 col = wp->w_width - 1; /* col is not used if breaking! */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006221 off += col;
6222 }
6223#endif
6224
6225 /* reset the drawing state for the start of a wrapped line */
6226 draw_state = WL_START;
6227 saved_n_extra = n_extra;
6228 saved_p_extra = p_extra;
6229 saved_c_extra = c_extra;
Bram Moolenaar83a52172019-01-16 22:41:54 +01006230 saved_c_final = c_final;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006231 saved_char_attr = char_attr;
6232 n_extra = 0;
6233 lcs_prec_todo = lcs_prec;
6234#ifdef FEAT_LINEBREAK
6235# ifdef FEAT_DIFF
6236 if (filler_todo <= 0)
6237# endif
6238 need_showbreak = TRUE;
6239#endif
6240#ifdef FEAT_DIFF
6241 --filler_todo;
6242 /* When the filler lines are actually below the last line of the
6243 * file, don't draw the line itself, break here. */
6244 if (filler_todo == 0 && wp->w_botfill)
6245 break;
6246#endif
6247 }
6248
6249 } /* for every character in the line */
6250
Bram Moolenaar600dddc2006-03-12 22:05:10 +00006251#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006252 /* After an empty line check first word for capital. */
6253 if (*skipwhite(line) == NUL)
6254 {
6255 capcol_lnum = lnum + 1;
6256 cap_col = 0;
6257 }
6258#endif
Bram Moolenaar98aefe72018-12-13 22:20:09 +01006259#ifdef FEAT_TEXT_PROP
6260 vim_free(text_props);
6261 vim_free(text_prop_idxs);
6262#endif
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006263
Bram Moolenaarb031c4e2017-01-24 20:14:48 +01006264 vim_free(p_extra_free);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006265 return row;
6266}
6267
Bram Moolenaar362e1a32006-03-06 23:29:24 +00006268/*
6269 * Return if the composing characters at "off_from" and "off_to" differ.
Bram Moolenaar70c49c12010-03-23 15:36:35 +01006270 * Only to be used when ScreenLinesUC[off_from] != 0.
Bram Moolenaar362e1a32006-03-06 23:29:24 +00006271 */
6272 static int
Bram Moolenaar05540972016-01-30 20:31:25 +01006273comp_char_differs(int off_from, int off_to)
Bram Moolenaar362e1a32006-03-06 23:29:24 +00006274{
6275 int i;
6276
6277 for (i = 0; i < Screen_mco; ++i)
6278 {
6279 if (ScreenLinesC[i][off_from] != ScreenLinesC[i][off_to])
6280 return TRUE;
6281 if (ScreenLinesC[i][off_from] == 0)
6282 break;
6283 }
6284 return FALSE;
6285}
Bram Moolenaar362e1a32006-03-06 23:29:24 +00006286
Bram Moolenaar071d4272004-06-13 20:20:40 +00006287/*
6288 * Check whether the given character needs redrawing:
6289 * - the (first byte of the) character is different
6290 * - the attributes are different
6291 * - the character is multi-byte and the next byte is different
Bram Moolenaar88f3d3a2008-06-21 12:14:30 +00006292 * - the character is two cells wide and the second cell differs.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006293 */
6294 static int
Bram Moolenaar05540972016-01-30 20:31:25 +01006295char_needs_redraw(int off_from, int off_to, int cols)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006296{
6297 if (cols > 0
6298 && ((ScreenLines[off_from] != ScreenLines[off_to]
6299 || ScreenAttrs[off_from] != ScreenAttrs[off_to])
Bram Moolenaar071d4272004-06-13 20:20:40 +00006300 || (enc_dbcs != 0
6301 && MB_BYTE2LEN(ScreenLines[off_from]) > 1
6302 && (enc_dbcs == DBCS_JPNU && ScreenLines[off_from] == 0x8e
6303 ? ScreenLines2[off_from] != ScreenLines2[off_to]
6304 : (cols > 1 && ScreenLines[off_from + 1]
6305 != ScreenLines[off_to + 1])))
6306 || (enc_utf8
6307 && (ScreenLinesUC[off_from] != ScreenLinesUC[off_to]
6308 || (ScreenLinesUC[off_from] != 0
Bram Moolenaar88f3d3a2008-06-21 12:14:30 +00006309 && comp_char_differs(off_from, off_to))
Bram Moolenaar451cf632012-08-23 18:58:14 +02006310 || ((*mb_off2cells)(off_from, off_from + cols) > 1
6311 && ScreenLines[off_from + 1]
Bram Moolenaara12a1612019-01-24 16:39:02 +01006312 != ScreenLines[off_to + 1])))))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006313 return TRUE;
6314 return FALSE;
6315}
6316
Bram Moolenaarcb8bbe92017-07-16 13:48:22 +02006317#if defined(FEAT_TERMINAL) || defined(PROTO)
6318/*
6319 * Return the index in ScreenLines[] for the current screen line.
6320 */
6321 int
6322screen_get_current_line_off()
6323{
6324 return (int)(current_ScreenLine - ScreenLines);
6325}
6326#endif
6327
Bram Moolenaar071d4272004-06-13 20:20:40 +00006328/*
6329 * Move one "cooked" screen line to the screen, but only the characters that
6330 * have actually changed. Handle insert/delete character.
6331 * "coloff" gives the first column on the screen for this line.
6332 * "endcol" gives the columns where valid characters are.
6333 * "clear_width" is the width of the window. It's > 0 if the rest of the line
6334 * needs to be cleared, negative otherwise.
Bram Moolenaar4d784b22019-05-25 19:51:39 +02006335 * "flags" can have bits:
6336 * SLF_POPUP popup window
6337 * SLF_RIGHTLEFT rightleft window:
Bram Moolenaar071d4272004-06-13 20:20:40 +00006338 * When TRUE and "clear_width" > 0, clear columns 0 to "endcol"
6339 * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width"
6340 */
Bram Moolenaarcb8bbe92017-07-16 13:48:22 +02006341 void
Bram Moolenaar05540972016-01-30 20:31:25 +01006342screen_line(
6343 int row,
6344 int coloff,
6345 int endcol,
Bram Moolenaarcb8bbe92017-07-16 13:48:22 +02006346 int clear_width,
Bram Moolenaar4d784b22019-05-25 19:51:39 +02006347 int flags UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006348{
6349 unsigned off_from;
6350 unsigned off_to;
Bram Moolenaar367329b2007-08-30 11:53:22 +00006351 unsigned max_off_from;
6352 unsigned max_off_to;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006353 int col = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006354 int hl;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006355 int force = FALSE; /* force update rest of the line */
6356 int redraw_this /* bool: does character need redraw? */
6357#ifdef FEAT_GUI
6358 = TRUE /* For GUI when while-loop empty */
6359#endif
6360 ;
6361 int redraw_next; /* redraw_this for next character */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006362 int clear_next = FALSE;
6363 int char_cells; /* 1: normal char */
6364 /* 2: occupies two display cells */
6365# define CHAR_CELLS char_cells
Bram Moolenaar071d4272004-06-13 20:20:40 +00006366
Bram Moolenaar5ad15df2012-03-16 19:07:58 +01006367 /* Check for illegal row and col, just in case. */
6368 if (row >= Rows)
6369 row = Rows - 1;
6370 if (endcol > Columns)
6371 endcol = Columns;
6372
Bram Moolenaar071d4272004-06-13 20:20:40 +00006373# ifdef FEAT_CLIPBOARD
6374 clip_may_clear_selection(row, row);
6375# endif
6376
6377 off_from = (unsigned)(current_ScreenLine - ScreenLines);
6378 off_to = LineOffset[row] + coloff;
Bram Moolenaar367329b2007-08-30 11:53:22 +00006379 max_off_from = off_from + screen_Columns;
6380 max_off_to = LineOffset[row] + screen_Columns;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006381
6382#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d784b22019-05-25 19:51:39 +02006383 if (flags & SLF_RIGHTLEFT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006384 {
6385 /* Clear rest first, because it's left of the text. */
6386 if (clear_width > 0)
6387 {
6388 while (col <= endcol && ScreenLines[off_to] == ' '
6389 && ScreenAttrs[off_to] == 0
Bram Moolenaara12a1612019-01-24 16:39:02 +01006390 && (!enc_utf8 || ScreenLinesUC[off_to] == 0))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006391 {
6392 ++off_to;
6393 ++col;
6394 }
6395 if (col <= endcol)
6396 screen_fill(row, row + 1, col + coloff,
6397 endcol + coloff + 1, ' ', ' ', 0);
6398 }
6399 col = endcol + 1;
6400 off_to = LineOffset[row] + col + coloff;
6401 off_from += col;
6402 endcol = (clear_width > 0 ? clear_width : -clear_width);
6403 }
6404#endif /* FEAT_RIGHTLEFT */
6405
6406 redraw_next = char_needs_redraw(off_from, off_to, endcol - col);
6407
6408 while (col < endcol)
6409 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006410 if (has_mbyte && (col + 1 < endcol))
Bram Moolenaar367329b2007-08-30 11:53:22 +00006411 char_cells = (*mb_off2cells)(off_from, max_off_from);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006412 else
6413 char_cells = 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006414
6415 redraw_this = redraw_next;
6416 redraw_next = force || char_needs_redraw(off_from + CHAR_CELLS,
6417 off_to + CHAR_CELLS, endcol - col - CHAR_CELLS);
6418
6419#ifdef FEAT_GUI
6420 /* If the next character was bold, then redraw the current character to
6421 * remove any pixels that might have spilt over into us. This only
6422 * happens in the GUI.
6423 */
6424 if (redraw_next && gui.in_use)
6425 {
6426 hl = ScreenAttrs[off_to + CHAR_CELLS];
Bram Moolenaar600dddc2006-03-12 22:05:10 +00006427 if (hl > HL_ALL)
6428 hl = syn_attr2attr(hl);
6429 if (hl & HL_BOLD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006430 redraw_this = TRUE;
6431 }
6432#endif
6433
6434 if (redraw_this)
6435 {
6436 /*
6437 * Special handling when 'xs' termcap flag set (hpterm):
6438 * Attributes for characters are stored at the position where the
6439 * cursor is when writing the highlighting code. The
6440 * start-highlighting code must be written with the cursor on the
6441 * first highlighted character. The stop-highlighting code must
6442 * be written with the cursor just after the last highlighted
6443 * character.
Bram Moolenaarc4568ab2018-11-16 16:21:05 +01006444 * Overwriting a character doesn't remove its highlighting. Need
Bram Moolenaar071d4272004-06-13 20:20:40 +00006445 * to clear the rest of the line, and force redrawing it
6446 * completely.
6447 */
6448 if ( p_wiv
6449 && !force
6450#ifdef FEAT_GUI
6451 && !gui.in_use
6452#endif
6453 && ScreenAttrs[off_to] != 0
6454 && ScreenAttrs[off_from] != ScreenAttrs[off_to])
6455 {
6456 /*
6457 * Need to remove highlighting attributes here.
6458 */
6459 windgoto(row, col + coloff);
6460 out_str(T_CE); /* clear rest of this screen line */
6461 screen_start(); /* don't know where cursor is now */
6462 force = TRUE; /* force redraw of rest of the line */
6463 redraw_next = TRUE; /* or else next char would miss out */
6464
6465 /*
6466 * If the previous character was highlighted, need to stop
6467 * highlighting at this character.
6468 */
6469 if (col + coloff > 0 && ScreenAttrs[off_to - 1] != 0)
6470 {
6471 screen_attr = ScreenAttrs[off_to - 1];
6472 term_windgoto(row, col + coloff);
6473 screen_stop_highlight();
6474 }
6475 else
6476 screen_attr = 0; /* highlighting has stopped */
6477 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006478 if (enc_dbcs != 0)
6479 {
6480 /* Check if overwriting a double-byte with a single-byte or
6481 * the other way around requires another character to be
6482 * redrawn. For UTF-8 this isn't needed, because comparing
6483 * ScreenLinesUC[] is sufficient. */
6484 if (char_cells == 1
6485 && col + 1 < endcol
Bram Moolenaar367329b2007-08-30 11:53:22 +00006486 && (*mb_off2cells)(off_to, max_off_to) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006487 {
6488 /* Writing a single-cell character over a double-cell
6489 * character: need to redraw the next cell. */
6490 ScreenLines[off_to + 1] = 0;
6491 redraw_next = TRUE;
6492 }
6493 else if (char_cells == 2
6494 && col + 2 < endcol
Bram Moolenaar367329b2007-08-30 11:53:22 +00006495 && (*mb_off2cells)(off_to, max_off_to) == 1
6496 && (*mb_off2cells)(off_to + 1, max_off_to) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006497 {
6498 /* Writing the second half of a double-cell character over
6499 * a double-cell character: need to redraw the second
6500 * cell. */
6501 ScreenLines[off_to + 2] = 0;
6502 redraw_next = TRUE;
6503 }
6504
6505 if (enc_dbcs == DBCS_JPNU)
6506 ScreenLines2[off_to] = ScreenLines2[off_from];
6507 }
6508 /* When writing a single-width character over a double-width
6509 * character and at the end of the redrawn text, need to clear out
6510 * the right halve of the old character.
6511 * Also required when writing the right halve of a double-width
6512 * char over the left halve of an existing one. */
6513 if (has_mbyte && col + char_cells == endcol
6514 && ((char_cells == 1
Bram Moolenaar367329b2007-08-30 11:53:22 +00006515 && (*mb_off2cells)(off_to, max_off_to) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006516 || (char_cells == 2
Bram Moolenaar367329b2007-08-30 11:53:22 +00006517 && (*mb_off2cells)(off_to, max_off_to) == 1
6518 && (*mb_off2cells)(off_to + 1, max_off_to) > 1)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006519 clear_next = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006520
6521 ScreenLines[off_to] = ScreenLines[off_from];
Bram Moolenaar071d4272004-06-13 20:20:40 +00006522 if (enc_utf8)
6523 {
6524 ScreenLinesUC[off_to] = ScreenLinesUC[off_from];
6525 if (ScreenLinesUC[off_from] != 0)
6526 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00006527 int i;
6528
6529 for (i = 0; i < Screen_mco; ++i)
6530 ScreenLinesC[i][off_to] = ScreenLinesC[i][off_from];
Bram Moolenaar071d4272004-06-13 20:20:40 +00006531 }
6532 }
6533 if (char_cells == 2)
6534 ScreenLines[off_to + 1] = ScreenLines[off_from + 1];
Bram Moolenaar071d4272004-06-13 20:20:40 +00006535
6536#if defined(FEAT_GUI) || defined(UNIX)
Bram Moolenaar2bea2912009-03-11 16:58:40 +00006537 /* The bold trick makes a single column of pixels appear in the
6538 * next character. When a bold character is removed, the next
Bram Moolenaar071d4272004-06-13 20:20:40 +00006539 * character should be redrawn too. This happens for our own GUI
6540 * and for some xterms. */
6541 if (
6542# ifdef FEAT_GUI
6543 gui.in_use
6544# endif
6545# if defined(FEAT_GUI) && defined(UNIX)
6546 ||
6547# endif
6548# ifdef UNIX
6549 term_is_xterm
6550# endif
6551 )
6552 {
6553 hl = ScreenAttrs[off_to];
Bram Moolenaar600dddc2006-03-12 22:05:10 +00006554 if (hl > HL_ALL)
6555 hl = syn_attr2attr(hl);
6556 if (hl & HL_BOLD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006557 redraw_next = TRUE;
6558 }
6559#endif
6560 ScreenAttrs[off_to] = ScreenAttrs[off_from];
Bram Moolenaara12a1612019-01-24 16:39:02 +01006561
Bram Moolenaar910f66f2006-04-05 20:41:53 +00006562 /* For simplicity set the attributes of second half of a
6563 * double-wide character equal to the first half. */
6564 if (char_cells == 2)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006565 ScreenAttrs[off_to + 1] = ScreenAttrs[off_from];
Bram Moolenaar910f66f2006-04-05 20:41:53 +00006566
6567 if (enc_dbcs != 0 && char_cells == 2)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006568 screen_char_2(off_to, row, col + coloff);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006569 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006570 screen_char(off_to, row, col + coloff);
6571 }
6572 else if ( p_wiv
6573#ifdef FEAT_GUI
6574 && !gui.in_use
6575#endif
6576 && col + coloff > 0)
6577 {
6578 if (ScreenAttrs[off_to] == ScreenAttrs[off_to - 1])
6579 {
6580 /*
6581 * Don't output stop-highlight when moving the cursor, it will
6582 * stop the highlighting when it should continue.
6583 */
6584 screen_attr = 0;
6585 }
6586 else if (screen_attr != 0)
6587 screen_stop_highlight();
6588 }
6589
6590 off_to += CHAR_CELLS;
6591 off_from += CHAR_CELLS;
6592 col += CHAR_CELLS;
6593 }
6594
Bram Moolenaar071d4272004-06-13 20:20:40 +00006595 if (clear_next)
6596 {
6597 /* Clear the second half of a double-wide character of which the left
6598 * half was overwritten with a single-wide character. */
6599 ScreenLines[off_to] = ' ';
6600 if (enc_utf8)
6601 ScreenLinesUC[off_to] = 0;
6602 screen_char(off_to, row, col + coloff);
6603 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006604
6605 if (clear_width > 0
6606#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d784b22019-05-25 19:51:39 +02006607 && !(flags & SLF_RIGHTLEFT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006608#endif
6609 )
6610 {
6611#ifdef FEAT_GUI
6612 int startCol = col;
6613#endif
6614
6615 /* blank out the rest of the line */
6616 while (col < clear_width && ScreenLines[off_to] == ' '
6617 && ScreenAttrs[off_to] == 0
Bram Moolenaara12a1612019-01-24 16:39:02 +01006618 && (!enc_utf8 || ScreenLinesUC[off_to] == 0))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006619 {
6620 ++off_to;
6621 ++col;
6622 }
6623 if (col < clear_width)
6624 {
6625#ifdef FEAT_GUI
6626 /*
6627 * In the GUI, clearing the rest of the line may leave pixels
6628 * behind if the first character cleared was bold. Some bold
6629 * fonts spill over the left. In this case we redraw the previous
6630 * character too. If we didn't skip any blanks above, then we
6631 * only redraw if the character wasn't already redrawn anyway.
6632 */
Bram Moolenaar9c697322006-10-09 20:11:17 +00006633 if (gui.in_use && (col > startCol || !redraw_this))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006634 {
6635 hl = ScreenAttrs[off_to];
6636 if (hl > HL_ALL || (hl & HL_BOLD))
Bram Moolenaar9c697322006-10-09 20:11:17 +00006637 {
6638 int prev_cells = 1;
Bram Moolenaara12a1612019-01-24 16:39:02 +01006639
Bram Moolenaar9c697322006-10-09 20:11:17 +00006640 if (enc_utf8)
6641 /* for utf-8, ScreenLines[char_offset + 1] == 0 means
6642 * that its width is 2. */
6643 prev_cells = ScreenLines[off_to - 1] == 0 ? 2 : 1;
6644 else if (enc_dbcs != 0)
6645 {
6646 /* find previous character by counting from first
6647 * column and get its width. */
6648 unsigned off = LineOffset[row];
Bram Moolenaar367329b2007-08-30 11:53:22 +00006649 unsigned max_off = LineOffset[row] + screen_Columns;
Bram Moolenaar9c697322006-10-09 20:11:17 +00006650
6651 while (off < off_to)
6652 {
Bram Moolenaar367329b2007-08-30 11:53:22 +00006653 prev_cells = (*mb_off2cells)(off, max_off);
Bram Moolenaar9c697322006-10-09 20:11:17 +00006654 off += prev_cells;
6655 }
6656 }
6657
6658 if (enc_dbcs != 0 && prev_cells > 1)
6659 screen_char_2(off_to - prev_cells, row,
6660 col + coloff - prev_cells);
6661 else
Bram Moolenaar9c697322006-10-09 20:11:17 +00006662 screen_char(off_to - prev_cells, row,
6663 col + coloff - prev_cells);
6664 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006665 }
6666#endif
6667 screen_fill(row, row + 1, col + coloff, clear_width + coloff,
6668 ' ', ' ', 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006669 off_to += clear_width - col;
6670 col = clear_width;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006671 }
6672 }
6673
Bram Moolenaar4d784b22019-05-25 19:51:39 +02006674 if (clear_width > 0
6675#ifdef FEAT_TEXT_PROP
6676 && !(flags & SLF_POPUP) // no separator for popup window
6677#endif
6678 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00006679 {
Bram Moolenaar4d784b22019-05-25 19:51:39 +02006680 // For a window that has a right neighbor, draw the separator char
6681 // right of the window contents.
6682 if (coloff + col < Columns)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006683 {
6684 int c;
6685
6686 c = fillchar_vsep(&hl);
Bram Moolenaarc60c4f62015-01-07 19:04:28 +01006687 if (ScreenLines[off_to] != (schar_T)c
Bram Moolenaar362e1a32006-03-06 23:29:24 +00006688 || (enc_utf8 && (int)ScreenLinesUC[off_to]
6689 != (c >= 0x80 ? c : 0))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006690 || ScreenAttrs[off_to] != hl)
6691 {
6692 ScreenLines[off_to] = c;
6693 ScreenAttrs[off_to] = hl;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006694 if (enc_utf8)
6695 {
6696 if (c >= 0x80)
6697 {
6698 ScreenLinesUC[off_to] = c;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00006699 ScreenLinesC[0][off_to] = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006700 }
6701 else
6702 ScreenLinesUC[off_to] = 0;
6703 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006704 screen_char(off_to, row, col + coloff);
6705 }
6706 }
6707 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006708 LineWraps[row] = FALSE;
6709 }
6710}
6711
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00006712#if defined(FEAT_RIGHTLEFT) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006713/*
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00006714 * Mirror text "str" for right-left displaying.
6715 * Only works for single-byte characters (e.g., numbers).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006716 */
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00006717 void
Bram Moolenaar05540972016-01-30 20:31:25 +01006718rl_mirror(char_u *str)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006719{
6720 char_u *p1, *p2;
6721 int t;
6722
6723 for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; ++p1, --p2)
6724 {
6725 t = *p1;
6726 *p1 = *p2;
6727 *p2 = t;
6728 }
6729}
6730#endif
6731
Bram Moolenaar071d4272004-06-13 20:20:40 +00006732/*
6733 * mark all status lines for redraw; used after first :cd
6734 */
6735 void
Bram Moolenaar05540972016-01-30 20:31:25 +01006736status_redraw_all(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006737{
6738 win_T *wp;
6739
Bram Moolenaar29323592016-07-24 22:04:11 +02006740 FOR_ALL_WINDOWS(wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006741 if (wp->w_status_height)
6742 {
6743 wp->w_redr_status = TRUE;
6744 redraw_later(VALID);
6745 }
6746}
6747
6748/*
6749 * mark all status lines of the current buffer for redraw
6750 */
6751 void
Bram Moolenaar05540972016-01-30 20:31:25 +01006752status_redraw_curbuf(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006753{
6754 win_T *wp;
6755
Bram Moolenaar29323592016-07-24 22:04:11 +02006756 FOR_ALL_WINDOWS(wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006757 if (wp->w_status_height != 0 && wp->w_buffer == curbuf)
6758 {
6759 wp->w_redr_status = TRUE;
6760 redraw_later(VALID);
6761 }
6762}
6763
6764/*
6765 * Redraw all status lines that need to be redrawn.
6766 */
6767 void
Bram Moolenaar05540972016-01-30 20:31:25 +01006768redraw_statuslines(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006769{
6770 win_T *wp;
6771
Bram Moolenaar29323592016-07-24 22:04:11 +02006772 FOR_ALL_WINDOWS(wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006773 if (wp->w_redr_status)
Bram Moolenaar6ba3ec12018-06-16 15:32:38 +02006774 win_redr_status(wp, FALSE);
Bram Moolenaar997fb4b2006-02-17 21:53:23 +00006775 if (redraw_tabline)
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00006776 draw_tabline();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006777}
Bram Moolenaar071d4272004-06-13 20:20:40 +00006778
Bram Moolenaar4033c552017-09-16 20:54:51 +02006779#if defined(FEAT_WILDMENU) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006780/*
6781 * Redraw all status lines at the bottom of frame "frp".
6782 */
6783 void
Bram Moolenaar05540972016-01-30 20:31:25 +01006784win_redraw_last_status(frame_T *frp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006785{
6786 if (frp->fr_layout == FR_LEAF)
6787 frp->fr_win->w_redr_status = TRUE;
6788 else if (frp->fr_layout == FR_ROW)
6789 {
Bram Moolenaar3d1491e2018-12-22 17:07:50 +01006790 FOR_ALL_FRAMES(frp, frp->fr_child)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006791 win_redraw_last_status(frp);
6792 }
6793 else /* frp->fr_layout == FR_COL */
6794 {
6795 frp = frp->fr_child;
6796 while (frp->fr_next != NULL)
6797 frp = frp->fr_next;
6798 win_redraw_last_status(frp);
6799 }
6800}
6801#endif
6802
Bram Moolenaar071d4272004-06-13 20:20:40 +00006803/*
6804 * Draw the verticap separator right of window "wp" starting with line "row".
6805 */
6806 static void
Bram Moolenaar05540972016-01-30 20:31:25 +01006807draw_vsep_win(win_T *wp, int row)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006808{
6809 int hl;
6810 int c;
6811
6812 if (wp->w_vsep_width)
6813 {
6814 /* draw the vertical separator right of this window */
6815 c = fillchar_vsep(&hl);
6816 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height,
6817 W_ENDCOL(wp), W_ENDCOL(wp) + 1,
6818 c, ' ', hl);
6819 }
6820}
Bram Moolenaar071d4272004-06-13 20:20:40 +00006821
6822#ifdef FEAT_WILDMENU
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01006823static int skip_status_match_char(expand_T *xp, char_u *s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006824
6825/*
Bram Moolenaar367329b2007-08-30 11:53:22 +00006826 * Get the length of an item as it will be shown in the status line.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006827 */
6828 static int
Bram Moolenaar05540972016-01-30 20:31:25 +01006829status_match_len(expand_T *xp, char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006830{
6831 int len = 0;
6832
6833#ifdef FEAT_MENU
6834 int emenu = (xp->xp_context == EXPAND_MENUS
6835 || xp->xp_context == EXPAND_MENUNAMES);
6836
6837 /* Check for menu separators - replace with '|'. */
6838 if (emenu && menu_is_separator(s))
6839 return 1;
6840#endif
6841
6842 while (*s != NUL)
6843 {
Bram Moolenaar7693ec62008-07-24 18:29:37 +00006844 s += skip_status_match_char(xp, s);
Bram Moolenaar81695252004-12-29 20:58:21 +00006845 len += ptr2cells(s);
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006846 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006847 }
6848
6849 return len;
6850}
6851
6852/*
Bram Moolenaar7693ec62008-07-24 18:29:37 +00006853 * Return the number of characters that should be skipped in a status match.
Bram Moolenaar35c54e52005-05-20 21:25:31 +00006854 * These are backslashes used for escaping. Do show backslashes in help tags.
6855 */
6856 static int
Bram Moolenaar05540972016-01-30 20:31:25 +01006857skip_status_match_char(expand_T *xp, char_u *s)
Bram Moolenaar35c54e52005-05-20 21:25:31 +00006858{
Bram Moolenaar7693ec62008-07-24 18:29:37 +00006859 if ((rem_backslash(s) && xp->xp_context != EXPAND_HELP)
Bram Moolenaar35c54e52005-05-20 21:25:31 +00006860#ifdef FEAT_MENU
6861 || ((xp->xp_context == EXPAND_MENUS
6862 || xp->xp_context == EXPAND_MENUNAMES)
6863 && (s[0] == '\t' || (s[0] == '\\' && s[1] != NUL)))
6864#endif
Bram Moolenaar7693ec62008-07-24 18:29:37 +00006865 )
6866 {
6867#ifndef BACKSLASH_IN_FILENAME
6868 if (xp->xp_shell && csh_like_shell() && s[1] == '\\' && s[2] == '!')
6869 return 2;
6870#endif
6871 return 1;
6872 }
6873 return 0;
Bram Moolenaar35c54e52005-05-20 21:25:31 +00006874}
6875
6876/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006877 * Show wildchar matches in the status line.
6878 * Show at least the "match" item.
6879 * We start at item 'first_match' in the list and show all matches that fit.
6880 *
6881 * If inversion is possible we use it. Else '=' characters are used.
6882 */
6883 void
Bram Moolenaar05540972016-01-30 20:31:25 +01006884win_redr_status_matches(
6885 expand_T *xp,
6886 int num_matches,
6887 char_u **matches, /* list of matches */
6888 int match,
6889 int showtail)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006890{
6891#define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m])
6892 int row;
6893 char_u *buf;
6894 int len;
Bram Moolenaar367329b2007-08-30 11:53:22 +00006895 int clen; /* length in screen cells */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006896 int fillchar;
6897 int attr;
6898 int i;
6899 int highlight = TRUE;
6900 char_u *selstart = NULL;
6901 int selstart_col = 0;
6902 char_u *selend = NULL;
6903 static int first_match = 0;
6904 int add_left = FALSE;
6905 char_u *s;
6906#ifdef FEAT_MENU
6907 int emenu;
6908#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006909 int l;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006910
6911 if (matches == NULL) /* interrupted completion? */
6912 return;
6913
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006914 if (has_mbyte)
Bram Moolenaar964b3742019-05-24 18:54:09 +02006915 buf = alloc(Columns * MB_MAXBYTES + 1);
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006916 else
Bram Moolenaar964b3742019-05-24 18:54:09 +02006917 buf = alloc(Columns + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006918 if (buf == NULL)
6919 return;
6920
6921 if (match == -1) /* don't show match but original text */
6922 {
6923 match = 0;
6924 highlight = FALSE;
6925 }
6926 /* count 1 for the ending ">" */
6927 clen = status_match_len(xp, L_MATCH(match)) + 3;
6928 if (match == 0)
6929 first_match = 0;
6930 else if (match < first_match)
6931 {
6932 /* jumping left, as far as we can go */
6933 first_match = match;
6934 add_left = TRUE;
6935 }
6936 else
6937 {
6938 /* check if match fits on the screen */
6939 for (i = first_match; i < match; ++i)
6940 clen += status_match_len(xp, L_MATCH(i)) + 2;
6941 if (first_match > 0)
6942 clen += 2;
6943 /* jumping right, put match at the left */
6944 if ((long)clen > Columns)
6945 {
6946 first_match = match;
6947 /* if showing the last match, we can add some on the left */
6948 clen = 2;
6949 for (i = match; i < num_matches; ++i)
6950 {
6951 clen += status_match_len(xp, L_MATCH(i)) + 2;
6952 if ((long)clen >= Columns)
6953 break;
6954 }
6955 if (i == num_matches)
6956 add_left = TRUE;
6957 }
6958 }
6959 if (add_left)
6960 while (first_match > 0)
6961 {
6962 clen += status_match_len(xp, L_MATCH(first_match - 1)) + 2;
6963 if ((long)clen >= Columns)
6964 break;
6965 --first_match;
6966 }
6967
Bram Moolenaar3633cf52017-07-31 22:29:35 +02006968 fillchar = fillchar_status(&attr, curwin);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006969
6970 if (first_match == 0)
6971 {
6972 *buf = NUL;
6973 len = 0;
6974 }
6975 else
6976 {
6977 STRCPY(buf, "< ");
6978 len = 2;
6979 }
6980 clen = len;
6981
6982 i = first_match;
6983 while ((long)(clen + status_match_len(xp, L_MATCH(i)) + 2) < Columns)
6984 {
6985 if (i == match)
6986 {
6987 selstart = buf + len;
6988 selstart_col = clen;
6989 }
6990
6991 s = L_MATCH(i);
6992 /* Check for menu separators - replace with '|' */
6993#ifdef FEAT_MENU
6994 emenu = (xp->xp_context == EXPAND_MENUS
6995 || xp->xp_context == EXPAND_MENUNAMES);
6996 if (emenu && menu_is_separator(s))
6997 {
6998 STRCPY(buf + len, transchar('|'));
6999 l = (int)STRLEN(buf + len);
7000 len += l;
7001 clen += l;
7002 }
7003 else
7004#endif
7005 for ( ; *s != NUL; ++s)
7006 {
Bram Moolenaar7693ec62008-07-24 18:29:37 +00007007 s += skip_status_match_char(xp, s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007008 clen += ptr2cells(s);
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00007009 if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007010 {
7011 STRNCPY(buf + len, s, l);
7012 s += l - 1;
7013 len += l;
7014 }
7015 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00007016 {
7017 STRCPY(buf + len, transchar_byte(*s));
7018 len += (int)STRLEN(buf + len);
7019 }
7020 }
7021 if (i == match)
7022 selend = buf + len;
7023
7024 *(buf + len++) = ' ';
7025 *(buf + len++) = ' ';
7026 clen += 2;
7027 if (++i == num_matches)
7028 break;
7029 }
7030
7031 if (i != num_matches)
7032 {
7033 *(buf + len++) = '>';
7034 ++clen;
7035 }
7036
7037 buf[len] = NUL;
7038
7039 row = cmdline_row - 1;
7040 if (row >= 0)
7041 {
7042 if (wild_menu_showing == 0)
7043 {
7044 if (msg_scrolled > 0)
7045 {
7046 /* Put the wildmenu just above the command line. If there is
7047 * no room, scroll the screen one line up. */
7048 if (cmdline_row == Rows - 1)
7049 {
Bram Moolenaarcfce7172017-08-17 20:31:48 +02007050 screen_del_lines(0, 0, 1, (int)Rows, TRUE, 0, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007051 ++msg_scrolled;
7052 }
7053 else
7054 {
7055 ++cmdline_row;
7056 ++row;
7057 }
7058 wild_menu_showing = WM_SCROLLED;
7059 }
7060 else
7061 {
7062 /* Create status line if needed by setting 'laststatus' to 2.
7063 * Set 'winminheight' to zero to avoid that the window is
7064 * resized. */
7065 if (lastwin->w_status_height == 0)
7066 {
7067 save_p_ls = p_ls;
7068 save_p_wmh = p_wmh;
7069 p_ls = 2;
7070 p_wmh = 0;
7071 last_status(FALSE);
7072 }
7073 wild_menu_showing = WM_SHOWN;
7074 }
7075 }
7076
7077 screen_puts(buf, row, 0, attr);
7078 if (selstart != NULL && highlight)
7079 {
7080 *selend = NUL;
Bram Moolenaar8820b482017-03-16 17:23:31 +01007081 screen_puts(selstart, row, selstart_col, HL_ATTR(HLF_WM));
Bram Moolenaar071d4272004-06-13 20:20:40 +00007082 }
7083
7084 screen_fill(row, row + 1, clen, (int)Columns, fillchar, fillchar, attr);
7085 }
7086
Bram Moolenaar071d4272004-06-13 20:20:40 +00007087 win_redraw_last_status(topframe);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007088 vim_free(buf);
7089}
7090#endif
7091
Bram Moolenaar071d4272004-06-13 20:20:40 +00007092/*
7093 * Redraw the status line of window wp.
7094 *
7095 * If inversion is possible we use it. Else '=' characters are used.
Bram Moolenaar6ba3ec12018-06-16 15:32:38 +02007096 * If "ignore_pum" is TRUE, also redraw statusline when the popup menu is
7097 * displayed.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007098 */
Bram Moolenaar6ba3ec12018-06-16 15:32:38 +02007099 static void
Bram Moolenaar829adb72018-06-24 19:24:03 +02007100win_redr_status(win_T *wp, int ignore_pum UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007101{
7102 int row;
7103 char_u *p;
7104 int len;
7105 int fillchar;
7106 int attr;
7107 int this_ru_col;
Bram Moolenaaradb09c22009-06-16 15:22:12 +00007108 static int busy = FALSE;
7109
7110 /* It's possible to get here recursively when 'statusline' (indirectly)
7111 * invokes ":redrawstatus". Simply ignore the call then. */
7112 if (busy)
7113 return;
7114 busy = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007115
7116 wp->w_redr_status = FALSE;
7117 if (wp->w_status_height == 0)
7118 {
7119 /* no status line, can only be last window */
7120 redraw_cmdline = TRUE;
7121 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007122 else if (!redrawing()
7123#ifdef FEAT_INS_EXPAND
Bram Moolenaar6ba3ec12018-06-16 15:32:38 +02007124 // don't update status line when popup menu is visible and may be
7125 // drawn over it, unless it will be redrawn later
7126 || (!ignore_pum && pum_visible())
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007127#endif
7128 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00007129 {
7130 /* Don't redraw right now, do it later. */
7131 wp->w_redr_status = TRUE;
7132 }
7133#ifdef FEAT_STL_OPT
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007134 else if (*p_stl != NUL || *wp->w_p_stl != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007135 {
7136 /* redraw custom status line */
Bram Moolenaar362f3562009-11-03 16:20:34 +00007137 redraw_custom_statusline(wp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007138 }
7139#endif
7140 else
7141 {
Bram Moolenaar3633cf52017-07-31 22:29:35 +02007142 fillchar = fillchar_status(&attr, wp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007143
Bram Moolenaar32466aa2006-02-24 23:53:04 +00007144 get_trans_bufname(wp->w_buffer);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007145 p = NameBuff;
7146 len = (int)STRLEN(p);
7147
Bram Moolenaard85f2712017-07-28 21:51:57 +02007148 if (bt_help(wp->w_buffer)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007149#ifdef FEAT_QUICKFIX
7150 || wp->w_p_pvw
7151#endif
7152 || bufIsChanged(wp->w_buffer)
7153 || wp->w_buffer->b_p_ro)
7154 *(p + len++) = ' ';
Bram Moolenaard85f2712017-07-28 21:51:57 +02007155 if (bt_help(wp->w_buffer))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007156 {
Bram Moolenaar899dddf2006-03-26 21:06:50 +00007157 STRCPY(p + len, _("[Help]"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00007158 len += (int)STRLEN(p + len);
7159 }
7160#ifdef FEAT_QUICKFIX
7161 if (wp->w_p_pvw)
7162 {
7163 STRCPY(p + len, _("[Preview]"));
7164 len += (int)STRLEN(p + len);
7165 }
7166#endif
Bram Moolenaar086d5352017-08-05 18:19:55 +02007167 if (bufIsChanged(wp->w_buffer)
7168#ifdef FEAT_TERMINAL
7169 && !bt_terminal(wp->w_buffer)
7170#endif
7171 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00007172 {
7173 STRCPY(p + len, "[+]");
7174 len += 3;
7175 }
7176 if (wp->w_buffer->b_p_ro)
7177 {
Bram Moolenaar23584032013-06-07 20:17:11 +02007178 STRCPY(p + len, _("[RO]"));
Bram Moolenaar3457d292017-02-23 14:55:59 +01007179 len += (int)STRLEN(p + len);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007180 }
7181
Bram Moolenaar02631462017-09-22 15:20:32 +02007182 this_ru_col = ru_col - (Columns - wp->w_width);
7183 if (this_ru_col < (wp->w_width + 1) / 2)
7184 this_ru_col = (wp->w_width + 1) / 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007185 if (this_ru_col <= 1)
7186 {
7187 p = (char_u *)"<"; /* No room for file name! */
7188 len = 1;
7189 }
Bram Moolenaara12a1612019-01-24 16:39:02 +01007190 else if (has_mbyte)
7191 {
7192 int clen = 0, i;
7193
7194 /* Count total number of display cells. */
7195 clen = mb_string2cells(p, -1);
7196
7197 /* Find first character that will fit.
7198 * Going from start to end is much faster for DBCS. */
7199 for (i = 0; p[i] != NUL && clen >= this_ru_col - 1;
7200 i += (*mb_ptr2len)(p + i))
7201 clen -= (*mb_ptr2cells)(p + i);
7202 len = clen;
7203 if (i > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007204 {
Bram Moolenaara12a1612019-01-24 16:39:02 +01007205 p = p + i - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007206 *p = '<';
Bram Moolenaara12a1612019-01-24 16:39:02 +01007207 ++len;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007208 }
7209
Bram Moolenaara12a1612019-01-24 16:39:02 +01007210 }
7211 else if (len > this_ru_col - 1)
7212 {
7213 p += len - (this_ru_col - 1);
7214 *p = '<';
7215 len = this_ru_col - 1;
7216 }
7217
Bram Moolenaar071d4272004-06-13 20:20:40 +00007218 row = W_WINROW(wp) + wp->w_height;
Bram Moolenaar53f81742017-09-22 14:35:51 +02007219 screen_puts(p, row, wp->w_wincol, attr);
7220 screen_fill(row, row + 1, len + wp->w_wincol,
7221 this_ru_col + wp->w_wincol, fillchar, fillchar, attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007222
Bram Moolenaar73ac0c42016-07-24 16:17:59 +02007223 if (get_keymap_str(wp, (char_u *)"<%s>", NameBuff, MAXPATHL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007224 && (int)(this_ru_col - len) > (int)(STRLEN(NameBuff) + 1))
7225 screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff)
Bram Moolenaar53f81742017-09-22 14:35:51 +02007226 - 1 + wp->w_wincol), attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007227
7228#ifdef FEAT_CMDL_INFO
Bram Moolenaar491ac282018-06-17 14:47:55 +02007229 win_redr_ruler(wp, TRUE, ignore_pum);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007230#endif
7231 }
7232
Bram Moolenaar071d4272004-06-13 20:20:40 +00007233 /*
7234 * May need to draw the character below the vertical separator.
7235 */
7236 if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing())
7237 {
7238 if (stl_connected(wp))
Bram Moolenaar3633cf52017-07-31 22:29:35 +02007239 fillchar = fillchar_status(&attr, wp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007240 else
7241 fillchar = fillchar_vsep(&attr);
7242 screen_putchar(fillchar, W_WINROW(wp) + wp->w_height, W_ENDCOL(wp),
7243 attr);
7244 }
Bram Moolenaaradb09c22009-06-16 15:22:12 +00007245 busy = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007246}
7247
Bram Moolenaar238a5642006-02-21 22:12:05 +00007248#ifdef FEAT_STL_OPT
7249/*
7250 * Redraw the status line according to 'statusline' and take care of any
7251 * errors encountered.
7252 */
7253 static void
Bram Moolenaar05540972016-01-30 20:31:25 +01007254redraw_custom_statusline(win_T *wp)
Bram Moolenaar238a5642006-02-21 22:12:05 +00007255{
Bram Moolenaar362f3562009-11-03 16:20:34 +00007256 static int entered = FALSE;
Bram Moolenaara742e082016-04-05 21:10:38 +02007257 int saved_did_emsg = did_emsg;
Bram Moolenaar362f3562009-11-03 16:20:34 +00007258
7259 /* When called recursively return. This can happen when the statusline
7260 * contains an expression that triggers a redraw. */
7261 if (entered)
7262 return;
7263 entered = TRUE;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007264
Bram Moolenaara742e082016-04-05 21:10:38 +02007265 did_emsg = FALSE;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007266 win_redr_custom(wp, FALSE);
Bram Moolenaara742e082016-04-05 21:10:38 +02007267 if (did_emsg)
Bram Moolenaar362f3562009-11-03 16:20:34 +00007268 {
7269 /* When there is an error disable the statusline, otherwise the
7270 * display is messed up with errors and a redraw triggers the problem
7271 * again and again. */
Bram Moolenaar238a5642006-02-21 22:12:05 +00007272 set_string_option_direct((char_u *)"statusline", -1,
7273 (char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007274 ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR);
Bram Moolenaar362f3562009-11-03 16:20:34 +00007275 }
Bram Moolenaara742e082016-04-05 21:10:38 +02007276 did_emsg |= saved_did_emsg;
Bram Moolenaar362f3562009-11-03 16:20:34 +00007277 entered = FALSE;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007278}
7279#endif
7280
Bram Moolenaar071d4272004-06-13 20:20:40 +00007281/*
7282 * Return TRUE if the status line of window "wp" is connected to the status
7283 * line of the window right of it. If not, then it's a vertical separator.
7284 * Only call if (wp->w_vsep_width != 0).
7285 */
7286 int
Bram Moolenaar05540972016-01-30 20:31:25 +01007287stl_connected(win_T *wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007288{
7289 frame_T *fr;
7290
7291 fr = wp->w_frame;
7292 while (fr->fr_parent != NULL)
7293 {
7294 if (fr->fr_parent->fr_layout == FR_COL)
7295 {
7296 if (fr->fr_next != NULL)
7297 break;
7298 }
7299 else
7300 {
7301 if (fr->fr_next != NULL)
7302 return TRUE;
7303 }
7304 fr = fr->fr_parent;
7305 }
7306 return FALSE;
7307}
Bram Moolenaar071d4272004-06-13 20:20:40 +00007308
Bram Moolenaar071d4272004-06-13 20:20:40 +00007309
Bram Moolenaar071d4272004-06-13 20:20:40 +00007310/*
7311 * Get the value to show for the language mappings, active 'keymap'.
7312 */
7313 int
Bram Moolenaar05540972016-01-30 20:31:25 +01007314get_keymap_str(
7315 win_T *wp,
Bram Moolenaar73ac0c42016-07-24 16:17:59 +02007316 char_u *fmt, /* format string containing one %s item */
Bram Moolenaar05540972016-01-30 20:31:25 +01007317 char_u *buf, /* buffer for the result */
7318 int len) /* length of buffer */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007319{
7320 char_u *p;
7321
7322 if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP)
7323 return FALSE;
7324
7325 {
7326#ifdef FEAT_EVAL
7327 buf_T *old_curbuf = curbuf;
7328 win_T *old_curwin = curwin;
7329 char_u *s;
7330
7331 curbuf = wp->w_buffer;
7332 curwin = wp;
7333 STRCPY(buf, "b:keymap_name"); /* must be writable */
7334 ++emsg_skip;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007335 s = p = eval_to_string(buf, NULL, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007336 --emsg_skip;
7337 curbuf = old_curbuf;
7338 curwin = old_curwin;
7339 if (p == NULL || *p == NUL)
7340#endif
7341 {
7342#ifdef FEAT_KEYMAP
7343 if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED)
7344 p = wp->w_buffer->b_p_keymap;
7345 else
7346#endif
7347 p = (char_u *)"lang";
7348 }
Bram Moolenaar73ac0c42016-07-24 16:17:59 +02007349 if (vim_snprintf((char *)buf, len, (char *)fmt, p) > len - 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007350 buf[0] = NUL;
7351#ifdef FEAT_EVAL
7352 vim_free(s);
7353#endif
7354 }
7355 return buf[0] != NUL;
7356}
Bram Moolenaar071d4272004-06-13 20:20:40 +00007357
7358#if defined(FEAT_STL_OPT) || defined(PROTO)
7359/*
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007360 * Redraw the status line or ruler of window "wp".
7361 * When "wp" is NULL redraw the tab pages line from 'tabline'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007362 */
7363 static void
Bram Moolenaar05540972016-01-30 20:31:25 +01007364win_redr_custom(
7365 win_T *wp,
7366 int draw_ruler) /* TRUE or FALSE */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007367{
Bram Moolenaar1d633412013-12-11 15:52:01 +01007368 static int entered = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007369 int attr;
7370 int curattr;
7371 int row;
7372 int col = 0;
7373 int maxwidth;
7374 int width;
7375 int n;
7376 int len;
7377 int fillchar;
7378 char_u buf[MAXPATHL];
Bram Moolenaar362f3562009-11-03 16:20:34 +00007379 char_u *stl;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007380 char_u *p;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007381 struct stl_hlrec hltab[STL_MAX_ITEM];
7382 struct stl_hlrec tabtab[STL_MAX_ITEM];
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007383 int use_sandbox = FALSE;
Bram Moolenaar61452852011-02-01 18:01:11 +01007384 win_T *ewp;
7385 int p_crb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007386
Bram Moolenaar1d633412013-12-11 15:52:01 +01007387 /* There is a tiny chance that this gets called recursively: When
7388 * redrawing a status line triggers redrawing the ruler or tabline.
7389 * Avoid trouble by not allowing recursion. */
7390 if (entered)
7391 return;
7392 entered = TRUE;
7393
Bram Moolenaar071d4272004-06-13 20:20:40 +00007394 /* setup environment for the task at hand */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007395 if (wp == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007396 {
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007397 /* Use 'tabline'. Always at the first line of the screen. */
Bram Moolenaar362f3562009-11-03 16:20:34 +00007398 stl = p_tal;
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007399 row = 0;
Bram Moolenaar65c923a2006-03-03 22:56:30 +00007400 fillchar = ' ';
Bram Moolenaar8820b482017-03-16 17:23:31 +01007401 attr = HL_ATTR(HLF_TPF);
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007402 maxwidth = Columns;
7403# ifdef FEAT_EVAL
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007404 use_sandbox = was_set_insecurely((char_u *)"tabline", 0);
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007405# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007406 }
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007407 else
7408 {
7409 row = W_WINROW(wp) + wp->w_height;
Bram Moolenaar3633cf52017-07-31 22:29:35 +02007410 fillchar = fillchar_status(&attr, wp);
Bram Moolenaar02631462017-09-22 15:20:32 +02007411 maxwidth = wp->w_width;
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007412
7413 if (draw_ruler)
7414 {
Bram Moolenaar362f3562009-11-03 16:20:34 +00007415 stl = p_ruf;
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007416 /* advance past any leading group spec - implicit in ru_col */
Bram Moolenaar362f3562009-11-03 16:20:34 +00007417 if (*stl == '%')
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007418 {
Bram Moolenaar362f3562009-11-03 16:20:34 +00007419 if (*++stl == '-')
7420 stl++;
7421 if (atoi((char *)stl))
7422 while (VIM_ISDIGIT(*stl))
7423 stl++;
7424 if (*stl++ != '(')
7425 stl = p_ruf;
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007426 }
Bram Moolenaar02631462017-09-22 15:20:32 +02007427 col = ru_col - (Columns - wp->w_width);
7428 if (col < (wp->w_width + 1) / 2)
7429 col = (wp->w_width + 1) / 2;
7430 maxwidth = wp->w_width - col;
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007431 if (!wp->w_status_height)
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007432 {
7433 row = Rows - 1;
7434 --maxwidth; /* writing in last column may cause scrolling */
7435 fillchar = ' ';
7436 attr = 0;
7437 }
7438
7439# ifdef FEAT_EVAL
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007440 use_sandbox = was_set_insecurely((char_u *)"rulerformat", 0);
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007441# endif
7442 }
7443 else
7444 {
7445 if (*wp->w_p_stl != NUL)
Bram Moolenaar362f3562009-11-03 16:20:34 +00007446 stl = wp->w_p_stl;
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007447 else
Bram Moolenaar362f3562009-11-03 16:20:34 +00007448 stl = p_stl;
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007449# ifdef FEAT_EVAL
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007450 use_sandbox = was_set_insecurely((char_u *)"statusline",
7451 *wp->w_p_stl == NUL ? 0 : OPT_LOCAL);
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007452# endif
7453 }
7454
Bram Moolenaar53f81742017-09-22 14:35:51 +02007455 col += wp->w_wincol;
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007456 }
7457
Bram Moolenaar071d4272004-06-13 20:20:40 +00007458 if (maxwidth <= 0)
Bram Moolenaar1d633412013-12-11 15:52:01 +01007459 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007460
Bram Moolenaar61452852011-02-01 18:01:11 +01007461 /* Temporarily reset 'cursorbind', we don't want a side effect from moving
7462 * the cursor away and back. */
7463 ewp = wp == NULL ? curwin : wp;
7464 p_crb_save = ewp->w_p_crb;
7465 ewp->w_p_crb = FALSE;
7466
Bram Moolenaar362f3562009-11-03 16:20:34 +00007467 /* Make a copy, because the statusline may include a function call that
7468 * might change the option value and free the memory. */
7469 stl = vim_strsave(stl);
Bram Moolenaar61452852011-02-01 18:01:11 +01007470 width = build_stl_str_hl(ewp, buf, sizeof(buf),
Bram Moolenaar362f3562009-11-03 16:20:34 +00007471 stl, use_sandbox,
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007472 fillchar, maxwidth, hltab, tabtab);
Bram Moolenaar362f3562009-11-03 16:20:34 +00007473 vim_free(stl);
Bram Moolenaar61452852011-02-01 18:01:11 +01007474 ewp->w_p_crb = p_crb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007475
Bram Moolenaar7c5676b2010-12-08 19:56:58 +01007476 /* Make all characters printable. */
7477 p = transstr(buf);
7478 if (p != NULL)
7479 {
7480 vim_strncpy(buf, p, sizeof(buf) - 1);
7481 vim_free(p);
7482 }
7483
7484 /* fill up with "fillchar" */
7485 len = (int)STRLEN(buf);
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00007486 while (width < maxwidth && len < (int)sizeof(buf) - 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007487 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007488 len += (*mb_char2bytes)(fillchar, buf + len);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007489 ++width;
7490 }
7491 buf[len] = NUL;
7492
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007493 /*
7494 * Draw each snippet with the specified highlighting.
7495 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007496 curattr = attr;
7497 p = buf;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007498 for (n = 0; hltab[n].start != NULL; n++)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007499 {
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007500 len = (int)(hltab[n].start - p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007501 screen_puts_len(p, len, row, col, curattr);
7502 col += vim_strnsize(p, len);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007503 p = hltab[n].start;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007504
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007505 if (hltab[n].userhl == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007506 curattr = attr;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007507 else if (hltab[n].userhl < 0)
7508 curattr = syn_id2attr(-hltab[n].userhl);
Bram Moolenaar4033c552017-09-16 20:54:51 +02007509#ifdef FEAT_TERMINAL
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +02007510 else if (wp != NULL && wp != curwin && bt_terminal(wp->w_buffer)
7511 && wp->w_status_height != 0)
7512 curattr = highlight_stltermnc[hltab[n].userhl - 1];
Bram Moolenaarbce4f622017-08-13 21:37:43 +02007513 else if (wp != NULL && bt_terminal(wp->w_buffer)
7514 && wp->w_status_height != 0)
7515 curattr = highlight_stlterm[hltab[n].userhl - 1];
Bram Moolenaar4033c552017-09-16 20:54:51 +02007516#endif
Bram Moolenaar238a5642006-02-21 22:12:05 +00007517 else if (wp != NULL && wp != curwin && wp->w_status_height != 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007518 curattr = highlight_stlnc[hltab[n].userhl - 1];
Bram Moolenaar071d4272004-06-13 20:20:40 +00007519 else
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007520 curattr = highlight_user[hltab[n].userhl - 1];
Bram Moolenaar071d4272004-06-13 20:20:40 +00007521 }
7522 screen_puts(p, row, col, curattr);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007523
7524 if (wp == NULL)
7525 {
7526 /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */
7527 col = 0;
7528 len = 0;
7529 p = buf;
7530 fillchar = 0;
7531 for (n = 0; tabtab[n].start != NULL; n++)
7532 {
7533 len += vim_strnsize(p, (int)(tabtab[n].start - p));
7534 while (col < len)
7535 TabPageIdxs[col++] = fillchar;
7536 p = tabtab[n].start;
7537 fillchar = tabtab[n].userhl;
7538 }
7539 while (col < Columns)
7540 TabPageIdxs[col++] = fillchar;
7541 }
Bram Moolenaar1d633412013-12-11 15:52:01 +01007542
7543theend:
7544 entered = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007545}
7546
7547#endif /* FEAT_STL_OPT */
7548
7549/*
7550 * Output a single character directly to the screen and update ScreenLines.
7551 */
7552 void
Bram Moolenaar05540972016-01-30 20:31:25 +01007553screen_putchar(int c, int row, int col, int attr)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007554{
Bram Moolenaar071d4272004-06-13 20:20:40 +00007555 char_u buf[MB_MAXBYTES + 1];
7556
Bram Moolenaar9a920d82012-06-01 15:21:02 +02007557 if (has_mbyte)
7558 buf[(*mb_char2bytes)(c, buf)] = NUL;
7559 else
Bram Moolenaar9a920d82012-06-01 15:21:02 +02007560 {
7561 buf[0] = c;
7562 buf[1] = NUL;
7563 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007564 screen_puts(buf, row, col, attr);
7565}
7566
7567/*
7568 * Get a single character directly from ScreenLines into "bytes[]".
7569 * Also return its attribute in *attrp;
7570 */
7571 void
Bram Moolenaar05540972016-01-30 20:31:25 +01007572screen_getbytes(int row, int col, char_u *bytes, int *attrp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007573{
7574 unsigned off;
7575
7576 /* safety check */
7577 if (ScreenLines != NULL && row < screen_Rows && col < screen_Columns)
7578 {
7579 off = LineOffset[row] + col;
7580 *attrp = ScreenAttrs[off];
7581 bytes[0] = ScreenLines[off];
7582 bytes[1] = NUL;
7583
Bram Moolenaar071d4272004-06-13 20:20:40 +00007584 if (enc_utf8 && ScreenLinesUC[off] != 0)
7585 bytes[utfc_char2bytes(off, bytes)] = NUL;
7586 else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e)
7587 {
7588 bytes[0] = ScreenLines[off];
7589 bytes[1] = ScreenLines2[off];
7590 bytes[2] = NUL;
7591 }
7592 else if (enc_dbcs && MB_BYTE2LEN(bytes[0]) > 1)
7593 {
7594 bytes[1] = ScreenLines[off + 1];
7595 bytes[2] = NUL;
7596 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007597 }
7598}
7599
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007600/*
7601 * Return TRUE if composing characters for screen posn "off" differs from
7602 * composing characters in "u8cc".
Bram Moolenaar70c49c12010-03-23 15:36:35 +01007603 * Only to be used when ScreenLinesUC[off] != 0.
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007604 */
7605 static int
Bram Moolenaar05540972016-01-30 20:31:25 +01007606screen_comp_differs(int off, int *u8cc)
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007607{
7608 int i;
7609
7610 for (i = 0; i < Screen_mco; ++i)
7611 {
7612 if (ScreenLinesC[i][off] != (u8char_T)u8cc[i])
7613 return TRUE;
7614 if (u8cc[i] == 0)
7615 break;
7616 }
7617 return FALSE;
7618}
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007619
Bram Moolenaar071d4272004-06-13 20:20:40 +00007620/*
7621 * Put string '*text' on the screen at position 'row' and 'col', with
7622 * attributes 'attr', and update ScreenLines[] and ScreenAttrs[].
7623 * Note: only outputs within one row, message is truncated at screen boundary!
7624 * Note: if ScreenLines[], row and/or col is invalid, nothing is done.
7625 */
7626 void
Bram Moolenaar05540972016-01-30 20:31:25 +01007627screen_puts(
7628 char_u *text,
7629 int row,
7630 int col,
7631 int attr)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007632{
7633 screen_puts_len(text, -1, row, col, attr);
7634}
7635
7636/*
7637 * Like screen_puts(), but output "text[len]". When "len" is -1 output up to
7638 * a NUL.
7639 */
7640 void
Bram Moolenaar05540972016-01-30 20:31:25 +01007641screen_puts_len(
7642 char_u *text,
7643 int textlen,
7644 int row,
7645 int col,
7646 int attr)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007647{
7648 unsigned off;
7649 char_u *ptr = text;
Bram Moolenaare4c21e62014-05-22 16:05:19 +02007650 int len = textlen;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007651 int c;
Bram Moolenaar367329b2007-08-30 11:53:22 +00007652 unsigned max_off;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007653 int mbyte_blen = 1;
7654 int mbyte_cells = 1;
7655 int u8c = 0;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007656 int u8cc[MAX_MCO];
Bram Moolenaar071d4272004-06-13 20:20:40 +00007657 int clear_next_cell = FALSE;
Bram Moolenaara12a1612019-01-24 16:39:02 +01007658#ifdef FEAT_ARABIC
Bram Moolenaar071d4272004-06-13 20:20:40 +00007659 int prev_c = 0; /* previous Arabic character */
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007660 int pc, nc, nc1;
7661 int pcc[MAX_MCO];
Bram Moolenaar071d4272004-06-13 20:20:40 +00007662#endif
Bram Moolenaar2bea2912009-03-11 16:58:40 +00007663 int force_redraw_this;
7664 int force_redraw_next = FALSE;
Bram Moolenaar2bea2912009-03-11 16:58:40 +00007665 int need_redraw;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007666
7667 if (ScreenLines == NULL || row >= screen_Rows) /* safety check */
7668 return;
Bram Moolenaar2bea2912009-03-11 16:58:40 +00007669 off = LineOffset[row] + col;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007670
Bram Moolenaarc236c162008-07-13 17:41:49 +00007671 /* When drawing over the right halve of a double-wide char clear out the
7672 * left halve. Only needed in a terminal. */
Bram Moolenaar7693ec62008-07-24 18:29:37 +00007673 if (has_mbyte && col > 0 && col < screen_Columns
Bram Moolenaara12a1612019-01-24 16:39:02 +01007674#ifdef FEAT_GUI
Bram Moolenaarc236c162008-07-13 17:41:49 +00007675 && !gui.in_use
Bram Moolenaara12a1612019-01-24 16:39:02 +01007676#endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00007677 && mb_fix_col(col, row) != col)
Bram Moolenaar2bea2912009-03-11 16:58:40 +00007678 {
7679 ScreenLines[off - 1] = ' ';
7680 ScreenAttrs[off - 1] = 0;
7681 if (enc_utf8)
7682 {
7683 ScreenLinesUC[off - 1] = 0;
7684 ScreenLinesC[0][off - 1] = 0;
7685 }
7686 /* redraw the previous cell, make it empty */
7687 screen_char(off - 1, row, col - 1);
7688 /* force the cell at "col" to be redrawn */
7689 force_redraw_next = TRUE;
7690 }
Bram Moolenaarc236c162008-07-13 17:41:49 +00007691
Bram Moolenaar367329b2007-08-30 11:53:22 +00007692 max_off = LineOffset[row] + screen_Columns;
Bram Moolenaara064ac82007-08-05 18:10:54 +00007693 while (col < screen_Columns
7694 && (len < 0 || (int)(ptr - text) < len)
7695 && *ptr != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007696 {
7697 c = *ptr;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007698 /* check if this is the first byte of a multibyte */
7699 if (has_mbyte)
7700 {
7701 if (enc_utf8 && len > 0)
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00007702 mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr));
Bram Moolenaar071d4272004-06-13 20:20:40 +00007703 else
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00007704 mbyte_blen = (*mb_ptr2len)(ptr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007705 if (enc_dbcs == DBCS_JPNU && c == 0x8e)
7706 mbyte_cells = 1;
7707 else if (enc_dbcs != 0)
7708 mbyte_cells = mbyte_blen;
7709 else /* enc_utf8 */
7710 {
7711 if (len >= 0)
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007712 u8c = utfc_ptr2char_len(ptr, u8cc,
Bram Moolenaar071d4272004-06-13 20:20:40 +00007713 (int)((text + len) - ptr));
7714 else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007715 u8c = utfc_ptr2char(ptr, u8cc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007716 mbyte_cells = utf_char2cells(u8c);
Bram Moolenaara12a1612019-01-24 16:39:02 +01007717#ifdef FEAT_ARABIC
Bram Moolenaar071d4272004-06-13 20:20:40 +00007718 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c))
7719 {
7720 /* Do Arabic shaping. */
7721 if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len)
7722 {
7723 /* Past end of string to be displayed. */
7724 nc = NUL;
7725 nc1 = NUL;
7726 }
7727 else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007728 {
Bram Moolenaar54620182009-11-11 16:07:20 +00007729 nc = utfc_ptr2char_len(ptr + mbyte_blen, pcc,
7730 (int)((text + len) - ptr - mbyte_blen));
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007731 nc1 = pcc[0];
7732 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007733 pc = prev_c;
7734 prev_c = u8c;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007735 u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007736 }
7737 else
7738 prev_c = u8c;
Bram Moolenaara12a1612019-01-24 16:39:02 +01007739#endif
Bram Moolenaare4ebd292010-01-19 17:40:46 +01007740 if (col + mbyte_cells > screen_Columns)
7741 {
7742 /* Only 1 cell left, but character requires 2 cells:
7743 * display a '>' in the last column to avoid wrapping. */
7744 c = '>';
7745 mbyte_cells = 1;
7746 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007747 }
7748 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007749
Bram Moolenaar2bea2912009-03-11 16:58:40 +00007750 force_redraw_this = force_redraw_next;
7751 force_redraw_next = FALSE;
Bram Moolenaar2bea2912009-03-11 16:58:40 +00007752
7753 need_redraw = ScreenLines[off] != c
Bram Moolenaar071d4272004-06-13 20:20:40 +00007754 || (mbyte_cells == 2
7755 && ScreenLines[off + 1] != (enc_dbcs ? ptr[1] : 0))
7756 || (enc_dbcs == DBCS_JPNU
7757 && c == 0x8e
7758 && ScreenLines2[off] != ptr[1])
7759 || (enc_utf8
Bram Moolenaar70c49c12010-03-23 15:36:35 +01007760 && (ScreenLinesUC[off] !=
7761 (u8char_T)(c < 0x80 && u8cc[0] == 0 ? 0 : u8c)
7762 || (ScreenLinesUC[off] != 0
7763 && screen_comp_differs(off, u8cc))))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007764 || ScreenAttrs[off] != attr
Bram Moolenaar2bea2912009-03-11 16:58:40 +00007765 || exmode_active;
7766
Bram Moolenaara12a1612019-01-24 16:39:02 +01007767 if (need_redraw || force_redraw_this)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007768 {
7769#if defined(FEAT_GUI) || defined(UNIX)
7770 /* The bold trick makes a single row of pixels appear in the next
7771 * character. When a bold character is removed, the next
7772 * character should be redrawn too. This happens for our own GUI
Bram Moolenaar2bea2912009-03-11 16:58:40 +00007773 * and for some xterms. */
7774 if (need_redraw && ScreenLines[off] != ' ' && (
Bram Moolenaar071d4272004-06-13 20:20:40 +00007775# ifdef FEAT_GUI
7776 gui.in_use
7777# endif
7778# if defined(FEAT_GUI) && defined(UNIX)
7779 ||
7780# endif
7781# ifdef UNIX
7782 term_is_xterm
7783# endif
Bram Moolenaar2bea2912009-03-11 16:58:40 +00007784 ))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007785 {
Bram Moolenaar2bea2912009-03-11 16:58:40 +00007786 int n = ScreenAttrs[off];
Bram Moolenaar071d4272004-06-13 20:20:40 +00007787
Bram Moolenaar2bea2912009-03-11 16:58:40 +00007788 if (n > HL_ALL)
7789 n = syn_attr2attr(n);
7790 if (n & HL_BOLD)
7791 force_redraw_next = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007792 }
7793#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007794 /* When at the end of the text and overwriting a two-cell
7795 * character with a one-cell character, need to clear the next
7796 * cell. Also when overwriting the left halve of a two-cell char
7797 * with the right halve of a two-cell char. Do this only once
7798 * (mb_off2cells() may return 2 on the right halve). */
7799 if (clear_next_cell)
7800 clear_next_cell = FALSE;
7801 else if (has_mbyte
7802 && (len < 0 ? ptr[mbyte_blen] == NUL
7803 : ptr + mbyte_blen >= text + len)
Bram Moolenaar367329b2007-08-30 11:53:22 +00007804 && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007805 || (mbyte_cells == 2
Bram Moolenaar367329b2007-08-30 11:53:22 +00007806 && (*mb_off2cells)(off, max_off) == 1
7807 && (*mb_off2cells)(off + 1, max_off) > 1)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007808 clear_next_cell = TRUE;
7809
7810 /* Make sure we never leave a second byte of a double-byte behind,
7811 * it confuses mb_off2cells(). */
7812 if (enc_dbcs
Bram Moolenaar367329b2007-08-30 11:53:22 +00007813 && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007814 || (mbyte_cells == 2
Bram Moolenaar367329b2007-08-30 11:53:22 +00007815 && (*mb_off2cells)(off, max_off) == 1
7816 && (*mb_off2cells)(off + 1, max_off) > 1)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007817 ScreenLines[off + mbyte_blen] = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007818 ScreenLines[off] = c;
7819 ScreenAttrs[off] = attr;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007820 if (enc_utf8)
7821 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007822 if (c < 0x80 && u8cc[0] == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007823 ScreenLinesUC[off] = 0;
7824 else
7825 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007826 int i;
7827
Bram Moolenaar071d4272004-06-13 20:20:40 +00007828 ScreenLinesUC[off] = u8c;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007829 for (i = 0; i < Screen_mco; ++i)
7830 {
7831 ScreenLinesC[i][off] = u8cc[i];
7832 if (u8cc[i] == 0)
7833 break;
7834 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007835 }
7836 if (mbyte_cells == 2)
7837 {
7838 ScreenLines[off + 1] = 0;
7839 ScreenAttrs[off + 1] = attr;
7840 }
7841 screen_char(off, row, col);
7842 }
7843 else if (mbyte_cells == 2)
7844 {
7845 ScreenLines[off + 1] = ptr[1];
7846 ScreenAttrs[off + 1] = attr;
7847 screen_char_2(off, row, col);
7848 }
7849 else if (enc_dbcs == DBCS_JPNU && c == 0x8e)
7850 {
7851 ScreenLines2[off] = ptr[1];
7852 screen_char(off, row, col);
7853 }
7854 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00007855 screen_char(off, row, col);
7856 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007857 if (has_mbyte)
7858 {
7859 off += mbyte_cells;
7860 col += mbyte_cells;
7861 ptr += mbyte_blen;
7862 if (clear_next_cell)
Bram Moolenaare4c21e62014-05-22 16:05:19 +02007863 {
7864 /* This only happens at the end, display one space next. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007865 ptr = (char_u *)" ";
Bram Moolenaare4c21e62014-05-22 16:05:19 +02007866 len = -1;
7867 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007868 }
7869 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00007870 {
7871 ++off;
7872 ++col;
7873 ++ptr;
7874 }
7875 }
Bram Moolenaar2bea2912009-03-11 16:58:40 +00007876
Bram Moolenaar2bea2912009-03-11 16:58:40 +00007877 /* If we detected the next character needs to be redrawn, but the text
7878 * doesn't extend up to there, update the character here. */
7879 if (force_redraw_next && col < screen_Columns)
7880 {
Bram Moolenaar2bea2912009-03-11 16:58:40 +00007881 if (enc_dbcs != 0 && dbcs_off2cells(off, max_off) > 1)
7882 screen_char_2(off, row, col);
7883 else
Bram Moolenaar2bea2912009-03-11 16:58:40 +00007884 screen_char(off, row, col);
7885 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007886}
7887
7888#ifdef FEAT_SEARCH_EXTRA
7889/*
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007890 * Prepare for 'hlsearch' highlighting.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007891 */
7892 static void
Bram Moolenaar05540972016-01-30 20:31:25 +01007893start_search_hl(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007894{
7895 if (p_hls && !no_hlsearch)
7896 {
7897 last_pat_prog(&search_hl.rm);
Bram Moolenaar8820b482017-03-16 17:23:31 +01007898 search_hl.attr = HL_ATTR(HLF_L);
Bram Moolenaar91a4e822008-01-19 14:59:58 +00007899# ifdef FEAT_RELTIME
7900 /* Set the time limit to 'redrawtime'. */
7901 profile_setlimit(p_rdt, &search_hl.tm);
7902# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007903 }
7904}
7905
7906/*
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007907 * Clean up for 'hlsearch' highlighting.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007908 */
7909 static void
Bram Moolenaar05540972016-01-30 20:31:25 +01007910end_search_hl(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007911{
7912 if (search_hl.rm.regprog != NULL)
7913 {
Bram Moolenaar473de612013-06-08 18:19:48 +02007914 vim_regfree(search_hl.rm.regprog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007915 search_hl.rm.regprog = NULL;
7916 }
7917}
7918
7919/*
Bram Moolenaar0af8ceb2010-07-05 22:22:57 +02007920 * Init for calling prepare_search_hl().
7921 */
7922 static void
Bram Moolenaar05540972016-01-30 20:31:25 +01007923init_search_hl(win_T *wp)
Bram Moolenaar0af8ceb2010-07-05 22:22:57 +02007924{
7925 matchitem_T *cur;
7926
7927 /* Setup for match and 'hlsearch' highlighting. Disable any previous
7928 * match */
7929 cur = wp->w_match_head;
7930 while (cur != NULL)
7931 {
7932 cur->hl.rm = cur->match;
7933 if (cur->hlg_id == 0)
7934 cur->hl.attr = 0;
7935 else
7936 cur->hl.attr = syn_id2attr(cur->hlg_id);
7937 cur->hl.buf = wp->w_buffer;
7938 cur->hl.lnum = 0;
7939 cur->hl.first_lnum = 0;
7940# ifdef FEAT_RELTIME
7941 /* Set the time limit to 'redrawtime'. */
7942 profile_setlimit(p_rdt, &(cur->hl.tm));
7943# endif
7944 cur = cur->next;
7945 }
7946 search_hl.buf = wp->w_buffer;
7947 search_hl.lnum = 0;
7948 search_hl.first_lnum = 0;
7949 /* time limit is set at the toplevel, for all windows */
7950}
7951
7952/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00007953 * Advance to the match in window "wp" line "lnum" or past it.
7954 */
7955 static void
Bram Moolenaar05540972016-01-30 20:31:25 +01007956prepare_search_hl(win_T *wp, linenr_T lnum)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007957{
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007958 matchitem_T *cur; /* points to the match list */
7959 match_T *shl; /* points to search_hl or a match */
7960 int shl_flag; /* flag to indicate whether search_hl
7961 has been processed or not */
Bram Moolenaarb3414592014-06-17 17:48:32 +02007962 int pos_inprogress; /* marks that position match search is
7963 in progress */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007964 int n;
7965
7966 /*
7967 * When using a multi-line pattern, start searching at the top
7968 * of the window or just after a closed fold.
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007969 * Do this both for search_hl and the match list.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007970 */
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007971 cur = wp->w_match_head;
7972 shl_flag = FALSE;
7973 while (cur != NULL || shl_flag == FALSE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007974 {
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007975 if (shl_flag == FALSE)
7976 {
7977 shl = &search_hl;
7978 shl_flag = TRUE;
7979 }
7980 else
7981 shl = &cur->hl;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007982 if (shl->rm.regprog != NULL
7983 && shl->lnum == 0
7984 && re_multiline(shl->rm.regprog))
7985 {
7986 if (shl->first_lnum == 0)
7987 {
7988# ifdef FEAT_FOLDING
7989 for (shl->first_lnum = lnum;
7990 shl->first_lnum > wp->w_topline; --shl->first_lnum)
7991 if (hasFoldingWin(wp, shl->first_lnum - 1,
7992 NULL, NULL, TRUE, NULL))
7993 break;
7994# else
7995 shl->first_lnum = wp->w_topline;
7996# endif
7997 }
Bram Moolenaarb3414592014-06-17 17:48:32 +02007998 if (cur != NULL)
7999 cur->pos.cur = 0;
8000 pos_inprogress = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008001 n = 0;
Bram Moolenaarb3414592014-06-17 17:48:32 +02008002 while (shl->first_lnum < lnum && (shl->rm.regprog != NULL
8003 || (cur != NULL && pos_inprogress)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008004 {
Bram Moolenaare17bdff2016-08-27 18:34:29 +02008005 next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n,
8006 shl == &search_hl ? NULL : cur);
Bram Moolenaarb3414592014-06-17 17:48:32 +02008007 pos_inprogress = cur == NULL || cur->pos.cur == 0
8008 ? FALSE : TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008009 if (shl->lnum != 0)
8010 {
8011 shl->first_lnum = shl->lnum
8012 + shl->rm.endpos[0].lnum
8013 - shl->rm.startpos[0].lnum;
8014 n = shl->rm.endpos[0].col;
8015 }
8016 else
8017 {
8018 ++shl->first_lnum;
8019 n = 0;
8020 }
8021 }
8022 }
Bram Moolenaar6ee10162007-07-26 20:58:42 +00008023 if (shl != &search_hl && cur != NULL)
8024 cur = cur->next;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008025 }
8026}
8027
8028/*
Bram Moolenaar6ee10162007-07-26 20:58:42 +00008029 * Search for a next 'hlsearch' or match.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008030 * Uses shl->buf.
8031 * Sets shl->lnum and shl->rm contents.
8032 * Note: Assumes a previous match is always before "lnum", unless
8033 * shl->lnum is zero.
8034 * Careful: Any pointers for buffer lines will become invalid.
8035 */
8036 static void
Bram Moolenaar05540972016-01-30 20:31:25 +01008037next_search_hl(
8038 win_T *win,
8039 match_T *shl, /* points to search_hl or a match */
8040 linenr_T lnum,
8041 colnr_T mincol, /* minimal column for a match */
8042 matchitem_T *cur) /* to retrieve match positions if any */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008043{
8044 linenr_T l;
8045 colnr_T matchcol;
8046 long nmatched;
Bram Moolenaarbcf94422018-06-23 14:21:42 +02008047 int save_called_emsg = called_emsg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008048
Bram Moolenaarb0acacd2018-08-11 16:40:43 +02008049 // for :{range}s/pat only highlight inside the range
8050 if (lnum < search_first_line || lnum > search_last_line)
8051 {
8052 shl->lnum = 0;
8053 return;
8054 }
8055
Bram Moolenaar071d4272004-06-13 20:20:40 +00008056 if (shl->lnum != 0)
8057 {
8058 /* Check for three situations:
8059 * 1. If the "lnum" is below a previous match, start a new search.
8060 * 2. If the previous match includes "mincol", use it.
8061 * 3. Continue after the previous match.
8062 */
8063 l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum;
8064 if (lnum > l)
8065 shl->lnum = 0;
8066 else if (lnum < l || shl->rm.endpos[0].col > mincol)
8067 return;
8068 }
8069
8070 /*
8071 * Repeat searching for a match until one is found that includes "mincol"
8072 * or none is found in this line.
8073 */
8074 called_emsg = FALSE;
8075 for (;;)
8076 {
Bram Moolenaar91a4e822008-01-19 14:59:58 +00008077#ifdef FEAT_RELTIME
8078 /* Stop searching after passing the time limit. */
8079 if (profile_passed_limit(&(shl->tm)))
8080 {
8081 shl->lnum = 0; /* no match found in time */
8082 break;
8083 }
8084#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008085 /* Three situations:
8086 * 1. No useful previous match: search from start of line.
8087 * 2. Not Vi compatible or empty match: continue at next character.
8088 * Break the loop if this is beyond the end of the line.
8089 * 3. Vi compatible searching: continue at end of previous match.
8090 */
8091 if (shl->lnum == 0)
8092 matchcol = 0;
8093 else if (vim_strchr(p_cpo, CPO_SEARCH) == NULL
8094 || (shl->rm.endpos[0].lnum == 0
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008095 && shl->rm.endpos[0].col <= shl->rm.startpos[0].col))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008096 {
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00008097 char_u *ml;
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008098
8099 matchcol = shl->rm.startpos[0].col;
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00008100 ml = ml_get_buf(shl->buf, lnum, FALSE) + matchcol;
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008101 if (*ml == NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008102 {
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008103 ++matchcol;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008104 shl->lnum = 0;
8105 break;
8106 }
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008107 if (has_mbyte)
8108 matchcol += mb_ptr2len(ml);
8109 else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008110 ++matchcol;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008111 }
8112 else
8113 matchcol = shl->rm.endpos[0].col;
8114
8115 shl->lnum = lnum;
Bram Moolenaarb3414592014-06-17 17:48:32 +02008116 if (shl->rm.regprog != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008117 {
Bram Moolenaarcbdf0a02014-11-27 13:37:10 +01008118 /* Remember whether shl->rm is using a copy of the regprog in
8119 * cur->match. */
8120 int regprog_is_copy = (shl != &search_hl && cur != NULL
8121 && shl == &cur->hl
8122 && cur->match.regprog == cur->hl.rm.regprog);
Bram Moolenaarfbd0b0a2017-06-17 18:44:21 +02008123 int timed_out = FALSE;
Bram Moolenaarcbdf0a02014-11-27 13:37:10 +01008124
Bram Moolenaarb3414592014-06-17 17:48:32 +02008125 nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum,
8126 matchcol,
8127#ifdef FEAT_RELTIME
Bram Moolenaarfbd0b0a2017-06-17 18:44:21 +02008128 &(shl->tm), &timed_out
Bram Moolenaarb3414592014-06-17 17:48:32 +02008129#else
Bram Moolenaarfbd0b0a2017-06-17 18:44:21 +02008130 NULL, NULL
Bram Moolenaarb3414592014-06-17 17:48:32 +02008131#endif
8132 );
Bram Moolenaarcbdf0a02014-11-27 13:37:10 +01008133 /* Copy the regprog, in case it got freed and recompiled. */
8134 if (regprog_is_copy)
8135 cur->match.regprog = cur->hl.rm.regprog;
8136
Bram Moolenaarfbd0b0a2017-06-17 18:44:21 +02008137 if (called_emsg || got_int || timed_out)
Bram Moolenaar0ddf0a72007-05-01 20:04:53 +00008138 {
Bram Moolenaarb3414592014-06-17 17:48:32 +02008139 /* Error while handling regexp: stop using this regexp. */
8140 if (shl == &search_hl)
8141 {
8142 /* don't free regprog in the match list, it's a copy */
8143 vim_regfree(shl->rm.regprog);
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008144 set_no_hlsearch(TRUE);
Bram Moolenaarb3414592014-06-17 17:48:32 +02008145 }
8146 shl->rm.regprog = NULL;
8147 shl->lnum = 0;
8148 got_int = FALSE; /* avoid the "Type :quit to exit Vim"
8149 message */
8150 break;
Bram Moolenaar0ddf0a72007-05-01 20:04:53 +00008151 }
Bram Moolenaarb3414592014-06-17 17:48:32 +02008152 }
8153 else if (cur != NULL)
Bram Moolenaarb3414592014-06-17 17:48:32 +02008154 nmatched = next_search_hl_pos(shl, lnum, &(cur->pos), matchcol);
Bram Moolenaardeae0f22014-06-18 21:20:11 +02008155 else
8156 nmatched = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008157 if (nmatched == 0)
8158 {
8159 shl->lnum = 0; /* no match found */
8160 break;
8161 }
8162 if (shl->rm.startpos[0].lnum > 0
8163 || shl->rm.startpos[0].col >= mincol
8164 || nmatched > 1
8165 || shl->rm.endpos[0].col > mincol)
8166 {
8167 shl->lnum += shl->rm.startpos[0].lnum;
8168 break; /* useful match found */
8169 }
8170 }
Bram Moolenaarbcf94422018-06-23 14:21:42 +02008171
8172 // Restore called_emsg for assert_fails().
8173 called_emsg = save_called_emsg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008174}
Bram Moolenaar071d4272004-06-13 20:20:40 +00008175
Bram Moolenaar85077472016-10-16 14:35:48 +02008176/*
8177 * If there is a match fill "shl" and return one.
8178 * Return zero otherwise.
8179 */
Bram Moolenaarb3414592014-06-17 17:48:32 +02008180 static int
Bram Moolenaar05540972016-01-30 20:31:25 +01008181next_search_hl_pos(
8182 match_T *shl, /* points to a match */
8183 linenr_T lnum,
8184 posmatch_T *posmatch, /* match positions */
8185 colnr_T mincol) /* minimal column for a match */
Bram Moolenaarb3414592014-06-17 17:48:32 +02008186{
8187 int i;
Bram Moolenaar85077472016-10-16 14:35:48 +02008188 int found = -1;
Bram Moolenaarb3414592014-06-17 17:48:32 +02008189
Bram Moolenaarb3414592014-06-17 17:48:32 +02008190 for (i = posmatch->cur; i < MAXPOSMATCH; i++)
8191 {
Bram Moolenaara6c27ee2016-10-15 14:56:30 +02008192 llpos_T *pos = &posmatch->pos[i];
8193
8194 if (pos->lnum == 0)
Bram Moolenaarb3414592014-06-17 17:48:32 +02008195 break;
Bram Moolenaar85077472016-10-16 14:35:48 +02008196 if (pos->len == 0 && pos->col < mincol)
Bram Moolenaarb3414592014-06-17 17:48:32 +02008197 continue;
Bram Moolenaara6c27ee2016-10-15 14:56:30 +02008198 if (pos->lnum == lnum)
Bram Moolenaarb3414592014-06-17 17:48:32 +02008199 {
Bram Moolenaar85077472016-10-16 14:35:48 +02008200 if (found >= 0)
Bram Moolenaarb3414592014-06-17 17:48:32 +02008201 {
Bram Moolenaar85077472016-10-16 14:35:48 +02008202 /* if this match comes before the one at "found" then swap
8203 * them */
8204 if (pos->col < posmatch->pos[found].col)
Bram Moolenaarb3414592014-06-17 17:48:32 +02008205 {
Bram Moolenaara6c27ee2016-10-15 14:56:30 +02008206 llpos_T tmp = *pos;
Bram Moolenaarb3414592014-06-17 17:48:32 +02008207
Bram Moolenaar85077472016-10-16 14:35:48 +02008208 *pos = posmatch->pos[found];
8209 posmatch->pos[found] = tmp;
Bram Moolenaarb3414592014-06-17 17:48:32 +02008210 }
8211 }
8212 else
Bram Moolenaar85077472016-10-16 14:35:48 +02008213 found = i;
Bram Moolenaarb3414592014-06-17 17:48:32 +02008214 }
8215 }
8216 posmatch->cur = 0;
Bram Moolenaar85077472016-10-16 14:35:48 +02008217 if (found >= 0)
Bram Moolenaarb3414592014-06-17 17:48:32 +02008218 {
Bram Moolenaar85077472016-10-16 14:35:48 +02008219 colnr_T start = posmatch->pos[found].col == 0
8220 ? 0 : posmatch->pos[found].col - 1;
8221 colnr_T end = posmatch->pos[found].col == 0
8222 ? MAXCOL : start + posmatch->pos[found].len;
Bram Moolenaarb3414592014-06-17 17:48:32 +02008223
Bram Moolenaar85077472016-10-16 14:35:48 +02008224 shl->lnum = lnum;
Bram Moolenaarb3414592014-06-17 17:48:32 +02008225 shl->rm.startpos[0].lnum = 0;
8226 shl->rm.startpos[0].col = start;
8227 shl->rm.endpos[0].lnum = 0;
8228 shl->rm.endpos[0].col = end;
Bram Moolenaar4f416e42016-08-16 16:08:18 +02008229 shl->is_addpos = TRUE;
Bram Moolenaar85077472016-10-16 14:35:48 +02008230 posmatch->cur = found + 1;
8231 return 1;
Bram Moolenaarb3414592014-06-17 17:48:32 +02008232 }
Bram Moolenaar85077472016-10-16 14:35:48 +02008233 return 0;
Bram Moolenaarb3414592014-06-17 17:48:32 +02008234}
Bram Moolenaarde993ea2014-06-17 23:18:01 +02008235#endif
Bram Moolenaarb3414592014-06-17 17:48:32 +02008236
Bram Moolenaar071d4272004-06-13 20:20:40 +00008237 static void
Bram Moolenaar05540972016-01-30 20:31:25 +01008238screen_start_highlight(int attr)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008239{
8240 attrentry_T *aep = NULL;
8241
8242 screen_attr = attr;
8243 if (full_screen
Bram Moolenaar4f974752019-02-17 17:44:42 +01008244#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00008245 && termcap_active
8246#endif
8247 )
8248 {
8249#ifdef FEAT_GUI
8250 if (gui.in_use)
8251 {
8252 char buf[20];
8253
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008254 /* The GUI handles this internally. */
8255 sprintf(buf, IF_EB("\033|%dh", ESC_STR "|%dh"), attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008256 OUT_STR(buf);
8257 }
8258 else
8259#endif
8260 {
8261 if (attr > HL_ALL) /* special HL attr. */
8262 {
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008263 if (IS_CTERM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008264 aep = syn_cterm_attr2entry(attr);
8265 else
8266 aep = syn_term_attr2entry(attr);
8267 if (aep == NULL) /* did ":syntax clear" */
8268 attr = 0;
8269 else
8270 attr = aep->ae_attr;
8271 }
Bram Moolenaar45a00002017-12-22 21:12:34 +01008272 if ((attr & HL_BOLD) && *T_MD != NUL) /* bold */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008273 out_str(T_MD);
Bram Moolenaard4fc5772018-02-27 14:39:03 +01008274 else if (aep != NULL && cterm_normal_fg_bold && (
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008275#ifdef FEAT_TERMGUICOLORS
Bram Moolenaard4fc5772018-02-27 14:39:03 +01008276 p_tgc && aep->ae_u.cterm.fg_rgb != CTERMCOLOR
8277 ? aep->ae_u.cterm.fg_rgb != INVALCOLOR
8278 :
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008279#endif
Bram Moolenaard4fc5772018-02-27 14:39:03 +01008280 t_colors > 1 && aep->ae_u.cterm.fg_color))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008281 /* If the Normal FG color has BOLD attribute and the new HL
8282 * has a FG color defined, clear BOLD. */
8283 out_str(T_ME);
Bram Moolenaar45a00002017-12-22 21:12:34 +01008284 if ((attr & HL_STANDOUT) && *T_SO != NUL) /* standout */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008285 out_str(T_SO);
Bram Moolenaar45a00002017-12-22 21:12:34 +01008286 if ((attr & HL_UNDERCURL) && *T_UCS != NUL) /* undercurl */
Bram Moolenaar8b9e20a2017-11-28 21:25:21 +01008287 out_str(T_UCS);
8288 if (((attr & HL_UNDERLINE) /* underline or undercurl */
Bram Moolenaar45a00002017-12-22 21:12:34 +01008289 || ((attr & HL_UNDERCURL) && *T_UCS == NUL))
8290 && *T_US != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008291 out_str(T_US);
Bram Moolenaar45a00002017-12-22 21:12:34 +01008292 if ((attr & HL_ITALIC) && *T_CZH != NUL) /* italic */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008293 out_str(T_CZH);
Bram Moolenaar45a00002017-12-22 21:12:34 +01008294 if ((attr & HL_INVERSE) && *T_MR != NUL) /* inverse (reverse) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008295 out_str(T_MR);
Bram Moolenaar45a00002017-12-22 21:12:34 +01008296 if ((attr & HL_STRIKETHROUGH) && *T_STS != NUL) /* strike */
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02008297 out_str(T_STS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008298
8299 /*
8300 * Output the color or start string after bold etc., in case the
8301 * bold etc. override the color setting.
8302 */
8303 if (aep != NULL)
8304 {
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008305#ifdef FEAT_TERMGUICOLORS
Bram Moolenaard4fc5772018-02-27 14:39:03 +01008306 /* When 'termguicolors' is set but fg or bg is unset,
8307 * fall back to the cterm colors. This helps for SpellBad,
8308 * where the GUI uses a red undercurl. */
8309 if (p_tgc && aep->ae_u.cterm.fg_rgb != CTERMCOLOR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008310 {
Bram Moolenaar1b58cdd2016-08-22 23:04:33 +02008311 if (aep->ae_u.cterm.fg_rgb != INVALCOLOR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008312 term_fg_rgb_color(aep->ae_u.cterm.fg_rgb);
Bram Moolenaard4fc5772018-02-27 14:39:03 +01008313 }
8314 else
8315#endif
8316 if (t_colors > 1)
8317 {
8318 if (aep->ae_u.cterm.fg_color)
8319 term_fg_color(aep->ae_u.cterm.fg_color - 1);
8320 }
8321#ifdef FEAT_TERMGUICOLORS
8322 if (p_tgc && aep->ae_u.cterm.bg_rgb != CTERMCOLOR)
8323 {
Bram Moolenaar1b58cdd2016-08-22 23:04:33 +02008324 if (aep->ae_u.cterm.bg_rgb != INVALCOLOR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008325 term_bg_rgb_color(aep->ae_u.cterm.bg_rgb);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008326 }
8327 else
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008328#endif
Bram Moolenaard4fc5772018-02-27 14:39:03 +01008329 if (t_colors > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008330 {
Bram Moolenaard4fc5772018-02-27 14:39:03 +01008331 if (aep->ae_u.cterm.bg_color)
8332 term_bg_color(aep->ae_u.cterm.bg_color - 1);
8333 }
8334
Bram Moolenaarf708ac52018-03-12 21:48:32 +01008335 if (!IS_CTERM)
Bram Moolenaard4fc5772018-02-27 14:39:03 +01008336 {
8337 if (aep->ae_u.term.start != NULL)
8338 out_str(aep->ae_u.term.start);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008339 }
8340 }
8341 }
8342 }
8343}
8344
8345 void
Bram Moolenaar05540972016-01-30 20:31:25 +01008346screen_stop_highlight(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008347{
8348 int do_ME = FALSE; /* output T_ME code */
8349
8350 if (screen_attr != 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01008351#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00008352 && termcap_active
8353#endif
8354 )
8355 {
8356#ifdef FEAT_GUI
8357 if (gui.in_use)
8358 {
8359 char buf[20];
8360
8361 /* use internal GUI code */
8362 sprintf(buf, IF_EB("\033|%dH", ESC_STR "|%dH"), screen_attr);
8363 OUT_STR(buf);
8364 }
8365 else
8366#endif
8367 {
8368 if (screen_attr > HL_ALL) /* special HL attr. */
8369 {
8370 attrentry_T *aep;
8371
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008372 if (IS_CTERM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008373 {
8374 /*
8375 * Assume that t_me restores the original colors!
8376 */
8377 aep = syn_cterm_attr2entry(screen_attr);
Bram Moolenaard4fc5772018-02-27 14:39:03 +01008378 if (aep != NULL && ((
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008379#ifdef FEAT_TERMGUICOLORS
Bram Moolenaard4fc5772018-02-27 14:39:03 +01008380 p_tgc && aep->ae_u.cterm.fg_rgb != CTERMCOLOR
8381 ? aep->ae_u.cterm.fg_rgb != INVALCOLOR
8382 :
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008383#endif
Bram Moolenaard4fc5772018-02-27 14:39:03 +01008384 aep->ae_u.cterm.fg_color) || (
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008385#ifdef FEAT_TERMGUICOLORS
Bram Moolenaard4fc5772018-02-27 14:39:03 +01008386 p_tgc && aep->ae_u.cterm.bg_rgb != CTERMCOLOR
8387 ? aep->ae_u.cterm.bg_rgb != INVALCOLOR
8388 :
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008389#endif
Bram Moolenaard4fc5772018-02-27 14:39:03 +01008390 aep->ae_u.cterm.bg_color)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008391 do_ME = TRUE;
8392 }
8393 else
8394 {
8395 aep = syn_term_attr2entry(screen_attr);
8396 if (aep != NULL && aep->ae_u.term.stop != NULL)
8397 {
8398 if (STRCMP(aep->ae_u.term.stop, T_ME) == 0)
8399 do_ME = TRUE;
8400 else
8401 out_str(aep->ae_u.term.stop);
8402 }
8403 }
8404 if (aep == NULL) /* did ":syntax clear" */
8405 screen_attr = 0;
8406 else
8407 screen_attr = aep->ae_attr;
8408 }
8409
8410 /*
8411 * Often all ending-codes are equal to T_ME. Avoid outputting the
8412 * same sequence several times.
8413 */
8414 if (screen_attr & HL_STANDOUT)
8415 {
8416 if (STRCMP(T_SE, T_ME) == 0)
8417 do_ME = TRUE;
8418 else
8419 out_str(T_SE);
8420 }
Bram Moolenaar45a00002017-12-22 21:12:34 +01008421 if ((screen_attr & HL_UNDERCURL) && *T_UCE != NUL)
Bram Moolenaar8b9e20a2017-11-28 21:25:21 +01008422 {
8423 if (STRCMP(T_UCE, T_ME) == 0)
8424 do_ME = TRUE;
8425 else
8426 out_str(T_UCE);
8427 }
8428 if ((screen_attr & HL_UNDERLINE)
Bram Moolenaar45a00002017-12-22 21:12:34 +01008429 || ((screen_attr & HL_UNDERCURL) && *T_UCE == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008430 {
8431 if (STRCMP(T_UE, T_ME) == 0)
8432 do_ME = TRUE;
8433 else
8434 out_str(T_UE);
8435 }
8436 if (screen_attr & HL_ITALIC)
8437 {
8438 if (STRCMP(T_CZR, T_ME) == 0)
8439 do_ME = TRUE;
8440 else
8441 out_str(T_CZR);
8442 }
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02008443 if (screen_attr & HL_STRIKETHROUGH)
8444 {
8445 if (STRCMP(T_STE, T_ME) == 0)
8446 do_ME = TRUE;
8447 else
8448 out_str(T_STE);
8449 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008450 if (do_ME || (screen_attr & (HL_BOLD | HL_INVERSE)))
8451 out_str(T_ME);
8452
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008453#ifdef FEAT_TERMGUICOLORS
8454 if (p_tgc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008455 {
Bram Moolenaar1b58cdd2016-08-22 23:04:33 +02008456 if (cterm_normal_fg_gui_color != INVALCOLOR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008457 term_fg_rgb_color(cterm_normal_fg_gui_color);
Bram Moolenaar1b58cdd2016-08-22 23:04:33 +02008458 if (cterm_normal_bg_gui_color != INVALCOLOR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008459 term_bg_rgb_color(cterm_normal_bg_gui_color);
8460 }
8461 else
8462#endif
8463 {
8464 if (t_colors > 1)
8465 {
8466 /* set Normal cterm colors */
8467 if (cterm_normal_fg_color != 0)
8468 term_fg_color(cterm_normal_fg_color - 1);
8469 if (cterm_normal_bg_color != 0)
8470 term_bg_color(cterm_normal_bg_color - 1);
8471 if (cterm_normal_fg_bold)
8472 out_str(T_MD);
8473 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008474 }
8475 }
8476 }
8477 screen_attr = 0;
8478}
8479
8480/*
8481 * Reset the colors for a cterm. Used when leaving Vim.
8482 * The machine specific code may override this again.
8483 */
8484 void
Bram Moolenaar05540972016-01-30 20:31:25 +01008485reset_cterm_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008486{
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008487 if (IS_CTERM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008488 {
8489 /* set Normal cterm colors */
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008490#ifdef FEAT_TERMGUICOLORS
Bram Moolenaar1b58cdd2016-08-22 23:04:33 +02008491 if (p_tgc ? (cterm_normal_fg_gui_color != INVALCOLOR
8492 || cterm_normal_bg_gui_color != INVALCOLOR)
8493 : (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0))
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008494#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00008495 if (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008496#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008497 {
8498 out_str(T_OP);
8499 screen_attr = -1;
8500 }
8501 if (cterm_normal_fg_bold)
8502 {
8503 out_str(T_ME);
8504 screen_attr = -1;
8505 }
8506 }
8507}
8508
8509/*
8510 * Put character ScreenLines["off"] on the screen at position "row" and "col",
8511 * using the attributes from ScreenAttrs["off"].
8512 */
8513 static void
Bram Moolenaar05540972016-01-30 20:31:25 +01008514screen_char(unsigned off, int row, int col)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008515{
8516 int attr;
8517
8518 /* Check for illegal values, just in case (could happen just after
8519 * resizing). */
8520 if (row >= screen_Rows || col >= screen_Columns)
8521 return;
8522
Bram Moolenaarae654382019-01-17 21:09:05 +01008523#ifdef FEAT_INS_EXPAND
8524 if (pum_under_menu(row, col))
8525 return;
8526#endif
Bram Moolenaar494838a2015-02-10 19:20:37 +01008527 /* Outputting a character in the last cell on the screen may scroll the
8528 * screen up. Only do it when the "xn" termcap property is set, otherwise
8529 * mark the character invalid (update it when scrolled up). */
8530 if (*T_XN == NUL
8531 && row == screen_Rows - 1 && col == screen_Columns - 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00008532#ifdef FEAT_RIGHTLEFT
8533 /* account for first command-line character in rightleft mode */
8534 && !cmdmsg_rl
8535#endif
8536 )
8537 {
8538 ScreenAttrs[off] = (sattr_T)-1;
8539 return;
8540 }
8541
8542 /*
8543 * Stop highlighting first, so it's easier to move the cursor.
8544 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008545 if (screen_char_attr != 0)
8546 attr = screen_char_attr;
8547 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00008548 attr = ScreenAttrs[off];
8549 if (screen_attr != attr)
8550 screen_stop_highlight();
8551
8552 windgoto(row, col);
8553
8554 if (screen_attr != attr)
8555 screen_start_highlight(attr);
8556
Bram Moolenaar071d4272004-06-13 20:20:40 +00008557 if (enc_utf8 && ScreenLinesUC[off] != 0)
8558 {
8559 char_u buf[MB_MAXBYTES + 1];
8560
Bram Moolenaarcb070082016-04-02 22:14:51 +02008561 if (utf_ambiguous_width(ScreenLinesUC[off]))
Bram Moolenaarfae8ed12017-12-12 22:29:30 +01008562 {
8563 if (*p_ambw == 'd'
Bram Moolenaara12a1612019-01-24 16:39:02 +01008564#ifdef FEAT_GUI
Bram Moolenaarfae8ed12017-12-12 22:29:30 +01008565 && !gui.in_use
Bram Moolenaara12a1612019-01-24 16:39:02 +01008566#endif
Bram Moolenaarfae8ed12017-12-12 22:29:30 +01008567 )
8568 {
8569 /* Clear the two screen cells. If the character is actually
8570 * single width it won't change the second cell. */
8571 out_str((char_u *)" ");
8572 term_windgoto(row, col);
8573 }
8574 /* not sure where the cursor is after drawing the ambiguous width
8575 * character */
Bram Moolenaarcb070082016-04-02 22:14:51 +02008576 screen_cur_col = 9999;
Bram Moolenaarfae8ed12017-12-12 22:29:30 +01008577 }
Bram Moolenaarcb070082016-04-02 22:14:51 +02008578 else if (utf_char2cells(ScreenLinesUC[off]) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008579 ++screen_cur_col;
Bram Moolenaarfae8ed12017-12-12 22:29:30 +01008580
8581 /* Convert the UTF-8 character to bytes and write it. */
8582 buf[utfc_char2bytes(off, buf)] = NUL;
8583 out_str(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008584 }
8585 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00008586 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008587 out_flush_check();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008588 out_char(ScreenLines[off]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008589 /* double-byte character in single-width cell */
8590 if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e)
8591 out_char(ScreenLines2[off]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008592 }
8593
8594 screen_cur_col++;
8595}
8596
Bram Moolenaar071d4272004-06-13 20:20:40 +00008597/*
8598 * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"]
8599 * on the screen at position 'row' and 'col'.
8600 * The attributes of the first byte is used for all. This is required to
8601 * output the two bytes of a double-byte character with nothing in between.
8602 */
8603 static void
Bram Moolenaar05540972016-01-30 20:31:25 +01008604screen_char_2(unsigned off, int row, int col)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008605{
8606 /* Check for illegal values (could be wrong when screen was resized). */
8607 if (off + 1 >= (unsigned)(screen_Rows * screen_Columns))
8608 return;
8609
8610 /* Outputting the last character on the screen may scrollup the screen.
8611 * Don't to it! Mark the character invalid (update it when scrolled up) */
8612 if (row == screen_Rows - 1 && col >= screen_Columns - 2)
8613 {
8614 ScreenAttrs[off] = (sattr_T)-1;
8615 return;
8616 }
8617
8618 /* Output the first byte normally (positions the cursor), then write the
8619 * second byte directly. */
8620 screen_char(off, row, col);
8621 out_char(ScreenLines[off + 1]);
8622 ++screen_cur_col;
8623}
Bram Moolenaar071d4272004-06-13 20:20:40 +00008624
Bram Moolenaar071d4272004-06-13 20:20:40 +00008625/*
8626 * Draw a rectangle of the screen, inverted when "invert" is TRUE.
8627 * This uses the contents of ScreenLines[] and doesn't change it.
8628 */
8629 void
Bram Moolenaar05540972016-01-30 20:31:25 +01008630screen_draw_rectangle(
8631 int row,
8632 int col,
8633 int height,
8634 int width,
8635 int invert)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008636{
8637 int r, c;
8638 int off;
Bram Moolenaar367329b2007-08-30 11:53:22 +00008639 int max_off;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008640
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00008641 /* Can't use ScreenLines unless initialized */
8642 if (ScreenLines == NULL)
8643 return;
8644
Bram Moolenaar071d4272004-06-13 20:20:40 +00008645 if (invert)
8646 screen_char_attr = HL_INVERSE;
8647 for (r = row; r < row + height; ++r)
8648 {
8649 off = LineOffset[r];
Bram Moolenaar367329b2007-08-30 11:53:22 +00008650 max_off = off + screen_Columns;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008651 for (c = col; c < col + width; ++c)
8652 {
Bram Moolenaar367329b2007-08-30 11:53:22 +00008653 if (enc_dbcs != 0 && dbcs_off2cells(off + c, max_off) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008654 {
8655 screen_char_2(off + c, r, c);
8656 ++c;
8657 }
8658 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00008659 {
8660 screen_char(off + c, r, c);
Bram Moolenaar367329b2007-08-30 11:53:22 +00008661 if (utf_off2cells(off + c, max_off) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008662 ++c;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008663 }
8664 }
8665 }
8666 screen_char_attr = 0;
8667}
Bram Moolenaar071d4272004-06-13 20:20:40 +00008668
Bram Moolenaar071d4272004-06-13 20:20:40 +00008669/*
8670 * Redraw the characters for a vertically split window.
8671 */
8672 static void
Bram Moolenaar05540972016-01-30 20:31:25 +01008673redraw_block(int row, int end, win_T *wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008674{
8675 int col;
8676 int width;
8677
8678# ifdef FEAT_CLIPBOARD
8679 clip_may_clear_selection(row, end - 1);
8680# endif
8681
8682 if (wp == NULL)
8683 {
8684 col = 0;
8685 width = Columns;
8686 }
8687 else
8688 {
8689 col = wp->w_wincol;
8690 width = wp->w_width;
8691 }
8692 screen_draw_rectangle(row, col, end - row, width, FALSE);
8693}
Bram Moolenaar071d4272004-06-13 20:20:40 +00008694
Bram Moolenaar1b9645d2017-09-17 23:03:31 +02008695 static void
8696space_to_screenline(int off, int attr)
8697{
8698 ScreenLines[off] = ' ';
8699 ScreenAttrs[off] = attr;
Bram Moolenaar1b9645d2017-09-17 23:03:31 +02008700 if (enc_utf8)
8701 ScreenLinesUC[off] = 0;
Bram Moolenaar1b9645d2017-09-17 23:03:31 +02008702}
8703
Bram Moolenaar071d4272004-06-13 20:20:40 +00008704/*
8705 * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col'
8706 * with character 'c1' in first column followed by 'c2' in the other columns.
8707 * Use attributes 'attr'.
8708 */
8709 void
Bram Moolenaar05540972016-01-30 20:31:25 +01008710screen_fill(
8711 int start_row,
8712 int end_row,
8713 int start_col,
8714 int end_col,
8715 int c1,
8716 int c2,
8717 int attr)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008718{
8719 int row;
8720 int col;
8721 int off;
8722 int end_off;
8723 int did_delete;
8724 int c;
8725 int norm_term;
8726#if defined(FEAT_GUI) || defined(UNIX)
8727 int force_next = FALSE;
8728#endif
8729
8730 if (end_row > screen_Rows) /* safety check */
8731 end_row = screen_Rows;
8732 if (end_col > screen_Columns) /* safety check */
8733 end_col = screen_Columns;
8734 if (ScreenLines == NULL
8735 || start_row >= end_row
8736 || start_col >= end_col) /* nothing to do */
8737 return;
8738
8739 /* it's a "normal" terminal when not in a GUI or cterm */
8740 norm_term = (
8741#ifdef FEAT_GUI
8742 !gui.in_use &&
8743#endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008744 !IS_CTERM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008745 for (row = start_row; row < end_row; ++row)
8746 {
Bram Moolenaarc236c162008-07-13 17:41:49 +00008747 if (has_mbyte
Bram Moolenaara12a1612019-01-24 16:39:02 +01008748#ifdef FEAT_GUI
Bram Moolenaarc236c162008-07-13 17:41:49 +00008749 && !gui.in_use
Bram Moolenaara12a1612019-01-24 16:39:02 +01008750#endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00008751 )
8752 {
8753 /* When drawing over the right halve of a double-wide char clear
8754 * out the left halve. When drawing over the left halve of a
8755 * double wide-char clear out the right halve. Only needed in a
8756 * terminal. */
Bram Moolenaar7693ec62008-07-24 18:29:37 +00008757 if (start_col > 0 && mb_fix_col(start_col, row) != start_col)
Bram Moolenaard91ffe92008-07-14 17:51:11 +00008758 screen_puts_len((char_u *)" ", 1, row, start_col - 1, 0);
Bram Moolenaara1aed622008-07-18 15:14:43 +00008759 if (end_col < screen_Columns && mb_fix_col(end_col, row) != end_col)
Bram Moolenaard91ffe92008-07-14 17:51:11 +00008760 screen_puts_len((char_u *)" ", 1, row, end_col, 0);
Bram Moolenaarc236c162008-07-13 17:41:49 +00008761 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008762 /*
8763 * Try to use delete-line termcap code, when no attributes or in a
8764 * "normal" terminal, where a bold/italic space is just a
8765 * space.
8766 */
8767 did_delete = FALSE;
8768 if (c2 == ' '
8769 && end_col == Columns
8770 && can_clear(T_CE)
8771 && (attr == 0
8772 || (norm_term
8773 && attr <= HL_ALL
8774 && ((attr & ~(HL_BOLD | HL_ITALIC)) == 0))))
8775 {
8776 /*
8777 * check if we really need to clear something
8778 */
8779 col = start_col;
8780 if (c1 != ' ') /* don't clear first char */
8781 ++col;
8782
8783 off = LineOffset[row] + col;
8784 end_off = LineOffset[row] + end_col;
8785
8786 /* skip blanks (used often, keep it fast!) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008787 if (enc_utf8)
8788 while (off < end_off && ScreenLines[off] == ' '
8789 && ScreenAttrs[off] == 0 && ScreenLinesUC[off] == 0)
8790 ++off;
8791 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00008792 while (off < end_off && ScreenLines[off] == ' '
8793 && ScreenAttrs[off] == 0)
8794 ++off;
8795 if (off < end_off) /* something to be cleared */
8796 {
8797 col = off - LineOffset[row];
8798 screen_stop_highlight();
8799 term_windgoto(row, col);/* clear rest of this screen line */
8800 out_str(T_CE);
8801 screen_start(); /* don't know where cursor is now */
8802 col = end_col - col;
8803 while (col--) /* clear chars in ScreenLines */
8804 {
Bram Moolenaar1b9645d2017-09-17 23:03:31 +02008805 space_to_screenline(off, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008806 ++off;
8807 }
8808 }
8809 did_delete = TRUE; /* the chars are cleared now */
8810 }
8811
8812 off = LineOffset[row] + start_col;
8813 c = c1;
8814 for (col = start_col; col < end_col; ++col)
8815 {
8816 if (ScreenLines[off] != c
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008817 || (enc_utf8 && (int)ScreenLinesUC[off]
8818 != (c >= 0x80 ? c : 0))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008819 || ScreenAttrs[off] != attr
8820#if defined(FEAT_GUI) || defined(UNIX)
8821 || force_next
8822#endif
8823 )
8824 {
8825#if defined(FEAT_GUI) || defined(UNIX)
8826 /* The bold trick may make a single row of pixels appear in
8827 * the next character. When a bold character is removed, the
8828 * next character should be redrawn too. This happens for our
8829 * own GUI and for some xterms. */
8830 if (
8831# ifdef FEAT_GUI
8832 gui.in_use
8833# endif
8834# if defined(FEAT_GUI) && defined(UNIX)
8835 ||
8836# endif
8837# ifdef UNIX
8838 term_is_xterm
8839# endif
8840 )
8841 {
8842 if (ScreenLines[off] != ' '
8843 && (ScreenAttrs[off] > HL_ALL
8844 || ScreenAttrs[off] & HL_BOLD))
8845 force_next = TRUE;
8846 else
8847 force_next = FALSE;
8848 }
8849#endif
8850 ScreenLines[off] = c;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008851 if (enc_utf8)
8852 {
8853 if (c >= 0x80)
8854 {
8855 ScreenLinesUC[off] = c;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008856 ScreenLinesC[0][off] = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008857 }
8858 else
8859 ScreenLinesUC[off] = 0;
8860 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008861 ScreenAttrs[off] = attr;
8862 if (!did_delete || c != ' ')
8863 screen_char(off, row, col);
8864 }
8865 ++off;
8866 if (col == start_col)
8867 {
8868 if (did_delete)
8869 break;
8870 c = c2;
8871 }
8872 }
8873 if (end_col == Columns)
8874 LineWraps[row] = FALSE;
8875 if (row == Rows - 1) /* overwritten the command line */
8876 {
8877 redraw_cmdline = TRUE;
Bram Moolenaar5bab5552018-04-13 20:41:29 +02008878 if (start_col == 0 && end_col == Columns
8879 && c1 == ' ' && c2 == ' ' && attr == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008880 clear_cmdline = FALSE; /* command line has been cleared */
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008881 if (start_col == 0)
8882 mode_displayed = FALSE; /* mode cleared or overwritten */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008883 }
8884 }
8885}
8886
8887/*
8888 * Check if there should be a delay. Used before clearing or redrawing the
8889 * screen or the command line.
8890 */
8891 void
Bram Moolenaar05540972016-01-30 20:31:25 +01008892check_for_delay(int check_msg_scroll)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008893{
8894 if ((emsg_on_display || (check_msg_scroll && msg_scroll))
8895 && !did_wait_return
8896 && emsg_silent == 0)
8897 {
8898 out_flush();
8899 ui_delay(1000L, TRUE);
8900 emsg_on_display = FALSE;
8901 if (check_msg_scroll)
8902 msg_scroll = FALSE;
8903 }
8904}
8905
8906/*
Bram Moolenaarca57ab52019-04-13 14:53:16 +02008907 * Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect.
8908 */
8909 static void
8910clear_TabPageIdxs(void)
8911{
8912 int scol;
8913
8914 for (scol = 0; scol < Columns; ++scol)
8915 TabPageIdxs[scol] = 0;
8916}
8917
8918/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00008919 * screen_valid - allocate screen buffers if size changed
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008920 * If "doclear" is TRUE: clear screen if it has been resized.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008921 * Returns TRUE if there is a valid screen to write to.
8922 * Returns FALSE when starting up and screen not initialized yet.
8923 */
8924 int
Bram Moolenaar05540972016-01-30 20:31:25 +01008925screen_valid(int doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008926{
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008927 screenalloc(doclear); /* allocate screen buffers if size changed */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008928 return (ScreenLines != NULL);
8929}
8930
8931/*
8932 * Resize the shell to Rows and Columns.
8933 * Allocate ScreenLines[] and associated items.
8934 *
8935 * There may be some time between setting Rows and Columns and (re)allocating
8936 * ScreenLines[]. This happens when starting up and when (manually) changing
8937 * the shell size. Always use screen_Rows and screen_Columns to access items
8938 * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the
8939 * final size of the shell is needed.
8940 */
8941 void
Bram Moolenaar05540972016-01-30 20:31:25 +01008942screenalloc(int doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008943{
8944 int new_row, old_row;
8945#ifdef FEAT_GUI
8946 int old_Rows;
8947#endif
8948 win_T *wp;
8949 int outofmem = FALSE;
8950 int len;
8951 schar_T *new_ScreenLines;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008952 u8char_T *new_ScreenLinesUC = NULL;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008953 u8char_T *new_ScreenLinesC[MAX_MCO];
Bram Moolenaar071d4272004-06-13 20:20:40 +00008954 schar_T *new_ScreenLines2 = NULL;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008955 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008956 sattr_T *new_ScreenAttrs;
8957 unsigned *new_LineOffset;
8958 char_u *new_LineWraps;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008959 short *new_TabPageIdxs;
Bram Moolenaarf740b292006-02-16 22:11:02 +00008960 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008961 static int entered = FALSE; /* avoid recursiveness */
Bram Moolenaar89d40322006-08-29 15:30:07 +00008962 static int done_outofmem_msg = FALSE; /* did outofmem message */
Bram Moolenaar87e817c2009-02-22 20:13:39 +00008963 int retry_count = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008964
Bram Moolenaar87e817c2009-02-22 20:13:39 +00008965retry:
Bram Moolenaar071d4272004-06-13 20:20:40 +00008966 /*
8967 * Allocation of the screen buffers is done only when the size changes and
8968 * when Rows and Columns have been set and we have started doing full
8969 * screen stuff.
8970 */
8971 if ((ScreenLines != NULL
8972 && Rows == screen_Rows
8973 && Columns == screen_Columns
Bram Moolenaar071d4272004-06-13 20:20:40 +00008974 && enc_utf8 == (ScreenLinesUC != NULL)
8975 && (enc_dbcs == DBCS_JPNU) == (ScreenLines2 != NULL)
Bram Moolenaara12a1612019-01-24 16:39:02 +01008976 && p_mco == Screen_mco)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008977 || Rows == 0
8978 || Columns == 0
8979 || (!full_screen && ScreenLines == NULL))
8980 return;
8981
8982 /*
8983 * It's possible that we produce an out-of-memory message below, which
8984 * will cause this function to be called again. To break the loop, just
8985 * return here.
8986 */
8987 if (entered)
8988 return;
8989 entered = TRUE;
8990
Bram Moolenaara3f2ecd2006-07-11 21:01:01 +00008991 /*
8992 * Note that the window sizes are updated before reallocating the arrays,
8993 * thus we must not redraw here!
8994 */
8995 ++RedrawingDisabled;
8996
Bram Moolenaar071d4272004-06-13 20:20:40 +00008997 win_new_shellsize(); /* fit the windows in the new sized shell */
8998
Bram Moolenaar071d4272004-06-13 20:20:40 +00008999 comp_col(); /* recompute columns for shown command and ruler */
9000
9001 /*
9002 * We're changing the size of the screen.
9003 * - Allocate new arrays for ScreenLines and ScreenAttrs.
9004 * - Move lines from the old arrays into the new arrays, clear extra
9005 * lines (unless the screen is going to be cleared).
9006 * - Free the old arrays.
9007 *
9008 * If anything fails, make ScreenLines NULL, so we don't do anything!
9009 * Continuing with the old ScreenLines may result in a crash, because the
9010 * size is wrong.
9011 */
Bram Moolenaarf740b292006-02-16 22:11:02 +00009012 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009013 win_free_lsize(wp);
Bram Moolenaar5e9b4542009-07-29 14:24:36 +00009014 if (aucmd_win != NULL)
9015 win_free_lsize(aucmd_win);
Bram Moolenaar8caaf822019-06-01 18:11:22 +02009016#ifdef FEAT_TEXT_PROP
9017 // global popup windows
9018 for (wp = first_popupwin; wp != NULL; wp = wp->w_next)
9019 win_free_lsize(wp);
9020 // tab-local popup windows
9021 FOR_ALL_TABPAGES(tp)
9022 for (wp = tp->tp_first_popupwin; wp != NULL; wp = wp->w_next)
9023 win_free_lsize(wp);
9024#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009025
Bram Moolenaarc799fe22019-05-28 23:08:19 +02009026 new_ScreenLines = LALLOC_MULT(schar_T, (Rows + 1) * Columns);
Bram Moolenaar216b7102010-03-23 13:56:59 +01009027 vim_memset(new_ScreenLinesC, 0, sizeof(u8char_T *) * MAX_MCO);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009028 if (enc_utf8)
9029 {
Bram Moolenaarc799fe22019-05-28 23:08:19 +02009030 new_ScreenLinesUC = LALLOC_MULT(u8char_T, (Rows + 1) * Columns);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009031 for (i = 0; i < p_mco; ++i)
Bram Moolenaarc799fe22019-05-28 23:08:19 +02009032 new_ScreenLinesC[i] = LALLOC_CLEAR_MULT(u8char_T,
9033 (Rows + 1) * Columns);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009034 }
9035 if (enc_dbcs == DBCS_JPNU)
Bram Moolenaarc799fe22019-05-28 23:08:19 +02009036 new_ScreenLines2 = LALLOC_MULT(schar_T, (Rows + 1) * Columns);
9037 new_ScreenAttrs = LALLOC_MULT(sattr_T, (Rows + 1) * Columns);
9038 new_LineOffset = LALLOC_MULT(unsigned, Rows);
9039 new_LineWraps = LALLOC_MULT(char_u, Rows);
9040 new_TabPageIdxs = LALLOC_MULT(short, Columns);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009041
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009042 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009043 {
9044 if (win_alloc_lines(wp) == FAIL)
9045 {
9046 outofmem = TRUE;
Bram Moolenaarbb9c7d12009-02-21 23:03:09 +00009047 goto give_up;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009048 }
9049 }
Bram Moolenaar5e9b4542009-07-29 14:24:36 +00009050 if (aucmd_win != NULL && aucmd_win->w_lines == NULL
9051 && win_alloc_lines(aucmd_win) == FAIL)
Bram Moolenaar746ebd32009-06-16 14:01:43 +00009052 outofmem = TRUE;
Bram Moolenaar8caaf822019-06-01 18:11:22 +02009053#ifdef FEAT_TEXT_PROP
9054 // global popup windows
9055 for (wp = first_popupwin; wp != NULL; wp = wp->w_next)
9056 if (win_alloc_lines(wp) == FAIL)
9057 {
9058 outofmem = TRUE;
9059 goto give_up;
9060 }
9061 // tab-local popup windows
9062 FOR_ALL_TABPAGES(tp)
9063 for (wp = tp->tp_first_popupwin; wp != NULL; wp = wp->w_next)
9064 if (win_alloc_lines(wp) == FAIL)
9065 {
9066 outofmem = TRUE;
9067 goto give_up;
9068 }
9069#endif
9070
Bram Moolenaarbb9c7d12009-02-21 23:03:09 +00009071give_up:
Bram Moolenaar071d4272004-06-13 20:20:40 +00009072
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009073 for (i = 0; i < p_mco; ++i)
9074 if (new_ScreenLinesC[i] == NULL)
9075 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009076 if (new_ScreenLines == NULL
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009077 || (enc_utf8 && (new_ScreenLinesUC == NULL || i != p_mco))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009078 || (enc_dbcs == DBCS_JPNU && new_ScreenLines2 == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009079 || new_ScreenAttrs == NULL
9080 || new_LineOffset == NULL
9081 || new_LineWraps == NULL
Bram Moolenaarf740b292006-02-16 22:11:02 +00009082 || new_TabPageIdxs == NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009083 || outofmem)
9084 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00009085 if (ScreenLines != NULL || !done_outofmem_msg)
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00009086 {
9087 /* guess the size */
9088 do_outofmem_msg((long_u)((Rows + 1) * Columns));
9089
9090 /* Remember we did this to avoid getting outofmem messages over
9091 * and over again. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00009092 done_outofmem_msg = TRUE;
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00009093 }
Bram Moolenaard23a8232018-02-10 18:45:26 +01009094 VIM_CLEAR(new_ScreenLines);
Bram Moolenaard23a8232018-02-10 18:45:26 +01009095 VIM_CLEAR(new_ScreenLinesUC);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009096 for (i = 0; i < p_mco; ++i)
Bram Moolenaard23a8232018-02-10 18:45:26 +01009097 VIM_CLEAR(new_ScreenLinesC[i]);
9098 VIM_CLEAR(new_ScreenLines2);
Bram Moolenaard23a8232018-02-10 18:45:26 +01009099 VIM_CLEAR(new_ScreenAttrs);
9100 VIM_CLEAR(new_LineOffset);
9101 VIM_CLEAR(new_LineWraps);
9102 VIM_CLEAR(new_TabPageIdxs);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009103 }
9104 else
9105 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00009106 done_outofmem_msg = FALSE;
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00009107
Bram Moolenaar071d4272004-06-13 20:20:40 +00009108 for (new_row = 0; new_row < Rows; ++new_row)
9109 {
9110 new_LineOffset[new_row] = new_row * Columns;
9111 new_LineWraps[new_row] = FALSE;
9112
9113 /*
9114 * If the screen is not going to be cleared, copy as much as
9115 * possible from the old screen to the new one and clear the rest
9116 * (used when resizing the window at the "--more--" prompt or when
9117 * executing an external command, for the GUI).
9118 */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009119 if (!doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009120 {
9121 (void)vim_memset(new_ScreenLines + new_row * Columns,
9122 ' ', (size_t)Columns * sizeof(schar_T));
Bram Moolenaar071d4272004-06-13 20:20:40 +00009123 if (enc_utf8)
9124 {
9125 (void)vim_memset(new_ScreenLinesUC + new_row * Columns,
9126 0, (size_t)Columns * sizeof(u8char_T));
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009127 for (i = 0; i < p_mco; ++i)
9128 (void)vim_memset(new_ScreenLinesC[i]
9129 + new_row * Columns,
Bram Moolenaar071d4272004-06-13 20:20:40 +00009130 0, (size_t)Columns * sizeof(u8char_T));
9131 }
9132 if (enc_dbcs == DBCS_JPNU)
9133 (void)vim_memset(new_ScreenLines2 + new_row * Columns,
9134 0, (size_t)Columns * sizeof(schar_T));
Bram Moolenaar071d4272004-06-13 20:20:40 +00009135 (void)vim_memset(new_ScreenAttrs + new_row * Columns,
9136 0, (size_t)Columns * sizeof(sattr_T));
9137 old_row = new_row + (screen_Rows - Rows);
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00009138 if (old_row >= 0 && ScreenLines != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009139 {
9140 if (screen_Columns < Columns)
9141 len = screen_Columns;
9142 else
9143 len = Columns;
Bram Moolenaarf4d11452005-12-02 00:46:37 +00009144 /* When switching to utf-8 don't copy characters, they
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009145 * may be invalid now. Also when p_mco changes. */
9146 if (!(enc_utf8 && ScreenLinesUC == NULL)
9147 && p_mco == Screen_mco)
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00009148 mch_memmove(new_ScreenLines + new_LineOffset[new_row],
9149 ScreenLines + LineOffset[old_row],
9150 (size_t)len * sizeof(schar_T));
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009151 if (enc_utf8 && ScreenLinesUC != NULL
9152 && p_mco == Screen_mco)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009153 {
9154 mch_memmove(new_ScreenLinesUC + new_LineOffset[new_row],
9155 ScreenLinesUC + LineOffset[old_row],
9156 (size_t)len * sizeof(u8char_T));
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009157 for (i = 0; i < p_mco; ++i)
9158 mch_memmove(new_ScreenLinesC[i]
9159 + new_LineOffset[new_row],
9160 ScreenLinesC[i] + LineOffset[old_row],
Bram Moolenaar071d4272004-06-13 20:20:40 +00009161 (size_t)len * sizeof(u8char_T));
9162 }
9163 if (enc_dbcs == DBCS_JPNU && ScreenLines2 != NULL)
9164 mch_memmove(new_ScreenLines2 + new_LineOffset[new_row],
9165 ScreenLines2 + LineOffset[old_row],
9166 (size_t)len * sizeof(schar_T));
Bram Moolenaar071d4272004-06-13 20:20:40 +00009167 mch_memmove(new_ScreenAttrs + new_LineOffset[new_row],
9168 ScreenAttrs + LineOffset[old_row],
9169 (size_t)len * sizeof(sattr_T));
9170 }
9171 }
9172 }
9173 /* Use the last line of the screen for the current line. */
9174 current_ScreenLine = new_ScreenLines + Rows * Columns;
9175 }
9176
Bram Moolenaar1ec484f2005-06-24 23:07:47 +00009177 free_screenlines();
9178
Bram Moolenaar071d4272004-06-13 20:20:40 +00009179 ScreenLines = new_ScreenLines;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009180 ScreenLinesUC = new_ScreenLinesUC;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009181 for (i = 0; i < p_mco; ++i)
9182 ScreenLinesC[i] = new_ScreenLinesC[i];
9183 Screen_mco = p_mco;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009184 ScreenLines2 = new_ScreenLines2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009185 ScreenAttrs = new_ScreenAttrs;
9186 LineOffset = new_LineOffset;
9187 LineWraps = new_LineWraps;
Bram Moolenaarf740b292006-02-16 22:11:02 +00009188 TabPageIdxs = new_TabPageIdxs;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009189
9190 /* It's important that screen_Rows and screen_Columns reflect the actual
9191 * size of ScreenLines[]. Set them before calling anything. */
9192#ifdef FEAT_GUI
9193 old_Rows = screen_Rows;
9194#endif
9195 screen_Rows = Rows;
9196 screen_Columns = Columns;
9197
9198 must_redraw = CLEAR; /* need to clear the screen later */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009199 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009200 screenclear2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009201#ifdef FEAT_GUI
9202 else if (gui.in_use
9203 && !gui.starting
9204 && ScreenLines != NULL
9205 && old_Rows != Rows)
9206 {
9207 (void)gui_redraw_block(0, 0, (int)Rows - 1, (int)Columns - 1, 0);
9208 /*
9209 * Adjust the position of the cursor, for when executing an external
9210 * command.
9211 */
9212 if (msg_row >= Rows) /* Rows got smaller */
9213 msg_row = Rows - 1; /* put cursor at last row */
9214 else if (Rows > old_Rows) /* Rows got bigger */
9215 msg_row += Rows - old_Rows; /* put cursor in same place */
9216 if (msg_col >= Columns) /* Columns got smaller */
9217 msg_col = Columns - 1; /* put cursor at last column */
9218 }
9219#endif
Bram Moolenaarca57ab52019-04-13 14:53:16 +02009220 clear_TabPageIdxs();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009221
Bram Moolenaar071d4272004-06-13 20:20:40 +00009222 entered = FALSE;
Bram Moolenaara3f2ecd2006-07-11 21:01:01 +00009223 --RedrawingDisabled;
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +00009224
Bram Moolenaar87e817c2009-02-22 20:13:39 +00009225 /*
9226 * Do not apply autocommands more than 3 times to avoid an endless loop
9227 * in case applying autocommands always changes Rows or Columns.
9228 */
9229 if (starting == 0 && ++retry_count <= 3)
9230 {
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +00009231 apply_autocmds(EVENT_VIMRESIZED, NULL, NULL, FALSE, curbuf);
Bram Moolenaar87e817c2009-02-22 20:13:39 +00009232 /* In rare cases, autocommands may have altered Rows or Columns,
9233 * jump back to check if we need to allocate the screen again. */
9234 goto retry;
9235 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009236}
9237
9238 void
Bram Moolenaar05540972016-01-30 20:31:25 +01009239free_screenlines(void)
Bram Moolenaar1ec484f2005-06-24 23:07:47 +00009240{
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009241 int i;
9242
Bram Moolenaar1ec484f2005-06-24 23:07:47 +00009243 vim_free(ScreenLinesUC);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009244 for (i = 0; i < Screen_mco; ++i)
9245 vim_free(ScreenLinesC[i]);
Bram Moolenaar1ec484f2005-06-24 23:07:47 +00009246 vim_free(ScreenLines2);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009247 vim_free(ScreenLines);
Bram Moolenaar1ec484f2005-06-24 23:07:47 +00009248 vim_free(ScreenAttrs);
9249 vim_free(LineOffset);
9250 vim_free(LineWraps);
Bram Moolenaarf740b292006-02-16 22:11:02 +00009251 vim_free(TabPageIdxs);
Bram Moolenaar1ec484f2005-06-24 23:07:47 +00009252}
9253
9254 void
Bram Moolenaar05540972016-01-30 20:31:25 +01009255screenclear(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009256{
9257 check_for_delay(FALSE);
9258 screenalloc(FALSE); /* allocate screen buffers if size changed */
9259 screenclear2(); /* clear the screen */
9260}
9261
9262 static void
Bram Moolenaar05540972016-01-30 20:31:25 +01009263screenclear2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009264{
9265 int i;
9266
9267 if (starting == NO_SCREEN || ScreenLines == NULL
9268#ifdef FEAT_GUI
9269 || (gui.in_use && gui.starting)
9270#endif
9271 )
9272 return;
9273
9274#ifdef FEAT_GUI
9275 if (!gui.in_use)
9276#endif
9277 screen_attr = -1; /* force setting the Normal colors */
9278 screen_stop_highlight(); /* don't want highlighting here */
9279
9280#ifdef FEAT_CLIPBOARD
9281 /* disable selection without redrawing it */
9282 clip_scroll_selection(9999);
9283#endif
9284
9285 /* blank out ScreenLines */
9286 for (i = 0; i < Rows; ++i)
9287 {
Bram Moolenaarcfce7172017-08-17 20:31:48 +02009288 lineclear(LineOffset[i], (int)Columns, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009289 LineWraps[i] = FALSE;
9290 }
9291
9292 if (can_clear(T_CL))
9293 {
9294 out_str(T_CL); /* clear the display */
9295 clear_cmdline = FALSE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00009296 mode_displayed = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009297 }
9298 else
9299 {
9300 /* can't clear the screen, mark all chars with invalid attributes */
9301 for (i = 0; i < Rows; ++i)
9302 lineinvalid(LineOffset[i], (int)Columns);
9303 clear_cmdline = TRUE;
9304 }
9305
9306 screen_cleared = TRUE; /* can use contents of ScreenLines now */
9307
9308 win_rest_invalid(firstwin);
9309 redraw_cmdline = TRUE;
Bram Moolenaar997fb4b2006-02-17 21:53:23 +00009310 redraw_tabline = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009311 if (must_redraw == CLEAR) /* no need to clear again */
9312 must_redraw = NOT_VALID;
9313 compute_cmdrow();
9314 msg_row = cmdline_row; /* put cursor on last line for messages */
9315 msg_col = 0;
9316 screen_start(); /* don't know where cursor is now */
9317 msg_scrolled = 0; /* can't scroll back */
9318 msg_didany = FALSE;
9319 msg_didout = FALSE;
9320}
9321
9322/*
9323 * Clear one line in ScreenLines.
9324 */
9325 static void
Bram Moolenaarcfce7172017-08-17 20:31:48 +02009326lineclear(unsigned off, int width, int attr)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009327{
9328 (void)vim_memset(ScreenLines + off, ' ', (size_t)width * sizeof(schar_T));
Bram Moolenaar071d4272004-06-13 20:20:40 +00009329 if (enc_utf8)
9330 (void)vim_memset(ScreenLinesUC + off, 0,
9331 (size_t)width * sizeof(u8char_T));
Bram Moolenaarcfce7172017-08-17 20:31:48 +02009332 (void)vim_memset(ScreenAttrs + off, attr, (size_t)width * sizeof(sattr_T));
Bram Moolenaar071d4272004-06-13 20:20:40 +00009333}
9334
9335/*
9336 * Mark one line in ScreenLines invalid by setting the attributes to an
9337 * invalid value.
9338 */
9339 static void
Bram Moolenaar05540972016-01-30 20:31:25 +01009340lineinvalid(unsigned off, int width)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009341{
9342 (void)vim_memset(ScreenAttrs + off, -1, (size_t)width * sizeof(sattr_T));
9343}
9344
Bram Moolenaar071d4272004-06-13 20:20:40 +00009345/*
9346 * Copy part of a Screenline for vertically split window "wp".
9347 */
9348 static void
Bram Moolenaar05540972016-01-30 20:31:25 +01009349linecopy(int to, int from, win_T *wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009350{
9351 unsigned off_to = LineOffset[to] + wp->w_wincol;
9352 unsigned off_from = LineOffset[from] + wp->w_wincol;
9353
9354 mch_memmove(ScreenLines + off_to, ScreenLines + off_from,
9355 wp->w_width * sizeof(schar_T));
Bram Moolenaar071d4272004-06-13 20:20:40 +00009356 if (enc_utf8)
9357 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009358 int i;
9359
Bram Moolenaar071d4272004-06-13 20:20:40 +00009360 mch_memmove(ScreenLinesUC + off_to, ScreenLinesUC + off_from,
9361 wp->w_width * sizeof(u8char_T));
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009362 for (i = 0; i < p_mco; ++i)
9363 mch_memmove(ScreenLinesC[i] + off_to, ScreenLinesC[i] + off_from,
9364 wp->w_width * sizeof(u8char_T));
Bram Moolenaar071d4272004-06-13 20:20:40 +00009365 }
9366 if (enc_dbcs == DBCS_JPNU)
9367 mch_memmove(ScreenLines2 + off_to, ScreenLines2 + off_from,
9368 wp->w_width * sizeof(schar_T));
Bram Moolenaar071d4272004-06-13 20:20:40 +00009369 mch_memmove(ScreenAttrs + off_to, ScreenAttrs + off_from,
9370 wp->w_width * sizeof(sattr_T));
9371}
Bram Moolenaar071d4272004-06-13 20:20:40 +00009372
9373/*
9374 * Return TRUE if clearing with term string "p" would work.
9375 * It can't work when the string is empty or it won't set the right background.
9376 */
9377 int
Bram Moolenaar05540972016-01-30 20:31:25 +01009378can_clear(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009379{
9380 return (*p != NUL && (t_colors <= 1
9381#ifdef FEAT_GUI
9382 || gui.in_use
9383#endif
Bram Moolenaar61be73b2016-04-29 22:59:22 +02009384#ifdef FEAT_TERMGUICOLORS
Bram Moolenaar1b58cdd2016-08-22 23:04:33 +02009385 || (p_tgc && cterm_normal_bg_gui_color == INVALCOLOR)
Bram Moolenaard18f6722016-06-17 13:18:49 +02009386 || (!p_tgc && cterm_normal_bg_color == 0)
9387#else
9388 || cterm_normal_bg_color == 0
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009389#endif
Bram Moolenaard18f6722016-06-17 13:18:49 +02009390 || *T_UT != NUL));
Bram Moolenaar071d4272004-06-13 20:20:40 +00009391}
9392
9393/*
9394 * Reset cursor position. Use whenever cursor was moved because of outputting
9395 * something directly to the screen (shell commands) or a terminal control
9396 * code.
9397 */
9398 void
Bram Moolenaar05540972016-01-30 20:31:25 +01009399screen_start(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009400{
9401 screen_cur_row = screen_cur_col = 9999;
9402}
9403
9404/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009405 * Move the cursor to position "row","col" in the screen.
9406 * This tries to find the most efficient way to move, minimizing the number of
9407 * characters sent to the terminal.
9408 */
9409 void
Bram Moolenaar05540972016-01-30 20:31:25 +01009410windgoto(int row, int col)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009411{
Bram Moolenaare2cc9702005-03-15 22:43:58 +00009412 sattr_T *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009413 int i;
9414 int plan;
9415 int cost;
9416 int wouldbe_col;
9417 int noinvcurs;
9418 char_u *bs;
9419 int goto_cost;
9420 int attr;
9421
Bram Moolenaar2c7a7632007-05-10 18:19:11 +00009422#define GOTO_COST 7 /* assume a term_windgoto() takes about 7 chars */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009423#define HIGHL_COST 5 /* assume unhighlight takes 5 chars */
9424
9425#define PLAN_LE 1
9426#define PLAN_CR 2
9427#define PLAN_NL 3
9428#define PLAN_WRITE 4
9429 /* Can't use ScreenLines unless initialized */
9430 if (ScreenLines == NULL)
9431 return;
9432
9433 if (col != screen_cur_col || row != screen_cur_row)
9434 {
9435 /* Check for valid position. */
9436 if (row < 0) /* window without text lines? */
9437 row = 0;
9438 if (row >= screen_Rows)
9439 row = screen_Rows - 1;
9440 if (col >= screen_Columns)
9441 col = screen_Columns - 1;
9442
9443 /* check if no cursor movement is allowed in highlight mode */
9444 if (screen_attr && *T_MS == NUL)
9445 noinvcurs = HIGHL_COST;
9446 else
9447 noinvcurs = 0;
9448 goto_cost = GOTO_COST + noinvcurs;
9449
9450 /*
9451 * Plan how to do the positioning:
9452 * 1. Use CR to move it to column 0, same row.
9453 * 2. Use T_LE to move it a few columns to the left.
9454 * 3. Use NL to move a few lines down, column 0.
9455 * 4. Move a few columns to the right with T_ND or by writing chars.
9456 *
9457 * Don't do this if the cursor went beyond the last column, the cursor
9458 * position is unknown then (some terminals wrap, some don't )
9459 *
Bram Moolenaar2c7a7632007-05-10 18:19:11 +00009460 * First check if the highlighting attributes allow us to write
Bram Moolenaar071d4272004-06-13 20:20:40 +00009461 * characters to move the cursor to the right.
9462 */
9463 if (row >= screen_cur_row && screen_cur_col < Columns)
9464 {
9465 /*
9466 * If the cursor is in the same row, bigger col, we can use CR
9467 * or T_LE.
9468 */
9469 bs = NULL; /* init for GCC */
9470 attr = screen_attr;
9471 if (row == screen_cur_row && col < screen_cur_col)
9472 {
9473 /* "le" is preferred over "bc", because "bc" is obsolete */
9474 if (*T_LE)
9475 bs = T_LE; /* "cursor left" */
9476 else
9477 bs = T_BC; /* "backspace character (old) */
9478 if (*bs)
9479 cost = (screen_cur_col - col) * (int)STRLEN(bs);
9480 else
9481 cost = 999;
9482 if (col + 1 < cost) /* using CR is less characters */
9483 {
9484 plan = PLAN_CR;
9485 wouldbe_col = 0;
9486 cost = 1; /* CR is just one character */
9487 }
9488 else
9489 {
9490 plan = PLAN_LE;
9491 wouldbe_col = col;
9492 }
9493 if (noinvcurs) /* will stop highlighting */
9494 {
9495 cost += noinvcurs;
9496 attr = 0;
9497 }
9498 }
9499
9500 /*
9501 * If the cursor is above where we want to be, we can use CR LF.
9502 */
9503 else if (row > screen_cur_row)
9504 {
9505 plan = PLAN_NL;
9506 wouldbe_col = 0;
9507 cost = (row - screen_cur_row) * 2; /* CR LF */
9508 if (noinvcurs) /* will stop highlighting */
9509 {
9510 cost += noinvcurs;
9511 attr = 0;
9512 }
9513 }
9514
9515 /*
9516 * If the cursor is in the same row, smaller col, just use write.
9517 */
9518 else
9519 {
9520 plan = PLAN_WRITE;
9521 wouldbe_col = screen_cur_col;
9522 cost = 0;
9523 }
9524
9525 /*
9526 * Check if any characters that need to be written have the
9527 * correct attributes. Also avoid UTF-8 characters.
9528 */
9529 i = col - wouldbe_col;
9530 if (i > 0)
9531 cost += i;
9532 if (cost < goto_cost && i > 0)
9533 {
9534 /*
9535 * Check if the attributes are correct without additionally
9536 * stopping highlighting.
9537 */
9538 p = ScreenAttrs + LineOffset[row] + wouldbe_col;
9539 while (i && *p++ == attr)
9540 --i;
9541 if (i != 0)
9542 {
9543 /*
9544 * Try if it works when highlighting is stopped here.
9545 */
9546 if (*--p == 0)
9547 {
9548 cost += noinvcurs;
9549 while (i && *p++ == 0)
9550 --i;
9551 }
9552 if (i != 0)
9553 cost = 999; /* different attributes, don't do it */
9554 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009555 if (enc_utf8)
9556 {
9557 /* Don't use an UTF-8 char for positioning, it's slow. */
9558 for (i = wouldbe_col; i < col; ++i)
9559 if (ScreenLinesUC[LineOffset[row] + i] != 0)
9560 {
9561 cost = 999;
9562 break;
9563 }
9564 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009565 }
9566
9567 /*
9568 * We can do it without term_windgoto()!
9569 */
9570 if (cost < goto_cost)
9571 {
9572 if (plan == PLAN_LE)
9573 {
9574 if (noinvcurs)
9575 screen_stop_highlight();
9576 while (screen_cur_col > col)
9577 {
9578 out_str(bs);
9579 --screen_cur_col;
9580 }
9581 }
9582 else if (plan == PLAN_CR)
9583 {
9584 if (noinvcurs)
9585 screen_stop_highlight();
9586 out_char('\r');
9587 screen_cur_col = 0;
9588 }
9589 else if (plan == PLAN_NL)
9590 {
9591 if (noinvcurs)
9592 screen_stop_highlight();
9593 while (screen_cur_row < row)
9594 {
9595 out_char('\n');
9596 ++screen_cur_row;
9597 }
9598 screen_cur_col = 0;
9599 }
9600
9601 i = col - screen_cur_col;
9602 if (i > 0)
9603 {
9604 /*
9605 * Use cursor-right if it's one character only. Avoids
9606 * removing a line of pixels from the last bold char, when
9607 * using the bold trick in the GUI.
9608 */
9609 if (T_ND[0] != NUL && T_ND[1] == NUL)
9610 {
9611 while (i-- > 0)
9612 out_char(*T_ND);
9613 }
9614 else
9615 {
9616 int off;
9617
9618 off = LineOffset[row] + screen_cur_col;
9619 while (i-- > 0)
9620 {
9621 if (ScreenAttrs[off] != screen_attr)
9622 screen_stop_highlight();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009623 out_flush_check();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009624 out_char(ScreenLines[off]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009625 if (enc_dbcs == DBCS_JPNU
9626 && ScreenLines[off] == 0x8e)
9627 out_char(ScreenLines2[off]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009628 ++off;
9629 }
9630 }
9631 }
9632 }
9633 }
9634 else
9635 cost = 999;
9636
9637 if (cost >= goto_cost)
9638 {
9639 if (noinvcurs)
9640 screen_stop_highlight();
Bram Moolenaar597a4222014-06-25 14:39:50 +02009641 if (row == screen_cur_row && (col > screen_cur_col)
9642 && *T_CRI != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009643 term_cursor_right(col - screen_cur_col);
9644 else
9645 term_windgoto(row, col);
9646 }
9647 screen_cur_row = row;
9648 screen_cur_col = col;
9649 }
9650}
9651
9652/*
9653 * Set cursor to its position in the current window.
9654 */
9655 void
Bram Moolenaar05540972016-01-30 20:31:25 +01009656setcursor(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009657{
Bram Moolenaar987723e2018-03-06 11:43:04 +01009658 setcursor_mayforce(FALSE);
9659}
9660
9661/*
9662 * Set cursor to its position in the current window.
9663 * When "force" is TRUE also when not redrawing.
9664 */
9665 void
9666setcursor_mayforce(int force)
9667{
9668 if (force || redrawing())
Bram Moolenaar071d4272004-06-13 20:20:40 +00009669 {
9670 validate_cursor();
9671 windgoto(W_WINROW(curwin) + curwin->w_wrow,
Bram Moolenaar53f81742017-09-22 14:35:51 +02009672 curwin->w_wincol + (
Bram Moolenaar071d4272004-06-13 20:20:40 +00009673#ifdef FEAT_RIGHTLEFT
Bram Moolenaar561f9db2008-02-20 13:16:29 +00009674 /* With 'rightleft' set and the cursor on a double-wide
9675 * character, position it on the leftmost column. */
Bram Moolenaara12a1612019-01-24 16:39:02 +01009676 curwin->w_p_rl ? ((int)curwin->w_width - curwin->w_wcol
9677 - ((has_mbyte
Bram Moolenaar561f9db2008-02-20 13:16:29 +00009678 && (*mb_ptr2cells)(ml_get_cursor()) == 2
Bram Moolenaara12a1612019-01-24 16:39:02 +01009679 && vim_isprintc(gchar_cursor())) ? 2 : 1)) :
Bram Moolenaar071d4272004-06-13 20:20:40 +00009680#endif
9681 curwin->w_wcol));
9682 }
9683}
9684
9685
9686/*
Bram Moolenaar86033562017-07-12 20:24:41 +02009687 * Insert 'line_count' lines at 'row' in window 'wp'.
9688 * If 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated.
9689 * If 'mayclear' is TRUE the screen will be cleared if it is faster than
Bram Moolenaar071d4272004-06-13 20:20:40 +00009690 * scrolling.
9691 * Returns FAIL if the lines are not inserted, OK for success.
9692 */
9693 int
Bram Moolenaar05540972016-01-30 20:31:25 +01009694win_ins_lines(
9695 win_T *wp,
9696 int row,
9697 int line_count,
9698 int invalid,
9699 int mayclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009700{
9701 int did_delete;
9702 int nextrow;
9703 int lastrow;
9704 int retval;
9705
9706 if (invalid)
9707 wp->w_lines_valid = 0;
9708
9709 if (wp->w_height < 5)
9710 return FAIL;
9711
9712 if (line_count > wp->w_height - row)
9713 line_count = wp->w_height - row;
9714
Bram Moolenaarcfce7172017-08-17 20:31:48 +02009715 retval = win_do_lines(wp, row, line_count, mayclear, FALSE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009716 if (retval != MAYBE)
9717 return retval;
9718
9719 /*
9720 * If there is a next window or a status line, we first try to delete the
9721 * lines at the bottom to avoid messing what is after the window.
9722 * If this fails and there are following windows, don't do anything to avoid
9723 * messing up those windows, better just redraw.
9724 */
9725 did_delete = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009726 if (wp->w_next != NULL || wp->w_status_height)
9727 {
9728 if (screen_del_lines(0, W_WINROW(wp) + wp->w_height - line_count,
Bram Moolenaarcfce7172017-08-17 20:31:48 +02009729 line_count, (int)Rows, FALSE, 0, NULL) == OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009730 did_delete = TRUE;
9731 else if (wp->w_next)
9732 return FAIL;
9733 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009734 /*
9735 * if no lines deleted, blank the lines that will end up below the window
9736 */
9737 if (!did_delete)
9738 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009739 wp->w_redr_status = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009740 redraw_cmdline = TRUE;
Bram Moolenaare0de17d2017-09-24 16:24:34 +02009741 nextrow = W_WINROW(wp) + wp->w_height + wp->w_status_height;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009742 lastrow = nextrow + line_count;
9743 if (lastrow > Rows)
9744 lastrow = Rows;
9745 screen_fill(nextrow - line_count, lastrow - line_count,
Bram Moolenaar53f81742017-09-22 14:35:51 +02009746 wp->w_wincol, (int)W_ENDCOL(wp),
Bram Moolenaar071d4272004-06-13 20:20:40 +00009747 ' ', ' ', 0);
9748 }
9749
Bram Moolenaarcfce7172017-08-17 20:31:48 +02009750 if (screen_ins_lines(0, W_WINROW(wp) + row, line_count, (int)Rows, 0, NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009751 == FAIL)
9752 {
9753 /* deletion will have messed up other windows */
9754 if (did_delete)
9755 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009756 wp->w_redr_status = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009757 win_rest_invalid(W_NEXT(wp));
9758 }
9759 return FAIL;
9760 }
9761
9762 return OK;
9763}
9764
9765/*
Bram Moolenaar86033562017-07-12 20:24:41 +02009766 * Delete "line_count" window lines at "row" in window "wp".
Bram Moolenaar071d4272004-06-13 20:20:40 +00009767 * If "invalid" is TRUE curwin->w_lines[] is invalidated.
9768 * If "mayclear" is TRUE the screen will be cleared if it is faster than
9769 * scrolling
9770 * Return OK for success, FAIL if the lines are not deleted.
9771 */
9772 int
Bram Moolenaar05540972016-01-30 20:31:25 +01009773win_del_lines(
9774 win_T *wp,
9775 int row,
9776 int line_count,
9777 int invalid,
Bram Moolenaarcfce7172017-08-17 20:31:48 +02009778 int mayclear,
9779 int clear_attr) /* for clearing lines */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009780{
9781 int retval;
9782
9783 if (invalid)
9784 wp->w_lines_valid = 0;
9785
9786 if (line_count > wp->w_height - row)
9787 line_count = wp->w_height - row;
9788
Bram Moolenaarcfce7172017-08-17 20:31:48 +02009789 retval = win_do_lines(wp, row, line_count, mayclear, TRUE, clear_attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009790 if (retval != MAYBE)
9791 return retval;
9792
9793 if (screen_del_lines(0, W_WINROW(wp) + row, line_count,
Bram Moolenaarcfce7172017-08-17 20:31:48 +02009794 (int)Rows, FALSE, clear_attr, NULL) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009795 return FAIL;
9796
Bram Moolenaar071d4272004-06-13 20:20:40 +00009797 /*
9798 * If there are windows or status lines below, try to put them at the
9799 * correct place. If we can't do that, they have to be redrawn.
9800 */
9801 if (wp->w_next || wp->w_status_height || cmdline_row < Rows - 1)
9802 {
9803 if (screen_ins_lines(0, W_WINROW(wp) + wp->w_height - line_count,
Bram Moolenaarcfce7172017-08-17 20:31:48 +02009804 line_count, (int)Rows, clear_attr, NULL) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009805 {
9806 wp->w_redr_status = TRUE;
9807 win_rest_invalid(wp->w_next);
9808 }
9809 }
9810 /*
9811 * If this is the last window and there is no status line, redraw the
9812 * command line later.
9813 */
9814 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00009815 redraw_cmdline = TRUE;
9816 return OK;
9817}
9818
9819/*
9820 * Common code for win_ins_lines() and win_del_lines().
9821 * Returns OK or FAIL when the work has been done.
9822 * Returns MAYBE when not finished yet.
9823 */
9824 static int
Bram Moolenaar05540972016-01-30 20:31:25 +01009825win_do_lines(
9826 win_T *wp,
9827 int row,
9828 int line_count,
9829 int mayclear,
Bram Moolenaarcfce7172017-08-17 20:31:48 +02009830 int del,
9831 int clear_attr)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009832{
9833 int retval;
9834
9835 if (!redrawing() || line_count <= 0)
9836 return FAIL;
9837
Bram Moolenaar29ae3772017-04-30 19:39:39 +02009838 /* When inserting lines would result in loss of command output, just redraw
9839 * the lines. */
9840 if (no_win_do_lines_ins && !del)
9841 return FAIL;
9842
Bram Moolenaar071d4272004-06-13 20:20:40 +00009843 /* only a few lines left: redraw is faster */
Bram Moolenaar4033c552017-09-16 20:54:51 +02009844 if (mayclear && Rows - line_count < 5 && wp->w_width == Columns)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009845 {
Bram Moolenaar29ae3772017-04-30 19:39:39 +02009846 if (!no_win_do_lines_ins)
9847 screenclear(); /* will set wp->w_lines_valid to 0 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009848 return FAIL;
9849 }
9850
9851 /*
9852 * Delete all remaining lines
9853 */
9854 if (row + line_count >= wp->w_height)
9855 {
9856 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height,
Bram Moolenaar53f81742017-09-22 14:35:51 +02009857 wp->w_wincol, (int)W_ENDCOL(wp),
Bram Moolenaar071d4272004-06-13 20:20:40 +00009858 ' ', ' ', 0);
9859 return OK;
9860 }
9861
9862 /*
Bram Moolenaar29ae3772017-04-30 19:39:39 +02009863 * When scrolling, the message on the command line should be cleared,
Bram Moolenaar071d4272004-06-13 20:20:40 +00009864 * otherwise it will stay there forever.
Bram Moolenaar29ae3772017-04-30 19:39:39 +02009865 * Don't do this when avoiding to insert lines.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009866 */
Bram Moolenaar29ae3772017-04-30 19:39:39 +02009867 if (!no_win_do_lines_ins)
9868 clear_cmdline = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009869
9870 /*
9871 * If the terminal can set a scroll region, use that.
9872 * Always do this in a vertically split window. This will redraw from
9873 * ScreenLines[] when t_CV isn't defined. That's faster than using
9874 * win_line().
9875 * Don't use a scroll region when we are going to redraw the text, writing
Bram Moolenaar48e330a2016-02-23 14:53:34 +01009876 * a character in the lower right corner of the scroll region may cause a
9877 * scroll-up .
Bram Moolenaar071d4272004-06-13 20:20:40 +00009878 */
Bram Moolenaar02631462017-09-22 15:20:32 +02009879 if (scroll_region || wp->w_width != Columns)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009880 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009881 if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009882 scroll_region_set(wp, row);
9883 if (del)
9884 retval = screen_del_lines(W_WINROW(wp) + row, 0, line_count,
Bram Moolenaarcfce7172017-08-17 20:31:48 +02009885 wp->w_height - row, FALSE, clear_attr, wp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009886 else
9887 retval = screen_ins_lines(W_WINROW(wp) + row, 0, line_count,
Bram Moolenaarcfce7172017-08-17 20:31:48 +02009888 wp->w_height - row, clear_attr, wp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009889 if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009890 scroll_region_reset();
9891 return retval;
9892 }
9893
Bram Moolenaar071d4272004-06-13 20:20:40 +00009894 if (wp->w_next != NULL && p_tf) /* don't delete/insert on fast terminal */
9895 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009896
9897 return MAYBE;
9898}
9899
9900/*
9901 * window 'wp' and everything after it is messed up, mark it for redraw
9902 */
9903 static void
Bram Moolenaar05540972016-01-30 20:31:25 +01009904win_rest_invalid(win_T *wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009905{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009906 while (wp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009907 {
9908 redraw_win_later(wp, NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009909 wp->w_redr_status = TRUE;
9910 wp = wp->w_next;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009911 }
9912 redraw_cmdline = TRUE;
9913}
9914
9915/*
9916 * The rest of the routines in this file perform screen manipulations. The
9917 * given operation is performed physically on the screen. The corresponding
9918 * change is also made to the internal screen image. In this way, the editor
9919 * anticipates the effect of editing changes on the appearance of the screen.
9920 * That way, when we call screenupdate a complete redraw isn't usually
9921 * necessary. Another advantage is that we can keep adding code to anticipate
9922 * screen changes, and in the meantime, everything still works.
9923 */
9924
9925/*
9926 * types for inserting or deleting lines
9927 */
9928#define USE_T_CAL 1
9929#define USE_T_CDL 2
9930#define USE_T_AL 3
9931#define USE_T_CE 4
9932#define USE_T_DL 5
9933#define USE_T_SR 6
9934#define USE_NL 7
9935#define USE_T_CD 8
9936#define USE_REDRAW 9
9937
9938/*
9939 * insert lines on the screen and update ScreenLines[]
9940 * 'end' is the line after the scrolled part. Normally it is Rows.
9941 * When scrolling region used 'off' is the offset from the top for the region.
9942 * 'row' and 'end' are relative to the start of the region.
9943 *
9944 * return FAIL for failure, OK for success.
9945 */
Bram Moolenaar87e25fd2005-07-27 21:13:01 +00009946 int
Bram Moolenaar05540972016-01-30 20:31:25 +01009947screen_ins_lines(
9948 int off,
9949 int row,
9950 int line_count,
9951 int end,
Bram Moolenaarcfce7172017-08-17 20:31:48 +02009952 int clear_attr,
Bram Moolenaar05540972016-01-30 20:31:25 +01009953 win_T *wp) /* NULL or window to use width from */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009954{
9955 int i;
9956 int j;
9957 unsigned temp;
9958 int cursor_row;
Bram Moolenaarbfa42462018-06-16 16:20:52 +02009959 int cursor_col = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009960 int type;
9961 int result_empty;
9962 int can_ce = can_clear(T_CE);
9963
9964 /*
9965 * FAIL if
9966 * - there is no valid screen
9967 * - the screen has to be redrawn completely
9968 * - the line count is less than one
9969 * - the line count is more than 'ttyscroll'
Bram Moolenaar80dd3f92017-07-19 12:51:52 +02009970 * - redrawing for a callback and there is a modeless selection
Bram Moolenaar071d4272004-06-13 20:20:40 +00009971 */
Bram Moolenaar80dd3f92017-07-19 12:51:52 +02009972 if (!screen_valid(TRUE) || line_count <= 0 || line_count > p_ttyscroll
9973#ifdef FEAT_CLIPBOARD
9974 || (clip_star.state != SELECT_CLEARED
9975 && redrawing_for_callback > 0)
9976#endif
9977 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009978 return FAIL;
9979
9980 /*
9981 * There are seven ways to insert lines:
9982 * 0. When in a vertically split window and t_CV isn't set, redraw the
9983 * characters from ScreenLines[].
9984 * 1. Use T_CD (clear to end of display) if it exists and the result of
9985 * the insert is just empty lines
9986 * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not
9987 * present or line_count > 1. It looks better if we do all the inserts
9988 * at once.
9989 * 3. Use T_CDL (delete multiple lines) if it exists and the result of the
9990 * insert is just empty lines and T_CE is not present or line_count >
9991 * 1.
9992 * 4. Use T_AL (insert line) if it exists.
9993 * 5. Use T_CE (erase line) if it exists and the result of the insert is
9994 * just empty lines.
9995 * 6. Use T_DL (delete line) if it exists and the result of the insert is
9996 * just empty lines.
9997 * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and
9998 * the 'da' flag is not set or we have clear line capability.
9999 * 8. redraw the characters from ScreenLines[].
10000 *
10001 * Careful: In a hpterm scroll reverse doesn't work as expected, it moves
10002 * the scrollbar for the window. It does have insert line, use that if it
10003 * exists.
10004 */
10005 result_empty = (row + line_count >= end);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010006 if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL)
10007 type = USE_REDRAW;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010008 else if (can_clear(T_CD) && result_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010009 type = USE_T_CD;
10010 else if (*T_CAL != NUL && (line_count > 1 || *T_AL == NUL))
10011 type = USE_T_CAL;
10012 else if (*T_CDL != NUL && result_empty && (line_count > 1 || !can_ce))
10013 type = USE_T_CDL;
10014 else if (*T_AL != NUL)
10015 type = USE_T_AL;
10016 else if (can_ce && result_empty)
10017 type = USE_T_CE;
10018 else if (*T_DL != NUL && result_empty)
10019 type = USE_T_DL;
10020 else if (*T_SR != NUL && row == 0 && (*T_DA == NUL || can_ce))
10021 type = USE_T_SR;
10022 else
10023 return FAIL;
10024
10025 /*
10026 * For clearing the lines screen_del_lines() is used. This will also take
10027 * care of t_db if necessary.
10028 */
10029 if (type == USE_T_CD || type == USE_T_CDL ||
10030 type == USE_T_CE || type == USE_T_DL)
Bram Moolenaarcfce7172017-08-17 20:31:48 +020010031 return screen_del_lines(off, row, line_count, end, FALSE, 0, wp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010032
10033 /*
10034 * If text is retained below the screen, first clear or delete as many
10035 * lines at the bottom of the window as are about to be inserted so that
10036 * the deleted lines won't later surface during a screen_del_lines.
10037 */
10038 if (*T_DB)
Bram Moolenaarcfce7172017-08-17 20:31:48 +020010039 screen_del_lines(off, end - line_count, line_count, end, FALSE, 0, wp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010040
10041#ifdef FEAT_CLIPBOARD
10042 /* Remove a modeless selection when inserting lines halfway the screen
10043 * or not the full width of the screen. */
Bram Moolenaar4033c552017-09-16 20:54:51 +020010044 if (off + row > 0 || (wp != NULL && wp->w_width != Columns))
Bram Moolenaarc0885aa2012-07-10 16:49:23 +020010045 clip_clear_selection(&clip_star);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010046 else
10047 clip_scroll_selection(-line_count);
10048#endif
10049
Bram Moolenaar071d4272004-06-13 20:20:40 +000010050#ifdef FEAT_GUI
10051 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the
10052 * scrolling is actually carried out. */
Bram Moolenaar107abd22016-08-12 14:08:25 +020010053 gui_dont_update_cursor(row + off <= gui.cursor_row);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010054#endif
10055
Bram Moolenaarbfa42462018-06-16 16:20:52 +020010056 if (wp != NULL && wp->w_wincol != 0 && *T_CSV != NUL && *T_CCS == NUL)
10057 cursor_col = wp->w_wincol;
10058
Bram Moolenaar071d4272004-06-13 20:20:40 +000010059 if (*T_CCS != NUL) /* cursor relative to region */
10060 cursor_row = row;
10061 else
10062 cursor_row = row + off;
10063
10064 /*
10065 * Shift LineOffset[] line_count down to reflect the inserted lines.
10066 * Clear the inserted lines in ScreenLines[].
10067 */
10068 row += off;
10069 end += off;
10070 for (i = 0; i < line_count; ++i)
10071 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000010072 if (wp != NULL && wp->w_width != Columns)
10073 {
10074 /* need to copy part of a line */
10075 j = end - 1 - i;
10076 while ((j -= line_count) >= row)
10077 linecopy(j + line_count, j, wp);
10078 j += line_count;
10079 if (can_clear((char_u *)" "))
Bram Moolenaarcfce7172017-08-17 20:31:48 +020010080 lineclear(LineOffset[j] + wp->w_wincol, wp->w_width,
10081 clear_attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010082 else
10083 lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width);
10084 LineWraps[j] = FALSE;
10085 }
10086 else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010087 {
10088 j = end - 1 - i;
10089 temp = LineOffset[j];
10090 while ((j -= line_count) >= row)
10091 {
10092 LineOffset[j + line_count] = LineOffset[j];
10093 LineWraps[j + line_count] = LineWraps[j];
10094 }
10095 LineOffset[j + line_count] = temp;
10096 LineWraps[j + line_count] = FALSE;
10097 if (can_clear((char_u *)" "))
Bram Moolenaarcfce7172017-08-17 20:31:48 +020010098 lineclear(temp, (int)Columns, clear_attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010099 else
10100 lineinvalid(temp, (int)Columns);
10101 }
10102 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010103
10104 screen_stop_highlight();
Bram Moolenaarbfa42462018-06-16 16:20:52 +020010105 windgoto(cursor_row, cursor_col);
Bram Moolenaarcfce7172017-08-17 20:31:48 +020010106 if (clear_attr != 0)
10107 screen_start_highlight(clear_attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010108
Bram Moolenaar071d4272004-06-13 20:20:40 +000010109 /* redraw the characters */
10110 if (type == USE_REDRAW)
10111 redraw_block(row, end, wp);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010112 else if (type == USE_T_CAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010113 {
10114 term_append_lines(line_count);
10115 screen_start(); /* don't know where cursor is now */
10116 }
10117 else
10118 {
10119 for (i = 0; i < line_count; i++)
10120 {
10121 if (type == USE_T_AL)
10122 {
10123 if (i && cursor_row != 0)
Bram Moolenaarbfa42462018-06-16 16:20:52 +020010124 windgoto(cursor_row, cursor_col);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010125 out_str(T_AL);
10126 }
10127 else /* type == USE_T_SR */
10128 out_str(T_SR);
10129 screen_start(); /* don't know where cursor is now */
10130 }
10131 }
10132
10133 /*
10134 * With scroll-reverse and 'da' flag set we need to clear the lines that
10135 * have been scrolled down into the region.
10136 */
10137 if (type == USE_T_SR && *T_DA)
10138 {
10139 for (i = 0; i < line_count; ++i)
10140 {
Bram Moolenaarbfa42462018-06-16 16:20:52 +020010141 windgoto(off + i, cursor_col);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010142 out_str(T_CE);
10143 screen_start(); /* don't know where cursor is now */
10144 }
10145 }
10146
10147#ifdef FEAT_GUI
10148 gui_can_update_cursor();
10149 if (gui.in_use)
10150 out_flush(); /* always flush after a scroll */
10151#endif
10152 return OK;
10153}
10154
10155/*
Bram Moolenaar107abd22016-08-12 14:08:25 +020010156 * Delete lines on the screen and update ScreenLines[].
10157 * "end" is the line after the scrolled part. Normally it is Rows.
10158 * When scrolling region used "off" is the offset from the top for the region.
10159 * "row" and "end" are relative to the start of the region.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010160 *
10161 * Return OK for success, FAIL if the lines are not deleted.
10162 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010163 int
Bram Moolenaar05540972016-01-30 20:31:25 +010010164screen_del_lines(
10165 int off,
10166 int row,
10167 int line_count,
10168 int end,
10169 int force, /* even when line_count > p_ttyscroll */
Bram Moolenaarcfce7172017-08-17 20:31:48 +020010170 int clear_attr, /* used for clearing lines */
Bram Moolenaar05540972016-01-30 20:31:25 +010010171 win_T *wp UNUSED) /* NULL or window to use width from */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010172{
10173 int j;
10174 int i;
10175 unsigned temp;
10176 int cursor_row;
Bram Moolenaarbfa42462018-06-16 16:20:52 +020010177 int cursor_col = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010178 int cursor_end;
10179 int result_empty; /* result is empty until end of region */
10180 int can_delete; /* deleting line codes can be used */
10181 int type;
10182
10183 /*
10184 * FAIL if
10185 * - there is no valid screen
10186 * - the screen has to be redrawn completely
10187 * - the line count is less than one
10188 * - the line count is more than 'ttyscroll'
Bram Moolenaar80dd3f92017-07-19 12:51:52 +020010189 * - redrawing for a callback and there is a modeless selection
Bram Moolenaar071d4272004-06-13 20:20:40 +000010190 */
Bram Moolenaar80dd3f92017-07-19 12:51:52 +020010191 if (!screen_valid(TRUE) || line_count <= 0
10192 || (!force && line_count > p_ttyscroll)
10193#ifdef FEAT_CLIPBOARD
10194 || (clip_star.state != SELECT_CLEARED
10195 && redrawing_for_callback > 0)
10196#endif
10197 )
Bram Moolenaar071d4272004-06-13 20:20:40 +000010198 return FAIL;
10199
10200 /*
10201 * Check if the rest of the current region will become empty.
10202 */
10203 result_empty = row + line_count >= end;
10204
10205 /*
10206 * We can delete lines only when 'db' flag not set or when 'ce' option
10207 * available.
10208 */
10209 can_delete = (*T_DB == NUL || can_clear(T_CE));
10210
10211 /*
10212 * There are six ways to delete lines:
10213 * 0. When in a vertically split window and t_CV isn't set, redraw the
10214 * characters from ScreenLines[].
10215 * 1. Use T_CD if it exists and the result is empty.
10216 * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist.
10217 * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or
10218 * none of the other ways work.
10219 * 4. Use T_CE (erase line) if the result is empty.
10220 * 5. Use T_DL (delete line) if it exists.
10221 * 6. redraw the characters from ScreenLines[].
10222 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010223 if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL)
10224 type = USE_REDRAW;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010225 else if (can_clear(T_CD) && result_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010226 type = USE_T_CD;
10227#if defined(__BEOS__) && defined(BEOS_DR8)
10228 /*
10229 * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in
10230 * its internal termcap... this works okay for tests which test *T_DB !=
10231 * NUL. It has the disadvantage that the user cannot use any :set t_*
10232 * command to get T_DB (back) to empty_option, only :set term=... will do
10233 * the trick...
10234 * Anyway, this hack will hopefully go away with the next OS release.
10235 * (Olaf Seibert)
10236 */
10237 else if (row == 0 && T_DB == empty_option
10238 && (line_count == 1 || *T_CDL == NUL))
10239#else
10240 else if (row == 0 && (
10241#ifndef AMIGA
10242 /* On the Amiga, somehow '\n' on the last line doesn't always scroll
10243 * up, so use delete-line command */
10244 line_count == 1 ||
10245#endif
10246 *T_CDL == NUL))
10247#endif
10248 type = USE_NL;
10249 else if (*T_CDL != NUL && line_count > 1 && can_delete)
10250 type = USE_T_CDL;
10251 else if (can_clear(T_CE) && result_empty
Bram Moolenaar4033c552017-09-16 20:54:51 +020010252 && (wp == NULL || wp->w_width == Columns))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010253 type = USE_T_CE;
10254 else if (*T_DL != NUL && can_delete)
10255 type = USE_T_DL;
10256 else if (*T_CDL != NUL && can_delete)
10257 type = USE_T_CDL;
10258 else
10259 return FAIL;
10260
10261#ifdef FEAT_CLIPBOARD
10262 /* Remove a modeless selection when deleting lines halfway the screen or
10263 * not the full width of the screen. */
Bram Moolenaar4033c552017-09-16 20:54:51 +020010264 if (off + row > 0 || (wp != NULL && wp->w_width != Columns))
Bram Moolenaarc0885aa2012-07-10 16:49:23 +020010265 clip_clear_selection(&clip_star);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010266 else
10267 clip_scroll_selection(line_count);
10268#endif
10269
Bram Moolenaar071d4272004-06-13 20:20:40 +000010270#ifdef FEAT_GUI
10271 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the
10272 * scrolling is actually carried out. */
Bram Moolenaar107abd22016-08-12 14:08:25 +020010273 gui_dont_update_cursor(gui.cursor_row >= row + off
10274 && gui.cursor_row < end + off);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010275#endif
10276
Bram Moolenaarbfa42462018-06-16 16:20:52 +020010277 if (wp != NULL && wp->w_wincol != 0 && *T_CSV != NUL && *T_CCS == NUL)
10278 cursor_col = wp->w_wincol;
10279
Bram Moolenaar071d4272004-06-13 20:20:40 +000010280 if (*T_CCS != NUL) /* cursor relative to region */
10281 {
10282 cursor_row = row;
10283 cursor_end = end;
10284 }
10285 else
10286 {
10287 cursor_row = row + off;
10288 cursor_end = end + off;
10289 }
10290
10291 /*
10292 * Now shift LineOffset[] line_count up to reflect the deleted lines.
10293 * Clear the inserted lines in ScreenLines[].
10294 */
10295 row += off;
10296 end += off;
10297 for (i = 0; i < line_count; ++i)
10298 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000010299 if (wp != NULL && wp->w_width != Columns)
10300 {
10301 /* need to copy part of a line */
10302 j = row + i;
10303 while ((j += line_count) <= end - 1)
10304 linecopy(j - line_count, j, wp);
10305 j -= line_count;
10306 if (can_clear((char_u *)" "))
Bram Moolenaarcfce7172017-08-17 20:31:48 +020010307 lineclear(LineOffset[j] + wp->w_wincol, wp->w_width,
10308 clear_attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010309 else
10310 lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width);
10311 LineWraps[j] = FALSE;
10312 }
10313 else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010314 {
10315 /* whole width, moving the line pointers is faster */
10316 j = row + i;
10317 temp = LineOffset[j];
10318 while ((j += line_count) <= end - 1)
10319 {
10320 LineOffset[j - line_count] = LineOffset[j];
10321 LineWraps[j - line_count] = LineWraps[j];
10322 }
10323 LineOffset[j - line_count] = temp;
10324 LineWraps[j - line_count] = FALSE;
10325 if (can_clear((char_u *)" "))
Bram Moolenaarcfce7172017-08-17 20:31:48 +020010326 lineclear(temp, (int)Columns, clear_attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010327 else
10328 lineinvalid(temp, (int)Columns);
10329 }
10330 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010331
Bram Moolenaarcfce7172017-08-17 20:31:48 +020010332 if (screen_attr != clear_attr)
10333 screen_stop_highlight();
10334 if (clear_attr != 0)
10335 screen_start_highlight(clear_attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010336
Bram Moolenaar071d4272004-06-13 20:20:40 +000010337 /* redraw the characters */
10338 if (type == USE_REDRAW)
10339 redraw_block(row, end, wp);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010340 else if (type == USE_T_CD) /* delete the lines */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010341 {
Bram Moolenaarbfa42462018-06-16 16:20:52 +020010342 windgoto(cursor_row, cursor_col);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010343 out_str(T_CD);
10344 screen_start(); /* don't know where cursor is now */
10345 }
10346 else if (type == USE_T_CDL)
10347 {
Bram Moolenaarbfa42462018-06-16 16:20:52 +020010348 windgoto(cursor_row, cursor_col);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010349 term_delete_lines(line_count);
10350 screen_start(); /* don't know where cursor is now */
10351 }
10352 /*
10353 * Deleting lines at top of the screen or scroll region: Just scroll
10354 * the whole screen (scroll region) up by outputting newlines on the
10355 * last line.
10356 */
10357 else if (type == USE_NL)
10358 {
Bram Moolenaarbfa42462018-06-16 16:20:52 +020010359 windgoto(cursor_end - 1, cursor_col);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010360 for (i = line_count; --i >= 0; )
10361 out_char('\n'); /* cursor will remain on same line */
10362 }
10363 else
10364 {
10365 for (i = line_count; --i >= 0; )
10366 {
10367 if (type == USE_T_DL)
10368 {
Bram Moolenaarbfa42462018-06-16 16:20:52 +020010369 windgoto(cursor_row, cursor_col);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010370 out_str(T_DL); /* delete a line */
10371 }
10372 else /* type == USE_T_CE */
10373 {
Bram Moolenaarbfa42462018-06-16 16:20:52 +020010374 windgoto(cursor_row + i, cursor_col);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010375 out_str(T_CE); /* erase a line */
10376 }
10377 screen_start(); /* don't know where cursor is now */
10378 }
10379 }
10380
10381 /*
10382 * If the 'db' flag is set, we need to clear the lines that have been
10383 * scrolled up at the bottom of the region.
10384 */
10385 if (*T_DB && (type == USE_T_DL || type == USE_T_CDL))
10386 {
10387 for (i = line_count; i > 0; --i)
10388 {
Bram Moolenaarbfa42462018-06-16 16:20:52 +020010389 windgoto(cursor_end - i, cursor_col);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010390 out_str(T_CE); /* erase a line */
10391 screen_start(); /* don't know where cursor is now */
10392 }
10393 }
10394
10395#ifdef FEAT_GUI
10396 gui_can_update_cursor();
10397 if (gui.in_use)
10398 out_flush(); /* always flush after a scroll */
10399#endif
10400
10401 return OK;
10402}
10403
10404/*
Bram Moolenaarcb574f42019-01-25 22:29:57 +010010405 * Return TRUE when postponing displaying the mode message: when not redrawing
10406 * or inside a mapping.
10407 */
10408 int
10409skip_showmode()
10410{
10411 // Call char_avail() only when we are going to show something, because it
10412 // takes a bit of time. redrawing() may also call char_avail_avail().
10413 if (global_busy
10414 || msg_silent != 0
10415 || !redrawing()
10416 || (char_avail() && !KeyTyped))
10417 {
Bram Moolenaar4c25bd72019-04-20 23:38:07 +020010418 redraw_mode = TRUE; // show mode later
Bram Moolenaarcb574f42019-01-25 22:29:57 +010010419 return TRUE;
10420 }
10421 return FALSE;
10422}
10423
10424/*
Bram Moolenaar81226e02018-02-20 21:44:45 +010010425 * Show the current mode and ruler.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010426 *
10427 * If clear_cmdline is TRUE, clear the rest of the cmdline.
10428 * If clear_cmdline is FALSE there may be a message there that needs to be
10429 * cleared only if a mode is shown.
Bram Moolenaar4c25bd72019-04-20 23:38:07 +020010430 * If redraw_mode is TRUE show or clear the mode.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010431 * Return the length of the message (0 if no message).
10432 */
10433 int
Bram Moolenaar05540972016-01-30 20:31:25 +010010434showmode(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010435{
10436 int need_clear;
10437 int length = 0;
10438 int do_mode;
10439 int attr;
10440 int nwr_save;
10441#ifdef FEAT_INS_EXPAND
10442 int sub_attr;
10443#endif
10444
Bram Moolenaar7df351e2006-01-23 22:30:28 +000010445 do_mode = ((p_smd && msg_silent == 0)
10446 && ((State & INSERT)
Bram Moolenaar942b4542018-06-17 16:23:34 +020010447 || restart_edit != NUL
Bram Moolenaarf7ff6e82014-03-23 15:13:05 +010010448 || VIsual_active));
Bram Moolenaar0b6d9112018-05-22 20:35:17 +020010449 if (do_mode || reg_recording != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010450 {
Bram Moolenaarcb574f42019-01-25 22:29:57 +010010451 if (skip_showmode())
10452 return 0; // show mode later
Bram Moolenaar071d4272004-06-13 20:20:40 +000010453
10454 nwr_save = need_wait_return;
10455
10456 /* wait a bit before overwriting an important message */
10457 check_for_delay(FALSE);
10458
10459 /* if the cmdline is more than one line high, erase top lines */
10460 need_clear = clear_cmdline;
10461 if (clear_cmdline && cmdline_row < Rows - 1)
10462 msg_clr_cmdline(); /* will reset clear_cmdline */
10463
10464 /* Position on the last line in the window, column 0 */
10465 msg_pos_mode();
10466 cursor_off();
Bram Moolenaar8820b482017-03-16 17:23:31 +010010467 attr = HL_ATTR(HLF_CM); /* Highlight mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010468 if (do_mode)
10469 {
Bram Moolenaar32526b32019-01-19 17:43:09 +010010470 msg_puts_attr("--", attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010471#if defined(FEAT_XIM)
Bram Moolenaarc236c162008-07-13 17:41:49 +000010472 if (
Bram Moolenaar09092152010-08-08 16:38:42 +020010473# ifdef FEAT_GUI_GTK
Bram Moolenaarc236c162008-07-13 17:41:49 +000010474 preedit_get_status()
Bram Moolenaar09092152010-08-08 16:38:42 +020010475# else
Bram Moolenaarc236c162008-07-13 17:41:49 +000010476 im_get_status()
Bram Moolenaarc236c162008-07-13 17:41:49 +000010477# endif
Bram Moolenaar09092152010-08-08 16:38:42 +020010478 )
Bram Moolenaar0eda7ac2010-06-26 05:38:18 +020010479# ifdef FEAT_GUI_GTK /* most of the time, it's not XIM being used */
Bram Moolenaar32526b32019-01-19 17:43:09 +010010480 msg_puts_attr(" IM", attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010481# else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010482 msg_puts_attr(" XIM", attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010483# endif
10484#endif
10485#if defined(FEAT_HANGULIN) && defined(FEAT_GUI)
10486 if (gui.in_use)
10487 {
10488 if (hangul_input_state_get())
Bram Moolenaar72f4cc42015-11-10 14:35:18 +010010489 {
10490 /* HANGUL */
10491 if (enc_utf8)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010492 msg_puts_attr(" \355\225\234\352\270\200", attr);
Bram Moolenaar72f4cc42015-11-10 14:35:18 +010010493 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010494 msg_puts_attr(" \307\321\261\333", attr);
Bram Moolenaar72f4cc42015-11-10 14:35:18 +010010495 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010496 }
10497#endif
10498#ifdef FEAT_INS_EXPAND
Bram Moolenaarea389e92014-05-28 21:40:52 +020010499 /* CTRL-X in Insert mode */
10500 if (edit_submode != NULL && !shortmess(SHM_COMPLETIONMENU))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010501 {
10502 /* These messages can get long, avoid a wrap in a narrow
10503 * window. Prefer showing edit_submode_extra. */
10504 length = (Rows - msg_row) * Columns - 3;
10505 if (edit_submode_extra != NULL)
10506 length -= vim_strsize(edit_submode_extra);
10507 if (length > 0)
10508 {
10509 if (edit_submode_pre != NULL)
10510 length -= vim_strsize(edit_submode_pre);
10511 if (length - vim_strsize(edit_submode) > 0)
10512 {
10513 if (edit_submode_pre != NULL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010514 msg_puts_attr((char *)edit_submode_pre, attr);
10515 msg_puts_attr((char *)edit_submode, attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010516 }
10517 if (edit_submode_extra != NULL)
10518 {
Bram Moolenaar32526b32019-01-19 17:43:09 +010010519 msg_puts_attr(" ", attr); /* add a space in between */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010520 if ((int)edit_submode_highl < (int)HLF_COUNT)
Bram Moolenaar8820b482017-03-16 17:23:31 +010010521 sub_attr = HL_ATTR(edit_submode_highl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010522 else
10523 sub_attr = attr;
Bram Moolenaar32526b32019-01-19 17:43:09 +010010524 msg_puts_attr((char *)edit_submode_extra, sub_attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010525 }
10526 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010527 }
10528 else
10529#endif
10530 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000010531 if (State & VREPLACE_FLAG)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010532 msg_puts_attr(_(" VREPLACE"), attr);
Bram Moolenaar1f0bfe52018-07-29 16:09:22 +020010533 else if (State & REPLACE_FLAG)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010534 msg_puts_attr(_(" REPLACE"), attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010535 else if (State & INSERT)
10536 {
10537#ifdef FEAT_RIGHTLEFT
10538 if (p_ri)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010539 msg_puts_attr(_(" REVERSE"), attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010540#endif
Bram Moolenaar32526b32019-01-19 17:43:09 +010010541 msg_puts_attr(_(" INSERT"), attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010542 }
Bram Moolenaar942b4542018-06-17 16:23:34 +020010543 else if (restart_edit == 'I' || restart_edit == 'A')
Bram Moolenaar32526b32019-01-19 17:43:09 +010010544 msg_puts_attr(_(" (insert)"), attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010545 else if (restart_edit == 'R')
Bram Moolenaar32526b32019-01-19 17:43:09 +010010546 msg_puts_attr(_(" (replace)"), attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010547 else if (restart_edit == 'V')
Bram Moolenaar32526b32019-01-19 17:43:09 +010010548 msg_puts_attr(_(" (vreplace)"), attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010549#ifdef FEAT_RIGHTLEFT
10550 if (p_hkmap)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010551 msg_puts_attr(_(" Hebrew"), attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010552#endif
10553#ifdef FEAT_KEYMAP
10554 if (State & LANGMAP)
10555 {
10556# ifdef FEAT_ARABIC
10557 if (curwin->w_p_arab)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010558 msg_puts_attr(_(" Arabic"), attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010559 else
10560# endif
Bram Moolenaar73ac0c42016-07-24 16:17:59 +020010561 if (get_keymap_str(curwin, (char_u *)" (%s)",
10562 NameBuff, MAXPATHL))
Bram Moolenaar32526b32019-01-19 17:43:09 +010010563 msg_puts_attr((char *)NameBuff, attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010564 }
10565#endif
10566 if ((State & INSERT) && p_paste)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010567 msg_puts_attr(_(" (paste)"), attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010568
Bram Moolenaar071d4272004-06-13 20:20:40 +000010569 if (VIsual_active)
10570 {
10571 char *p;
10572
10573 /* Don't concatenate separate words to avoid translation
10574 * problems. */
10575 switch ((VIsual_select ? 4 : 0)
10576 + (VIsual_mode == Ctrl_V) * 2
10577 + (VIsual_mode == 'V'))
10578 {
10579 case 0: p = N_(" VISUAL"); break;
10580 case 1: p = N_(" VISUAL LINE"); break;
10581 case 2: p = N_(" VISUAL BLOCK"); break;
10582 case 4: p = N_(" SELECT"); break;
10583 case 5: p = N_(" SELECT LINE"); break;
10584 default: p = N_(" SELECT BLOCK"); break;
10585 }
Bram Moolenaar32526b32019-01-19 17:43:09 +010010586 msg_puts_attr(_(p), attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010587 }
Bram Moolenaar32526b32019-01-19 17:43:09 +010010588 msg_puts_attr(" --", attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010589 }
Bram Moolenaard12f5c12006-01-25 22:10:52 +000010590
Bram Moolenaar071d4272004-06-13 20:20:40 +000010591 need_clear = TRUE;
10592 }
Bram Moolenaar0b6d9112018-05-22 20:35:17 +020010593 if (reg_recording != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010594#ifdef FEAT_INS_EXPAND
10595 && edit_submode == NULL /* otherwise it gets too long */
10596#endif
10597 )
10598 {
Bram Moolenaara0ed84a2015-11-19 17:56:13 +010010599 recording_mode(attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010600 need_clear = TRUE;
10601 }
Bram Moolenaard12f5c12006-01-25 22:10:52 +000010602
10603 mode_displayed = TRUE;
Bram Moolenaar4c25bd72019-04-20 23:38:07 +020010604 if (need_clear || clear_cmdline || redraw_mode)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010605 msg_clr_eos();
10606 msg_didout = FALSE; /* overwrite this message */
10607 length = msg_col;
10608 msg_col = 0;
10609 need_wait_return = nwr_save; /* never ask for hit-return for this */
10610 }
10611 else if (clear_cmdline && msg_silent == 0)
10612 /* Clear the whole command line. Will reset "clear_cmdline". */
10613 msg_clr_cmdline();
Bram Moolenaar4c25bd72019-04-20 23:38:07 +020010614 else if (redraw_mode)
10615 {
10616 msg_pos_mode();
10617 msg_clr_eos();
10618 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010619
10620#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000010621 /* In Visual mode the size of the selected area must be redrawn. */
10622 if (VIsual_active)
10623 clear_showcmd();
Bram Moolenaar071d4272004-06-13 20:20:40 +000010624
10625 /* If the last window has no status line, the ruler is after the mode
10626 * message and must be redrawn */
Bram Moolenaar4033c552017-09-16 20:54:51 +020010627 if (redrawing() && lastwin->w_status_height == 0)
Bram Moolenaar491ac282018-06-17 14:47:55 +020010628 win_redr_ruler(lastwin, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010629#endif
10630 redraw_cmdline = FALSE;
Bram Moolenaar4c25bd72019-04-20 23:38:07 +020010631 redraw_mode = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010632 clear_cmdline = FALSE;
10633
10634 return length;
10635}
10636
10637/*
10638 * Position for a mode message.
10639 */
10640 static void
Bram Moolenaar05540972016-01-30 20:31:25 +010010641msg_pos_mode(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010642{
10643 msg_col = 0;
10644 msg_row = Rows - 1;
10645}
10646
10647/*
10648 * Delete mode message. Used when ESC is typed which is expected to end
10649 * Insert mode (but Insert mode didn't end yet!).
Bram Moolenaard12f5c12006-01-25 22:10:52 +000010650 * Caller should check "mode_displayed".
Bram Moolenaar071d4272004-06-13 20:20:40 +000010651 */
10652 void
Bram Moolenaar05540972016-01-30 20:31:25 +010010653unshowmode(int force)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010654{
10655 /*
Bram Moolenaare4ebd292010-01-19 17:40:46 +010010656 * Don't delete it right now, when not redrawing or inside a mapping.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010657 */
10658 if (!redrawing() || (!force && char_avail() && !KeyTyped))
10659 redraw_cmdline = TRUE; /* delete mode later */
10660 else
Bram Moolenaarfd773e92016-04-02 19:39:16 +020010661 clearmode();
10662}
10663
10664/*
10665 * Clear the mode message.
10666 */
10667 void
Bram Moolenaarcf089462016-06-12 21:18:43 +020010668clearmode(void)
Bram Moolenaarfd773e92016-04-02 19:39:16 +020010669{
Bram Moolenaar2abad542018-05-19 14:43:45 +020010670 int save_msg_row = msg_row;
10671 int save_msg_col = msg_col;
10672
Bram Moolenaarfd773e92016-04-02 19:39:16 +020010673 msg_pos_mode();
Bram Moolenaar0b6d9112018-05-22 20:35:17 +020010674 if (reg_recording != 0)
Bram Moolenaar8820b482017-03-16 17:23:31 +010010675 recording_mode(HL_ATTR(HLF_CM));
Bram Moolenaarfd773e92016-04-02 19:39:16 +020010676 msg_clr_eos();
Bram Moolenaar2abad542018-05-19 14:43:45 +020010677
10678 msg_col = save_msg_col;
10679 msg_row = save_msg_row;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010680}
10681
Bram Moolenaara0ed84a2015-11-19 17:56:13 +010010682 static void
Bram Moolenaar05540972016-01-30 20:31:25 +010010683recording_mode(int attr)
Bram Moolenaara0ed84a2015-11-19 17:56:13 +010010684{
Bram Moolenaar32526b32019-01-19 17:43:09 +010010685 msg_puts_attr(_("recording"), attr);
Bram Moolenaara0ed84a2015-11-19 17:56:13 +010010686 if (!shortmess(SHM_RECORDING))
10687 {
Bram Moolenaar32526b32019-01-19 17:43:09 +010010688 char s[4];
10689
10690 sprintf(s, " @%c", reg_recording);
10691 msg_puts_attr(s, attr);
Bram Moolenaara0ed84a2015-11-19 17:56:13 +010010692 }
10693}
10694
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010695/*
10696 * Draw the tab pages line at the top of the Vim window.
10697 */
Bram Moolenaare12bab32019-01-08 22:02:56 +010010698 void
Bram Moolenaar05540972016-01-30 20:31:25 +010010699draw_tabline(void)
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010700{
10701 int tabcount = 0;
10702 tabpage_T *tp;
10703 int tabwidth;
10704 int col = 0;
Bram Moolenaar997fb4b2006-02-17 21:53:23 +000010705 int scol = 0;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010706 int attr;
10707 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +000010708 win_T *cwp;
10709 int wincount;
10710 int modified;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010711 int c;
10712 int len;
Bram Moolenaar8820b482017-03-16 17:23:31 +010010713 int attr_sel = HL_ATTR(HLF_TPS);
10714 int attr_nosel = HL_ATTR(HLF_TP);
10715 int attr_fill = HL_ATTR(HLF_TPF);
Bram Moolenaar997fb4b2006-02-17 21:53:23 +000010716 char_u *p;
Bram Moolenaarfaa959a2006-02-20 21:37:40 +000010717 int room;
10718 int use_sep_chars = (t_colors < 8
10719#ifdef FEAT_GUI
10720 && !gui.in_use
10721#endif
Bram Moolenaar61be73b2016-04-29 22:59:22 +020010722#ifdef FEAT_TERMGUICOLORS
10723 && !p_tgc
Bram Moolenaar8a633e32016-04-21 21:10:14 +020010724#endif
Bram Moolenaarfaa959a2006-02-20 21:37:40 +000010725 );
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010726
Bram Moolenaarc695cec2017-01-08 20:00:04 +010010727 if (ScreenLines == NULL)
10728 return;
Bram Moolenaar997fb4b2006-02-17 21:53:23 +000010729 redraw_tabline = FALSE;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010730
Bram Moolenaar32466aa2006-02-24 23:53:04 +000010731#ifdef FEAT_GUI_TABLINE
Bram Moolenaardb552d602006-03-23 22:59:57 +000010732 /* Take care of a GUI tabline. */
Bram Moolenaar32466aa2006-02-24 23:53:04 +000010733 if (gui_use_tabline())
10734 {
10735 gui_update_tabline();
10736 return;
10737 }
10738#endif
10739
10740 if (tabline_height() < 1)
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010741 return;
10742
Bram Moolenaarfaa959a2006-02-20 21:37:40 +000010743#if defined(FEAT_STL_OPT)
Bram Moolenaarca57ab52019-04-13 14:53:16 +020010744 clear_TabPageIdxs();
Bram Moolenaard1f56e62006-02-22 21:25:37 +000010745
Bram Moolenaarfaa959a2006-02-20 21:37:40 +000010746 /* Use the 'tabline' option if it's set. */
10747 if (*p_tal != NUL)
10748 {
Bram Moolenaarf73d3bc2016-04-11 21:55:15 +020010749 int saved_did_emsg = did_emsg;
Bram Moolenaar238a5642006-02-21 22:12:05 +000010750
10751 /* Check for an error. If there is one we would loop in redrawing the
10752 * screen. Avoid that by making 'tabline' empty. */
Bram Moolenaarf73d3bc2016-04-11 21:55:15 +020010753 did_emsg = FALSE;
Bram Moolenaarfaa959a2006-02-20 21:37:40 +000010754 win_redr_custom(NULL, FALSE);
Bram Moolenaarf73d3bc2016-04-11 21:55:15 +020010755 if (did_emsg)
Bram Moolenaar238a5642006-02-21 22:12:05 +000010756 set_string_option_direct((char_u *)"tabline", -1,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010757 (char_u *)"", OPT_FREE, SID_ERROR);
Bram Moolenaarf73d3bc2016-04-11 21:55:15 +020010758 did_emsg |= saved_did_emsg;
Bram Moolenaarfaa959a2006-02-20 21:37:40 +000010759 }
Bram Moolenaar238a5642006-02-21 22:12:05 +000010760 else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +000010761#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010762 {
Bram Moolenaar29323592016-07-24 22:04:11 +020010763 FOR_ALL_TABPAGES(tp)
Bram Moolenaar238a5642006-02-21 22:12:05 +000010764 ++tabcount;
Bram Moolenaarf740b292006-02-16 22:11:02 +000010765
Bram Moolenaar238a5642006-02-21 22:12:05 +000010766 tabwidth = (Columns - 1 + tabcount / 2) / tabcount;
10767 if (tabwidth < 6)
10768 tabwidth = 6;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010769
Bram Moolenaar238a5642006-02-21 22:12:05 +000010770 attr = attr_nosel;
10771 tabcount = 0;
Bram Moolenaarfd2ac762006-03-01 22:09:21 +000010772 for (tp = first_tabpage; tp != NULL && col < Columns - 4;
10773 tp = tp->tp_next)
Bram Moolenaarf740b292006-02-16 22:11:02 +000010774 {
Bram Moolenaar238a5642006-02-21 22:12:05 +000010775 scol = col;
Bram Moolenaarf740b292006-02-16 22:11:02 +000010776
Bram Moolenaar238a5642006-02-21 22:12:05 +000010777 if (tp->tp_topframe == topframe)
10778 attr = attr_sel;
10779 if (use_sep_chars && col > 0)
10780 screen_putchar('|', 0, col++, attr);
10781
10782 if (tp->tp_topframe != topframe)
10783 attr = attr_nosel;
10784
10785 screen_putchar(' ', 0, col++, attr);
10786
10787 if (tp == curtab)
Bram Moolenaarf740b292006-02-16 22:11:02 +000010788 {
Bram Moolenaar238a5642006-02-21 22:12:05 +000010789 cwp = curwin;
10790 wp = firstwin;
10791 }
10792 else
10793 {
10794 cwp = tp->tp_curwin;
10795 wp = tp->tp_firstwin;
10796 }
10797
10798 modified = FALSE;
10799 for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount)
10800 if (bufIsChanged(wp->w_buffer))
10801 modified = TRUE;
10802 if (modified || wincount > 1)
10803 {
10804 if (wincount > 1)
10805 {
10806 vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +000010807 len = (int)STRLEN(NameBuff);
Bram Moolenaarfd2ac762006-03-01 22:09:21 +000010808 if (col + len >= Columns - 3)
10809 break;
Bram Moolenaar238a5642006-02-21 22:12:05 +000010810 screen_puts_len(NameBuff, len, 0, col,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +000010811#if defined(FEAT_SYN_HL)
Bram Moolenaar8820b482017-03-16 17:23:31 +010010812 hl_combine_attr(attr, HL_ATTR(HLF_T))
Bram Moolenaarfaa959a2006-02-20 21:37:40 +000010813#else
Bram Moolenaare0f14822014-08-06 13:20:56 +020010814 attr
Bram Moolenaarfaa959a2006-02-20 21:37:40 +000010815#endif
Bram Moolenaar238a5642006-02-21 22:12:05 +000010816 );
10817 col += len;
10818 }
10819 if (modified)
10820 screen_puts_len((char_u *)"+", 1, 0, col++, attr);
10821 screen_putchar(' ', 0, col++, attr);
10822 }
10823
10824 room = scol - col + tabwidth - 1;
10825 if (room > 0)
10826 {
Bram Moolenaar32466aa2006-02-24 23:53:04 +000010827 /* Get buffer name in NameBuff[] */
10828 get_trans_bufname(cwp->w_buffer);
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010829 shorten_dir(NameBuff);
Bram Moolenaar238a5642006-02-21 22:12:05 +000010830 len = vim_strsize(NameBuff);
10831 p = NameBuff;
Bram Moolenaar238a5642006-02-21 22:12:05 +000010832 if (has_mbyte)
10833 while (len > room)
10834 {
10835 len -= ptr2cells(p);
Bram Moolenaar91acfff2017-03-12 19:22:36 +010010836 MB_PTR_ADV(p);
Bram Moolenaar238a5642006-02-21 22:12:05 +000010837 }
Bram Moolenaara12a1612019-01-24 16:39:02 +010010838 else if (len > room)
Bram Moolenaar238a5642006-02-21 22:12:05 +000010839 {
10840 p += len - room;
10841 len = room;
10842 }
Bram Moolenaarfd2ac762006-03-01 22:09:21 +000010843 if (len > Columns - col - 1)
10844 len = Columns - col - 1;
Bram Moolenaar238a5642006-02-21 22:12:05 +000010845
Bram Moolenaara93fa7e2006-04-17 22:14:47 +000010846 screen_puts_len(p, (int)STRLEN(p), 0, col, attr);
Bram Moolenaarf740b292006-02-16 22:11:02 +000010847 col += len;
10848 }
Bram Moolenaarf740b292006-02-16 22:11:02 +000010849 screen_putchar(' ', 0, col++, attr);
Bram Moolenaar238a5642006-02-21 22:12:05 +000010850
10851 /* Store the tab page number in TabPageIdxs[], so that
10852 * jump_to_mouse() knows where each one is. */
10853 ++tabcount;
10854 while (scol < col)
10855 TabPageIdxs[scol++] = tabcount;
Bram Moolenaarf740b292006-02-16 22:11:02 +000010856 }
10857
Bram Moolenaar238a5642006-02-21 22:12:05 +000010858 if (use_sep_chars)
10859 c = '_';
10860 else
10861 c = ' ';
10862 screen_fill(0, 1, col, (int)Columns, c, c, attr_fill);
Bram Moolenaard1f56e62006-02-22 21:25:37 +000010863
10864 /* Put an "X" for closing the current tab if there are several. */
10865 if (first_tabpage->tp_next != NULL)
10866 {
10867 screen_putchar('X', 0, (int)Columns - 1, attr_nosel);
10868 TabPageIdxs[Columns - 1] = -999;
10869 }
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010870 }
Bram Moolenaarb21e5842006-04-16 18:30:08 +000010871
10872 /* Reset the flag here again, in case evaluating 'tabline' causes it to be
10873 * set. */
10874 redraw_tabline = FALSE;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010875}
Bram Moolenaar32466aa2006-02-24 23:53:04 +000010876
10877/*
10878 * Get buffer name for "buf" into NameBuff[].
10879 * Takes care of special buffer names and translates special characters.
10880 */
10881 void
Bram Moolenaar05540972016-01-30 20:31:25 +010010882get_trans_bufname(buf_T *buf)
Bram Moolenaar32466aa2006-02-24 23:53:04 +000010883{
10884 if (buf_spname(buf) != NULL)
Bram Moolenaare1704ba2012-10-03 18:25:00 +020010885 vim_strncpy(NameBuff, buf_spname(buf), MAXPATHL - 1);
Bram Moolenaar32466aa2006-02-24 23:53:04 +000010886 else
10887 home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE);
10888 trans_characters(NameBuff, MAXPATHL);
10889}
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010890
Bram Moolenaar071d4272004-06-13 20:20:40 +000010891/*
10892 * Get the character to use in a status line. Get its attributes in "*attr".
10893 */
10894 static int
Bram Moolenaar3633cf52017-07-31 22:29:35 +020010895fillchar_status(int *attr, win_T *wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010896{
10897 int fill;
Bram Moolenaar3633cf52017-07-31 22:29:35 +020010898
10899#ifdef FEAT_TERMINAL
10900 if (bt_terminal(wp->w_buffer))
10901 {
Bram Moolenaar3633cf52017-07-31 22:29:35 +020010902 if (wp == curwin)
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +020010903 {
10904 *attr = HL_ATTR(HLF_ST);
Bram Moolenaar3633cf52017-07-31 22:29:35 +020010905 fill = fill_stl;
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +020010906 }
Bram Moolenaar3633cf52017-07-31 22:29:35 +020010907 else
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +020010908 {
10909 *attr = HL_ATTR(HLF_STNC);
Bram Moolenaar3633cf52017-07-31 22:29:35 +020010910 fill = fill_stlnc;
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +020010911 }
Bram Moolenaar3633cf52017-07-31 22:29:35 +020010912 }
10913 else
10914#endif
10915 if (wp == curwin)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010916 {
Bram Moolenaar8820b482017-03-16 17:23:31 +010010917 *attr = HL_ATTR(HLF_S);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010918 fill = fill_stl;
10919 }
10920 else
10921 {
Bram Moolenaar8820b482017-03-16 17:23:31 +010010922 *attr = HL_ATTR(HLF_SNC);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010923 fill = fill_stlnc;
10924 }
10925 /* Use fill when there is highlighting, and highlighting of current
10926 * window differs, or the fillchars differ, or this is not the
10927 * current window */
Bram Moolenaar8820b482017-03-16 17:23:31 +010010928 if (*attr != 0 && ((HL_ATTR(HLF_S) != HL_ATTR(HLF_SNC)
Bram Moolenaar3633cf52017-07-31 22:29:35 +020010929 || wp != curwin || ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010930 || (fill_stl != fill_stlnc)))
10931 return fill;
Bram Moolenaar3633cf52017-07-31 22:29:35 +020010932 if (wp == curwin)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010933 return '^';
10934 return '=';
10935}
Bram Moolenaar071d4272004-06-13 20:20:40 +000010936
Bram Moolenaar071d4272004-06-13 20:20:40 +000010937/*
10938 * Get the character to use in a separator between vertically split windows.
10939 * Get its attributes in "*attr".
10940 */
10941 static int
Bram Moolenaar05540972016-01-30 20:31:25 +010010942fillchar_vsep(int *attr)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010943{
Bram Moolenaar8820b482017-03-16 17:23:31 +010010944 *attr = HL_ATTR(HLF_C);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010945 if (*attr == 0 && fill_vert == ' ')
10946 return '|';
10947 else
10948 return fill_vert;
10949}
Bram Moolenaar071d4272004-06-13 20:20:40 +000010950
10951/*
10952 * Return TRUE if redrawing should currently be done.
10953 */
10954 int
Bram Moolenaar05540972016-01-30 20:31:25 +010010955redrawing(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010956{
Bram Moolenaareb992cb2017-03-09 18:20:16 +010010957#ifdef FEAT_EVAL
10958 if (disable_redraw_for_testing)
10959 return 0;
10960 else
10961#endif
Bram Moolenaared5a9d62018-09-06 13:14:43 +020010962 return ((!RedrawingDisabled
10963#ifdef FEAT_EVAL
10964 || ignore_redraw_flag_for_testing
10965#endif
10966 ) && !(p_lz && char_avail() && !KeyTyped && !do_redraw));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010967}
10968
10969/*
10970 * Return TRUE if printing messages should currently be done.
10971 */
10972 int
Bram Moolenaar05540972016-01-30 20:31:25 +010010973messaging(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010974{
10975 return (!(p_lz && char_avail() && !KeyTyped));
10976}
10977
Bram Moolenaar1b9645d2017-09-17 23:03:31 +020010978#ifdef FEAT_MENU
10979/*
10980 * Draw the window toolbar.
10981 */
10982 static void
10983redraw_win_toolbar(win_T *wp)
10984{
10985 vimmenu_T *menu;
10986 int item_idx = 0;
10987 int item_count = 0;
10988 int col = 0;
10989 int next_col;
10990 int off = (int)(current_ScreenLine - ScreenLines);
10991 int fill_attr = syn_name2attr((char_u *)"ToolbarLine");
10992 int button_attr = syn_name2attr((char_u *)"ToolbarButton");
10993
10994 vim_free(wp->w_winbar_items);
10995 for (menu = wp->w_winbar->children; menu != NULL; menu = menu->next)
10996 ++item_count;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020010997 wp->w_winbar_items = ALLOC_CLEAR_MULT(winbar_item_T, item_count + 1);
Bram Moolenaar1b9645d2017-09-17 23:03:31 +020010998
10999 /* TODO: use fewer spaces if there is not enough room */
11000 for (menu = wp->w_winbar->children;
Bram Moolenaar02631462017-09-22 15:20:32 +020011001 menu != NULL && col < wp->w_width; menu = menu->next)
Bram Moolenaar1b9645d2017-09-17 23:03:31 +020011002 {
11003 space_to_screenline(off + col, fill_attr);
Bram Moolenaar02631462017-09-22 15:20:32 +020011004 if (++col >= wp->w_width)
Bram Moolenaar1b9645d2017-09-17 23:03:31 +020011005 break;
11006 if (col > 1)
11007 {
11008 space_to_screenline(off + col, fill_attr);
Bram Moolenaar02631462017-09-22 15:20:32 +020011009 if (++col >= wp->w_width)
Bram Moolenaar1b9645d2017-09-17 23:03:31 +020011010 break;
11011 }
11012
11013 wp->w_winbar_items[item_idx].wb_startcol = col;
11014 space_to_screenline(off + col, button_attr);
Bram Moolenaar02631462017-09-22 15:20:32 +020011015 if (++col >= wp->w_width)
Bram Moolenaar1b9645d2017-09-17 23:03:31 +020011016 break;
11017
11018 next_col = text_to_screenline(wp, menu->name, col);
11019 while (col < next_col)
11020 {
11021 ScreenAttrs[off + col] = button_attr;
11022 ++col;
11023 }
11024 wp->w_winbar_items[item_idx].wb_endcol = col;
11025 wp->w_winbar_items[item_idx].wb_menu = menu;
11026 ++item_idx;
11027
Bram Moolenaar02631462017-09-22 15:20:32 +020011028 if (col >= wp->w_width)
Bram Moolenaar1b9645d2017-09-17 23:03:31 +020011029 break;
11030 space_to_screenline(off + col, button_attr);
11031 ++col;
11032 }
Bram Moolenaar02631462017-09-22 15:20:32 +020011033 while (col < wp->w_width)
Bram Moolenaar1b9645d2017-09-17 23:03:31 +020011034 {
11035 space_to_screenline(off + col, fill_attr);
11036 ++col;
11037 }
11038 wp->w_winbar_items[item_idx].wb_menu = NULL; /* end marker */
11039
Bram Moolenaar02631462017-09-22 15:20:32 +020011040 screen_line(wp->w_winrow, wp->w_wincol, (int)wp->w_width,
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011041 (int)wp->w_width, 0);
Bram Moolenaar1b9645d2017-09-17 23:03:31 +020011042}
11043#endif
Bram Moolenaar491ac282018-06-17 14:47:55 +020011044
Bram Moolenaar071d4272004-06-13 20:20:40 +000011045/*
11046 * Show current status info in ruler and various other places
11047 * If always is FALSE, only show ruler if position has changed.
11048 */
11049 void
Bram Moolenaar05540972016-01-30 20:31:25 +010011050showruler(int always)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011051{
11052 if (!always && !redrawing())
11053 return;
Bram Moolenaar9372a112005-12-06 19:59:18 +000011054#ifdef FEAT_INS_EXPAND
11055 if (pum_visible())
11056 {
11057 /* Don't redraw right now, do it later. */
11058 curwin->w_redr_status = TRUE;
11059 return;
11060 }
11061#endif
Bram Moolenaar4033c552017-09-16 20:54:51 +020011062#if defined(FEAT_STL_OPT)
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011063 if ((*p_stl != NUL || *curwin->w_p_stl != NUL) && curwin->w_status_height)
Bram Moolenaar362f3562009-11-03 16:20:34 +000011064 redraw_custom_statusline(curwin);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011065 else
11066#endif
11067#ifdef FEAT_CMDL_INFO
Bram Moolenaar491ac282018-06-17 14:47:55 +020011068 win_redr_ruler(curwin, always, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011069#endif
11070
11071#ifdef FEAT_TITLE
11072 if (need_maketitle
11073# ifdef FEAT_STL_OPT
11074 || (p_icon && (stl_syntax & STL_IN_ICON))
11075 || (p_title && (stl_syntax & STL_IN_TITLE))
11076# endif
11077 )
11078 maketitle();
11079#endif
Bram Moolenaar497683b2008-05-28 17:02:46 +000011080 /* Redraw the tab pages line if needed. */
11081 if (redraw_tabline)
11082 draw_tabline();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011083}
11084
11085#ifdef FEAT_CMDL_INFO
11086 static void
Bram Moolenaar491ac282018-06-17 14:47:55 +020011087win_redr_ruler(win_T *wp, int always, int ignore_pum)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011088{
Bram Moolenaar0ab2a882009-05-13 10:51:08 +000011089#define RULER_BUF_LEN 70
11090 char_u buffer[RULER_BUF_LEN];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011091 int row;
11092 int fillchar;
11093 int attr;
11094 int empty_line = FALSE;
11095 colnr_T virtcol;
11096 int i;
Bram Moolenaar0ab2a882009-05-13 10:51:08 +000011097 size_t len;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011098 int o;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011099 int this_ru_col;
11100 int off = 0;
Bram Moolenaar2c519cf2019-03-21 21:45:34 +010011101 int width;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011102
11103 /* If 'ruler' off or redrawing disabled, don't do anything */
11104 if (!p_ru)
11105 return;
11106
11107 /*
11108 * Check if cursor.lnum is valid, since win_redr_ruler() may be called
11109 * after deleting lines, before cursor.lnum is corrected.
11110 */
11111 if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count)
11112 return;
11113
11114#ifdef FEAT_INS_EXPAND
11115 /* Don't draw the ruler while doing insert-completion, it might overwrite
11116 * the (long) mode message. */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011117 if (wp == lastwin && lastwin->w_status_height == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011118 if (edit_submode != NULL)
11119 return;
Bram Moolenaar491ac282018-06-17 14:47:55 +020011120 // Don't draw the ruler when the popup menu is visible, it may overlap.
11121 // Except when the popup menu will be redrawn anyway.
11122 if (!ignore_pum && pum_visible())
Bram Moolenaar1c7715d2005-10-03 22:02:18 +000011123 return;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011124#endif
11125
11126#ifdef FEAT_STL_OPT
11127 if (*p_ruf)
11128 {
Bram Moolenaar238a5642006-02-21 22:12:05 +000011129 int save_called_emsg = called_emsg;
11130
11131 called_emsg = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011132 win_redr_custom(wp, TRUE);
Bram Moolenaar238a5642006-02-21 22:12:05 +000011133 if (called_emsg)
11134 set_string_option_direct((char_u *)"rulerformat", -1,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011135 (char_u *)"", OPT_FREE, SID_ERROR);
Bram Moolenaar238a5642006-02-21 22:12:05 +000011136 called_emsg |= save_called_emsg;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011137 return;
11138 }
11139#endif
11140
11141 /*
11142 * Check if not in Insert mode and the line is empty (will show "0-1").
11143 */
11144 if (!(State & INSERT)
11145 && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL)
11146 empty_line = TRUE;
11147
11148 /*
11149 * Only draw the ruler when something changed.
11150 */
11151 validate_virtcol_win(wp);
11152 if ( redraw_cmdline
11153 || always
11154 || wp->w_cursor.lnum != wp->w_ru_cursor.lnum
11155 || wp->w_cursor.col != wp->w_ru_cursor.col
11156 || wp->w_virtcol != wp->w_ru_virtcol
Bram Moolenaar071d4272004-06-13 20:20:40 +000011157 || wp->w_cursor.coladd != wp->w_ru_cursor.coladd
Bram Moolenaar071d4272004-06-13 20:20:40 +000011158 || wp->w_topline != wp->w_ru_topline
11159 || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count
11160#ifdef FEAT_DIFF
11161 || wp->w_topfill != wp->w_ru_topfill
11162#endif
11163 || empty_line != wp->w_ru_empty)
11164 {
11165 cursor_off();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011166 if (wp->w_status_height)
11167 {
11168 row = W_WINROW(wp) + wp->w_height;
Bram Moolenaar3633cf52017-07-31 22:29:35 +020011169 fillchar = fillchar_status(&attr, wp);
Bram Moolenaar53f81742017-09-22 14:35:51 +020011170 off = wp->w_wincol;
Bram Moolenaar02631462017-09-22 15:20:32 +020011171 width = wp->w_width;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011172 }
11173 else
Bram Moolenaar071d4272004-06-13 20:20:40 +000011174 {
11175 row = Rows - 1;
11176 fillchar = ' ';
11177 attr = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011178 width = Columns;
11179 off = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011180 }
11181
11182 /* In list mode virtcol needs to be recomputed */
11183 virtcol = wp->w_virtcol;
11184 if (wp->w_p_list && lcs_tab1 == NUL)
11185 {
11186 wp->w_p_list = FALSE;
11187 getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL);
11188 wp->w_p_list = TRUE;
11189 }
11190
11191 /*
11192 * Some sprintfs return the length, some return a pointer.
11193 * To avoid portability problems we use strlen() here.
11194 */
Bram Moolenaar0ab2a882009-05-13 10:51:08 +000011195 vim_snprintf((char *)buffer, RULER_BUF_LEN, "%ld,",
Bram Moolenaar071d4272004-06-13 20:20:40 +000011196 (wp->w_buffer->b_ml.ml_flags & ML_EMPTY)
11197 ? 0L
11198 : (long)(wp->w_cursor.lnum));
Bram Moolenaar0ab2a882009-05-13 10:51:08 +000011199 len = STRLEN(buffer);
11200 col_print(buffer + len, RULER_BUF_LEN - len,
Bram Moolenaar071d4272004-06-13 20:20:40 +000011201 empty_line ? 0 : (int)wp->w_cursor.col + 1,
11202 (int)virtcol + 1);
11203
11204 /*
11205 * Add a "50%" if there is room for it.
11206 * On the last line, don't print in the last column (scrolls the
11207 * screen up on some terminals).
11208 */
11209 i = (int)STRLEN(buffer);
Bram Moolenaar0ab2a882009-05-13 10:51:08 +000011210 get_rel_pos(wp, buffer + i + 1, RULER_BUF_LEN - i - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011211 o = i + vim_strsize(buffer + i + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011212 if (wp->w_status_height == 0) /* can't use last char of screen */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011213 ++o;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011214 this_ru_col = ru_col - (Columns - width);
11215 if (this_ru_col < 0)
11216 this_ru_col = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011217 /* Never use more than half the window/screen width, leave the other
11218 * half for the filename. */
Bram Moolenaar4033c552017-09-16 20:54:51 +020011219 if (this_ru_col < (width + 1) / 2)
11220 this_ru_col = (width + 1) / 2;
11221 if (this_ru_col + o < width)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011222 {
Bram Moolenaar0027c212015-01-07 13:31:52 +010011223 /* need at least 3 chars left for get_rel_pos() + NUL */
Bram Moolenaar4033c552017-09-16 20:54:51 +020011224 while (this_ru_col + o < width && RULER_BUF_LEN > i + 4)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011225 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000011226 if (has_mbyte)
11227 i += (*mb_char2bytes)(fillchar, buffer + i);
11228 else
Bram Moolenaar071d4272004-06-13 20:20:40 +000011229 buffer[i++] = fillchar;
11230 ++o;
11231 }
Bram Moolenaar0ab2a882009-05-13 10:51:08 +000011232 get_rel_pos(wp, buffer + i, RULER_BUF_LEN - i);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011233 }
11234 /* Truncate at window boundary. */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011235 if (has_mbyte)
11236 {
11237 o = 0;
Bram Moolenaar0fa313a2005-08-10 21:07:57 +000011238 for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011239 {
11240 o += (*mb_ptr2cells)(buffer + i);
Bram Moolenaar4033c552017-09-16 20:54:51 +020011241 if (this_ru_col + o > width)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011242 {
11243 buffer[i] = NUL;
11244 break;
11245 }
11246 }
11247 }
Bram Moolenaara12a1612019-01-24 16:39:02 +010011248 else if (this_ru_col + (int)STRLEN(buffer) > width)
Bram Moolenaar4033c552017-09-16 20:54:51 +020011249 buffer[width - this_ru_col] = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011250
Bram Moolenaar4033c552017-09-16 20:54:51 +020011251 screen_puts(buffer, row, this_ru_col + off, attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011252 i = redraw_cmdline;
11253 screen_fill(row, row + 1,
Bram Moolenaar4033c552017-09-16 20:54:51 +020011254 this_ru_col + off + (int)STRLEN(buffer),
11255 (int)(off + width),
Bram Moolenaar071d4272004-06-13 20:20:40 +000011256 fillchar, fillchar, attr);
11257 /* don't redraw the cmdline because of showing the ruler */
11258 redraw_cmdline = i;
11259 wp->w_ru_cursor = wp->w_cursor;
11260 wp->w_ru_virtcol = wp->w_virtcol;
11261 wp->w_ru_empty = empty_line;
11262 wp->w_ru_topline = wp->w_topline;
11263 wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count;
11264#ifdef FEAT_DIFF
11265 wp->w_ru_topfill = wp->w_topfill;
11266#endif
11267 }
11268}
11269#endif
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011270
11271#if defined(FEAT_LINEBREAK) || defined(PROTO)
11272/*
Bram Moolenaar64486672010-05-16 15:46:46 +020011273 * Return the width of the 'number' and 'relativenumber' column.
11274 * Caller may need to check if 'number' or 'relativenumber' is set.
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011275 * Otherwise it depends on 'numberwidth' and the line count.
11276 */
11277 int
Bram Moolenaar05540972016-01-30 20:31:25 +010011278number_width(win_T *wp)
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011279{
11280 int n;
11281 linenr_T lnum;
11282
Bram Moolenaar5ebc09b2013-06-04 22:13:50 +020011283 if (wp->w_p_rnu && !wp->w_p_nu)
11284 /* cursor line shows "0" */
11285 lnum = wp->w_height;
11286 else
11287 /* cursor line shows absolute line number */
11288 lnum = wp->w_buffer->b_ml.ml_line_count;
Bram Moolenaar64486672010-05-16 15:46:46 +020011289
Bram Moolenaar6b314672015-03-20 15:42:10 +010011290 if (lnum == wp->w_nrwidth_line_count && wp->w_nuw_cached == wp->w_p_nuw)
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011291 return wp->w_nrwidth_width;
11292 wp->w_nrwidth_line_count = lnum;
11293
11294 n = 0;
11295 do
11296 {
Bram Moolenaarc9b4b052006-04-30 18:54:39 +000011297 lnum /= 10;
11298 ++n;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011299 } while (lnum > 0);
11300
11301 /* 'numberwidth' gives the minimal width plus one */
11302 if (n < wp->w_p_nuw - 1)
11303 n = wp->w_p_nuw - 1;
11304
11305 wp->w_nrwidth_width = n;
Bram Moolenaar6b314672015-03-20 15:42:10 +010011306 wp->w_nuw_cached = wp->w_p_nuw;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011307 return n;
11308}
11309#endif
Bram Moolenaar9750bb12012-12-05 16:10:42 +010011310
Bram Moolenaar113e1072019-01-20 15:30:40 +010011311#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaar9750bb12012-12-05 16:10:42 +010011312/*
11313 * Return the current cursor column. This is the actual position on the
11314 * screen. First column is 0.
11315 */
11316 int
Bram Moolenaar05540972016-01-30 20:31:25 +010011317screen_screencol(void)
Bram Moolenaar9750bb12012-12-05 16:10:42 +010011318{
11319 return screen_cur_col;
11320}
11321
11322/*
11323 * Return the current cursor row. This is the actual position on the screen.
11324 * First row is 0.
11325 */
11326 int
Bram Moolenaar05540972016-01-30 20:31:25 +010011327screen_screenrow(void)
Bram Moolenaar9750bb12012-12-05 16:10:42 +010011328{
11329 return screen_cur_row;
11330}
Bram Moolenaar113e1072019-01-20 15:30:40 +010011331#endif